🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: muc.lists.freebsd.hackers
Article #89

Re: FemtoFS

#89
From: Andrea Cocito
Date: Fri, 16 Oct 2026 10:04
205 lines
15639 bytes
--Apple-Mail=_00990E5F-3203-4DFB-AA93-CD68A8406936
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
	charset=utf-8

Hello Adrian, adding -fs@ in the loop.

> On 15 Oct 2026, at 23:22, Adrian Chadd <adrian@freebsd.org> wrote:
> On Wed, 14 Oct 2026 at 23:56, Andrea Cocito <andrea@cocito.eu =
<mailto:andrea@cocito.eu>> wrote:
>> Hello,
>>=20
>> As a weekend project I am working on a small filesystem.=20
>>=20
>> The idea is to have a read-only filesystem focused at efficiency =
useable for =E2=80=9Cfirmare images=E2=80=9D or projects like NanoBSD or =
mfsBSD, where using a full UFS image is a waste of space and resources.
>>=20
>> I am at a point where I have it more or less working (see =
git@github.com:puffetto/FemtoFS.git / =
https://github.com/puffetto/FemtoFS.git ); but need advice and a second =
opinion about a design issue.
>>=20
>> Currently the code, when mounting an image off md(4), duplicates the =
whole memory area to have a private copy.
>>=20
>> To avoid this I see two options:
>>=20
>> a. Add two hooks in md(4): md_image_hold(*consumer, **address, *size) =
and md_image_release(*consumer) which basically tell md(4): =E2=80=9CThis =
image is now locked for my use, don=E2=80=99t touch it=E2=80=9D and =
=E2=80=9CHere is it, it's back yours=E2=80=9D.
>>=20
>> b. Implement a separate (and simplified) =E2=80=9Crmd=E2=80=9D driver =
which exposes those two hooks in a simplified =E2=80=9Cmd=E2=80=9D =
provider.
>>=20
>> I think that option =E2=80=98a.=E2=80=99 is cleaner, but I wonder =
if/when a small patch providing those hooks would ever make it into the =
FreeBSD tree.=20
>=20
> Oh, interesting. You're not accessing the backing device via bio =
calls. Your code treats the filesystem as one big chunk of memory.
> I think that's the big disconnect here - md doesn't expose the memory =
region as a single huge region.
>=20
> It would change your filesystem to be quite a bit more complicated =
because your code would have to grow bio and sleep/wakeup code.

The point is exactly not using bio*, take the case when we boot off an =
md image as mfsBSD/NanoBSD and think of libc.so <http://libc.so/>, with =
UFS:
- The bootloader uncompresses the image in physical RAM
- Each and every binary mmap() libc.so and makes a new copy of it
Avoiding it would mean, as a minimum, use a sector size of 4KiB for the =
image and make substantial work in UFS.

While with FemtoFS once a file is made of pages of physical memory it =
can be mmap=E2=80=99ed in process memory without copying anything: just =
moving pointers*.

One copy, without changing md(4) or using another driver, is still =
needed when =E2=80=9Cmounting=E2=80=9D the filesystem; changing md to =
expose the backing memory pages (obviously when in RAM) would avoid that =
copy.

The impact would not be huge: a few dozens of real lines of code in =
md(4) and no expected change in behaviour unless one uses those hooks:

 =
https://github.com/freebsd/freebsd-src/compare/releng/15.1...puffetto:free=
bsd-src:femtofs/md-preload-15.1

[Code is mine, docs and tests done by LLM]

The other way could be to used something dedicated instead of md(4), and =
which way to follow is the open question.

*) Actually when FemtoFS mounts in =E2=80=9Cclean=E2=80=9D mode the last =
page of the file needs to be copied, only one and only the first time we =
mmap(), as the free space after EOF could have been reused to store some =
small file and full posix compliance requires it to be zeroed.

Thanks for you advice,

A.


