From patchwork Mon Apr 5 17:08:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tim Chen X-Patchwork-Id: 12183453 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 950CDC433B4 for ; Mon, 5 Apr 2021 18:09:02 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id F378C61359 for ; Mon, 5 Apr 2021 18:09:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F378C61359 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 815FE6B0078; Mon, 5 Apr 2021 14:09:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 79DB26B007B; Mon, 5 Apr 2021 14:09:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5A2E66B007D; Mon, 5 Apr 2021 14:09:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0169.hostedemail.com [216.40.44.169]) by kanga.kvack.org (Postfix) with ESMTP id 340BA6B0078 for ; Mon, 5 Apr 2021 14:09:01 -0400 (EDT) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id F1DF6F040 for ; Mon, 5 Apr 2021 18:09:00 +0000 (UTC) X-FDA: 77999099640.01.CA23701 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by imf06.hostedemail.com (Postfix) with ESMTP id 351F5C0007C6 for ; Mon, 5 Apr 2021 18:09:01 +0000 (UTC) IronPort-SDR: 32Rs5JK445cD6yN5xaScNOvErdqW2G8+qWq7GAwS7JcgtI76DxljUhWFfCC46AacV1XdLvBOza 3cifWu4mmdCw== X-IronPort-AV: E=McAfee;i="6000,8403,9945"; a="172968199" X-IronPort-AV: E=Sophos;i="5.81,307,1610438400"; d="scan'208";a="172968199" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Apr 2021 11:09:00 -0700 IronPort-SDR: +HUey/5dlE1yomxaN4NZGyrmKeFWrxhZy1afGwPD497QiQPpdG0WuCOHBvsRGzWRXKSVEtNmzP cDI92OwtOb+g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.81,307,1610438400"; d="scan'208";a="448153881" Received: from skl-02.jf.intel.com ([10.54.74.28]) by fmsmga002.fm.intel.com with ESMTP; 05 Apr 2021 11:08:59 -0700 From: Tim Chen To: Michal Hocko Cc: Tim Chen , Johannes Weiner , Andrew Morton , Dave Hansen , Ying Huang , Dan Williams , David Rientjes , Shakeel Butt , linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH v1 02/11] mm: Add soft memory limit for mem cgroup Date: Mon, 5 Apr 2021 10:08:26 -0700 Message-Id: <96026428f135c1199a3216fde6e48317fc45486f.1617642417.git.tim.c.chen@linux.intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 351F5C0007C6 X-Stat-Signature: 57xgborqurqhbqbkmrg6amy5xsqp77kk Received-SPF: none (linux.intel.com>: No applicable sender policy available) receiver=imf06; identity=mailfrom; envelope-from=""; helo=mga17.intel.com; client-ip=192.55.52.151 X-HE-DKIM-Result: none/none X-HE-Tag: 1617646141-239483 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: For each memory cgroup, define a soft memory limit on its top tier memory consumption. Memory cgroups exceeding their top tier limit will be selected for demotion of their top tier memory to lower tier under memory pressure. Signed-off-by: Tim Chen --- include/linux/memcontrol.h | 1 + mm/memcontrol.c | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index eeb0b52203e9..25d8b9acec7c 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -230,6 +230,7 @@ struct mem_cgroup { struct work_struct high_work; unsigned long soft_limit; + unsigned long toptier_soft_limit; /* vmpressure notifications */ struct vmpressure vmpressure; diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 41a3f22b6639..9a9d677a6654 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -3603,6 +3603,7 @@ enum { RES_MAX_USAGE, RES_FAILCNT, RES_SOFT_LIMIT, + RES_TOPTIER_SOFT_LIMIT, }; static u64 mem_cgroup_read_u64(struct cgroup_subsys_state *css, @@ -3643,6 +3644,8 @@ static u64 mem_cgroup_read_u64(struct cgroup_subsys_state *css, return counter->failcnt; case RES_SOFT_LIMIT: return (u64)memcg->soft_limit * PAGE_SIZE; + case RES_TOPTIER_SOFT_LIMIT: + return (u64)memcg->toptier_soft_limit * PAGE_SIZE; default: BUG(); } @@ -3881,6 +3884,14 @@ static ssize_t mem_cgroup_write(struct kernfs_open_file *of, memcg->soft_limit = nr_pages; ret = 0; break; + case RES_TOPTIER_SOFT_LIMIT: + if (mem_cgroup_is_root(memcg)) { /* Can't set limit on root */ + ret = -EINVAL; + break; + } + memcg->toptier_soft_limit = nr_pages; + ret = 0; + break; } return ret ?: nbytes; } @@ -5029,6 +5040,12 @@ static struct cftype mem_cgroup_legacy_files[] = { .write = mem_cgroup_write, .read_u64 = mem_cgroup_read_u64, }, + { + .name = "toptier_soft_limit_in_bytes", + .private = MEMFILE_PRIVATE(_MEM, RES_TOPTIER_SOFT_LIMIT), + .write = mem_cgroup_write, + .read_u64 = mem_cgroup_read_u64, + }, { .name = "failcnt", .private = MEMFILE_PRIVATE(_MEM, RES_FAILCNT), @@ -5365,6 +5382,7 @@ mem_cgroup_css_alloc(struct cgroup_subsys_state *parent_css) page_counter_set_high(&memcg->memory, PAGE_COUNTER_MAX); memcg->soft_limit = PAGE_COUNTER_MAX; page_counter_set_high(&memcg->swap, PAGE_COUNTER_MAX); + memcg->toptier_soft_limit = PAGE_COUNTER_MAX; if (parent) { memcg->swappiness = mem_cgroup_swappiness(parent); memcg->oom_kill_disable = parent->oom_kill_disable;