From nobody Mon Apr 6 11:52:06 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7336AC32771 for ; Mon, 26 Sep 2022 15:15:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236031AbiIZPPC (ORCPT ); Mon, 26 Sep 2022 11:15:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236212AbiIZPOR (ORCPT ); Mon, 26 Sep 2022 11:14:17 -0400 Received: from mail-qv1-xf2f.google.com (mail-qv1-xf2f.google.com [IPv6:2607:f8b0:4864:20::f2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB35B3FA22 for ; Mon, 26 Sep 2022 06:57:14 -0700 (PDT) Received: by mail-qv1-xf2f.google.com with SMTP id y9so4337372qvo.4 for ; Mon, 26 Sep 2022 06:57:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=+6iJEmxp4bl9ohblP/ldB8IdtUPtHQigooDS1dl/Wc4=; b=etTRTh75O0L4i1MKIV2WPz590yQ569uvsT2rLsbPXxXGZXz2RBYFV5wchPr7zQK5tL oKGHX2usHRR86OnURr2MSY5OsLn+FPSGi0cWEjYbrBecrnPDlDdIsXtPuhTteUv6OR3a j1i0QT1+oNdpUtMM/f4xY4B9BSZJNunaqZhsqJn+WVGvKfDDTfgT/MCt1pQVZ+y3Ehma DketzHiCsnHYz+XZLjsvaxacOFveJcQ5rSZm/TZuvbXYyQtmkhekX4aNfwoyTdpAqF0J d0qnwZlfllTz+GnXoV8iFQtjUTzGkfeExjCA+2BCn5FZUQiquYNkxnmPLs4fEq73CRFc SvGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=+6iJEmxp4bl9ohblP/ldB8IdtUPtHQigooDS1dl/Wc4=; b=sNDpDq8lE/Rc/+Tn7jncqUVJGmOHAWeuFOw6+amEhxifKaL6lwQGp8nNDRpPNDIAjs ebiX1qLRDw3JNLMJ1yaQF9t53avpO//WiJFh1bK7xQhM20/+lgFE5tvVVFxh7BYqC/zG pyS4ZRAwXG4/zlFzBJ1XvIFErMWrX3iBLTetbG8vgbTLOvmbJ/s1dVzx4FT2R+Hz2s0H wUm332UcKqj5u7JY7mO3u2gUD+Q4oCW2AndFOXsDIPaRhLKLhDsMKzcfUbM5JXlYlDvi WMA5pq7e4FwCry+AcQxIikBx+JZPdhhSU28Yjiwu5VICcA4fLmjNnHRYJMyNfKj5FVay 6UTQ== X-Gm-Message-State: ACrzQf19cXuNOc6SuPRUYIaEFEiFSusk7e4DR2lHAuKx6RPRJ6c8zrvG wjx2N3Uw6tYpXDAT2pXvfteLhA== X-Google-Smtp-Source: AMsMyM5bOx93hkMCNRDGZm4BGsvx4b//fZgec4uv6OS22XlPPvI7A2qmMP0JLkBjQPe7FgcA5u1bqQ== X-Received: by 2002:a05:6214:27c6:b0:4ac:94f9:c727 with SMTP id ge6-20020a05621427c600b004ac94f9c727mr17339942qvb.51.1664200633825; Mon, 26 Sep 2022 06:57:13 -0700 (PDT) Received: from localhost (2603-7000-0c01-2716-9175-2920-760a-79fa.res6.spectrum.com. [2603:7000:c01:2716:9175:2920:760a:79fa]) by smtp.gmail.com with ESMTPSA id h7-20020ac85047000000b0035d0520db17sm10745315qtm.49.2022.09.26.06.57.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Sep 2022 06:57:13 -0700 (PDT) From: Johannes Weiner To: Andrew Morton Cc: Shakeel Butt , Michal Hocko , Roman Gushchin , Hugh Dickins , linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/4] mm: memcontrol: don't allocate cgroup swap arrays when memcg is disabled Date: Mon, 26 Sep 2022 09:57:01 -0400 Message-Id: <20220926135704.400818-2-hannes@cmpxchg.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220926135704.400818-1-hannes@cmpxchg.org> References: <20220926135704.400818-1-hannes@cmpxchg.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Since commit 2d1c498072de ("mm: memcontrol: make swap tracking an integral part of memory control"), the cgroup swap arrays are used to track memory ownership at the time of swap readahead and swapoff, even if swap space *accounting* has been turned off by the user via swapaccount=3D0 (which sets cgroup_memory_noswap). However, the patch was overzealous: by simply dropping the cgroup_memory_noswap conditionals in the swapon, swapoff and uncharge path, it caused the cgroup arrays being allocated even when the memory controller as a whole is disabled. This is a waste of that memory. Restore mem_cgroup_disabled() checks, implied previously by cgroup_memory_noswap, in the swapon, swapoff, and swap_entry_free callbacks. Fixes: 2d1c498072de ("mm: memcontrol: make swap tracking an integral part o= f memory control") Reported-by: Hugh Dickins Signed-off-by: Johannes Weiner Reviewed-by: Shakeel Butt Acked-by: Hugh Dickins Acked-by: Michal Hocko --- mm/memcontrol.c | 3 +++ mm/swap_cgroup.c | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 6b74bbdc2659..9e3c010ca676 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -7459,6 +7459,9 @@ void __mem_cgroup_uncharge_swap(swp_entry_t entry, un= signed int nr_pages) struct mem_cgroup *memcg; unsigned short id; =20 + if (mem_cgroup_disabled()) + return; + id =3D swap_cgroup_record(entry, 0, nr_pages); rcu_read_lock(); memcg =3D mem_cgroup_from_id(id); diff --git a/mm/swap_cgroup.c b/mm/swap_cgroup.c index 5a9442979a18..db6c4a26cf59 100644 --- a/mm/swap_cgroup.c +++ b/mm/swap_cgroup.c @@ -170,6 +170,9 @@ int swap_cgroup_swapon(int type, unsigned long max_page= s) unsigned long length; struct swap_cgroup_ctrl *ctrl; =20 + if (mem_cgroup_disabled()) + return 0; + length =3D DIV_ROUND_UP(max_pages, SC_PER_PAGE); =20 array =3D vcalloc(length, sizeof(void *)); @@ -204,6 +207,9 @@ void swap_cgroup_swapoff(int type) unsigned long i, length; struct swap_cgroup_ctrl *ctrl; =20 + if (mem_cgroup_disabled()) + return; + mutex_lock(&swap_cgroup_mutex); ctrl =3D &swap_cgroup_ctrl[type]; map =3D ctrl->map; --=20 2.37.3 From nobody Mon Apr 6 11:52:06 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9AD08C32771 for ; Mon, 26 Sep 2022 15:15:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236058AbiIZPPH (ORCPT ); Mon, 26 Sep 2022 11:15:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57416 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236219AbiIZPOS (ORCPT ); Mon, 26 Sep 2022 11:14:18 -0400 Received: from mail-qv1-xf30.google.com (mail-qv1-xf30.google.com [IPv6:2607:f8b0:4864:20::f30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 618735A148 for ; Mon, 26 Sep 2022 06:57:15 -0700 (PDT) Received: by mail-qv1-xf30.google.com with SMTP id w4so4348269qvp.2 for ; Mon, 26 Sep 2022 06:57:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=HeJ4YaLZeye7K1WDyF1k6x7DVspo4c+vBec349uMCXA=; b=0d/wItGXbtug7zpturg/zxUG+IZarNXHxgNZ2X8AOYRuE9PfYFwwS5l6CL131XGwvT F22e4LAZG3MD/PUwEN6sr7Hw9S+5Apeqx+qfbFw+GDau4kqS3lvpdGgY7KuJRn9M1UNX puNO1MgLzrzXTx3MVyb9aIZlat2aM4gNqTkE+wAjMl1rgTbDL0vKg99D8WL8zytzSMcj 4ZlKV/xY9ZUNiuX0Q1ZadfGHe9gXSROaEQHpHK1V3wiKZqnHy/DLWNDSpW/HE/Vk0U+u +otTACZTiF+2iS//DQyG7gsLLmfOuSzIlyfQ2A4Zfohjsbr2RxOOaJ3JHrv3EgWTASFH B6SA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=HeJ4YaLZeye7K1WDyF1k6x7DVspo4c+vBec349uMCXA=; b=Q8xHR6AVm3X5m0+N68OwAAhP7qUrA2fY/f8pNnNWB1HROQTSoWTkw4u9SEXbn2pCmM 2c4BRe/Uty/ipQHM+8K+V50h6Tu3YN42MHeci4KdDg9pnEUlLbG+tPQB4hMds6sFzLR3 tNWL7Rfa/6aEVwku8Dr9NmSArq4DwvoiN34Qmzrr7XYeGhD7GwMkv1Jr7PrpdyVWNT/I jSm+VOuLWTVKR5QPKZgT+kJR7GMZ8c9DnXzfDT3VizQhmsJa9oHitDvb3OmcU7Uwl+NK RzsVvOnzXU26/RRAhXzu0CMkmMp7uIauucIKnK5nGp+wiegv628FPgCNzT5lZJEj7FCE iV9g== X-Gm-Message-State: ACrzQf1x0CdPsLWc1hZ/nn+B7bA1qxJkznLwQGxNm1GDCbHR1ccR7inu JETiqv2q8Ee23T6dq947gHnDAg== X-Google-Smtp-Source: AMsMyM6FFcCCA0OAWsPzQLrlbPjXWThgUurSXOP/ecbenkipkttwdl4PhN2O8Tv+RF7syCrQiz1dEA== X-Received: by 2002:a0c:abc8:0:b0:4ac:d471:7b83 with SMTP id k8-20020a0cabc8000000b004acd4717b83mr17310086qvb.102.1664200635053; Mon, 26 Sep 2022 06:57:15 -0700 (PDT) Received: from localhost (2603-7000-0c01-2716-9175-2920-760a-79fa.res6.spectrum.com. [2603:7000:c01:2716:9175:2920:760a:79fa]) by smtp.gmail.com with ESMTPSA id fg21-20020a05622a581500b00342f8d4d0basm10991554qtb.43.2022.09.26.06.57.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Sep 2022 06:57:14 -0700 (PDT) From: Johannes Weiner To: Andrew Morton Cc: Shakeel Butt , Michal Hocko , Roman Gushchin , Hugh Dickins , linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/4] mm: memcontrol: deprecate swapaccounting=0 mode Date: Mon, 26 Sep 2022 09:57:02 -0400 Message-Id: <20220926135704.400818-3-hannes@cmpxchg.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220926135704.400818-1-hannes@cmpxchg.org> References: <20220926135704.400818-1-hannes@cmpxchg.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The swapaccounting=3D commandline option already does very little today. To close a trivial containment failure case, the swap ownership tracking part of the swap controller has recently become mandatory (see commit 2d1c498072de ("mm: memcontrol: make swap tracking an integral part of memory control") for details), which makes up the majority of the work during swapout, swapin, and the swap slot map. The only thing left under this flag is the page_counter operations and the visibility of the swap control files in the first place, which are rather meager savings. There also aren't many scenarios, if any, where controlling the memory of a cgroup while allowing it unlimited access to a global swap space is a workable resource isolation strategy. On the other hand, there have been several bugs and confusion around the many possible swap controller states (cgroup1 vs cgroup2 behavior, memory accounting without swap accounting, memcg runtime disabled). This puts the maintenance overhead of retaining the toggle above its practical benefits. Deprecate it. Suggested-by: Shakeel Butt Signed-off-by: Johannes Weiner Reviewed-by: Shakeel Butt --- .../admin-guide/kernel-parameters.txt | 6 --- mm/memcontrol.c | 50 ++++--------------- 2 files changed, 10 insertions(+), 46 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentatio= n/admin-guide/kernel-parameters.txt index 3b95f65bafe2..99a13f2be2ef 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -6036,12 +6036,6 @@ This parameter controls use of the Protected Execution Facility on pSeries. =20 - swapaccount=3D [KNL] - Format: [0|1] - Enable accounting of swap in memory resource - controller if no parameter or 1 is given or disable - it if 0 is given (See Documentation/admin-guide/cgroup-v1/memory.rst) - swiotlb=3D [ARM,IA-64,PPC,MIPS,X86] Format: { [,] | force | noforce } -- Number of I/O TLB slabs diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 9e3c010ca676..4be1b48b9659 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -88,22 +88,6 @@ static bool cgroup_memory_nosocket __ro_after_init; /* Kernel memory accounting disabled? */ static bool cgroup_memory_nokmem __ro_after_init; =20 -/* Whether the swap controller is active */ -#ifdef CONFIG_MEMCG_SWAP -static bool cgroup_memory_noswap __initdata; - -static DEFINE_STATIC_KEY_FALSE(memcg_swap_enabled_key); -static inline bool memcg_swap_enabled(void) -{ - return static_branch_likely(&memcg_swap_enabled_key); -} -#else -static inline bool memcg_swap_enabled(void) -{ - return false; -} -#endif - #ifdef CONFIG_CGROUP_WRITEBACK static DECLARE_WAIT_QUEUE_HEAD(memcg_cgwb_frn_waitq); #endif @@ -111,7 +95,7 @@ static DECLARE_WAIT_QUEUE_HEAD(memcg_cgwb_frn_waitq); /* Whether legacy memory+swap accounting is active */ static bool do_memsw_account(void) { - return !cgroup_subsys_on_dfl(memory_cgrp_subsys) && memcg_swap_enabled(); + return !cgroup_subsys_on_dfl(memory_cgrp_subsys); } =20 #define THRESHOLDS_EVENTS_TARGET 128 @@ -7379,7 +7363,7 @@ void mem_cgroup_swapout(struct folio *folio, swp_entr= y_t entry) if (!mem_cgroup_is_root(memcg)) page_counter_uncharge(&memcg->memory, nr_entries); =20 - if (memcg_swap_enabled() && memcg !=3D swap_memcg) { + if (memcg !=3D swap_memcg) { if (!mem_cgroup_is_root(swap_memcg)) page_counter_charge(&swap_memcg->memsw, nr_entries); page_counter_uncharge(&memcg->memsw, nr_entries); @@ -7431,7 +7415,7 @@ int __mem_cgroup_try_charge_swap(struct folio *folio,= swp_entry_t entry) =20 memcg =3D mem_cgroup_id_get_online(memcg); =20 - if (memcg_swap_enabled() && !mem_cgroup_is_root(memcg) && + if (!mem_cgroup_is_root(memcg) && !page_counter_try_charge(&memcg->swap, nr_pages, &counter)) { memcg_memory_event(memcg, MEMCG_SWAP_MAX); memcg_memory_event(memcg, MEMCG_SWAP_FAIL); @@ -7466,7 +7450,7 @@ void __mem_cgroup_uncharge_swap(swp_entry_t entry, un= signed int nr_pages) rcu_read_lock(); memcg =3D mem_cgroup_from_id(id); if (memcg) { - if (memcg_swap_enabled() && !mem_cgroup_is_root(memcg)) { + if (!mem_cgroup_is_root(memcg)) { if (cgroup_subsys_on_dfl(memory_cgrp_subsys)) page_counter_uncharge(&memcg->swap, nr_pages); else @@ -7482,7 +7466,7 @@ long mem_cgroup_get_nr_swap_pages(struct mem_cgroup *= memcg) { long nr_swap_pages =3D get_nr_swap_pages(); =20 - if (!memcg_swap_enabled() || !cgroup_subsys_on_dfl(memory_cgrp_subsys)) + if (mem_cgroup_disabled() || do_memsw_account()) return nr_swap_pages; for (; memcg !=3D root_mem_cgroup; memcg =3D parent_mem_cgroup(memcg)) nr_swap_pages =3D min_t(long, nr_swap_pages, @@ -7499,7 +7483,7 @@ bool mem_cgroup_swap_full(struct folio *folio) =20 if (vm_swap_full()) return true; - if (!memcg_swap_enabled() || !cgroup_subsys_on_dfl(memory_cgrp_subsys)) + if (do_memsw_account()) return false; =20 memcg =3D folio_memcg(folio); @@ -7519,10 +7503,9 @@ bool mem_cgroup_swap_full(struct folio *folio) =20 static int __init setup_swap_account(char *s) { - bool res; - - if (!kstrtobool(s, &res)) - cgroup_memory_noswap =3D !res; + pr_warn_once("The swapaccount=3D commandline option is deprecated. " + "Please report your usecase to linux-mm@kvack.org if you " + "depend on this functionality.\n"); return 1; } __setup("swapaccount=3D", setup_swap_account); @@ -7791,24 +7774,11 @@ static struct cftype zswap_files[] =3D { }; #endif /* CONFIG_MEMCG_KMEM && CONFIG_ZSWAP */ =20 -/* - * If mem_cgroup_swap_init() is implemented as a subsys_initcall() - * instead of a core_initcall(), this could mean cgroup_memory_noswap still - * remains set to false even when memcg is disabled via "cgroup_disable=3D= memory" - * boot parameter. This may result in premature OOPS inside - * mem_cgroup_get_nr_swap_pages() function in corner cases. - */ static int __init mem_cgroup_swap_init(void) { - /* No memory control -> no swap control */ if (mem_cgroup_disabled()) - cgroup_memory_noswap =3D true; - - if (cgroup_memory_noswap) return 0; =20 - static_branch_enable(&memcg_swap_enabled_key); - WARN_ON(cgroup_add_dfl_cftypes(&memory_cgrp_subsys, swap_files)); WARN_ON(cgroup_add_legacy_cftypes(&memory_cgrp_subsys, memsw_files)); #if defined(CONFIG_MEMCG_KMEM) && defined(CONFIG_ZSWAP) @@ -7816,6 +7786,6 @@ static int __init mem_cgroup_swap_init(void) #endif return 0; } -core_initcall(mem_cgroup_swap_init); +subsys_initcall(mem_cgroup_swap_init); =20 #endif /* CONFIG_MEMCG_SWAP */ --=20 2.37.3 From nobody Mon Apr 6 11:52:06 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D8EBFC07E9D for ; Mon, 26 Sep 2022 15:15:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236076AbiIZPPL (ORCPT ); Mon, 26 Sep 2022 11:15:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236222AbiIZPOT (ORCPT ); Mon, 26 Sep 2022 11:14:19 -0400 Received: from mail-qk1-x730.google.com (mail-qk1-x730.google.com [IPv6:2607:f8b0:4864:20::730]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4CE557D1CC for ; Mon, 26 Sep 2022 06:57:17 -0700 (PDT) Received: by mail-qk1-x730.google.com with SMTP id c19so4099221qkm.7 for ; Mon, 26 Sep 2022 06:57:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=nxWlvz8nHKxF79bLiRXoWvFCmNni5yV7mxHmCxzwA1c=; b=Pm8S7GcSFRJWTzik7LhbfogyC+//ZqsABilFvcQgI1rbJfqhpFRdanL1+GHXzprwnB rX2IGIitEbL0wUDSi9cTNbod47SaPSyBy1s2M/5H5oBEUnarJed+X2kV8S+NiGjcxDM2 vyiCvtjy2NTBluE9HJcH16mhvyA2bKbIXJVu1otPRo9tqdUIPRMnydMZ/oIzuoWf11ut +nM6kLfw8XCbjB5tY3+nupim51GjwAgoM6PbDihvDKfLcwrDvb6/cuOqvgB8YzwSaOsa psRi+d0w+GC+hRxyaO6MjNfx63poKtPW1lqwUQp53OOsA/8Eh8fpODIaU+m2krXZThHf NCJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=nxWlvz8nHKxF79bLiRXoWvFCmNni5yV7mxHmCxzwA1c=; b=uoyufhJC9lKhVDXJYBw5GBC44eHiUSflejDsQcAJQYm7oTAQqbC68iy2tIbxX5511e fqB8XDOW5StX6Ol7y0st7ZUS8PmFifk9dS7Hm0VopRrhRdyIybBK+sMdEq2nKFRKW4hj DTjyaWZGvK2BCCFSLClYCFU3f8/GilCt45wJhoDY7+/r8HW/lb3cQ8/ZJ7SGQKCqiVpl Il9bGn4BKsMnF9aj7I73izCs/bPIhno5HsgWsN4fTe48t1u8fUkn3HyXuhlpWABxu2w2 SJl08CK1EwA3JgphdKnRDLPjn7LLusdNSDKzk2WiE2XC+TyKg8003upiIiIBPU6HhHpt Kywg== X-Gm-Message-State: ACrzQf26SqnUQjGX5pkS98mgWL7N5tNLWSEiroAE2HbcF2JmQrtLI0ED joMIhL0/vL2sK/lSf53YtG29uQ== X-Google-Smtp-Source: AMsMyM5O56YPOTRdHT3lUuv+iV2e4l+65dldttI4qaDrt0US4VeJH9VyMv8TwUNBtUP9qPXPOLlhbA== X-Received: by 2002:a05:620a:1b9b:b0:6cf:3c66:8e47 with SMTP id dv27-20020a05620a1b9b00b006cf3c668e47mr14337449qkb.478.1664200636452; Mon, 26 Sep 2022 06:57:16 -0700 (PDT) Received: from localhost (2603-7000-0c01-2716-9175-2920-760a-79fa.res6.spectrum.com. [2603:7000:c01:2716:9175:2920:760a:79fa]) by smtp.gmail.com with ESMTPSA id k15-20020a05620a0b8f00b006cf3592cc20sm10804639qkh.55.2022.09.26.06.57.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Sep 2022 06:57:16 -0700 (PDT) From: Johannes Weiner To: Andrew Morton Cc: Shakeel Butt , Michal Hocko , Roman Gushchin , Hugh Dickins , linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/4] mm: memcontrol: use do_memsw_account() in a few more places Date: Mon, 26 Sep 2022 09:57:03 -0400 Message-Id: <20220926135704.400818-4-hannes@cmpxchg.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220926135704.400818-1-hannes@cmpxchg.org> References: <20220926135704.400818-1-hannes@cmpxchg.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" It's slightly more descriptive and consistent with other places that distinguish cgroup1's combined memory+swap accounting scheme from cgroup2's dedicated swap accounting. Signed-off-by: Johannes Weiner Acked-by: Shakeel Butt --- mm/memcontrol.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 4be1b48b9659..76bb0a18a2f3 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -1667,17 +1667,17 @@ unsigned long mem_cgroup_get_max(struct mem_cgroup = *memcg) { unsigned long max =3D READ_ONCE(memcg->memory.max); =20 - if (cgroup_subsys_on_dfl(memory_cgrp_subsys)) { - if (mem_cgroup_swappiness(memcg)) - max +=3D min(READ_ONCE(memcg->swap.max), - (unsigned long)total_swap_pages); - } else { /* v1 */ + if (do_memsw_account()) { if (mem_cgroup_swappiness(memcg)) { /* Calculate swap excess capacity from memsw limit */ unsigned long swap =3D READ_ONCE(memcg->memsw.max) - max; =20 max +=3D min(swap, (unsigned long)total_swap_pages); } + } else { + if (mem_cgroup_swappiness(memcg)) + max +=3D min(READ_ONCE(memcg->swap.max), + (unsigned long)total_swap_pages); } return max; } @@ -7334,7 +7334,7 @@ void mem_cgroup_swapout(struct folio *folio, swp_entr= y_t entry) if (mem_cgroup_disabled()) return; =20 - if (cgroup_subsys_on_dfl(memory_cgrp_subsys)) + if (!do_memsw_account()) return; =20 memcg =3D folio_memcg(folio); @@ -7399,7 +7399,7 @@ int __mem_cgroup_try_charge_swap(struct folio *folio,= swp_entry_t entry) struct mem_cgroup *memcg; unsigned short oldid; =20 - if (!cgroup_subsys_on_dfl(memory_cgrp_subsys)) + if (do_memsw_account()) return 0; =20 memcg =3D folio_memcg(folio); @@ -7451,10 +7451,10 @@ void __mem_cgroup_uncharge_swap(swp_entry_t entry, = unsigned int nr_pages) memcg =3D mem_cgroup_from_id(id); if (memcg) { if (!mem_cgroup_is_root(memcg)) { - if (cgroup_subsys_on_dfl(memory_cgrp_subsys)) - page_counter_uncharge(&memcg->swap, nr_pages); - else + if (do_memsw_account()) page_counter_uncharge(&memcg->memsw, nr_pages); + else + page_counter_uncharge(&memcg->swap, nr_pages); } mod_memcg_state(memcg, MEMCG_SWAP, -nr_pages); mem_cgroup_id_put_many(memcg, nr_pages); --=20 2.37.3 From nobody Mon Apr 6 11:52:06 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1568FC07E9D for ; Mon, 26 Sep 2022 15:15:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235551AbiIZPPQ (ORCPT ); Mon, 26 Sep 2022 11:15:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236228AbiIZPOU (ORCPT ); Mon, 26 Sep 2022 11:14:20 -0400 Received: from mail-qt1-x829.google.com (mail-qt1-x829.google.com [IPv6:2607:f8b0:4864:20::829]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 109977E30D for ; Mon, 26 Sep 2022 06:57:18 -0700 (PDT) Received: by mail-qt1-x829.google.com with SMTP id y2so4111366qtv.5 for ; Mon, 26 Sep 2022 06:57:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=X0S0bdsMSZwjlbQsv+GYht3cMFqf9TlaOrFi2tt0ZUE=; b=ivgKMYEx6KKFhpp8wNE19iM09oj8t0G7ajjdlApXiV8dHxl6sdRPZlL3sNkFlSDNwy rnXLGG7lYYJAxGKw1r/ekzCIehnIVG05fD84xOZnCYJ98uQr0VSqu4gi3uFUuh/7uMYt odr+evVu3To0Y90IeM8RLSdC8kXkAJV9dsY3cmFWEcyVPtDrJuPsRKaLmE6gFZ28BSIc ovC/udwIpbLSyiJdrqlUZu9ncSBsbrTC2ca1wRvfr87LNGa+OY4lP8zmbXErXnQCfk08 t9y3dA2dkaXRSH3P2RHybF9daxj+aOSeam6tQeY7J+TPfzO+K56S2MduhvUdrFpDD51K xVsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=X0S0bdsMSZwjlbQsv+GYht3cMFqf9TlaOrFi2tt0ZUE=; b=gdjGB5E4bAjj7peZI6e7PfetQWXVNjATGCu+kAn0/i9ndPrbJFlqCiPNmYw4pQKKTX MXJJs5d0cGwjqmPU+xgl2IgrRBSUaCq7SoWLvE43U9cFKMgG5YNgFcQMnXRBclTPuNte 7rUTi1Hij9JJxds00lnx2XstI7i/kkMVsSyCSfAXuCUfHsGP2pS7Xam0k7st1YhPXuRL XFLrIsaN9EPGFcTLbwNV4pjyIspW6skVgDyNfsKwDdk2BhRQkKoFw1gPkm0FmKGWNZGZ wPIvYliTVlruV/VJFqqmFBqFoGyemD/EKEug/z7MSBSvez/Prtdt+W9HRvC+h4LSHxzn OQbQ== X-Gm-Message-State: ACrzQf1N92CIFDFWUAOUY1klNpQSK9SSdv+tUg/4xloYivFLzFUjdBX9 6rTPjC8201JCqsBw/1l/7Uq0qg== X-Google-Smtp-Source: AMsMyM7Ul5O43S3u/fkDoFtmHr+YA4o1q3LjljR0Uy16ObfFPlUp15Qpp7LaXeGU4Il4nCoBD2Oe0A== X-Received: by 2002:ac8:7d4c:0:b0:35c:c979:dc17 with SMTP id h12-20020ac87d4c000000b0035cc979dc17mr18455434qtb.271.1664200637789; Mon, 26 Sep 2022 06:57:17 -0700 (PDT) Received: from localhost (2603-7000-0c01-2716-9175-2920-760a-79fa.res6.spectrum.com. [2603:7000:c01:2716:9175:2920:760a:79fa]) by smtp.gmail.com with ESMTPSA id az35-20020a05620a172300b0069fe1dfbeffsm11925212qkb.92.2022.09.26.06.57.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Sep 2022 06:57:17 -0700 (PDT) From: Johannes Weiner To: Andrew Morton Cc: Shakeel Butt , Michal Hocko , Roman Gushchin , Hugh Dickins , linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/4] mm: memcontrol: drop dead CONFIG_MEMCG_SWAP config symbol Date: Mon, 26 Sep 2022 09:57:04 -0400 Message-Id: <20220926135704.400818-5-hannes@cmpxchg.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220926135704.400818-1-hannes@cmpxchg.org> References: <20220926135704.400818-1-hannes@cmpxchg.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Since 2d1c498072de ("mm: memcontrol: make swap tracking an integral part of memory control"), CONFIG_MEMCG_SWAP hasn't been a user-visible config option anymore, it just means CONFIG_MEMCG && CONFIG_SWAP. Update the sites accordingly and drop the symbol. [ While touching the docs, remove two references to CONFIG_MEMCG_KMEM, which hasn't been a user-visible symbol for over half a decade. ] Signed-off-by: Johannes Weiner Acked-by: Shakeel Butt --- Documentation/admin-guide/cgroup-v1/memory.rst | 4 +--- arch/mips/configs/db1xxx_defconfig | 1 - arch/mips/configs/generic_defconfig | 1 - arch/powerpc/configs/powernv_defconfig | 1 - arch/powerpc/configs/pseries_defconfig | 1 - arch/sh/configs/sdk7786_defconfig | 1 - arch/sh/configs/urquell_defconfig | 1 - include/linux/swap.h | 2 +- include/linux/swap_cgroup.h | 4 ++-- init/Kconfig | 5 ----- mm/Makefile | 4 +++- mm/memcontrol.c | 6 +++--- tools/testing/selftests/cgroup/config | 1 - 13 files changed, 10 insertions(+), 22 deletions(-) diff --git a/Documentation/admin-guide/cgroup-v1/memory.rst b/Documentation= /admin-guide/cgroup-v1/memory.rst index 2cc502a75ef6..5b86245450bd 100644 --- a/Documentation/admin-guide/cgroup-v1/memory.rst +++ b/Documentation/admin-guide/cgroup-v1/memory.rst @@ -299,7 +299,7 @@ Per-node-per-memcgroup LRU (cgroup's private LRU) is gu= arded by lruvec->lru_lock; PG_lru bit of page->flags is cleared before isolating a page from its LRU under lruvec->lru_lock. =20 -2.7 Kernel Memory Extension (CONFIG_MEMCG_KMEM) +2.7 Kernel Memory Extension ----------------------------------------------- =20 With the Kernel memory extension, the Memory Controller is able to limit @@ -386,8 +386,6 @@ limit, and "K" the kernel limit. There are three possib= le ways limits can be =20 a. Enable CONFIG_CGROUPS b. Enable CONFIG_MEMCG -c. Enable CONFIG_MEMCG_SWAP (to use swap extension) -d. Enable CONFIG_MEMCG_KMEM (to use kmem extension) =20 3.1. Prepare the cgroups (see cgroups.txt, Why are cgroups needed?) ------------------------------------------------------------------- diff --git a/arch/mips/configs/db1xxx_defconfig b/arch/mips/configs/db1xxx_= defconfig index b8bd66300996..83cbdecb27e6 100644 --- a/arch/mips/configs/db1xxx_defconfig +++ b/arch/mips/configs/db1xxx_defconfig @@ -9,7 +9,6 @@ CONFIG_HIGH_RES_TIMERS=3Dy CONFIG_LOG_BUF_SHIFT=3D16 CONFIG_CGROUPS=3Dy CONFIG_MEMCG=3Dy -CONFIG_MEMCG_SWAP=3Dy CONFIG_BLK_CGROUP=3Dy CONFIG_CGROUP_SCHED=3Dy CONFIG_CFS_BANDWIDTH=3Dy diff --git a/arch/mips/configs/generic_defconfig b/arch/mips/configs/generi= c_defconfig index 714169e411cf..48e4e251779b 100644 --- a/arch/mips/configs/generic_defconfig +++ b/arch/mips/configs/generic_defconfig @@ -3,7 +3,6 @@ CONFIG_NO_HZ_IDLE=3Dy CONFIG_IKCONFIG=3Dy CONFIG_IKCONFIG_PROC=3Dy CONFIG_MEMCG=3Dy -CONFIG_MEMCG_SWAP=3Dy CONFIG_BLK_CGROUP=3Dy CONFIG_CFS_BANDWIDTH=3Dy CONFIG_RT_GROUP_SCHED=3Dy diff --git a/arch/powerpc/configs/powernv_defconfig b/arch/powerpc/configs/= powernv_defconfig index 49f49c263935..4acca5263404 100644 --- a/arch/powerpc/configs/powernv_defconfig +++ b/arch/powerpc/configs/powernv_defconfig @@ -17,7 +17,6 @@ CONFIG_LOG_CPU_MAX_BUF_SHIFT=3D13 CONFIG_NUMA_BALANCING=3Dy CONFIG_CGROUPS=3Dy CONFIG_MEMCG=3Dy -CONFIG_MEMCG_SWAP=3Dy CONFIG_CGROUP_SCHED=3Dy CONFIG_CGROUP_FREEZER=3Dy CONFIG_CPUSETS=3Dy diff --git a/arch/powerpc/configs/pseries_defconfig b/arch/powerpc/configs/= pseries_defconfig index b571d084c148..fead14ebb1fc 100644 --- a/arch/powerpc/configs/pseries_defconfig +++ b/arch/powerpc/configs/pseries_defconfig @@ -16,7 +16,6 @@ CONFIG_LOG_CPU_MAX_BUF_SHIFT=3D13 CONFIG_NUMA_BALANCING=3Dy CONFIG_CGROUPS=3Dy CONFIG_MEMCG=3Dy -CONFIG_MEMCG_SWAP=3Dy CONFIG_CGROUP_SCHED=3Dy CONFIG_CGROUP_FREEZER=3Dy CONFIG_CPUSETS=3Dy diff --git a/arch/sh/configs/sdk7786_defconfig b/arch/sh/configs/sdk7786_de= fconfig index a8662b6927ec..97b7356639ed 100644 --- a/arch/sh/configs/sdk7786_defconfig +++ b/arch/sh/configs/sdk7786_defconfig @@ -16,7 +16,6 @@ CONFIG_CPUSETS=3Dy # CONFIG_PROC_PID_CPUSET is not set CONFIG_CGROUP_CPUACCT=3Dy CONFIG_CGROUP_MEMCG=3Dy -CONFIG_CGROUP_MEMCG_SWAP=3Dy CONFIG_CGROUP_SCHED=3Dy CONFIG_RT_GROUP_SCHED=3Dy CONFIG_BLK_CGROUP=3Dy diff --git a/arch/sh/configs/urquell_defconfig b/arch/sh/configs/urquell_de= fconfig index cb2f56468fe0..be478f3148f2 100644 --- a/arch/sh/configs/urquell_defconfig +++ b/arch/sh/configs/urquell_defconfig @@ -14,7 +14,6 @@ CONFIG_CPUSETS=3Dy # CONFIG_PROC_PID_CPUSET is not set CONFIG_CGROUP_CPUACCT=3Dy CONFIG_CGROUP_MEMCG=3Dy -CONFIG_CGROUP_MEMCG_SWAP=3Dy CONFIG_CGROUP_SCHED=3Dy CONFIG_RT_GROUP_SCHED=3Dy CONFIG_BLK_DEV_INITRD=3Dy diff --git a/include/linux/swap.h b/include/linux/swap.h index fc8d98660326..a18cf4b7c724 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -666,7 +666,7 @@ static inline void folio_throttle_swaprate(struct folio= *folio, gfp_t gfp) cgroup_throttle_swaprate(&folio->page, gfp); } =20 -#ifdef CONFIG_MEMCG_SWAP +#if defined(CONFIG_MEMCG) && defined(CONFIG_SWAP) void mem_cgroup_swapout(struct folio *folio, swp_entry_t entry); int __mem_cgroup_try_charge_swap(struct folio *folio, swp_entry_t entry); static inline int mem_cgroup_try_charge_swap(struct folio *folio, diff --git a/include/linux/swap_cgroup.h b/include/linux/swap_cgroup.h index a12dd1c3966c..ae73a87775b3 100644 --- a/include/linux/swap_cgroup.h +++ b/include/linux/swap_cgroup.h @@ -4,7 +4,7 @@ =20 #include =20 -#ifdef CONFIG_MEMCG_SWAP +#if defined(CONFIG_MEMCG) && defined(CONFIG_SWAP) =20 extern unsigned short swap_cgroup_cmpxchg(swp_entry_t ent, unsigned short old, unsigned short new); @@ -40,6 +40,6 @@ static inline void swap_cgroup_swapoff(int type) return; } =20 -#endif /* CONFIG_MEMCG_SWAP */ +#endif =20 #endif /* __LINUX_SWAP_CGROUP_H */ diff --git a/init/Kconfig b/init/Kconfig index 532362fcfe31..7d86cf6b3012 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -958,11 +958,6 @@ config MEMCG help Provides control over the memory footprint of tasks in a cgroup. =20 -config MEMCG_SWAP - bool - depends on MEMCG && SWAP - default y - config MEMCG_KMEM bool depends on MEMCG && !SLOB diff --git a/mm/Makefile b/mm/Makefile index cc23b0052584..8e105e5b3e29 100644 --- a/mm/Makefile +++ b/mm/Makefile @@ -98,7 +98,9 @@ obj-$(CONFIG_DEVICE_MIGRATION) +=3D migrate_device.o obj-$(CONFIG_TRANSPARENT_HUGEPAGE) +=3D huge_memory.o khugepaged.o obj-$(CONFIG_PAGE_COUNTER) +=3D page_counter.o obj-$(CONFIG_MEMCG) +=3D memcontrol.o vmpressure.o -obj-$(CONFIG_MEMCG_SWAP) +=3D swap_cgroup.o +ifdef CONFIG_SWAP +obj-$(CONFIG_MEMCG) +=3D swap_cgroup.o +endif obj-$(CONFIG_CGROUP_HUGETLB) +=3D hugetlb_cgroup.o obj-$(CONFIG_GUP_TEST) +=3D gup_test.o obj-$(CONFIG_MEMORY_FAILURE) +=3D memory-failure.o diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 76bb0a18a2f3..61e05fc281fb 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -3423,7 +3423,7 @@ void split_page_memcg(struct page *head, unsigned int= nr) css_get_many(&memcg->css, nr - 1); } =20 -#ifdef CONFIG_MEMCG_SWAP +#ifdef CONFIG_SWAP /** * mem_cgroup_move_swap_account - move swap charge and swap_cgroup's recor= d. * @entry: swap entry to be moved @@ -7296,7 +7296,7 @@ static int __init mem_cgroup_init(void) } subsys_initcall(mem_cgroup_init); =20 -#ifdef CONFIG_MEMCG_SWAP +#ifdef CONFIG_SWAP static struct mem_cgroup *mem_cgroup_id_get_online(struct mem_cgroup *memc= g) { while (!refcount_inc_not_zero(&memcg->id.ref)) { @@ -7788,4 +7788,4 @@ static int __init mem_cgroup_swap_init(void) } subsys_initcall(mem_cgroup_swap_init); =20 -#endif /* CONFIG_MEMCG_SWAP */ +#endif /* CONFIG_SWAP */ diff --git a/tools/testing/selftests/cgroup/config b/tools/testing/selftest= s/cgroup/config index 84fe884fad86..97d549ee894f 100644 --- a/tools/testing/selftests/cgroup/config +++ b/tools/testing/selftests/cgroup/config @@ -4,5 +4,4 @@ CONFIG_CGROUP_FREEZER=3Dy CONFIG_CGROUP_SCHED=3Dy CONFIG_MEMCG=3Dy CONFIG_MEMCG_KMEM=3Dy -CONFIG_MEMCG_SWAP=3Dy CONFIG_PAGE_COUNTER=3Dy --=20 2.37.3