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#
endif /* not lint */ 1N/A * __memp_reg_alloc -- 1N/A * Allocate some space in the mpool region, with locking. 1N/A * PUBLIC: int __memp_reg_alloc __P((DB_MPOOL *, size_t, size_t *, void *)); 1N/A * Allocate some space in the mpool region. 1N/A * PUBLIC: int __memp_alloc __P((DB_MPOOL *, size_t, size_t *, void *)); 1N/A "Unable to allocate %lu bytes from mpool shared region: %s\n",
1N/A /* Look for a buffer on the free list that's the right size. */ 1N/A /* Discard from the free list until we've freed enough memory. */ 1N/A * Retry as soon as we've freed up sufficient space. If we 1N/A * will have to coalesce memory to satisfy the request, don't 1N/A * try until it's likely (possible?) that we'll succeed. 1N/Aretry:
/* Find a buffer we can flush; pure LRU. */ 1N/A /* Ignore pinned or locked (I/O in progress) buffers. */ 1N/A /* Find the associated MPOOLFILE. */ 1N/A * Write the page if it's dirty. 1N/A * If we wrote the page, fall through and free the buffer. We 1N/A * don't have to rewalk the list to acquire the buffer because 1N/A * it was never available for any other process to modify it. 1N/A * If we didn't write the page, but we discarded and reacquired 1N/A * the region lock, restart the buffer list walk. If we neither 1N/A * wrote the buffer nor discarded the region lock, continue down 1N/A * It's possible that another process wants this buffer 1N/A * and incremented the ref count while we were writing 1N/A * Check to see if the buffer is the size we're looking for. 1N/A * If it is, simply reuse it. 1N/A /* Free the buffer. */ 1N/A * Retry as soon as we've freed up sufficient space. If we 1N/A * have to coalesce of memory to satisfy the request, don't 1N/A * try until it's likely (possible?) that we'll succeed. 1N/A /* Restart the walk if we discarded the region lock. */ 1N/A * Attach to, and optionally create, the mpool region. 1N/A * PUBLIC: int __memp_ropen 1N/A * PUBLIC: __P((DB_MPOOL *, const char *, size_t, int, int, u_int32_t)); 1N/A * Unlike other DB subsystems, mpool can't simply grow the region 1N/A * because it returns pointers into the region to its clients. To 1N/A * "grow" the region, we'd have to allocate a new region and then 1N/A * store a region number in the structures that reference regional 1N/A * objects. It's reasonable that we fail regardless, as clients 1N/A * shouldn't have every page in the region pinned, so the only 1N/A * "failure" mode should be a performance penalty because we don't 1N/A * find a page in the cache that we'd like to have found. 1N/A * Up the user's cachesize by 25% to account for our overhead. 1N/A * Map in the region. 1N/A * If it's a private mpool, use malloc, it's a lot faster than 1N/A * instantiating a region. 1N/A * If we're creating a temporary region, don't use any standard 1N/A * The MPOOL structure is first in the region, the rest of the region 1N/A /* Initialize a created region. */ 1N/A * Assume we want to keep the hash chains with under 10 pages 1N/A * on each chain. We don't know the pagesize in advance, and 1N/A * it may differ for different files. Use a pagesize of 1K for 1N/A * the calculation -- we walk these chains a lot, they should 1N/A /* Allocate hash table space and initialize it. */ 1N/A /* Get the local hash table address. */