large-cache-fix-20050815

FIXES 20821

make large caches actually work
This commit is contained in:
Chas Williams 2005-08-15 16:39:51 +00:00 committed by Derrick Brashear
parent 45d144da14
commit bbe7880568
5 changed files with 25 additions and 23 deletions

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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 */

View File

@ -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);
}

View File

@ -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",