[PATCH] Drop VFS cache when there is not enough free memory to allocate

From: Aubrey . Li
Date: Wed Nov 22 2006 - 02:10:18 EST


Signed-off-by: Aubrey.Li <aubrey.li@xxxxxxxxxx>
---
mm/page_alloc.c | 5 +++++
1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index bf2f6cf..62559fd 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -1039,6 +1039,11 @@ restart:
if (page)
goto got_pg;

+#if defined(CONFIG_EMBEDDED) && !defined(CONFIG_MMU)
+ drop_pagecache();
+ drop_slab();
+#endif
+
/* This allocation should allow future memory freeing. */

if (((p->flags & PF_MEMALLOC) || unlikely(test_thread_flag(TIF_MEMDIE)))
--
1.4.2
========================================

The patch drop the page cache and slab and then give a new chance to
get more free pages. Applied this patch, my test application can
allocate memory sucessfully and drop the cache and slab as well. See
below:
================================
root:/mnt> ./t
Alloc 8 MB !
alloc successful
root:/mnt> cat /proc/meminfo
MemTotal: 54196 kB
MemFree: 43684 kB
Buffers: 36 kB
Cached: 440 kB
SwapCached: 0 kB
Active: 32 kB
Inactive: 432 kB
HighTotal: 0 kB
HighFree: 0 kB
LowTotal: 54196 kB
LowFree: 43684 kB
SwapTotal: 0 kB
SwapFree: 0 kB
Dirty: 8 kB
Writeback: 0 kB
AnonPages: 0 kB
Mapped: 0 kB
Slab: 9812 kB
PageTables: 0 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
CommitLimit: 27096 kB
Committed_AS: 0 kB
VmallocTotal: 0 kB
VmallocUsed: 0 kB
VmallocChunk: 0 kB
=============================

I know performance is important for linux, and VFS cache obviously
improve the performance when implement file operation. But for
embedded system, we'll try our best to make the application executable
rather than hanging system to guarantee the system performance.

Any suggestions and solutions are really appreciated!

Thanks,
-Aubrey

------=_Part_67747_12127413.1164181866877
Content-Type: text/plain; name="0001-Drop-VFS-cache-when-there-is-not-enough-free-memory-to-allocate.txt"
Content-Transfer-Encoding: base64
Content-Dis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NQUxMT0MpIHx8
IHVubGlrZWx5KHRlc3RfdGhyZWFkX2ZsYWcoVElGX01FTURJRSkpKQotLSAKMS40LjIKCg==
------=_Part_67747_12127413.1164181866877--
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/