ITS#7191 Align dirty MDB pages on the stack

vmware
Hallvard Furuseth 13 years ago
parent 15f3e650da
commit 2baadabdff
  1. 32
      libraries/libmdb/mdb.c

@ -764,6 +764,20 @@ typedef struct MDB_meta {
txnid_t mm_txnid; /**< txnid that committed this page */ txnid_t mm_txnid; /**< txnid that committed this page */
} MDB_meta; } MDB_meta;
/** Buffer for a stack-allocated dirty page.
* The members define size and alignment, and silence type
* aliasing warnings. They are not used directly; that could
* mean incorrectly using several union members in parallel.
*/
typedef union MDB_pagebuf {
char mb_raw[MDB_PAGESIZE];
MDB_page mb_page;
struct {
char mm_pad[PAGEHDRSZ];
MDB_meta mm_meta;
} mb_metabuf;
} MDB_pagebuf;
/** Auxiliary DB info. /** Auxiliary DB info.
* The information here is mostly static/read-only. There is * The information here is mostly static/read-only. There is
* only a single copy of this record in the environment. * only a single copy of this record in the environment.
@ -2050,7 +2064,7 @@ done:
static int static int
mdb_env_read_header(MDB_env *env, MDB_meta *meta) mdb_env_read_header(MDB_env *env, MDB_meta *meta)
{ {
char page[MDB_PAGESIZE]; MDB_pagebuf pbuf;
MDB_page *p; MDB_page *p;
MDB_meta *m; MDB_meta *m;
int rc, err; int rc, err;
@ -2059,9 +2073,9 @@ mdb_env_read_header(MDB_env *env, MDB_meta *meta)
*/ */
#ifdef _WIN32 #ifdef _WIN32
if (!ReadFile(env->me_fd, page, MDB_PAGESIZE, (DWORD *)&rc, NULL) || rc == 0) if (!ReadFile(env->me_fd, &pbuf, MDB_PAGESIZE, (DWORD *)&rc, NULL) || rc == 0)
#else #else
if ((rc = read(env->me_fd, page, MDB_PAGESIZE)) == 0) if ((rc = read(env->me_fd, &pbuf, MDB_PAGESIZE)) == 0)
#endif #endif
{ {
return ENOENT; return ENOENT;
@ -2074,7 +2088,7 @@ mdb_env_read_header(MDB_env *env, MDB_meta *meta)
return err; return err;
} }
p = (MDB_page *)page; p = (MDB_page *)&pbuf;
if (!F_ISSET(p->mp_flags, P_META)) { if (!F_ISSET(p->mp_flags, P_META)) {
DPRINTF("page %zu not a meta page", p->mp_pgno); DPRINTF("page %zu not a meta page", p->mp_pgno);
@ -3996,7 +4010,7 @@ mdb_cursor_put(MDB_cursor *mc, MDB_val *key, MDB_val *data,
unsigned int mcount = 0; unsigned int mcount = 0;
size_t nsize; size_t nsize;
int rc, rc2; int rc, rc2;
char pbuf[MDB_PAGESIZE]; MDB_pagebuf pbuf;
char dbuf[MAXKEYSIZE+1]; char dbuf[MAXKEYSIZE+1];
unsigned int nflags; unsigned int nflags;
DKBUF; DKBUF;
@ -4092,7 +4106,7 @@ more:
/* create a fake page for the dup items */ /* create a fake page for the dup items */
memcpy(dbuf, dkey.mv_data, dkey.mv_size); memcpy(dbuf, dkey.mv_data, dkey.mv_size);
dkey.mv_data = dbuf; dkey.mv_data = dbuf;
fp = (MDB_page *)pbuf; fp = (MDB_page *)&pbuf;
fp->mp_pgno = mc->mc_pg[mc->mc_top]->mp_pgno; fp->mp_pgno = mc->mc_pg[mc->mc_top]->mp_pgno;
fp->mp_flags = P_LEAF|P_DIRTY|P_SUBP; fp->mp_flags = P_LEAF|P_DIRTY|P_SUBP;
fp->mp_lower = PAGEHDRSZ; fp->mp_lower = PAGEHDRSZ;
@ -4108,7 +4122,7 @@ more:
do_sub = 1; do_sub = 1;
rdata = &xdata; rdata = &xdata;
xdata.mv_size = fp->mp_upper; xdata.mv_size = fp->mp_upper;
xdata.mv_data = pbuf; xdata.mv_data = fp;
flags |= F_DUPDATA; flags |= F_DUPDATA;
goto new_sub; goto new_sub;
} }
@ -4161,8 +4175,8 @@ more:
/* no, just grow it */ /* no, just grow it */
rdata = &xdata; rdata = &xdata;
xdata.mv_size = NODEDSZ(leaf) + offset; xdata.mv_size = NODEDSZ(leaf) + offset;
xdata.mv_data = pbuf; xdata.mv_data = &pbuf;
mp = (MDB_page *)pbuf; mp = (MDB_page *)&pbuf;
mp->mp_pgno = mc->mc_pg[mc->mc_top]->mp_pgno; mp->mp_pgno = mc->mc_pg[mc->mc_top]->mp_pgno;
flags |= F_DUPDATA; flags |= F_DUPDATA;
} }

Loading…
Cancel
Save