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 5BF54C77B7D for ; Thu, 18 May 2023 19:10:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A29C2900004; Thu, 18 May 2023 15:10:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9D9CA900003; Thu, 18 May 2023 15:10:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8A17F900004; Thu, 18 May 2023 15:10:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 76687900003 for ; Thu, 18 May 2023 15:10:51 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 36BEF160920 for ; Thu, 18 May 2023 19:10:51 +0000 (UTC) X-FDA: 80804317902.17.A657F71 Received: from out-12.mta0.migadu.com (out-12.mta0.migadu.com [91.218.175.12]) by imf29.hostedemail.com (Postfix) with ESMTP id 1A12312000E for ; Thu, 18 May 2023 19:10:48 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=i13k7+86; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf29.hostedemail.com: domain of kent.overstreet@linux.dev designates 91.218.175.12 as permitted sender) smtp.mailfrom=kent.overstreet@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684437049; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=pTE9m9G2YQF3y82OvwFBbeZse+nVjMDUG8xTbRI5o5Q=; b=U61te+pjnZirlnZACk3NkjwlGcGxBgO108xLlW8wGF0DH/NTvnSP9kIuOuBjIhzgWYB9hJ r6pNDzK824DcMKXQ5c8zZqTkpKtS7MFHtlKLmBw5lSm+dWDgKQKz3Uz3psWqWen+LbGMoT vGD7YoL/Kf9Xbf2zV6mM8XuWUypRObg= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=i13k7+86; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf29.hostedemail.com: domain of kent.overstreet@linux.dev designates 91.218.175.12 as permitted sender) smtp.mailfrom=kent.overstreet@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684437049; a=rsa-sha256; cv=none; b=TvKWKFn+HkcxfG7FdpSbWRT37d6VKTTVZE+d8qFDYLoQkiQyi8TR99krYt9wtdkCNEavCC wDRutGIRTDbiducgxt9edw1qetKkDqc5RJzRhsZw35OQVh5PbMR1950DWeuFPK4Lbs/30H buTV9HANbPHlN5FCX5YuTcDigwq0Qfw= 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-Rspamd-Queue-Id: 1A12312000E X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: oppxi76m6y4nqpiqq5jiqs6c3b4kfhcn X-HE-Tag: 1684437048-209671 X-HE-Meta: U2FsdGVkX1/+key14ZP6PG4Ev9wiJqr1sFFuwwj/iLBrBH/7iTKnreU9uWD/mNjkI0HhgeeV9dVAej6xXQWb5zbGrLr2s3ajnGcctVOsJhYGusicoolwIaT1Q9wtrWhSx5kWrLktsgEjqWLZNcv2EJYX2KYKlRgd1DGHgjS0TLeeIxj+Aw4ucO/wj9JaLyC+AeddzHNsqkvtvyRuKopYzSqU0IuHjY8o87Ptr0oslm97KFgMABhQehRs5kJCHHw5/VeDSHH2yMVPwIPX9hPN3D/BOaEZEBsC7XwNfL2aBOy+Oq5EMhc/1ZzOKbfU84r9/OcfxrCbAx9Ayg2EwKMIKPBVNU0Il1yfkXzLQLG5GxLbKJM5ZdVObiTY0PnOeRLueVDNlW238N4GeWNl6ap5eihAwtB/koY0bjOzH1zNB49pq//xNNdXa3hFr7iELs7zv7sJCPks9kMYUSCoyPcM2E8RFxir4v88vI+lLmr0x/d52ZTXK6M4GUZzu1hQUwum5Z/G90I1gUTx/pR2IGRxIz0GayQ54O/iYDseTb/GNr7pjFy44LRjK6Y+ihnGIC0aoEiNsk01pejL/HIO7munF3HHxHHj//gY4DgkCTvhBQu4sJRbcV7WYlukS/H3thzCzUO6eh9Lf5e1YXTeNhXiNmEuZG/W0qy2uRLDeOQz/KIXE221N8riju+SjxgvzwfUKWij7teZERxh32MqSM1perE1U2pFkuskQpsGlSUJ6wR+KRkTzmL7nkvtdDhVkji6KCEcVh2wWWd0THxXoCMZv1dHbsmmOswOJfxrcxPXmD/vFoHJYVQKzQUMB5EKn6h8JH0JoLNopWrusvT3P95CHuH3/CZc/z72ecMMySyFLEqZKy1oGlCGGPtRBZ3VaXGVxT+MqFpmKFnWf1DDJzoESnqblBMHeXpUsS7nayQUCSUwmsdjX9kKUsI8pKqVwGe4q2NWxK1LgGtUirprxyl hspLe4ve b5LieEEJbE1uZF/XG+iFmnDpsuYH8BZO8FlkW9RU2gtBJsvll01jxnxtMrVNdsVaPamrrCDQ6YVslXmHRCLFwsMbqG+JgK9WA7qKB 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 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.