emacs-diffs
[Top][All Lists]
Advanced

[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;
 }
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]