struct sysinfo mem_unit field

From: Pete Wyckoff (wyckoff@ca.sandia.gov)
Date: Tue Mar 07 2000 - 18:19:43 EST


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 I'm scared away by how much it's been
changing across different kernel versions. Anything 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 userspace 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 gnats list. Thanks,

                -- Pete

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Tue Mar 07 2000 - 21:00:24 EST