From 6a948bc8ac0d7b3c4bf1a46838fb3786ecffbd93 Mon Sep 17 00:00:00 2001 From: Andrew Morton Date: Wed, 23 Jun 2004 18:55:44 -0700 Subject: [PATCH] nr_pagecache can go negative We use per-cpu counters for the system-wide pagecache accounting. The counters spill into the global nr_pagecache atomic_t when they underflow or overflow. Hence it is possible, under weird circumstances, for nr_pagecache to go negative. Anton says he has hit this. Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- include/linux/pagemap.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'include/linux') diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 427b696f484b..4da205f3cb26 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -136,7 +137,10 @@ static inline void pagecache_acct(int count) static inline unsigned long get_page_cache_size(void) { - return atomic_read(&nr_pagecache); + int ret = atomic_read(&nr_pagecache); + if (unlikely(ret < 0)) + ret = 0; + return ret; } static inline pgoff_t linear_page_index(struct vm_area_struct *vma, -- cgit v1.2.3