Article View: muc.lists.freebsd.fs
Article #10Re: Terminal number of files in a ZFS directory.
From: Andrea Cocito
Date: Mon, 19 Oct 2026 17:20
Date: Mon, 19 Oct 2026 17:20
141 lines
12693 bytes
12693 bytes
--Apple-Mail-D0EAEF74-9365-4C2E-A783-81E19A4B6647
Content-Type: text/html;
charset=utf-8
Content-Transfer-Encoding: quoted-printable
<html class=3D"apple-mail-supports-explicit-dark-mode"><head><meta http-equi=
v=3D"content-type" content=3D"text/html; charset=3Dutf-8"></head><body dir=3D=
"auto"><br id=3D"lineBreakAtBeginningOfSignature"><div dir=3D"ltr">Sent from=
my iPhone</div><div dir=3D"ltr"><br><blockquote type=3D"cite">On 19 Oct 202=
6, at 14:52, Frank Leonhardt <freebsd-doc@fjl.co.uk> wrote:<br><br></b=
lockquote></div><blockquote type=3D"cite"><div dir=3D"ltr">=EF=BB=BF
=20
<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3DUTF-8"=
>
=20
=20
<div class=3D"moz-cite-prefix">On 19/10/2026 00:57, Zaphod Beeblebrox
wrote:<br>
</div>
<blockquote type=3D"cite" cite=3D"mid:CACpH0Md47U9Gd=3DjAr=3D02SGvZSb1j0=
EuC2BSKOL2cZXpMpJbq7A@mail.gmail.com">
<meta http-equiv=3D"content-type" content=3D"text/html; charset=3DUTF-=
8">
<div dir=3D"ltr">
<div>The TLDR is "I don't know, but I have such a directory".</=
div>
<div><br>
</div>
<div>The directory developed on a jail. It was the maild=
rop
directory for a postfix no longer running as the server had
become a jail and no longer needed it's own mail service. Th=
e
maildrop, however, continued to receive cron generated
periodic mail for years. So that's 2 per day plus another on=
e
per week, IIRC. That would be about 5980 email per year.&nbs=
p;
Now... give it 15 years ... 89700? That doesn't seem like
enough. There must have been more crap.</div>
<div><br>
</div>
<div>On the jail server, the zfs filesystem only occupies about
10G. echo * on the directory runs at 100% cpu for over a
week. So I reboot (to stop it... it's stuck in kernel) and
zfs send it to a NVME only system (my desktop) and try again. =
;
I was thinking that much faster disk could compensate for
abominably bad big-O behavior. But this two ran for a week
without finishing.</div>
<div><br>
</div>
<div>What are the limits we're running into here. This is
academic. I can solve the problem (already have). I st=
ill
don't know what the limit is. Somewhere around September
15th, this directory started sticking finds and whatnot --- so
it tipped over from working to broken. I have the filesystem=
,
BTW... </div>
<div><br>
</div>
<div>What is this limit that toggles zfs from working large
directory to completely broken sysadmin problem?</div>
<div><br>
</div>
</div>
</blockquote>
<p>As Daniel Kalchev <a class=3D"moz-txt-link-rfc2396E" href=3D"mailto:d=
aniel@digsys.bg"><daniel@digsys.bg></a> has said, you can have
a stupid number of files in a directory and it still works, so I
decided to have a look-see in the OpenZFS source. I suspected that
the limit might be kernel rather than ZFS related, and this
appears to be true.</p>
<p>Firstly, a directory might contain subdriectories so you're going
to hit a problem with the link count wrapping (.. - parent
directory). On Linux this is defined in include/os/linux/zfs/sys/=
zfs_vfsops_os.h
- ZFS_LINK_MAX =3D 2^31 =E2=88=92 1. According to the comments
inode->i_nlink is an unsigned int. I'll leave that one to the
penguinistas.</p>
<p>On FreeBSD ZFS_LINK_MAX (defined in zfs_znode_impl.h) is set to
UINT64_MAX. So Linux will fail at mere 4 Billion directories but
on FreeBSD that's barely getting started.</p>
<p>So what about files?</p>
<p>Well there's going to be st_size (from struct stat) to worry
about, which maps on to z_size in ZFS's in-memory znode (i.e.
znode_t). That's also uint64_t. For a regular file this holds the
file size but *I THINK* for a directory it holds the entry count
instead. Either way, it does set a limit on the number of files
one way or another, 2^64 is a very big number.<br>
<br>
Incidentally, you can get this number using stat rather than ls
(or echo) - try "stat -f %z bigdir" which is the standard way of
getting the number of files in a directory without counting them
in a shell script, but subtract two for . and .. (I think it's
stat -c %s bigdir on Linux but don't quote me).<br>
<br>
</p>
<p>But... I think the real limit might be ZAP objects, the ZFS
hashed key-value store. A directory ZAP object internally. What is
the limit there? Not so neat as an integer to overflow, and I'm
now out of my depth but what it looks like...</p>
<p>The main hash table has 28 bit hash values, but the system will
stop growing it at 28-2 =3D 26 bit entries (i.e. 2^26). These point
to leaf buckets of 16K, which can hold, I don't know, 200 entries
on average? Say 10 billion files.</p>
<p>Because it's all hashed, unlike UFS2, getting a file out of an
enormous directory is cheap - especially if the matadata is in the
ARC. If you do max-out the ARC capacity it's gonna slow down, but
what do you expect?</p>
<p>I can see lots of problems with large directories slowing down
(no kidding) but they're not ZFS specific. For example, readdir
will return files in random order that have to be sorted in
userland. Any change to a directory locks the whole directory
(that's a VFS thing in the kernel) so add that to the write
amplification from dirtying leaf nodes in the ZAP as it rebalances
- I don't *know* but it all smells like trouble and when the ARC
is exhausted then performance will go off a cliff. The same as if
a zpool is >80% full. My guess is this is what you were seeing
- performance off a cliff-edge rather than a hard limit.</p>
<p>Regards, Frank.</p>
<p><br>
</p>
=20
</div></blockquote><br><div>Hi,</div><div><br></div><div>IMHO =E2=80=9Cecho *=
=E2=80=9D is more a shell expansion or argv[] building issue than a filesyst=
em one. </div><div><br></div><div>I would give a try to =E2=80=9Cfind d=
ir |wc -l=E2=80=9D. </div><div><br></div><div>To cleanup I bet find -rm=
would work. </div><div><br></div><div>Cheers,</div><div><br></div><div=
>A. </div></body></html>=
--Apple-Mail-D0EAEF74-9365-4C2E-A783-81E19A4B6647--
--
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:
<409A7867-45C6-4B7F-ADB8-D030B16D3E2E@gmail.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!uucp.gnuu.de!news.karotte.org!news.space.net!news.muc.de!.POSTED.news.muc.de!not-for-mailReferences:
<7a01fc64-8343-418d-9914-aa639ac9aa43@fjl.co.uk>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!uucp.gnuu.de!news.karotte.org!news.space.net!news.muc.de!.POSTED.news.muc.de!not-for-mail
From: Andrea Cocito <blackye@gmail.com>
Newsgroups: muc.lists.freebsd.fs
Subject: Re: Terminal number of files in a ZFS directory.
Date: Mon, 19 Oct 2026 19:20:44 +0200
Organization: Newsgate at muc.de e.V.
Sender: owner-freebsd-fs@FreeBSD.org
Approved: news-admin@muc.de
Distribution: world
Message-ID: <409A7867-45C6-4B7F-ADB8-D030B16D3E2E@gmail.com>
References: <7a01fc64-8343-418d-9914-aa639ac9aa43@fjl.co.uk>
MIME-Version: 1.0 (1.0)
Content-Type: multipart/alternative; boundary=Apple-Mail-D0EAEF74-9365-4C2E-A783-81E19A4B6647
Content-Transfer-Encoding: 7bit
Injection-Info: news.muc.de; posting-host="news.muc.de:193.149.48.2";
logging-data="23917"; mail-complaints-to="news-admin@muc.de"
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim;
t=1792430473; 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:
content-transfer-encoding:content-transfer-encoding:
in-reply-to:in-reply-to:references:references:list-id:list-help:
list-owner:list-unsubscribe:list-subscribe:list-post;
bh=6YiUFle9eW0XTwWSVbw5xDsmYI1ctDZH4zSYRV6dsMc=;
b=VJ8ZTwAeO+Otr4WfGq1R3jObHQOtbKQdPeNorHCxkLJP0gudIr2/itcL9dVH2Tr8V1/8Cc
U46hsjIoyjRCF/fBceQ1f88222gM4w1gUlQVFzEUGmF04YtC+e56QoRz6BHiSmNwkoFkHf
/r0t2eY4mXD8xsPS0FnQNaE3T21NAOdJwBGb5GgBOSoXCg7iqeHCFRhGS4Za11WW517C/R
Aoy+rdxkQTe3ZaRYuNdQ8i37IYSy5KLuHKaYZSmlSUF20Pw8JkylMr4I9GlN4uT7BCQfZE
sKZ2GVd4g9qZBItnk+LN0R7M6oAtpf1QQznNKNXjFe39hlFBLwhOr+mJ8LBfVQ==
X-Original-To: freebsd-fs@mlmmj.nyi.freebsd.org
Authentication-Results: mx1.freebsd.org;
dkim=pass header.d=gmail.com header.s=20251104 header.b=LVhGQ2HI;
spf=pass (mx1.freebsd.org: domain of blackye@gmail.com designates 2a00:1450:4864:20::42b as permitted sender) smtp.mailfrom=blackye@gmail.com;
dmarc=pass (policy=none) header.from=gmail.com
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20251104; t=1792430456; x=1793035256; darn=freebsd.org;
h=to:in-reply-to:cc:references:message-id:date:subject:mime-version
:from:content-transfer-encoding:content-type:from:to:cc:subject:date
:message-id:reply-to:content-type;
bh=6YiUFle9eW0XTwWSVbw5xDsmYI1ctDZH4zSYRV6dsMc=;
b=LVhGQ2HI3MwkN8+eQ+tNDkCrKCWq3SCjdvzUi+6codOAhrJvu3fZ2LQw6xnWpwCEb/
/5Npv0FOzkG33jzILJtUUqF8kcYWoxqCDkWjW5z78zMnvJJOuTul0WiWCd2dIHXH/1gZ
Xpn3Ikj2Kf9zInYh4ukvZwOjoA03lR3uqw6anXeQL77yMxe3uA6ZhCmnqtx99j8itmLs
+haMPVGDy034DzkrfWxEu6JKSMuLLu6mFwDI7CnWFgKFz8KkEsZAbzWzHu3iJOG8eEUg
72fdBHz3RgikWUZP7rr2bs+MUbp6GWhxC5KTZJSmk8BMLKI8QD8zJdoUTkcmFDMMz/nh
KGUg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1792430456; x=1793035256;
h=to:in-reply-to:cc:references:message-id:date:subject:mime-version
:from:content-transfer-encoding:content-type:x-gm-gg
:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to
:content-type;
bh=6YiUFle9eW0XTwWSVbw5xDsmYI1ctDZH4zSYRV6dsMc=;
b=gyUEMmgHKPV8ZQ8NhjV9aieZ499kBUDNi13jgDfrywNL+BBXeERGM1ZmpovxOp8TkL
BGbqays0iWo4xxiqVhztbpgsdoVB0H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POLICY_ALLOW(-0.50)[gmail.com,none];
R_SPF_ALLOW(-0.20)[+ip6:2a00:1450:4864::/56];
R_DKIM_ALLOW(-0.20)[gmail.com:s=20251104];
MIME_HTML_ONLY(0.20)[];
MIME_GOOD(-0.10)[multipart/alternative];
FROM_HAS_DN(0.00)[];
RCVD_TLS_LAST(0.00)[];
RCPT_COUNT_TWO(0.00)[2];
ARC_NA(0.00)[];
TO_DN_SOME(0.00)[];
MIME_TRACE(0.00)[0:+,1:~];
DWL_DNSWL_NONE(0.00)[gmail.com:dkim];
FREEMAIL_FROM(0.00)[gmail.com];
DKIM_TRACE(0.00)[gmail.com:+];
APPLE_IOS_MAILER_COMMON(0.00)[];
ASN(0.00)[asn:15169, ipnet:2a00:1450::/32, country:US];
TO_MATCH_ENVRCPT_SOME(0.00)[];
RCVD_COUNT_TWO(0.00)[2];
FROM_EQ_ENVFROM(0.00)[];
FREEMAIL_ENVFROM(0.00)[gmail.com];
PREVIOUSLY_DELIVERED(0.00)[freebsd-fs@freebsd.org];
MID_RHS_MATCH_FROM(0.00)[];
MLMMJ_DEST(0.00)[freebsd-fs@freebsd.org];
RCVD_VIA_SMTP_AUTH(0.00)[];
RCVD_IN_DNSWL_NONE(0.00)[2a00:1450:4864:20::42b:from]
X-Rspamd-Queue-Id: 4j7j4W5Zk1z4cmG
X-Newsgate-Id: f02c70b8849f+
X-No-Archive: Yes