calloc.go 2.0 KB

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