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 E3C21CCA473 for ; Wed, 6 Jul 2022 18:05:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 567966B0072; Wed, 6 Jul 2022 14:05:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 516546B0073; Wed, 6 Jul 2022 14:05:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3DDA66B0074; Wed, 6 Jul 2022 14:05:32 -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 2C2296B0072 for ; Wed, 6 Jul 2022 14:05:32 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id BABF5120445 for ; Wed, 6 Jul 2022 18:05:30 +0000 (UTC) X-FDA: 79657452420.01.283CB1E Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) by imf16.hostedemail.com (Postfix) with ESMTP id 33AD1180037 for ; Wed, 6 Jul 2022 18:05:30 +0000 (UTC) Received: by mail-pl1-f169.google.com with SMTP id m14so14280985plg.5 for ; Wed, 06 Jul 2022 11:05:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=i/uw/dcSlMSSrdMGqGMlhLWezxnqW48ImhZuLtj9UNk=; b=AAuxWvp3lkLUJhlzLCNTmZbwMj75lW5f+cB2htn/fK/HebPMnNioSuUAWvsiB0Qt7q ifjkYiLVqafHvqzE4cxTeiDmzvYO16Qz539kjK1wHmTa/de7lwTj2r1s4GhAh4yz+ABh +/Peau72XSNz4pW1dffLZQ+GRvMy6cZurSXl8d+p1UwwuxwgNHn0FijZ23V51SJiyNkQ KBzdBsgrPw5b4yv6k+jl4BfcJu3ubtVHGI9wF2JFfDUgWzAiSiK5BSsgo0ZTmIYCQ1Sx 48lfYjzLhph7OdSPqSw7HmRBxE3IY4Q8UgmNTleQ/dSlh0a2+YjKFmNfOWk5nN9E2ZFe /k7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=i/uw/dcSlMSSrdMGqGMlhLWezxnqW48ImhZuLtj9UNk=; b=HepPrRv2RV4S058Yjp5tWCEz/Xeds1oFLEs3kKIcOLdbzgyjy2bm9b8teBuhcJYriZ MOrFe+4X0/9Ctf11Ygt8fBpXfI5sNHlyg2KRLm2SoMZGCw+ZU1Ck1HkSb8iy6r9aTgho XISD4N7Yfns3QZJ7Xx9eQHRescVeVFpRIp/y2//iqIKud0hDoVsR42nHhzljA+PMJRhO Xi36H2H8DmxG6DRmx1SUwGZNWIXcSqlZyVDT3XdMtwHdQCdDBO1T9/HsUjPT3Vi99Mpb 4pyN+diA5UbQZmiR4v8KwUZNfyW1ScAlj+0WgmgNqMv7B5L8m9S42BG806RiIlZK2NNu x/tg== X-Gm-Message-State: AJIora+y6X2othE5ZBS020GMF4EwuDur3cqcm8zIlaM0ZfgzpcLC8qRS S+neybPydMBUYtV93KFmvcw0wHyow4E= X-Google-Smtp-Source: AGRyM1uY/bT0SLXQLiK9eq+6CtGzvVK6V9wnN2EPI/XRYcv/M8B3WZE/CLB999i40J2VTSSoJ5U/1Q== X-Received: by 2002:a17:90b:1d8f:b0:1ec:cd0c:23fe with SMTP id pf15-20020a17090b1d8f00b001eccd0c23femr51893129pjb.147.1657130729149; Wed, 06 Jul 2022 11:05:29 -0700 (PDT) Received: from MacBook-Pro-3.local.dhcp.thefacebook.com ([2620:10d:c090:500::2:8597]) by smtp.gmail.com with ESMTPSA id x4-20020a170902a38400b0015e8d4eb1easm26173434pla.52.2022.07.06.11.05.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Jul 2022 11:05:28 -0700 (PDT) Date: Wed, 6 Jul 2022 11:05:25 -0700 From: Alexei Starovoitov To: Matthew Wilcox Cc: 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 Subject: Re: [PATCH bpf-next 0/5] bpf: BPF specific memory allocator. Message-ID: <20220706180525.ozkxnbifgd4vzxym@MacBook-Pro-3.local.dhcp.thefacebook.com> References: <20220623003230.37497-1-alexei.starovoitov@gmail.com> <20220706175034.y4hw5gfbswxya36z@MacBook-Pro-3.local> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1657130730; 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=i/uw/dcSlMSSrdMGqGMlhLWezxnqW48ImhZuLtj9UNk=; b=dYCblCImTf3GA9zVL6BZjF+IhWNlzdAkwT3qkD2+kFwvG2hKyrBka+hb+ukfZJb1xdQHQu hU1YVijPd8aUsrqcksrLQcfBnSFwaDjs+Z4jMqNcD3vOod5VaavGRH8nwbxlyAMTUccTp1 ulu4II+4XnUwiUQHZQw/AQtlJ4Mn80c= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1657130730; a=rsa-sha256; cv=none; b=t1+o51dWasbvNqtfqoK70EsMGeCfgJa6+aC04vX0EW47ChVqliMBmgQj85bzcdqjM61IwM P6fd5KuZfXpWlV+6kY2CcGLJ23PsD/d+2YpKWt2Q4QmuV0IhOabSSyxm1YIRtDup2PKcss /lN83kY4VjNqm2iwUhIt0jY4zh/wf48= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=AAuxWvp3; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf16.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.214.169 as permitted sender) smtp.mailfrom=alexei.starovoitov@gmail.com X-Stat-Signature: fi46g5esyytupuszo767wtna1sxn46fk X-Rspamd-Queue-Id: 33AD1180037 X-Rspam-User: Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=AAuxWvp3; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf16.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.214.169 as permitted sender) smtp.mailfrom=alexei.starovoitov@gmail.com X-Rspamd-Server: rspam10 X-HE-Tag: 1657130730-508127 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 06:55:36PM +0100, Matthew Wilcox wrote: > On Wed, Jul 06, 2022 at 10:50:34AM -0700, Alexei Starovoitov wrote: > > On Mon, Jul 04, 2022 at 09:34:23PM +0100, Matthew Wilcox wrote: > > > On Mon, Jun 27, 2022 at 12:03:08AM -0700, Christoph Hellwig wrote: > > > > I'd suggest you discuss you needs with the slab mainainers and the mm > > > > community firs. > > > > > > > > On Wed, Jun 22, 2022 at 05:32:25PM -0700, Alexei Starovoitov wrote: > > > > > From: Alexei Starovoitov > > > > > > > > > > Introduce any context BPF specific memory allocator. > > > > > > > > > > Tracing BPF programs can attach to kprobe and fentry. Hence they > > > > > run in unknown context where calling plain kmalloc() might not be safe. > > > > > Front-end kmalloc() with per-cpu per-bucket cache of free elements. > > > > > Refill this cache asynchronously from irq_work. > > > > > > I can't tell from your description whether a bump allocator would work > > > for you. That is, can you tell which allocations need to persist past > > > program execution (and use kmalloc for them) and which can be freed as > > > soon as the program has finished (and can use the bump allocator)? > > > > > > If so, we already have one for you, the page_frag allocator > > > (Documentation/vm/page_frags.rst). It might need to be extended to meet > > > your needs, but it's certainly faster than the kmalloc allocator. > > > > Already looked at it, and into mempool, and everything we could find. > > All 'normal' allocators sooner or later synchornously call into page_alloc, > > Today it does, yes. But it might be adaptable to your needs if only I > knew what those needs were. needs: fully reentrant, nmi safe, any context safe. I feel you're still failing to grasp 'any context' part. bpf prog can attach to all available_filter_functions and should be able to alloc from there. Or kprobe anywhere and everywhere in the kernel .text that is not marked notrace/nokprobe. > 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.