This is the mail archive of the
glibc-linux@ricardo.ecn.wfu.edu
mailing list for the glibc project.
struct sysinfo mem_unit field
- To: glibc-linux at ricardo dot ecn dot wfu dot edu
- Subject: struct sysinfo mem_unit field
- From: Pete Wyckoff <wyckoff at ca dot sandia dot gov>
- Date: Thu, 9 Mar 2000 11:44:41 -0800
- Reply-To: glibc-linux at ricardo dot ecn dot wfu dot edu
I'd like a nice way to get info on freeram, sharedram, etc. from
userspace. The sysinfo() system call fits the bill nicer than grepping
through /proc/meminfo, but it's changed recently, and I'm not sure if
the glibc interface should change as well.
Any kernel before 2.3.16 (incl 2.2 and earlier) has:
struct sysinfo {
long uptime; /* Seconds since boot */
unsigned long loads[3]; /* 1, 5, and 15 minute load averages */
unsigned long totalram; /* Total usable main memory size */
unsigned long freeram; /* Available memory size */
unsigned long sharedram; /* Amount of shared memory */
unsigned long bufferram; /* Memory used by buffers */
unsigned long totalswap; /* Total swap space size */
unsigned long freeswap; /* swap space still available */
unsigned short procs; /* Number of current processes */
char _f[22]; /* Pads structure to 64 bytes */
};
and units of memory items were bytes. A few fields were added/removed in
2.3.16 and .17, then the big change happened in 2.3.23 and is with us
today:
struct sysinfo {
long uptime; /* Seconds since boot */
unsigned long loads[3]; /* 1, 5, and 15 minute load averages */
unsigned long totalram; /* Total usable main memory size */
unsigned long freeram; /* Available memory size */
unsigned long sharedram; /* Amount of shared memory */
unsigned long bufferram; /* Memory used by buffers */
unsigned long totalswap; /* Total swap space size */
unsigned long freeswap; /* swap space still available */
unsigned short procs; /* Number of current processes */
unsigned long totalhigh; /* Total high memory size */
unsigned long freehigh; /* Available high memory size */
unsigned int mem_unit; /* Memory unit size in bytes */
char _f[20-2*sizeof(long)-sizeof(int)]; /* Padding: libc5 uses this.. */
};
Now the units returned are essentially pages, and userspace needs to scale
by mem_unit to get values in bytes. Seems nicer in the long run, but I'm
unsure how to deal with it today.
Should I figure out the kernel version in my app at compile time to
decide if I need to do this scaling? Should glibc be taking care of the
issue for me? I see nothing in glibc-2.1.3 using mem_unit, and nothing on
the bug/discussion lists. Thanks,
-- Pete