linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp>
To: Linux Containers <containers@lists.osdl.org>,
	Linux MM <linux-mm@kvack.org>
Cc: Balbir Singh <balbir@linux.vnet.ibm.com>,
	Pavel Emelyanov <xemul@openvz.org>,
	KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>,
	YAMAMOTO Takashi <yamamoto@valinux.co.jp>,
	Hugh Dickins <hugh@veritas.com>,
	"IKEDA, Munehiro" <m-ikeda@ds.jp.nec.com>,
	Rik van Riel <riel@redhat.com>,
	Lee Schermerhorn <Lee.Schermerhorn@hp.com>,
	kosaki.motohiro@jp.fujitsu.com
Subject: [PATCH 4/4] swapcgroup: modify vm_swap_full for cgroup
Date: Thu, 22 May 2008 15:22:24 +0900	[thread overview]
Message-ID: <48351120.6000800@mxp.nes.nec.co.jp> (raw)
In-Reply-To: <48350F15.9070007@mxp.nes.nec.co.jp>

This patch modifies vm_swap_full() to calculate
the rate of swap usage per cgroup.

The purpose of this change is to free freeable swap caches
(that is, swap entries) per cgroup, so that swap_cgroup_charge()
fails less frequently.

I think I can free freeable swap caches more agressively
with one of Rik's splitlru patchset:

  [patch 04/14] free swap space on swap-in/activation

but, I should verify whether this change to vm_swap_full()
is valid.


Signed-off-by: Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp>

---
 include/linux/memcontrol.h |    3 +++
 include/linux/swap.h       |    6 +++++-
 mm/memcontrol.c            |   10 ++++++++++
 mm/memory.c                |    2 +-
 mm/swapfile.c              |   35 ++++++++++++++++++++++++++++++++++-
 5 files changed, 53 insertions(+), 3 deletions(-)

diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index a7e6621..256b298 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -179,6 +179,9 @@ extern int swap_cgroup_charge(struct page *page,
 			unsigned long offset);
 extern void swap_cgroup_uncharge(struct swap_info_struct *si,
 				unsigned long offset);
+extern int swap_cgroup_vm_swap_full(struct page *page);
+extern u64 swap_cgroup_read_usage(struct mem_cgroup *mem);
+extern u64 swap_cgroup_read_limit(struct mem_cgroup *mem);
 #else /* CONFIG_CGROUP_SWAP_RES_CTLR */
 static inline int swap_cgroup_charge(struct page *page,
 			struct swap_info_struct *si,
diff --git a/include/linux/swap.h b/include/linux/swap.h
index 18887f0..ef156c9 100644
--- a/include/linux/swap.h
+++ b/include/linux/swap.h
@@ -159,8 +159,12 @@ struct swap_list_t {
 	int next;	/* swapfile to be used next */
 };
 
+#ifndef CONFIG_CGROUP_SWAP_RES_CTLR
 /* Swap 50% full? Release swapcache more aggressively.. */
-#define vm_swap_full() (nr_swap_pages*2 < total_swap_pages)
+#define vm_swap_full(page) (nr_swap_pages*2 < total_swap_pages)
+#else
+#define vm_swap_full(page) swap_cgroup_vm_swap_full(page)
+#endif
 
 /* linux/mm/page_alloc.c */
 extern unsigned long totalram_pages;
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 84e803d..58d72ca 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -1265,5 +1265,15 @@ void swap_cgroup_uncharge(struct swap_info_struct *si,
 		css_put(&mem->css);
 	}
 }
+
+u64 swap_cgroup_read_usage(struct mem_cgroup *mem)
+{
+	return res_counter_read_u64(&mem->swap_res, RES_USAGE);
+}
+
+u64 swap_cgroup_read_limit(struct mem_cgroup *mem)
+{
+	return res_counter_read_u64(&mem->swap_res, RES_LIMIT);
+}
 #endif
 
diff --git a/mm/memory.c b/mm/memory.c
index df8f0e9..be2ff96 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -2175,7 +2175,7 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
 	page_add_anon_rmap(page, vma, address);
 
 	swap_free(entry);
-	if (vm_swap_full())
+	if (vm_swap_full(page))
 		remove_exclusive_swap_page(page);
 	unlock_page(page);
 
diff --git a/mm/swapfile.c b/mm/swapfile.c
index 682b71e..9256c2d 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -429,7 +429,7 @@ void free_swap_and_cache(swp_entry_t entry)
 		/* Only cache user (+us), or swap space full? Free it! */
 		/* Also recheck PageSwapCache after page is locked (above) */
 		if (PageSwapCache(page) && !PageWriteback(page) &&
-					(one_user || vm_swap_full())) {
+					(one_user || vm_swap_full(page))) {
 			delete_from_swap_cache(page);
 			SetPageDirty(page);
 		}
