sg_get_mem_stats(3)
β¨ NAME β¨
sg_get_mem_stats, sg_get_mem_stats_r, sg_free_mem_stats, sg_get_swap_stats, sg_get_swap_stats_r, sg_free_swap_stats β get VM statistics. This is the manual page for sg_get_mem_stats(3), bestie, and it is literally all about VM stats π
πΈ SYNOPSIS πΈ
#include <statgrab.h>
sg_mem_stats *sg_get_mem_stats (size_t *entries);
sg_mem_stats *sg_get_mem_stats_r (size_t *entries);
sg_error sg_free_mem_stats (sg_mem_stats *data);
sg_swap_stats *sg_get_swap_stats (size_t *entries);
sg_swap_stats *sg_get_swap_stats_r (size_t *entries);
sg_error sg_free_swap_stats (sg_swap_stats *data);
π¦ DESCRIPTION π¦
okay so memory stats come through sg_get_mem_stats() and sg_get_mem_stats_r(). Both of them hand you back a pointer to a sg_mem_stats buffer. Quick note bestie: this statistic doesn't need to map the entire physical memory usage β it represents the real memory usable by the operating system π«Ά
Swap stats come through sg_get_swap_stats() and sg_get_swap_stats_r(). Both return a pointer to a sg_swap_stats buffer β¨
π API Shortcut π
sg_get_mem_statsβ returnssg_mem_stats *; data owner: libstatgrab (thread local)sg_get_mem_stats_rβ returnssg_mem_stats *; data owner: callersg_get_swap_statsβ returnssg_swap_stats *; data owner: libstatgrab (thread local)sg_get_swap_stats_rβ returnssg_swap_stats *; data owner: caller
The sg_mem_stats buffer you get from sg_get_mem_stats_r() and the sg_swap_stats buffer you get from sg_get_swap_stats_r() must be freed using sg_free_mem_stats() or sg_free_swap_stats(), respectively, when they're not needed any more. The caller is responsible for doing it β that's you, bestie π
π¨ FreeBSD heads-up: on the FreeBSD operating system, elevated privileges are required to access the swap statistics. Making the program setgid kmem should be sufficient. Programs running as root will not have this problem.
π RETURN VALUES π
The VM system calls can return a pointer to either a sg_mem_stats or a sg_swap_stats π
β¨ sg_mem_stats β¨
typedef struct{
unsigned long long total;
unsigned long long free;
unsigned long long used;
unsigned long long cache;
time_t systime;
} sg_mem_stats;
totalβ the total amount of real memory, in bytesfreeβ the free amount of real memory, in bytesusedβ the used amount of real memory, in bytescacheβ the amount of real memory in bytes used for cachingsystimeβ the timestamp when those stats got collected, in seconds since epoch
π sg_swap_stats π
typedef struct {
unsigned long long total;
unsigned long long used;
unsigned long long free;
time_t systime;
} sg_swap_stats;
totalβ the total swap space, in bytesusedβ the used swap, in bytesfreeβ the free swap, in bytessystimeβ the timestamp when those stats got collected, in seconds since epoch
π«Ά TODO π«Ά
TODO time, bestie: add a function to hold open the file descriptor to the kernel memory structures. Doing this would allow the elevated privileges to be dropped early on π₯
π₯ SEE ALSO π₯
statgrab(3) β go check it out, iykyk π
π WEBSITE π
β¨https://libstatgrab.org/β© β that's the website, no cap π¦
okay that's the whole vibe: this page is from libstatgrab, dated 2019-03-08, and it's literally sg_get_mem_stats(3). bye bestie π
β¨π«Ά
π¦ where this page comes from
- alpine 3.24: libstatgrab-doc 0.92.1-r1 Β· LGPL-2.0-or-later
- arch rolling: libstatgrab 0.92.1-2 Β· LGPL AND GPL
- fedora 43: libstatgrab-devel 1:0.92.1-14.fc43 Β· LGPL-2.1-or-later
- fedora 43: libstatgrab-devel 1:0.92.1-14.fc43 Β· LGPL-2.1-or-later
- fedora 44: libstatgrab-devel 1:0.92.1-15.fc44 Β· LGPL-2.1-or-later
- fedora 44: libstatgrab-devel 1:0.92.1-15.fc44 Β· LGPL-2.1-or-later
- nixos 26.05: libstatgrab 0.92.1
- nixpkgs unstable: libstatgrab 0.92.1
- opensuse-leap 16.0: libstatgrab-devel 0.92.1-bp160.1.14 Β· LGPL-2.1-or-later
- opensuse-leap 16.0: libstatgrab-devel 0.92.1-bp160.1.14 Β· LGPL-2.1-or-later
- opensuse-leap 16.0: libstatgrab-devel 0.92.1-bp160.1.14 Β· LGPL-2.1-or-later
- opensuse-leap 16.0: libstatgrab-devel 0.92.1-bp160.1.14 Β· LGPL-2.1-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms