From patchwork Mon Sep 26 13:57:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Weiner X-Patchwork-Id: 12988720 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 CE514C32771 for ; Mon, 26 Sep 2022 13:57:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5725F8E0052; Mon, 26 Sep 2022 09:57:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4FA628E0047; Mon, 26 Sep 2022 09:57:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 34D738E0052; Mon, 26 Sep 2022 09:57:16 -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 26A3C8E0047 for ; Mon, 26 Sep 2022 09:57:16 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id EE7EB140264 for ; Mon, 26 Sep 2022 13:57:15 +0000 (UTC) X-FDA: 79954388430.02.4B9D7A2 Received: from mail-qv1-f53.google.com (mail-qv1-f53.google.com [209.85.219.53]) by imf03.hostedemail.com (Postfix) with ESMTP id 9896520004 for ; Mon, 26 Sep 2022 13:57:14 +0000 (UTC) Received: by mail-qv1-f53.google.com with SMTP id g4so4351004qvo.3 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=Hv4QohTyCZdRCFlCIlsRo5VWsxR1gzxAuVld6vEKbUE6h8mVLj9cHB/UUjLQE1BIo7 OIsSM44ZT0J2W8O+3SMKjtdrRD3DalXF9nP+RhkP0H9BlulFEYrEVLvBErGf4oU67uMR JVEJR7M3F26jlYLncYvtExEC84axhUUBp2Ekrd/d2zvOdCaD+viJTgR+RQ7v2Zs/VN9z 4UgXRg8TIpLpKbafZ+HZ428HB0/F5peVTCgeZ1IdA9gQYuP62jUPhmaaat+LPwggodH9 oc8gQeEBm6dkT0FHgjrziNt+w3JPYeWAqBCVTK8u61XfP2thhUcDH43fo0y/5S9oeKp8 bpNg== X-Gm-Message-State: ACrzQf3/TSPAxi+QMtdMyased3zo7TXsvNxwmN0D9967/0+APMhnBUch 9oZiteFljrSda4KZIegnVPbWPA== 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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1664200634; 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=+6iJEmxp4bl9ohblP/ldB8IdtUPtHQigooDS1dl/Wc4=; b=CPHdSTdOstEp16cglGkBtKGOc2O0ZaxdkP9EwjPCXJXmBri4JMfOTt54UA3S+LuD+Y7VhF 9aRpFw38lfx6wTUy+NE+j9nnWujx4BeHw75DdvY7O6iLzIFXccLwQhEBlWQgG6s0Bv4VvM rsu37sfguY4EHZSDYqmfBk1uWIlkr2Y= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=cmpxchg-org.20210112.gappssmtp.com header.s=20210112 header.b=etTRTh75; dmarc=pass (policy=none) header.from=cmpxchg.org; spf=pass (imf03.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.219.53 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1664200634; a=rsa-sha256; cv=none; b=MUnYDwlATiuklOFqstW2UbZ2QTcxcm77mO9nPa4lBdPHCGZ92Gb/39QWzOUV6Ymxk7/BCL Q9P6EwPK8J9SzJcICs0gyPAgKf6UEq4AzL5sI5jZyMKu3urXNmLAowpy+oRxhWS0hfXJ0E GBM1x7TlWMTQQcGXAhYWlUwvHrOM/r0= X-Rspam-User: Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=cmpxchg-org.20210112.gappssmtp.com header.s=20210112 header.b=etTRTh75; dmarc=pass (policy=none) header.from=cmpxchg.org; spf=pass (imf03.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.219.53 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 9896520004 X-Stat-Signature: uwggyhhm385d3cqxfpp3wwrymosgoqke X-HE-Tag: 1664200634-40827 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: 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=0 (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 of 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, unsigned int nr_pages) struct mem_cgroup *memcg; unsigned short id; + if (mem_cgroup_disabled()) + return; + id = swap_cgroup_record(entry, 0, nr_pages); rcu_read_lock(); memcg = 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_pages) unsigned long length; struct swap_cgroup_ctrl *ctrl; + if (mem_cgroup_disabled()) + return 0; + length = DIV_ROUND_UP(max_pages, SC_PER_PAGE); array = vcalloc(length, sizeof(void *)); @@ -204,6 +207,9 @@ void swap_cgroup_swapoff(int type) unsigned long i, length; struct swap_cgroup_ctrl *ctrl; + if (mem_cgroup_disabled()) + return; + mutex_lock(&swap_cgroup_mutex); ctrl = &swap_cgroup_ctrl[type]; map = ctrl->map;