@@ -1892,3 +1892,36 @@ int valid_swaphandles(swp_entry_t entry, unsigned long *offset)
 	*offset = ++toff;
 	return nr_pages? ++nr_pages: 0;
 }
+
+#ifdef CONFIG_CGROUP_SWAP_RES_CTLR
+int swap_cgroup_vm_swap_full(struct page *page)
+{
+	int ret;
+	struct swap_info_struct *p;
+	struct mem_cgroup *mem;
+	u64 usage;
+	u64 limit;
+	swp_entry_t entry;
+
+	VM_BUG_ON(!PageLocked(page));
+	VM_BUG_ON(!PageSwapCache(page));
+
+	ret = 0;
+	entry.val = page_private(page);
+	p = swap_info_get(entry);
+	if (!p)
+		goto out;
+
+	mem = p->memcg[swp_offset(entry)];
+	usage = swap_cgroup_read_usage(mem) / PAGE_SIZE;
+	limit = swap_cgroup_read_limit(mem) / PAGE_SIZE;
+	limit = (limit < total_swap_pages) ? limit : total_swap_pages;
+
+	ret = usage * 2 > limit;
+
+	spin_unlock(&swap_lock);
+
+out:
+	return ret;
+}
+#endif


--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  parent reply	other threads:[~2008-05-22  6:22 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-22  6:13 [PATCH 0/4] swapcgroup(v2) Daisuke Nishimura
2008-05-22  6:17 ` [PATCH 1/4] swapcgroup: add cgroup files Daisuke Nishimura
2008-05-22  6:18 ` [PATCH 2/4] swapcgroup: add member to swap_info_struct for cgroup Daisuke Nishimura
2008-05-22  7:23   ` KAMEZAWA Hiroyuki
2008-05-22  8:46     ` Daisuke Nishimura
2008-05-22  9:35       ` KAMEZAWA Hiroyuki
2008-05-22  6:20 ` [PATCH 3/4] swapcgroup: implement charge/uncharge Daisuke Nishimura
2008-05-22  7:37   ` KAMEZAWA Hiroyuki
2008-05-23 11:52     ` Daisuke Nishimura
2008-05-26  0:57       ` KAMEZAWA Hiroyuki
2008-05-27 13:42         ` KAMEZAWA Hiroyuki
2008-05-22  6:22 ` Daisuke Nishimura [this message]
2008-05-22  6:45   ` [PATCH 4/4] swapcgroup: modify vm_swap_full for cgroup YAMAMOTO Takashi
2008-05-22 12:34     ` Daisuke Nishimura
2008-05-25 23:35       ` YAMAMOTO Takashi
2008-05-22  7:39   ` KAMEZAWA Hiroyuki
2008-05-22  8:00   ` KOSAKI Motohiro
2008-05-22 12:22     ` Daisuke Nishimura
2008-05-22 12:32       ` KOSAKI Motohiro
2008-05-23 12:26         ` Daisuke Nishimura
2008-05-22  7:44 ` [PATCH 0/4] swapcgroup(v2) KAMEZAWA Hiroyuki
2008-05-23  2:10   ` Daisuke Nishimura
2008-05-23  2:42     ` Daisuke Nishimura
2008-05-22 21:27 ` Balbir Singh
2008-05-23  4:27   ` Daisuke Nishimura
2008-05-27  7:31     ` YAMAMOTO Takashi
2008-05-27  7:42       ` Balbir Singh
2008-05-27  8:30         ` Daisuke Nishimura
2008-05-27 13:18           ` Balbir Singh
2008-05-27 13:42             ` Daisuke Nishimura
2008-05-27 13:46               ` Balbir Singh
2008-05-27 14:00                 ` Daisuke Nishimura
2008-05-23  2:26 ` Rik van Riel
2008-05-23  3:10   ` KAMEZAWA Hiroyuki
2008-05-23  3:32     ` Rik van Riel
2008-05-23  3:59     ` Balbir Singh
2008-05-23  4:30       ` KOSAKI Motohiro
2008-05-23  4:51         ` Balbir Singh
2008-05-23  5:23           ` KAMEZAWA Hiroyuki
2008-05-23  5:29           ` David Singleton
2008-05-23  6:00             ` KOSAKI Motohiro
2008-05-23  6:45               ` Balbir Singh

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=48351120.6000800@mxp.nes.nec.co.jp \
    --to=nishimura@mxp.nes.nec.co.jp \
    --cc=Lee.Schermerhorn@hp.com \
    --cc=balbir@linux.vnet.ibm.com \
    --cc=containers@lists.osdl.org \
    --cc=hugh@veritas.com \
    --cc=kamezawa.hiroyu@jp.fujitsu.com \
    --cc=kosaki.motohiro@jp.fujitsu.com \
    --cc=linux-mm@kvack.org \
    --cc=m-ikeda@ds.jp.nec.com \
    --cc=riel@redhat.com \
    --cc=xemul@openvz.org \
    --cc=yamamoto@valinux.co.jp \
    /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