fs: timestamps come from the clock, and /proc/fsstat says how full the tables are
Everything created after boot was stamped 1970. know() in SchFS and now_sec() in the v1 filesystem both returned uptime(), under comments saying the kernel had no wall clock -- which stopped being true when time_init() started reading the RTC. The comments outlived the condition they described. Two errors, and the second is the less obvious: uptime() counts 10 ms *ticks* and they were being used as *seconds*, so a node created 0.6 s into boot read back as 00:01:00 and the clocks ran a hundred times too fast. Both now go through wallclock(), which exists precisely so nothing can disagree with gettimeofday about the time. Confirmed against the RTC line from the same boot. The occupancy counters are the instrumentation docs/plan/roadmap.md asked for while hunting the ls -lR hang: inode, file and pinned-buffer counts with a high-water mark each, maintained at the 0->1 and 1->0 transitions rather than by scanning, so they cost one increment on a path that already holds the table's lock. The peaks are the diagnostic. A live count only describes the moment you looked, and a reference leak is invisible in it right up until the table is full -- at which point iget() panics and filealloc() returns 0, which is where the trail used to go cold. What they measured: across ten iterations of ls -lR with writes interleaved, 33 execs and 13378 tree descents, inode_peak stayed at 9/200, file_peak at 9/512 and buf_pinned_peak at 1/256, with the SchFS bracket unlocked throughout. That eliminates the roadmap's own hypothesis -- "a lock or reference-count leak somewhere in the *at() paths" -- and the hang did not reproduce. It is very likely fixed in passing by the *at() dirfd rewrite, the getdents cookie rewrite or SchFS becoming the root, all of which landed after it was reported. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VQ7Qx8E1q1M1bbCq8QLHS2
This commit is contained in:
parent
73acc40dbb
commit
fc0a7c6f4e
5 changed files with 78 additions and 6 deletions
|
|
@ -41,6 +41,7 @@
|
|||
#include "sleeplock.h"
|
||||
#include "fs.h"
|
||||
#include "buf.h"
|
||||
#include "fsstat.h"
|
||||
#include "file.h"
|
||||
|
||||
extern uint uptime(void);
|
||||
|
|
@ -356,12 +357,20 @@ ifree(int dev, int inum)
|
|||
// Timestamp helper
|
||||
// ===========================================================================
|
||||
|
||||
// Returns the current time in seconds. uptime() is assumed to return ticks;
|
||||
// replace with a real wall-clock source if your kernel has one.
|
||||
// Returns the current time in seconds since the epoch.
|
||||
//
|
||||
// It used to return uptime() under a comment saying to replace it with a real
|
||||
// wall-clock source "if your kernel has one". It has one -- see wallclock() in
|
||||
// kernel/core/time.c -- and the same fix went into SchFS's know(), where the
|
||||
// symptom was visible: every file created after boot was stamped 1970, and the
|
||||
// timestamps advanced a hundred times too fast because uptime() counts 10 ms
|
||||
// ticks and they were being read as seconds.
|
||||
static uint
|
||||
now_sec(void)
|
||||
{
|
||||
return (uint)uptime();
|
||||
uint64 sec;
|
||||
wallclock(&sec, 0);
|
||||
return (uint)sec;
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
|
@ -450,6 +459,7 @@ iget(uint dev, uint64 inum)
|
|||
ip->dev = dev;
|
||||
ip->inum = inum;
|
||||
ip->ref = 1;
|
||||
FSSTAT_TAKE(fsstat.inode_used, fsstat.inode_peak); // 0 -> 1
|
||||
ip->valid = 0;
|
||||
ip->ops = ops_for(dev);
|
||||
release(&itable.lock);
|
||||
|
|
@ -534,7 +544,8 @@ iput(struct inode *ip)
|
|||
acquire(&itable.lock);
|
||||
}
|
||||
|
||||
ip->ref--;
|
||||
if (--ip->ref == 0)
|
||||
FSSTAT_DROP(fsstat.inode_used);
|
||||
release(&itable.lock);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue