From: wessels <> Date: Fri, 8 May 1998 02:49:18 +0000 (+0000) Subject: store_client.c X-Git-Tag: SQUID_3_0_PRE1~3369 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a2899918dbfa95a305d0ff7f69b790305c85d7a0;p=thirdparty%2Fsquid.git store_client.c --- diff --git a/src/store_client.cc b/src/store_client.cc index 635553a04b..6dc87067b3 100644 --- a/src/store_client.cc +++ b/src/store_client.cc @@ -73,6 +73,8 @@ storeClientCopyEvent(void *data) if (!valid) return; sc->flags.copy_event_pending = 0; + if (!sc->callback) + return; storeClientCopy2(sc->entry, sc); } diff --git a/src/store_dir.cc b/src/store_dir.cc index 94d76a46b2..333bfd5db6 100644 --- a/src/store_dir.cc +++ b/src/store_dir.cc @@ -1,6 +1,6 @@ /* - * $Id: store_dir.cc,v 1.64 1998/04/16 17:47:15 wessels Exp $ + * $Id: store_dir.cc,v 1.65 1998/05/07 20:49:19 wessels Exp $ * * DEBUG: section 47 Store Directory Routines * AUTHOR: Duane Wessels @@ -37,7 +37,7 @@ #define DefaultLevelTwoDirs 256 static char *storeSwapSubDir(int dirn, int subdirn); -static int storeMostFreeSwapDir(void); +static int storeDirSelectSwapDir(void); static int storeVerifyDirectory(const char *path); static void storeCreateDirectory(const char *path, int lvl); static void storeCreateSwapSubDirs(int j); @@ -209,6 +209,7 @@ storeCreateSwapSubDirs(int j) } } +#if OLD_CODE static int storeMostFreeSwapDir(void) { @@ -229,6 +230,93 @@ storeMostFreeSwapDir(void) } return dirn; } +#endif + +/* + *Spread load across least 3/4 of the store directories + */ +static int +storeDirSelectSwapDir(void) +{ + double least_used = 1.0; + int dirn; + int i, j; + SwapDir *SD; + static int nleast = 0; + static int nconf = 0; + static int *dirq = NULL; + static double *diru = NULL; + /* + * Handle simplest case of a single swap directory immediately + */ + if (Config.cacheSwap.n_configured == 1) + return 0; + /* + * Initialise dirq on the first call or on change of number of dirs + */ + if (nconf != Config.cacheSwap.n_configured) { + nconf = Config.cacheSwap.n_configured; + nleast = (nconf * 3) / 4; + if (dirq != NULL) + xfree(dirq); + dirq = (int *) xmalloc(sizeof(int) * nleast); + if (diru != NULL) + xfree(diru); + diru = (double *) xmalloc(sizeof(double) * nconf); + for (j = 0; j < nleast; j++) + dirq[j] = -1; + } + /* + * Scan for a non-negative dirn in the dirq array and return that one + */ + dirn = -1; + for (j = 0; j < nleast; j++) { + dirn = dirq[j]; + if (dirn < 0) + continue; + dirq[j] = -1; + break; + } + /* + * If we found a valid dirn return it + */ + if (dirn >= 0) + return dirn; + /* + * Now for the real guts of the algorithm - building the dirq array + */ + for (i = 0; i < nconf; i++) { + diru[i] = 1.1; + SD = &Config.cacheSwap.swapDirs[i]; + if (SD->read_only) + continue; + diru[i] = (double) SD->cur_size; + diru[i] /= SD->max_size; + } + for (j = 0; j < nleast; j++) { + dirq[j] = -1; + least_used = 1.0; + dirn = -1; + for (i = 0; i < nconf; i++) { + if (diru[i] < least_used) { + least_used = diru[i]; + dirn = i; + } + } + if (dirn < 0) + break; + dirq[j] = dirn; + diru[dirn] = 1.1; + } + /* + * Setup default return of 0 if no least found + */ + if (dirq[0] < 0) + dirq[0] = 0; + dirn = dirq[0]; + dirq[0] = -1; + return dirn; +} int storeDirValidFileno(int fn) @@ -273,7 +361,7 @@ storeDirMapBitReset(int fn) int storeDirMapAllocate(void) { - int dirn = storeMostFreeSwapDir(); + int dirn = storeDirSelectSwapDir(); SwapDir *SD = &Config.cacheSwap.swapDirs[dirn]; int filn = file_map_allocate(SD->map, SD->suggest); SD->suggest = filn + 1;