[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
scratch/hash-table-perf e366ae38cd5 36/37: Improved hash-table allocatio
From: |
Mattias Engdegård |
Subject: |
scratch/hash-table-perf e366ae38cd5 36/37: Improved hash-table allocation accounting |
Date: |
Sun, 7 Jan 2024 12:41:24 -0500 (EST) |
branch: scratch/hash-table-perf
commit e366ae38cd56d94d7af0514dd23a313887c186b4
Author: Mattias Engdegård <mattiase@acm.org>
Commit: Mattias Engdegård <mattiase@acm.org>
Improved hash-table allocation accounting
Keep track of the combined size of hash-table ancillary arrays
for a more accurate measurement of live objects which is used to
inform the GC clock.
* src/alloc.c (gcstat): Add total_hash_table_bytes.
hash_table_allocated_bytes: New.
(cleanup_vector, hash_table_alloc_bytes, hash_table_free_bytes):
Update hash_table_allocated_bytes.
(sweep_vectors): Update gcstat.total_hash_table_bytes.
(total_bytes_of_live_objects): Use it.
---
src/alloc.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/src/alloc.c b/src/alloc.c
index ba4ef5c9fdc..b0dc08eb3f0 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -360,8 +360,16 @@ static struct gcstat
object_ct total_floats, total_free_floats;
object_ct total_intervals, total_free_intervals;
object_ct total_buffers;
+
+ /* Size of the ancillary arrays of live hash-table objects.
+ The objects themselves are not included (counted as vectors above). */
+ byte_ct total_hash_table_bytes;
} gcstat;
+/* Total size of ancillary arrays of all allocated hash-table objects,
+ both dead and alive. This number is always kept up-to-date. */
+static ptrdiff_t hash_table_allocated_bytes = 0;
+
/* Points to memory space allocated as "spare", to be freed if we run
out of memory. We keep one large block, four cons-blocks, and
two string blocks. */
@@ -3464,6 +3472,10 @@ cleanup_vector (struct Lisp_Vector *vector)
xfree (h->key_and_value);
xfree (h->next);
xfree (h->hash);
+ ptrdiff_t bytes = (h->table_size * (2 * sizeof *h->key_and_value
+ + sizeof *h->hash + sizeof *h->next)
+ + h->index_size * sizeof *h->index);
+ hash_table_allocated_bytes -= bytes;
}
/* Keep the switch exhaustive. */
case PVEC_NORMAL_VECTOR:
@@ -3588,6 +3600,8 @@ sweep_vectors (void)
lisp_free (lv);
}
}
+
+ gcstat.total_hash_table_bytes = hash_table_allocated_bytes;
}
/* Maximum number of elements in a vector. This is a macro so that it
@@ -5651,6 +5665,7 @@ hash_table_alloc_bytes (ptrdiff_t nbytes)
if (nbytes == 0)
return NULL;
tally_consing (nbytes);
+ hash_table_allocated_bytes += nbytes;
return xmalloc (nbytes);
}
@@ -5659,6 +5674,7 @@ void
hash_table_free_bytes (void *p, ptrdiff_t nbytes)
{
tally_consing (-nbytes);
+ hash_table_allocated_bytes -= nbytes;
xfree (p);
}
@@ -6152,6 +6168,7 @@ total_bytes_of_live_objects (void)
tot += object_bytes (gcstat.total_floats, sizeof (struct Lisp_Float));
tot += object_bytes (gcstat.total_intervals, sizeof (struct interval));
tot += object_bytes (gcstat.total_strings, sizeof (struct Lisp_String));
+ tot += gcstat.total_hash_table_bytes;
return tot;
}
- scratch/hash-table-perf ad3d2f8ed88 25/37: Share hash table test structs, (continued)
- scratch/hash-table-perf ad3d2f8ed88 25/37: Share hash table test structs, Mattias Engdegård, 2024/01/07
- scratch/hash-table-perf e53398ab698 26/37: ; Reorder structs (hash and test), Mattias Engdegård, 2024/01/07
- scratch/hash-table-perf 1672d880e0c 29/37: Change hash_idx_t to int32_t on all platforms, Mattias Engdegård, 2024/01/07
- scratch/hash-table-perf e6defe82569 27/37: Change default hash table size to 8 (from 65), Mattias Engdegård, 2024/01/07
- scratch/hash-table-perf 41e37c978e6 28/37: Rework index size and resize factor computations, Mattias Engdegård, 2024/01/07
- scratch/hash-table-perf 5cf627d70e1 30/37: Don't dump Qunbound, Mattias Engdegård, 2024/01/07
- scratch/hash-table-perf 8b1b140bed9 32/37: * src/lisp.h (hash_hash_t): Change to uint32_t., Mattias Engdegård, 2024/01/07
- scratch/hash-table-perf 830838eb5f3 31/37: Use KEY=Qunbound instead of HASH=hash_unused for unused entries, Mattias Engdegård, 2024/01/07
- scratch/hash-table-perf 05297736aa6 33/37: Adapt hash functions to produce a hash_hash_t eventually, Mattias Engdegård, 2024/01/07
- scratch/hash-table-perf 8cd35079f4c 34/37: Don't pretend that hash-table-size is useful, Mattias Engdegård, 2024/01/07
- scratch/hash-table-perf e366ae38cd5 36/37: Improved hash-table allocation accounting,
Mattias Engdegård <=
- scratch/hash-table-perf b9c9539db96 37/37: Change hash range reduction from remainder to multiplication, Mattias Engdegård, 2024/01/07
- scratch/hash-table-perf 681a2877cc2 35/37: Hash-table documentation updates, Mattias Engdegård, 2024/01/07