After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 129863 - wrong glibtop_mem.used and glibtop_mem.shared value
wrong glibtop_mem.used and glibtop_mem.shared value
Status: RESOLVED FIXED
Product: libgtop
Classification: Core
Component: linux
2.5.x
Other Linux
: Immediate blocker
: ---
Assigned To: libgtop maintainers
libgtop maintainers
: 129562 129721 134422 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2003-12-22 21:12 UTC by Benoît Dejean
Modified: 2004-12-22 21:47 UTC
See Also:
GNOME target: ---
GNOME version: 2.3/2.4


Attachments
Test Program Using shmget to allocate shared memory (699 bytes, text/plain)
2004-01-18 17:13 UTC, Steve Fosdick
Details
Test Program Using mmap of /dev/zero to allocate shared memory (963 bytes, text/plain)
2004-01-18 17:13 UTC, Steve Fosdick
Details
Comparison of /proc/mem before and after allocating 10M with shmget (855 bytes, text/plain)
2004-01-18 17:20 UTC, Steve Fosdick
Details
Comparison of /proc/mem before and after allocating 10M with mmap of /dev/zero (856 bytes, text/plain)
2004-01-18 17:21 UTC, Steve Fosdick
Details

Description Benoît Dejean 2003-12-22 21:12:09 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:");
Comment 1 Bastien Nocera 2003-12-23 01:31:25 UTC
Is that an actual bug Robert?
Comment 2 Benoît Dejean 2003-12-23 03:38:40 UTC
yes, gnome-system-monitor and gdesklets display wrong memory informations
Comment 3 Robert Love 2003-12-23 03:45:41 UTC
Yup, this is a real bug and this is the correct fix.
Comment 4 Bastien Nocera 2003-12-23 10:39:53 UTC
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)
Comment 5 Benoît Dejean 2004-01-13 22:12:55 UTC
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:");
Comment 6 Robert Love 2004-01-13 22:20:10 UTC
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?).
Comment 7 Benoît Dejean 2004-01-13 23:07:42 UTC
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
Comment 8 Robert Love 2004-01-13 23:13:36 UTC
Yah, OK.

Patch looks good to me, Hadess.
Comment 9 Bastien Nocera 2004-01-14 13:59:05 UTC
Benoit, please commit your changes.
Comment 10 Steve Fosdick 2004-01-18 17:13:04 UTC
Created attachment 23496 [details]
Test Program Using shmget to allocate shared memory
Comment 11 Steve Fosdick 2004-01-18 17:13:32 UTC
Created attachment 23497 [details]
Test Program Using mmap of /dev/zero to allocate shared memory
Comment 12 Steve Fosdick 2004-01-18 17:20:59 UTC
Created attachment 23498 [details]
Comparison of /proc/mem before and after allocating 10M with shmget
Comment 13 Steve Fosdick 2004-01-18 17:21:24 UTC
Created attachment 23499 [details]
Comparison of /proc/mem before and after allocating 10M with mmap of /dev/zero
Comment 14 Steve Fosdick 2004-01-18 17:23:58 UTC
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?
Comment 15 Benoît Dejean 2004-01-18 19:12:59 UTC
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.
Comment 16 Sebastien Bacher 2004-02-02 20:15:27 UTC
Fix commited in head and 2.4
Comment 17 Matthew Gatto 2004-02-16 00:08:25 UTC
*** Bug 134422 has been marked as a duplicate of this bug. ***
Comment 18 Marcin Zajaczkowski 2004-03-02 18:34:28 UTC
*** Bug 129562 has been marked as a duplicate of this bug. ***
Comment 19 Kjartan Maraas 2004-03-04 21:59:05 UTC
*** Bug 129721 has been marked as a duplicate of this bug. ***