From bbe78805681ec8303ab198288693586e8bfdb7f3 Mon Sep 17 00:00:00 2001 From: Chas Williams Date: Mon, 15 Aug 2005 16:39:51 +0000 Subject: [PATCH] large-cache-fix-20050815 FIXES 20821 make large caches actually work --- src/afs/SOLARIS/osi_vnodeops.c | 4 ++-- src/afs/VNOPS/afs_vnop_write.c | 12 ++++++------ src/afs/afs.h | 8 ++++++-- src/afs/afs_dcache.c | 22 ++++++++++------------ src/afsd/afsd.c | 2 +- 5 files changed, 25 insertions(+), 23 deletions(-) diff --git a/src/afs/SOLARIS/osi_vnodeops.c b/src/afs/SOLARIS/osi_vnodeops.c index 212b10f927..d4c0590876 100644 --- a/src/afs/SOLARIS/osi_vnodeops.c +++ b/src/afs/SOLARIS/osi_vnodeops.c @@ -762,9 +762,9 @@ afs_nfsrdwr(avc, auio, arw, ioflag, acred) */ afs_MaybeWakeupTruncateDaemon(); while ((arw == UIO_WRITE) - && (afs_blocksUsed > (CM_WAITFORDRAINPCT * afs_cacheBlocks) / 100)) { + && (afs_blocksUsed > PERCENT(CM_WAITFORDRAINPCT, afs_cacheBlocks))) { if (afs_blocksUsed - afs_blocksDiscarded > - (CM_WAITFORDRAINPCT * afs_cacheBlocks) / 100) { + PERCENT(CM_WAITFORDRAINPCT, afs_cacheBlocks)) { afs_WaitForCacheDrain = 1; afs_osi_Sleep(&afs_WaitForCacheDrain); } diff --git a/src/afs/VNOPS/afs_vnop_write.c b/src/afs/VNOPS/afs_vnop_write.c index 4a93e5572b..ed1ee645fe 100644 --- a/src/afs/VNOPS/afs_vnop_write.c +++ b/src/afs/VNOPS/afs_vnop_write.c @@ -197,7 +197,7 @@ afs_MemWrite(register struct vcache *avc, struct uio *auio, int aio, if (tdc) ObtainWriteLock(&tdc->lock, 653); } else if (afs_blocksUsed > - (CM_WAITFORDRAINPCT * afs_cacheBlocks) / 100) { + PERCENT(CM_WAITFORDRAINPCT, afs_cacheBlocks)) { tdc = afs_FindDCache(avc, filePos); if (tdc) { ObtainWriteLock(&tdc->lock, 654); @@ -211,10 +211,10 @@ afs_MemWrite(register struct vcache *avc, struct uio *auio, int aio, if (!tdc) { afs_MaybeWakeupTruncateDaemon(); while (afs_blocksUsed > - (CM_WAITFORDRAINPCT * afs_cacheBlocks) / 100) { + PERCENT(CM_WAITFORDRAINPCT, afs_cacheBlocks)) { ReleaseWriteLock(&avc->lock); if (afs_blocksUsed - afs_blocksDiscarded > - (CM_WAITFORDRAINPCT * afs_cacheBlocks) / 100) { + PERCENT(CM_WAITFORDRAINPCT, afs_cacheBlocks)) { afs_WaitForCacheDrain = 1; afs_osi_Sleep(&afs_WaitForCacheDrain); } @@ -441,7 +441,7 @@ afs_UFSWrite(register struct vcache *avc, struct uio *auio, int aio, if (tdc) ObtainWriteLock(&tdc->lock, 657); } else if (afs_blocksUsed > - (CM_WAITFORDRAINPCT * afs_cacheBlocks) / 100) { + PERCENT(CM_WAITFORDRAINPCT, afs_cacheBlocks)) { tdc = afs_FindDCache(avc, filePos); if (tdc) { ObtainWriteLock(&tdc->lock, 658); @@ -455,10 +455,10 @@ afs_UFSWrite(register struct vcache *avc, struct uio *auio, int aio, if (!tdc) { afs_MaybeWakeupTruncateDaemon(); while (afs_blocksUsed > - (CM_WAITFORDRAINPCT * afs_cacheBlocks) / 100) { + PERCENT(CM_WAITFORDRAINPCT, afs_cacheBlocks)) { ReleaseWriteLock(&avc->lock); if (afs_blocksUsed - afs_blocksDiscarded > - (CM_WAITFORDRAINPCT * afs_cacheBlocks) / 100) { + PERCENT(CM_WAITFORDRAINPCT, afs_cacheBlocks)) { afs_WaitForCacheDrain = 1; afs_osi_Sleep(&afs_WaitForCacheDrain); } diff --git a/src/afs/afs.h b/src/afs/afs.h index 9fd1814c40..85e0186c82 100644 --- a/src/afs/afs.h +++ b/src/afs/afs.h @@ -1116,11 +1116,15 @@ extern struct brequest afs_brs[NBRS]; /* request structures */ #define CM_CACHESIZEDRAINEDPCT 95 /* wakeup processes when down to here. */ #define CM_WAITFORDRAINPCT 98 /* sleep if cache is this full. */ +/* when afs_cacheBlocks is large, settle for slightly decreased precision */ +#define PERCENT(p, v) \ + ((afs_cacheBlocks & 0xffe00000) ? ((v) / 100 * (p)) : ((p) * (v) / 100)) + #define afs_CacheIsTooFull() \ (afs_blocksUsed - afs_blocksDiscarded > \ - (CM_DCACHECOUNTFREEPCT*afs_cacheBlocks)/100 || \ + PERCENT(CM_DCACHECOUNTFREEPCT, afs_cacheBlocks) || \ afs_freeDCCount - afs_discardDCCount < \ - ((100-CM_DCACHECOUNTFREEPCT)*afs_cacheFiles)/100) + PERCENT(100 - CM_DCACHECOUNTFREEPCT, afs_cacheFiles)) /* Handy max length of a numeric string. */ #define CVBS 12 /* max afs_int32 is 2^32 ~ 4*10^9, +1 for NULL, +luck */ diff --git a/src/afs/afs_dcache.c b/src/afs/afs_dcache.c index cf4cef70a4..cd253e929c 100644 --- a/src/afs/afs_dcache.c +++ b/src/afs/afs_dcache.c @@ -227,8 +227,8 @@ afs_DCWhichBucket(afs_int32 phase, afs_int32 bucket) if (!splitdcache) return 0; - afs_pct1 = afs_blocksUsed_1*100/afs_cacheBlocks; - afs_pct2 = afs_blocksUsed_2*100/afs_cacheBlocks; + afs_pct1 = afs_blocksUsed_1 / (afs_cacheBlocks / 100); + afs_pct2 = afs_blocksUsed_2 / (afs_cacheBlocks / 100); /* Short cut: if we don't know about it, try to kill it */ if (phase < 2 && afs_blocksUsed_0) @@ -346,16 +346,14 @@ afs_CacheTruncateDaemon(void) u_int counter; u_int cb_lowat; u_int dc_hiwat = - (100 - CM_DCACHECOUNTFREEPCT + - CM_DCACHEEXTRAPCT) * afs_cacheFiles / 100; + PERCENT((100 - CM_DCACHECOUNTFREEPCT + CM_DCACHEEXTRAPCT), afs_cacheFiles); afs_min_cache = (((10 * AFS_CHUNKSIZE(0)) + afs_fsfragsize) & ~afs_fsfragsize) >> 10; osi_GetuTime(&CTD_stats.CTD_afterSleep); afs_TruncateDaemonRunning = 1; while (1) { - cb_lowat = ((CM_DCACHESPACEFREEPCT - CM_DCACHEEXTRAPCT) - * afs_cacheBlocks) / 100; + cb_lowat = PERCENT((CM_DCACHESPACEFREEPCT - CM_DCACHEEXTRAPCT), afs_cacheBlocks); MObtainWriteLock(&afs_xdcache, 266); if (afs_CacheTooFull) { int space_needed, slots_needed; @@ -916,7 +914,7 @@ afs_FlushDCache(register struct dcache *adc) if (afs_WaitForCacheDrain) { if (afs_blocksUsed <= - (CM_CACHESIZEDRAINEDPCT * afs_cacheBlocks) / 100) { + PERCENT(CM_CACHESIZEDRAINEDPCT, afs_cacheBlocks)) { afs_WaitForCacheDrain = 0; afs_osi_Wakeup(&afs_WaitForCacheDrain); } @@ -949,7 +947,7 @@ afs_FreeDCache(register struct dcache *adc) if (afs_WaitForCacheDrain) { if ((afs_blocksUsed - afs_blocksDiscarded) <= - (CM_CACHESIZEDRAINEDPCT * afs_cacheBlocks) / 100) { + PERCENT(CM_CACHESIZEDRAINEDPCT, afs_cacheBlocks)) { afs_WaitForCacheDrain = 0; afs_osi_Wakeup(&afs_WaitForCacheDrain); } @@ -999,7 +997,7 @@ afs_DiscardDCache(register struct dcache *adc) if (afs_WaitForCacheDrain) { if ((afs_blocksUsed - afs_blocksDiscarded) <= - (CM_CACHESIZEDRAINEDPCT * afs_cacheBlocks) / 100) { + PERCENT(CM_CACHESIZEDRAINEDPCT, afs_cacheBlocks)) { afs_WaitForCacheDrain = 0; afs_osi_Wakeup(&afs_WaitForCacheDrain); } @@ -1084,7 +1082,7 @@ afs_MaybeFreeDiscardedDCache(void) while (afs_blocksDiscarded && (afs_blocksUsed > - (CM_WAITFORDRAINPCT * afs_cacheBlocks) / 100)) { + PERCENT(CM_WAITFORDRAINPCT, afs_cacheBlocks))) { afs_FreeDiscardedDCache(); } return 0; @@ -2118,7 +2116,7 @@ afs_GetDCache(register struct vcache *avc, afs_size_t abyte, /* Sleep here when cache needs to be drained. */ if (setLocks && !slowPass && (afs_blocksUsed > - (CM_WAITFORDRAINPCT * afs_cacheBlocks) / 100)) { + PERCENT(CM_WAITFORDRAINPCT, afs_cacheBlocks))) { /* Make sure truncate daemon is running */ afs_MaybeWakeupTruncateDaemon(); ObtainWriteLock(&tdc->tlock, 614); @@ -2127,7 +2125,7 @@ afs_GetDCache(register struct vcache *avc, afs_size_t abyte, ReleaseWriteLock(&tdc->lock); ReleaseReadLock(&avc->lock); while ((afs_blocksUsed - afs_blocksDiscarded) > - (CM_WAITFORDRAINPCT * afs_cacheBlocks) / 100) { + PERCENT(CM_WAITFORDRAINPCT, afs_cacheBlocks)) { afs_WaitForCacheDrain = 1; afs_osi_Sleep(&afs_WaitForCacheDrain); } diff --git a/src/afsd/afsd.c b/src/afsd/afsd.c index 94b6cdf67c..88c18656f4 100644 --- a/src/afsd/afsd.c +++ b/src/afsd/afsd.c @@ -461,7 +461,7 @@ int PartSizeOverflow(char *path, int cs) totalblks /= (1024 / bsize); } - mint = totalblks - ((totalblks * 5) / 100); + mint = totalblks / 100 * 95; if (cs > mint) { printf ("Cache size (%d) must be less than 95%% of partition size (which is %d). Lower cache size\n",