9 ulong lasticachechange;
14 int p, nwrite, nflush, ndirty, tdirty, toflush;
20 * no locks because all the data accesses are atomic.
28 if(t-lasttime[0] < l0quantum){
29 /* level-0 disk access going on */
30 p = icachedirtyfrac();
31 if(p < IcacheFrac*5/10){ /* can wait */
32 icachesleeptime = SleepForever;
34 }else if(p > IcacheFrac*9/10){ /* can't wait */
37 }else if(t-lasticachechange > 60){
38 /* have minute worth of data for current rate */
39 prev = &stathist[(stattime-60+nstathist)%nstathist];
41 /* # entries written to index cache */
42 nwrite = stats.n[StatIcacheWrite] - prev->n[StatIcacheWrite];
44 /* # dirty entries in index cache */
45 ndirty = stats.n[StatIcacheDirty] - prev->n[StatIcacheDirty];
47 /* # entries flushed to disk */
48 nflush = nwrite - ndirty;
50 /* want to stay around 70% dirty */
51 tdirty = (vlong)stats.n[StatIcacheSize]*700/1000;
53 /* assume nflush*icachesleeptime is a constant */
54 cflush = (vlong)nflush*(icachesleeptime+1);
56 /* computer number entries to write in next minute */
57 toflush = nwrite + (stats.n[StatIcacheDirty] - tdirty);
59 /* schedule for that many */
60 if(toflush <= 0 || cflush/toflush > 100000)
61 icachesleeptime = SleepForever;
63 icachesleeptime = cflush/toflush;
65 arenasumsleeptime = SleepForever;
68 if(t-lasttime[1] < l1quantum){
69 /* level-1 disk access (icache flush) going on */
71 arenasumsleeptime = SleepForever;
74 /* no disk access going on - no holds barred*/
76 arenasumsleeptime = 0;
82 if(level < 0 || level >= nelem(lasttime)){
83 fprint(2, "bad level in diskaccess; caller=%#p\n",
87 lasttime[level] = time(0);