Post #3362366
2026-06-20 20:02 UTC
Okay, I hit a crazy #OpenBSD (or possibly Perl) peculiarity today. For background context, OpenBSD's pkg_* tools are all written in Perl.
Testing stuff in a discussion with @rl_dane@polymaths.social, I had cause to throw ktrace on the pkg_info command like
$ ktrace -f pkg_info.ktrace pkg_info -Q remind
All said, fairly boring. But when I was browsing through the dump
$ kdump -R -f pkg_info.ktrace | less
I found that it did a stat(2) call on every single file in my current working directory:
$ kdump -f pkg_info.ktrace -R | awk '/NAMI *"\./{++c; print}END{print "Total count:", c}'
This means that pkg_info runs noticeably faster in an empty directory than if run in a directory containing tens of thousands of files, especially if the machine uses a spinning-rust HDD rather than flash storage.
I haven't read the pkg_info source code deeply since I don't natively do perl, so I'm uncertain whether pkg_info is intentionally stat'ing every file, or whether perl just does this as part of its startup, but it seemed like a really weird behavior..
Replies (2)
-
@gumnos@mastodon.bsd.cafe 2026-06-20 20:22
As a POC: $ mkdir -p ~/tmp/poc/{empty,full} $ cd ~/tmp/poc/full $ jot 10000 | xargs touch $ ktrace -f ../full.ktrace pkg_info -Q remind $ cd ../empty $ ktrace -f ../empty.ktrace pkg_info -Q remind $ cd .. then $ for f in full.ktrace empty.ktrace ; do echo -n $f ; kdump -f $f": " | grep -c 'NAMI *"\.' ; done
-
@pertho@mastodon.bsd.cafe 2026-06-20 21:23
@gumnos@mastodon.bsd.cafe @rl_dane@polymaths.social What happens if you run it in a NFS directory with thousands of files? ๐๐