Debian Codegraph @

decommit_unix.go

raw symbols SCIP
1 // Copyright 2026 The Memory Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 //go:build unix
6
7 package memoryscip-go gomod modernc.org/memory . `modernc.org/memory`/ // import "modernc.org/memory"
8
9 import (
10 "unsafescip-go gomod github.com/golang/go/src go1.23.0 unsafe/"
11
12 "golang.org/x/sys/unixscip-go gomod golang.org/x/sys v0.31.0 `golang.org/x/sys/unix`/"
13 )
14
15 // canDecommit gates the decommit policy: pooled regions past the hot window
16 // hand their pages back to the OS.
17 const canDecommitscip-go gomod modernc.org/memory . `modernc.org/memory`/canDecommit. = true
18
19 // madviseAdvice is the advice passed for a region falling out of the hot
20 // window.
21 //
22 // MADV_DONTNEED rather than MADV_FREE: MADV_FREE reclaims lazily, so the
23 // resident set does not actually drop until the machine is under pressure
24 // - measured, a 2 GiB pool still read as 2 GiB of RSS. That is the same
25 // reason the Go runtime defaults to MADV_DONTNEED.
26 const madviseAdvicescip-go gomod modernc.org/memory . `modernc.org/memory`/madviseAdvice. = unixscip-go gomod golang.org/x/sys v0.31.0 `golang.org/x/sys/unix`/.MADV_DONTNEEDscip-go gomod golang.org/x/sys v0.31.0 `golang.org/x/sys/unix`/MADV_DONTNEED.
27
28 // decommit asks the kernel to reclaim the physical pages backing the empty
29 // region at p without unmapping it. The mapping stays, and with it the address,
30 // the VMA and the absence of a future mmap - that is the whole point: retention
31 // keeps its syscall and map-count savings while handing the resident set back.
32 //
33 // MADV_DONTNEED does not change vm_flags, so this does not split the VMA.
34 //
35 // The first OS page is left alone because it carries the page header, so
36 // nothing has to be reconstructed when the region comes back out of the pool.
37 // That holds only while osPageSize < pageSize; on a kernel configured with
38 // 64 KiB base pages the two are equal and decommit turns itself off rather than
39 // zeroing a live header. Such hosts would instead need page.size restored from
40 // the pool's map key in the reuse path.
41 func decommitscip-go gomod modernc.org/memory . `modernc.org/memory`/decommit().(p uintptr, size int) {
42 if size <= osPageSizescip-go gomod modernc.org/memory . `modernc.org/memory`/osPageSize. {
43 return
44 }
45
46 n := size - osPageSizescip-go gomod modernc.org/memory . `modernc.org/memory`/osPageSize.
47 unixscip-go gomod golang.org/x/sys v0.31.0 `golang.org/x/sys/unix`/.Madvisescip-go gomod golang.org/x/sys v0.31.0 `golang.org/x/sys/unix`/Madvise().((*rawmemscip-go gomod modernc.org/memory . `modernc.org/memory`/rawmem#)(unsafescip-go gomod github.com/golang/go/src go1.23.0 unsafe/.Pointer(p + uintptr(osPageSizescip-go gomod modernc.org/memory . `modernc.org/memory`/osPageSize.)))[:n:n], madviseAdvicescip-go gomod modernc.org/memory . `modernc.org/memory`/madviseAdvice.)
48 }
49
50 // recommit is what makes a region from the pool's decommitted prefix usable
51 // again before it is handed out. On unix there is nothing to do: pages
52 // discarded by MADV_DONTNEED soft-fault back zero-filled on first touch.
53 func recommitscip-go gomod modernc.org/memory . `modernc.org/memory`/recommit().(uintptr, int) error { return nil }