calloc.go raw
1 /*
2 * SPDX-FileCopyrightText: © Hypermode Inc. <hello@hypermode.com>
3 * SPDX-License-Identifier: Apache-2.0
4 */
5
6 package z
7
8 import "sync/atomic"
9
10 var numBytes int64
11
12 // NumAllocBytes returns the number of bytes allocated using calls to z.Calloc. The allocations
13 // could be happening via either Go or jemalloc, depending upon the build flags.
14 func NumAllocBytes() int64 {
15 return atomic.LoadInt64(&numBytes)
16 }
17
18 // MemStats is used to fetch JE Malloc Stats. The stats are fetched from
19 // the mallctl namespace http://jemalloc.net/jemalloc.3.html#mallctl_namespace.
20 type MemStats struct {
21 // Total number of bytes allocated by the application.
22 // http://jemalloc.net/jemalloc.3.html#stats.allocated
23 Allocated uint64
24 // Total number of bytes in active pages allocated by the application. This
25 // is a multiple of the page size, and greater than or equal to
26 // Allocated.
27 // http://jemalloc.net/jemalloc.3.html#stats.active
28 Active uint64
29 // Maximum number of bytes in physically resident data pages mapped by the
30 // allocator, comprising all pages dedicated to allocator metadata, pages
31 // backing active allocations, and unused dirty pages. This is a maximum
32 // rather than precise because pages may not actually be physically
33 // resident if they correspond to demand-zeroed virtual memory that has not
34 // yet been touched. This is a multiple of the page size, and is larger
35 // than stats.active.
36 // http://jemalloc.net/jemalloc.3.html#stats.resident
37 Resident uint64
38 // Total number of bytes in virtual memory mappings that were retained
39 // rather than being returned to the operating system via e.g. munmap(2) or
40 // similar. Retained virtual memory is typically untouched, decommitted, or
41 // purged, so it has no strongly associated physical memory (see extent
42 // hooks http://jemalloc.net/jemalloc.3.html#arena.i.extent_hooks for
43 // details). Retained memory is excluded from mapped memory statistics,
44 // e.g. stats.mapped (http://jemalloc.net/jemalloc.3.html#stats.mapped).
45 // http://jemalloc.net/jemalloc.3.html#stats.retained
46 Retained uint64
47 }
48