From: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
To: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: kosaki.motohiro@jp.fujitsu.com,
Lee Schermerhorn <Lee.Schermerhorn@hp.com>,
Rik van Riel <riel@redhat.com>,
balbir@linux.vnet.ibm.com, linux-kernel@vger.kernel.org,
Andrew Morton <akpm@linux-foundation.org>
Subject: [RFC PATCH] No Reclaim LRU Infrastructure enhancement for memcgroup
Date: Wed, 28 May 2008 20:04:38 +0900 [thread overview]
Message-ID: <20080528155809.9CD0.KOSAKI.MOTOHIRO@jp.fujitsu.com> (raw)
In-Reply-To: <20080528101229.f14e0f09.kamezawa.hiroyu@jp.fujitsu.com>
[-- Attachment #1: Type: text/plain, Size: 871 bytes --]
Hi
> In my understanding, 2 checks we have to do.
>
> 1. When memcg finds PG_noreclaim page in its LRU, move it to noreclaim list of
> memcg.
> 2. When PG_noreclaim page is moved back to generic LRU, memcg should move
> it on its list. (we have to add a hook somewhere.)
>
> But this may break current 'loose' synchronization between global LRU and
> memcg's LRU. When PG_noreclaim page is put back into active/inactive LRU ?
>
> concerns are
> A. how to implement '2'
I tried to implement it today.
this patch is made against "[PATCH -mm 13/16] No Reclaim LRU Infrastructure"
> B. race condtions.
don't worry :)
it isn't big problem.
global lru is reclaimbale and memcg lru is noreclaimable
-> we can repair at move lru of shrink_[in]active_page().
global lru is noreclaimbale and memcg lru is reclaimable
-> we can repair mem_cgroup_isolate_pages()
[-- Attachment #2: rvr-13.2-kosaki-memcg-noreclaim.patch --]
[-- Type: application/octet-stream, Size: 7316 bytes --]
When memco lru moved, mem_cgroup_move_lists() is called.
thus, I add noreclaim lru logic at that point.
Signed-off-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
---
include/linux/memcontrol.h | 2 -
mm/memcontrol.c | 73 +++++++++++++++++++++++++++------------------
mm/swap.c | 2 -
mm/vmscan.c | 10 ++++--
4 files changed, 54 insertions(+), 33 deletions(-)
Index: b/mm/memcontrol.c
===================================================================
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -161,9 +161,10 @@ struct page_cgroup {
int ref_cnt; /* cached, mapped, migrating */
int flags;
};
-#define PAGE_CGROUP_FLAG_CACHE (0x1) /* charged as cache */
-#define PAGE_CGROUP_FLAG_ACTIVE (0x2) /* page is active in this cgroup */
-#define PAGE_CGROUP_FLAG_FILE (0x4) /* page is file system backed */
+#define PAGE_CGROUP_FLAG_CACHE (0x1) /* charged as cache */
+#define PAGE_CGROUP_FLAG_ACTIVE (0x2) /* page is active in this cgroup */
+#define PAGE_CGROUP_FLAG_FILE (0x4) /* page is file system backed */
+#define PAGE_CGROUP_FLAG_NORECLAIM (0x8) /* page is noreclaimable page */
static int page_cgroup_nid(struct page_cgroup *pc)
{
@@ -283,10 +284,14 @@ static void __mem_cgroup_remove_list(str
{
int lru = LRU_BASE;
- if (pc->flags & PAGE_CGROUP_FLAG_ACTIVE)
- lru += LRU_ACTIVE;
- if (pc->flags & PAGE_CGROUP_FLAG_FILE)
- lru += LRU_FILE;
+ if (pc->flags & PAGE_CGROUP_FLAG_NORECLAIM)
+ lru = LRU_NORECLAIM;
+ else {
+ if (pc->flags & PAGE_CGROUP_FLAG_ACTIVE)
+ lru += LRU_ACTIVE;
+ if (pc->flags & PAGE_CGROUP_FLAG_FILE)
+ lru += LRU_FILE;
+ }
MEM_CGROUP_ZSTAT(mz, lru) -= 1;
@@ -299,10 +304,14 @@ static void __mem_cgroup_add_list(struct
{
int lru = LRU_BASE;
- if (pc->flags & PAGE_CGROUP_FLAG_ACTIVE)
- lru += LRU_ACTIVE;
- if (pc->flags & PAGE_CGROUP_FLAG_FILE)
- lru += LRU_FILE;
+ if (pc->flags & PAGE_CGROUP_FLAG_NORECLAIM)
+ lru = LRU_NORECLAIM;
+ else {
+ if (pc->flags & PAGE_CGROUP_FLAG_ACTIVE)
+ lru += LRU_ACTIVE;
+ if (pc->flags & PAGE_CGROUP_FLAG_FILE)
+ lru += LRU_FILE;
+ }
MEM_CGROUP_ZSTAT(mz, lru) += 1;
list_add(&pc->lru, &mz->lists[lru]);
@@ -310,21 +319,31 @@ static void __mem_cgroup_add_list(struct
mem_cgroup_charge_statistics(pc->mem_cgroup, pc->flags, true);
}
-static void __mem_cgroup_move_lists(struct page_cgroup *pc, bool active)
+static void __mem_cgroup_move_lists(struct page_cgroup *pc, enum lru_list lru)
{
struct mem_cgroup_per_zone *mz = page_cgroup_zoneinfo(pc);
- int from = pc->flags & PAGE_CGROUP_FLAG_ACTIVE;
- int file = pc->flags & PAGE_CGROUP_FLAG_FILE;
- int lru = LRU_FILE * !!file + !!from;
+ int active = pc->flags & PAGE_CGROUP_FLAG_ACTIVE;
+ int file = pc->flags & PAGE_CGROUP_FLAG_FILE;
+ int noreclaim = pc->flags & PAGE_CGROUP_FLAG_NORECLAIM;
+ enum lru_list from = noreclaim ? LRU_NORECLAIM :
+ (LRU_FILE * !!file + !!active);
- MEM_CGROUP_ZSTAT(mz, lru) -= 1;
+ if (lru == from)
+ return;
- if (active)
- pc->flags |= PAGE_CGROUP_FLAG_ACTIVE;
- else
+ MEM_CGROUP_ZSTAT(mz, from) -= 1;
+
+ if (is_noreclaim_lru(lru)) {
pc->flags &= ~PAGE_CGROUP_FLAG_ACTIVE;
+ pc->flags |= PAGE_CGROUP_FLAG_NORECLAIM;
+ } else {
+ if (is_active_lru(lru))
+ pc->flags |= PAGE_CGROUP_FLAG_ACTIVE;
+ else
+ pc->flags &= ~PAGE_CGROUP_FLAG_ACTIVE;
+ pc->flags &= ~PAGE_CGROUP_FLAG_NORECLAIM;
+ }
- lru = LRU_FILE * !!file + !!active;
MEM_CGROUP_ZSTAT(mz, lru) += 1;
list_move(&pc->lru, &mz->lists[lru]);
}
@@ -342,7 +361,7 @@ int task_in_mem_cgroup(struct task_struc
/*
* This routine assumes that the appropriate zone's lru lock is already held
*/
-void mem_cgroup_move_lists(struct page *page, bool active)
+void mem_cgroup_move_lists(struct page *page, enum lru_list lru)
{
struct page_cgroup *pc;
struct mem_cgroup_per_zone *mz;
@@ -362,7 +381,7 @@ void mem_cgroup_move_lists(struct page *
if (pc) {
mz = page_cgroup_zoneinfo(pc);
spin_lock_irqsave(&mz->lru_lock, flags);
- __mem_cgroup_move_lists(pc, active);
+ __mem_cgroup_move_lists(pc, lru);
spin_unlock_irqrestore(&mz->lru_lock, flags);
}
unlock_page_cgroup(page);
@@ -460,12 +479,10 @@ unsigned long mem_cgroup_isolate_pages(u
/*
* TODO: play better with lumpy reclaim, grabbing anything.
*/
- if (PageActive(page) && !active) {
- __mem_cgroup_move_lists(pc, true);
- continue;
- }
- if (!PageActive(page) && active) {
- __mem_cgroup_move_lists(pc, false);
+ if (PageNoreclaim(page) ||
+ (PageActive(page) && !active) ||
+ (!PageActive(page) && active)) {
+ __mem_cgroup_move_lists(pc, page_lru(page));
continue;
}
Index: b/mm/swap.c
===================================================================
--- a/mm/swap.c
+++ b/mm/swap.c
@@ -189,7 +189,7 @@ void activate_page(struct page *page)
lru += LRU_ACTIVE;
add_page_to_lru_list(zone, page, lru);
__count_vm_event(PGACTIVATE);
- mem_cgroup_move_lists(page, true);
+ mem_cgroup_move_lists(page, lru);
if (file) {
zone->recent_scanned_file++;
Index: b/mm/vmscan.c
===================================================================
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -475,13 +475,16 @@ int putback_lru_page(struct page *page)
* non-reclaimable page on [in]active list.
* We know how to handle that.
*/
- lru_cache_add_lru(page, lru + page_file_cache(page));
+ lru += page_file_cache(page);
+ lru_cache_add_lru(page, lru);
+ mem_cgroup_move_lists(page, lru);
} else {
/*
* Put non-reclaimable pages directly on zone's noreclaim
* list.
*/
add_page_to_noreclaim_list(page);
+ mem_cgroup_move_lists(page, LRU_NORECLAIM);
}
put_page(page); /* drop ref from isolate */
@@ -1065,6 +1068,7 @@ static unsigned long shrink_inactive_lis
}
SetPageLRU(page);
add_page_to_lru_list(zone, page, lru);
+ mem_cgroup_move_lists(page, lru);
if (!pagevec_add(&pvec, page)) {
spin_unlock_irq(&zone->lru_lock);
__pagevec_release(&pvec);
@@ -1202,7 +1206,7 @@ static void shrink_active_list(unsigned
ClearPageActive(page);
list_move(&page->lru, &zone->list[lru]);
- mem_cgroup_move_lists(page, false);
+ mem_cgroup_move_lists(page, lru);
pgmoved++;
if (!pagevec_add(&pvec, page)) {
__mod_zone_page_state(zone, NR_INACTIVE_ANON + lru,
@@ -1234,7 +1238,7 @@ static void shrink_active_list(unsigned
VM_BUG_ON(!PageActive(page));
list_move(&page->lru, &zone->list[lru]);
- mem_cgroup_move_lists(page, true);
+ mem_cgroup_move_lists(page, lru);
pgmoved++;
if (!pagevec_add(&pvec, page)) {
__mod_zone_page_state(zone, NR_INACTIVE_ANON + lru,
Index: b/include/linux/memcontrol.h
===================================================================
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -35,7 +35,7 @@ extern int mem_cgroup_charge(struct page
extern int mem_cgroup_cache_charge(struct page *page, struct mm_struct *mm,
gfp_t gfp_mask);
extern void mem_cgroup_uncharge_page(struct page *page);
-extern void mem_cgroup_move_lists(struct page *page, bool active);
+extern void mem_cgroup_move_lists(struct page *page, enum lru_list lru);
extern unsigned long mem_cgroup_isolate_pages(unsigned long nr_to_scan,
struct list_head *dst,
unsigned long *scanned, int order,
[-- Attachment #3: rvr-13.3-kosaki-memcg-stat.patch --]
[-- Type: application/octet-stream, Size: 1165 bytes --]
add noreclaim field to /dev/cgroup/[group]/memory.stat.
Signed-off-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
---
mm/memcontrol.c | 6 ++++++
1 file changed, 6 insertions(+)
Index: b/mm/memcontrol.c
===================================================================
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -903,6 +903,7 @@ static int mem_control_stat_show(struct
{
unsigned long active_anon, inactive_anon;
unsigned long active_file, inactive_file;
+ unsigned long noreclaim;
inactive_anon = mem_cgroup_get_all_zonestat(mem_cont,
LRU_INACTIVE_ANON);
@@ -912,10 +913,15 @@ static int mem_control_stat_show(struct
LRU_INACTIVE_FILE);
active_file = mem_cgroup_get_all_zonestat(mem_cont,
LRU_ACTIVE_FILE);
+ noreclaim = mem_cgroup_get_all_zonestat(mem_cont,
+ LRU_NORECLAIM);
+
cb->fill(cb, "active_anon", (active_anon) * PAGE_SIZE);
cb->fill(cb, "inactive_anon", (inactive_anon) * PAGE_SIZE);
cb->fill(cb, "active_file", (active_file) * PAGE_SIZE);
cb->fill(cb, "inactive_file", (inactive_file) * PAGE_SIZE);
+ cb->fill(cb, "noreclaim", noreclaim * PAGE_SIZE);
+
}
return 0;
}
next prev parent reply other threads:[~2008-05-28 11:07 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-05-23 19:55 [PATCH -mm 00/16] VM pageout scalability improvements (V8) Rik van Riel
2008-05-23 19:55 ` [PATCH -mm 01/16] move isolate_lru_page() to vmscan.c Rik van Riel
2008-05-23 19:55 ` [PATCH -mm 02/16] Use an indexed array for LRU variables Rik van Riel
2008-05-27 16:54 ` Lee Schermerhorn
2008-05-27 17:03 ` Rik van Riel
2008-05-23 19:55 ` [PATCH -mm 03/16] use an array for the LRU pagevecs Rik van Riel
2008-05-23 19:55 ` [PATCH -mm 04/16] free swap space on swap-in/activation Rik van Riel
2008-05-28 9:08 ` Daisuke Nishimura
2008-05-23 19:55 ` [PATCH -mm 05/16] define page_file_cache() function Rik van Riel
2008-05-23 19:55 ` [PATCH -mm 06/16] split LRU lists into anon & file sets Rik van Riel
2008-05-23 19:55 ` [PATCH -mm 07/16] second chance replacement for anonymous pages Rik van Riel
2008-05-28 5:36 ` Daisuke Nishimura
2008-05-28 13:39 ` Rik van Riel
2008-05-28 15:42 ` Daisuke Nishimura
2008-05-28 16:08 ` Rik van Riel
2008-05-28 11:03 ` KOSAKI Motohiro
2008-05-28 13:43 ` Rik van Riel
2008-05-23 19:55 ` [PATCH -mm 08/16] add some sanity checks to get_scan_ratio Rik van Riel
2008-05-23 19:55 ` [PATCH -mm 09/16] fix pagecache reclaim referenced bit check Rik van Riel
2008-05-23 19:55 ` [PATCH -mm 10/16] add newly swapped in pages to the inactive list Rik van Riel
2008-05-23 19:55 ` [PATCH -mm 11/16] more aggressively use lumpy reclaim Rik van Riel
2008-05-23 19:55 ` [PATCH -mm 12/16] pageflag helpers for configed-out flags Rik van Riel
2008-05-23 19:55 ` [PATCH -mm 13/16] No Reclaim LRU Infrastructure Rik van Riel
2008-05-23 19:55 ` [PATCH -mm 14/16] Non-reclaimable page statistics Rik van Riel
2008-05-23 19:55 ` [PATCH -mm 15/16] ramfs pages are non-reclaimable Rik van Riel
2008-05-23 19:55 ` [PATCH -mm 16/16] SHM_LOCKED pages are nonreclaimable Rik van Riel
2008-05-26 18:24 ` [PATCH -mm 00/16] VM pageout scalability improvements (V8) Balbir Singh
2008-05-26 19:33 ` Rik van Riel
2008-05-27 15:54 ` Lee Schermerhorn
2008-05-27 16:10 ` Balbir Singh
2008-05-28 1:12 ` KAMEZAWA Hiroyuki
2008-05-28 11:04 ` KOSAKI Motohiro [this message]
2008-05-29 2:30 ` [RFC PATCH] No Reclaim LRU Infrastructure enhancement for memcgroup Balbir Singh
2008-05-29 11:14 ` Daisuke Nishimura
2008-05-28 11:49 ` [PATCH -mm 00/16] VM pageout scalability improvements (V8) Balbir Singh
2008-05-28 13:33 ` KOSAKI Motohiro
2008-05-28 13:36 ` Balbir Singh
2008-05-29 12:47 ` Carsten Otte
2008-05-29 14:43 ` Rik van Riel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20080528155809.9CD0.KOSAKI.MOTOHIRO@jp.fujitsu.com \
--to=kosaki.motohiro@jp.fujitsu.com \
--cc=Lee.Schermerhorn@hp.com \
--cc=akpm@linux-foundation.org \
--cc=balbir@linux.vnet.ibm.com \
--cc=kamezawa.hiroyu@jp.fujitsu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=riel@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®