From nobody Wed Aug 19 20:03:42 2026 X-Original-To: freebsd-hackers@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4hQHZX4Ntlz6pZjf for ; Wed, 19 Aug 2026 20:03:48 +0000 (UTC) (envelope-from vadimnuclight@gmail.com) Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "WR4" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4hQHZW6qJ2z3dsy for ; Wed, 19 Aug 2026 20:03:47 +0000 (UTC) (envelope-from vadimnuclight@gmail.com) Authentication-Results: mx1.freebsd.org; dkim=pass header.d=gmail.com header.s=20251104 header.b=DUuA89fP; spf=pass (mx1.freebsd.org: domain of vadimnuclight@gmail.com designates 2a00:1450:4864:20::330 as permitted sender) smtp.mailfrom=vadimnuclight@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-4956869750eso9256095e9.2 for ; Wed, 19 Aug 2026 13:03:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787169825; x=1787774625; darn=freebsd.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=Dl62dyv/gurW2hjQ13XYEthRSWkHytDVG/uRbbR6yoM=; b=DUuA89fPfi9bUzzt90+IVdfVH/e13d5Lkk+Ck5R3f6MpWR2P1+geokZwNMAdyXPADH 6QJjNtUcmi4zpWRl0NoLh81p10d7SnBYSyyje582RKFBDT0hCOb0Qw6Q9zczcQ9yjZQE 19zCAHdoWdiZ6hVmE6vwrz5NciPTdjb5Col8QYt92rBpJwSPxcXZT0grOM2QhK+TwL1z rKDjki5P8JZnhxQ0MJ0AHGEUuRqsWCz+ZXL56AsQd1u4r2aAwHdx0uMY3HuUfRzsWrNu nJQDNC6X10L4FCQXmbApmHB146MWdWqrERdgxBbH6ebxQXir1Q27WIWOZTzlgxp2G0D8 RIBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787169825; x=1787774625; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=Dl62dyv/gurW2hjQ13XYEthRSWkHytDVG/uRbbR6yoM=; b=W2pcS59JLS54YqvkeRm2idSTRgYOPSZftdS6i7yUx+1kEzGiIm75/D/8i+vfZ+fpJf FvgHCrfMvVy8CXZMRgq/O1n7yIjAfln0XX5EjXQSQ28E2iIzvpHIYCmyEX0E0EMk+bDm 0rP2F+eIU8lr2C3UrtW828yFBLMxesSx/nRjg0MDD9/pAs9aXM8nTHN2ZCy4TOtWv7Bp dT1nKMFoVQ62TLI4piAlGvfj1xNcz1IKLw6Zs4D5/+rPOSvhS1lB9B3956wuCOXansKR 5e/O5FzTET0T57WzXAFlvLlpwsepSZawT6zsmYgCh6Yg8Ba7+9Qw+JKlwct1hMBJ7pgR 6btQ== X-Gm-Message-State: AOJu0YwZZOQeXwpelHdycSuYQnQZAyrLF4XHU1wo4EiqfAhUfr4SwEts JBEA1clTstoUvRJR3wgACRMNdWRi7K7Y9jnhJjt/SvWoziZBXKhmy9DskmUolrHE X-Gm-Gg: AR+sD12EtCxgeaVKZeXM8hCiTEuA37B/ph8li9GzcS/4A6oUCguxqynCY5JC7d9C7C1 jrUQV/frOSCFCfUDMSKznpUWO5v/L02zZbZjPcaq+Uh5cWhMzinz7NkddKTKqf44Qpcx5Oh/7jo flG0/Z4KokTzt6s5PBhM7HiVDK36FrCa6ayQkO9jqNgPTlSKBNK2nnknN+SYFIKWtSvxYmrd8+H 1cloLbaa4Kxny7ZIsKcLyU1sBLPb3piElgoZW99wy+s87D4SIiAUv7MPLp3YLW5HeZonTD+t2AV jaPShVntmi+0/Cxgu8mH6tcRU+aMppLtUPN7VNhajKSm1kZ72G1qTBEfXwAJPPAMZrd+va936rA MI7NQUeSc5zF4CPXu/5xj60VbSzvmUd2C0uxyqZ7D5q+bp54pv4CrjGUQVE47W1QVcSqpxTICbj 3aLHo/pyhdX91uXfwON+DneyywMBLs/tgP6ccQbwKw0xwIDl5TsEuhUW5lngQboCVeiyiJIwcX1 BSq8+Qm9M/cmja7X8+UnS4vDlVH4z+4WOH2 X-Received: by 2002:a05:600c:1d1a:b0:493:a623:d090 with SMTP id 5b1f17b1804b1-499aa1dde53mr130489355e9.10.1787169825023; Wed, 19 Aug 2026 13:03:45 -0700 (PDT) Received: from nuclight.lan (broadband-77-37-180-76.ip.moscow.rt.ru. [77.37.180.76]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-499aa0fd728sm120328555e9.3.2026.08.19.13.03.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Aug 2026 13:03:44 -0700 (PDT) Date: Wed, 19 Aug 2026 23:03:42 +0300 From: Vadim Goncharov To: Mark Johnston Cc: freebsd-hackers@freebsd.org Subject: Re: 5 gigs of contiguos kernel VM shared with userspace Message-ID: <20260819230342.0bacc088@nuclight.lan> In-Reply-To: References: <20260810013202.1c5a16d1@nuclight.lan> <20260810051249.747e59c2@nuclight.lan> X-Mailer: Claws Mail 4.4.0 (GTK 3.24.52; amd64-portbld-freebsd13.5) List-Id: Technical discussions relating to FreeBSD List-Archive: https://lists.freebsd.org/archives/freebsd-hackers List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-hackers@FreeBSD.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spamd-Result: default: False [-4.00 / 15.00]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-1.00)[-0.998]; DMARC_POLICY_ALLOW(-0.50)[gmail.com,none]; R_SPF_ALLOW(-0.20)[+ip6:2a00:1450:4864::/56:c]; R_DKIM_ALLOW(-0.20)[gmail.com:s=20251104]; MIME_GOOD(-0.10)[text/plain]; MIME_TRACE(0.00)[0:+]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; FREEMAIL_FROM(0.00)[gmail.com]; ASN(0.00)[asn:15169, ipnet:2a00:1450::/32, country:US]; DWL_DNSWL_NONE(0.00)[gmail.com:dkim]; FREEMAIL_ENVFROM(0.00)[gmail.com]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCVD_IN_DNSWL_NONE(0.00)[2a00:1450:4864:20::330:from]; PREVIOUSLY_DELIVERED(0.00)[freebsd-hackers@freebsd.org]; TO_MATCH_ENVRCPT_SOME(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; RCVD_TLS_LAST(0.00)[]; RCPT_COUNT_TWO(0.00)[2]; MLMMJ_DEST(0.00)[freebsd-hackers@freebsd.org]; DKIM_TRACE(0.00)[gmail.com:+] X-Rspamd-Queue-Id: 4hQHZW6qJ2z3dsy X-Spamd-Bar: --- On Mon, 10 Aug 2026 11:22:29 -0400 Mark Johnston wrote: > On Mon, Aug 10, 2026 at 05:12:49AM +0300, Vadim Goncharov wrote: > > On Sun, 9 Aug 2026 19:15:59 -0400 > > Mark Johnston wrote: > > > > > On Mon, Aug 10, 2026 at 01:32:02AM +0300, Vadim Goncharov wrote: > > > > Hello, > > > > > > > > Are there ways to allocate in kernel a range of contiguous virtual > > > > address space, share it with userspace, and preferably run memory > > > > allocator inside it which has it's pointers relative to base address? > > > > Same as processes cooperating via mmap(), but for kernel<->user. > > > > > > > > I'd like just run UMA inside it, but seems UMA zones cannot be told to > > > > take from particular range, or am I missing something? On user side, > > > > jemalloc mentions something like arenas, but seems it is too > > > > unprepared for even mmap() between processes case (may be adapting > > > > some TLSF allocator [*] is possible, but that's a premature question > > > > before VM one). > > > > > > UMA is really two fairly distinct things: a slab allocator, and a cache. > > > UMA zones provide per-CPU and per-NUMA domain caches, and UMA kegs > > > allocate and manage slabs. > > > > > > You can have a zone without a keg: if you have some collection of > > > objects you want to allocate to consumers, you can use > > > uma_zcache_create() to create a "cache zone" which provides the usual > > > per-CPU etc. caches to store objects returned by a custom uz_import > > > callback that you provide when creating the zone. For instance, if you > > > have some static array of objects (i.e., there is no need to subdivide a > > > slab) and just want to slap a scalable cache in front of it, > > > uma_zcache_create() is handy. > > > > > > The other thing you could do is provide a custom slab allocator for the > > > keg via uma_zone_set_allocf(). There, you provide some page allocator, > > > and you can impose whatever constraints you want. uma_small_alloc() is > > > used by default for page-sized slabs, and page_alloc() is used by > > > > Is that all ported/portable to userspace? > > No. Most of it probably wouldn't be too bad. I'd move some parts of it > to a uma_kern.c (e.g., uma_small_alloc() and page_alloc(), referenced > above, would live there). Have jemalloc similar thing to slabs, even if only for some limited set of sizes? I expect many of my objects being 32-byte size. > But you'd also need to decide how per-CPU > caches should be implemented in userspace. Oh, I did not think about that at all - so far, I presumed single-threaded userspace process. > > > default for multi-page slabs. Your implementation could return pages > > > from some pre-allocated, contiguous range of memory. > > > > That's the main [prerequisite] question: how to do in kernel thing similar > > to mmap(0, 0x5000000, MAP_SHARED|MAP_ALIGNED_SUPER, ...) and share this > > region with userspace process(es). > > It depends, I guess you want the region to be demand-paged? I don't know for sure. Likely, I'll need it wired, or both variants for different setups. The question is because being swapped is simpler? > If so, something like: > 1. kmem_subinit() to find some region of the kernel address space it can > use to map the area. > 2. Allocate a VM object. > 3. Use vm_map_find() to allocate the kernel virtual address region from > the submap, and to associate that region with your VM object. > 4. Map that VM object into userspace as desired, e.g., by returning the > VM object from some device node's d_mmap_single implementation. > 5. Now the kernel and participating userspace programs can fault on > their respective mappings of that VM object. I haven't found man page for kmem_subinit, where can I read more background on it? -- WBR, @nuclight