fs: inode and open-file tables that grow, with a hash for iget

The inode table was NINODE (200) entries, searched end to end on every
iget(), and a panic -- "iget: no inodes" -- when all of them were held.
Held means open, a cwd, a running binary or a directory mid-walk, so a
few busy processes reached it. iget() now finds an inode through a hash
on (dev, inum), takes a free one from a list, and makes more from a
slab cache once the NINODE in the image are all in use.

The open-file table had the same shape, NFILE (512) and then ENFILE,
and gets the same treatment: a free list, and the slab past NFILE.
/proc/fsstat's peaks now read against how many exist.

getrlimit(RLIMIT_NOFILE) said unlimited, which musl turns into
sysconf(_SC_OPEN_MAX) == -1, after which zsh believed it had no
descriptors and `exec {fd}<file` failed on the first one. It reports
NOFILE now. And a comment in sys_fs.c held a "*/" that ended it early.

Checked under QEMU: six processes holding 115 files each, 713 open
descriptions and 341 inodes at once, all back to the baseline after.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01S1giNvrHTrPMPw7V6x1kQ4
This commit is contained in:
Nexoniarz 2026-10-23 13:39:14 +02:00
commit 09e07423e8
6 changed files with 161 additions and 40 deletions

View file

@ -295,10 +295,10 @@ gen_fsstat(struct sbuf *sb)
// leak, and which line it is on says where to look.
sb_puts(sb, "\ninode_used "); sb_putu(sb, fsstat.inode_used);
sb_puts(sb, "\ninode_peak "); sb_putu(sb, fsstat.inode_peak);
sb_puts(sb, " / "); sb_putu(sb, NINODE);
sb_puts(sb, " / "); sb_putu(sb, inode_slots());
sb_puts(sb, "\nfile_used "); sb_putu(sb, fsstat.file_used);
sb_puts(sb, "\nfile_peak "); sb_putu(sb, fsstat.file_peak);
sb_puts(sb, " / "); sb_putu(sb, NFILE);
sb_puts(sb, " / "); sb_putu(sb, file_slots());
sb_puts(sb, "\nbuf_pinned "); sb_putu(sb, fsstat.buf_pinned);
{
uint nb, maxb;