diff options
author | Ron Yorston <rmy@pobox.com> | 2021-02-18 15:27:44 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2021-02-18 15:47:47 +0000 |
commit | 2b8770720868c750ad8609df4041337eb2c6cf71 (patch) | |
tree | 85aff1e2b748d0e75ee5dbe82bc574bb2a5a9c1b /procps/free.c | |
parent | 2d20b9d88c4fc91637babaafa4a60dd7943e03a7 (diff) | |
download | busybox-w32-2b8770720868c750ad8609df4041337eb2c6cf71.tar.gz busybox-w32-2b8770720868c750ad8609df4041337eb2c6cf71.tar.bz2 busybox-w32-2b8770720868c750ad8609df4041337eb2c6cf71.zip |
free: implement sysinfo(2) and enable free(1)
This is an experimental implementation of sysinfo(2)/free(1).
It uses the WIN32 API GlobalMemoryStatusEx() to obtain information
about memory.
It seems that the 'total pagefile' value includes total RAM as well
as pagefile and 'available pagefile' includes available RAM. So the
RAM values are deducted.
I've no idea what corresponds to Linux buffers and cache.
Diffstat (limited to 'procps/free.c')
-rw-r--r-- | procps/free.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/procps/free.c b/procps/free.c index 0adef501f..142786083 100644 --- a/procps/free.c +++ b/procps/free.c | |||
@@ -52,6 +52,7 @@ static unsigned long long scale(struct globals *g, unsigned long d) | |||
52 | return ((unsigned long long)d * g->mem_unit) >> G_unit_steps; | 52 | return ((unsigned long long)d * g->mem_unit) >> G_unit_steps; |
53 | } | 53 | } |
54 | 54 | ||
55 | #if !ENABLE_PLATFORM_MINGW32 | ||
55 | /* NOINLINE reduces main() stack usage, which makes code smaller (on x86 at least) */ | 56 | /* NOINLINE reduces main() stack usage, which makes code smaller (on x86 at least) */ |
56 | static NOINLINE unsigned int parse_meminfo(struct globals *g) | 57 | static NOINLINE unsigned int parse_meminfo(struct globals *g) |
57 | { | 58 | { |
@@ -78,6 +79,14 @@ static NOINLINE unsigned int parse_meminfo(struct globals *g) | |||
78 | 79 | ||
79 | return seen_cached_and_available_and_reclaimable == 0; | 80 | return seen_cached_and_available_and_reclaimable == 0; |
80 | } | 81 | } |
82 | #else | ||
83 | static NOINLINE unsigned int parse_meminfo(struct globals *g) | ||
84 | { | ||
85 | g->cached_kb = g->available_kb = g->reclaimable_kb = 0; | ||
86 | |||
87 | return 1; | ||
88 | } | ||
89 | #endif | ||
81 | 90 | ||
82 | int free_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 91 | int free_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
83 | int free_main(int argc UNUSED_PARAM, char **argv IF_NOT_DESKTOP(UNUSED_PARAM)) | 92 | int free_main(int argc UNUSED_PARAM, char **argv IF_NOT_DESKTOP(UNUSED_PARAM)) |
@@ -135,9 +144,15 @@ int free_main(int argc UNUSED_PARAM, char **argv IF_NOT_DESKTOP(UNUSED_PARAM)) | |||
135 | } | 144 | } |
136 | #endif | 145 | #endif |
137 | 146 | ||
147 | #if !ENABLE_PLATFORM_MINGW32 | ||
138 | #define FIELDS_6 "%12llu %11llu %11llu %11llu %11llu %11llu\n" | 148 | #define FIELDS_6 "%12llu %11llu %11llu %11llu %11llu %11llu\n" |
139 | #define FIELDS_3 (FIELDS_6 + 6 + 7 + 7) | 149 | #define FIELDS_3 (FIELDS_6 + 6 + 7 + 7) |
140 | #define FIELDS_2 (FIELDS_6 + 6 + 7 + 7 + 7) | 150 | #define FIELDS_2 (FIELDS_6 + 6 + 7 + 7 + 7) |
151 | #else | ||
152 | #define FIELDS_6 "%12I64u %11I64u %11I64u %11I64u %11I64u %11I64u\n" | ||
153 | #define FIELDS_3 (FIELDS_6 + 7 + 8 + 8) | ||
154 | #define FIELDS_2 (FIELDS_6 + 8 + 8 + 8 + 8) | ||
155 | #endif | ||
141 | 156 | ||
142 | printf(FIELDS_6, | 157 | printf(FIELDS_6, |
143 | scale(&G, info.totalram), //total | 158 | scale(&G, info.totalram), //total |