From ccce1aa254cb9c7a2796e3171c7146703ab7ae40 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 30 Jul 2009 08:50:38 +0930 Subject: [PATCH] Import from SAMBA tdb: commit a6cc04a20089e8fbcce138c271961c37ddcd6c34 Author: Andrew Tridgell Date: Mon Jun 1 13:13:07 2009 +1000 overallocate all records by 25% This greatly reduces the fragmentation of databases where records tend to grow slowly by a small amount each time. The case where this is most seen is the ldb index records. Adding this overallocation reduced the size of the resulting database by more than 20x when running a test that adds 10k users. --- ccan/tdb/freelist.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ccan/tdb/freelist.c b/ccan/tdb/freelist.c index 2f2a4c37..3bc39651 100644 --- a/ccan/tdb/freelist.c +++ b/ccan/tdb/freelist.c @@ -284,6 +284,9 @@ tdb_off_t tdb_allocate(struct tdb_context *tdb, tdb_len_t length, struct list_st if (tdb_lock(tdb, -1, F_WRLCK) == -1) return 0; + /* over-allocate to reduce fragmentation */ + length *= 1.25; + /* Extra bytes required for tailer */ length += sizeof(tdb_off_t); length = TDB_ALIGN(length, TDB_ALIGNMENT); -- 2.39.2