From patchwork Sun Jun 25 14:28:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abel Wu X-Patchwork-Id: 13292001 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 081CB63BD for ; Sun, 25 Jun 2023 14:29:20 +0000 (UTC) Received: from mail-ot1-x329.google.com (mail-ot1-x329.google.com [IPv6:2607:f8b0:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E2D9D3 for ; Sun, 25 Jun 2023 07:29:19 -0700 (PDT) Received: by mail-ot1-x329.google.com with SMTP id 46e09a7af769-6b74b37fbe0so73340a34.1 for ; Sun, 25 Jun 2023 07:29:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1687703359; x=1690295359; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=TGKSvilmZgPJXmejRM2lBTN0K9/2tgMZGylX16m+j6g=; b=eG2+tYqWkPkRCKS2RqWlEWAPeVeLRLXmJgJx4B9MSOk2J+FsmkJeEiMFUA6KvpbbCr 89LyphI33da0F/giPdABa5kExZR8OYAsgy2vh6TTPohdM7/mDDY59lwOBYhzfAZGp30D 05pvyoXfP1v6weRD8GBJFn77jPCHxgvEBe4tRKrmVB99zADfpEQj9rgiQSB4nWZARxBJ iugI3imnns3+ApJ9CMskLtS5DWhnJubAU58LcP/z9QP9bpnq/Uer7js5m5TVx2r4pZLD 9dBPFp5TTAK7U6Hbyi7hFev30VCCcg47CUJ0RupDMTD90mAWngVaaxqxkRgiGVjgjUqd gIpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687703359; x=1690295359; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=TGKSvilmZgPJXmejRM2lBTN0K9/2tgMZGylX16m+j6g=; b=dEXMk5hPwErRhqEmZFolPTo4qP31t3UKSLJE3Zkt1uwWH8Su9qNUBgaaX2tEwB4eAu cgRyGj0v3+Ihm90cZpg4cszRPLbDnjWI39PSM5hqvYOBOdb1czEcSkWQ9yx4j+h2zAYR LejyIla4Hn+AVVF2rXNYAx4G3W4nwbIdQ+nonIE9sXOGkfnaF3TilgmhjBataAumwtgA sgHARPAnmfiAfp2rAvBC7MkDyBIkmmC3deEA4/ESs+cmAU3UBe0WlU21lxFKXCMh81G0 1+Y7d5fLPezzmMGXH3LuUNmE2DsAzGZmHuYwuk6PnpyTZjLFUPOwEaV4blUNFIKeGCQJ +m7g== X-Gm-Message-State: AC+VfDxYO05BM4MC8daKNTmARS1WXb5REBIAgVuhYN5f0Icyau9Pdvbo goW00YjSndzCd1G2u6c12yiGFg== X-Google-Smtp-Source: ACHHUZ5ORDdc7sTEUz6Kzs7YToDfn6ptrUe/hYZt5RefjV2u7D3+JoGbfaDk2v3JXbuijopR6K45tQ== X-Received: by 2002:a05:6808:3098:b0:398:55ff:1fb8 with SMTP id bl24-20020a056808309800b0039855ff1fb8mr33372212oib.37.1687703358696; Sun, 25 Jun 2023 07:29:18 -0700 (PDT) Received: from C02DV8HUMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id 29-20020a17090a195d00b0025ef39c0f87sm2980744pjh.0.2023.06.25.07.29.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Jun 2023 07:29:18 -0700 (PDT) From: Abel Wu To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Johannes Weiner , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song , Andrew Morton , David Ahern , Yosry Ahmed , "Matthew Wilcox (Oracle)" , Yu Zhao , Abel Wu , Kuniyuki Iwashima , Alexei Starovoitov , Martin KaFai Lau , Alexander Mikhalitsyn , Breno Leitao , David Howells , Jason Xing , Xin Long Cc: Michal Hocko , linux-kernel@vger.kernel.org (open list), netdev@vger.kernel.org (open list:NETWORKING [GENERAL]), cgroups@vger.kernel.org (open list:CONTROL GROUP - MEMORY RESOURCE CONTROLLER (MEMCG)), linux-mm@kvack.org (open list:CONTROL GROUP - MEMORY RESOURCE CONTROLLER (MEMCG)) Subject: [PATCH net-next 1/2] net-memcg: Scopify the indicators of sockmem pressure Date: Sun, 25 Jun 2023 22:28:10 +0800 Message-Id: <20230625142820.47185-1-wuyun.abel@bytedance.com> X-Mailer: git-send-email 2.37.3 Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org Now there are two indicators of socket memory pressure sit inside struct mem_cgroup, socket_pressure and tcpmem_pressure. When in legacy mode aka. cgroupv1, the socket memory is charged into a separate counter memcg->tcpmem rather than ->memory, so the reclaim pressure of the memcg has nothing to do with socket's pressure at all. While for default mode, the ->tcpmem is simply not used. So {socket,tcpmem}_pressure are only used in default/legacy mode respectively. This patch fixes the pieces of code that make mixed use of both. Signed-off-by: Abel Wu --- include/linux/memcontrol.h | 4 ++-- mm/vmpressure.c | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 222d7370134c..9b1b536b4ec9 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -1743,8 +1743,8 @@ void mem_cgroup_sk_alloc(struct sock *sk); void mem_cgroup_sk_free(struct sock *sk); static inline bool mem_cgroup_under_socket_pressure(struct mem_cgroup *memcg) { - if (!cgroup_subsys_on_dfl(memory_cgrp_subsys) && memcg->tcpmem_pressure) - return true; + if (!cgroup_subsys_on_dfl(memory_cgrp_subsys)) + return !!memcg->tcpmem_pressure; do { if (time_before(jiffies, READ_ONCE(memcg->socket_pressure))) return true; diff --git a/mm/vmpressure.c b/mm/vmpressure.c index b52644771cc4..22c6689d9302 100644 --- a/mm/vmpressure.c +++ b/mm/vmpressure.c @@ -244,6 +244,14 @@ void vmpressure(gfp_t gfp, struct mem_cgroup *memcg, bool tree, if (mem_cgroup_disabled()) return; + /* + * The in-kernel users only care about the reclaim efficiency + * for this @memcg rather than the whole subtree, and there + * isn't and won't be any in-kernel user in a legacy cgroup. + */ + if (!cgroup_subsys_on_dfl(memory_cgrp_subsys) && !tree) + return; + vmpr = memcg_to_vmpressure(memcg); /* From patchwork Sun Jun 25 14:28:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abel Wu X-Patchwork-Id: 13292002 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 402AD613E for ; Sun, 25 Jun 2023 14:29:40 +0000 (UTC) Received: from mail-pg1-x533.google.com (mail-pg1-x533.google.com [IPv6:2607:f8b0:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9FC21EE for ; Sun, 25 Jun 2023 07:29:36 -0700 (PDT) Received: by mail-pg1-x533.google.com with SMTP id 41be03b00d2f7-54fb3c168fcso2118307a12.0 for ; Sun, 25 Jun 2023 07:29:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1687703376; x=1690295376; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VJ3Ti/D8S3EnbGsOdGwNu9kTjaPf3p14ktWAeREbOBA=; b=R76JOrQ1dPo/73QodWvkhogr6Xt3xbQEkJkqTXvgiKUM710so38qio0hXQtzJsCbye O64gRUD8e4b7zMBLCa8BCFkjiCVBuoelt8Lz44yLSCENsHauLJ5VAqcybrk7HI43XjZJ xw1A0f0eaZzKR/Ar36Kqyfhr3MjK8BgRBvHCT8PoFVrsUtlG8ClolFEc1xl4ajF7FpQ4 jG1bDDFxEkF4PmsG5MN5jtqcIgZemQAg42B1hTpu7CQnS5UpXJ+RqiyD5oKIhLIk3DKX 7lQZBR+vpTUq2cMa25g5g10YhFZV5+0w3BEdk2HvIp0mOd/DI175m+zpOf8KM/i3awwh RfiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687703376; x=1690295376; 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:message-id:reply-to; bh=VJ3Ti/D8S3EnbGsOdGwNu9kTjaPf3p14ktWAeREbOBA=; b=R6sUs7bpiP2XYODrXd50zfPFDkQslOPiBPiuzZVBrSY6R6t7evuHsd2c0XKqZxkeUP QEsUG9G6AfrBpDFfaDJF/r6Vx/3UhDR/HuQmJAVcM2b5n6cmj1mxCcAYfAy+7KFrJgT7 OXMJDiGyDVuHbFJGr86Wd0TZDZAAXrgMLG/ZVglUWHnEpViUifHdzFWxq7YiacBS7vfU nLCb4ymALgUrUbXwnMJC4bMS7BPdxjRH5/UjwMNCeFKqewIdzW3Am2rFctJTBn+PVbwS nFNcs/Zevv4lgtHBjj8EQ8G0YkOK223YlHx0pmNks7iY1eTsvkMa764HKwCiHMKp2gEg lT4Q== X-Gm-Message-State: AC+VfDyhmytppVabyqhKUA1vs6S+HBjZ1RyinaOxGgNSgxPi88wHZx85 N2lIXxl628tHS1Nff24/PApgeA== X-Google-Smtp-Source: ACHHUZ4HqtHP/zbYUeJtO1vXlwl9dfUGTA5Z2y9D1QGuKBCZoms2r2/THr49mB8kg8U5Z9mw09DG5Q== X-Received: by 2002:a17:90b:4b4c:b0:25b:eeb3:adc4 with SMTP id mi12-20020a17090b4b4c00b0025beeb3adc4mr26482189pjb.15.1687703376138; Sun, 25 Jun 2023 07:29:36 -0700 (PDT) Received: from C02DV8HUMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id 29-20020a17090a195d00b0025ef39c0f87sm2980744pjh.0.2023.06.25.07.29.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Jun 2023 07:29:35 -0700 (PDT) From: Abel Wu To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Johannes Weiner , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song , Andrew Morton , David Ahern , Yosry Ahmed , Yu Zhao , "Matthew Wilcox (Oracle)" , Kuniyuki Iwashima , Martin KaFai Lau , Alexander Mikhalitsyn , Breno Leitao , David Howells , Jason Xing , Xin Long Cc: Abel Wu , Michal Hocko , linux-kernel@vger.kernel.org (open list), netdev@vger.kernel.org (open list:NETWORKING [GENERAL]), cgroups@vger.kernel.org (open list:CONTROL GROUP - MEMORY RESOURCE CONTROLLER (MEMCG)), linux-mm@kvack.org (open list:CONTROL GROUP - MEMORY RESOURCE CONTROLLER (MEMCG)) Subject: [PATCH net-next 2/2] net-memcg: Remove redundant tcpmem_pressure Date: Sun, 25 Jun 2023 22:28:11 +0800 Message-Id: <20230625142820.47185-2-wuyun.abel@bytedance.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20230625142820.47185-1-wuyun.abel@bytedance.com> References: <20230625142820.47185-1-wuyun.abel@bytedance.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org As {socket,tcpmem}_pressure are only used in default/legacy mode respectively, use socket_pressure instead of tcpmem_pressure in all kinds of cgroup hierarchies. Signed-off-by: Abel Wu --- include/linux/memcontrol.h | 3 +-- mm/memcontrol.c | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 9b1b536b4ec9..05e9fb5fa08d 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -288,7 +288,6 @@ struct mem_cgroup { /* Legacy tcp memory accounting */ bool tcpmem_active; - int tcpmem_pressure; #ifdef CONFIG_MEMCG_KMEM int kmemcg_id; @@ -1744,7 +1743,7 @@ void mem_cgroup_sk_free(struct sock *sk); static inline bool mem_cgroup_under_socket_pressure(struct mem_cgroup *memcg) { if (!cgroup_subsys_on_dfl(memory_cgrp_subsys)) - return !!memcg->tcpmem_pressure; + return !!memcg->socket_pressure; do { if (time_before(jiffies, READ_ONCE(memcg->socket_pressure))) return true; diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 4b27e245a055..76c4e5c6e558 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -7337,10 +7337,10 @@ bool mem_cgroup_charge_skmem(struct mem_cgroup *memcg, unsigned int nr_pages, struct page_counter *fail; if (page_counter_try_charge(&memcg->tcpmem, nr_pages, &fail)) { - memcg->tcpmem_pressure = 0; + memcg->socket_pressure = 0; return true; } - memcg->tcpmem_pressure = 1; + memcg->socket_pressure = 1; if (gfp_mask & __GFP_NOFAIL) { page_counter_charge(&memcg->tcpmem, nr_pages); return true;