aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2025-08-05 14:04:01 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2025-08-05 14:21:51 +0200
commitd16bde623ced3cf113648e0bb977c1befed6d601 (patch)
tree08f688dc57a6efbc9e82f6eaa7587849fee68f2c /include
parent58b2353baaebdfdfd166e0745aea0fe75d1a3d10 (diff)
downloadbusybox-w32-d16bde623ced3cf113648e0bb977c1befed6d601.tar.gz
busybox-w32-d16bde623ced3cf113648e0bb977c1befed6d601.tar.bz2
busybox-w32-d16bde623ced3cf113648e0bb977c1befed6d601.zip
top,pmap: do not use common code for reading /proc/PID/smaps
The logic is in fact quite far from common. While at it, stop accounting "---p" mappings as mapped (e.g. VSZ in top). Nothing is mapped there (why would kernel waste RAM to map pages which can't be accessed?). function old new delta read_smaps - 562 +562 read_cmdline 315 326 +11 print_smaprec 97 101 +4 procps_scan 1219 1211 -8 .rodata 115541 115533 -8 skip_whitespace_if_prefixed_with 25 - -25 procps_read_smaps 864 577 -287 ------------------------------------------------------------------------------ (add/remove: 1/1 grow/shrink: 2/3 up/down: 577/-328) Total: 249 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'include')
-rw-r--r--include/libbb.h41
1 files changed, 12 insertions, 29 deletions
diff --git a/include/libbb.h b/include/libbb.h
index 895200192..fba898943 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -2081,33 +2081,6 @@ enum { COMM_LEN = 16 };
2081# endif 2081# endif
2082#endif 2082#endif
2083 2083
2084struct smaprec {
2085 unsigned long mapped_rw;
2086 unsigned long mapped_ro;
2087 unsigned long shared_clean;
2088 unsigned long shared_dirty;
2089 unsigned long private_clean;
2090 unsigned long private_dirty;
2091 unsigned long stack;
2092 unsigned long smap_pss, smap_swap;
2093 unsigned long smap_size;
2094 // For mixed 32/64 userspace, 32-bit pmap still needs
2095 // 64-bit field here to correctly show 64-bit processes:
2096 unsigned long long smap_start;
2097 // (strictly speaking, other fields need to be wider too,
2098 // but they are in kbytes, not bytes, and they hold sizes,
2099 // not start addresses, sizes tend to be less than 4 terabytes)
2100 char smap_mode[5];
2101 char *smap_name;
2102};
2103
2104#if !ENABLE_PMAP
2105#define procps_read_smaps(pid, total, cb, data) \
2106 procps_read_smaps(pid, total)
2107#endif
2108int FAST_FUNC procps_read_smaps(pid_t pid, struct smaprec *total,
2109 void (*cb)(struct smaprec *, void *), void *data);
2110
2111typedef struct procps_status_t { 2084typedef struct procps_status_t {
2112 DIR *dir; 2085 DIR *dir;
2113 IF_FEATURE_SHOW_THREADS(DIR *task_dir;) 2086 IF_FEATURE_SHOW_THREADS(DIR *task_dir;)
@@ -2137,7 +2110,13 @@ typedef struct procps_status_t {
2137#endif 2110#endif
2138 unsigned tty_major,tty_minor; 2111 unsigned tty_major,tty_minor;
2139#if ENABLE_FEATURE_TOPMEM 2112#if ENABLE_FEATURE_TOPMEM
2140 struct smaprec smaps; 2113 unsigned long mapped_rw;
2114 unsigned long mapped_ro;
2115 unsigned long shared_clean;
2116 unsigned long shared_dirty;
2117 unsigned long private_clean;
2118 unsigned long private_dirty;
2119 unsigned long stack;
2141#endif 2120#endif
2142 char state[4]; 2121 char state[4];
2143 /* basename of executable in exec(2), read from /proc/N/stat 2122 /* basename of executable in exec(2), read from /proc/N/stat
@@ -2186,11 +2165,15 @@ void free_procps_scan(procps_status_t* sp) FAST_FUNC;
2186procps_status_t* procps_scan(procps_status_t* sp, int flags) FAST_FUNC; 2165procps_status_t* procps_scan(procps_status_t* sp, int flags) FAST_FUNC;
2187/* Format cmdline (up to col chars) into char buf[size] */ 2166/* Format cmdline (up to col chars) into char buf[size] */
2188/* Puts [comm] if cmdline is empty (-> process is a kernel thread) */ 2167/* Puts [comm] if cmdline is empty (-> process is a kernel thread) */
2189void read_cmdline(char *buf, int size, unsigned pid, const char *comm) FAST_FUNC; 2168int read_cmdline(char *buf, int size, unsigned pid, const char *comm) FAST_FUNC;
2190pid_t *find_pid_by_name(const char* procName) FAST_FUNC; 2169pid_t *find_pid_by_name(const char* procName) FAST_FUNC;
2191pid_t *pidlist_reverse(pid_t *pidList) FAST_FUNC; 2170pid_t *pidlist_reverse(pid_t *pidList) FAST_FUNC;
2192int starts_with_cpu(const char *str) FAST_FUNC; 2171int starts_with_cpu(const char *str) FAST_FUNC;
2193unsigned get_cpu_count(void) FAST_FUNC; 2172unsigned get_cpu_count(void) FAST_FUNC;
2173/* Some internals reused by pmap: */
2174unsigned long FAST_FUNC fast_strtoul_10(char **endptr);
2175unsigned long long FAST_FUNC fast_strtoull_16(char **endptr);
2176char* FAST_FUNC skip_fields(char *str, int count);
2194 2177
2195 2178
2196/* Use strict=1 if you process input from untrusted source: 2179/* Use strict=1 if you process input from untrusted source: