[linux-mm-cc] [PATCH 06/12] avoid OOM : link chunk_heads' in lrus'

IKEDA Munehiro m-ikeda at ds.jp.nec.com
Mon Jul 23 06:07:45 EDT 2007


Define LRUs for fs_backed and anon chunk_heads'.
chunk_heads' are linked in either corresponging LRU
so that we can select the oldest fs_backed chunk_head
and free it.

Signed-off-by: IKEDA, Munehiro <m-ikeda at ds.jp.nec.com>
---
 mm/ccache.c |   16 ++++++++++++----
 1 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/mm/ccache.c b/mm/ccache.c
index a3f591b..5ee1c3e 100644
--- a/mm/ccache.c
+++ b/mm/ccache.c
@@ -20,7 +20,7 @@ unsigned long max_anon_cc_size = 0, max_fs_backed_cc_size = 0;
 static atomic_t anon_cc_size, fs_backed_cc_size;	/* current sizes */
 const unsigned long ccache_size_limit = MAX_SWAP_OFFSET - 1;
 
-static struct list_head pages_head, mcl_head, lru_head;
+static struct list_head pages_head, mcl_head, lru_anon, lru_fs_backed;
 static struct chunk *free_head = NULL;
 
 /* show ccache stats via /proc/ccache_stats */
@@ -441,7 +441,6 @@ static int init_ccache(void)
 	if (anon_cc_started || fs_backed_cc_started) return 0;
 
 	INIT_LIST_HEAD(&pages_head);
-	INIT_LIST_HEAD(&lru_head);
 	INIT_LIST_HEAD(&mcl_head);
 	free_head = NULL;
 
@@ -475,6 +474,7 @@ static int init_anon_ccache(unsigned long num)
 	if (anon_cc_started)
 		return 0;
 
+	INIT_LIST_HEAD(&lru_anon);
 	init_ccache();
 	return init_virt_swap(num);
 }
@@ -484,6 +484,7 @@ static int init_fs_backed_ccache(unsigned long num)
 	if (fs_backed_cc_started)
 		return 0;
 
+	INIT_LIST_HEAD(&lru_fs_backed);
 	init_ccache();
 	return 0;
 }
@@ -641,11 +642,10 @@ static struct page *cc_readpage(struct chunk_head *ch)
 	}
 
 	chunk = ch->chunk_list;
-#if 0
+
 	spin_lock(&ccache_lock);
 	list_del_init(&ch->lru);
 	spin_unlock(&ccache_lock);
-#endif
 
 	while (chunk) {
 		memcpy(comp_data, chunk->start_addr, ChunkSize(chunk));
@@ -811,6 +811,14 @@ int cc_writepage(struct page *page)
 	CC_DEBUG2("after put_page, before unlock page");
 
 	unlock_page(page);	/* page unlocked only when success */
+
+	spin_lock(&ccache_lock);
+	if (PageSwapCache(ch))
+		list_add(&ch->lru, &lru_anon);
+	else
+		list_add(&ch->lru, &lru_fs_backed);
+	spin_unlock(&ccache_lock);
+
 	CC_DEBUG("success");
 	return 0;
 out_locked:
-- 
1.4.4.4



More information about the linux-mm-cc mailing list