>=20
>>=20
>> Opinions?
>>=20
>> While here if anyone wants to take a look at the specification and =
code and report me any issue, mistake or bug they find it would be =
great. A lot of work, admittedly, was done by Codex.
>=20
> It definitely needs a bunch of cleanup work and layout work but i =
mean, if it works it works! It's a good starting point, and I think the =
first filesystem I've seen written for FreeBSD in a while now. :-)
>=20
>=20
>=20
> -adrian
>=20


--Apple-Mail=_00990E5F-3203-4DFB-AA93-CD68A8406936
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html;
	charset=utf-8

<html aria-label=3D"message body"><head><meta http-equiv=3D"content-type" =
content=3D"text/html; charset=3Dutf-8"></head><body =
style=3D"overflow-wrap: break-word; -webkit-nbsp-mode: space; =
line-break: after-white-space;">Hello Adrian, adding -fs@ in the =
loop.<br id=3D"lineBreakAtBeginningOfMessage"><div><br><blockquote =
type=3D"cite"><div>On 15 Oct 2026, at 23:22, Adrian Chadd =
&lt;adrian@freebsd.org&gt; wrote:</div><div><div dir=3D"ltr"><div =
class=3D"gmail_quote gmail_quote_container"><div dir=3D"ltr" =
class=3D"gmail_attr">On Wed, 14 Oct 2026 at 23:56, Andrea Cocito &lt;<a =
href=3D"mailto:andrea@cocito.eu">andrea@cocito.eu</a>&gt; =
wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0px =
0px 0px 0.8ex;border-left:1px solid =
rgb(204,204,204);padding-left:1ex"><div>Hello,<div><br></div><div>As a =
weekend project I am working on a small =
filesystem.&nbsp;</div><div><br></div><div>The idea is to have a =
read-only filesystem focused at efficiency useable for =E2=80=9Cfirmare =
images=E2=80=9D or projects like NanoBSD or mfsBSD, where using a full =
UFS image is a waste of space and resources.</div><div><br></div><div>I =
am at a point where I have it more or less working (see =
git@github.com:puffetto/FemtoFS.git / <a =
href=3D"https://github.com/puffetto/FemtoFS.git" =
target=3D"_blank">https://github.com/puffetto/FemtoFS.git</a> ); but =
need advice and a second opinion about a design =
issue.</div><div><br></div><div>Currently the code, when mounting an =
image off md(4), duplicates the whole memory area to have a private =
copy.</div><div><br></div><div>To avoid this I see two =
options:</div><div><br></div><div>a. Add two hooks in md(4): =
md_image_hold(*consumer, **address, *size) and =
md_image_release(*consumer) which basically tell md(4): =E2=80=9CThis =
image is now locked for my use, don=E2=80=99t touch it=E2=80=9D and =
=E2=80=9CHere is it, it's back yours=E2=80=9D.</div><div><br></div><div>b.=
 Implement a separate (and simplified) =E2=80=9Crmd=E2=80=9D driver =
which exposes those two hooks in a simplified =E2=80=9Cmd=E2=80=9D =
provider.</div><div><br></div><div>I think that option =E2=80=98a.=E2=80=99=
 is cleaner, but I wonder if/when a small patch providing those hooks =
would ever make it into the FreeBSD =
tree.&nbsp;</div></div></blockquote><div><br></div><div>Oh, interesting. =
You're not accessing the backing device via bio calls. Your code treats =
the filesystem as one big chunk of memory.</div><div>I think that's the =
big disconnect here - md doesn't expose the memory region as a single =
huge region.</div><div><br></div><div>It would change your filesystem to =
be quite a bit more complicated because your code would have to grow bio =
and sleep/wakeup =
code.</div></div></div></div></blockquote><div><br></div><div>The point =
is exactly not using bio*, take the case when we boot off an md image as =
mfsBSD/NanoBSD and think of <a href=3D"http://libc.so">libc.so</a>, with =
UFS:</div><div>- The bootloader uncompresses the image in physical =
RAM</div><div>- Each and every binary mmap() libc.so and makes a new =
copy of it</div><div>Avoiding it would mean, as a minimum, use a sector =
size of 4KiB for the image and make substantial work in =
UFS.</div><div><br></div><div>While with FemtoFS once a file is made of =
pages of physical memory it can be mmap=E2=80=99ed in process memory =
without copying anything: just moving =
pointers*.</div><div><br></div><div>One copy, without changing md(4) or =
using another driver, is still needed when =E2=80=9Cmounting=E2=80=9D =
the filesystem; changing md to expose the backing memory pages =
(obviously when in RAM) would avoid that =
copy.</div><div><br></div><div>The impact would not be huge: a few =
dozens of real lines of code in md(4) and no expected change in =
behaviour unless one uses those =
hooks:</div><div><br></div><div>&nbsp;https://github.com/freebsd/freebsd-s=
rc/compare/releng/15.1...puffetto:freebsd-src:femtofs/md-preload-15.1</div=
><div><br></div><div>[Code is mine, docs and tests done by =
LLM]</div><div><br></div><div>The other way could be to used something =
dedicated instead of md(4), and which way to follow is the open =
question.</div><div><br></div><div>*) Actually when FemtoFS mounts in =
=E2=80=9Cclean=E2=80=9D mode the last page of the file needs to be =
copied, only one and only the first time we mmap(), as the free space =
after EOF could have been reused to store some small file and full posix =
compliance requires it to be zeroed.</div><div><br></div><div>Thanks for =
you =
advice,</div><div><br></div><div>A.</div><div><br></div><br><blockquote =
type=3D"cite"><div><div dir=3D"ltr"><div class=3D"gmail_quote =
gmail_quote_container"><div><br></div><blockquote class=3D"gmail_quote" =
style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid =
rgb(204,204,204);padding-left:1ex"><div><div><br></div><div>Opinions?</div=
><div><br></div><div>While here if anyone wants to take a look at the =
specification and code and report me any issue, mistake or bug they find =
it would be great. A lot of work, admittedly, was done by =
Codex.</div></div></blockquote><div><br></div><div>It definitely needs a =
bunch of cleanup work and layout work but i mean, if it works it works! =
It's a good starting point, and I think the first filesystem I've seen =
written for FreeBSD in a while now. =
:-)</div><div><br></div><div><br></div><div><br></div><div>-adrian</div><d=
iv><br></div></div></div>
</div></blockquote></div><br></body></html>=

