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 A4C0FC43334 for ; Mon, 27 Jun 2022 07:03:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DD85E6B0071; Mon, 27 Jun 2022 03:03:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D87DE8E0001; Mon, 27 Jun 2022 03:03:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C4F0E6B0073; Mon, 27 Jun 2022 03:03:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id B38076B0071 for ; Mon, 27 Jun 2022 03:03:24 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 8713461043 for ; Mon, 27 Jun 2022 07:03:24 +0000 (UTC) X-FDA: 79623124728.08.4D7F277 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf07.hostedemail.com (Postfix) with ESMTP id 479014009E for ; Mon, 27 Jun 2022 07:03:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=In-Reply-To:Content-Type:MIME-Version :Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To:Content-Transfer-Encoding :Content-ID:Content-Description:References; bh=geJYwLUtZ4AXrvb8AEzXOmV/g8d678nc6SKMnLPSG1M=; b=m6b2pcf5uAViOElJV26xDPMepE 1hBW3qL+THetwMi0IzDHfC+hMrKzWr1/XuqBbA/yprRUQwFmxd3AdB4FHuMMuFZNX9FvEOrcXuJQK SqBSrjZ2o2WAwlilmIi8842J5aqNElWwJZT+U5835oJK3BQ3E9Vw8BT80wwmpzaQeFnh1Y9RBxLuO et4NHfVnT+CCAKWhq2vmTk8BNx2gfTtSnTjl2R0tvu6FJTBHdPD3QTaYDe2c0lHC65LDpC4W7++ms 3GgInQ2YSzp2iSDTLJ15GNmIEeUpHe0JksjrdONWpKx6BmwjWj3npSZkT3b94HlO3mHpLXpCXztQY YoyIy4Iw==; Received: from hch by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1o5im4-00GI72-PA; Mon, 27 Jun 2022 07:03:08 +0000 Date: Mon, 27 Jun 2022 00:03:08 -0700 From: Christoph Hellwig To: Alexei Starovoitov Cc: 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: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220623003230.37497-1-alexei.starovoitov@gmail.com> X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656313404; 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:dkim-signature; bh=geJYwLUtZ4AXrvb8AEzXOmV/g8d678nc6SKMnLPSG1M=; b=kZPXEtoPG2C/CnSBBwKGTZRKFnDgJSoQZ43dOhideUnLD1sQ3H61K7jst8GOtbuyVUPB5I URbCpxHyegMqNPEFI5lT4C/fWeElSO1KC3pbsotPxN5KIqRXwu9D5b44oc1L3ovYi0LG7w QaCs3at7hMzb1VB2zWrRrp2+J18QZCs= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=m6b2pcf5; dmarc=none; spf=none (imf07.hostedemail.com: domain of BATV+327ef3b6ae2033f48346+6882+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+327ef3b6ae2033f48346+6882+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1656313404; a=rsa-sha256; cv=none; b=KtP6mjwmm5+oKaIniWtoohPZbbzAgLSG9aHDJGo548uBOpVSaCsxaOM60TPX6hTbHShQOL U1QLqG7hF5wEHR5dJJSgqtxv11kAivFGxKfdcaL/LoCtKiScpjjRhLt+eEojpGnYQv+8QY 2yWpdgkcIyHGhqV++VmeHnJHeeVXx2U= X-Rspamd-Queue-Id: 479014009E Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=m6b2pcf5; dmarc=none; spf=none (imf07.hostedemail.com: domain of BATV+327ef3b6ae2033f48346+6882+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+327ef3b6ae2033f48346+6882+infradead.org+hch@bombadil.srs.infradead.org X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: qh76tt5x1b3fpezbhr7aama49eei58ce X-HE-Tag: 1656313403-52837 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: 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. > > There is a lot more work ahead, but this set is useful base. > Future work: > - get rid of call_rcu in hash map > - get rid of atomic_inc/dec in hash map > - tune watermarks per allocation size > - adopt this approach alloc_percpu_gfp > - expose bpf_mem_alloc as uapi FD to be used in dynptr_alloc, kptr_alloc > - add sysctl to force bpf_mem_alloc in hash map when safe even if pre-alloc > requested to reduce memory consumption > - convert lru map to bpf_mem_alloc > > Alexei Starovoitov (5): > bpf: Introduce any context BPF specific memory allocator. > bpf: Convert hash map to bpf_mem_alloc. > selftests/bpf: Improve test coverage of test_maps > samples/bpf: Reduce syscall overhead in map_perf_test. > bpf: Relax the requirement to use preallocated hash maps in tracing > progs. > > include/linux/bpf_mem_alloc.h | 26 ++ > kernel/bpf/Makefile | 2 +- > kernel/bpf/hashtab.c | 16 +- > kernel/bpf/memalloc.c | 512 ++++++++++++++++++++++++ > kernel/bpf/verifier.c | 31 +- > samples/bpf/map_perf_test_kern.c | 22 +- > tools/testing/selftests/bpf/test_maps.c | 38 +- > 7 files changed, 610 insertions(+), 37 deletions(-) > create mode 100644 include/linux/bpf_mem_alloc.h > create mode 100644 kernel/bpf/memalloc.c > > -- > 2.30.2 > ---end quoted text---