This is the mail archive of the glibc-linux@ricardo.ecn.wfu.edu mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

struct sysinfo mem_unit field


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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]