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 58832C433EF for ; Thu, 7 Jul 2022 00:07:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EA26F6B0073; Wed, 6 Jul 2022 20:07:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E52616B0075; Wed, 6 Jul 2022 20:07:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D1A896B0078; Wed, 6 Jul 2022 20:07:26 -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 BDB446B0073 for ; Wed, 6 Jul 2022 20:07:26 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 9D18A3492C for ; Thu, 7 Jul 2022 00:07:26 +0000 (UTC) X-FDA: 79658364492.19.EB77251 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf15.hostedemail.com (Postfix) with ESMTP id 11CD8A0015 for ; Thu, 7 Jul 2022 00:07:25 +0000 (UTC) Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-2dc7bdd666fso116208487b3.7 for ; Wed, 06 Jul 2022 17:07:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=oBkjfLfTEe2MgY1tbr+b+YRDO7m34AyR7isp5tYHsyE=; b=Z7AjiUhHDTpQXIK5bWfF18O1wlVwizlxsJhPWgycIxNfqamCT8q4eNshfVTUlTWxhe GjJTiKHROX3m+xYIv6QRj7edR0KpUycKzHK19fOZ4ARls+HFQZfNC2s4/ebdEBWprw5c m1yGFm9MFAes4M/8bJNTO4fvKqXXVA9hDw270MjM9wcexGb8PIjH4wRuN/gmUyPT/9s3 mDqqXZqzOGDbGAd4ZqFCywVqqKbEz0pfbw6Jc9U6BgH4G16nxVE47F3g5xC7q5XzBO37 lUqNrfvShb/mFbP1jiiL9jNvm9JQN3qGIyoyREhdW11u7+NwiQNVzJ/RHYW2S+N3WzC7 ZhwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=oBkjfLfTEe2MgY1tbr+b+YRDO7m34AyR7isp5tYHsyE=; b=ue0NDMacTMKJdt17b+7eN/r60OOVsLn5OHdWiaA3rXdEM/hfwlOlqA4DlmyDIkQkHx j5sGANEdA+qgKfwkeBR079aPKoMlXsfYGE2rt0FLvgjQevdwYrGsv2sjLYuCj5nccHCi g7actBv6N/jOdMjqUdasVo1Y7ZJCd43qjMSsE/btbZubkFrmmYIVnCFRUojECWlnObAP 6i1J98S8XiTKbJJQ4HJ600KobGMy9jTJkay5TwLyDkPyPpPc+S/+9UH4yT8L+7p/pdhs YlMKMCmvmLuaehbnVm+SGthnlNCSlgiZdH1Jjr2qh4g+zI7kCSCMh8yxYjwOOCYxh/T/ jKMg== X-Gm-Message-State: AJIora+y/pRkVi3dsfjHKHxV4fd1wQdYowDdp240q65fLN3FdbDks9ja u1QAFGovePmIuTVYlkNN81CvNVF+bQUvPg== X-Google-Smtp-Source: AGRyM1uTurFidR9Y6QsPzCPcVaFPYCIzXq/t8W3PN13Eo4HbuKd2k129zCsQPbGnBCCf8ExYJuVYm9Jl/K8c9w== X-Received: from shakeelb.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:28b]) (user=shakeelb job=sendgmr) by 2002:a05:6902:1026:b0:66e:93aa:b4ae with SMTP id x6-20020a056902102600b0066e93aab4aemr5977002ybt.575.1657152445268; Wed, 06 Jul 2022 17:07:25 -0700 (PDT) Date: Thu, 7 Jul 2022 00:07:21 +0000 In-Reply-To: <20220706155848.4939-2-laoar.shao@gmail.com> Message-Id: <20220707000721.dtl356trspb23ctp@google.com> Mime-Version: 1.0 References: <20220706155848.4939-1-laoar.shao@gmail.com> <20220706155848.4939-2-laoar.shao@gmail.com> Subject: Re: [PATCH bpf-next v2 1/2] bpf: Make non-preallocated allocation low priority From: Shakeel Butt To: Yafang Shao Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, kafai@fb.com, songliubraving@fb.com, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, quentin@isovalent.com, roman.gushchin@linux.dev, haoluo@google.com, bpf@vger.kernel.org, linux-mm@kvack.org Content-Type: text/plain; charset="us-ascii" ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1657152446; a=rsa-sha256; cv=none; b=EBs/d8kycS6cEvT3icPLt7eTYsoosX3QbErUx3CheHt09KQM9FnGj1u74QvlsR/eWTboO3 1uSXc7jo1ebXyoTO4uDHDz9lK546fGpjPyDwrRgrNR5+E1ur/Dh38c0tZntSK4KdHE8iOW aFs9RNPQLfdik6ZhZ/+7uxzP0KNPboo= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=Z7AjiUhH; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf15.hostedemail.com: domain of 3vSPGYggKCDoodWgaahXckkcha.Ykihejqt-iigrWYg.knc@flex--shakeelb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3vSPGYggKCDoodWgaahXckkcha.Ykihejqt-iigrWYg.knc@flex--shakeelb.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1657152446; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=oBkjfLfTEe2MgY1tbr+b+YRDO7m34AyR7isp5tYHsyE=; b=pOGrzmURfsE7R1/WYVOjstMoyQr/spqJdZNaMTLGTWQ99S1G74xZ89PXyKGFiAZe5dmKcT 5uB4TNUVxm5QdntsX/4TQBd3R40ZlpoUxX8G7UG7hk9ATEw/JLTjsaqakAxEl2u7TirkZl l+rSwQVQTyMoeTUeF8n9MFkhdQEN1W4= X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 11CD8A0015 X-Rspam-User: Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=Z7AjiUhH; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf15.hostedemail.com: domain of 3vSPGYggKCDoodWgaahXckkcha.Ykihejqt-iigrWYg.knc@flex--shakeelb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3vSPGYggKCDoodWgaahXckkcha.Ykihejqt-iigrWYg.knc@flex--shakeelb.bounces.google.com X-Stat-Signature: pu89ji6yer6e5i6cdbc1udpshqysxm5o X-HE-Tag: 1657152445-156417 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 Wed, Jul 06, 2022 at 03:58:47PM +0000, Yafang Shao wrote: > GFP_ATOMIC doesn't cooperate well with memcg pressure so far, especially > if we allocate too much GFP_ATOMIC memory. For example, when we set the > memcg limit to limit a non-preallocated bpf memory, the GFP_ATOMIC can > easily break the memcg limit by force charge. So it is very dangerous to > use GFP_ATOMIC in non-preallocated case. One way to make it safe is to > remove __GFP_HIGH from GFP_ATOMIC, IOW, use (__GFP_ATOMIC | > __GFP_KSWAPD_RECLAIM) instead, then it will be limited if we allocate > too much memory. Please use GFP_NOWAIT instead of (__GFP_ATOMIC | __GFP_KSWAPD_RECLAIM). There is already a plan to completely remove __GFP_ATOMIC and mm-tree already have a patch for that. > > We introduced BPF_F_NO_PREALLOC is because full map pre-allocation is > too memory expensive for some cases. That means removing __GFP_HIGH > doesn't break the rule of BPF_F_NO_PREALLOC, but has the same goal with > it-avoiding issues caused by too much memory. So let's remove it. > > The force charge of GFP_ATOMIC was introduced in > commit 869712fd3de5 ("mm: memcontrol: fix network errors from failing > __GFP_ATOMIC charges") by checking __GFP_ATOMIC, then got improved in > commit 1461e8c2b6af ("memcg: unify force charging conditions") by > checking __GFP_HIGH (that is no problem because both __GFP_HIGH and > __GFP_ATOMIC are set in GFP_AOMIC). So, if we want to fix it in memcg, > we have to carefully verify all the callsites. Now that we can fix it in > BPF, we'd better not modify the memcg code. > > This fix can also apply to other run-time allocations, for example, the > allocation in lpm trie, local storage and devmap. So let fix it > consistently over the bpf code > > __GFP_KSWAPD_RECLAIM doesn't cooperate well with memcg pressure neither > currently. But the memcg code can be improved to make > __GFP_KSWAPD_RECLAIM work well under memcg pressure if desired. > IMO there is no need to give all this detail and background on GFP_ATOMIC and __GFP_KSWAPD_RECLAIM. Just say kernel allows GFP_ATOMIC allocations to exceed memcg limits which we don't want in this case. So, replace with GFP_NOWAIT which obey memcg limits. Both of these flags tell kernel that the caller can not sleep.