Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp294409rdb; Thu, 19 Oct 2023 05:01:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEc6YiyX/EOSk7GRujyNnGwmArdJ2exu5tk5hMReRZjptCqD1pyMVFGn46X6FGTcOGzDeXd X-Received: by 2002:a05:6359:3015:b0:13c:eea2:d021 with SMTP id rf21-20020a056359301500b0013ceea2d021mr1555386rwb.9.1697716895851; Thu, 19 Oct 2023 05:01:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697716895; cv=none; d=google.com; s=arc-20160816; b=tJeH9KEhH8oJKS8wh3Djh0uMHcgAvItNIdWTkENk5c2O04pHIDRso9kqwiyG1EvqK/ qFvcF9IUdESY8AK3lSvNNym10qfcTX6+im+COyoz1I+fWdIOg5Ee5jEgDU37N4UFoXkL 2nbAVNIGE5XJ40rp1gEwSzvuKWrEWTPK+CjZWX7EDV/T+GLhWXLYHj89yRfkPpxkihkQ USroKqd5/xFgiZBuZtHmTF+7RDLSSxmgpHFxBKbsTOAWZ6zi+28EciA781V97ItXSZ7t Qu9m5+nBZRhVPx0xvrhrw+GkDt9RroOpBWP6/8ESdV/vab/uZh63s3/yCpreKZB2/0ab TPsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=b7MqzCn5z9sc3xLiS0TjD71DTwTzVkWYSBF1gVBH140=; fh=NAzjwYjhJuad6Dfdv6L/yFkzoQ/crn31I7NowP28YKE=; b=Y8cDgIPj4rLj5sb3m16b5AQ2ID2f0u/mhvnuj69GNh3zVNoYo90fTXMxSezosNDfk9 6ZrRYEFQ97yu/OG6YS180XkJMZwo2J3AqRRXlaZEWHevCFIWvmHUaPo1jtG/3UV6jzci /RBKU/gcUzjwh8Tt1Gc/ICIq8W0C0D09slqMscPhGdMOtG8FBH1l9Jl7g8MVnBk8n2mV 6riDJTCkj5Zqr9Dfnb733OiShdErR+jOw0xv7rzU5uaN06i2qpsjN71hygcGrNBs+AUP TJq1B3n7CIJjpHO1n+2LP4RqAUOMx8h1JCAmFT4/V1h3kuZpQbpoBCPj3qpQ/M74Ze1N 3GIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=OMaf916y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Return-Path: Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id cw10-20020a056a00450a00b006933c57195esi5868056pfb.399.2023.10.19.05.01.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 05:01:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=OMaf916y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id C2246836D926; Thu, 19 Oct 2023 05:01:29 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345484AbjJSMBS (ORCPT + 99 others); Thu, 19 Oct 2023 08:01:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36246 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235359AbjJSMBO (ORCPT ); Thu, 19 Oct 2023 08:01:14 -0400 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 146A2134 for ; Thu, 19 Oct 2023 05:00:51 -0700 (PDT) Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-1c9de3f66e5so51849505ad.3 for ; Thu, 19 Oct 2023 05:00:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1697716850; x=1698321650; darn=vger.kernel.org; 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=b7MqzCn5z9sc3xLiS0TjD71DTwTzVkWYSBF1gVBH140=; b=OMaf916yBVqlHFe0BwPb3MC3EBkvSDewja2C/2ZXQNEF0wmlvSv/KeErnJavykFCDP 2sxcAYzKW1ate2jGChJBTYzDbYtLqIjXorzW7U5c85Yx+426aPMniBETArpCRgJvSCH/ oXKJAMEbcnvdWjChgddrlUFCxeNk3EguD3y+VrLg1TiJl0ERsAiHcIUHNhHHKZUvbvRQ jUs0sDCaIQe3k7qaSB3hYlppFFB9d+pUFrrkXv0jPvHMggNY94olZmjOWUvXpEcrc6ND NGhhYNVhU1I9azvqi/T2xOS0qX0B87iA+KGW8syXkUHeBJsfk9QoXRX8d04LRIzn/TNV 1msg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697716850; x=1698321650; 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=b7MqzCn5z9sc3xLiS0TjD71DTwTzVkWYSBF1gVBH140=; b=i912we5N82fl+PYOHJ6QYLWDyo7ZlS8Ypp+yrYtaNMEkE6Tv3qXYTHSYl5w0TsERDx sOA5sJRn03izYTo6AtjwZSgmTcWcV4KdqSgFmXS5jY+/PsvXCX1017O2ze6lZ+MzWUJD D7IKVTwHhcYw+VyTYgDUvssblgluySnBMS31qIj9sAwRDcrQ+1dzVPJCSZRCNtrA10tG 0aYn8+ma9jBxN8Oh27MrSuN05/0/SW9DfnyZjigPdq9M1a9DWdXlBeraqmJh0cvFibYe QvAVuvDywwgSwowNS1TCUu9IOpTgpxeNqr315B+npxnR90slUMDCJNePhlacbpi1LJEe Yp0g== X-Gm-Message-State: AOJu0YxaGJeb6QoYyjagbIELhlCRqdzXjfLmCzmvsMtyQmpMOjc78s1M jQ4E00XRyj5TZO0MH4KxpB0yUQ== X-Received: by 2002:a17:902:dac5:b0:1ca:4ad7:682f with SMTP id q5-20020a170902dac500b001ca4ad7682fmr2419059plx.26.1697716850434; Thu, 19 Oct 2023 05:00:50 -0700 (PDT) Received: from C02DV8HUMD6R.bytedance.net ([203.208.167.147]) by smtp.gmail.com with ESMTPSA id jg9-20020a17090326c900b001c727d3ea6bsm1785646plb.74.2023.10.19.05.00.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 05:00:50 -0700 (PDT) From: Abel Wu To: "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Shakeel Butt Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Abel Wu Subject: [PATCH net v3 2/3] sock: Doc behaviors for pressure heurisitics Date: Thu, 19 Oct 2023 20:00:25 +0800 Message-Id: <20231019120026.42215-2-wuyun.abel@bytedance.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20231019120026.42215-1-wuyun.abel@bytedance.com> References: <20231019120026.42215-1-wuyun.abel@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Thu, 19 Oct 2023 05:01:29 -0700 (PDT) There are now two accounting infrastructures for skmem, while the heuristics in __sk_mem_raise_allocated() were actually introduced before memcg was born. Add some comments to clarify whether they can be applied to both infrastructures or not. Suggested-by: Shakeel Butt Signed-off-by: Abel Wu Acked-by: Shakeel Butt --- net/core/sock.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/net/core/sock.c b/net/core/sock.c index 4412c47466a7..45841a5689b6 100644 --- a/net/core/sock.c +++ b/net/core/sock.c @@ -3069,7 +3069,14 @@ int __sk_mem_raise_allocated(struct sock *sk, int size, int amt, int kind) if (allocated > sk_prot_mem_limits(sk, 2)) goto suppress_allocation; - /* guarantee minimum buffer size under pressure */ + /* Guarantee minimum buffer size under pressure (either global + * or memcg) to make sure features described in RFC 7323 (TCP + * Extensions for High Performance) work properly. + * + * This rule does NOT stand when exceeds global or memcg's hard + * limit, or else a DoS attack can be taken place by spawning + * lots of sockets whose usage are under minimum buffer size. + */ if (kind == SK_MEM_RECV) { if (atomic_read(&sk->sk_rmem_alloc) < sk_get_rmem0(sk, prot)) return 1; @@ -3090,6 +3097,11 @@ int __sk_mem_raise_allocated(struct sock *sk, int size, int amt, int kind) if (!sk_under_memory_pressure(sk)) return 1; + + /* Try to be fair among all the sockets under global + * pressure by allowing the ones that below average + * usage to raise. + */ alloc = sk_sockets_allocated_read_positive(sk); if (sk_prot_mem_limits(sk, 2) > alloc * sk_mem_pages(sk->sk_wmem_queued + -- 2.37.3