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 DB51FC43334 for ; Thu, 7 Jul 2022 10:28:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0E8EA6B0072; Thu, 7 Jul 2022 06:28:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0990C6B0073; Thu, 7 Jul 2022 06:28:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EA2586B0074; Thu, 7 Jul 2022 06:28:35 -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 D884D6B0072 for ; Thu, 7 Jul 2022 06:28:35 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id A7F5734E7F for ; Thu, 7 Jul 2022 10:28:35 +0000 (UTC) X-FDA: 79659929790.19.772205A Received: from mail-vk1-f174.google.com (mail-vk1-f174.google.com [209.85.221.174]) by imf16.hostedemail.com (Postfix) with ESMTP id 57ED5180030 for ; Thu, 7 Jul 2022 10:28:35 +0000 (UTC) Received: by mail-vk1-f174.google.com with SMTP id a15so8637115vkl.10 for ; Thu, 07 Jul 2022 03:28:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=1jEVdpbvqQRSNIv0th7cTYiMXpo4mnpeXk5Jx9vXc6A=; b=c6SGCzZUWXWpcQ/dc2iZFuXm7QnCRInKAoYhk4Xln25UlRThSvkhHl2OogHcqXcmsF uZdcXwd8rn7qqgA9A6XbbEGFnhj9q6jwYx2NKWHYMVVnDQ+igRyzV1o1JuxQxkbWSyUp jCg5W5nnDUM5J/LF/v09sKXfwIjaRk7L4AzfQsoXhv2JqU1XO/qOpT9uhnJkFijdJrZf tmsvwL4mDGjUIALs/jyhbr2MvrZrhF+SC7drgWztn2hMCOAlCp4exYDUbpEZGTFXYXw5 s/6/WI8QjelD/w9Ja0DoiCzZXkfWIcZ0d7ezmt1auPev1BTRI5Tl3FxbxyinPKg/iq/i e26g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=1jEVdpbvqQRSNIv0th7cTYiMXpo4mnpeXk5Jx9vXc6A=; b=zEiKURNPfu+AtIrW5nTUMFtB72fHTYAUSt1ZXfINbTelJFMw7SARODCM5dInYR7zZL RVlZOxoVr0mhw53u4vorJIZQUKXFSGBySQ7dTVJE0gKrJGrtUiXNbGa/8HhXr5RXMJyb WHIuXl03Su9c11Xn8QHMMKZ4KQqhYgcXSPOUgMPK6JBTgMng31tVosxIMXWnEHFHyj5X DVRFLP2H/G8kcVkwhDvZAhPfRsHw+P3dv+QsPYnEuUNXIMr9j/8xUYJ8Tfpe5R/csNad hMN5IsR3MOT+RtqXWlWggRNk/Cv4VY+1cCdyz0Ab9DS1PJU0JbFrbNc7dBLjINIFetHk i3Rw== X-Gm-Message-State: AJIora8p4ArTHWipSqEKMeLNT/TvtoZZLnDwTl0wAkQ4oAHBbFvlwA2M Q2JlrKYMh6uIdgWg95pJfBuqh5+r3qT0MCrwOD0= X-Google-Smtp-Source: AGRyM1tBtowXYd5lLM+Pntndrj091k2gteG2hyYSLebqnYBWJJFmiE+1vjRbe6ECBC7bfQjZ554a+jYwNnZaRPsUjYA= X-Received: by 2002:ac5:ccc1:0:b0:374:61a7:e99f with SMTP id j1-20020ac5ccc1000000b0037461a7e99fmr307279vkn.14.1657189714511; Thu, 07 Jul 2022 03:28:34 -0700 (PDT) MIME-Version: 1.0 References: <20220706155848.4939-1-laoar.shao@gmail.com> <20220706155848.4939-2-laoar.shao@gmail.com> <20220707000721.dtl356trspb23ctp@google.com> In-Reply-To: <20220707000721.dtl356trspb23ctp@google.com> From: Yafang Shao Date: Thu, 7 Jul 2022 18:27:57 +0800 Message-ID: Subject: Re: [PATCH bpf-next v2 1/2] bpf: Make non-preallocated allocation low priority To: Shakeel Butt Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin Lau , Song Liu , Yonghong Song , john fastabend , KP Singh , Quentin Monnet , Roman Gushchin , Hao Luo , bpf , Linux MM Content-Type: text/plain; charset="UTF-8" ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1657189715; a=rsa-sha256; cv=none; b=WyZAbHYkn4sXXZ6PzL34bxUZhBw5WtZmGLzg2M1+7PvjTSZMgQnuXcit4hRGyFyWJFn01O +hHHTIuTKgK62On5ywrtaLOPWFsyuHgcF9Q9fu/z3iMDx2QDrIEa7yx+4swkv2hCJWWtQZ EdZh/8OATPRlVmeZvB6B1UDIAcnTc5s= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=c6SGCzZU; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf16.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.221.174 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1657189715; 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=1jEVdpbvqQRSNIv0th7cTYiMXpo4mnpeXk5Jx9vXc6A=; b=RkowiBIYwyVZfi1ax+nGMeCglXZZ+iMS+6gPpyw1QTjHAfyZw0xZ6et5TC+c4r61GRxudW pF0naZ7rnQSlJCkWzKDVQPsA4pN7tixoeW/O2eXFYCkI/xwu+beJnV7Uhvg3/PZSjKd0H9 dquM0025oqDPsB6uVvBrrlTY3G7BbIw= X-Rspamd-Server: rspam04 X-Rspam-User: Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=c6SGCzZU; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf16.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.221.174 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com X-Stat-Signature: mgaxqyx1xbpynczb9bk31f9qh4ztcwnr X-Rspamd-Queue-Id: 57ED5180030 X-HE-Tag: 1657189715-682947 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 Thu, Jul 7, 2022 at 8:07 AM Shakeel Butt wrote: > > 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. > After reading the discussion[1], it looks good to me to use GFP_NOWAIT instead. I will update it. [1]. https://lore.kernel.org/linux-mm/163712397076.13692.4727608274002939094@noble.neil.brown.name/ > > > > 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. > Sure, thanks. -- Regards Yafang