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 0A594C433EF for ; Mon, 4 Jul 2022 20:34:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 848166B0071; Mon, 4 Jul 2022 16:34:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7F7CB6B0073; Mon, 4 Jul 2022 16:34:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6E6A06B0074; Mon, 4 Jul 2022 16:34:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 60E6F6B0071 for ; Mon, 4 Jul 2022 16:34:45 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id 37551608EB for ; Mon, 4 Jul 2022 20:34:45 +0000 (UTC) X-FDA: 79650570930.21.39A5632 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf05.hostedemail.com (Postfix) with ESMTP id 05A8110000A for ; Mon, 4 Jul 2022 20:34:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=KhZLsdjNJwqTmp88ps2zeJpnsRuT5FoHdMFz9vEVRgg=; b=sB1rdYGO1L1ZeDjR6sSTw8ZEw2 mRwfnP+6T+ZFFVrLxRnrkwGQo5diBirgFsy50bJGgiNi4ZK8vVudvG4Mv57ZScEhzHXWt549g+dDI T5KfoWyDG0fLCMKe+61xej6OTrTGh6RhY9bPxri5R5Z22GrhDWcQvar8d6uJy+hZZsBg/e4Cu9UYv td74VEzB8St4G4p3vHd/rFVKajqiF8M9duRD8iZDGC62RLlkcq2Oqf5mCsNjujZxlyrgQKOZTa52d D+YoSINfnVxJK3tpdjtKdG99+PBQ7N4oQvEV2VVqFOjmd8vpq350s+Bzz1lA52uuDOAjKtBvVmivg Qo35ut7A==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1o8Slz-00HZql-SG; Mon, 04 Jul 2022 20:34:24 +0000 Date: Mon, 4 Jul 2022 21:34:23 +0100 From: Matthew Wilcox To: Christoph Hellwig Cc: Alexei Starovoitov , 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: 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=1656966884; a=rsa-sha256; cv=none; b=nPCpG89Ncszx/wL8wtYueU4bG+5IN4e06t0YqqDi5aAVVVsCZ2LZZoCuJjZOdEp0b4auf+ 8LJJWrW1+i5kIg6S2dxvXTTCm3gupOeJJs4hDhXdEL9hT4J5clPWbFd0lrx277TzcaGcgA 9XSUqFcl1CYYmf1xlk1AYZEIXL9VBg8= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=sB1rdYGO; dmarc=none; spf=none (imf05.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656966884; 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=KhZLsdjNJwqTmp88ps2zeJpnsRuT5FoHdMFz9vEVRgg=; b=jilNGbiJqWRbgkGo1GgON6bmn6TBBKKwhN9o9hcr4OE/51qcb5LbUektvODORyWt3KFlNa M89xlGl6erD8GO5yfxo6VykAGg2WH/eIFRaBKz9nBcErYBaZ6fuaWGBSV3NBkvDHfAtM0m yL9OMwFl6suVYmq/s0tXU1b3Dktt8+I= Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=sB1rdYGO; dmarc=none; spf=none (imf05.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org X-Rspam-User: X-Stat-Signature: ua7c4qcs1183jg9ey9bn8t838tfku9bp X-Rspamd-Queue-Id: 05A8110000A X-Rspamd-Server: rspam04 X-HE-Tag: 1656966883-514394 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, 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. > > 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--- >