linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] meminfo: add Cached underflow check
@ 2005-04-04 15:11 Martin Hicks
  2005-04-04 22:10 ` Andrew Morton
  0 siblings, 1 reply; 3+ messages in thread
From: Martin Hicks @ 2005-04-04 15:11 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel


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.

Signed-off-by:  Martin Hicks <mort@sgi.com>

 proc_misc.c |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletion(-)

Index: linux-2.6.11.cached-limit/fs/proc/proc_misc.c
===================================================================
--- linux-2.6.11.cached-limit.orig/fs/proc/proc_misc.c	2005-03-31 11:36:46.000000000 -0800
+++ linux-2.6.11.cached-limit/fs/proc/proc_misc.c	2005-03-31 11:37:12.000000000 -0800
@@ -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),

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] meminfo: add Cached underflow check
  2005-04-04 15:11 [PATCH] meminfo: add Cached underflow check Martin Hicks
@ 2005-04-04 22:10 ` Andrew Morton
  2005-04-04 22:41   ` Martin Hicks
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Morton @ 2005-04-04 22:10 UTC (permalink / raw)
  To: Martin Hicks; +Cc: linux-kernel

Martin Hicks <mort@sgi.com> wrote:
>
> 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.

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.


diff -puN fs/proc/proc_misc.c~meminfo-add-cached-underflow-check fs/proc/proc_misc.c
--- 25/fs/proc/proc_misc.c~meminfo-add-cached-underflow-check	Mon Apr  4 15:06:38 2005
+++ 25-akpm/fs/proc/proc_misc.c	Mon Apr  4 15:10:24 2005
@@ -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),
_


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] meminfo: add Cached underflow check
  2005-04-04 22:10 ` Andrew Morton
@ 2005-04-04 22:41   ` Martin Hicks
  0 siblings, 0 replies; 3+ messages in thread
From: Martin Hicks @ 2005-04-04 22:41 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Martin Hicks, linux-kernel


On Mon, Apr 04, 2005 at 03:10:49PM -0700, Andrew Morton wrote:
> Martin Hicks <mort@sgi.com> wrote:
> >
> > 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.
> 
> 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

-- 
Martin Hicks   ||   Silicon Graphics Inc.   ||   mort@sgi.com

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2005-04-04 22:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-04-04 15:11 [PATCH] meminfo: add Cached underflow check Martin Hicks
2005-04-04 22:10 ` Andrew Morton
2005-04-04 22:41   ` Martin Hicks

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).