From patchwork Thu Oct 28 11:56:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ning Zhang X-Patchwork-Id: 12589933 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 66FC2C433FE for ; Thu, 28 Oct 2021 11:57:05 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 112A260E8C for ; Thu, 28 Oct 2021 11:57:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 112A260E8C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 76837940009; Thu, 28 Oct 2021 07:57:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6C9DB940008; Thu, 28 Oct 2021 07:57:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 51C87940009; Thu, 28 Oct 2021 07:57:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0200.hostedemail.com [216.40.44.200]) by kanga.kvack.org (Postfix) with ESMTP id 2BFF6940008 for ; Thu, 28 Oct 2021 07:57:03 -0400 (EDT) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id A63F62FE09 for ; Thu, 28 Oct 2021 11:57:02 +0000 (UTC) X-FDA: 78745695084.25.680E9EE Received: from out30-56.freemail.mail.aliyun.com (out30-56.freemail.mail.aliyun.com [115.124.30.56]) by imf03.hostedemail.com (Postfix) with ESMTP id 2C42330039A7 for ; Thu, 28 Oct 2021 11:56:56 +0000 (UTC) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R161e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04400;MF=ningzhang@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0Uu0GVSZ_1635422217; Received: from localhost(mailfrom:ningzhang@linux.alibaba.com fp:SMTPD_---0Uu0GVSZ_1635422217) by smtp.aliyun-inc.com(127.0.0.1); Thu, 28 Oct 2021 19:56:57 +0800 From: Ning Zhang To: linux-mm@kvack.org Cc: Andrew Morton , Johannes Weiner , Michal Hocko , Vladimir Davydov , Yu Zhao Subject: [RFC 4/6] mm, thp: introduce a controller to trigger zero subpages reclaim Date: Thu, 28 Oct 2021 19:56:53 +0800 Message-Id: <1635422215-99394-5-git-send-email-ningzhang@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1635422215-99394-1-git-send-email-ningzhang@linux.alibaba.com> References: <1635422215-99394-1-git-send-email-ningzhang@linux.alibaba.com> X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 2C42330039A7 X-Stat-Signature: cdde144bd3qmeudyc617tariojp3ppo4 Authentication-Results: imf03.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=alibaba.com; spf=pass (imf03.hostedemail.com: domain of ningzhang@linux.alibaba.com designates 115.124.30.56 as permitted sender) smtp.mailfrom=ningzhang@linux.alibaba.com X-HE-Tag: 1635422216-912258 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Add a new controller named "reclaim" for memory.thp_reclaim_ctrl to trigger thp reclaim immediately: echo "reclaim 1" > memory.thp_reclaim_ctrl echo "reclaim 2" > memory.thp_reclaim_ctrl "reclaim 1" means triggering reclaim only for current memcg. "reclaim 2" means triggering reclaim for current memcg and it's children memcgs. Signed-off-by: Ning Zhang --- include/linux/huge_mm.h | 1 + mm/huge_memory.c | 29 +++++++++++++++++++++++++++++ mm/memcontrol.c | 27 +++++++++++++++++++++++++++ 3 files changed, 57 insertions(+) diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h index 304e3df..f792433 100644 --- a/include/linux/huge_mm.h +++ b/include/linux/huge_mm.h @@ -190,6 +190,7 @@ unsigned long thp_get_unmapped_area(struct file *filp, unsigned long addr, int zsr_get_hpage(struct hpage_reclaim *hr_queue, struct page **reclaim_page, int threshold); unsigned long zsr_reclaim_hpage(struct lruvec *lruvec, struct page *page); +void zsr_reclaim_memcg(struct mem_cgroup *memcg); static inline struct list_head *hpage_reclaim_list(struct page *page) { return &page[3].hpage_reclaim_list; diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 40a9879..633fd0f 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -3541,4 +3541,33 @@ unsigned long zsr_reclaim_hpage(struct lruvec *lruvec, struct page *page) return reclaimed; } + +void zsr_reclaim_memcg(struct mem_cgroup *memcg) +{ + struct lruvec *lruvec; + struct hpage_reclaim *hr_queue; + int threshold, nid; + + if (get_thp_reclaim_mode(memcg) == THP_RECLAIM_DISABLE) + return; + + threshold = READ_ONCE(memcg->thp_reclaim_threshold); + for_each_online_node(nid) { + lruvec = mem_cgroup_lruvec(memcg, NODE_DATA(nid)); + hr_queue = &memcg->nodeinfo[nid]->hpage_reclaim_queue; + for ( ; ; ) { + struct page *page = NULL; + + if (zsr_get_hpage(hr_queue, &page, threshold)) + break; + + if (!page) + continue; + + zsr_reclaim_hpage(lruvec, page); + + cond_resched(); + } + } +} #endif diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 7ba3c69..a8e3ca1 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -4521,6 +4521,8 @@ static int memcg_thp_reclaim_ctrl_show(struct seq_file *m, void *v) return 0; } +#define CTRL_RECLAIM_MEMCG 1 /* only relciam current memcg */ +#define CTRL_RECLAIM_ALL 2 /* reclaim current memcg and all the children memcgs */ static ssize_t memcg_thp_reclaim_ctrl_write(struct kernfs_open_file *of, char *buf, size_t nbytes, loff_t off) @@ -4548,6 +4550,31 @@ static ssize_t memcg_thp_reclaim_ctrl_write(struct kernfs_open_file *of, return -EINVAL; xchg(&memcg->thp_reclaim_threshold, threshold); + } else if (!strcmp(key, "reclaim")) { + struct mem_cgroup *iter; + int mode; + + value = strsep_s(&buf, " \t\n"); + if (!value) + return -EINVAL; + + ret = kstrtouint(value, 0, &mode); + if (ret) + return ret; + + switch (mode) { + case CTRL_RECLAIM_MEMCG: + zsr_reclaim_memcg(memcg); + break; + case CTRL_RECLAIM_ALL: + iter = mem_cgroup_iter(memcg, NULL, NULL); + do { + zsr_reclaim_memcg(iter); + } while ((iter = mem_cgroup_iter(memcg, iter, NULL))); + break; + default: + return -EINVAL; + } } else return -EINVAL;