From: hno <> Date: Sat, 6 Apr 2002 19:54:42 +0000 (+0000) Subject: Patch by Duane: X-Git-Tag: SQUID_3_0_PRE1~1123 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=924720b6bb7038a082909428b228a2906fdee7fb;p=thirdparty%2Fsquid.git Patch by Duane: Dynamically calculate the amount of needed SHM buffers for diskd at startup, and complain if squid -k reconfigure tries to increase the Q1/Q2 values. --- diff --git a/src/fs/diskd/store_dir_diskd.cc b/src/fs/diskd/store_dir_diskd.cc index cf6c1b9147..a21b131124 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.62 2002/04/06 08:49:43 adrian Exp $ + * $Id: store_dir_diskd.cc,v 1.63 2002/04/06 12:54:42 hno Exp $ * * DEBUG: section 47 Store Directory Routines * AUTHOR: Duane Wessels @@ -385,8 +385,9 @@ storeDiskdDirInit(SwapDir * sd) debug(50, 0) ("storeDiskdInit: msgget: %s\n", xstrerror()); fatal("msgget failed"); } + diskdinfo->shm.nbufs = diskdinfo->magic2 * 1.3; diskdinfo->shm.id = shmget((key_t) (ikey + 2), - SHMBUFS * SHMBUF_BLKSZ, 0600 | IPC_CREAT); + diskdinfo->shm.nbufs * SHMBUF_BLKSZ, 0600 | IPC_CREAT); if (diskdinfo->shm.id < 0) { debug(50, 0) ("storeDiskdInit: shmget: %s\n", xstrerror()); fatal("shmget failed"); @@ -396,9 +397,9 @@ storeDiskdDirInit(SwapDir * sd) debug(50, 0) ("storeDiskdInit: shmat: %s\n", xstrerror()); fatal("shmat failed"); } - diskdinfo->shm.inuse_map = xcalloc((SHMBUFS + 7) / 8, 1); - diskd_stats.shmbuf_count += SHMBUFS; - for (i = 0; i < SHMBUFS; i++) { + diskdinfo->shm.inuse_map = xcalloc((diskdinfo->shm.nbufs + 7) / 8, 1); + diskd_stats.shmbuf_count += diskdinfo->shm.nbufs; + for (i = 0; i < diskdinfo->shm.nbufs; i++) { CBIT_SET(diskdinfo->shm.inuse_map, i); storeDiskdShmPut(sd, i * SHMBUF_BLKSZ); } @@ -1632,7 +1633,7 @@ storeDiskdShmGet(SwapDir * sd, off_t * shm_offset) char *buf = NULL; diskdinfo_t *diskdinfo = sd->fsdata; int i; - for (i = 0; i < SHMBUFS; i++) { + for (i = 0; i < diskdinfo->shm.nbufs; i++) { if (CBIT_TEST(diskdinfo->shm.inuse_map, i)) continue; CBIT_SET(diskdinfo->shm.inuse_map, i); @@ -1642,7 +1643,7 @@ storeDiskdShmGet(SwapDir * sd, off_t * shm_offset) } assert(buf); assert(buf >= diskdinfo->shm.buf); - assert(buf < diskdinfo->shm.buf + (SHMBUFS * SHMBUF_BLKSZ)); + assert(buf < diskdinfo->shm.buf + (diskdinfo->shm.nbufs * SHMBUF_BLKSZ)); diskd_stats.shmbuf_count++; if (diskd_stats.max_shmuse < diskd_stats.shmbuf_count) diskd_stats.max_shmuse = diskd_stats.shmbuf_count; @@ -1655,9 +1656,9 @@ storeDiskdShmPut(SwapDir * sd, off_t offset) int i; diskdinfo_t *diskdinfo = sd->fsdata; assert(offset >= 0); - assert(offset < SHMBUFS * SHMBUF_BLKSZ); + assert(offset < diskdinfo->shm.nbufs * SHMBUF_BLKSZ); i = offset / SHMBUF_BLKSZ; - assert(i < SHMBUFS); + assert(i < diskdinfo->shm.nbufs); assert(CBIT_TEST(diskdinfo->shm.inuse_map, i)); CBIT_CLR(diskdinfo->shm.inuse_map, i); diskd_stats.shmbuf_count--; @@ -1712,7 +1713,21 @@ storeDiskdDirParseQ1(SwapDir * sd, const char *name, const char *value, int reco diskdinfo_t *diskdinfo = sd->fsdata; int old_magic1 = diskdinfo->magic1; diskdinfo->magic1 = atoi(value); - if (reconfiguring && old_magic1 != diskdinfo->magic1) + if (!reconfiguring) + return; + if (old_magic1 < diskdinfo->magic1) { + /* + * This is because shm.nbufs is computed at startup, when + * we call shmget(). We can't increase the Q1/Q2 parameters + * beyond their initial values because then we might have + * more "Q2 messages" than shared memory chunks, and this + * will cause an assertion in storeDiskdShmGet(). + */ + debug(3, 1) ("WARNING: cannot increase cache_dir '%s' Q1 value while Squid is running.\n", sd->path); + diskdinfo->magic1 = old_magic1; + return; + } + if (old_magic1 != diskdinfo->magic1) debug(3, 1) ("cache_dir '%s' new Q1 value '%d'\n", sd->path, diskdinfo->magic1); } @@ -1730,7 +1745,15 @@ storeDiskdDirParseQ2(SwapDir * sd, const char *name, const char *value, int reco diskdinfo_t *diskdinfo = sd->fsdata; int old_magic2 = diskdinfo->magic2; diskdinfo->magic2 = atoi(value); - if (reconfiguring && old_magic2 != diskdinfo->magic2) + if (!reconfiguring) + return; + if (old_magic2 < diskdinfo->magic2) { + /* See comments in Q1 function above */ + debug(3, 1) ("WARNING: cannot increase cache_dir '%s' Q2 value while Squid is running.\n", sd->path); + diskdinfo->magic2 = old_magic2; + return; + } + if (old_magic2 != diskdinfo->magic2) debug(3, 1) ("cache_dir '%s' new Q2 value '%d'\n", sd->path, diskdinfo->magic2); } diff --git a/src/fs/diskd/store_diskd.h b/src/fs/diskd/store_diskd.h index 8470cb84d9..1a955b76ef 100644 --- a/src/fs/diskd/store_diskd.h +++ b/src/fs/diskd/store_diskd.h @@ -29,6 +29,7 @@ struct _diskdinfo_t { char *buf; char *inuse_map; int id; + int nbufs; } shm; int magic1; int magic2; @@ -111,11 +112,6 @@ extern STOBJREAD storeDiskdRead; extern STOBJWRITE storeDiskdWrite; extern STOBJUNLINK storeDiskdUnlink; -/* - * SHMBUFS is the number of shared memory buffers to allocate for - * Each SwapDir. - */ -#define SHMBUFS 96 #define SHMBUF_BLKSZ SM_PAGE_SIZE extern diskd_stats_t diskd_stats;