1N/A * See the file LICENSE for redistribution information. 1N/A * Copyright (c) 1996, 1997, 1998 1N/A * Sleepycat Software. All rights reserved. 1N/A * @(#)mp.h 10.37 (Sleepycat) 1/1/99 1N/A /* Default mpool name. */ 1N/A * We default to 256K (32 8K pages) if the user doesn't specify, and 1N/A * require a minimum of 20K. 1N/A#
define INVALID 0
/* Invalid shared memory offset. */ 1N/A * There are three ways we do locking in the mpool code: 1N/A * Locking a handle mutex to provide concurrency for DB_THREAD operations. 1N/A * Locking the region mutex to provide mutual exclusion while reading and 1N/A * writing structures in the shared region. 1N/A * Locking buffer header mutexes during I/O. 1N/A * The first will not be further described here. We use the shared mpool 1N/A * the data structures, including the buffer headers. We use a per-buffer 1N/A * header lock to wait on buffer I/O. The order of locking is as follows: 1N/A * Searching for a buffer: 1N/A * Acquire the region lock. 1N/A * Find the buffer header. 1N/A * Increment the reference count (guarantee the buffer stays). 1N/A * While the BH_LOCKED flag is set (I/O is going on) { 1N/A * Release the region lock. 1N/A * Explicitly yield the processor if it's not the first pass 1N/A * through this loop, otherwise, we can simply spin because 1N/A * we'll be simply switching between the two locks. 1N/A * Request the buffer lock. 1N/A * The I/O will complete... 1N/A * Acquire the buffer lock. 1N/A * Release the buffer lock. 1N/A * Acquire the region lock. 1N/A * Return the buffer. 1N/A * Acquire the region lock. 1N/A * If reading, increment the reference count (guarantee the buffer stays). 1N/A * Set the BH_LOCKED flag. 1N/A * Acquire the buffer lock (guaranteed not to block). 1N/A * Release the region lock. 1N/A * Do the I/O and/or initialize the buffer contents. 1N/A * Release the buffer lock. 1N/A * At this point, the buffer lock is available, but the logical 1N/A * operation (flagged by BH_LOCKED) is not yet completed. For 1N/A * this reason, among others, threads checking the BH_LOCKED flag 1N/A * must loop around their test. 1N/A * Acquire the region lock. 1N/A * Clear the BH_LOCKED flag. 1N/A * Release the region lock. 1N/A * Pointers to DB_MPOOL, MPOOL, DB_MPOOLFILE and MPOOLFILE structures are not 1N/A * reacquired when a region lock is reacquired because they couldn't have been 1N/A/* Check for region catastrophic shutdown. */ 1N/A * Per-process memory pool structure. 1N/A/* These fields need to be protected for multi-threaded support. */ 1N/A /* List of DB_MPOOLFILE's. */ 1N/A/* These fields are not protected. */ 1N/A void *
addr;
/* Address of shalloc() region. */ 1N/A /* Pgin, pgout routines. */ 1N/A * Per-process DB_MPOOLFILE information. 1N/A/* These fields need to be protected for multi-threaded support. */ 1N/A int fd;
/* Underlying file descriptor. */ 1N/A * This field is a special case -- it's protected by the region lock 1N/A * NOT the thread lock. The reason for this is that we always have 1N/A * the region lock immediately before or after we modify the field, 1N/A * and we don't want to use the structure lock to protect it because 1N/A * then I/O (which is done with the structure lock held because of 1N/A * the race between the seek and write of the file descriptor) will 1N/A * block any other put/get calls using this DB_MPOOLFILE structure. 1N/A/* These fields are not protected. */ 1N/A void *
addr;
/* Address of mmap'd region. */ 1N/A/* These fields need to be protected for multi-threaded support. */ 1N/A * Shared memory pool region. One of these is allocated in shared 1N/A * memory, and describes the pool. 1N/A * We make the assumption that the early pages of the file are far 1N/A * more likely to be retrieved than the later pages, which means 1N/A * that the top bits are more interesting for hashing since they're 1N/A * less likely to collide. On the other hand, since 512 4K pages 1N/A * represents a 2MB file, only the bottom 9 bits of the page number 1N/A * are likely to be set. We XOR in the offset in the MPOOL of the 1N/A * MPOOLFILE that backs this particular page, since that should also 1N/A * be unique for the page. 1N/A * Shared DB_MPOOLFILE information. 1N/A#
define MP_TEMP 0x02 /* Backing file is a temporary. */ 1N/A#
define BH_LOCKED 0x008 /* Page is locked (I/O in progress). */ 1N/A#
define BH_WRITE 0x020 /* Page scheduled for writing. */ 1N/A * This array must be size_t aligned -- the DB access methods put PAGE 1N/A * and other structures into it, and expect to be able to access them 1N/A * directly. (We guarantee size_t alignment in the db_mpool(3) manual