From mboxrd@z Thu Jan 1 00:00:00 1970 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 F0929C46CA1 for ; Mon, 18 Sep 2023 07:48:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 416076B02A6; Mon, 18 Sep 2023 03:48:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3EC8D6B02AA; Mon, 18 Sep 2023 03:48:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 17CD46B02A6; Mon, 18 Sep 2023 03:48:55 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id E7C596B02A9 for ; Mon, 18 Sep 2023 03:48:54 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id C0F4A40B9E for ; Mon, 18 Sep 2023 07:48:54 +0000 (UTC) X-FDA: 81248941788.03.1BB4F23 Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) by imf14.hostedemail.com (Postfix) with ESMTP id AA7A5100028 for ; Mon, 18 Sep 2023 07:48:51 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=DCsPyt42; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf14.hostedemail.com: domain of wuyun.abel@bytedance.com designates 209.85.210.177 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=1695023332; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=SmPJUeRmGlrr7ZOL7yO07ODjPeIo7fJ0V72dQGfG3EE=; b=Z7IGctcNIJsZTnwrNToAirkz/sNZLxswTxzaQZHDurkRjgSBXys7ZmhUrJNLUQlnxPbl/d 8fQe1qFO5h6itE/K6neFrkDiwtjmC3vNA1kjBmrQI41Ofm+xzxLvpF/JRrgUBwynX5R/Ma cKH+mrXwIJRmtPzYP0Oqr+yHSMZ7VR0= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=DCsPyt42; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf14.hostedemail.com: domain of wuyun.abel@bytedance.com designates 209.85.210.177 as permitted sender) smtp.mailfrom=wuyun.abel@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695023332; a=rsa-sha256; cv=none; b=5YKfFEM+z114qsQU91fl7GYL91pFjkMaQeeNR1cQWPVxKxxhsB9oOlAH1sFCq4niCygP3u I5w4T9yzZqJENEoKzuSBDy0KDuV1pSIgrkYJ8U06SswNwEw2lNREzo7xTnmZp2THQTmKbL ASK+u/+yIqry8X72GMUKRDFSQabPM80= Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-68fe39555a0so3878582b3a.3 for ; Mon, 18 Sep 2023 00:48:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1695023330; x=1695628130; darn=kvack.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=SmPJUeRmGlrr7ZOL7yO07ODjPeIo7fJ0V72dQGfG3EE=; b=DCsPyt427I+bIjdPR5wOhVfJSIPB3+245s2lB3Y0REBuWqf6Va6rj3k17pP+jAqQju nVgOv+4r2HC3TOS9g0+BL0b2P9siK3g4rqU/VgRLioPBcIGOUJtPHmW8+Uv/F7jBrwUI m4Kxcyn8JebsNewCyrUkilQ5nT6P3j+9OWfz3XEVG1zHrnMwUbk2hai9Y1ZvqzLUpGCf W37Gh0+EwhWj1EN8mQNfnscp6o9MNU5Nl8i/djiblIcTuRkOIWCyZHCpQgqCh0penrwv Pwi9eaDntBNMKQb+DgF0nUJvXpdPJUnYx54Tqyg/egbjBZMo2CprH+uQiZVzxd5c/ZG0 FcGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695023330; x=1695628130; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=SmPJUeRmGlrr7ZOL7yO07ODjPeIo7fJ0V72dQGfG3EE=; b=vvlbPqoPE3f/9qxQsjNuovGxbhIjmkUUmKZ6IuVv8gJc4pHgI8c0EiIlh8LEu9A/Ds +3XrqkKk1GMZdx7XlI66iTdJqsG5r3KpT52oKjEIiqzOjrmv+KlGMifhwhsaCi/NVQz+ pWZX+CAFBTE9m6JuWbyuepsr5aDrFHos+rfnl+eAG6K4ZRQR7yJEZLfFqCWJo5QKNheH dGRxHQ5LIkcC1Kv0F8jI+gDpKE8LXoE8Vf4JZgRJkaWzAZCWHqlkd0GBUj1cqFZppOaQ auzBRTrP8hS6LpaSFU+BMrpyI17Y9okJwsYUspgksVaJwH45dUni6q7S0jn5DzJwGFS8 k4lA== X-Gm-Message-State: AOJu0Ywx4oXlyXrLvLLEfpHaj1yACTxJrILAz6hEGXo6ptToswXUK4q0 7eYTGMCybMZ2iGXL6+KwqtuCFw== X-Google-Smtp-Source: AGHT+IFOar8uTivRcaTdmiCu7ECbgRQSP1xI2cWroqrLtu3MSOVG0cnFtJK1UrO+j+9nXaWVod2Iaw== X-Received: by 2002:a05:6a20:6a1a:b0:137:a08b:8bef with SMTP id p26-20020a056a206a1a00b00137a08b8befmr10484697pzk.44.1695023330281; Mon, 18 Sep 2023 00:48:50 -0700 (PDT) Received: from [10.254.1.7] ([139.177.225.229]) by smtp.gmail.com with ESMTPSA id q8-20020a170902a3c800b001c474d6a408sm2238768plb.201.2023.09.18.00.48.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 18 Sep 2023 00:48:49 -0700 (PDT) Message-ID: <8c470d4d-b972-3f43-9b0a-712ee882a402@bytedance.com> Date: Mon, 18 Sep 2023 15:48:39 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: [RFC PATCH net-next 3/3] sock: Throttle pressure-aware sockets under pressure To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andrew Morton , Shakeel Butt , Roman Gushchin , Michal Hocko , Johannes Weiner , Yosry Ahmed , Yu Zhao , "Matthew Wilcox (Oracle)" , Kefeng Wang , Yafang Shao , Kuniyuki Iwashima , Martin KaFai Lau , Breno Leitao , Alexander Mikhalitsyn , David Howells , Jason Xing Cc: open list , "open list:NETWORKING [GENERAL]" , "open list:MEMORY MANAGEMENT" References: <20230901062141.51972-1-wuyun.abel@bytedance.com> <20230901062141.51972-4-wuyun.abel@bytedance.com> Content-Language: en-US From: Abel Wu In-Reply-To: <20230901062141.51972-4-wuyun.abel@bytedance.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: AA7A5100028 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 6wqaxqftsdr6anunee3fc7eiggzq49zm X-HE-Tag: 1695023331-883253 X-HE-Meta: U2FsdGVkX1+A6PjIiY2Pnp62d/k5kqmYbI8LKgAQbSJaIn4x2hVmNzKjbkhmb1qQieDJigHPn7+Iolr87RwdCWVySpPaUHSUUpKY9iuCXTmG4R6sr18XTZDB7zaOz1bJDQqc5Hcfqz6t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NDkqa/pDmLM3nfxjHSh97ldpJHfjizCXZ1SSwmBbydT2DKt0J07vhnqleBiDuyLsggBaulEwtRRt74OWV+oeSb0DN0h1Z7i91T/XyXPvl/UqMqstTJwald6siGvPa7YIusJXevxCtGD+BlPln9A/3CpRQMQ6XcoOcAiXGQ2XYUglwbiTKX1qKg9iJGkwiuYUCjKPzYS5khl0n/GoGpxFu+dEU7vH1uw== 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: On 9/1/23 2:21 PM, Abel Wu wrote: > @@ -3087,8 +3100,20 @@ 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)) > + /* Be more conservative if the socket's memcg (or its > + * parents) is under reclaim pressure, try to possibly > + * avoid further memstall. > + */ > + if (under_memcg_pressure) > + goto suppress_allocation; > + > + if (!sk_under_global_memory_pressure(sk)) > return 1; > + > + /* Trying to be fair among all the sockets of same > + * protocal under global memory pressure, by allowing > + * the ones that under 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 + I totally agree with what Shakeel said in last reply and will try ebpf- based solution to let userspace inject proper strategies. But IMHO the above hunk is irrelevant to the idea of this patchset, and is the right thing to do, so maybe worth a separate patch? This hunk originally passes the allocation when this socket is below average usage even under global and/or memcg pressure. It makes sense to do so under global pressure, as the 'average' is in the scope of global, but it's really weird from a memcg's point of view. Actually this pass condition was present before memcg pressure was introduced. Please correct me if I missed something, thanks! Best, Abel