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 96BF5C43334 for ; Fri, 8 Jul 2022 21:55:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DF0D46B0072; Fri, 8 Jul 2022 17:55:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D782A6B0073; Fri, 8 Jul 2022 17:55:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C18F06B0074; Fri, 8 Jul 2022 17:55:40 -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 B0A1E6B0072 for ; Fri, 8 Jul 2022 17:55:40 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id 7F82812099E for ; Fri, 8 Jul 2022 21:55:40 +0000 (UTC) X-FDA: 79665290040.21.502E3ED Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf07.hostedemail.com (Postfix) with ESMTP id 28C0C40022 for ; Fri, 8 Jul 2022 21:55:40 +0000 (UTC) Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-31ce88f9ab8so626617b3.16 for ; Fri, 08 Jul 2022 14:55:39 -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=KTcMDJIWF7maQXKusrmUSDyrUm3bNQKSsaTD9FZyhVo=; b=Url6xAqmGVyxaGjlRTUrF9phR12iTaqlJWEzoG69laThxIE1WCDlBSWrGbXiqt6otT SDt0fTPtdpAs55TSiCVROsmTQLhkqIA4Za0BTVUuXZRYfE3cxeCwu5khduZgQVcZJT5k 1uM1qJoJlEcE25710S7Jui7GVKsmgUI08tmhfO133LFU5zJB+mFrcV10CxmyBNdDEwqC BpCR8AQ8XkzdR/YWkaV4vjbO9MLjMGJtX8sH2/5BuiIfK6v2r7FQgrcB/+rWNhUyfSM5 DwONximW1fiH0EtRdAnFlYnPngA3SBRV6WuVRVvvH+ebBSc3pUM7hHGuCKCMbXY2Fcr+ eKIw== 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=KTcMDJIWF7maQXKusrmUSDyrUm3bNQKSsaTD9FZyhVo=; b=EX15srvY6TtZnp+tPNYfI0DE3Xh/60/sacQoGab9oA1KHwBsv3ly5Zej7gWoor3bms hHeahepxoK+xW7i8Ut8PjZJQcpVbV7eD+pcGU0Jr8hyTSagb8rY3cgqIkdUFYsa3tM9F Yl2aZd1N6UORCpghsZa7Vtyqmrmt1uXi6fro097y/Py6HKxJ3MPrhhyhCOLZesE/CsFY 8n7qoAPH0r4IN1Chm+fwz26z/RXwe1NOP9iC0KwJjv799qnOhuU6nuo0Re/MA+sSCD54 6r9PEs+/7F6KMkUh7ax4WpbTeHglIHRzEsuUP2+uHLf5pa/4MC0cODJWqNkYPDzSSLP0 MUjQ== X-Gm-Message-State: AJIora/A3eyCgs2mcy4yj325xGb/d9vrqwDPcrieRaworoynBgcZK7l+ V/rqTNqR3OKUirm/KyPS7De5DnGubq1MNQ== X-Google-Smtp-Source: AGRyM1somxke5cd59gI0MGLidzR4nzR4e0KlSKmNXY0RMr2FB0Q3YkA7ars8LWkkqwa8vMzedqr/X8/auq7hpg== X-Received: from shakeelb.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:28b]) (user=shakeelb job=sendgmr) by 2002:a0d:e249:0:b0:31c:82a2:e31e with SMTP id l70-20020a0de249000000b0031c82a2e31emr6620087ywe.342.1657317339422; Fri, 08 Jul 2022 14:55:39 -0700 (PDT) Date: Fri, 8 Jul 2022 21:55:36 +0000 In-Reply-To: <20220708174858.6gl2ag3asmoimpoe@macbook-pro-3.dhcp.thefacebook.com> Message-Id: <20220708215536.pqclxdqvtrfll2y4@google.com> Mime-Version: 1.0 References: <20220623003230.37497-1-alexei.starovoitov@gmail.com> <20220706175034.y4hw5gfbswxya36z@MacBook-Pro-3.local> <20220706180525.ozkxnbifgd4vzxym@MacBook-Pro-3.local.dhcp.thefacebook.com> <20220708174858.6gl2ag3asmoimpoe@macbook-pro-3.dhcp.thefacebook.com> Subject: Re: [PATCH bpf-next 0/5] bpf: BPF specific memory allocator. From: Shakeel Butt To: Alexei Starovoitov Cc: Michal Hocko , Matthew Wilcox , Christoph Hellwig , davem@davemloft.net, daniel@iogearbox.net, andrii@kernel.org, tj@kernel.org, kafai@fb.com, bpf@vger.kernel.org, kernel-team@fb.com, linux-mm@kvack.org, Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Vlastimil Babka Content-Type: text/plain; charset="us-ascii" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1657317340; 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=KTcMDJIWF7maQXKusrmUSDyrUm3bNQKSsaTD9FZyhVo=; b=nsfBJPTb1Mh8jGArItXx5hodFgX/Pg4VKPHyxywu/b8cJ2QEwW36IcfGv/digQ30fLlWCY Ai3337P3kFyeSW4SKFYJr3mc2A2ONHo87ZCFPSaYNLBd5Z1M3gi4fSjctkj0En2//1y9RE e/GQwn2aLWN1u2+LQoJhm1Qu4BUOV3I= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1657317340; a=rsa-sha256; cv=none; b=PMHa1iGYB7NBUZBsiVvxIyHVfm0+bVgyvZm5w6qnDLoyM6n3bJg4EQt1/1swnFnAmEGegH OU94nPBydTi9Y+428KaOA3S+TsmkJREACH/feLKLMa5ywojg4hLhxT/A8MpVUgXtsC4up5 x4jIulFEzcQkLiVDuX9GCc94piYJ+g0= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=Url6xAqm; spf=pass (imf07.hostedemail.com: domain of 326fIYggKCGoaPISMMTJOWWOTM.KWUTQVcf-UUSdIKS.WZO@flex--shakeelb.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=326fIYggKCGoaPISMMTJOWWOTM.KWUTQVcf-UUSdIKS.WZO@flex--shakeelb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspamd-Queue-Id: 28C0C40022 Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=Url6xAqm; spf=pass (imf07.hostedemail.com: domain of 326fIYggKCGoaPISMMTJOWWOTM.KWUTQVcf-UUSdIKS.WZO@flex--shakeelb.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=326fIYggKCGoaPISMMTJOWWOTM.KWUTQVcf-UUSdIKS.WZO@flex--shakeelb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspam-User: X-Rspamd-Server: rspam06 X-Stat-Signature: rkyqz57syjxtnj6tbfhnfu1sur5o5p9u X-HE-Tag: 1657317340-441368 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 Fri, Jul 08, 2022 at 10:48:58AM -0700, Alexei Starovoitov wrote: > On Fri, Jul 08, 2022 at 03:41:47PM +0200, Michal Hocko wrote: > > On Wed 06-07-22 11:05:25, Alexei Starovoitov wrote: > > > On Wed, Jul 06, 2022 at 06:55:36PM +0100, Matthew Wilcox wrote: > > [...] > > > > For example, I assume that a BPF program > > > > has a fairly tight limit on how much memory it can cause to be allocated. > > > > Right? > > > > > > No. It's constrained by memcg limits only. It can allocate gigabytes. > > > > I have very briefly had a look at the core allocator parts (please note > > that my understanding of BPF is really close to zero so I might be > > missing a lot of implicit stuff). So by constrained by memcg you mean > > __GFP_ACCOUNT done from the allocation context (irq_work). The complete > > gfp mask is GFP_ATOMIC | __GFP_NOMEMALLOC | __GFP_NOWARN | __GFP_ACCOUNT > > which means this allocation is not allowed to sleep and GFP_ATOMIC > > implies __GFP_HIGH to say that access to memory reserves is allowed. > > Memcg charging code interprets this that the hard limit can be breached > > under assumption that these are rare and will be compensated in some > > way. The bulk allocator implemented here, however, doesn't reflect that > > and continues allocating as it sees a success so the breach of the limit > > is only bound by the number of objects to be allocated. If those can be > > really large then this is a clear problem and __GFP_HIGH usage is not > > really appropriate. > > That was a copy paste from the networking stack. See kmalloc_reserve(). > Not sure whether it's a bug there or not. kmalloc_reserve() is good. Most of calls to kmalloc_reserve() are for skbs and we don't use __GFP_ACCOUNT for skbs. Actually skbs are charged to memcg through a separate interface (i.e. mem_cgroup_charge_skmem()) > In a separate thread we've agreed to convert all of bpf allocations > to GFP_NOWAIT. For this patch set I've already fixed it in my branch. > > > Also, I do not see any tracking of the overall memory sitting in these > > pools and I think this would be really appropriate. As there doesn't > > seem to be any reclaim mechanism implemented this can hide quite some > > unreachable memory. > > > > Finally it is not really clear to what kind of entity is the life time > > of these caches bound to. Let's say the system goes OOM, is any process > > responsible for it and a clean up would be done if it gets killed? > > We've been asking these questions for years and have been trying to > come up with a solution. > bpf progs are not analogous to user space processes. > There are bpf progs that function completely without user space component. > bpf progs are pretty close to be full featured kernel modules with > the difference that bpf progs are safe, portable and users have > full visibility into them (source code, line info, type info, etc) > They are not binary blobs unlike kernel modules. > But from OOM perspective they're pretty much like .ko-s. > Which kernel module would you force unload when system is OOMing ? > Force unloading ko-s will likely crash the system. > Force unloading bpf progs maybe equally bad. The system won't crash, > but it may be a sorrow state. The bpf could have been doing security > enforcement or network firewall or providing key insights to critical > user space components like systemd or health check daemon. > We've been discussing ideas on how to rank and auto cleanup > the system state when progs have to be unloaded. Some sort of > destructor mechanism. Fingers crossed we will have it eventually. > bpf infra keeps track of everything, of course. > Technically we can detach, unpin and unload everything and all memory > will be returned back to the system. > Anyhow not a new problem. Orthogonal to this patch set. > bpf progs have been doing memory allocation from day one. 8 years ago. > This patch set is trying to make it 100% safe. > Currently it's 99% safe. Most probably Michal's comment was on free objects sitting in the caches (also pointed out by Yosry). Should we drain them on memory pressure / OOM or should we ignore them as the amount of memory is not significant?