Mercurial > hg > xemacs-beta
changeset 2775:05d62157e048
[xemacs-hg @ 2005-05-15 16:37:52 by crestani]
New allocator improvements
lisp/ChangeLog addition:
2005-05-15 Marcus Crestani <crestani@xemacs.org>
* diagnose.el: Lrecord and string data statistics.
* diagnose.el (show-memory-usage): Add output for additional
lrecord statistics (currently only string data).
* diagnose.el (show-lrecord-stats): New. Print detailed lrecord
statistics.
src/ChangeLog addition:
2005-05-15 Marcus Crestani <crestani@xemacs.org>
* alloc.c: Add string data statistics.
* alloc.c (dec_lrecord_stats): Use size of lrecord for statistics
and cons counter bookkeeping.
* alloc.c (finalize_string): Add string data statistics.
* alloc.c (make_uninit_string): Add string data statistics.
* alloc.c (make_string_nocopy): Add string data statistics.
* alloc.c (kkcc_marking): Move break out of #ifdef.
* alloc.c (Flrecord_stats): New. Collect lrecord statistics.
* alloc.c (Fgarbage_collect): Use Flrecord_stats.
* alloc.c (syms_of_alloc): Add Flrecord_stats.
* dumper.c: Fix hash table.
* dumper.c (pdump_make_hash): Fix hash table.
* dumper.c (pdump_get_mc_addr): Fix hash table.
* dumper.c (pdump_put_mc_addr): Fix hash table.
* dumper.c (pdump_reloc_one_mc): Fix indentation.
* dumper.c (pdump_load_finish): Add lrecord statistics
bookkeeping.
* lrecord.h: Add string data statistics.
* mc-alloc.c (remove_cell): Lrecord statistics, fix indentation.
* mule-charset.c: Marking through *_unicode_description not
needed.
* symbols.c (init_symbols_once_early): Bump lrecord statistics.
* window.c: Marking through line_start_cache not needed.
* xemacs.def.in.in: Fix typo.
author | crestani |
---|---|
date | Sun, 15 May 2005 16:38:14 +0000 |
parents | d72eefd1305a |
children | 05c69626659f |
files | lisp/ChangeLog lisp/diagnose.el src/ChangeLog src/alloc.c src/dumper.c src/lrecord.h src/mc-alloc.c src/mule-charset.c src/symbols.c src/window.c src/xemacs.def.in.in |
diffstat | 11 files changed, 239 insertions(+), 55 deletions(-) [+] |
line wrap: on
line diff
--- a/lisp/ChangeLog Sat May 14 21:50:55 2005 +0000 +++ b/lisp/ChangeLog Sun May 15 16:38:14 2005 +0000 @@ -1,3 +1,11 @@ +2005-05-15 Marcus Crestani <crestani@xemacs.org> + + * diagnose.el: Lrecord and string data statistics. + * diagnose.el (show-memory-usage): Add output for additional + lrecord statistics (currently only string data). + * diagnose.el (show-lrecord-stats): New. Print detailed lrecord + statistics. + 2005-05-10 Aidan Kehoe <kehoea@parhasard.net> * menubar-items.el (default-menubar):
--- a/lisp/diagnose.el Sat May 14 21:50:55 2005 +0000 +++ b/lisp/diagnose.el Sun May 15 16:38:14 2005 +0000 @@ -139,8 +139,9 @@ (princ (make-string 40 ?-)) (princ "\n") (map-plist #'(lambda (stat num) - (when (string-match "\\(.*\\)-storage$" - (symbol-name stat)) + (when (string-match + "\\(.*\\)-storage\\(-additional\\)?$" + (symbol-name stat)) (incf total num) (princ (format fmt (match-string 1 (symbol-name stat)) @@ -165,6 +166,83 @@ grandtotal)))) +(defun show-lrecord-stats () + "Show statistics about lrecord usage in XEmacs." + (interactive) + (garbage-collect) + (let ((buffer "*lrecord statistics*") + (plist (lrecord-stats)) + (fmt "%-30s%10s%10s\n") + (grandtotal 0) + begin) + (flet ((show-stats (match-string) + (princ (format fmt "object" "count" "storage")) + (princ (make-string 50 ?-)) + (princ "\n") + (let ((total-use 0) + (total-use-overhead 0) + (total-count 0)) + (map-plist + #'(lambda (stat num) + (when (string-match match-string + (symbol-name stat)) + (let ((storage-use num) + (storage-use-overhead + (plist-get + plist + (intern (concat (match-string 1 (symbol-name stat)) + "-storage-including-overhead")))) + (storage-count + (or (plist-get + plist + (intern + (concat (match-string 1 (symbol-name stat)) + "s-used"))) + (plist-get + plist + (intern + (concat (match-string 1 (symbol-name stat)) + "es-used"))) + (plist-get + plist + (intern + (concat (match-string 1 (symbol-name stat)) + "-used")))))) + (incf total-use storage-use) + (incf total-use-overhead (if storage-use-overhead + storage-use-overhead + storage-use)) + (incf total-count storage-count) + (princ (format fmt + (match-string 1 (symbol-name stat)) + storage-count storage-use))))) + plist) + (princ "\n") + (princ (format fmt "total" + total-count total-use-overhead)) + (incf grandtotal total-use-overhead) + (sort-numeric-fields -1 + (save-excursion + (goto-char begin) + (forward-line 2) + (point)) + (save-excursion + (forward-line -2) + (point)))))) + (with-output-to-temp-buffer buffer + (save-excursion + (set-buffer buffer) + (setq begin (point)) + (princ "Allocated with new allocator:\n") + (show-stats "\\(.*\\)-storage$") + (princ "\n\n") + (setq begin (point)) + (princ "Allocated additionally:\n") + (show-stats "\\(.*\\)-storage-additional$") + (princ (format "\n\ngrand total: %s\n" grandtotal))) + grandtotal)))) + + (defun show-mc-alloc-memory-usage () "Show statistics about memory usage of the new allocator." (interactive)
--- a/src/ChangeLog Sat May 14 21:50:55 2005 +0000 +++ b/src/ChangeLog Sun May 15 16:38:14 2005 +0000 @@ -1,3 +1,30 @@ +2005-05-15 Marcus Crestani <crestani@xemacs.org> + + * alloc.c: Add string data statistics. + * alloc.c (dec_lrecord_stats): Use size of lrecord for statistics + and cons counter bookkeeping. + * alloc.c (finalize_string): Add string data statistics. + * alloc.c (make_uninit_string): Add string data statistics. + * alloc.c (make_string_nocopy): Add string data statistics. + * alloc.c (kkcc_marking): Move break out of #ifdef. + * alloc.c (Flrecord_stats): New. Collect lrecord statistics. + * alloc.c (Fgarbage_collect): Use Flrecord_stats. + * alloc.c (syms_of_alloc): Add Flrecord_stats. + * dumper.c: Fix hash table. + * dumper.c (pdump_make_hash): Fix hash table. + * dumper.c (pdump_get_mc_addr): Fix hash table. + * dumper.c (pdump_put_mc_addr): Fix hash table. + * dumper.c (pdump_reloc_one_mc): Fix indentation. + * dumper.c (pdump_load_finish): Add lrecord statistics + bookkeeping. + * lrecord.h: Add string data statistics. + * mc-alloc.c (remove_cell): Lrecord statistics, fix indentation. + * mule-charset.c: Marking through *_unicode_description not + needed. + * symbols.c (init_symbols_once_early): Bump lrecord statistics. + * window.c: Marking through line_start_cache not needed. + * xemacs.def.in.in: Fix typo. + 2005-05-10 Aidan Kehoe <kehoea@parhasard.net> * extents.c: Clarify that the atomic extent property is a kludge
--- a/src/alloc.c Sat May 14 21:50:55 2005 +0000 +++ b/src/alloc.c Sun May 15 16:38:14 2005 +0000 @@ -519,10 +519,33 @@ } lrecord_stats [countof (lrecord_implementations_table) + MODULE_DEFINABLE_TYPE_COUNT]; +int lrecord_string_data_instances_in_use; +int lrecord_string_data_bytes_in_use; +int lrecord_string_data_bytes_in_use_including_overhead; + void init_lrecord_stats () { xzero (lrecord_stats); + lrecord_string_data_instances_in_use = 0; + lrecord_string_data_bytes_in_use = 0; + lrecord_string_data_bytes_in_use_including_overhead = 0; +} + +void +inc_lrecord_string_data_stats (Bytecount size) +{ + lrecord_string_data_instances_in_use++; + lrecord_string_data_bytes_in_use += size; + lrecord_string_data_bytes_in_use_including_overhead += size; +} + +void +dec_lrecord_string_data_stats (Bytecount size) +{ + lrecord_string_data_instances_in_use--; + lrecord_string_data_bytes_in_use -= size; + lrecord_string_data_bytes_in_use_including_overhead -= size; } void @@ -547,13 +570,14 @@ const struct lrecord_header *h) { int type_index = h->type; + int size = detagged_lisp_object_size (h); lrecord_stats[type_index].instances_in_use--; - lrecord_stats[type_index].bytes_in_use -= detagged_lisp_object_size (h); + lrecord_stats[type_index].bytes_in_use -= size; lrecord_stats[type_index].bytes_in_use_including_overhead -= size_including_overhead; - DECREMENT_CONS_COUNTER (lrecord_stats[type_index].bytes_in_use); + DECREMENT_CONS_COUNTER (size); } #endif /* not MC_ALLOC_TYPE_STATS */ @@ -2468,6 +2492,9 @@ { Lisp_String *s = (Lisp_String *) header; Bytecount size = s->size_; +#ifdef MC_ALLOC_TYPE_STATS + dec_lrecord_string_data_stats (size); +#endif /* MC_ALLOC_TYPE_STATS */ if (BIG_STRING_SIZE_P (size)) xfree (s->data_, Ibyte *); } @@ -2587,6 +2614,9 @@ #ifdef MC_ALLOC s = alloc_lrecord_type (Lisp_String, &lrecord_string); +#ifdef MC_ALLOC_TYPE_STATS + inc_lrecord_string_data_stats (length); +#endif /* MC_ALLOC_TYPE_STATS */ #else /* not MC_ALLOC */ /* Allocate the string header */ ALLOCATE_FIXED_TYPE (string, Lisp_String, s); @@ -2970,6 +3000,9 @@ #ifdef MC_ALLOC s = alloc_lrecord_type (Lisp_String, &lrecord_string); +#ifdef MC_ALLOC_TYPE_STATS + inc_lrecord_string_data_stats (length); +#endif /* MC_ALLOC_TYPE_STATS */ mcpro (wrap_pointer_1 (s)); /* otherwise nocopy_strings get collected and static data is tried to be freed. */ @@ -4113,8 +4146,8 @@ mark_object_maybe_checking_free (*stored_obj, (desc1->flags) & XD_FLAG_FREE_LISP_OBJECT, level, pos); +#endif /* not MC_ALLOC */ break; -#endif /* not MC_ALLOC */ } case XD_LISP_OBJECT_ARRAY: { @@ -5644,29 +5677,15 @@ arrays, or exceptions, or ...) */ return cons3 (intern (name), make_int (value), tail); } -#endif /* MC_ALLOC_TYPE_STATS */ - -DEFUN ("garbage-collect", Fgarbage_collect, 0, 0, "", /* -Reclaim storage for Lisp objects no longer needed. -Return info on amount of space in use: - ((USED-CONSES . STORAGE-CONSES) (USED-SYMS . STORAGE-SYMS) - (USED-MARKERS . STORAGE-MARKERS) USED-STRING-CHARS USED-VECTOR-SLOTS - PLIST) - where `PLIST' is a list of alternating keyword/value pairs providing - more detailed information. -Garbage collection happens automatically if you cons more than -`gc-cons-threshold' bytes of Lisp data since previous garbage collection. + +DEFUN("lrecord-stats", Flrecord_stats, 0, 0 ,"", /* +Return statistics about lrecords in a property list. */ ()) { -#ifdef MC_ALLOC_TYPE_STATS Lisp_Object pl = Qnil; int i; -#endif /* not MC_ALLOC_TYPE_STATS */ - - garbage_collect_1 (); - -#ifdef MC_ALLOC_TYPE_STATS + for (i = 0; i < (countof (lrecord_implementations_table) + MODULE_DEFINABLE_TYPE_COUNT); i++) { @@ -5698,14 +5717,40 @@ pl = gc_plist_hack (buf, lrecord_stats[i].instances_in_use, pl); } } - + pl = gc_plist_hack ("string-data-storage-including-overhead", + lrecord_string_data_bytes_in_use_including_overhead, pl); + pl = gc_plist_hack ("string-data-storage-additional", + lrecord_string_data_bytes_in_use, pl); + pl = gc_plist_hack ("string-data-used", + lrecord_string_data_instances_in_use, pl); + + return pl; +} +#endif /* not MC_ALLOC_TYPE_STATS */ + +DEFUN ("garbage-collect", Fgarbage_collect, 0, 0, "", /* +Reclaim storage for Lisp objects no longer needed. +Return info on amount of space in use: + ((USED-CONSES . STORAGE-CONSES) (USED-SYMS . STORAGE-SYMS) + (USED-MARKERS . STORAGE-MARKERS) USED-STRING-CHARS USED-VECTOR-SLOTS + PLIST) + where `PLIST' is a list of alternating keyword/value pairs providing + more detailed information. +Garbage collection happens automatically if you cons more than +`gc-cons-threshold' bytes of Lisp data since previous garbage collection. +*/ + ()) +{ + garbage_collect_1 (); + +#ifdef MC_ALLOC_TYPE_STATS /* The things we do for backwards-compatibility */ return list6 (Fcons (make_int (lrecord_stats[lrecord_type_cons].instances_in_use), make_int (lrecord_stats[lrecord_type_cons] .bytes_in_use_including_overhead)), - Fcons (make_int (lrecord_stats[lrecord_type_symbol].instances_in_use), + Fcons (make_int (lrecord_stats[lrecord_type_symbol].instances_in_use), make_int (lrecord_stats[lrecord_type_symbol] .bytes_in_use_including_overhead)), Fcons (make_int (lrecord_stats[lrecord_type_marker].instances_in_use), @@ -5715,7 +5760,7 @@ .bytes_in_use_including_overhead), make_int (lrecord_stats[lrecord_type_vector] .bytes_in_use_including_overhead), - pl); + Flrecord_stats ()); #else /* not MC_ALLOC_TYPE_STATS */ return Qnil; #endif /* not MC_ALLOC_TYPE_STATS */ @@ -6302,6 +6347,9 @@ DEFSUBR (Fmake_symbol); DEFSUBR (Fmake_marker); DEFSUBR (Fpurecopy); +#ifdef MC_ALLOC_TYPE_STATS + DEFSUBR (Flrecord_stats); +#endif /* MC_ALLOC_TYPE_STATS */ DEFSUBR (Fgarbage_collect); #if 0 DEFSUBR (Fmemory_limit);
--- a/src/dumper.c Sat May 14 21:50:55 2005 +0000 +++ b/src/dumper.c Sun May 15 16:38:14 2005 +0000 @@ -434,23 +434,29 @@ static void *pdump_buf; static FILE *pdump_out; -#if defined (MC_ALLOC) -/* With mc_alloc, way more entries are added to the hash tables: - increase hash table size to avoid collisions. */ -#define PDUMP_HASHSIZE 1000001 +#ifdef MC_ALLOC +/* PDUMP_HASHSIZE is a large prime. */ +#define PDUMP_HASHSIZE 1000003 +/* Nothing special about PDUMP_HASH_MULTIPLIER: arbitrary odd integer + smaller than PDUMP_HASHSIZE. */ +#define PDUMP_HASH_MULTIPLIER 12347 +/* Nothing special about PDUMP_HASH_STEP: arbitrary integer for linear + probing. */ +#define PDUMP_HASH_STEP 574853 #else /* not MC_ALLOC */ #define PDUMP_HASHSIZE 200001 #endif /* not MC_ALLOC */ static pdump_block_list_elt **pdump_hash; +#ifndef MC_ALLOC /* Since most pointers are eight bytes aligned, the >>3 allows for a better hash */ +#endif /* not MC_ALLOC */ static int pdump_make_hash (const void *obj) { -#if defined (MC_ALLOC) - /* Use >>2 for a better hash to avoid collisions. */ - return ((unsigned long)(obj)>>2) % PDUMP_HASHSIZE; +#ifdef MC_ALLOC + return ((unsigned long)(obj) * PDUMP_HASH_MULTIPLIER) % PDUMP_HASHSIZE; #else /* not MC_ALLOC */ return ((unsigned long)(obj)>>3) % PDUMP_HASHSIZE; #endif /* not MC_ALLOC */ @@ -542,9 +548,9 @@ if (mc_addr->obj == obj) return mc_addr->addr; - pos++; - if (pos == PDUMP_HASHSIZE) - pos = 0; + pos += PDUMP_HASH_STEP; + if (pos >= PDUMP_HASHSIZE) + pos -= PDUMP_HASHSIZE; } /* If this code is reached, an heap address occurred which has not @@ -573,9 +579,9 @@ if (mc_addr->obj == obj) return; - pos++; - if (pos == PDUMP_HASHSIZE) - pos = 0; + pos += PDUMP_HASH_STEP; + if (pos >= PDUMP_HASHSIZE) + pos -= PDUMP_HASHSIZE; } pdump_mc_hash[pos].obj = obj; @@ -1263,7 +1269,7 @@ if (POINTER_TYPE_P (XTYPE (*pobj)) && ! EQ (*pobj, Qnull_pointer)) *pobj = wrap_pointer_1 ((char *) pdump_get_mc_addr - (XPNTR (*pobj))); + (XPNTR (*pobj))); } break; } @@ -2155,11 +2161,21 @@ if (i == 0) { Bytecount real_size = size * elt_count; -#ifdef MC_ALLOC if (count == 2) - mc_addr = (Rawbyte *) mc_alloc (real_size); + { + mc_addr = (Rawbyte *) mc_alloc (real_size); +#ifdef MC_ALLOC_TYPE_STATS + inc_lrecord_stats (real_size, + (const struct lrecord_header *) + ((char *) rdata + delta)); + if (((const struct lrecord_header *) + ((char *) rdata + delta))->type + == lrecord_type_string) + inc_lrecord_string_data_stats + (((Lisp_String *) ((char *) rdata + delta))->size_); +#endif /* not MC_ALLOC_TYPE_STATS */ + } else -#endif /* not MC_ALLOC */ mc_addr = (Rawbyte *) xmalloc_and_zero (real_size); } else
--- a/src/lrecord.h Sat May 14 21:50:55 2005 +0000 +++ b/src/lrecord.h Sun May 15 16:38:14 2005 +0000 @@ -380,6 +380,8 @@ #ifdef MC_ALLOC_TYPE_STATS void init_lrecord_stats (void); +void inc_lrecord_string_data_stats (Bytecount size); +void dec_lrecord_string_data_stats (Bytecount size); void inc_lrecord_stats (Bytecount size, const struct lrecord_header *h); void dec_lrecord_stats (Bytecount size_including_overhead, const struct lrecord_header *h);
--- a/src/mc-alloc.c Sat May 14 21:50:55 2005 +0000 +++ b/src/mc-alloc.c Sun May 15 16:38:14 2005 +0000 @@ -1484,17 +1484,18 @@ else PLH_USED_SPACE (PH_PLH (ph)) -= PH_CELL_SIZE (ph); #endif -#ifdef ERROR_CHECK_GC - if (PH_ON_USED_LIST_P (ph)) { + if (PH_ON_USED_LIST_P (ph)) + { #ifdef MC_ALLOC_TYPE_STATS - dec_lrecord_stats (PH_CELL_SIZE (ph), - (const struct lrecord_header *) ptr); + dec_lrecord_stats (PH_CELL_SIZE (ph), + (const struct lrecord_header *) ptr); #endif /* MC_ALLOC_TYPE_STATS */ - assert (!LRECORD_FREE_P (ptr)); - deadbeef_memory (ptr, PH_CELL_SIZE (ph)); - MARK_LRECORD_AS_FREE (ptr); - } +#ifdef ERROR_CHECK_GC + assert (!LRECORD_FREE_P (ptr)); + deadbeef_memory (ptr, PH_CELL_SIZE (ph)); + MARK_LRECORD_AS_FREE (ptr); #endif + } /* hooks cell into free list */ NEXT_FREE (ptr) = PH_FREE_LIST (ph);
--- a/src/mule-charset.c Sat May 14 21:50:55 2005 +0000 +++ b/src/mule-charset.c Sun May 15 16:38:14 2005 +0000 @@ -173,9 +173,9 @@ { XD_LISP_OBJECT, offsetof (Lisp_Charset, reverse_direction_charset) }, { XD_LISP_OBJECT, offsetof (Lisp_Charset, ccl_program) }, { XD_UNION, offsetof (Lisp_Charset, to_unicode_table), - XD_INDIRECT (0, 0), { &to_unicode_description } }, + XD_INDIRECT (0, 0), { &to_unicode_description }, XD_FLAG_NO_KKCC }, { XD_UNION, offsetof (Lisp_Charset, from_unicode_table), - XD_INDIRECT (1, 0), { &from_unicode_description } }, + XD_INDIRECT (1, 0), { &from_unicode_description }, XD_FLAG_NO_KKCC }, { XD_END } };
--- a/src/symbols.c Sat May 14 21:50:55 2005 +0000 +++ b/src/symbols.c Sun May 15 16:38:14 2005 +0000 @@ -3331,6 +3331,10 @@ mcpro (wrap_pointer_1 (tem)); tem->value = 0; tem->type = SYMVAL_UNBOUND_MARKER; +#ifdef MC_ALLOC_TYPE_STATS + inc_lrecord_stats (sizeof (struct symbol_value_magic), + (const struct lrecord_header *) tem); +#endif /* not MC_ALLOC_TYPE_STATS */ #else /* not MC_ALLOC */ const struct symbol_value_magic *tem = &guts_of_unbound_marker; #endif /* not MC_ALLOC */
--- a/src/window.c Sat May 14 21:50:55 2005 +0000 +++ b/src/window.c Sun May 15 16:38:14 2005 +0000 @@ -246,7 +246,7 @@ { XD_BLOCK_PTR, offsetof (struct window, glyph_cachels), 1, { &glyph_cachel_dynarr_description } }, { XD_BLOCK_PTR, offsetof (struct window, line_start_cache), - 1, { &line_start_cache_dynarr_description } }, + 1, { &line_start_cache_dynarr_description }, XD_FLAG_NO_KKCC }, { XD_END } };
--- a/src/xemacs.def.in.in Sat May 14 21:50:55 2005 +0000 +++ b/src/xemacs.def.in.in Sun May 15 16:38:14 2005 +0000 @@ -16,7 +16,7 @@ #ifdef DEBUG_XEMACS mcpro_1 /* mcpro */ #endif -mc_allocate /* DEFSUBR */ +mc_alloc /* DEFSUBR */ #else /* not MC_ALLOC */ alloc_automanaged_lcrecord /* alloc_lcrecord_type */ #endif /* not MC_ALLOC */