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: 13291999 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 1BEE9EB64DC for ; Sun, 25 Jun 2023 14:29:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1FB4E6B0071; Sun, 25 Jun 2023 10:29:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1ABDC6B0072; Sun, 25 Jun 2023 10:29:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 04CCF6B0074; Sun, 25 Jun 2023 10:29:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id E5ED26B0071 for ; Sun, 25 Jun 2023 10:29:22 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id B0CE9C04F8 for ; Sun, 25 Jun 2023 14:29:22 +0000 (UTC) X-FDA: 80941502964.13.55CAE49 Received: from mail-ot1-f46.google.com (mail-ot1-f46.google.com [209.85.210.46]) by imf29.hostedemail.com (Postfix) with ESMTP id 0723A120005 for ; Sun, 25 Jun 2023 14:29:19 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=eG2+tYqW; spf=pass (imf29.hostedemail.com: domain of wuyun.abel@bytedance.com designates 209.85.210.46 as permitted sender) smtp.mailfrom=wuyun.abel@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687703361; a=rsa-sha256; cv=none; b=7BK0YFeS+/WJC5GsuRJPMSpNQY9RUl/Cc9uIvFEc9haX2V4PV48Rjg70ZknTkzlBY7S0Cs WWK56XeaWKSauRBtzPl+JBC/NWLQT5R/lw/HRRF3+Xruj1wxgAxbjWk0LCOpqE6uAW3FoV yIgOk3ISrSKCKrGFz6GmH41Dlzk5va4= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=eG2+tYqW; spf=pass (imf29.hostedemail.com: domain of wuyun.abel@bytedance.com designates 209.85.210.46 as permitted sender) smtp.mailfrom=wuyun.abel@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1687703361; 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:references:dkim-signature; bh=TGKSvilmZgPJXmejRM2lBTN0K9/2tgMZGylX16m+j6g=; b=34lpEc9C5Lyl+lIGDEXmgz3PX6W5pK3ZID35tdvj0sIu3xGlsBOm87KokF1DNvjdHjgQYa /blf3axtyvysXz5j1gKnvJ0BVUjVM+rlZKXgacE45vxlWp6enh6v7GdlP05RWE77j/s/a/ pfwmplGqieWdFr0B06g2uvzdhXpzsRQ= Received: by mail-ot1-f46.google.com with SMTP id 46e09a7af769-6b74b37fbe0so73344a34.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=c/IhCHo9gaAu4TDvEHOBJnyAkGA4tcd5VKjrERKh9ff+t4huRigRp26QJI758GscJZ 7CuxPxP32VZWlN2UXj3HbMiDn1jAGUE2WsnDb7nNeOwbikD4woD+cvhV9cHnrs5Zhf5j ilY2EDrojVYALNnow82KrlxRhAEBdvcZCmW/yAsjEqVn7PFQ/LFh7IviHJqbpehCptA7 F3FkR4ls9D+Ubymk0qZksk/THyR/1P+WHwisQa0wajYxxDgasfAG81iolDPvKmLqc55P oXJc3im3JdUwJDbKK3uuADGDPzf75mkRc3VQZmJoFF3n1lv7Zp83LaUhE8kYAxj2idze vlAQ== X-Gm-Message-State: AC+VfDyGbgmcF7/nWCol/L/o9kjN7pgvtDrsCzDDd112178U15cehMzh SWJEa0RCUt/qP49xwmjPvoYJsw== 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 MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 0723A120005 X-Stat-Signature: 3sg5wuia3539itd5jfzi63nr9tb84upb X-Rspam-User: X-HE-Tag: 1687703359-710225 X-HE-Meta: U2FsdGVkX19Rrs6z+9715WjFRVvn1KVhnYf+2KaZbPQ11ZkAdT2KeuNI2pUsDj2HADHzVXq+Z+qZhYlnwawskbmtvPjnI+qcJQaP4h1Ixa7JSkSX0Qcb7TfMRpq2Q/U4sSp/q2MW0U11ImgRqQDKs8dAxPnYXZrNyTgirM50ypmlNeVDGoMNyOECsp683/Nnfg+Tt1Da2+uBKSqhTG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9id3MUyniA4C8oqXPcmwyFMpHdI1sbYJdTEvy6zfj5D7ILqwbBm3oO/ADA/KJqOdd/H7C+3pfEvQmZxlmgbQu6QoC9jrGxu7fVkT4BIETtS8IkuOPFgwcFdNmELdYOeTH8ZirMfWRjFwhApfXv/V1jVMJ5edfiX/e4opOfD13duzAdxUyf9fBfO4hTOgPmaWIqHX/W0QuBKC9DW2KIW5RphbT168e9keoCuVm5TtsWODGInNEh3AHhzcGQokpJwaheeio1nPg9MaUEWosuhonLASIqiIOWTbMAXIWTTrhVmM64foFDJDMC7yPCPOCAbfAlHy4fzz8sRFfxw53teKAylnBIdyi8xdl1Rc0RXg0sOC+219PVtZP6IWXzGDGJ+193GtF64bhFMyjqi+qD+FJ8IcSA7tU4oevkSs7iK72fF8JPzJ3alr8raM/TRtnUbME7PA4ZHlQlND3DwTZ7vev9Wzw72V25V8Swu95jH+F3D0CM3k0PKQ2c/PmTMkiXNxJnbFrHZR3jEeGgllHaYpHGkkw63O1+7LQAHZ/zAB2IJMzj9T3mTFDqNNdE+OaZLStRqBH++CWNHz87oRApwjj3bZD474HCVSykGC2CNepo1/7T8bgF3NhY8m2LqpQDhauwiNEE1SUqZgoJXMsXMS7kTR9KiUX6M+Lrjsofxpbl65q0s5awSuHPhBe44 40IjB9gY 6U8S8xjRD5BdaaDCzbhvL9HaIWNawB3tQ0tcZbYtSu7Bxc4RKywCkkHohvq9mW9gMuN2QJJ3jCDahgD90Ybhnv1JfFaGs8M8nfkyVApfsFW4qbv5dMcc3pIjYxHH6/X/cKtQPM7ELJS7dD4Zsw02y48MHKsTIpq1V1O3rtTPWje4r4exNChPUuqBRqQ7wNAOmJm1HkKRnmGtI5YrOLmLSNy1HbCp1xOoWcN2sULSgXtZSGlPUXIHSpdU1pZZ661kiatrE4aSTcGqGAm5YA4Y/1jPDN0SV6LTz04w8hPZE+I= 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: 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); /*