windows-buffer-mgmt-20070204

Instead of using a fixed sized hashtable of 1024 entries regardless
of the number of buffers, compute the hashtable to be large enough
for on average 7 buffers per bucket.

Remove the 'size' field from cm_buf_t since it is never used.

Add more info to the output of cm_buf_t objects when using "fs memdump"
This commit is contained in:
Jeffrey Altman 2007-02-05 03:41:06 +00:00
parent 333005c463
commit cec0b902f6
4 changed files with 32 additions and 35 deletions

View File

@ -307,7 +307,7 @@ long buf_Init(int newFile, cm_buf_ops_t *opsp, afs_uint64 nbuffers)
cm_data.buf_nOrigBuffers = cm_data.buf_nbuffers;
/* lower hash size to a prime number */
cm_data.buf_hashSize = osi_PrimeLessThan(CM_BUF_HASHSIZE);
cm_data.buf_hashSize = osi_PrimeLessThan((afs_uint32)(cm_data.buf_nbuffers/7 + 1));
/* create hash table */
memset((void *)cm_data.buf_hashTablepp, 0, cm_data.buf_hashSize * sizeof(cm_buf_t *));
@ -502,7 +502,7 @@ void buf_WaitIO(cm_scache_t * scp, cm_buf_t *bp)
*/
cm_buf_t *buf_FindLocked(struct cm_scache *scp, osi_hyper_t *offsetp)
{
long i;
afs_uint32 i;
cm_buf_t *bp;
i = BUF_HASH(&scp->fid, offsetp);
@ -634,8 +634,8 @@ void buf_Recycle(cm_buf_t *bp)
* have any lock conflicts, so we can grab the buffer lock out of
* order in the locking hierarchy.
*/
osi_Log2( buf_logp, "buf_Recycle recycles 0x%p, off 0x%x",
bp, bp->offset.LowPart);
osi_Log3( buf_logp, "buf_Recycle recycles 0x%p, off 0x%x:%08x",
bp, bp->offset.HighPart, bp->offset.LowPart);
osi_assert(bp->refCount == 0);
osi_assert(!(bp->flags & (CM_BUF_READING | CM_BUF_WRITING | CM_BUF_DIRTY)));
@ -918,8 +918,8 @@ long buf_GetNew(struct cm_scache *scp, osi_hyper_t *offsetp, cm_buf_t **bufpp)
*/
lock_ReleaseMutex(&bp->mx);
*bufpp = bp;
osi_Log3(buf_logp, "buf_GetNew returning bp 0x%p for scp 0x%p, offset 0x%x",
bp, scp, offsetp->LowPart);
osi_Log4(buf_logp, "buf_GetNew returning bp 0x%p for scp 0x%p, offset 0x%x:%08x",
bp, scp, offsetp->HighPart, offsetp->LowPart);
return 0;
}
@ -1060,8 +1060,8 @@ long buf_Get(struct cm_scache *scp, osi_hyper_t *offsetp, cm_buf_t **bufpp)
}
lock_ReleaseWrite(&buf_globalLock);
osi_Log3(buf_logp, "buf_Get returning bp 0x%p for scp 0x%p, offset 0x%x",
bp, scp, offsetp->LowPart);
osi_Log4(buf_logp, "buf_Get returning bp 0x%p for scp 0x%p, offset 0x%x:%08x",
bp, scp, offsetp->HighPart, offsetp->LowPart);
#ifdef TESTING
buf_ValidateBufQueues();
#endif /* TESTING */
@ -1184,7 +1184,7 @@ void buf_SetDirty(cm_buf_t *bp)
*/
long buf_CleanAndReset(void)
{
long i;
afs_uint32 i;
cm_buf_t *bp;
cm_req_t req;
@ -1556,7 +1556,7 @@ int cm_DumpBufHashTable(FILE *outputFile, char *cookie, int lock)
int zilch;
cm_buf_t *bp;
char output[1024];
int i;
afs_uint32 i;
if (cm_data.buf_hashTablepp == NULL)
return -1;
@ -1574,9 +1574,12 @@ int cm_DumpBufHashTable(FILE *outputFile, char *cookie, int lock)
{
StringCbPrintfA(output, sizeof(output),
"%s bp=0x%08X, hash=%d, fid (cell=%d, volume=%d, "
"vnode=%d, unique=%d), size=%d flags=0x%x, refCount=%d\r\n",
"vnode=%d, unique=%d), offset=%x:%08x, dv=%d, "
"flags=0x%x, cmFlags=0x%x, refCount=%d\r\n",
cookie, (void *)bp, i, bp->fid.cell, bp->fid.volume,
bp->fid.vnode, bp->fid.unique, bp->size, bp->flags, bp->refCount);
bp->fid.vnode, bp->fid.unique, bp->offset.HighPart,
bp->offset.LowPart, bp->dataVersion, bp->flags,
bp->cmFlags, bp->refCount);
WriteFile(outputFile, output, (DWORD)strlen(output), &zilch, NULL);
}
}
@ -1589,9 +1592,12 @@ int cm_DumpBufHashTable(FILE *outputFile, char *cookie, int lock)
for(bp = cm_data.buf_freeListEndp; bp; bp=(cm_buf_t *) osi_QPrev(&bp->q)) {
StringCbPrintfA(output, sizeof(output),
"%s bp=0x%08X, fid (cell=%d, volume=%d, "
"vnode=%d, unique=%d), size=%d flags=0x%x, refCount=%d\r\n",
"vnode=%d, unique=%d), offset=%x:%08x, dv=%d, "
"flags=0x%x, cmFlags=0x%x, refCount=%d\r\n",
cookie, (void *)bp, bp->fid.cell, bp->fid.volume,
bp->fid.vnode, bp->fid.unique, bp->size, bp->flags, bp->refCount);
bp->fid.vnode, bp->fid.unique, bp->offset.HighPart,
bp->offset.LowPart, bp->dataVersion, bp->flags,
bp->cmFlags, bp->refCount);
WriteFile(outputFile, output, (DWORD)strlen(output), &zilch, NULL);
}
StringCbPrintfA(output, sizeof(output), "%s - Done dumping buf_FreeListEndp.\r\n", cookie);
@ -1602,9 +1608,12 @@ int cm_DumpBufHashTable(FILE *outputFile, char *cookie, int lock)
for(bp = cm_data.buf_dirtyListEndp; bp; bp=(cm_buf_t *) osi_QPrev(&bp->q)) {
StringCbPrintfA(output, sizeof(output),
"%s bp=0x%08X, fid (cell=%d, volume=%d, "
"vnode=%d, unique=%d), size=%d flags=0x%x, refCount=%d\r\n",
"vnode=%d, unique=%d), offset=%x:%08x, dv=%d, "
"flags=0x%x, cmFlags=0x%x, refCount=%d\r\n",
cookie, (void *)bp, bp->fid.cell, bp->fid.volume,
bp->fid.vnode, bp->fid.unique, bp->size, bp->flags, bp->refCount);
bp->fid.vnode, bp->fid.unique, bp->offset.HighPart,
bp->offset.LowPart, bp->dataVersion, bp->flags,
bp->cmFlags, bp->refCount);
WriteFile(outputFile, output, (DWORD)strlen(output), &zilch, NULL);
}
StringCbPrintfA(output, sizeof(output), "%s - Done dumping buf_dirtyListEndp.\r\n", cookie);

