From patchwork Tue May 30 11:40:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abel Wu X-Patchwork-Id: 13259793 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 18823C77B73 for ; Tue, 30 May 2023 11:40:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 44B426B0074; Tue, 30 May 2023 07:40:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3FAC56B0075; Tue, 30 May 2023 07:40:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2C2B1900002; Tue, 30 May 2023 07:40:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 1F4456B0074 for ; Tue, 30 May 2023 07:40:37 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id B6E421401D5 for ; Tue, 30 May 2023 11:40:36 +0000 (UTC) X-FDA: 80846728872.25.8FD27E9 Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) by imf15.hostedemail.com (Postfix) with ESMTP id BB7DFA0017 for ; Tue, 30 May 2023 11:40:34 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=hhLQ3LoK; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf15.hostedemail.com: domain of wuyun.abel@bytedance.com designates 209.85.210.173 as permitted sender) smtp.mailfrom=wuyun.abel@bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1685446834; 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=zSeZy3dBgM/hAvW1l4S3j81M4ry+F3vLfbl4Wg72DeY=; b=huhgklOj9u8QTC4x0gIqAgA+3Pc/2XS2YZDOZ1IhermK29/y14hTO328VdAvUs+Lv/Jv+v wwxTVd93Jm8m2n5mQxiJQH3ZAHbSlMBBAkplSYSizBnTBMK87pWmKqUxZkZ2L69EOKhV2A jR+LWH0XtQ9aHYXEG+ckoYF+FR9Ms2M= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=hhLQ3LoK; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf15.hostedemail.com: domain of wuyun.abel@bytedance.com designates 209.85.210.173 as permitted sender) smtp.mailfrom=wuyun.abel@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1685446834; a=rsa-sha256; cv=none; b=IrdPuyVAf0JsKU//uSLGTwc5URhs3ksta84Bfd7NCF75ZU40dGpVD5rqvbUg/UZN/9ebZh QJUPAk67HwosFQetEB/olaKcCoolfJrMeS/fPQlOyZUOoFd2VR3bmAOeK5iYBjDP7/fSMK EFjyZBsaRrR++hJj/n4CTIil48JQZPE= Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-64d5b4c3ffeso3113963b3a.2 for ; Tue, 30 May 2023 04:40:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1685446833; x=1688038833; 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=zSeZy3dBgM/hAvW1l4S3j81M4ry+F3vLfbl4Wg72DeY=; b=hhLQ3LoKBaJEJ5y7uGQ1a6tBrIrMZV+1pnIfqUg+3PPYZLcdnc+7VDqo7mmHd61hrj Sd4swO79Q16159eQDWb/4DVkqYPSM/uwLu9+nrIMavuQvSS0iMMA2tKxbWYOLOTyMNNW 8Q9YqbEBpn+Nx2pNK4smxSztJf5X5kZARTJKBTBELw90yTB1VKCkqnwAR8Px/p/KKR7V fOhc0w5nYnh7RRxeDgcc3lEBrXih07VolZo5Ebp7QGT1yNFQEfcQDeiZsXJhF9CLMeJk SavXV7b4KyPrvCtY6W/D4aQTnvHV5HjuN8C1ttrCgPPMzrSoHBP01IYNksy9EhRLI1EZ mTeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685446833; x=1688038833; 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=zSeZy3dBgM/hAvW1l4S3j81M4ry+F3vLfbl4Wg72DeY=; b=Qgm36iIJGJ4l6gB9RgOTcLeh8Ch1fKBuc5K4FH+VcMbUpKJ+XRrkHcuG/w/4Cv10iL KB3CevdB+1nBZ2y4XhUYyyCkM57cSb/mQ2cv6V1c7fIgdN2ZzOeU4SL7ViLY0ttADBj5 Q2F/ekDNWR1kMKg0yxRrrXjhbVxo1bEDKqzHdpifmS5opl2w9i0YXGsZ/VR8mz/syNx/ /EnNIKayc14lzns0GkzL/MiOWN+9NtzGM2ylZpb2q6qOlIYB8vr0BJZZsNIsNE2GACta JSjgJcrdp2JMzoiADxb4Y1yWe7CpZI1QKiRfAnQibqQHoMJfesSg/FsjdBWa/mCck0My FNFA== X-Gm-Message-State: AC+VfDzRcFR7r+b1hILMd84RBOTdmxzB09PvBbXP7rG95w84e4OQHr3y YQEIe7BGZtu1RMgHhjCdaHjLTQ== X-Google-Smtp-Source: ACHHUZ4xzkdDhUOHefB08/7eoqUUKTgwsuecz4t21GvJg0uPWZgET1FRSQPRi1s3ik542LqiUkJgag== X-Received: by 2002:a05:6a20:8e14:b0:103:b0f9:7110 with SMTP id y20-20020a056a208e1400b00103b0f97110mr2307010pzj.11.1685446833446; Tue, 30 May 2023 04:40:33 -0700 (PDT) Received: from C02DV8HUMD6R.bytedance.net ([203.208.167.147]) by smtp.gmail.com with ESMTPSA id j20-20020aa78dd4000000b00642ea56f06fsm1515103pfr.0.2023.05.30.04.40.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 04:40:32 -0700 (PDT) From: Abel Wu To: "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Johannes Weiner , Michal Hocko , Vladimir Davydov , Shakeel Butt , Muchun Song Cc: Simon Horman , netdev@vger.kernel.org, linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Abel Wu Subject: [PATCH v4 1/4] net-memcg: Fold dependency into memcg pressure cond Date: Tue, 30 May 2023 19:40:08 +0800 Message-Id: <20230530114011.13368-2-wuyun.abel@bytedance.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20230530114011.13368-1-wuyun.abel@bytedance.com> References: <20230530114011.13368-1-wuyun.abel@bytedance.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: BB7DFA0017 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: tptgm3x1pcrdc9i31pbu9dydatau5ejg X-HE-Tag: 1685446834-169015 X-HE-Meta: U2FsdGVkX18pZ9gimLUHPXe6exhTjkI4bIBmLiMdC2fM8fNmPgS7CVFvOd7f2VfstgR+gkCoWDigE72SO1gkMIRJgOVYHeRFbSOO2l3YA6FMVAw+hbCvudrGKSay4sIulLtLl2hgEgHlSuCryhtNWUU83ZhzspD4pZ5TlfeGcGUbH4cy5LCa7ovOf9Y5+whn+UAQjCMEm7PRSjNGQzGt315ZGyneHmQHptm3yyZcCDBxs324xVouLjhAr1KS5Qzi2s+MU6nUdxB+MYf3gh4tHQCvDCd/SXCqbdLea9CrJ9ug6zOWacpAPHxVuOaKOSPBnDmoq2YXfHJi/nNG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ZqAcT29rPVj2Pwt0Owd6/66nDVrt5nr0eIv+y6l+u0ufj/LdB3pFQxtgtCs24YKouinNcI= 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: The callers of mem_cgroup_under_socket_pressure() should always make sure that (mem_cgroup_sockets_enabled && sk->sk_memcg) is true. So instead of coding around all the callsites, put the dependencies into mem_cgroup_under_socket_pressure() to avoid redundancy and possibly bugs. This change might also introduce slight function call overhead *iff* the function gets expanded in the future. But for now this change doesn't make binaries different (checked by vimdiff) except the one net/ipv4/tcp_input.o (by scripts/bloat-o-meter), which is probably negligible to performance: add/remove: 0/0 grow/shrink: 1/2 up/down: 5/-5 (0) Function old new delta tcp_grow_window 573 578 +5 tcp_try_rmem_schedule 1083 1081 -2 tcp_check_space 324 321 -3 Total: Before=44647, After=44647, chg +0.00% So folding the dependencies into mem_cgroup_under_socket_pressure() is generally a good thing and provides better readablility. Signed-off-by: Abel Wu --- include/linux/memcontrol.h | 2 ++ include/net/sock.h | 3 +-- include/net/tcp.h | 3 +-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 222d7370134c..a1aead140ff8 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -1743,6 +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 (!mem_cgroup_sockets_enabled || !memcg) + return false; if (!cgroup_subsys_on_dfl(memory_cgrp_subsys) && memcg->tcpmem_pressure) return true; do { diff --git a/include/net/sock.h b/include/net/sock.h index 8b7ed7167243..641c9373b44b 100644 --- a/include/net/sock.h +++ b/include/net/sock.h @@ -1414,8 +1414,7 @@ static inline bool sk_under_memory_pressure(const struct sock *sk) if (!sk->sk_prot->memory_pressure) return false; - if (mem_cgroup_sockets_enabled && sk->sk_memcg && - mem_cgroup_under_socket_pressure(sk->sk_memcg)) + if (mem_cgroup_under_socket_pressure(sk->sk_memcg)) return true; return !!*sk->sk_prot->memory_pressure; diff --git a/include/net/tcp.h b/include/net/tcp.h index 04a31643cda3..3c5e3718b454 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -261,8 +261,7 @@ extern unsigned long tcp_memory_pressure; /* optimized version of sk_under_memory_pressure() for TCP sockets */ static inline bool tcp_under_memory_pressure(const struct sock *sk) { - if (mem_cgroup_sockets_enabled && sk->sk_memcg && - mem_cgroup_under_socket_pressure(sk->sk_memcg)) + if (mem_cgroup_under_socket_pressure(sk->sk_memcg)) return true; return READ_ONCE(tcp_memory_pressure); From patchwork Tue May 30 11:40:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abel Wu X-Patchwork-Id: 13259794 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 5E80FC7EE23 for ; Tue, 30 May 2023 11:40:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BC8136B0075; Tue, 30 May 2023 07:40:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B765D900002; Tue, 30 May 2023 07:40:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A63FC6B007B; Tue, 30 May 2023 07:40:42 -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 98EE96B0075 for ; Tue, 30 May 2023 07:40:42 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 610E9A01F5 for ; Tue, 30 May 2023 11:40:42 +0000 (UTC) X-FDA: 80846729124.01.B5D1C16 Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) by imf20.hostedemail.com (Postfix) with ESMTP id 77D711C0014 for ; Tue, 30 May 2023 11:40:40 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=XUY6RCnc; spf=pass (imf20.hostedemail.com: domain of wuyun.abel@bytedance.com designates 209.85.210.180 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=1685446840; 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=7JbrrHsu8KzXBp8abtNpZsLO9DbdsQWsXzCPkkoYMdc=; b=nMO9htCOW+NbrJCEZzHGWM0nOrbuIQfpz5sS4T+cuizhZ23jFtKE7DAxB7yYHl5kACezQl sB27WLxN8ahWngLE1c4KB8zsN6bfdl5pHuyFVRgG/8/GRaOnpQOsXscc0mDLQCt3QM1suS 8dAnICAi0bePHJfxqYEpPFTXZSXh0ts= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=XUY6RCnc; spf=pass (imf20.hostedemail.com: domain of wuyun.abel@bytedance.com designates 209.85.210.180 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=1685446840; a=rsa-sha256; cv=none; b=aIikwA6eyt8ePXHaQ+Z9pdn9ExIbp7+9SBumXWDpKcdGfU+K5802l99BlA+f7plFVNhu5I ffTTAcWJns/WCgRbUrAKTrnuketFZrLIw35IefIfjWgWq81ycmuqw5tRN9zKglt1VwCGXu QGWHD2gkEz3vNus+WvfCeUHmdypPLpU= Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-64d2b42a8f9so3373361b3a.3 for ; Tue, 30 May 2023 04:40:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1685446839; x=1688038839; 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=7JbrrHsu8KzXBp8abtNpZsLO9DbdsQWsXzCPkkoYMdc=; b=XUY6RCnc6d+7un5QD7wAiC5Pb7wzmwMI4vRo1wJc4PF0bSz7lhpfuw5w2hLGZ7RA/3 n332Bt+Pe4lAngq6WuKUDTougZGEtz32pIJU7zKJ8QTXJ5ViSZGmOERloMz4QRJYUPXH hsv0l3Khpa0C5xc3NS3GzMJDoOmmkOVJ01kqthm/kqhC6JK6gClKXL3r+jLADDxhzx9e f8NGSVpHLSwGsRh54M1XlrCzSrhEhoysZtz/ipf9w+BGN8Jbp6s9IBTI7fqTjtdWxouD Z3Xw+ieXdkIIETN2bAKZUVTNN+xCGvn93OegJEeKCcXmPMVmn2p4opliPA/APLsYLQee burg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685446839; x=1688038839; 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=7JbrrHsu8KzXBp8abtNpZsLO9DbdsQWsXzCPkkoYMdc=; b=cxGYybndaLgya0JgShhypxsRtaK8b/9XgBwXn0+91ZDHAsgTgpNweVGl5uATS5GK0P /2HBsq1EdTT3fE8qS6Yk3vB+7NP+JIDcuHRuqCy4osqgPjEkmaA7fHkq/OJWSUfdCRsJ uulz4m5T4v1t1dp6RjYiZBh/GTl8WlXXqKGjlDw9fEhwvyUiiD0N5HBBU+xteoXrHRdO YIpJYjvlVZrF1UL8F735IhwmBt2z0hBQDO6q7bBYIojXZei/MIeBALj1XRlri7HxETa5 lRABZ1iWNbAvnrNUMALzVtGQjl/xGaH6kBwwhTR+tp20srX1SviyAS/0P5VjDDq3CtKX n28A== X-Gm-Message-State: AC+VfDxNqqpwOeEqu7iRhxnUKBBphLoddT0MXaxe4OW1w6DmhFlkpZ/z Lxm8qFRiDF9eCTuEWFrDIAQE8g== X-Google-Smtp-Source: ACHHUZ5emuULCTRsl8IAfWUHF9798CEwa7RQFgXH9Xp8NT+z0Zduzv+V05AvK7LnBc/h3VKpGHIubA== X-Received: by 2002:a05:6a20:9151:b0:10c:71de:5dc5 with SMTP id x17-20020a056a20915100b0010c71de5dc5mr2593508pzc.30.1685446839327; Tue, 30 May 2023 04:40:39 -0700 (PDT) Received: from C02DV8HUMD6R.bytedance.net ([203.208.167.147]) by smtp.gmail.com with ESMTPSA id j20-20020aa78dd4000000b00642ea56f06fsm1515103pfr.0.2023.05.30.04.40.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 04:40:38 -0700 (PDT) From: Abel Wu To: "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Johannes Weiner , Michal Hocko , Vladimir Davydov , Shakeel Butt , Muchun Song Cc: Simon Horman , netdev@vger.kernel.org, linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Abel Wu Subject: [PATCH v4 2/4] sock: Always take memcg pressure into consideration Date: Tue, 30 May 2023 19:40:09 +0800 Message-Id: <20230530114011.13368-3-wuyun.abel@bytedance.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20230530114011.13368-1-wuyun.abel@bytedance.com> References: <20230530114011.13368-1-wuyun.abel@bytedance.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 77D711C0014 X-Rspam-User: X-Stat-Signature: iiwrr3s3ur5c77cxbzbhrfnzyk8y7okk X-Rspamd-Server: r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M3OD65r+3Xp9aB3MDgCfCWRVyB9RNEE997e99KwwVJOK9o0K6y6paxyyW6Ba8uKyq2Ld2SMVj2kpD6MlJ63kooXpmdwDx951LhkqCjkpTcatG0gtC42+CeAmLfcaNObpI1Da09AY68lsyDxOiJOCq7Sl6CN9B8Malh+mL5GiZom/3ygMhq7PNmazy1IFG6upC4fpTtCpcVuZ/zdsI04+ucFLMysITf99W0t8HjDDBR8c7/ozILHGmsAwAvgiZSjmXauzVxTqUbEXF4uwiwHiQ4khRS6b2cprcE3eTgcWkjGzDxZa6PCPl2Rpg2EYvukDqbgGXOLGj91WzaMu5U36pX1TOBOYeyKWG9EoKbiT6Otcg2RTrGTDsj6KjMDHZqCNkdwcwyFzN2vpC5o7BKeUSlr8LHeUgY1g1B4Hy+JpuNfq/errQOuf8kN4OVNjydw+wyGFFcoFZ2z3xtPVdQipCCm/yLHU7KJmr5fJBxfv3g8qGugWlzazuJ1e+7xPVkC5n8zut2gg== 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: The sk_under_memory_pressure() is called to check whether there is memory pressure related to this socket. But now it ignores the net- memcg's pressure if the proto of the socket doesn't care about the global pressure, which may put burden on its memcg compaction or reclaim path (also remember that socket memory is un-reclaimable). So always check the memcg's vm status to alleviate memstalls when it's in pressure. Signed-off-by: Abel Wu --- include/net/sock.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/include/net/sock.h b/include/net/sock.h index 641c9373b44b..b0e5533e5909 100644 --- a/include/net/sock.h +++ b/include/net/sock.h @@ -1411,13 +1411,11 @@ static inline bool sk_has_memory_pressure(const struct sock *sk) static inline bool sk_under_memory_pressure(const struct sock *sk) { - if (!sk->sk_prot->memory_pressure) - return false; - if (mem_cgroup_under_socket_pressure(sk->sk_memcg)) return true; - return !!*sk->sk_prot->memory_pressure; + return sk->sk_prot->memory_pressure && + *sk->sk_prot->memory_pressure; } static inline long From patchwork Tue May 30 11:40: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: 13259795 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 4BC28C7EE23 for ; Tue, 30 May 2023 11:40:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CFD556B0078; Tue, 30 May 2023 07:40:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CADCB900002; Tue, 30 May 2023 07:40:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B75DD6B007D; Tue, 30 May 2023 07:40:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id A56E56B0078 for ; Tue, 30 May 2023 07:40:49 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 77E8D1601A2 for ; Tue, 30 May 2023 11:40:49 +0000 (UTC) X-FDA: 80846729418.08.0E0D87E Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) by imf08.hostedemail.com (Postfix) with ESMTP id 85FD216000A for ; Tue, 30 May 2023 11:40:46 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=MLCKl3On; spf=pass (imf08.hostedemail.com: domain of wuyun.abel@bytedance.com designates 209.85.210.169 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=1685446846; 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=RMeJmdZ3LE5akFulN2YKZF3yDR93Nfz5GrpK/FAs6Mo=; b=NQIoCZbwXlm+6bzxFwKDHqrw8Pcc2NSgF6Nj5ODXYs2Jm7+Ps/UOLnMs08D5qvBX+mVFvK 3ZtD1wlUK2DJwjQChvo9U4Tm+opAA/G8F885tncWTWL6NOsL1h71ISiRw7xQ46LNIOK4EQ z+64JNBbJwvy5nF5aW9PRC1KZpZgAAs= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1685446846; a=rsa-sha256; cv=none; b=7Zi1VFkuULCBdOq2lvztqaywMe1yEMmIW7Ghbl3H4rDJBqK+Okvz/HQSMzI6iqAUsrPOLp /zBZL1lGSTkbdbwAVq0PpSH6CICeVZcdlQzTtQZC+qThSGdJoRaWTboCNnH7QT+LwiqEoU mZ2UzgC2sv9luCU+YJBbY7/Z3QQUMDo= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=MLCKl3On; spf=pass (imf08.hostedemail.com: domain of wuyun.abel@bytedance.com designates 209.85.210.169 as permitted sender) smtp.mailfrom=wuyun.abel@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-64d3e5e5980so5033371b3a.2 for ; Tue, 30 May 2023 04:40:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1685446845; x=1688038845; 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=RMeJmdZ3LE5akFulN2YKZF3yDR93Nfz5GrpK/FAs6Mo=; b=MLCKl3OnqWHHyXcRdZaVayKCzY/Bl9wft7bDvD2wXODqoMTB/13VogpAknl5CPMsXy wPBLqktlL943IhkSBca1F/4EKfZGosHuGtUVdAkmBtNQRexyuge61JELuTrFyQTGDioc F0+b378M/Xr6NaH/X+q+yQL1JQ/nwwtFEKWza3rDI41G736sUwtprZHvXv+Sux07oy6G fAZMZSW2ZMmZCDiyKMZRxpfS15mP7ANNqmo2OSU7cqlFHCIbN4eBKRCfszo0suTUZ7wg rjPsmbI5Fxu5tY3g9Zhpc4nPO8DVN9OKcwpkE9piTLUZvZs5e+AEoecTNY5JWmxU1rCO 9ANw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685446845; x=1688038845; 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=RMeJmdZ3LE5akFulN2YKZF3yDR93Nfz5GrpK/FAs6Mo=; b=Rr4ltJ+6F7/kq1uIENtfvDfRTdpSaHvH6oEGgCuM0Nn+fQ0eVKxKWWJfQP7uYzdGME tPyObWo3qrJO1Ljll/1a+1+l5Hpu51QIhUD/9ihlTzKTLfrE0f7rpH5sy38El4CNDwrx t91W1Clrb2J5RKQgyu0HMxBcN4cxIBkCwyEfuP9oEhlYYo/Kp060g5u0K493c/ahXDS5 xrBSXJByjTveesdHjBBa7iEZ7/Wf3Easal2I2y1ZpEMixQQJGXz+qGTixxeMDfPhgzdi BmZJ1/FUHhiyn7Onfz7nUO22AWmoqttwNR43oJ/bMtv9oP2VBeOksz4GGSxnB025b+yz buRQ== X-Gm-Message-State: AC+VfDzwpVTSu2Iyc6YSdj9HOSsXjsanah0qUOEAXONBmJR1AQDQgUlk o7LutdcRg1wYUJ/IKSDYd5lB5g== X-Google-Smtp-Source: ACHHUZ4FxxxoqYMoybqsRIkoNDdsA2hhrYAf6bOI8yODoZkUkDER+ZRyPtG6yvCay1gYPFhUPVfCzQ== X-Received: by 2002:a05:6a20:bea6:b0:10c:3cf3:ef7e with SMTP id gf38-20020a056a20bea600b0010c3cf3ef7emr1747230pzb.42.1685446845141; Tue, 30 May 2023 04:40:45 -0700 (PDT) Received: from C02DV8HUMD6R.bytedance.net ([203.208.167.147]) by smtp.gmail.com with ESMTPSA id j20-20020aa78dd4000000b00642ea56f06fsm1515103pfr.0.2023.05.30.04.40.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 04:40:44 -0700 (PDT) From: Abel Wu To: "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Johannes Weiner , Michal Hocko , Vladimir Davydov , Shakeel Butt , Muchun Song Cc: Simon Horman , netdev@vger.kernel.org, linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Abel Wu Subject: [PATCH v4 3/4] sock: Fix misuse of sk_under_memory_pressure() Date: Tue, 30 May 2023 19:40:10 +0800 Message-Id: <20230530114011.13368-4-wuyun.abel@bytedance.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20230530114011.13368-1-wuyun.abel@bytedance.com> References: <20230530114011.13368-1-wuyun.abel@bytedance.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 85FD216000A X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: r43rz7qdidukwrw9ezya6so59dir4akj X-HE-Tag: 1685446846-462224 X-HE-Meta: U2FsdGVkX1/niC3ZHH3566r3Ut7R5isbsxgDWkOztrJGVSqhrVCm39UFlIsWdnR+UOtjND3Jlr9qH6oO01zF2o5qxvElLSY8nFBLzkKauyabWC4kS71CUleC55uClHemTCD2D8hMAXdS9nUGtn+3BlWC12s65Wi0E2O/lTc01dk139zqhw/k0MaXvjccOM594xQhnJWin0G16HKn+ESodpehjUbwO0xsOlfQgrNLXnvE6YMYsreRwiBUobK8++MxX0iWJxXcLhbZ2zGiWuaEvCmIEGHBXh7j/FNQr1GkPtR9tRFTapm6WD2XzrLnyrZIeBevsfguu0bIffpZ21Rt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WoFJiQbnDjKRSNvfby5HU9zConLfQAL826tYqh6SkbEkTkzvuNRaSZP4hYJTQfxQzd6MuKBU7Y3XtgckDq/Rc4ucG4WKy0nwvGqL+pl6VoCuBiEbYwyhc0UJHcC8rPkxfqxIlJ6Uqygdh82qPvW+sZlBt1X8u5EcFhulLEI1yDiSJlAzroZOB9ZAWmSzix/o= 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: The status of global socket memory pressure is updated when: a) __sk_mem_raise_allocated(): enter: sk_memory_allocated(sk) > sysctl_mem[1] leave: sk_memory_allocated(sk) <= sysctl_mem[0] b) __sk_mem_reduce_allocated(): leave: sk_under_memory_pressure(sk) && sk_memory_allocated(sk) < sysctl_mem[0] So the conditions of leaving global pressure are inconstant, which may lead to the situation that one pressured net-memcg prevents the global pressure from being cleared when there is indeed no global pressure, thus the global constrains are still in effect unexpectedly on the other sockets. This patch fixes this by ignoring the net-memcg's pressure when deciding whether should leave global memory pressure. Fixes: e1aab161e013 ("socket: initial cgroup code.") Signed-off-by: Abel Wu --- include/net/sock.h | 9 +++++++-- net/core/sock.c | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/include/net/sock.h b/include/net/sock.h index b0e5533e5909..257706710be5 100644 --- a/include/net/sock.h +++ b/include/net/sock.h @@ -1409,13 +1409,18 @@ static inline bool sk_has_memory_pressure(const struct sock *sk) return sk->sk_prot->memory_pressure != NULL; } +static inline bool sk_under_global_memory_pressure(const struct sock *sk) +{ + return sk->sk_prot->memory_pressure && + *sk->sk_prot->memory_pressure; +} + static inline bool sk_under_memory_pressure(const struct sock *sk) { if (mem_cgroup_under_socket_pressure(sk->sk_memcg)) return true; - return sk->sk_prot->memory_pressure && - *sk->sk_prot->memory_pressure; + return sk_under_global_memory_pressure(sk); } static inline long diff --git a/net/core/sock.c b/net/core/sock.c index 5440e67bcfe3..801df091e37a 100644 --- a/net/core/sock.c +++ b/net/core/sock.c @@ -3095,7 +3095,7 @@ void __sk_mem_reduce_allocated(struct sock *sk, int amount) if (mem_cgroup_sockets_enabled && sk->sk_memcg) mem_cgroup_uncharge_skmem(sk->sk_memcg, amount); - if (sk_under_memory_pressure(sk) && + if (sk_under_global_memory_pressure(sk) && (sk_memory_allocated(sk) < sk_prot_mem_limits(sk, 0))) sk_leave_memory_pressure(sk); } From patchwork Tue May 30 11:40: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: 13259796 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 EF8C3C77B73 for ; Tue, 30 May 2023 11:40:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 709C36B007B; Tue, 30 May 2023 07:40:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6B9FF6B007D; Tue, 30 May 2023 07:40:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 533CF6B007E; Tue, 30 May 2023 07:40:54 -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 448C36B007B for ; Tue, 30 May 2023 07:40:54 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id F0369120209 for ; Tue, 30 May 2023 11:40:53 +0000 (UTC) X-FDA: 80846729586.12.18E557F Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) by imf26.hostedemail.com (Postfix) with ESMTP id 05EDD140024 for ; Tue, 30 May 2023 11:40:51 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=btr0FoS+; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf26.hostedemail.com: domain of wuyun.abel@bytedance.com designates 209.85.210.180 as permitted sender) smtp.mailfrom=wuyun.abel@bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1685446852; 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=RnVh2joarXNT9aj52CHZE7i4DFTKtYVUHBE2hndAHFM=; b=3QjWSOIa22kq2m7dgOvNHMJfyPhOZ0jpcHETiR5WomAI0K2vfcCZtnji4Q7Y7d+j0Os8JX eapi6cRF+NyoNX7zILkG4vaIm6/8Sv9ZG52ht5/Rl210+fhQsfvt9h6FhhGfuHBeZVCdwg 7KsqME8ZXco7zwqbnkosbhsuzpo0pxc= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=btr0FoS+; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf26.hostedemail.com: domain of wuyun.abel@bytedance.com designates 209.85.210.180 as permitted sender) smtp.mailfrom=wuyun.abel@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1685446852; a=rsa-sha256; cv=none; b=IqTPYxgQ5XEf5N7wqgFXhnIhDoQvFrRGqZKpOYVG5GRBuvwRXR0UDX5SeByiqmeWW66ZOM MiIpYkaLV0XrXLP/AaCBsQks4ctGuWKBYfFvi27X1rabHfOBnSimdaETjUpwNjcaHouoiE R72xjB/DjViyHvkkaF/uw2YKAu7GqWg= Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-64d3fbb8c1cso4828380b3a.3 for ; Tue, 30 May 2023 04:40:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1685446851; x=1688038851; 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=RnVh2joarXNT9aj52CHZE7i4DFTKtYVUHBE2hndAHFM=; b=btr0FoS+C6fgN8Erg41EU1t5DJZD+PGpyR8bakM6GW+5ICYCzcrthDnH/6xVPa+R/Q wG33TV1SZXTSdoEBPSuVByreJr8Gqe+O51Rrgz9Y73Q9ejyvJRjXK5eIT9djyPPlFgvb 7yjesf0wmL+VpcChkGgR+xTrD7A7FInxqIyHcX7V0kBikEvD+Gcmwvvj1tjFmu6SjTWU 1mtHFPzNab3djs/NQuIwpZKWzAqcOIj7G4B3U0h+DRCca2OlBrJX+tqBNTydDQfcbJO7 DKVs5NHggfUWPYEokBru5ocQ0Gp4jvD47OV3sXrkPMdZtcuktJf9yWqNjhJ2I4I7b8BW 09mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685446851; x=1688038851; 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=RnVh2joarXNT9aj52CHZE7i4DFTKtYVUHBE2hndAHFM=; b=Zk6MfDx0QuGILCee9nWYrcQPh+sqP4fBkDL/EboeyUOFJNTXupaJWzKtOgQrQSHIEz 5c1tG0voFJwV1Mvpry2XJa9Komb1yZhmqaTVxr7OCXtugXKNt5WzZKAFS7FjLXwIwnWn FziOp1VJlggJuTeEJC4Bvj+h3ITSjK+Bm7mbzPIDobZ5m3AxUXkV9AgOfGOXQ5216XCM 8hxAkrDFgbuUIjIWSqk1Q2NZDSTG8m9kEV9IuZbdkPkUDVpHN2ap4Rxsl5BnEs4n4YhZ OZTiDKyiEE2oXyPZzItVjcO25VI8lRdkxyXFI/YjeSgVamGtJfYzXURVsGI5iPKFh6uP /qXg== X-Gm-Message-State: AC+VfDzWJZaFKxMYGp8vf2qOGZbEXcK6+IPUtmSpCA6UEisySad1ffvF WDifgQnRA3xzehJuHu0nk+MUHQ== X-Google-Smtp-Source: ACHHUZ7/L6D/t8C+fhV1v7/kaE8Q+tmoGMGurwakklgYU2DF5zQp3EuB0WovCQ651Y9p7EeFL5iXhA== X-Received: by 2002:a05:6a00:b81:b0:643:5d7a:a898 with SMTP id g1-20020a056a000b8100b006435d7aa898mr2408213pfj.0.1685446850941; Tue, 30 May 2023 04:40:50 -0700 (PDT) Received: from C02DV8HUMD6R.bytedance.net ([203.208.167.147]) by smtp.gmail.com with ESMTPSA id j20-20020aa78dd4000000b00642ea56f06fsm1515103pfr.0.2023.05.30.04.40.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 04:40:50 -0700 (PDT) From: Abel Wu To: "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Johannes Weiner , Michal Hocko , Vladimir Davydov , Shakeel Butt , Muchun Song Cc: Simon Horman , netdev@vger.kernel.org, linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Abel Wu Subject: [PATCH v4 4/4] sock: Remove redundant cond of memcg pressure Date: Tue, 30 May 2023 19:40:11 +0800 Message-Id: <20230530114011.13368-5-wuyun.abel@bytedance.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20230530114011.13368-1-wuyun.abel@bytedance.com> References: <20230530114011.13368-1-wuyun.abel@bytedance.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 05EDD140024 X-Stat-Signature: 4smpp3zjx6ejrwj4m3q8knepxo964jj7 X-HE-Tag: 1685446851-871495 X-HE-Meta: U2FsdGVkX1/Bk2tm/hmdzt4ep+Y1BIvVHHhxK+x7jzoN7Bc/aKsVSGGuWjuEbW4aLaUwJqr1BiLZeJfhBokY8HQxRFT/gjYHB8RJ3Cf2umc2Xw/WjPA/7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W6qQRoPDr0GJv/sObpNXhYEywd7xOgMC7sKaY2RxMG8DN/AcGDaSuhZKkXjOeHx96sf6RTRivzlzxC2Zlc2nZLoeIhIdvlr36llGMuLnao+oyGxKxZjV54qJE6y0ODvwADhhMm1NoJRMO0Ev84Lld30DmsTYnFCV6568wgK3upgnNVhyTIrK7hYjalnpOLg+7l5lgDoLNJFLY9azUZ09oNrXa2ePXT56FEqT08h0VR1cxXz/u/d9sWpqg0jxRp4TDKcDelzyIp45sgUuN5Cl2fMqJbfK9DC1o= 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 with the previous patch, __sk_mem_raise_allocated() considers the memory pressure of both global and the socket's memcg on a func- wide level, making the condition of memcg's pressure in question redundant. Signed-off-by: Abel Wu --- net/core/sock.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/net/core/sock.c b/net/core/sock.c index 801df091e37a..86735ad2f903 100644 --- a/net/core/sock.c +++ b/net/core/sock.c @@ -3020,9 +3020,15 @@ int __sk_mem_raise_allocated(struct sock *sk, int size, int amt, int kind) if (sk_has_memory_pressure(sk)) { u64 alloc; - if (!sk_under_memory_pressure(sk)) + if (!sk_under_global_memory_pressure(sk)) return 1; + alloc = sk_sockets_allocated_read_positive(sk); + + /* If under global pressure, allow the sockets that are below + * average memory usage to raise, trying to be fair among all + * the sockets under global constrains. + */ if (sk_prot_mem_limits(sk, 2) > alloc * sk_mem_pages(sk->sk_wmem_queued + atomic_read(&sk->sk_rmem_alloc) +