From: wessels <> Date: Tue, 10 Jul 2001 21:35:45 +0000 (+0000) Subject: Bugzilla #184: storeDiskdShmGet() assertion X-Git-Tag: SQUID_3_0_PRE1~1472 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ab848be4999b79429b92f2f5400a77d9cc103ea8;p=thirdparty%2Fsquid.git Bugzilla #184: storeDiskdShmGet() assertion This patch changes the mechanism for keeping track of unused shared memory chunks. Instead of using a linked list, now we'll use a bitmap. It should eliminate the problems I'm seeing on Alphas where the linklist->ptr value has bit #33 mysteriously set. In the new scheme, the shm chunk pointer is always recalculated based on the index of the bitmap. --- diff --git a/src/fs/diskd/store_dir_diskd.cc b/src/fs/diskd/store_dir_diskd.cc index 1c7924e318..64b9dc7551 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.51 2001/06/28 05:18:25 wessels Exp $ + * $Id: store_dir_diskd.cc,v 1.52 2001/07/10 15:35:45 wessels Exp $ * * DEBUG: section 47 Store Directory Routines * AUTHOR: Duane Wessels @@ -402,9 +402,12 @@ 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++) + for (i = 0; i < SHMBUFS; i++) { + CBIT_SET(diskdinfo->shm.inuse_map, i); storeDiskdShmPut(sd, i * SHMBUF_BLKSZ); + } snprintf(skey1, 32, "%d", ikey); snprintf(skey2, 32, "%d", ikey + 1); snprintf(skey3, 32, "%d", ikey + 2); @@ -514,7 +517,6 @@ storeDiskdDirCallback(SwapDir * SD) if (diskd_stats.sent_count - diskd_stats.recv_count > diskd_stats.max_away) { diskd_stats.max_away = diskd_stats.sent_count - diskd_stats.recv_count; - diskd_stats.max_shmuse = diskd_stats.shmbuf_count; } while (1) { memset(&M, '\0', sizeof(M)); @@ -1638,26 +1640,37 @@ storeDiskdDirReplRemove(StoreEntry * e) void * storeDiskdShmGet(SwapDir * sd, off_t * shm_offset) { - char *buf; + char *buf = NULL; diskdinfo_t *diskdinfo = sd->fsdata; - buf = linklistShift(&diskdinfo->shm.stack); + int i; + for (i = 0; i < SHMBUFS; i++) { + if (CBIT_TEST(diskdinfo->shm.inuse_map, i)) + continue; + CBIT_SET(diskdinfo->shm.inuse_map, i); + *shm_offset = i * SHMBUF_BLKSZ; + buf = diskdinfo->shm.buf + (*shm_offset); + break; + } assert(buf); assert(buf >= diskdinfo->shm.buf); assert(buf < diskdinfo->shm.buf + (SHMBUFS * SHMBUF_BLKSZ)); - *shm_offset = buf - diskdinfo->shm.buf; diskd_stats.shmbuf_count++; + if (diskd_stats.max_shmuse < diskd_stats.shmbuf_count) + diskd_stats.max_shmuse = diskd_stats.shmbuf_count; return buf; } void storeDiskdShmPut(SwapDir * sd, off_t offset) { - char *buf; + int i; diskdinfo_t *diskdinfo = sd->fsdata; assert(offset >= 0); assert(offset < SHMBUFS * SHMBUF_BLKSZ); - buf = diskdinfo->shm.buf + offset; - linklistPush(&diskdinfo->shm.stack, buf); + i = offset / SHMBUF_BLKSZ; + assert(i < SHMBUFS); + assert(CBIT_TEST(diskdinfo->shm.inuse_map, i)); + CBIT_CLR(diskdinfo->shm.inuse_map, i); diskd_stats.shmbuf_count--; } diff --git a/src/fs/diskd/store_diskd.h b/src/fs/diskd/store_diskd.h index 32247701a5..8470cb84d9 100644 --- a/src/fs/diskd/store_diskd.h +++ b/src/fs/diskd/store_diskd.h @@ -27,7 +27,7 @@ struct _diskdinfo_t { int away; struct { char *buf; - link_list *stack; + char *inuse_map; int id; } shm; int magic1;