--Apple-Mail=_00990E5F-3203-4DFB-AA93-CD68A8406936--


--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
Technical Details
Message-ID: <1568ADBB-8BBB-4144-8040-E486B919501A@cocito.eu>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!2.eu.feeder.erje.net!feeder.erje.net!news2.arglkargh.de!news.karotte.org!news.space.net!news.muc.de!.POSTED.news.muc.de!not-for-mail
References: <CAJ-Vmomx6p7y6e2CeXaniYuz=ar74q5q2Ao2Zkk2zris3HG_+w@mail.gmail.com> <>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!2.eu.feeder.erje.net!feeder.erje.net!news2.arglkargh.de!news.karotte.org!news.space.net!news.muc.de!.POSTED.news.muc.de!not-for-mail
From: Andrea Cocito <andrea@cocito.eu>
Newsgroups: muc.lists.freebsd.hackers
Subject: Re: FemtoFS
Date: Fri, 16 Oct 2026 12:04:28 +0200
Organization: Newsgate at muc.de e.V.
Sender: owner-freebsd-hackers@FreeBSD.org
Approved: news-admin@muc.de
Distribution: world
Message-ID: <1568ADBB-8BBB-4144-8040-E486B919501A@cocito.eu>
References: <CAJ-Vmomx6p7y6e2CeXaniYuz=ar74q5q2Ao2Zkk2zris3HG_+w@mail.gmail.com> <>
MIME-Version: 1.0 (Mac OS X Mail 16.0 \(3864.700.51.1.1\))
Content-Type: multipart/alternative;
	boundary="Apple-Mail=_00990E5F-3203-4DFB-AA93-CD68A8406936"
