meminfo: add Cached underflow check
PATCH 1/1 meminfo: add Cached underflow check
Hi,
This patch was generated against 2.6.12-rc1
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.
proc_misc.c | 9 ++++++++- 1 files changed, 8 insertions(+), 1 deletion(-)
fs/proc/proc_misc.c +8 -1
@@ -126,6 +126,7 @@ static int meminfo_read_proc(char *page,unsigned long committed;unsigned long allowed;struct vmalloc_info vmi; +unsigned long cached;get_page_state (&ps);get_zone_counts (&active, &inactive, &free);
@@ -140,6 +141,12 @@ static int meminfo_read_proc(char *page, allowed = ((totalram_pages -hugetlb_total_pages ()) * sysctl_overcommit_ratio /100 ) + total_swap_pages; + cached =get_page_cache_size (); +if (total_swapcache_pages+i.bufferram < cached) + cached -= total_swapcache_pages + i.bufferram; +else + cached =0 ; +get_vmalloc_info (&vmi);/*
@@ -172,7 +179,7 @@ static int meminfo_read_proc(char *page,K (i.totalram),K (i.freeram),K (i.bufferram), -K (get_page_cache_size ()-total_swapcache_pages-i.bufferram), +K (cached),K (total_swapcache_pages),K (active), K(inactive),
Quoted 5 lines · Martin Hicks
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 ofget_page_cache_size()the value underflows.
OK..
I think I'd prefer to do it this way - it's simpler and the original patch had a teeny race wrt changes in total_swapcache_pages.
fs/proc/proc_misc.c renamed from fs/proc/proc_misc.c~meminfo-add-cached-underflow-check +6 -1
@@ -126,6 +126,7 @@ static int meminfo_read_proc(char *page,unsigned long committed;unsigned long allowed;struct vmalloc_info vmi; +long cached;get_page_state (&ps);get_zone_counts (&active, &inactive, &free);
@@ -140,6 +141,10 @@ static int meminfo_read_proc(char *page, allowed = ((totalram_pages -hugetlb_total_pages ()) * sysctl_overcommit_ratio /100 ) + total_swap_pages; + cached =get_page_cache_size () - total_swapcache_pages - i.bufferram; +if (cached <0 ) + cached =0 ; +get_vmalloc_info (&vmi);/*
@@ -172,7 +177,7 @@ static int meminfo_read_proc(char *page,K (i.totalram),K (i.freeram),K (i.bufferram), -K (get_page_cache_size ()-total_swapcache_pages-i.bufferram), +K (cached),K (total_swapcache_pages),K (active), K(inactive),
_
Quoted 11 lines · Andrew Morton
Quoted 5 lines · Martin Hicks
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 ofget_page_cache_size()the value underflows.OK..
I think I'd prefer to do it this way - it's simpler and the original patch had a teeny race wrt changes in
total_swapcache_pages.
Fine by me.
mh
Signature · 1 line
Martin Hicks || Silicon Graphics Inc. || [email protected]