ntdb: inline oob check
authorRusty Russell <rusty@rustcorp.com.au>
Tue, 19 Jun 2012 03:12:12 +0000 (12:42 +0930)
committerRusty Russell <rusty@rustcorp.com.au>
Tue, 19 Jun 2012 03:38:07 +0000 (05:38 +0200)
The simple "is it in range" check can be inline; complex cases can be
handed through to the normal or transaction handler.

NTDB speed:
Adding 10000 records: 4111-9983(9149) ns (815528 bytes)
Finding 10000 records: 1667-4464(3810) ns (815528 bytes)
Missing 10000 records: 1511-3992(3546) ns (815528 bytes)
Traversing 10000 records: 1698-4254(3724) ns (815528 bytes)
Deleting 10000 records: 3608-7998(7358) ns (815528 bytes)
Re-adding 10000 records: 3259-8504(7805) ns (815528 bytes)
Appending 10000 records: 5393-13579(12356) ns (1274312 bytes)
Churning 10000 records: 6966-17813(16136) ns (1274312 bytes)
NTDB speed in transaction:
Adding 10000 records: 916-2230(2004) ns (815528 bytes)
Finding 10000 records: 330-866(770) ns (815528 bytes)
Missing 10000 records: 196-520(471) ns (815528 bytes)
Traversing 10000 records: 356-879(800) ns (815528 bytes)
Deleting 10000 records: 505-1267(1108) ns (815528 bytes)
Re-adding 10000 records: 658-1681(1477) ns (815528 bytes)
Appending 10000 records: 1088-2827(2498) ns (1274312 bytes)
Churning 10000 records: 1636-4267(3785) ns (1274312 bytes)
smbtorture results:
ntdb speed 85588-189430(157110) ops/sec

lib/ntdb/check.c
lib/ntdb/free.c
lib/ntdb/io.c
lib/ntdb/open.c
lib/ntdb/private.h
lib/ntdb/transaction.c

index 723e7b11bf0d66bf2f78794c3f46b33778994276..be27003a510d87bfa9802b7e5342883bc66597f8 100644 (file)
@@ -505,10 +505,9 @@ static enum NTDB_ERROR check_free(struct ntdb_context *ntdb,
 
        }
 
-       ecode = ntdb->io->oob(ntdb, off,
-                            frec_len(frec)
-                            + sizeof(struct ntdb_used_record),
-                            false);
+       ecode = ntdb_oob(ntdb, off,
+                        frec_len(frec) + sizeof(struct ntdb_used_record),
+                        false);
        if (ecode != NTDB_SUCCESS) {
                return ecode;
        }
index f51aa5bc331bfc9bcd9ce45ee789ea9b56fdb517..3e31937382ba70ab1195da4bef9096bebf0789dd 100644 (file)
@@ -932,7 +932,7 @@ static enum NTDB_ERROR ntdb_expand(struct ntdb_context *ntdb, ntdb_len_t size)
 
        /* Someone else may have expanded the file, so retry. */
        old_size = ntdb->file->map_size;
