From: Simon Wilkinson Date: Mon, 26 Oct 2009 19:52:48 +0000 (+0000) Subject: Use fewer #ifdefs for dynamic vcaches X-Git-Tag: openafs-devel-1_5_67~100 X-Git-Url: https://git.openafs.org/?p=openafs.git;a=commitdiff_plain;h=bea4c4ea5d563bebe9f9c6289a1f25fd016a01a4 Use fewer #ifdefs for dynamic vcaches When we're not in AFS_MAXVCOUNT_ENV, make afsd_dynamic_vcaches a static 0, which allows the removal of a scattering of #ifdef's in the middle of conditionals in afs_vcache.c, and generally improves the code browsing experience. Also, move the externs for this variable to afs.h, where they belong, and fix related formatting. Change-Id: I4d56ebae63fe1855ac80f8511b9fc76f7e5a326f Reviewed-on: http://gerrit.openafs.org/741 Tested-by: Derrick Brashear Reviewed-by: Derrick Brashear --- diff --git a/src/afs/afs.h b/src/afs/afs.h index 69021d7..8e86273 100644 --- a/src/afs/afs.h +++ b/src/afs/afs.h @@ -1410,4 +1410,11 @@ struct afs_fakestat_state { }; extern int afs_fakestat_enable; + +#ifdef AFS_MAXVCOUNT_ENV +extern int afsd_dynamic_vcaches; +#else +#define afsd_dynamic_vcaches 0 +#endif + #endif /* _AFS_H_ */ diff --git a/src/afs/afs_daemons.c b/src/afs/afs_daemons.c index ff2fd17..21cf931 100644 --- a/src/afs/afs_daemons.c +++ b/src/afs/afs_daemons.c @@ -40,8 +40,6 @@ static int rxepoch_checked = 0; #define afs_CheckRXEpoch() {if (rxepoch_checked == 0 && rxkad_EpochWasSet) { \ rxepoch_checked = 1; afs_GCUserData(/* force flag */ 1); } } -extern int afsd_dynamic_vcaches; - /* PAG garbage collection */ /* We induce a compile error if param.h does not define AFS_GCPAGS */ afs_int32 afs_gcpags = AFS_GCPAGS; @@ -212,19 +210,19 @@ afs_Daemon(void) * tickets */ last3MinCheck = now; } -#ifdef AFS_MAXVCOUNT_ENV - if (afsd_dynamic_vcaches && (last5MinCheck + 300 < now)) { - /* start with trying to drop us back to our base usage */ - int anumber; - if (afs_maxvcount <= afs_cacheStats) - anumber = VCACHE_FREE; - else - anumber = VCACHE_FREE + (afs_maxvcount - afs_cacheStats); - - afs_ShakeLooseVCaches(anumber); - last5MinCheck = now; - } -#endif + + if (afsd_dynamic_vcaches && (last5MinCheck + 300 < now)) { + /* start with trying to drop us back to our base usage */ + int anumber; + if (afs_maxvcount <= afs_cacheStats) + anumber = VCACHE_FREE; + else + anumber = VCACHE_FREE + (afs_maxvcount - afs_cacheStats); + + afs_ShakeLooseVCaches(anumber); + last5MinCheck = now; + } + if (!afs_CheckServerDaemonStarted) { /* Do the check here if the correct afsd is not installed. */ if (!cs_warned) { diff --git a/src/afs/afs_init.c b/src/afs/afs_init.c index abe5e96..0036107 100644 --- a/src/afs/afs_init.c +++ b/src/afs/afs_init.c @@ -53,7 +53,9 @@ extern afs_rwlock_t afs_disconDirtyLock; #endif /* This is the kernel side of the dynamic vcache setting */ +#ifdef AFS_MAXVCOUNT_ENV int afsd_dynamic_vcaches = 0; /* Enable dynamic-vcache support */ +#endif /* * Initialization order is important. Must first call afs_CacheInit, @@ -109,10 +111,9 @@ afs_CacheInit(afs_int32 astatSize, afs_int32 afiles, afs_int32 ablocks, #endif /* SYS_NAME_ID */ #ifdef AFS_MAXVCOUNT_ENV - afsd_dynamic_vcaches = dynamic_vcaches; - printf("%s dynamically allocated vcaches\n", ( afsd_dynamic_vcaches ? "enabling" : "disabling" )); -#else - afsd_dynamic_vcaches = 0; + afsd_dynamic_vcaches = dynamic_vcaches; + printf("%s dynamically allocated vcaches\n", + ( afsd_dynamic_vcaches ? "enabling" : "disabling" )); #endif printf("Starting AFS cache scan..."); diff --git a/src/afs/afs_vcache.c b/src/afs/afs_vcache.c index 6457918..da6972b 100644 --- a/src/afs/afs_vcache.c +++ b/src/afs/afs_vcache.c @@ -80,7 +80,6 @@ struct afs_q afs_vhashTV[VCSIZE]; static struct afs_cbr *afs_cbrHashT[CBRSIZE]; afs_int32 afs_bulkStatsLost; int afs_norefpanic = 0; -extern int afsd_dynamic_vcaches; /* Disk backed vcache definitions @@ -643,23 +642,14 @@ afs_ShakeLooseVCaches(afs_int32 anumber) AFS_GLOCK(); } - if ( -#ifdef AFS_MAXVCOUNT_ENV - afsd_dynamic_vcaches || /* Always run if dynamic vcaches are enabled. */ -#endif - afs_vcount >= afs_maxvcount - ) { + if (afsd_dynamic_vcaches || afs_vcount >= afs_maxvcount) { i = 0; for (tq = VLRU.prev; tq != &VLRU && anumber > 0; tq = uq) { tvc = QTOV(tq); uq = QPrev(tq); if (tvc->f.states & CVFlushed) { refpanic("CVFlushed on VLRU"); - } else if ( -#ifdef AFS_MAXVCOUNT_ENV - ! afsd_dynamic_vcaches && -#endif - i++ > afs_maxvcount) { + } else if (!afsd_dynamic_vcaches && i++ > afs_maxvcount) { refpanic("Exceeded pool of AFS vnodes(VLRU cycle?)"); } else if (QNext(uq) != tq) { refpanic("VLRU inconsistent"); @@ -725,11 +715,7 @@ restart: if (tq == uq) break; } - if ( -#ifdef AFS_MAXVCOUNT_ENV - !afsd_dynamic_vcaches && -#endif - anumber == target) { + if (!afsd_dynamic_vcaches && anumber == target) { printf("afs_ShakeLooseVCaches: warning none freed, using %d of %d\n", afs_vcount, afs_maxvcount); } @@ -778,13 +764,13 @@ afs_AllocVCache(void) #endif afs_vcount++; -#ifdef AFS_MAXVCOUNT_ENV + /* track the peak */ if (afsd_dynamic_vcaches && afs_maxvcount < afs_vcount) { afs_maxvcount = afs_vcount; /*printf("peak vnodes: %d\n", afs_maxvcount);*/ } -#endif + afs_stats_cmperf.vcacheXAllocs++; /* count in case we have a leak */ #else /* none free, making one is better than a panic */ @@ -866,17 +852,13 @@ afs_NewVCache(struct VenusFid *afid, struct server *serverp) afs_FlushReclaimedVcaches(); #if defined(AFS_OSF_ENV) || defined(AFS_LINUX22_ENV) -#ifdef AFS_MAXVCOUNT_ENV if(!afsd_dynamic_vcaches) { -#endif afs_ShakeLooseVCaches(anumber); if (afs_vcount >= afs_maxvcount) { printf("afs_NewVCache - none freed\n"); return NULL; } -#ifdef AFS_MAXVCOUNT_ENV } -#endif tvc = afs_AllocVCache(); #else /* AFS_OSF_ENV */ /* pull out a free cache entry */