aboutsummaryrefslogtreecommitdiffstats
path: root/src/alloc.c
diff options
context:
space:
mode:
authorDmitry Antipov2012-07-17 09:01:33 +0400
committerDmitry Antipov2012-07-17 09:01:33 +0400
commit7098646f5d49eabca79baf013b58911e65bf6d99 (patch)
treeb1b2f25063a6cd051972a37a2c92468238d20256 /src/alloc.c
parent22657b40985ec990ea20df878bde97af76b19ed1 (diff)
downloademacs-7098646f5d49eabca79baf013b58911e65bf6d99.tar.gz
emacs-7098646f5d49eabca79baf013b58911e65bf6d99.zip
Simple free memory accounting feature.
* alloc.c (bytes_free, total_free_vector_bytes): New variable. (sweep_vectors): Accumulate size of free vectors. (Fgarbage_collect): Setup bytes_free. (Fmemory_free): New function. (syms_of_alloc): Register it.
Diffstat (limited to 'src/alloc.c')
-rw-r--r--src/alloc.c45
1 files changed, 43 insertions, 2 deletions
diff --git a/src/alloc.c b/src/alloc.c
index 39c360a67e7..fd5111412f7 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -84,6 +84,10 @@ extern void *sbrk ();
84 84
85#define MMAP_MAX_AREAS 100000000 85#define MMAP_MAX_AREAS 100000000
86 86
87/* Value of mallinfo ().fordblks as seen at the end of last GC. */
88
89static int bytes_free;
90
87#else /* not DOUG_LEA_MALLOC */ 91#else /* not DOUG_LEA_MALLOC */
88 92
89/* The following come from gmalloc.c. */ 93/* The following come from gmalloc.c. */
@@ -191,7 +195,7 @@ int abort_on_gc;
191 195
192static EMACS_INT total_conses, total_markers, total_symbols, total_vector_size; 196static EMACS_INT total_conses, total_markers, total_symbols, total_vector_size;
193static EMACS_INT total_free_conses, total_free_markers, total_free_symbols; 197static EMACS_INT total_free_conses, total_free_markers, total_free_symbols;
194static EMACS_INT total_free_floats, total_floats; 198static EMACS_INT total_free_floats, total_floats, total_free_vector_bytes;
195 199
196/* Points to memory space allocated as "spare", to be freed if we run 200/* Points to memory space allocated as "spare", to be freed if we run
197 out of memory. We keep one large block, four cons-blocks, and 201 out of memory. We keep one large block, four cons-blocks, and
@@ -3048,7 +3052,7 @@ sweep_vectors (void)
3048 struct vector_block *block = vector_blocks, **bprev = &vector_blocks; 3052 struct vector_block *block = vector_blocks, **bprev = &vector_blocks;
3049 struct Lisp_Vector *vector, *next, **vprev = &large_vectors; 3053 struct Lisp_Vector *vector, *next, **vprev = &large_vectors;
3050 3054
3051 total_vector_size = 0; 3055 total_free_vector_bytes = total_vector_size = 0;
3052 memset (vector_free_lists, 0, sizeof (vector_free_lists)); 3056 memset (vector_free_lists, 0, sizeof (vector_free_lists));
3053 3057
3054 /* Looking through vector blocks. */ 3058 /* Looking through vector blocks. */
@@ -3095,6 +3099,7 @@ sweep_vectors (void)
3095 else 3099 else
3096 { 3100 {
3097 int tmp; 3101 int tmp;
3102 total_free_vector_bytes += total_bytes;
3098 SETUP_ON_FREE_LIST (vector, total_bytes, tmp); 3103 SETUP_ON_FREE_LIST (vector, total_bytes, tmp);
3099 } 3104 }
3100 } 3105 }
@@ -5605,6 +5610,10 @@ See Info node `(elisp)Garbage Collection'. */)
5605 total[7] = Fcons (make_number (total_strings), 5610 total[7] = Fcons (make_number (total_strings),
5606 make_number (total_free_strings)); 5611 make_number (total_free_strings));
5607 5612
5613#ifdef DOUG_LEA_MALLOC
5614 bytes_free = mallinfo ().fordblks;
5615#endif
5616
5608#if GC_MARK_STACK == GC_USE_GCPROS_CHECK_ZOMBIES 5617#if GC_MARK_STACK == GC_USE_GCPROS_CHECK_ZOMBIES
5609 { 5618 {
5610 /* Compute average percentage of zombies. */ 5619 /* Compute average percentage of zombies. */
@@ -6549,6 +6558,37 @@ We divide the value by 1024 to make sure it fits in a Lisp integer. */)
6549 return end; 6558 return end;
6550} 6559}
6551 6560
6561DEFUN ("memory-free", Fmemory_free, Smemory_free, 0, 0, 0,
6562 doc: /* Return a list of two counters that measure how much free memory
6563is hold by the Emacs process. Both counters are in KBytes. First
6564counter shows how much memory holds in a free lists maintained by
6565the Emacs itself. Second counter shows how much free memory is in
6566the heap (freed by Emacs but not released back to the operating
6567system). If the second counter is zero, heap statistics is not
6568available. Since both counters are updated after each garbage
6569collection, use (progn (garbage-collect) (memory-free)) to get
6570accurate numbers. */)
6571 (void)
6572{
6573 Lisp_Object data[2];
6574
6575 data[0] = make_number
6576 (min (MOST_POSITIVE_FIXNUM,
6577 (total_free_conses * sizeof (struct Lisp_Cons)
6578 + total_free_markers * sizeof (union Lisp_Misc)
6579 + total_free_symbols * sizeof (struct Lisp_Symbol)
6580 + total_free_floats * sizeof (struct Lisp_Float)
6581 + total_free_intervals * sizeof (struct interval)
6582 + total_free_strings * sizeof (struct Lisp_String)
6583 + total_free_vector_bytes) / 1024));
6584#ifdef DOUG_LEA_MALLOC
6585 data[1] = make_number (min (MOST_POSITIVE_FIXNUM, bytes_free / 1024));
6586#else
6587 data[1] = make_number (0);
6588#endif
6589 return Flist (2, data);
6590}
6591
6552DEFUN ("memory-use-counts", Fmemory_use_counts, Smemory_use_counts, 0, 0, 0, 6592DEFUN ("memory-use-counts", Fmemory_use_counts, Smemory_use_counts, 0, 0, 0,
6553 doc: /* Return a list of counters that measure how much consing there has been. 6593 doc: /* Return a list of counters that measure how much consing there has been.
6554Each of these counters increments for a certain kind of object. 6594Each of these counters increments for a certain kind of object.
@@ -6785,6 +6825,7 @@ The time is in seconds as a floating point value. */);
6785 defsubr (&Spurecopy); 6825 defsubr (&Spurecopy);
6786 defsubr (&Sgarbage_collect); 6826 defsubr (&Sgarbage_collect);
6787 defsubr (&Smemory_limit); 6827 defsubr (&Smemory_limit);
6828 defsubr (&Smemory_free);
6788 defsubr (&Smemory_use_counts); 6829 defsubr (&Smemory_use_counts);
6789 6830
6790#if GC_MARK_STACK == GC_USE_GCPROS_CHECK_ZOMBIES 6831#if GC_MARK_STACK == GC_USE_GCPROS_CHECK_ZOMBIES