summaryrefslogtreecommitdiff
path: root/src/support/scratch.c
diff options
context:
space:
mode:
authorKeith Bostic <keith@wiredtiger.com>2013-01-27 10:37:01 -0500
committerKeith Bostic <keith@wiredtiger.com>2013-01-27 10:37:01 -0500
commitb94993320657eb4c7ed116e76a2c7914db78f33f (patch)
tree3e633624e1611c6262ec3696bbe489fdb1c9183d /src/support/scratch.c
parent3860a40a1242ff6eeda88459b51a9a15177a2f5f (diff)
downloadmongo-b94993320657eb4c7ed116e76a2c7914db78f33f.tar.gz
Add mmap support for read-only objects (a read-only object is an object
using a checkpoint other than the "live" system). Basically, when a read-only object reads pages from the backing file, it maps them into memory rather than copying them into the buffers. This change adds support for a new class of WT_ITEM buffer, one that has WT_ITEM_MAPPED set. The WT_ITEM_MAPPED flag gets set when the buffer's object is mapped into memory by the underlying block manager read call. Add configuration string "mmap", defaults to on, turns off mmap calls.
Diffstat (limited to 'src/support/scratch.c')
-rw-r--r--src/support/scratch.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/src/support/scratch.c b/src/support/scratch.c
index 6c4e77289a7..9cda695ec89 100644
--- a/src/support/scratch.c
+++ b/src/support/scratch.c
@@ -22,7 +22,11 @@ __wt_buf_clear(WT_ITEM *buf)
buf->mem = NULL;
buf->memsize = 0;
- /* Note: don't clear the flags, the buffer remains marked in-use. */
+ /*
+ * Note: don't clear the flags, the buffer remains marked for aligned
+ * use as well as "in-use".
+ */
+ F_CLR(buf, WT_ITEM_MAPPED);
}
/*
@@ -37,6 +41,10 @@ __wt_buf_grow(WT_SESSION_IMPL *session, WT_ITEM *buf, size_t size)
WT_ASSERT(session, size <= UINT32_MAX);
+ /* Clear buffers previously used for mapped returns. */
+ if (F_ISSET(buf, WT_ITEM_MAPPED))
+ __wt_buf_clear(buf);
+
if (size > buf->memsize) {
/*
* Grow the buffer's memory: if the data reference is not set
@@ -132,6 +140,8 @@ __wt_buf_steal(WT_SESSION_IMPL *session, WT_ITEM *buf, uint32_t *sizep)
{
void *retp;
+ WT_ASSERT(session, !F_ISSET(buf, WT_ITEM_MAPPED));
+
/*
* Sometimes we steal a buffer for a different purpose, for example,
* we've read in an overflow item, and now it's going to become a key
@@ -169,7 +179,8 @@ __wt_buf_steal(WT_SESSION_IMPL *session, WT_ITEM *buf, uint32_t *sizep)
void
__wt_buf_free(WT_SESSION_IMPL *session, WT_ITEM *buf)
{
- __wt_free(session, buf->mem);
+ if (!F_ISSET(buf, WT_ITEM_MAPPED))
+ __wt_free(session, buf->mem);
__wt_buf_clear(buf);
}
@@ -184,6 +195,10 @@ __wt_buf_fmt(WT_SESSION_IMPL *session, WT_ITEM *buf, const char *fmt, ...)
va_list ap;
size_t len;
+ /* Clear buffers previously used for mapped returns. */
+ if (F_ISSET(buf, WT_ITEM_MAPPED))
+ __wt_buf_clear(buf);
+
for (;;) {
va_start(ap, fmt);
len = (size_t)vsnprintf(buf->mem, buf->memsize, fmt, ap);
@@ -217,6 +232,10 @@ __wt_buf_catfmt(WT_SESSION_IMPL *session, WT_ITEM *buf, const char *fmt, ...)
size_t len, space;
char *p;
+ /* Clear buffers previously used for mapped returns. */
+ if (F_ISSET(buf, WT_ITEM_MAPPED))
+ __wt_buf_clear(buf);
+
for (;;) {
va_start(ap, fmt);
p = (char *)((uint8_t *)buf->mem + buf->size);