Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[PATCH] meminfo: add Cached underflow check

Working on some code lately I've been getting huge values for "Cached".
The cause is that get_page_cache_size() is an approximate value, and for a
sufficiently small returned value of get_page_cache_size() the value
underflows.

Signed-off-by: Martin Hicks <mort@sgi.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

authored by

Martin Hicks and committed by
Linus Torvalds
4c4c402d 76c3073a

+6 -1
+6 -1
fs/proc/proc_misc.c
··· 126 126 unsigned long committed; 127 127 unsigned long allowed; 128 128 struct vmalloc_info vmi; 129 + long cached; 129 130 130 131 get_page_state(&ps); 131 132 get_zone_counts(&active, &inactive, &free); ··· 140 139 committed = atomic_read(&vm_committed_space); 141 140 allowed = ((totalram_pages - hugetlb_total_pages()) 142 141 * sysctl_overcommit_ratio / 100) + total_swap_pages; 142 + 143 + cached = get_page_cache_size() - total_swapcache_pages - i.bufferram; 144 + if (cached < 0) 145 + cached = 0; 143 146 144 147 get_vmalloc_info(&vmi); 145 148 ··· 177 172 K(i.totalram), 178 173 K(i.freeram), 179 174 K(i.bufferram), 180 - K(get_page_cache_size()-total_swapcache_pages-i.bufferram), 175 + K(cached), 181 176 K(total_swapcache_pages), 182 177 K(active), 183 178 K(inactive),