-       ntdb->io->oob(ntdb, ntdb->file->map_size, 1, true);
+       ntdb_oob(ntdb, ntdb->file->map_size, 1, true);
        if (ntdb->file->map_size != old_size) {
                ntdb_unlock_expand(ntdb, F_WRLCK);
                return NTDB_SUCCESS;
index b20141cc8fc677de7a176efcf47652aab190c4e4..138a405dda3ff5679dfb70cbc36937c0f53b75f1 100644 (file)
@@ -92,8 +92,9 @@ enum NTDB_ERROR ntdb_mmap(struct ntdb_context *ntdb)
 
    If probe is true, len being too large isn't a failure.
 */
-static enum NTDB_ERROR ntdb_oob(struct ntdb_context *ntdb,
-                             ntdb_off_t off, ntdb_len_t len, bool probe)
+static enum NTDB_ERROR ntdb_normal_oob(struct ntdb_context *ntdb,
+                                      ntdb_off_t off, ntdb_len_t len,
+                                      bool probe)
 {
        struct stat st;
        enum NTDB_ERROR ecode;
@@ -112,8 +113,6 @@ static enum NTDB_ERROR ntdb_oob(struct ntdb_context *ntdb,
                                  (long long)off, (long long)len);
        }
 
-       if (len + off <= ntdb->file->map_size)
-               return NTDB_SUCCESS;
        if (ntdb->flags & NTDB_INTERNAL) {
                if (probe)
                        return NTDB_SUCCESS;
@@ -271,7 +270,7 @@ static enum NTDB_ERROR ntdb_write(struct ntdb_context *ntdb, ntdb_off_t off,
                                  "Write to read-only database");
        }
 
-       ecode = ntdb->io->oob(ntdb, off, len, false);
+       ecode = ntdb_oob(ntdb, off, len, false);
        if (ecode != NTDB_SUCCESS) {
                return ecode;
        }
@@ -305,7 +304,7 @@ static enum NTDB_ERROR ntdb_read(struct ntdb_context *ntdb, ntdb_off_t off,
 {
        enum NTDB_ERROR ecode;
 
-       ecode = ntdb->io->oob(ntdb, off, len, false);
+       ecode = ntdb_oob(ntdb, off, len, false);
        if (ecode != NTDB_SUCCESS) {
                return ecode;
        }
@@ -639,7 +638,7 @@ void ntdb_inc_seqnum(struct ntdb_context *ntdb)
 static const struct ntdb_methods io_methods = {
        ntdb_read,
        ntdb_write,
-       ntdb_oob,
+       ntdb_normal_oob,
        ntdb_expand_file,
        ntdb_direct,
 };
index dc473d26804dc66f7e88d49fe5887956c9b2392e..6aac46ab2f53c2b68824e515d7425ffc94c73754 100644 (file)
@@ -718,7 +718,7 @@ _PUBLIC_ struct ntdb_context *ntdb_open(const char *name, int ntdb_flags,
        ntdb_unlock_open(ntdb, openlock);
 
        /* This makes sure we have current map_size and mmap. */
-       ecode = ntdb->io->oob(ntdb, ntdb->file->map_size, 1, true);
+       ecode = ntdb_oob(ntdb, ntdb->file->map_size, 1, true);
        if (unlikely(ecode != NTDB_SUCCESS))
                goto fail;
 
index ee8eeb76aff4247d048a3e0e39a46c17d7e446a0..f46b5ef9069feba8c3241dfed2935e95d5ad31d3 100644 (file)
@@ -630,6 +630,18 @@ enum NTDB_ERROR COLD PRINTF_FMT(4, 5)
                    enum ntdb_log_level level,
                    const char *fmt, ...);
 
+static inline enum NTDB_ERROR ntdb_oob(struct ntdb_context *ntdb,
+                                      ntdb_off_t off, ntdb_len_t len,
+                                      bool probe)
+{
+       if (likely(off + len >= off)
+           && likely(off + len <= ntdb->file->map_size)
+           && likely(!probe)) {
+                   return NTDB_SUCCESS;
+       }
+       return ntdb->io->oob(ntdb, off, len, probe);
+}
+
 #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);
index 11dd7b4af5c1790dbee2e81bca67d34e50e1bb8a..a265252174b155f7123628f209b53d94f56a7494 100644 (file)
@@ -568,7 +568,7 @@ _PUBLIC_ enum NTDB_ERROR ntdb_transaction_start(struct ntdb_context *ntdb)
 
        /* make sure we know about any file expansions already done by
           anyone else */
-       ntdb->io->oob(ntdb, ntdb->file->map_size, 1, true);
+       ntdb_oob(ntdb, ntdb->file->map_size, 1, true);
        ntdb->transaction->old_map_size = ntdb->file->map_size;
 
        /* finally hook the io methods, replacing them with