Injection-Info: news.muc.de; posting-host="news.muc.de:193.149.48.2";
	logging-data="62273"; mail-complaints-to="news-admin@muc.de"
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim;
	t=1792145103; h=from:from:sender:sender:reply-to:subject:subject:date:date:
	 message-id:message-id:to:to:cc:cc:mime-version:mime-version:
	 content-type:content-type:in-reply-to:in-reply-to:
	 references:references:list-id:list-help:list-owner:list-unsubscribe:
	 list-subscribe:list-post; bh=SDqGnE1XBvMYMbTjranxWBzSLFivUM6hx0gGZrOFK0M=;
	b=Y/LZxuRPr5BPAOvV/wz2IiMXPYFmnmw88Uy8ujNYrjkR8OuuWZlsaKWc+eBlNbgWwaRolQ
	gePv0Geq8YBL/reutdI141+FWpGIjf8GTLBu7kd42YxA6E9pswzfV9nX/r/xXZcEbZRF2d
	7XPIAN4qGpFlTysBtsEIs2GKSQD6tS9QLBwFt0algU3ABwMak25VxHRxWmXCz+J+lxud86
	67Erpkj75vedNd8jEmwLFF+D4Q9IfzoqJupDpATmn7RlBUcifqQXvNJGrfGCpMiAq0avbm
	HxoTD6EstG/uf+B024ywa7LUwbFLloowy2QynGivpJelU1hnjKFG7e3LXDuw3w==
X-Original-To: freebsd-hackers@mlmmj.nyi.freebsd.org
Authentication-Results: mx1.freebsd.org;
	dkim=pass header.d=cocito-eu.20251104.gappssmtp.com header.s=20251104 header.b=f22C4bcg;
	spf=pass (mx1.freebsd.org: domain of andrea@cocito.eu designates 2a00:1450:4864:20::42e as permitted sender) smtp.mailfrom=andrea@cocito.eu;
	dmarc=none
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=cocito-eu.20251104.gappssmtp.com; s=20251104; t=1792145085; x=1792749885; darn=freebsd.org;
        h=references:to:cc:in-reply-to:date:subject:mime-version:content-type
         :message-id:from:from:to:cc:subject:date:message-id:reply-to
         :content-type;
        bh=SDqGnE1XBvMYMbTjranxWBzSLFivUM6hx0gGZrOFK0M=;
        b=f22C4bcgne8p8XdXgR4PXpqlMTLzp+ONiQfALujpU27NJ2CTWGR1XAzi/7LorJQqQh
         CvzZKt9yOm7eOrYClDpZ0CVGnmJ2jd0utwHkXfcfaCdda2E7NEUxFBAhr3NhAm3tIU1/
         or/XxpqJyAbWLklspA6eS81XBXTvOcyg4wB7/OaNnL7DIycAK9X0b8UctB8tv1XgleoO
         BwDPPrRM96eO6q2hqIU4bAMH9OygNsMRgwy2Nq2eWW1WM2QHg4arWnw1niquFC1DS1Jg
         885BeqD8D3ZbPYbjTa3EZlLIOnDLB/+RbgIiZiIBhcB5i3qqDCookYmuNgc1Om0s3KyY
         XHBw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20260707; t=1792145085; x=1792749885;
        h=references:to:cc:in-reply-to:date:subject:mime-version:content-type
         :message-id:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date
         :message-id:reply-to:content-type;
        bh=SDqGnE1XBvMYMbTjranxWBzSLFivUM6hx0gGZrOFK0M=;
        b=vEG14MIUI6Mjr8Uctem8UDhPWSCpfG6CGXK09DZBxu15zD4W7Gj2Hv9m2+CToBl+Cn
         CtCA+4mPxAxPLqwy2TlxXxQvGGwYc561KvjOAzLUCdwErFfswsIOb7nNLn8zfHHZ1WZS
         x/fULORTADxv5uNRtYdIA4gCr3IihhnBIXOoefbEQB0Vhs2xggsQET+ju/Zn7iGAUIjL
         olJdJQhVVFdE3Y0WBHq3ycjFEUTrPpuYW6ae/6k7XEHdHvvVzHPDvITNJYCKDwfPKppA
         JnKGSzNfQ516xkQtDHLBntjuxQh4I+p4rRUyX+3nNPpg+W0lOmMLSB5nG7t79dutI9Uw
         cW5A==
