From: wessels <> Date: Tue, 2 Jan 2001 08:41:30 +0000 (+0000) Subject: swap space accounting used to assume 1K block size. This patch uses X-Git-Tag: SQUID_3_0_PRE1~1711 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=90d42c2863149e2c5ef1d8b02b5871a335e3aa8e;p=thirdparty%2Fsquid.git swap space accounting used to assume 1K block size. This patch uses statvfs/statfs to get the actual block size and use it when accounting for filesystem overheads. --- diff --git a/src/cache_cf.cc b/src/cache_cf.cc index f5e04afb5f..151790cbb8 100644 --- a/src/cache_cf.cc +++ b/src/cache_cf.cc @@ -1,6 +1,6 @@ /* - * $Id: cache_cf.cc,v 1.361 2000/12/09 04:16:07 wessels Exp $ + * $Id: cache_cf.cc,v 1.362 2001/01/02 01:41:30 wessels Exp $ * * DEBUG: section 3 Configuration File Parsing * AUTHOR: Harvest Derived @@ -947,6 +947,9 @@ parse_cachedir(cacheSwap * swap) /* XXX should we dupe the string here, in case it gets trodden on? */ sd->type = storefs_list[fs].typestr; sd->max_objsize = maxobjsize; + /* defaults in case fs implementation fails to set these */ + sd->fs.blksize = 1024; + sd->fs.kperblk = 1; swap->n_configured++; /* Update the max object size */ update_maxobjsize(); diff --git a/src/fs/aufs/store_dir_aufs.cc b/src/fs/aufs/store_dir_aufs.cc index a0c4cc1cee..4f7eb6779f 100644 --- a/src/fs/aufs/store_dir_aufs.cc +++ b/src/fs/aufs/store_dir_aufs.cc @@ -1,6 +1,6 @@ /* - * $Id: store_dir_aufs.cc,v 1.22 2000/12/09 01:47:22 wessels Exp $ + * $Id: store_dir_aufs.cc,v 1.23 2001/01/02 01:41:33 wessels Exp $ * * DEBUG: section 47 Store Directory Routines * AUTHOR: Duane Wessels @@ -370,6 +370,8 @@ storeAufsDirInit(SwapDir * sd) eventAdd("storeDirClean", storeAufsDirCleanEvent, NULL, 15.0, 1); started_clean_event = 1; } + if (0 == storeDirGetBlkSize(sd->path, &sd->fs.blksize)) + sd->fs.kperblk = sd->fs.blksize >> 10; } static void diff --git a/src/fs/coss/store_dir_coss.cc b/src/fs/coss/store_dir_coss.cc index 142be65d87..72e7f58c63 100644 --- a/src/fs/coss/store_dir_coss.cc +++ b/src/fs/coss/store_dir_coss.cc @@ -1,6 +1,6 @@ /* - * $Id: store_dir_coss.cc,v 1.12 2000/12/09 00:35:04 wessels Exp $ + * $Id: store_dir_coss.cc,v 1.13 2001/01/02 01:41:34 wessels Exp $ * * DEBUG: section 81 Store COSS Directory Routines * AUTHOR: Eric Stern @@ -153,6 +153,8 @@ storeCossDirInit(SwapDir * sd) storeCossDirRebuild(sd); cs->fd = file_open(sd->path, O_RDWR | O_CREAT); n_coss_dirs++; + if (0 == storeDirGetBlkSize(sd->path, &sd->fs.blksize)) + sd->fs.kperblk = sd->fs.blksize >> 10; } void diff --git a/src/fs/diskd/store_dir_diskd.cc b/src/fs/diskd/store_dir_diskd.cc index 6d6bec4a74..a4f62295c3 100644 --- a/src/fs/diskd/store_dir_diskd.cc +++ b/src/fs/diskd/store_dir_diskd.cc @@ -1,6 +1,6 @@ /* - * $Id: store_dir_diskd.cc,v 1.29 2000/12/09 01:47:22 wessels Exp $ + * $Id: store_dir_diskd.cc,v 1.30 2001/01/02 01:41:34 wessels Exp $ * * DEBUG: section 47 Store Directory Routines * AUTHOR: Duane Wessels @@ -441,6 +441,8 @@ storeDiskdDirInit(SwapDir * sd) eventAdd("storeDirClean", storeDiskdDirCleanEvent, NULL, 15.0, 1); started_clean_event = 1; } + if (0 == storeDirGetBlkSize(sd->path, &sd->fs.blksize)) + sd->fs.kperblk = sd->fs.blksize >> 10; } diff --git a/src/fs/ufs/store_dir_ufs.cc b/src/fs/ufs/store_dir_ufs.cc index 25806688d8..04b2ecf62e 100644 --- a/src/fs/ufs/store_dir_ufs.cc +++ b/src/fs/ufs/store_dir_ufs.cc @@ -1,6 +1,6 @@ /* - * $Id: store_dir_ufs.cc,v 1.20 2001/01/02 00:11:55 wessels Exp $ + * $Id: store_dir_ufs.cc,v 1.21 2001/01/02 01:41:35 wessels Exp $ * * DEBUG: section 47 Store Directory Routines * AUTHOR: Duane Wessels @@ -368,6 +368,8 @@ storeUfsDirInit(SwapDir * sd) eventAdd("storeDirClean", storeUfsDirCleanEvent, NULL, 15.0, 1); started_clean_event = 1; } + if (0 == storeDirGetBlkSize(sd->path, &sd->fs.blksize)) + sd->fs.kperblk = sd->fs.blksize >> 10; } static void diff --git a/src/protos.h b/src/protos.h index 5762122f1e..167d11f98b 100644 --- a/src/protos.h +++ b/src/protos.h @@ -1,6 +1,6 @@ /* - * $Id: protos.h,v 1.389 2000/12/30 23:29:07 wessels Exp $ + * $Id: protos.h,v 1.390 2001/01/02 01:41:30 wessels Exp $ * * * SQUID Internet Object Cache http://squid.nlanr.net/Squid/ @@ -939,6 +939,7 @@ extern void storeDirSync(void); extern void storeDirCallback(void); extern void storeDirLRUDelete(StoreEntry *); extern void storeDirLRUAdd(StoreEntry *); +int storeDirGetBlkSize(const char *path, int *blksize); /* * store_swapmeta.c diff --git a/src/store_dir.cc b/src/store_dir.cc index 0cce350b4a..d338feb81f 100644 --- a/src/store_dir.cc +++ b/src/store_dir.cc @@ -1,6 +1,6 @@ /* - * $Id: store_dir.cc,v 1.117 2000/12/05 09:11:24 wessels Exp $ + * $Id: store_dir.cc,v 1.118 2001/01/02 01:41:31 wessels Exp $ * * DEBUG: section 47 Store Directory Routines * AUTHOR: Duane Wessels @@ -248,7 +248,8 @@ storeDirSwapLog(const StoreEntry * e, int op) void storeDirUpdateSwapSize(SwapDir * SD, size_t size, int sign) { - int k = ((size + 1023) >> 10) * sign; + int blks = (size + SD->fs.blksize - 1) / SD->fs.blksize; + int k = blks * SD->fs.kperblk * sign; SD->cur_size += k; store_swap_size += k; if (sign > 0) @@ -280,6 +281,8 @@ storeDirStats(StoreEntry * sentry) SD = &(Config.cacheSwap.swapDirs[i]); storeAppendPrintf(sentry, "Store Directory #%d (%s): %s\n", i, SD->type, storeSwapDir(i)); + storeAppendPrintf(sentry, "FS Block Size %d KB\n", + SD->fs.kperblk); SD->statfs(SD, sentry); } } @@ -452,3 +455,23 @@ storeDirCallback(void) } while (j > 0); ndir++; } + +int +storeDirGetBlkSize(const char *path, int *blksize) +{ +#if HAVE_STATVFS + struct statvfs sfs; + if (statvfs(path, &sfs)) { + debug(0, 0) ("%s: %s\n", path, xstrerror()); + return 1; + } +#else + struct statfs sfs; + if (statfs(path, &sfs)) { + debug(0, 0) ("%s: %s\n", path, xstrerror()); + return 1; + } +#endif + *blksize = (int) sfs.f_bsize; + return 0; +} diff --git a/src/structs.h b/src/structs.h index c8dbbe10af..7f326f8f9d 100644 --- a/src/structs.h +++ b/src/structs.h @@ -1,6 +1,6 @@ /* - * $Id: structs.h,v 1.369 2001/01/01 23:09:59 wessels Exp $ + * $Id: structs.h,v 1.370 2001/01/02 01:41:31 wessels Exp $ * * * SQUID Internet Object Cache http://squid.nlanr.net/Squid/ @@ -1388,6 +1388,10 @@ struct _SwapDir { } clean; int writes_since_clean; } log; + struct { + int blksize; + int kperblk; + } fs; void *fsdata; };