From patchwork Thu May 9 03:41:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Gushchin X-Patchwork-Id: 13659417 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 94789C10F1A for ; Thu, 9 May 2024 03:42:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1EE806B009C; Wed, 8 May 2024 23:42:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1503B6B009D; Wed, 8 May 2024 23:42:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EC01F6B009E; Wed, 8 May 2024 23:42:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id C97D86B009C for ; Wed, 8 May 2024 23:42:30 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 726FC814A4 for ; Thu, 9 May 2024 03:42:30 +0000 (UTC) X-FDA: 82097460060.15.F149895 Received: from out-185.mta1.migadu.com (out-185.mta1.migadu.com [95.215.58.185]) by imf16.hostedemail.com (Postfix) with ESMTP id C15AF180002 for ; Thu, 9 May 2024 03:42:27 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=v3WirRuP; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf16.hostedemail.com: domain of roman.gushchin@linux.dev designates 95.215.58.185 as permitted sender) smtp.mailfrom=roman.gushchin@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1715226147; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=l+IGewwB/hA9+YLjb6ALMedkw3L1LhLjm9qHeDH2NK8=; b=plNYogeUq9lm2REd7Ju04HbemLDW3QgJPP7zinHtNtfWcL5VSa3lrR3slzz2nqETv7UQg5 XKxttuJ4OOwYxUj2Co+Tv2cOAW5r9V0STsaq0QxsoGKWAL797M2Pwhom80lA7Z2bbY+TkA cb0N+WYZOuXomqMEtM2Zkq1nhwk15pw= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=v3WirRuP; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf16.hostedemail.com: domain of roman.gushchin@linux.dev designates 95.215.58.185 as permitted sender) smtp.mailfrom=roman.gushchin@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1715226147; a=rsa-sha256; cv=none; b=FFLKK3UMhMcKwPup6dxeTGSrvIEJIUcPeTM951Hy5t/yeQcScgEqf3k4T51I4AvkWrrbqG WEXuM8lJguHkCkqI46c3xliwb5mbDnulvL0wv9BLMs+nFGhK2kD/UgUpABVRud3Jd+4a2g N/whgJb1BDY8iXl1pXZR2A48spMYRTY= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1715226146; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=l+IGewwB/hA9+YLjb6ALMedkw3L1LhLjm9qHeDH2NK8=; b=v3WirRuPZx7HirePbOwRVVFlRmAV+7Kqm9Fygr0Fyu/mHOUusNM9d1Yx0CyL77pcjEW8ts yGTX8zbOBHHSfUmaGJxX9wXy+GdtMzoWUunKwUsMYZReY/qWviEnhC6mnHc2R3raGj6PXG U1kZCFpWMRAfAUegfstelLCrjJD1xaM= From: Roman Gushchin To: Andrew Morton Cc: Muchun Song , Johannes Weiner , Michal Hocko , Shakeel Butt , Matthew Wilcox , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Roman Gushchin Subject: [PATCH rfc 8/9] mm: memcg: put corresponding struct mem_cgroup members under CONFIG_MEMCG_V1 Date: Wed, 8 May 2024 20:41:37 -0700 Message-ID: <20240509034138.2207186-9-roman.gushchin@linux.dev> In-Reply-To: <20240509034138.2207186-1-roman.gushchin@linux.dev> References: <20240509034138.2207186-1-roman.gushchin@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Stat-Signature: djx7cuowp4qy7y1f3twa1d65c1k8spud X-Rspamd-Queue-Id: C15AF180002 X-Rspam-User: X-Rspamd-Server: rspam12 X-HE-Tag: 1715226147-386017 X-HE-Meta: U2FsdGVkX18GAWN5xHSqN+1ArxjBAF8Zdt4RMbMxBZP7GTxKXsLrhzeWpiHwq7l6KZsEe90To4dcG6zkHqyaqI73f1n8pMTRwW5kJf7CKw6wGcpL52Xyh3Fzo/DAi5IFmTlLER0VjXjG+NSUU1KXYSKBNWF1uWqafK+ealvdprBjM6ANIqDfk9ouHqp22EIDlyJcFMY/zKrmRxPT8GeSEl//lFUNt1UdQ5IKhXRqsBCxKnLF6yRup6BHeE7rWiT3ivutx9tj5fsf1CKlnVCnNedD1k4/ycSEXn+mHjpmtMFrPRJqb0fsIIeX53VIePIYuNJK1RBmoR6BbpsPh9xvnmkhms1FI+mx2e5pimGeCROch4VBvOAsNmAYPQN6wJXy5+ktDyZI/JMbSsxHsxbdnsZ0LM7x2Khe/J+kSDqTSi1RT7CSCLWJIUE+aH6ZXLpPjiy0GCvwyk/xOUf9U+r5W48/hm1VFhfGYhNTpWGQP1tka36U9IAG8MLINCYb6Ku5RLL9V7tR0CEGARDK/KSlzKgQCv5lHtr75oAci3PBD1lONsAXYaaovM+c3F5lFunkrs14kjX8OZ8K6NGUzD095JwFDvsI9+TMIQ+DU+ShQe2nPH+Kl3oy52uPzxIniU/sn3k/hlGHnctmneoZzYd2FxQs62lPctValx/QaZr1+Jzq/80x+a/wooEYt/C/eNZZVCPtiFJButgAT06x5TiWevXcSBbKUmm1oAv6e04f9Vh4FZwnGkEfnXX6fFj6UZDqUQmNZ7fEHMW92PsvYiljQ+m5E7iTAG+k8dMXmftZJH27uyIDaDjZmxfbm0/KN4PqWQSSKPsVkRJoXXTNbVUr074Xj9oTbfde2+P7N1wh3lNkcOSY3HFpt/JiKGVLnZdioLyub5IwfbgjP94lvFbfDZ8DDQFUUQXti+QCmIZS8sdUm3g2p4/cclLjxVyKlb3vGmcbpx75uQjFFrIO/7A /91VKmtj 2Lk/Q+2qxVotvrGuZxCnQCyRLWTQ9aORJd6P6PazsJapEDzPXF1CFaEz5TrELszQFyG+yOX9roDOPKzBlAVI0ldheIv3Fcpc2q+bob9Y3ATklmEx5eevYxnvMPx8ks4oU8SrA 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: List-Subscribe: List-Unsubscribe: Put members of struct mem_cgroup which are related to the legacy cgroup v1 memory controller under the CONFIG_MEMCG_V1 config option. Also, put the initialization and some trivial access code under the same option. Signed-off-by: Roman Gushchin --- include/linux/memcontrol.h | 33 ++++++++++++++++++++------------- mm/memcontrol.c | 25 +++++++++++++++++++------ 2 files changed, 39 insertions(+), 19 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index d2a4145b1909..4347d6889fa0 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -182,9 +182,11 @@ struct mem_cgroup { struct page_counter memsw; /* v1 only */ }; +#ifdef CONFIG_MEMCG_V1 /* Legacy consumer-oriented counters */ struct page_counter kmem; /* v1 only */ struct page_counter tcpmem; /* v1 only */ +#endif /* Range enforcement for interrupt charges */ struct work_struct high_work; @@ -198,24 +200,15 @@ struct mem_cgroup { */ bool zswap_writeback; #endif - - unsigned long soft_limit; - - /* vmpressure notifications */ - struct vmpressure vmpressure; + int swappiness; /* * Should the OOM killer kill all belonging tasks, had it kill one? */ bool oom_group; - /* protected by memcg_oom_lock */ - bool oom_lock; - int under_oom; - - int swappiness; - /* OOM-Killer disable */ - int oom_kill_disable; + /* vmpressure notifications */ + struct vmpressure vmpressure; /* memory.events and memory.events.local */ struct cgroup_file events_file; @@ -224,6 +217,16 @@ struct mem_cgroup { /* handle for "memory.swap.events" */ struct cgroup_file swap_events_file; +#ifdef CONFIG_MEMCG_V1 + unsigned long soft_limit; + + /* protected by memcg_oom_lock */ + bool oom_lock; + int under_oom; + + /* OOM-Killer disable */ + int oom_kill_disable; + /* protect arrays of thresholds */ struct mutex thresholds_lock; @@ -244,6 +247,7 @@ struct mem_cgroup { /* taken only while moving_account > 0 */ spinlock_t move_lock; unsigned long move_lock_flags; +#endif CACHELINE_PADDING(_pad1_); @@ -279,12 +283,13 @@ struct mem_cgroup { #endif CACHELINE_PADDING(_pad2_); - +#ifdef CONFIG_MEMCG_V1 /* * set > 0 if pages under this cgroup are moving to other cgroup. */ atomic_t moving_account; struct task_struct *move_lock_task; +#endif struct memcg_vmstats_percpu __percpu *vmstats_percpu; @@ -294,9 +299,11 @@ struct mem_cgroup { struct memcg_cgwb_frn cgwb_frn[MEMCG_CGWB_FRN_CNT]; #endif +#ifdef CONFIG_MEMCG_V1 /* List of events which userspace want to receive */ struct list_head event_list; spinlock_t event_list_lock; +#endif #ifdef CONFIG_TRANSPARENT_HUGEPAGE struct deferred_split deferred_split_queue; diff --git a/mm/memcontrol.c b/mm/memcontrol.c index d5883f748330..4dcfd1ef5d61 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -1537,6 +1537,7 @@ void mem_cgroup_print_oom_meminfo(struct mem_cgroup *memcg) pr_info("swap: usage %llukB, limit %llukB, failcnt %lu\n", K((u64)page_counter_read(&memcg->swap)), K((u64)READ_ONCE(memcg->swap.max)), memcg->swap.failcnt); +#ifdef CONFIG_MEMCG_V1 else { pr_info("memory+swap: usage %llukB, limit %llukB, failcnt %lu\n", K((u64)page_counter_read(&memcg->memsw)), @@ -1545,6 +1546,7 @@ void mem_cgroup_print_oom_meminfo(struct mem_cgroup *memcg) K((u64)page_counter_read(&memcg->kmem)), K((u64)memcg->kmem.max), memcg->kmem.failcnt); } +#endif pr_info("Memory cgroup stats for "); pr_cont_cgroup_path(memcg->css.cgroup); @@ -2650,12 +2652,14 @@ struct obj_cgroup *get_obj_cgroup_from_folio(struct folio *folio) static void memcg_account_kmem(struct mem_cgroup *memcg, int nr_pages) { mod_memcg_state(memcg, MEMCG_KMEM, nr_pages); +#ifdef CONFIG_MEMCG_V1 if (!cgroup_subsys_on_dfl(memory_cgrp_subsys)) { if (nr_pages > 0) page_counter_charge(&memcg->kmem, nr_pages); else page_counter_uncharge(&memcg->kmem, -nr_pages); } +#endif } @@ -3602,12 +3606,14 @@ static struct mem_cgroup *mem_cgroup_alloc(struct mem_cgroup *parent) goto fail; INIT_WORK(&memcg->high_work, high_work_func); +#ifdef CONFIG_MEMCG_V1 INIT_LIST_HEAD(&memcg->oom_notify); mutex_init(&memcg->thresholds_lock); spin_lock_init(&memcg->move_lock); - vmpressure_init(&memcg->vmpressure); INIT_LIST_HEAD(&memcg->event_list); spin_lock_init(&memcg->event_list_lock); +#endif + vmpressure_init(&memcg->vmpressure); memcg->socket_pressure = jiffies; #ifdef CONFIG_MEMCG_KMEM memcg->kmemcg_id = -1; @@ -3654,20 +3660,22 @@ mem_cgroup_css_alloc(struct cgroup_subsys_state *parent_css) page_counter_set_high(&memcg->swap, PAGE_COUNTER_MAX); if (parent) { WRITE_ONCE(memcg->swappiness, mem_cgroup_swappiness(parent)); - WRITE_ONCE(memcg->oom_kill_disable, READ_ONCE(parent->oom_kill_disable)); - page_counter_init(&memcg->memory, &parent->memory); page_counter_init(&memcg->swap, &parent->swap); +#ifdef CONFIG_MEMCG_V1 page_counter_init(&memcg->kmem, &parent->kmem); page_counter_init(&memcg->tcpmem, &parent->tcpmem); + WRITE_ONCE(memcg->oom_kill_disable, READ_ONCE(parent->oom_kill_disable)); +#endif } else { init_memcg_stats(); init_memcg_events(); page_counter_init(&memcg->memory, NULL); page_counter_init(&memcg->swap, NULL); +#ifdef CONFIG_MEMCG_V1 page_counter_init(&memcg->kmem, NULL); page_counter_init(&memcg->tcpmem, NULL); - +#endif root_mem_cgroup = memcg; return &memcg->css; } @@ -3802,12 +3810,14 @@ static void mem_cgroup_css_reset(struct cgroup_subsys_state *css) page_counter_set_max(&memcg->memory, PAGE_COUNTER_MAX); page_counter_set_max(&memcg->swap, PAGE_COUNTER_MAX); +#ifdef CONFIG_MEMCG_V1 page_counter_set_max(&memcg->kmem, PAGE_COUNTER_MAX); page_counter_set_max(&memcg->tcpmem, PAGE_COUNTER_MAX); + mem_cgroup_soft_limit_reset(memcg); +#endif page_counter_set_min(&memcg->memory, 0); page_counter_set_low(&memcg->memory, 0); page_counter_set_high(&memcg->memory, PAGE_COUNTER_MAX); - mem_cgroup_soft_limit_reset(memcg); page_counter_set_high(&memcg->swap, PAGE_COUNTER_MAX); memcg_wb_domain_size_changed(memcg); } @@ -5018,6 +5028,7 @@ void mem_cgroup_sk_free(struct sock *sk) bool mem_cgroup_charge_skmem(struct mem_cgroup *memcg, unsigned int nr_pages, gfp_t gfp_mask) { +#ifdef CONFIG_MEMCG_V1 if (!cgroup_subsys_on_dfl(memory_cgrp_subsys)) { struct page_counter *fail; @@ -5032,6 +5043,7 @@ bool mem_cgroup_charge_skmem(struct mem_cgroup *memcg, unsigned int nr_pages, } return false; } +#endif if (try_charge(memcg, gfp_mask, nr_pages) == 0) { mod_memcg_state(memcg, MEMCG_SOCK, nr_pages); @@ -5048,11 +5060,12 @@ bool mem_cgroup_charge_skmem(struct mem_cgroup *memcg, unsigned int nr_pages, */ void mem_cgroup_uncharge_skmem(struct mem_cgroup *memcg, unsigned int nr_pages) { +#ifdef CONFIG_MEMCG_V1 if (!cgroup_subsys_on_dfl(memory_cgrp_subsys)) { page_counter_uncharge(&memcg->tcpmem, nr_pages); return; } - +#endif mod_memcg_state(memcg, MEMCG_SOCK, -nr_pages); refill_stock(memcg, nr_pages);