From patchwork Mon Sep 26 13:57:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Weiner X-Patchwork-Id: 12988722 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 79CDAC6FA83 for ; Mon, 26 Sep 2022 13:57:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BDC058E0054; Mon, 26 Sep 2022 09:57:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B3DE98E0047; Mon, 26 Sep 2022 09:57:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 941B88E0054; Mon, 26 Sep 2022 09:57:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 865C58E0047 for ; Mon, 26 Sep 2022 09:57:17 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 6170F12048D for ; Mon, 26 Sep 2022 13:57:17 +0000 (UTC) X-FDA: 79954388514.04.5E3D6DD Received: from mail-qk1-f176.google.com (mail-qk1-f176.google.com [209.85.222.176]) by imf16.hostedemail.com (Postfix) with ESMTP id 1697218000A for ; Mon, 26 Sep 2022 13:57:16 +0000 (UTC) Received: by mail-qk1-f176.google.com with SMTP id i3so4112063qkl.3 for ; Mon, 26 Sep 2022 06:57:16 -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=RaJHhqiZG61j9dVbBRWuxGBpQi8CJ+BbX10nZ3qUnbVXgQQ0mTiJ4Grl1LPnEl4Ce7 HJwv4y+550YWJrMw1Ytxjs8z9VpqSIcWFL1r2lp1ql+ca32ZFhRpXWIGAv5eBUXxQzms Rm038EqZsHYicHem5cwueV7uNXQRukEMe+hNHXZ6nq783jECiMgDMRpByiwcWVSzJFqR HViYNY1kCC5QS+bT7JJ0ls9d2X6dcq7fqRFMK0KQx3SL9qaEzklax+YHInmYWCSW6cce ZhjkAoLDsLYwpvNN0bh6Cz/y0KdzHqYckXGWI4vkNqd+Yfdb0z55ZdFn09ul1oYb8CTq qPxg== X-Gm-Message-State: ACrzQf1NNR8wtQ5O4/c0E0RI+nwP4WW+KWyGKNA7w7xEC/x8R6PO0trm 6T0tyO9/OS8bh/qAeUk0xFGpNA== 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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1664200637; 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=nxWlvz8nHKxF79bLiRXoWvFCmNni5yV7mxHmCxzwA1c=; b=pexBpqd94Yi5EYV8S0eRTgqfgdAaOSXZYgOzXhMPzkskzaO4RalE+22CXmpjj7vUtwSVoJ oCdWsls/Mj3Odd3wDYxObOm1Fs9jSm6OJpMG3Esce11YcpCdEEkdqeo7LN3bxgYddyqrtw O0u2uS49Qcd2nRencWpw9hcyP+gMiUA= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=cmpxchg-org.20210112.gappssmtp.com header.s=20210112 header.b=Pm8S7GcS; dmarc=pass (policy=none) header.from=cmpxchg.org; spf=pass (imf16.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.222.176 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1664200637; a=rsa-sha256; cv=none; b=Qhg43knEqTtPYwTLhKU57csaajhG1KvgVmcVwwjDmBgac64CI7FDBA7SqI/TQfCcKxf156 Gu57vjFjpMcODWGrdZVShDMSQN9dXJQqwozW5niLh8GyQ5Izb3dqhQTwRfG8N+hchyi37A X8T3+IRcW0ynSjuqr01BSBz/15+T/m0= X-Rspam-User: Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=cmpxchg-org.20210112.gappssmtp.com header.s=20210112 header.b=Pm8S7GcS; dmarc=pass (policy=none) header.from=cmpxchg.org; spf=pass (imf16.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.222.176 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 1697218000A X-Stat-Signature: zfmjxztmzjftt3cff7ou7pm76sag3155 X-HE-Tag: 1664200636-575640 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: 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 = READ_ONCE(memcg->memory.max); - if (cgroup_subsys_on_dfl(memory_cgrp_subsys)) { - if (mem_cgroup_swappiness(memcg)) - max += 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 = READ_ONCE(memcg->memsw.max) - max; max += min(swap, (unsigned long)total_swap_pages); } + } else { + if (mem_cgroup_swappiness(memcg)) + max += 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_entry_t entry) if (mem_cgroup_disabled()) return; - if (cgroup_subsys_on_dfl(memory_cgrp_subsys)) + if (!do_memsw_account()) return; memcg = 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; - if (!cgroup_subsys_on_dfl(memory_cgrp_subsys)) + if (do_memsw_account()) return 0; memcg = folio_memcg(folio); @@ -7451,10 +7451,10 @@ void __mem_cgroup_uncharge_swap(swp_entry_t entry, unsigned int nr_pages) memcg = 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);