[PATCH v2] top: fix and merge code to parse /proc/meminfo

Timo Teras timo.teras at iki.fi
Mon Jul 28 14:21:24 UTC 2014


On Sun, 27 Jul 2014 21:50:28 +0200
Denys Vlasenko <vda.linux at googlemail.com> wrote:

> On Mon, Jul 21, 2014 at 1:14 PM, Timo Teräs <timo.teras at iki.fi> wrote:
> > display_header() code to parse meminfo as is was buggy:
> > - uninitialized variables were used if meminfo was not as expected
> > - meminfo parsing failed on new kernels (3.14+) as new field
> > 'MemAvailable' was introduced between MemFree and Buffers
> > - shared memory was handled only for ancient kernels (2.4.x and
> > earlier)
> >
> > as result Buffers and shared memory fields were shown with bogus
> > values on current kernels.
> >
> > The new code does not try to parse the old style summary header, as
> > the separated fields are always present (it saves code size).
> > Additionally, both Shmem (2.6+) and MemShared (2.4 and earlier)
> > fields are now parsed and summed for shared memory usage; as only
> > one of them exists depending on kernel version.
> >
> > display_topmem_header() parses also meminfo so this makes it use the
> > same code for code shrink.
> 
> Applied, thanks!

Thanks, though I noticed now a weirdness that did not happen before.

+static void parse_meminfo(unsigned long meminfo[MI_MAX])
+{
...
+	memset(meminfo, 0, sizeof(meminfo));

Seems to not work. The sizeof() return something small. Probably
sizeof(unsigned long*).

Is my compiler broken, or is the expected behaviour?


More information about the busybox mailing list