GNOME Bugzilla – Bug 129863
wrong glibtop_mem.used and glibtop_mem.shared value
Last modified: 2004-12-22 21:47:04 UTC
memused is not Active from /proc/meminfo used = total - free; --- libgtop/sysdeps/linux/mem.c 2003-10-20 22:41:16.000000000 +0200 +++ libgtop.ben/sysdeps/linux/mem.c 2003-12-22 22:04:57.000000000 +0100 @@ -66,8 +66,8 @@ buffer [len] = '\0'; buf->total = get_scaled(buffer, "MemTotal:"); - buf->used = get_scaled(buffer, "Active:"); buf->free = get_scaled(buffer, "MemFree:"); + buf->used = buf->total - buf->free; buf->shared = get_scaled(buffer, "Mapped:"); buf->buffer = get_scaled(buffer, "Buffers:"); buf->cached = get_scaled(buffer, "Cached:");
Is that an actual bug Robert?
yes, gnome-system-monitor and gdesklets display wrong memory informations
Yup, this is a real bug and this is the correct fix.
Fixed in gnome-2-4 and HEAD. 2003-12-23 Bastien Nocera <hadess@hadess.net> * mem.c: (glibtop_get_mem_s): Fix calculation of used memory, patch by Benoît Dejean, <bnet@ifrance.com> (Closes: #129863)
glibtop_mem.shared value is wrong because of this buf->shared = get_scaled(buffer, "Mapped:"); on my computer /proc/meminfo::Mapped is 260288 kB but free and top show that shared memory is 0. /proc/meminfo::Mapped is not available on linux2.4 linux2.6 __and__ linux2.4 -> wrong value linux/fs/proc/meminfo_read_proc linux/include/kernel.h struct sysinfo still has a "unsigned long sharedram;" memberin linux2.6 linux2.6.x/mm/page_alloc.c:si_meminfo doesn't initialize it linux2.4/arch/<arch>/mm/init.c:si_meminfo sets it to 0 the fix is trivial --- libgtop/sysdeps/linux/mem.c 2004-01-13 23:10:26.000000000 +0100 +++ ben/libgtop/mem.c 2004-01-13 23:10:54.000000000 +0100 @@ -68,7 +68,7 @@ buf->total = get_scaled(buffer, "MemTotal:"); buf->free = get_scaled(buffer, "MemFree:"); buf->used = buf->total - buf->free; - buf->shared = get_scaled(buffer, "Mapped:"); + buf->shared = 0; buf->buffer = get_scaled(buffer, "Buffers:"); buf->cached = get_scaled(buffer, "Cached:");
This is more like a separate bug than a continuation of this existing one... but the fix is correct (at least for 2.6 -- why not read Shared on 2.4?).
this is not a seperate bug because the one who rewrote this in order ton deal with 2.6.x kernel made several mistakes. i renamed the bug it appears that even on 2.4.x the MemShared value is always 0 linux-2.4.24/arch/i386/mm/init.c void si_meminfo(struct sysinfo *val) { val->totalram = totalram_pages; val->sharedram = 0; val->freeram = nr_free_pages(); val->bufferram = atomic_read(&buffermem_pages); val->totalhigh = totalhigh_pages; val->freehigh = nr_free_highpages(); val->mem_unit = PAGE_SIZE; return; } -> on every arch -> grep -r "val->sharedram" /usr/src/linux-2.4.24 /usr/src/linux-2.4.24/arch/sh/mm/init.c: val->sharedram = 0; /usr/src/linux-2.4.24/arch/arm/mm/init.c: val->sharedram = 0; /usr/src/linux-2.4.24/arch/ppc/mm/init.c: val->sharedram = 0; /usr/src/linux-2.4.24/arch/i386/mm/init.c: val->sharedram = 0; /usr/src/linux-2.4.24/arch/cris/mm/init.c: * val->sharedram will stay 0 /usr/src/linux-2.4.24/arch/cris/mm/init.c: val->sharedram = 0; /usr/src/linux-2.4.24/arch/ia64/mm/init.c: val->sharedram = 0; /usr/src/linux-2.4.24/arch/m68k/mm/init.c: val->sharedram = 0; /usr/src/linux-2.4.24/arch/mips/mm/init.c: val->sharedram = 0; /usr/src/linux-2.4.24/arch/s390/mm/init.c: val->sharedram = 0; /usr/src/linux-2.4.24/arch/sh64/mm/init.c: val->sharedram = 0; /usr/src/linux-2.4.24/arch/alpha/mm/init.c: val->sharedram = 0; /usr/src/linux-2.4.24/arch/s390x/mm/init.c: val->sharedram = 0; /usr/src/linux-2.4.24/arch/ppc64/mm/init.c: val->sharedram = 0; /usr/src/linux-2.4.24/arch/sparc/mm/init.c: val->sharedram = 0; /usr/src/linux-2.4.24/arch/sparc64/mm/init.c: val->sharedram = 0; /usr/src/linux-2.4.24/arch/mips64/mm/init.c: val->sharedram = 0; /usr/src/linux-2.4.24/arch/parisc/mm/init.c: val->sharedram = 0; /usr/src/linux-2.4.24/arch/x86_64/mm/init.c: val->sharedram = 0; so the fix is correct for 2.6.x __and__ 2.4.x
Yah, OK. Patch looks good to me, Hadess.
Benoit, please commit your changes.
Created attachment 23496 [details] Test Program Using shmget to allocate shared memory
Created attachment 23497 [details] Test Program Using mmap of /dev/zero to allocate shared memory
Created attachment 23498 [details] Comparison of /proc/mem before and after allocating 10M with shmget
Created attachment 23499 [details] Comparison of /proc/mem before and after allocating 10M with mmap of /dev/zero
It is not so much that the amount of shared memory is actually zero, more that Linux does not provide any info on the amount for shared memory and using zero means at least the other values add up in a sensible way. I tried a couple of tests to see if any of the values in /proc/meminfo appear to change when shared memory is allocated and I attach both programs. The first program allocates shared memory using shmget, the second one by using mmap with /dev/zero. In both cases the only value that changed significantly in /proc/meminfo was Committed_AS which grew by aproximately the 10M I was testing with each time. Does anyone know what Committed_AS is?
2.4.x kernel sets val->sharedram = 0; but 2.6.x doesn't initialize it, it seems that this member is obsolete, or may be value of total shared memory cannot be retrieve efficiently (or is not interesting) with 1G on my 2.6.1 Committed_AS: 643404 kB so clearly it is not what we are looking for see /usr/src/linux/Documentation/filesystems/proc.txt for the moment, we need to set shared memmory to 0.
Fix commited in head and 2.4
*** Bug 134422 has been marked as a duplicate of this bug. ***
*** Bug 129562 has been marked as a duplicate of this bug. ***
*** Bug 129721 has been marked as a duplicate of this bug. ***