Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1502516rwd; Thu, 18 May 2023 12:54:46 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5FVKLI/BvO/545ZiVL2VNsYjhbSK681SXKYILo1W5Pgg+jGIZ68xBmoUGd1bDHUVX5MN6l X-Received: by 2002:a17:90a:118f:b0:250:d12d:1a1 with SMTP id e15-20020a17090a118f00b00250d12d01a1mr4197899pja.12.1684439685797; Thu, 18 May 2023 12:54:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684439685; cv=none; d=google.com; s=arc-20160816; b=fu5DxQEvxq2yMR3HizDd88NnEpYNKNNGgDPsFYEqykRkfoJOw9GJPHJkZb3w6uxnDz qRFyk8YLM3x1kHdBkR7q7W0TpImAAq+Euzfp8lx4M5CYJQLxeci5tErsN/V29YxX9cws FxFJIYAX3mvCgoI5W98u9EcXJzHxt7hO6s8E/f5VnPvCxIxfWPLtxEqGqUj79GRLsViE zDkzAEaICTqPr+piRzdLJ7jZlgFdiMFam8p1ThxR4mfvLEXmmfrYVXL/I+5K6P+AzKBA i/ZG5lAyIscDAhBLtrklsNGZDz69EyYX8mEGtLVi2qkLwwvjC5h7m9G7ZrQ6/7t0TRya vI9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:dkim-signature:date; bh=pTE9m9G2YQF3y82OvwFBbeZse+nVjMDUG8xTbRI5o5Q=; b=v0QfMSlOUbjqezXWbEDIDcVzqDPzF2E/+7MMzVgemZPNpEE0wJWgT1jHdRR6KHfbEF RJkDdabOZZuYZvs2JdMoL+2jZbET9Ac5cpaCq94o1e83lTkUBvsBxPgWy0Ju6099+Gb3 u0GxCfQaEBC+huWVHKVc8BbUdW+V9Zn+i1nQsJZkI2pyOpbJ1Q+9a4pdoTQjC6zNUU1n XZuoS/oE1uylRJ84z0ai4L0T+klS6IEYJzPt1DUDHYyx/8SVBh8xYnlNjW1npd/gDoNO jNo1Elc+h5WCeg8E4ZC0aZDURJGSuViIhg+O8aZ4lFl4CeMBE/aea/Zp4Mhc1AshGZeV SDBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=i13k7+86; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s30-20020a63925e000000b005304a8af2a2si2403309pgn.404.2023.05.18.12.54.33; Thu, 18 May 2023 12:54:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=i13k7+86; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229967AbjERTKv (ORCPT + 99 others); Thu, 18 May 2023 15:10:51 -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 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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.