aboutsummaryrefslogtreecommitdiffstats
path: root/src/alloc.c
diff options
context:
space:
mode:
authorDmitry Antipov2012-07-17 11:15:50 +0400
committerDmitry Antipov2012-07-17 11:15:50 +0400
commit3900d5de1b3cbb4171db39b5a187b623a7393087 (patch)
treee4a0248b890abb30fb08ef724cf5a73b2e914520 /src/alloc.c
parent7098646f5d49eabca79baf013b58911e65bf6d99 (diff)
downloademacs-3900d5de1b3cbb4171db39b5a187b623a7393087.tar.gz
emacs-3900d5de1b3cbb4171db39b5a187b623a7393087.zip
Fix previous change to make Fmemory_free always accurate.
* alloc.c (make_interval): Update total_free_intervals. (make_float): Likewise for total_free_floats. (free_cons, Fcons): Likewise for total_free_conses. (SETUP_ON_FREE_LIST, allocate_vector_from_block): Likewise for total_free_vector_bytes. (Fmake_symbol): Likewise for total_free_symbols. (bytes_free): Remove.
Diffstat (limited to 'src/alloc.c')
-rw-r--r--src/alloc.c28
1 files changed, 15 insertions, 13 deletions
diff --git a/src/alloc.c b/src/alloc.c
index fd5111412f7..6cbd63f716c 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -84,10 +84,6 @@ 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
91#else /* not DOUG_LEA_MALLOC */ 87#else /* not DOUG_LEA_MALLOC */
92 88
93/* The following come from gmalloc.c. */ 89/* The following come from gmalloc.c. */
@@ -1516,6 +1512,7 @@ make_interval (void)
1516 newi->next = interval_block; 1512 newi->next = interval_block;
1517 interval_block = newi; 1513 interval_block = newi;
1518 interval_block_index = 0; 1514 interval_block_index = 0;
1515 total_free_intervals += INTERVAL_BLOCK_SIZE;
1519 } 1516 }
1520 val = &interval_block->intervals[interval_block_index++]; 1517 val = &interval_block->intervals[interval_block_index++];
1521 } 1518 }
@@ -1524,6 +1521,7 @@ make_interval (void)
1524 1521
1525 consing_since_gc += sizeof (struct interval); 1522 consing_since_gc += sizeof (struct interval);
1526 intervals_consed++; 1523 intervals_consed++;
1524 total_free_intervals--;
1527 RESET_INTERVAL (val); 1525 RESET_INTERVAL (val);
1528 val->gcmarkbit = 0; 1526 val->gcmarkbit = 0;
1529 return val; 1527 return val;
@@ -2607,6 +2605,7 @@ make_float (double float_value)
2607 memset (new->gcmarkbits, 0, sizeof new->gcmarkbits); 2605 memset (new->gcmarkbits, 0, sizeof new->gcmarkbits);
2608 float_block = new; 2606 float_block = new;
2609 float_block_index = 0; 2607 float_block_index = 0;
2608 total_free_floats += FLOAT_BLOCK_SIZE;
2610 } 2609 }
2611 XSETFLOAT (val, &float_block->floats[float_block_index]); 2610 XSETFLOAT (val, &float_block->floats[float_block_index]);
2612 float_block_index++; 2611 float_block_index++;
@@ -2618,6 +2617,7 @@ make_float (double float_value)
2618 eassert (!FLOAT_MARKED_P (XFLOAT (val))); 2617 eassert (!FLOAT_MARKED_P (XFLOAT (val)));
2619 consing_since_gc += sizeof (struct Lisp_Float); 2618 consing_since_gc += sizeof (struct Lisp_Float);
2620 floats_consed++; 2619 floats_consed++;
2620 total_free_floats--;
2621 return val; 2621 return val;
2622} 2622}
2623 2623
@@ -2683,6 +2683,7 @@ free_cons (struct Lisp_Cons *ptr)
2683 ptr->car = Vdead; 2683 ptr->car = Vdead;
2684#endif 2684#endif
2685 cons_free_list = ptr; 2685 cons_free_list = ptr;
2686 total_free_conses++;
2686} 2687}
2687 2688
2688DEFUN ("cons", Fcons, Scons, 2, 2, 0, 2689DEFUN ("cons", Fcons, Scons, 2, 2, 0,
@@ -2712,6 +2713,7 @@ DEFUN ("cons", Fcons, Scons, 2, 2, 0,
2712 new->next = cons_block; 2713 new->next = cons_block;
2713 cons_block = new; 2714 cons_block = new;
2714 cons_block_index = 0; 2715 cons_block_index = 0;
2716 total_free_conses += CONS_BLOCK_SIZE;
2715 } 2717 }
2716 XSETCONS (val, &cons_block->conses[cons_block_index]); 2718 XSETCONS (val, &cons_block->conses[cons_block_index]);
2717 cons_block_index++; 2719 cons_block_index++;
@@ -2723,6 +2725,7 @@ DEFUN ("cons", Fcons, Scons, 2, 2, 0,
2723 XSETCDR (val, cdr); 2725 XSETCDR (val, cdr);
2724 eassert (!CONS_MARKED_P (XCONS (val))); 2726 eassert (!CONS_MARKED_P (XCONS (val)));
2725 consing_since_gc += sizeof (struct Lisp_Cons); 2727 consing_since_gc += sizeof (struct Lisp_Cons);
2728 total_free_conses--;
2726 cons_cells_consed++; 2729 cons_cells_consed++;
2727 return val; 2730 return val;
2728} 2731}
@@ -2909,6 +2912,7 @@ verify (VECTOR_BLOCK_SIZE <= (1 << PSEUDOVECTOR_SIZE_BITS));
2909 eassert ((index) < VECTOR_MAX_FREE_LIST_INDEX); \ 2912 eassert ((index) < VECTOR_MAX_FREE_LIST_INDEX); \
2910 (v)->header.next.vector = vector_free_lists[index]; \ 2913 (v)->header.next.vector = vector_free_lists[index]; \
2911 vector_free_lists[index] = (v); \ 2914 vector_free_lists[index] = (v); \
2915 total_free_vector_bytes += (nbytes); \
2912 } while (0) 2916 } while (0)
2913 2917
2914struct vector_block 2918struct vector_block
@@ -2979,6 +2983,7 @@ allocate_vector_from_block (size_t nbytes)
2979 vector = vector_free_lists[index]; 2983 vector = vector_free_lists[index];
2980 vector_free_lists[index] = vector->header.next.vector; 2984 vector_free_lists[index] = vector->header.next.vector;
2981 vector->header.next.nbytes = nbytes; 2985 vector->header.next.nbytes = nbytes;
2986 total_free_vector_bytes -= nbytes;
2982 return vector; 2987 return vector;
2983 } 2988 }
2984 2989
@@ -2993,6 +2998,7 @@ allocate_vector_from_block (size_t nbytes)
2993 vector = vector_free_lists[index]; 2998 vector = vector_free_lists[index];
2994 vector_free_lists[index] = vector->header.next.vector; 2999 vector_free_lists[index] = vector->header.next.vector;
2995 vector->header.next.nbytes = nbytes; 3000 vector->header.next.nbytes = nbytes;
3001 total_free_vector_bytes -= nbytes;
2996 3002
2997 /* Excess bytes are used for the smaller vector, 3003 /* Excess bytes are used for the smaller vector,
2998 which should be set on an appropriate free list. */ 3004 which should be set on an appropriate free list. */
@@ -3099,7 +3105,6 @@ sweep_vectors (void)
3099 else 3105 else
3100 { 3106 {
3101 int tmp; 3107 int tmp;
3102 total_free_vector_bytes += total_bytes;
3103 SETUP_ON_FREE_LIST (vector, total_bytes, tmp); 3108 SETUP_ON_FREE_LIST (vector, total_bytes, tmp);
3104 } 3109 }
3105 } 3110 }
@@ -3447,6 +3452,7 @@ Its value and function definition are void, and its property list is nil. */)
3447 new->next = symbol_block; 3452 new->next = symbol_block;
3448 symbol_block = new; 3453 symbol_block = new;
3449 symbol_block_index = 0; 3454 symbol_block_index = 0;
3455 total_free_symbols += SYMBOL_BLOCK_SIZE;
3450 } 3456 }
3451 XSETSYMBOL (val, &symbol_block->symbols[symbol_block_index].s); 3457 XSETSYMBOL (val, &symbol_block->symbols[symbol_block_index].s);
3452 symbol_block_index++; 3458 symbol_block_index++;
@@ -3467,6 +3473,7 @@ Its value and function definition are void, and its property list is nil. */)
3467 p->declared_special = 0; 3473 p->declared_special = 0;
3468 consing_since_gc += sizeof (struct Lisp_Symbol); 3474 consing_since_gc += sizeof (struct Lisp_Symbol);
3469 symbols_consed++; 3475 symbols_consed++;
3476 total_free_symbols--;
3470 return val; 3477 return val;
3471} 3478}
3472 3479
@@ -5610,10 +5617,6 @@ See Info node `(elisp)Garbage Collection'. */)
5610 total[7] = Fcons (make_number (total_strings), 5617 total[7] = Fcons (make_number (total_strings),
5611 make_number (total_free_strings)); 5618 make_number (total_free_strings));
5612 5619
5613#ifdef DOUG_LEA_MALLOC
5614 bytes_free = mallinfo ().fordblks;
5615#endif
5616
5617#if GC_MARK_STACK == GC_USE_GCPROS_CHECK_ZOMBIES 5620#if GC_MARK_STACK == GC_USE_GCPROS_CHECK_ZOMBIES
5618 { 5621 {
5619 /* Compute average percentage of zombies. */ 5622 /* Compute average percentage of zombies. */
@@ -6565,9 +6568,7 @@ counter shows how much memory holds in a free lists maintained by
6565the Emacs itself. Second counter shows how much free memory is in 6568the Emacs itself. Second counter shows how much free memory is in
6566the heap (freed by Emacs but not released back to the operating 6569the heap (freed by Emacs but not released back to the operating
6567system). If the second counter is zero, heap statistics is not 6570system). If the second counter is zero, heap statistics is not
6568available. Since both counters are updated after each garbage 6571available. */)
6569collection, use (progn (garbage-collect) (memory-free)) to get
6570accurate numbers. */)
6571 (void) 6572 (void)
6572{ 6573{
6573 Lisp_Object data[2]; 6574 Lisp_Object data[2];
@@ -6582,7 +6583,8 @@ accurate numbers. */)
6582 + total_free_strings * sizeof (struct Lisp_String) 6583 + total_free_strings * sizeof (struct Lisp_String)
6583 + total_free_vector_bytes) / 1024)); 6584 + total_free_vector_bytes) / 1024));
6584#ifdef DOUG_LEA_MALLOC 6585#ifdef DOUG_LEA_MALLOC
6585 data[1] = make_number (min (MOST_POSITIVE_FIXNUM, bytes_free / 1024)); 6586 data[1] = make_number
6587 (min (MOST_POSITIVE_FIXNUM, mallinfo ().fordblks / 1024));
6586#else 6588#else
6587 data[1] = make_number (0); 6589 data[1] = make_number (0);
6588#endif 6590#endif