X-Gm-Message-State: AFq9FYJL655xU9+grgx9W99lZxYVKa0t0wuhtM9FyWymW0320DfrC2XB
	rLdyBpi2AshJz0qN1iFOQ6e75AD0wS4BUOkaxbI/jIHCzeXoIe6YZmHsFwPzNm0BdtEFj+b9Cju
	XtJ7zzZs=
X-Gm-Gg: AYBFou2e6/gGjiweV4OjTuiYP71F3VVNBHf07SkFDJJRzmDAMp+3KecsxT4fzldttUO
	ljMdsyKAgCCNakd2vuBptM6C5ILWTntq+vGx+1des2U9qSOMHgCFH+37RGk8ry+sdk2JKVZJF6d
	kEGFHvW+1pegrQVVU8O2U3V+zc/qApI37TmxSsTx0F+WtRD23GiGuKT+QH/jQ5Hq7Kd0fioiIc6
	tI1EuudbLgyICLUNS/+G+Z37nRcB8pk9UgKxcBQrc4wwG/n+0Izl2hs0iX+dNmZvw5tNKeztG6d
	rzMV2SITo2if3dhpMOECQ1wU9ps+OKuAHjDrw0uJRp8qP3FEjtKPEl8NKUNJ2SmjJNsig5Mil+2
	ce2zA72Z5N+To6Q7j3mwWAMOaptONQOTHdAgDnf3UGwFG3wMYncbNYLWHlzlxDOYIN4qN5AK0Wl
	fau+VFVy7QsV2ydmhoSbo4jaNAcl7/yOt9SvlpN92sMEEhf7twmsyBpf4DCvhPmyJCfll1Ii97j
	Y9kIbPMzzno2Ypr2X27xw8p
Precedence: list
In-Reply-To: <CAJ-Vmomx6p7y6e2CeXaniYuz=ar74q5q2Ao2Zkk2zris3HG_+w@mail.gmail.com>
X-Spamd-Bar: +
X-Spamd-Result: default: False [1.00 / 15.00];
	URI_COUNT_ODD(1.00)[9];
	MV_CASE(0.50)[];
	R_DKIM_ALLOW(-0.20)[cocito-eu.20251104.gappssmtp.com:s=20251104];
	R_SPF_ALLOW(-0.20)[+ip6:2a00:1450:4864::/56];
	MIME_GOOD(-0.10)[multipart/alternative,text/plain];
	RCVD_VIA_SMTP_AUTH(0.00)[];
	ARC_NA(0.00)[];
	MIME_TRACE(0.00)[0:+,1:+,2:~];
	ASN(0.00)[asn:15169, ipnet:2a00:1450::/32, country:US];
	RCVD_IN_DNSWL_NONE(0.00)[2a00:1450:4864:20::42e:from];
	TO_DN_SOME(0.00)[];
	FROM_HAS_DN(0.00)[];
	MID_RHS_MATCH_FROM(0.00)[];
	RCPT_COUNT_THREE(0.00)[3];
	RCVD_COUNT_TWO(0.00)[2];
	FROM_EQ_ENVFROM(0.00)[];
	DMARC_NA(0.00)[cocito.eu];
	TO_MATCH_ENVRCPT_SOME(0.00)[];
	RCVD_TLS_LAST(0.00)[];
	PREVIOUSLY_DELIVERED(0.00)[freebsd-hackers@freebsd.org];
	MLMMJ_DEST(0.00)[freebsd-hackers@freebsd.org];
	DKIM_TRACE(0.00)[cocito-eu.20251104.gappssmtp.com:+]
X-Rspamd-Queue-Id: 4j5gXb0d1vz4WFD
X-Newsgate-Id: f02c70b8849f+
X-No-Archive: Yes