lkml.org 
[lkml]   [2009]   [Apr]   [3]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[RFC][PATCH 8/9] lru reordering
From: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>

This patch adds a function to change the LRU order of pages in global LRU
under control of memcg's victim of soft limit.

FILE and ANON victim is divided and LRU rotation will be done independently.
(memcg which only includes FILE cache or ANON can exists.)

This patch removes finds specfied number of pages from memcg's LRU and
move it to top of global LRU. They will be the first target of shrink_xxx_list.

Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
---
include/linux/memcontrol.h | 15 ++++++++++
mm/memcontrol.c | 67 +++++++++++++++++++++++++++++++++++++++++++++
mm/vmscan.c | 18 +++++++++++-
3 files changed, 99 insertions(+), 1 deletion(-)

Index: softlimit-test2/include/linux/memcontrol.h
===================================================================
--- softlimit-test2.orig/include/linux/memcontrol.h
+++ softlimit-test2/include/linux/memcontrol.h
@@ -117,6 +117,9 @@ static inline bool mem_cgroup_disabled(v

extern bool mem_cgroup_oom_called(struct task_struct *task);

+void mem_cgroup_soft_limit_reorder_lru(struct zone *zone,
+ unsigned long nr_to_scan, enum lru_list l);
+int mem_cgroup_soft_limit_inactive_anon_is_low(struct zone *zone);
#else /* CONFIG_CGROUP_MEM_RES_CTLR */
struct mem_cgroup;

@@ -264,6 +267,18 @@ mem_cgroup_print_oom_info(struct mem_cgr
{
}

+static inline void
+mem_cgroup_soft_limit_reorder_lru(struct zone *zone, unsigned long nr_to_scan,
+ enum lru_list lru);
+{
+}
+
+static inline
+int mem_cgroup_soft_limit_inactive_anon_is_low(struct zone *zone)
+{
+ return 0;
+}
+
#endif /* CONFIG_CGROUP_MEM_CONT */

#endif /* _LINUX_MEMCONTROL_H */
Index: softlimit-test2/mm/memcontrol.c
===================================================================
--- softlimit-test2.orig/mm/memcontrol.c
+++ softlimit-test2/mm/memcontrol.c
@@ -1257,6 +1257,73 @@ static struct mem_cgroup *get_soft_limit
return ret;
}

+/*
+ * zone->lru and memcg's lru is synchronous under zone->lock.
+ * This tries to rotate pages in specfied LRU.
+ */
+void mem_cgroup_soft_limit_reorder_lru(struct zone *zone,
+ unsigned long nr_to_scan,
+ enum lru_list l)
+{
+ struct mem_cgroup *mem;
+ struct mem_cgroup_per_zone *mz;
+ int nid, zid, file;
+ unsigned long scan, flags;
+ struct list_head *src;
+ LIST_HEAD(found);
+ struct page_cgroup *pc;
+ struct page *page;
+
+ nid = zone->zone_pgdat->node_id;
+ zid = zone_idx(zone);
+
+ file = is_file_lru(l);
+
+ mem = get_soft_limit_victim(zone, file);
+ if (!mem)
+ return;
+ mz = mem_cgroup_zoneinfo(mem, nid, zid);
+ src = &mz->lists[l];
+ scan = 0;
+
+ /* Find at most nr_to_scan pages from local LRU */
+ spin_lock_irqsave(&zone->lru_lock, flags);
+ list_for_each_entry_reverse(pc, src, lru) {
+ if (scan >= nr_to_scan)
+ break;
+ /* We don't check Used bit */
+ page = pc->page;
+ /* Can happen ? */
+ if (unlikely(!PageLRU(page)))
+ continue;
+ /* This page is on (the same) LRU */
+ list_move(&page->lru, &found);
+ scan++;
+ }
+ /* vmscan searches pages from lru->prev. link this to lru->prev. */
+ list_splice_tail(&found, &zone->lru[l].list);
+ spin_unlock_irqrestore(&zone->lru_lock, flags);
+
+ /* When we cannot fill the request, check we should forget this cache
+ or not */
+ if (scan < nr_to_scan &&
+ !is_active_lru(l) &&
+ mem_cgroup_usage(mem, zone, file) < SWAP_CLUSTER_MAX)
+ slc_reset_cache_ticket(file);
+}
+
+/* Returns 1 if soft limit is active && memcg's zone's status is that */
+int mem_cgroup_soft_limit_inactive_anon_is_low(struct zone *zone)
+{
+ struct soft_limit_cache *slc;
+ int ret = 0;
+
+ slc = &get_cpu_var(soft_limit_cache);
+ if (slc->mem[SL_ANON])
+ ret = mem_cgroup_inactive_anon_is_low(slc->mem[SL_ANON], zone);
+ put_cpu_var(soft_limit_cache);
+ return ret;
+}

static void softlimitq_init(void)
{
Index: softlimit-test2/mm/vmscan.c
===================================================================
--- softlimit-test2.orig/mm/vmscan.c
+++ softlimit-test2/mm/vmscan.c
@@ -1066,6 +1066,13 @@ static unsigned long shrink_inactive_lis
pagevec_init(&pvec, 1);

lru_add_drain();
+ if (scanning_global_lru(sc)) {
+ enum lru_list l = LRU_INACTIVE_ANON;
+ if (file)
+ l = LRU_INACTIVE_FILE;
+ mem_cgroup_soft_limit_reorder_lru(zone, max_scan, l);
+ }
+
spin_lock_irq(&zone->lru_lock);
do {
struct page *page;
@@ -1233,6 +1240,13 @@ static void shrink_active_list(unsigned
struct zone_reclaim_stat *reclaim_stat = get_reclaim_stat(zone, sc);

lru_add_drain();
+ if (scanning_global_lru(sc)) {
+ enum lru_list l = LRU_ACTIVE_ANON;
+ if (file)
+ l = LRU_ACTIVE_FILE;
+ mem_cgroup_soft_limit_reorder_lru(zone, nr_pages, l);
+ }
+
spin_lock_irq(&zone->lru_lock);
pgmoved = sc->isolate_pages(nr_pages, &l_hold, &pgscanned, sc->order,
ISOLATE_ACTIVE, zone,
@@ -1328,7 +1342,9 @@ static int inactive_anon_is_low_global(s

if (inactive * zone->inactive_ratio < active)
return 1;
-
+ /* check soft limit vicitm's status */
+ if (mem_cgroup_soft_limit_inactive_anon_is_low(zone))
+ return 1;
return 0;
}



\
 
 \ /
  Last update: 2009-04-03 10:21    [W:0.162 / U:0.120 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site