View File

@ -47,11 +47,6 @@ extern int buf_cacheType;
/* backup over pointer to the buffer */
#define BUF_OVERTOBUF(op) ((cm_buf_t *)(((char *)op) - ((long)(&((cm_buf_t *)0)->over))))
#ifdef notdef
/* pretend we have logs, too */
typedef char cm_log_t;
#endif
#define CM_BUF_MAGIC ('B' | 'U' <<8 | 'F'<<16 | 'F'<<24)
/* represents a single buffer */
@ -75,10 +70,6 @@ typedef struct cm_buf {
unsigned long refCount; /* reference count (buf_globalLock) */
long idCounter; /* counter for softrefs; bumped at each recycle */
long dirtyCounter; /* bumped at each dirty->clean transition */
#ifdef notdef
cm_log_t *logp; /* log for this buffer, if any */
osi_hyper_t lsn; /* lsn to force to (last LSN changing this buffer) */
#endif /* notdef */
osi_hyper_t offset; /* offset */
cm_fid_t fid; /* file ID */
#ifdef DEBUG
@ -86,7 +77,6 @@ typedef struct cm_buf {
/* the fid at the time of fid assignment. */
#endif
long flags; /* flags we're using */
long size; /* size in bytes of this buffer */
char *datap; /* data in this buffer */
unsigned long error; /* last error code, if CM_BUF_ERROR is set */
cm_user_t *userp; /* user who wrote to the buffer last */
@ -157,8 +147,6 @@ extern cm_buf_t *buf_FindLocked(struct cm_scache *, osi_hyper_t *);
extern cm_buf_t *buf_Find(struct cm_scache *, osi_hyper_t *);
extern HANDLE buf_GetFileHandle(long);
extern long buf_GetNewLocked(struct cm_scache *, osi_hyper_t *, cm_buf_t **);
extern long buf_Get(struct cm_scache *, osi_hyper_t *, cm_buf_t **);

View File

@ -87,10 +87,10 @@ ComputeSizeOfDataBuffers(afs_uint64 cacheBlocks, DWORD blockSize)
}
afs_uint64
ComputeSizeOfDataHT(void)
ComputeSizeOfDataHT(afs_uint64 cacheBlocks)
{
afs_uint64 size;
size = osi_PrimeLessThan(CM_BUF_HASHSIZE) * sizeof(cm_buf_t *);
size = osi_PrimeLessThan((afs_uint32)(cacheBlocks/7 + 1)) * sizeof(cm_buf_t *);
return size;
}
@ -115,7 +115,7 @@ ComputeSizeOfMappingFile(DWORD stats, DWORD maxVols, DWORD maxCells, DWORD chunk
+ ComputeSizeOfSCacheHT(stats)
+ ComputeSizeOfDNLCache()
+ ComputeSizeOfDataBuffers(cacheBlocks, blockSize)
+ 2 * ComputeSizeOfDataHT()
+ 2 * ComputeSizeOfDataHT(cacheBlocks)
+ ComputeSizeOfDataHeaders(cacheBlocks);
return size;
}
@ -837,7 +837,7 @@ cm_InitMappedMemory(DWORD virtualCache, char * cachePath, DWORD stats, DWORD chu
cm_data.buf_nbuffers = cacheBlocks;
cm_data.buf_nOrigBuffers = 0;
cm_data.buf_blockSize = CM_BUF_BLOCKSIZE;
cm_data.buf_hashSize = CM_BUF_HASHSIZE;
cm_data.buf_hashSize = osi_PrimeLessThan((afs_uint32)(cacheBlocks/7 + 1));
cm_data.mountRootGen = time(NULL);
@ -855,9 +855,9 @@ cm_InitMappedMemory(DWORD virtualCache, char * cachePath, DWORD stats, DWORD chu
cm_data.dnlcBaseAddress = (cm_nc_t *) baseAddress;
baseAddress += ComputeSizeOfDNLCache();
cm_data.buf_hashTablepp = (cm_buf_t **) baseAddress;
baseAddress += ComputeSizeOfDataHT();
baseAddress += ComputeSizeOfDataHT(cacheBlocks);
cm_data.buf_fileHashTablepp = (cm_buf_t **) baseAddress;
baseAddress += ComputeSizeOfDataHT();
baseAddress += ComputeSizeOfDataHT(cacheBlocks);
cm_data.bufHeaderBaseAddress = (cm_buf_t *) baseAddress;
baseAddress += ComputeSizeOfDataHeaders(cacheBlocks);
cm_data.bufDataBaseAddress = (char *) baseAddress;

View File

@ -95,7 +95,7 @@ afs_uint64 ComputeSizeOfSCache(DWORD stats);
afs_uint64 ComputeSizeOfSCacheHT(DWORD stats);
afs_uint64 ComputeSizeOfDNLCache(void);
afs_uint64 ComputeSizeOfDataBuffers(afs_uint64 cacheBlocks, DWORD blockSize);
afs_uint64 ComputeSizeOfDataHT(void);
afs_uint64 ComputeSizeOfDataHT(afs_uint64 cacheBlocks);
afs_uint64 ComputeSizeOfDataHeaders(afs_uint64 cacheBlocks);
afs_uint64 ComputeSizeOfMappingFile(DWORD stats, DWORD maxVols, DWORD maxCells, DWORD chunkSize, afs_uint64 cacheBlocks, DWORD blockSize);
PSECURITY_ATTRIBUTES CreateCacheFileSA();