s4-ldb: overallocate idxptr to reduce memory fragmentation
authorAndrew Tridgell <tridge@samba.org>
Wed, 23 Sep 2009 05:14:30 +0000 (22:14 -0700)
committerMatthias Dieter Wallnöfer <mwallnoefer@yahoo.de>
Fri, 2 Oct 2009 10:45:04 +0000 (12:45 +0200)
source4/lib/ldb/ldb_tdb/ldb_index.c

index 0b96e07a7d12589d9b9904326375e2cb231e66c1..1acbc204f7f13d44673c1bfc3d6349a4149dc7ef 100644 (file)
@@ -70,8 +70,10 @@ static int ltdb_idxptr_add(struct ldb_module *module, const struct ldb_message *
 {
        void *data = ldb_module_get_private(module);
        struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private);
+       /* we overallocate a bit to save on memory fragmentation */
+       unsigned alloc_length = ((ltdb->idxptr->num_dns+1) + 16) & ~15;
        ltdb->idxptr->dn_list = talloc_realloc(ltdb->idxptr, ltdb->idxptr->dn_list, 
-                                              struct TDB_DATA, ltdb->idxptr->num_dns+1);
+                                              struct TDB_DATA, alloc_length);
        if (ltdb->idxptr->dn_list == NULL) {
                ltdb->idxptr->num_dns = 0;
                return LDB_ERR_OPERATIONS_ERROR;