[Toybox] [PATCH] top: don't report GiB sizes in KiB.

Rob Landley rob at landley.net
Thu Sep 3 23:14:26 PDT 2020


On 9/3/20 9:56 AM, enh wrote:
> I think hard-coded MiB would be fine for me right now,

I'm worried that on embedded systems that _don't_ have gigs of memory, kilobytes
may be the desired units, so auto-adjusting makes sense. (If you have 16 megs
ram you care about a 300k fluctuation which you can't even SEE if the units are
megabytes.)

> but -- re-reading the
> full discussion from last time rather than relying on my memory -- it seems like
> your main complaint the first time I tried to fix this was that you didn't like
> the possibility of not using the same unit for every value.

I don't, but it's a lesser of two evils kind of thing.

> So hard-coding MiB
> might be better in that it would be more likely to stick rather than getting
> reverted. 

Given that I'd be the one doing the reverting and I'm suggesting this solution... :)

Ok, human_readable_long() is more or less only used directly by ps.c. (The other
2 files are demo_number.c and lib/lib.c wrapping it in human_readable()
providing defaults for the micromanagement fields.) So instead of detecting
"units" from 0 I can feed it a minimum units (k=1, M=2, and so on). So I can
have the ps.c check the total size field and if it's 10 gig or larger force
megabytes, and otherwise do kilobytes. (It's gotta be at least kilobytes because
the granularity of the input is kilobytes anyway...)

I pushed a change. On my laptop it now looks like:

  Mem:   15,955M total,   15,426M used,      528M free,      151M buffers
 Swap:   16,286M total,      523M used,   15,763M free,     1594M cached

Even though the top in debian is still doing:

KiB Mem : 16337976 total,   524876 free, 13746900 used,  2066200 buff/cache
KiB Swap: 16677884 total, 16141660 free,   536224 used.  1502312 avail Mem

Which is why my output ooked like it did before. Sigh. I have NO idea why they
renamed "cached" to "avail mem", it isn't unless you wanna fight the balance
logic or echo 3 > /proc/sys/vm/drop_caches

> Want me to send that patch?

I have a tropism for "what we're doing makes logical sense" vs just "tweak to
fix the problem I hit". I tend to want a _systemic_ fix, which is inconvenient
at times. :)

Rob


More information about the Toybox mailing list