summaryrefslogtreecommitdiff
path: root/tools/gdbmshell.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2022-01-06 14:49:30 +0200
committerSergey Poznyakoff <gray@gnu.org>2022-01-06 15:36:10 +0200
commitb8c3d13fd821e90a190cc5cfad3a9e17f18aa416 (patch)
tree1beb84078d59d5800ade4de7972671c2b823b8b7 /tools/gdbmshell.c
parent42276af5bd0a48512a23f83db021b6e832c3fb92 (diff)
downloadgdbm-b8c3d13fd821e90a190cc5cfad3a9e17f18aa416.tar.gz
Speed up flushing the bucket cache on disk
The implementation of _gdbm_cache_flush becomes prohibitively inefficient during extensive updates of large databases. The bug was reported at https://github.com/Perl/perl5/issues/19306. To fix it, make sure that all changed cache entries are placed at the head of the cache_mru list, forming a contiguous sequence. This way a potentially long iteration over all cache entries can be cut off at the first entry with ca_changed == FALSE. This commit also gets rid of several superfluous fields in struct gdbm_file_info: - cache_entry Not needed, because the most recently used cache entry (cache_mru) is always the current one. - bucket_changed dbf->cache_mru->ca_changed reflects the status of the current bucket. - second_changed Not needed because _gdbm_cache_flush, which flushes all changed buckets, is now invoked unconditionally by _gdbm_end_update (and also whenever dbf->cache_mru changes). * src/gdbmdefs.h (struct gdbm_file_info): Remove cache_entry. The current cache entry is cache_mru. Remove bucket_changed, and second_changed. All uses changed. * src/proto.h (_gdbm_current_bucket_changed): New inline function. * src/bucket.c (_gdbm_cache_flush): Assume all changed elements form a contiguous sequence beginning with dbf->cache_mru. (set_cache_entry): Remove. All callers changed. (lru_link_elem,lru_unlink_elem): Update dbf->bucket as necessary. (cache_lookup): If the obtained bucket is not changed and is going to become current, flush all changed cache elements. * src/update.c (_gdbm_end_update): Call _gdbm_cache_flush unconditionally. * src/findkey.c: Use dbf->cache_mru instead of the removed dbf->cache_entry. * src/gdbmseq.c: Likewise. * tools/gdbmshell.c (_gdbm_print_bucket_cache): Likewise. * src/falloc.c: Use _gdbm_current_bucket_changed to mark the current bucket as changed. * src/gdbmstore.c: Likewise. * src/gdbmdelete.c: Likewise. Use _gdbm_current_bucket_changed. * tests/gtcacheopt.c: Fix typo. * tests/gtload.c: New option: -cachesize
Diffstat (limited to 'tools/gdbmshell.c')
-rw-r--r--tools/gdbmshell.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/tools/gdbmshell.c b/tools/gdbmshell.c
index 3a85211..22c4938 100644
--- a/tools/gdbmshell.c
+++ b/tools/gdbmshell.c
@@ -373,7 +373,7 @@ _gdbm_print_bucket_cache (FILE *fp, GDBM_FILE dbf)
fprintf (fp,
_("Bucket Cache (size %zu/%zu):\n Index: Address Changed Data_Hash \n"),
dbf->cache_num, dbf->cache_size);
- for (elem = dbf->cache_entry, i = 0; elem; elem = elem->ca_next, i++)
+ for (elem = dbf->cache_mru, i = 0; elem; elem = elem->ca_next, i++)
{
fprintf (fp, " %5d: %15lu %7s %x\n",
i,