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