diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2020-11-27 12:40:31 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2020-11-27 12:40:31 +0100 |
commit | fc63549352c371617e68fcf7ecbe4978fa207c6a (patch) | |
tree | 559dd67966454b50af62eb54f3d728d4ad49460f /procps | |
parent | 20900489a1fff2a563999d90e24239206f202b21 (diff) | |
download | busybox-fc63549352c371617e68fcf7ecbe4978fa207c6a.tar.gz |
free: code shrink
function old new delta
free_main 664 657 -7
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'procps')
-rw-r--r-- | procps/free.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/procps/free.c b/procps/free.c index b33506b9e..0adef501f 100644 --- a/procps/free.c +++ b/procps/free.c @@ -97,10 +97,10 @@ int free_main(int argc UNUSED_PARAM, char **argv IF_NOT_DESKTOP(UNUSED_PARAM)) case 'k': /* 2^10 */ /* G.unit_steps = 10; - already is */ break; - case 'm': /* 2^(2*10) */ + case 'm': /* 2^20 */ G.unit_steps = 20; break; - case 'g': /* 2^(3*10) */ + case 'g': /* 2^30 */ G.unit_steps = 30; break; default: @@ -117,16 +117,24 @@ int free_main(int argc UNUSED_PARAM, char **argv IF_NOT_DESKTOP(UNUSED_PARAM)) ); sysinfo(&info); - /* Kernels prior to 2.4.x will return info.mem_unit==0, so cope... */ - G.mem_unit = (info.mem_unit ? info.mem_unit : 1); /* Extract cached and memavailable from /proc/meminfo and convert to mem_units */ seen_available = parse_meminfo(&G); + G.mem_unit = (info.mem_unit ? info.mem_unit : 1); /* kernels < 2.4.x return mem_unit==0, so cope */ available = ((unsigned long long) G.available_kb * 1024) / G.mem_unit; cached = ((unsigned long long) G.cached_kb * 1024) / G.mem_unit; cached += info.bufferram; cached += ((unsigned long long) G.reclaimable_kb * 1024) / G.mem_unit; cached_plus_free = cached + info.freeram; +/* In case (long long * G.mem_unit) can overflow, this can be used to reduce the chances */ +#if 0 //ENABLE_DESKTOP + while (!(G.mem_unit & 1) && G.unit_steps != 0) { + G.mem_unit >>= 1; + G.unit_steps--; + //bb_error_msg("mem_unit:%d unit_steps:%d", G.mem_unit, G.unit_steps); + } +#endif + #define FIELDS_6 "%12llu %11llu %11llu %11llu %11llu %11llu\n" #define FIELDS_3 (FIELDS_6 + 6 + 7 + 7) #define FIELDS_2 (FIELDS_6 + 6 + 7 + 7 + 7) |