From nobody Mon Apr 6 13:30:31 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