calloc.go 1.9 KB

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