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 34408C433EF for ; Wed, 6 Jul 2022 23:23:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BABC16B0072; Wed, 6 Jul 2022 19:23:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B5BB36B0073; Wed, 6 Jul 2022 19:23:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A22D66B0074; Wed, 6 Jul 2022 19:23:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 911776B0072 for ; Wed, 6 Jul 2022 19:23:12 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id C4FF12046B for ; Wed, 6 Jul 2022 23:23:10 +0000 (UTC) X-FDA: 79658252940.07.1F24660 Received: from mail-ed1-f50.google.com (mail-ed1-f50.google.com [209.85.208.50]) by imf19.hostedemail.com (Postfix) with ESMTP id 61FB61A0041 for ; Wed, 6 Jul 2022 23:23:10 +0000 (UTC) Received: by mail-ed1-f50.google.com with SMTP id k30so12969313edk.8 for ; Wed, 06 Jul 2022 16:23:10 -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=a0ZFkLPHJzfEYXmetfXf9lMt20DN6mMWrCB9iVapBS4=; b=VRNLmRhuPzknCE/58AeA5wYE/FE0RwkgkDron0lnlL8uTOJX5wCFBXan3bT+Gj8DBV PqrVg0reJw6m4buFrEN7BjhIh3DXPRF1sB21BCpza2RLAZNQfdh42mTPqwnkjc7FIGEm l94iUH0eaciOD68py/6rurX3WMGfXVfs3Xm/w+8F0fw71I+zIyCqwN0gkA9ysAodZBsC KmXpcF5y77I4+gw4DPhmJpiOe8T18/HeIkz6KX1Ti8Y6iGp0+nHy8alTVHZBr7NWy5ze W2K4TVY8gXUIWCkav6IBzw7HEtRRWMIPI3N2uOGxEnNw23CHERDrfwqoCFpSRJ+Jjzd2 WFlw== 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=a0ZFkLPHJzfEYXmetfXf9lMt20DN6mMWrCB9iVapBS4=; b=CZxPYdxlcJbgHChpqW1cF6POQTnb6Yxb+ZNvEd2Crj86IahBL7G2pDkJ+yrQv2lZwp Muq8Frsw6HtxCF0Em4IJgsF6rIlxuMOY5+d3BCxrbY5LFF/jLXh2bG4vNHALkBjJOQWr OnBzcHDUomDeclK+CKG+OQxGewMqUVGjuZEGjpfKrZJNHk+c38r6Aw+RIeY4tz7kF302 susCS6w3I5KH9wAOhHJRZBC2gOkienByl9pAorLgEm3ntFu5Oz5A8uxQyfAfwzhMYDBF mSyPnh45RtcCsQyAKXDMO3oHk7mAiBRW9R5MRT5og70wmHRGzBrQFu+vlIewVGY+Wz/H MfPw== X-Gm-Message-State: AJIora/O3N2bmN/5TYlbkpfQV2Fg7+dsYzBga44f+qXCaq/FLtKpB8Mu lk/rOHHmAWqvrF1wvXeMQTykdY2sRqw2a7ocVRk= X-Google-Smtp-Source: AGRyM1sl9m2uuD9+jE5b+KRE+yam2Lcab6zQrnxfA3ccMLJcM8hZA38bv3nM4Jo4A4fNpS+7wdd+cpFA4AvUTgO42yM= X-Received: by 2002:a05:6402:2cd:b0:43a:70f7:1af2 with SMTP id b13-20020a05640202cd00b0043a70f71af2mr20127796edx.357.1657149788960; Wed, 06 Jul 2022 16:23:08 -0700 (PDT) MIME-Version: 1.0 References: <20220706155848.4939-1-laoar.shao@gmail.com> <20220706155848.4939-2-laoar.shao@gmail.com> In-Reply-To: From: Alexei Starovoitov Date: Wed, 6 Jul 2022 16:22:50 -0700 Message-ID: Subject: Re: [PATCH bpf-next v2 1/2] bpf: Make non-preallocated allocation low priority To: Roman Gushchin Cc: Yafang Shao , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Quentin Monnet , Hao Luo , bpf , linux-mm Content-Type: text/plain; charset="UTF-8" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1657149790; 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=a0ZFkLPHJzfEYXmetfXf9lMt20DN6mMWrCB9iVapBS4=; b=EsewVv2PBTpUaZaxv1i6cIM/GbyfQoE9evNxXMxtF4PF15Y8pJJywZyjGmE3dpGOj9DN4K bTh0FRQAzZB+P1s4oYZs+Vkp3/qA8IBfkKWed4L20BgXh1XXRDKROdIyxiRE2OLnSoTdnt y9LhvBjLZR4jU4T6PMyhG5ueb4Lxe1E= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=VRNLmRhu; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf19.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.208.50 as permitted sender) smtp.mailfrom=alexei.starovoitov@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1657149790; a=rsa-sha256; cv=none; b=NVccA5JsXmLIi0iEmyi1LE0yIl0I0YX+XunNA0V0D8BqAKJBYwuJ45pBghP7hv+2V4JZlp +Sdj2aLM8h2WySx2yvuMDEP+rzReDcisnyZ57NCMQmaDC5rfSh7cQrsU1nBX8w9kvQWJYv EeMJmvhfVdp9EDaXiwqx4xolEhXOpXs= X-Rspam-User: X-Rspamd-Server: rspam07 Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=VRNLmRhu; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf19.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.208.50 as permitted sender) smtp.mailfrom=alexei.starovoitov@gmail.com X-Stat-Signature: zf95wze7to4wg9hhwiucpxugydnqta84 X-Rspamd-Queue-Id: 61FB61A0041 X-HE-Tag: 1657149790-918352 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 6, 2022 at 3:54 PM Roman Gushchin wrote: > > On Wed, Jul 06, 2022 at 03:11:46PM -0700, Alexei Starovoitov wrote: > > On Wed, Jul 6, 2022 at 12:09 PM Roman Gushchin wrote: > > > > > > On Wed, Jul 06, 2022 at 09:47:32AM -0700, Alexei Starovoitov wrote: > > > > On Wed, Jul 6, 2022 at 8:59 AM 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. > > > > > > > > > > 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. > > > > > > > > Could you elaborate ? > > > > > > > > > It also fixes a typo in the comment. > > > > > > > > > > Signed-off-by: Yafang Shao > > > > > Reviewed-by: Roman Gushchin > > > > > > > > Roman, do you agree with this change ? > > > > > > Yes, removing __GFP_HIGH makes sense to me. I can imagine we might want > > > it for *some* bpf allocations, but applying it unconditionally looks wrong. > > > > Yeah. It's a difficult trade-off to make without having the data > > to decide whether removing __GFP_HIGH can cause issues or not, > > Yeah, the change looks reasonable, but it's hard to say without giving > it a good testing in (something close to) a production environment. > > > but do you agree that __GFP_HIGH doesn't cooperate well with memcg ? > > If so it's a bug on memcg side, right? > > No. Historically we allowed high-prio allocations to exceed the memcg limit > because otherwise there were too many stability and performance issues. > It's not a memcg bug, it's a way to avoid exposing ENOMEM handling bugs all over > the kernel code. Without memory cgroups GFP_ATOMIC allocations rarely fail > and a lot of code paths in the kernel are not really ready for it (at least > it was the case several years ago, maybe things are better now). > > But it was usually thought in the context of small(ish) allocations which do not > change the global memory usage picture. Subsequent "normal" allocations are > triggering reclaim/OOM, so from a user's POV the limit works as expected. > > But with the ownership model and size of bpf maps it's a different story: > if a bpf map belongs to an abandoned cgroup, it might consume a lot of memory > and there will be no "normal" allocations. So cgroup memory limit will be never > applied. It's a valid issue, I agree with Yafang here. Understood. > > but we should probably > > apply this band-aid on bpf side to fix the bleeding. > > Later we can add a knob to allow __GFP_HIGH usage on demand from > > bpf prog. > > Yes, it sounds like a good idea. I have to think what's the best approach > here, it's not obvious for me. Ok. Applied this patch for now.