• Michael Anthony Knyszek's avatar
    runtime: use MADV_FREE_REUSABLE on darwin · abf8e355
    Michael Anthony Knyszek authored
    Currently on darwin we use MADV_FREE, which unfortunately doesn't result
    in a change in the process's RSS until pages actually get kicked out,
    which the OS is free to do lazily (e.g. until it finds itself under
    memory pressure).
    
    To remedy this, we instead use MADV_FREE_REUSABLE which has similar
    semantics, except that it also sets a reusable bit on each page so the
    process's RSS gets reported more accurately. The one caveat is for every
    time we call MADV_FREE_REUSABLE on a region we must call MADV_FREE_REUSE
    to keep the kernel's accounting updated.
    
    Also, because this change requires adding new constants that only exist
    on darwin, it splits mem_bsd.go into mem_bsd.go and mem_darwin.go.
    
    Fixes #29844.
    
    Change-Id: Idb6421698511138a430807bcbbd1516cd57557c8
    Reviewed-on: https://go-review.googlesource.com/c/go/+/159117Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
    Run-TryBot: Michael Knyszek <mknyszek@google.com>
    TryBot-Result: Gobot Gobot <gobot@golang.org>
    abf8e355
defs_darwin_arm64.go 3.78 KB