summaryrefslogtreecommitdiff
path: root/mm
diff options
context:
space:
mode:
authorDongwoo Lee <dwoo08.lee@samsung.com>2020-08-03 14:44:43 +0900
committerDongwoo Lee <dwoo08.lee@samsung.com>2020-08-21 20:28:41 +0900
commitcad4c208fb4555786244483ce0f917847677e6ef (patch)
tree6fd07f2e080a51584ae355e53da6b515fb5fe535 /mm
parenta51d13fed28dc28eb69c575c660c9f1667a0a57f (diff)
downloadlinux-rpi-cad4c208fb4555786244483ce0f917847677e6ef.tar.gz
linux-rpi-cad4c208fb4555786244483ce0f917847677e6ef.tar.bz2
linux-rpi-cad4c208fb4555786244483ce0f917847677e6ef.zip
mm: memcontrol: Add force_reclaim to reclaim tasks' memory in memcg
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@xxxxxxxxxxx> Signed-off-by: Kyungmin Park <kyungmin.park@xxxxxxxxxxx> [dwoo08.lee: ported from mailing list https://www.spinics.net/lists/cgroups/msg07874.html] Change-Id: I40b1322dfe2628ca306690a15958881b3026606f Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
Diffstat (limited to 'mm')
-rw-r--r--mm/memcontrol.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index a3f4c35bb5fa..704e812bb980 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -3367,6 +3367,36 @@ static ssize_t mem_cgroup_force_empty_write(struct kernfs_open_file *of,
return mem_cgroup_force_empty(memcg) ?: nbytes;
}
+#ifdef CONFIG_MEMCG_SWAP
+static int mem_cgroup_force_reclaim(struct cgroup_subsys_state *css,
+ struct cftype *cft, u64 val)
+{
+ struct mem_cgroup *memcg = mem_cgroup_from_css(css);
+ 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, nr_to_reclaim,
+ GFP_KERNEL, true);
+
+ /*
+ * 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;
+ }
+
+ pr_info("%s: [Mem_reclaim] Loop: %d - Total_reclaimed: %lu - nr_to_reclaim: %lu\n",
+ __func__, loop, total, nr_to_reclaim);
+
+ return total;
+}
+#endif
+
static u64 mem_cgroup_hierarchy_read(struct cgroup_subsys_state *css,
struct cftype *cft)
{
@@ -7309,6 +7339,10 @@ static struct cftype memsw_cgroup_files[] = {
.write = mem_cgroup_reset,
.read_u64 = mem_cgroup_read_u64,
},
+ {
+ .name = "force_reclaim",
+ .write_u64 = mem_cgroup_force_reclaim,
+ },
{ }, /* terminate */
};