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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 70098C77B7D for ; Thu, 18 May 2023 19:11:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230218AbjERTKw (ORCPT ); Thu, 18 May 2023 15:10:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229553AbjERTKu (ORCPT ); Thu, 18 May 2023 15:10:50 -0400 Received: from out-22.mta0.migadu.com (out-22.mta0.migadu.com [91.218.175.22]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AEF1198 for ; Thu, 18 May 2023 12:10:48 -0700 (PDT) Date: Thu, 18 May 2023 15:10:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1684437046; h=from:from: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pTE9m9G2YQF3y82OvwFBbeZse+nVjMDUG8xTbRI5o5Q=; b=i13k7+869NLwZHoG32SSkSjBCsz/GmdDXRWkQt7PfcP7BocdKjdrKACQgzHQfznKCl8VRa XvYbZX3X7zVKBis8q4OTniEc5QE9YOTi3HypKZx6OcNqyz+9aVpiZxKfyoiOBIYaGgtfIh Kz3mgAERwxzMjLWwlXkozEhwruCWcAg= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Kent Overstreet To: Song Liu Cc: Mike Rapoport , linux-mm@kvack.org, Andrew Morton , Dave Hansen , Peter Zijlstra , Rick Edgecombe , Thomas Gleixner , Vlastimil Babka , linux-kernel@vger.kernel.org, x86@kernel.org Subject: Re: [RFC PATCH 1/5] mm: intorduce __GFP_UNMAPPED and unmapped_alloc() Message-ID: References: <20230308094106.227365-1-rppt@kernel.org> <20230308094106.227365-2-rppt@kernel.org> <20230518152354.GD4967@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Migadu-Flow: FLOW_OUT Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 18, 2023 at 12:01:26PM -0700, Song Liu wrote: > On Thu, May 18, 2023 at 9:58 AM Kent Overstreet > wrote: > > > > On Thu, May 18, 2023 at 09:33:20AM -0700, Song Liu wrote: > > > I am working on patches based on the discussion in [1]. I am planning to > > > send v1 for review in a week or so. > > > > For reference, here's my own (early, but functioning :) slab allocator: > > > > Look forward to comparing! > > -->-- > > From 6eeb6b8ef4271ea1a8d9cac7fbaeeb7704951976 Mon Sep 17 00:00:00 2001 > > From: Kent Overstreet > > Date: Wed, 17 May 2023 01:22:06 -0400 > > Subject: [PATCH] mm: jit/text allocator > > > > This provides a new, very simple slab allocator for jit/text, i.e. bpf, > > ftrace trampolines, or bcachefs unpack functions. > > > > With this API we can avoid ever mapping pages both writeable and > > executable (not implemented in this patch: need to tweak > > module_alloc()), and it also supports sub-page sized allocations. > > > > Signed-off-by: Kent Overstreet > > [...] > > > +static void *jit_cache_alloc(void *buf, size_t len, struct jit_cache *cache) > > +{ > > + struct jit_slab *s = > > + list_first_entry_or_null(&cache->partial, struct jit_slab, list) ?: > > + jit_slab_alloc(cache); > > + unsigned obj_idx, nr_allocated; > > + > > + if (!s) > > + return NULL; > > + > > + obj_idx = find_first_zero_bit(s->objs_allocated, cache->objs_per_slab); > > + > > + BUG_ON(obj_idx >= cache->objs_per_slab); > > + __set_bit(obj_idx, s->objs_allocated); > > + > > + nr_allocated = bitmap_weight(s->objs_allocated, s->cache->objs_per_slab); > > + > > + if (nr_allocated == s->cache->objs_per_slab) { > > + list_del_init(&s->list); > > + } else if (nr_allocated == 1) { > > + list_del(&s->list); > > + list_add(&s->list, &s->cache->partial); > > + } > > + > > + return s->executably_mapped + (obj_idx << cache->obj_size_bits); > > +} > > IIUC, "len" is ignored in jit_cache_alloc(), so it can only handle > <=16 byte allocations? len is a redundant parameter (good catch); at that point we've picked a cache for the specific allocation size. Since there's multiple caches for each power of two size, it can handle allocations up to PAGE_SIZE.