mirror of
https://github.com/samba-team/samba.git
synced 2025-02-25 17:57:42 +03:00
ntdb: special accessor functions for read/write of an offset.
We also split off the NTDB_CONVERT case (where the ntdb is of a different endian) into its own io function. NTDB speed: Adding 10000 records: 3894-9951(8553) ns (815528 bytes) Finding 10000 records: 1644-4294(3580) ns (815528 bytes) Missing 10000 records: 1497-4018(3303) ns (815528 bytes) Traversing 10000 records: 1585-4225(3505) ns (815528 bytes) Deleting 10000 records: 3088-8154(6927) ns (815528 bytes) Re-adding 10000 records: 3192-8308(7089) ns (815528 bytes) Appending 10000 records: 5187-13307(11365) ns (1274312 bytes) Churning 10000 records: 6772-17567(15078) ns (1274312 bytes) NTDB speed in transaction: Adding 10000 records: 1602-2404(2214) ns (815528 bytes) Finding 10000 records: 456-871(778) ns (815528 bytes) Missing 10000 records: 393-522(503) ns (815528 bytes) Traversing 10000 records: 729-1015(945) ns (815528 bytes) Deleting 10000 records: 1065-1476(1374) ns (815528 bytes) Re-adding 10000 records: 1397-1930(1819) ns (815528 bytes) Appending 10000 records: 2927-3351(3184) ns (1274312 bytes) Churning 10000 records: 3921-4697(4378) ns (1274312 bytes) smbtorture results: ntdb speed 86581-191518(175666) ops/sec Applying patch..increase-top-level.patch
This commit is contained in:
parent
9133a98c44
commit
f986554b1e
116
lib/ntdb/io.c
116
lib/ntdb/io.c
@ -238,27 +238,6 @@ enum NTDB_ERROR zero_out(struct ntdb_context *ntdb, ntdb_off_t off, ntdb_len_t l
|
||||
return ecode;
|
||||
}
|
||||
|
||||
ntdb_off_t ntdb_read_off(struct ntdb_context *ntdb, ntdb_off_t off)
|
||||
{
|
||||
ntdb_off_t ret;
|
||||
enum NTDB_ERROR ecode;
|
||||
|
||||
if (likely(!(ntdb->flags & NTDB_CONVERT))) {
|
||||
ntdb_off_t *p = ntdb->io->direct(ntdb, off, sizeof(*p), false);
|
||||
if (NTDB_PTR_IS_ERR(p)) {
|
||||
return NTDB_ERR_TO_OFF(NTDB_PTR_ERR(p));
|
||||
}
|
||||
if (p)
|
||||
return *p;
|
||||
}
|
||||
|
||||
ecode = ntdb_read_convert(ntdb, off, &ret, sizeof(ret));
|
||||
if (ecode != NTDB_SUCCESS) {
|
||||
return NTDB_ERR_TO_OFF(ecode);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* write a lump of data at a specified offset */
|
||||
static enum NTDB_ERROR ntdb_write(struct ntdb_context *ntdb, ntdb_off_t off,
|
||||
const void *buf, ntdb_len_t len)
|
||||
@ -359,27 +338,6 @@ enum NTDB_ERROR ntdb_read_convert(struct ntdb_context *ntdb, ntdb_off_t off,
|
||||
return ecode;
|
||||
}
|
||||
|
||||
enum NTDB_ERROR ntdb_write_off(struct ntdb_context *ntdb,
|
||||
ntdb_off_t off, ntdb_off_t val)
|
||||
{
|
||||
if (ntdb->flags & NTDB_RDONLY) {
|
||||
return ntdb_logerr(ntdb, NTDB_ERR_RDONLY, NTDB_LOG_USE_ERROR,
|
||||
"Write to read-only database");
|
||||
}
|
||||
|
||||
if (likely(!(ntdb->flags & NTDB_CONVERT))) {
|
||||
ntdb_off_t *p = ntdb->io->direct(ntdb, off, sizeof(*p), true);
|
||||
if (NTDB_PTR_IS_ERR(p)) {
|
||||
return NTDB_PTR_ERR(p);
|
||||
}
|
||||
if (p) {
|
||||
*p = val;
|
||||
return NTDB_SUCCESS;
|
||||
}
|
||||
}
|
||||
return ntdb_write_convert(ntdb, off, &val, sizeof(val));
|
||||
}
|
||||
|
||||
static void *_ntdb_alloc_read(struct ntdb_context *ntdb, ntdb_off_t offset,
|
||||
ntdb_len_t len, unsigned int prefix)
|
||||
{
|
||||
@ -607,6 +565,63 @@ static void *ntdb_direct(struct ntdb_context *ntdb, ntdb_off_t off, size_t len,
|
||||
return (char *)ntdb->file->map_ptr + off;
|
||||
}
|
||||
|
||||
static ntdb_off_t ntdb_read_normal_off(struct ntdb_context *ntdb,
|
||||
ntdb_off_t off)
|
||||
{
|
||||
ntdb_off_t ret;
|
||||
enum NTDB_ERROR ecode;
|
||||
ntdb_off_t *p;
|
||||
|
||||
p = ntdb_direct(ntdb, off, sizeof(*p), false);
|
||||
if (NTDB_PTR_IS_ERR(p)) {
|
||||
return NTDB_ERR_TO_OFF(NTDB_PTR_ERR(p));
|
||||
}
|
||||
if (likely(p)) {
|
||||
return *p;
|
||||
}
|
||||
|
||||
ecode = ntdb_read(ntdb, off, &ret, sizeof(ret));
|
||||
if (ecode != NTDB_SUCCESS) {
|
||||
return NTDB_ERR_TO_OFF(ecode);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static ntdb_off_t ntdb_read_convert_off(struct ntdb_context *ntdb,
|
||||
ntdb_off_t off)
|
||||
{
|
||||
ntdb_off_t ret;
|
||||
enum NTDB_ERROR ecode;
|
||||
|
||||
ecode = ntdb_read_convert(ntdb, off, &ret, sizeof(ret));
|
||||
if (ecode != NTDB_SUCCESS) {
|
||||
return NTDB_ERR_TO_OFF(ecode);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static enum NTDB_ERROR ntdb_write_normal_off(struct ntdb_context *ntdb,
|
||||
ntdb_off_t off, ntdb_off_t val)
|
||||
{
|
||||
ntdb_off_t *p;
|
||||
|
||||
p = ntdb_direct(ntdb, off, sizeof(*p), true);
|
||||
if (NTDB_PTR_IS_ERR(p)) {
|
||||
return NTDB_PTR_ERR(p);
|
||||
}
|
||||
if (likely(p)) {
|
||||
*p = val;
|
||||
return NTDB_SUCCESS;
|
||||
}
|
||||
return ntdb_write(ntdb, off, &val, sizeof(val));
|
||||
}
|
||||
|
||||
static enum NTDB_ERROR ntdb_write_convert_off(struct ntdb_context *ntdb,
|
||||
ntdb_off_t off, ntdb_off_t val)
|
||||
{
|
||||
return ntdb_write_convert(ntdb, off, &val, sizeof(val));
|
||||
}
|
||||
|
||||
void ntdb_inc_seqnum(struct ntdb_context *ntdb)
|
||||
{
|
||||
ntdb_off_t seq;
|
||||
@ -641,6 +656,18 @@ static const struct ntdb_methods io_methods = {
|
||||
ntdb_normal_oob,
|
||||
ntdb_expand_file,
|
||||
ntdb_direct,
|
||||
ntdb_read_normal_off,
|
||||
ntdb_write_normal_off,
|
||||
};
|
||||
|
||||
static const struct ntdb_methods io_convert_methods = {
|
||||
ntdb_read,
|
||||
ntdb_write,
|
||||
ntdb_normal_oob,
|
||||
ntdb_expand_file,
|
||||
ntdb_direct,
|
||||
ntdb_read_convert_off,
|
||||
ntdb_write_convert_off,
|
||||
};
|
||||
|
||||
/*
|
||||
@ -648,5 +675,8 @@ static const struct ntdb_methods io_methods = {
|
||||
*/
|
||||
void ntdb_io_init(struct ntdb_context *ntdb)
|
||||
{
|
||||
ntdb->io = &io_methods;
|
||||
if (ntdb->flags & NTDB_CONVERT)
|
||||
ntdb->io = &io_convert_methods;
|
||||
else
|
||||
ntdb->io = &io_methods;
|
||||
}
|
||||
|
@ -367,6 +367,9 @@ struct ntdb_methods {
|
||||
enum NTDB_ERROR (*oob)(struct ntdb_context *, ntdb_off_t, ntdb_len_t, bool);
|
||||
enum NTDB_ERROR (*expand_file)(struct ntdb_context *, ntdb_len_t);
|
||||
void *(*direct)(struct ntdb_context *, ntdb_off_t, size_t, bool);
|
||||
ntdb_off_t (*read_off)(struct ntdb_context *ntdb, ntdb_off_t off);
|
||||
enum NTDB_ERROR (*write_off)(struct ntdb_context *ntdb, ntdb_off_t off,
|
||||
ntdb_off_t val);
|
||||
};
|
||||
|
||||
/*
|
||||
@ -467,13 +470,6 @@ void ntdb_access_release(struct ntdb_context *ntdb, const void *p);
|
||||
/* Commit result of ntdb_acces_write. */
|
||||
enum NTDB_ERROR ntdb_access_commit(struct ntdb_context *ntdb, void *p);
|
||||
|
||||
/* Convenience routine to get an offset. */
|
||||
ntdb_off_t ntdb_read_off(struct ntdb_context *ntdb, ntdb_off_t off);
|
||||
|
||||
/* Write an offset at an offset. */
|
||||
enum NTDB_ERROR ntdb_write_off(struct ntdb_context *ntdb, ntdb_off_t off,
|
||||
ntdb_off_t val);
|
||||
|
||||
/* Clear an ondisk area. */
|
||||
enum NTDB_ERROR zero_out(struct ntdb_context *ntdb, ntdb_off_t off, ntdb_len_t len);
|
||||
|
||||
@ -642,6 +638,21 @@ static inline enum NTDB_ERROR ntdb_oob(struct ntdb_context *ntdb,
|
||||
return ntdb->io->oob(ntdb, off, len, probe);
|
||||
}
|
||||
|
||||
/* Convenience routine to get an offset. */
|
||||
static inline ntdb_off_t ntdb_read_off(struct ntdb_context *ntdb,
|
||||
ntdb_off_t off)
|
||||
{
|
||||
return ntdb->io->read_off(ntdb, off);
|
||||
}
|
||||
|
||||
/* Write an offset at an offset. */
|
||||
static inline enum NTDB_ERROR ntdb_write_off(struct ntdb_context *ntdb,
|
||||
ntdb_off_t off,
|
||||
ntdb_off_t val)
|
||||
{
|
||||
return ntdb->io->write_off(ntdb, off, val);
|
||||
}
|
||||
|
||||
#ifdef NTDB_TRACE
|
||||
void ntdb_trace(struct ntdb_context *ntdb, const char *op);
|
||||
void ntdb_trace_seqnum(struct ntdb_context *ntdb, uint32_t seqnum, const char *op);
|
||||
|
@ -393,12 +393,35 @@ static void *transaction_direct(struct ntdb_context *ntdb, ntdb_off_t off,
|
||||
return ntdb->transaction->io_methods->direct(ntdb, off, len, false);
|
||||
}
|
||||
|
||||
static ntdb_off_t transaction_read_off(struct ntdb_context *ntdb,
|
||||
ntdb_off_t off)
|
||||
{
|
||||
ntdb_off_t ret;
|
||||
enum NTDB_ERROR ecode;
|
||||
|
||||
ecode = transaction_read(ntdb, off, &ret, sizeof(ret));
|
||||
ntdb_convert(ntdb, &ret, sizeof(ret));
|
||||
if (ecode != NTDB_SUCCESS) {
|
||||
return NTDB_ERR_TO_OFF(ecode);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static enum NTDB_ERROR transaction_write_off(struct ntdb_context *ntdb,
|
||||
ntdb_off_t off, ntdb_off_t val)
|
||||
{
|
||||
ntdb_convert(ntdb, &val, sizeof(val));
|
||||
return transaction_write(ntdb, off, &val, sizeof(val));
|
||||
}
|
||||
|
||||
static const struct ntdb_methods transaction_methods = {
|
||||
transaction_read,
|
||||
transaction_write,
|
||||
transaction_oob,
|
||||
transaction_expand_file,
|
||||
transaction_direct,
|
||||
transaction_read_off,
|
||||
transaction_write_off,
|
||||
};
|
||||
|
||||
/*
|
||||
|
Loading…
x
Reference in New Issue
Block a user