linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Hyunhee Kim <hyunhee.kim@samsung.com>
To: linux-mm@kvack.org, cgroups@vger.kernel.org
Cc: 'Kyungmin Park' <kyungmin.park@samsung.com>
Subject: [PATCH] memcg: Add force_reclaim to reclaim tasks' memory in memcg.
Date: Mon, 10 Jun 2013 20:16:31 +0900	[thread overview]
Message-ID: <021801ce65cb$f5b0bc50$e11234f0$%kim@samsung.com> (raw)

These days, platforms tend to manage memory on low memory state
like andloid's lowmemory killer. These platforms might want to
reclaim memory from background tasks as well as kill victims
to guarantee free memory at use space level. This patch provides
an interface to reclaim a given memcg. After platform's low memory
handler moves tasks that the platform wants to reclaim to
a memcg and decides how many pages should be reclaimed, it can
reclaim the pages from the tasks by writing the number of pages
at memory.force_reclaim.

Signed-off-by: Hyunhee Kim <hyunhee.kim@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
---
 mm/memcontrol.c |   26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 010d6c1..21819c9 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -4980,6 +4980,28 @@ static int mem_cgroup_force_empty_write(struct cgroup
*cont, unsigned int event)
 	return ret;
 }
 
+static int mem_cgroup_force_reclaim(struct cgroup *cont, struct cftype
*cft, u64 val)
+{
+
+	struct mem_cgroup *memcg = mem_cgroup_from_cont(cont);
+	unsigned long nr_to_reclaim = val;
+	unsigned long total = 0;
+	int loop;
+
+	for (loop = 0; loop < MEM_CGROUP_MAX_RECLAIM_LOOPS; loop++) {
+		total += try_to_free_mem_cgroup_pages(memcg, GFP_KERNEL,
false);
+
+		/*
+		 * If nothing was reclaimed after two attempts, there
+		 * may be no reclaimable pages in this hierarchy.
+		 * If more than nr_to_reclaim pages were already reclaimed,
+		 * finish force reclaim.
+		 */
+		if (loop && (!total || total > nr_to_reclaim))
+			break;
+	}
+	return total;
+}
 
 static u64 mem_cgroup_hierarchy_read(struct cgroup *cont, struct cftype
*cft)
 {
@@ -5938,6 +5960,10 @@ static struct cftype mem_cgroup_files[] = {
 		.trigger = mem_cgroup_force_empty_write,
 	},
 	{
+		.name = "force_reclaim",
+		.write_u64 = mem_cgroup_force_reclaim,
+	},
+	{
 		.name = "use_hierarchy",
 		.flags = CFTYPE_INSANE,
 		.write_u64 = mem_cgroup_hierarchy_write,
-- 
1.7.9.5


--
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>

             reply	other threads:[~2013-06-10 11:16 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-10 11:16 Hyunhee Kim [this message]
2013-06-10 15:22 ` Michal Hocko
2013-06-18  9:46   ` Hyunhee Kim
2013-06-18 10:40     ` Michal Hocko

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='021801ce65cb$f5b0bc50$e11234f0$%kim@samsung.com' \
    --to=hyunhee.kim@samsung.com \
    --cc=cgroups@vger.kernel.org \
    --cc=kyungmin.park@samsung.com \
    --cc=linux-mm@kvack.org \
    /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