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 B477FC433EF for ; Wed, 6 Jul 2022 17:50:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 169E46B0072; Wed, 6 Jul 2022 13:50:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 119F86B0073; Wed, 6 Jul 2022 13:50:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F23326B0074; Wed, 6 Jul 2022 13:50:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id E308A6B0072 for ; Wed, 6 Jul 2022 13:50:39 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id AE17720E98 for ; Wed, 6 Jul 2022 17:50:39 +0000 (UTC) X-FDA: 79657414998.23.502DFEE Received: from mail-pj1-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) by imf17.hostedemail.com (Postfix) with ESMTP id F386440050 for ; Wed, 6 Jul 2022 17:50:38 +0000 (UTC) Received: by mail-pj1-f46.google.com with SMTP id 89-20020a17090a09e200b001ef7638e536so12901537pjo.3 for ; Wed, 06 Jul 2022 10:50:38 -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=Fe8Q2UUclVbaN//xksGPDN/FPyfgVOHDsw8MqncmWZI=; b=b64OOiZgE7soHHxKtHffWVVok+++6eFqAB4q3hQg/lBq6l3Ze4xIzBmHXBfXGlapPo rAVd6oCLfVL1xn4G9uoaVxKWNls/ZU17uJv4uvQ7/ePWexOOLaJJMEwjbtZp9wRmEWLl g8RtOy58ardTZRwpWyfrp/h+VlC6o/51LJwMGnJItVY+pKArdzMj9CtxjGSOi0eXHF5l TbMclnjUxiuyLScwlRLpNxv60d6NNcMKaTwtfDteJ/c51mchlHPT6SfSB0KcZMmtwpNl a17iaWCJpDTOMbOVcfhG9EqlR0U3sBq0KQZB5/Id86eDWWSX7k+3pIX2Fq0gXhts6KCZ K+0w== 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=Fe8Q2UUclVbaN//xksGPDN/FPyfgVOHDsw8MqncmWZI=; b=XPhaQzlE6GIO/wSURRrm2uwRpZEU/j4xvMCLzcSlCUPOju4MZdidh27kMYqA3PgDe6 fycPFXFaDKS/wAhYWPEdFjbE1PVi8VlAJcogz3V6gufwtOHT8PtWZB+Pg28qFCjqlmKh CITZx2Fct0r95nvse5PhvATEN+4BlxT1BkM6k62AZoxygDZATrKcmYzeSwPk22WjeBsm JNkcoK+jQNEoHBg29mjCoqBpDCmLFTuoE/2x3FSYImmzSD6kz4+ZKVaT/xj5NlTavGMm aZCL576FN6DCIJLYLDzZ/Aoch63Ib3L3tpASE+MqaBz/skZwrxkVstde1Wf1ASYSmqBz z6hA== X-Gm-Message-State: AJIora+2aehfDDQGcYMYbtvwvwzwj8pylGpCR19hUaHlXhPOOA7e5Mah /umEV6RyUygYA8HC9LUFDNw= X-Google-Smtp-Source: AGRyM1s+iahg02Bpk2EnSzbzRcnr2mtDT4ApnSHUmAQAgW6yLoAtrRkD328H3ucsSETDujo2et3RxQ== X-Received: by 2002:a17:90a:fa05:b0:1ef:89d1:1255 with SMTP id cm5-20020a17090afa0500b001ef89d11255mr20275204pjb.73.1657129837984; Wed, 06 Jul 2022 10:50:37 -0700 (PDT) Received: from MacBook-Pro-3.local ([2620:10d:c090:500::2:8597]) by smtp.gmail.com with ESMTPSA id 200-20020a6214d1000000b00524f29903e0sm25048734pfu.56.2022.07.06.10.50.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Jul 2022 10:50:37 -0700 (PDT) Date: Wed, 6 Jul 2022 10:50:34 -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: <20220706175034.y4hw5gfbswxya36z@MacBook-Pro-3.local> References: <20220623003230.37497-1-alexei.starovoitov@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1657129839; a=rsa-sha256; cv=none; b=qNf/O6w0Ia/wXLQcYlObGDiW0Vh3kj1oc6mFUCt6MWdUsYzFCLRhII+EpK8GDid4ItJlOh h8/xU1aJuSit3Oxx835VvIRaGhrsHkx6dlsv15jL/4/PqnvG5ALJInJ3ikIErvPHuVcsa8 U5lKwTCA4ftF47tfaOxlXYdypWJ0m6c= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=b64OOiZg; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf17.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.216.46 as permitted sender) smtp.mailfrom=alexei.starovoitov@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1657129839; 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=Fe8Q2UUclVbaN//xksGPDN/FPyfgVOHDsw8MqncmWZI=; b=zX/RCzvs/IYvPb0aLPoZ0H9YgL3FYEdY+dMn0LYRUfYDBOs1fpj+rwN5imCts5LE6ofczT BKFKqeLEk910JYBSKXz9r5haSOr1HBzYqlUmLPMQEiEVHb4Qvpg/5ggYeELq97y1nlcA3y /AbrCvmFt1azL+JiUTL970zch+Cy79s= X-Rspamd-Server: rspam04 X-Rspam-User: Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=b64OOiZg; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf17.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.216.46 as permitted sender) smtp.mailfrom=alexei.starovoitov@gmail.com X-Stat-Signature: h8f7twmr46k9188k1m3ctsrxtduab51x X-Rspamd-Queue-Id: F386440050 X-HE-Tag: 1657129838-858370 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 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, kasan, memleak and other debugging facilites that grab locks which make them unusable for bpf tracing progs. The main difference of bpf specific alloc vs the rest is bpf_mem_alloc from the cache and refill of the cache are two asynchronous operations. It allows the former to be reentrant and nmi safe. The speed of bpf mem alloc is secondary here. The lock less free list is there to absorb async refill. irq_work_queue is not instant while bpf prog might do several bpf_mem_alloc before irq_work has a chance to refill. We're thinking about self adjusting low/high watermarks that will be tunned by the bpf verifier that has visibility into what program is going to do.