comparison src/alloc.c @ 17345:4e11e27ce1f1

For glibc's malloc, include <malloc.h> for mallinfo, mallopt, struct mallinfo, and mallopt constants. (BYTES_USED): New macro. (memory_full, emacs_blocked_free): Replace _bytes_used with BYTES_USED. (emacs_blocked_malloc): Set sbrk padding value for glibc, as is done with gmalloc. (allocate_vectorlike, make_uninit_string): Prevent using mmap for possible large chunks. (init_alloc_once): Set trim and mmap malloc parms, when using glibc.
author Richard M. Stallman <rms@gnu.org>
date Wed, 09 Apr 1997 03:59:08 +0000
parents e2a6f31ee014
children ceb61585d2fc
comparison
equal deleted inserted replaced
17344:0178aa2a41e9 17345:4e11e27ce1f1
35 35
36 #include "syssignal.h" 36 #include "syssignal.h"
37 37
38 extern char *sbrk (); 38 extern char *sbrk ();
39 39
40 #ifdef DOUG_LEA_MALLOC
41 #include <malloc.h>
42 #define __malloc_size_t int
43 #else
40 /* The following come from gmalloc.c. */ 44 /* The following come from gmalloc.c. */
41 45
42 #if defined (__STDC__) && __STDC__ 46 #if defined (__STDC__) && __STDC__
43 #include <stddef.h> 47 #include <stddef.h>
44 #define __malloc_size_t size_t 48 #define __malloc_size_t size_t
45 #else 49 #else
46 #define __malloc_size_t unsigned int 50 #define __malloc_size_t unsigned int
47 #endif 51 #endif
48 extern __malloc_size_t _bytes_used; 52 extern __malloc_size_t _bytes_used;
49 extern int __malloc_extra_blocks; 53 extern int __malloc_extra_blocks;
54 #endif /* !defined(DOUG_LEA_MALLOC) */
50 55
51 extern Lisp_Object Vhistory_length; 56 extern Lisp_Object Vhistory_length;
52 57
53 #define max(A,B) ((A) > (B) ? (A) : (B)) 58 #define max(A,B) ((A) > (B) ? (A) : (B))
54 #define min(A,B) ((A) < (B) ? (A) : (B)) 59 #define min(A,B) ((A) < (B) ? (A) : (B))
206 val = build_string (pending_malloc_warning); 211 val = build_string (pending_malloc_warning);
207 pending_malloc_warning = 0; 212 pending_malloc_warning = 0;
208 internal_with_output_to_temp_buffer (" *Danger*", malloc_warning_1, val); 213 internal_with_output_to_temp_buffer (" *Danger*", malloc_warning_1, val);
209 } 214 }
210 215
216 #ifdef DOUG_LEA_MALLOC
217 #define BYTES_USED (mallinfo ().arena)
218 #else
219 #define BYTES_USED _bytes_used
220 #endif
221
211 /* Called if malloc returns zero */ 222 /* Called if malloc returns zero */
212 223
213 memory_full () 224 memory_full ()
214 { 225 {
215 #ifndef SYSTEM_MALLOC 226 #ifndef SYSTEM_MALLOC
216 bytes_used_when_full = _bytes_used; 227 bytes_used_when_full = BYTES_USED;
217 #endif 228 #endif
218 229
219 /* The first time we get here, free the spare memory. */ 230 /* The first time we get here, free the spare memory. */
220 if (spare_memory) 231 if (spare_memory)
221 { 232 {
331 /* Verify there is enough space that even with the malloc 342 /* Verify there is enough space that even with the malloc
332 hysteresis this call won't run out again. 343 hysteresis this call won't run out again.
333 The code here is correct as long as SPARE_MEMORY 344 The code here is correct as long as SPARE_MEMORY
334 is substantially larger than the block size malloc uses. */ 345 is substantially larger than the block size malloc uses. */
335 && (bytes_used_when_full 346 && (bytes_used_when_full
336 > _bytes_used + max (malloc_hysteresis, 4) * SPARE_MEMORY)) 347 > BYTES_USED + max (malloc_hysteresis, 4) * SPARE_MEMORY))
337 spare_memory = (char *) malloc (SPARE_MEMORY); 348 spare_memory = (char *) malloc (SPARE_MEMORY);
338 349
339 __free_hook = emacs_blocked_free; 350 __free_hook = emacs_blocked_free;
340 UNBLOCK_INPUT; 351 UNBLOCK_INPUT;
341 } 352 }
361 { 372 {
362 void *value; 373 void *value;
363 374
364 BLOCK_INPUT; 375 BLOCK_INPUT;
365 __malloc_hook = old_malloc_hook; 376 __malloc_hook = old_malloc_hook;
366 __malloc_extra_blocks = malloc_hysteresis; 377 #ifdef DOUG_LEA_MALLOC
378 mallopt (M_TOP_PAD, malloc_hysteresis * 4096);
379 #else
380 __malloc_extra_blocks = malloc_hysteresis;
381 #endif
367 value = (void *) malloc (size); 382 value = (void *) malloc (size);
368 __malloc_hook = emacs_blocked_malloc; 383 __malloc_hook = emacs_blocked_malloc;
369 UNBLOCK_INPUT; 384 UNBLOCK_INPUT;
370 385
371 return value; 386 return value;
729 EMACS_INT len; 744 EMACS_INT len;
730 { 745 {
731 struct Lisp_Vector *p; 746 struct Lisp_Vector *p;
732 747
733 allocating_for_lisp = 1; 748 allocating_for_lisp = 1;
749 #ifdef DOUG_LEA_MALLOC
750 /* Prevent mmap'ing the chunk (which is potentially very large). */
751 mallopt (M_MMAP_MAX, 0);
752 #endif
734 p = (struct Lisp_Vector *)xmalloc (sizeof (struct Lisp_Vector) 753 p = (struct Lisp_Vector *)xmalloc (sizeof (struct Lisp_Vector)
735 + (len - 1) * sizeof (Lisp_Object)); 754 + (len - 1) * sizeof (Lisp_Object));
755 #ifdef DOUG_LEA_MALLOC
756 /* Back to a reasonable maximum of mmap'ed areas. */
757 mallopt (M_MMAP_MAX, 64);
758 #endif
736 allocating_for_lisp = 0; 759 allocating_for_lisp = 0;
737 VALIDATE_LISP_STORAGE (p, 0); 760 VALIDATE_LISP_STORAGE (p, 0);
738 consing_since_gc += (sizeof (struct Lisp_Vector) 761 consing_since_gc += (sizeof (struct Lisp_Vector)
739 + (len - 1) * sizeof (Lisp_Object)); 762 + (len - 1) * sizeof (Lisp_Object));
740 vector_cells_consed += len; 763 vector_cells_consed += len;
1178 else if (fullsize > STRING_BLOCK_OUTSIZE) 1201 else if (fullsize > STRING_BLOCK_OUTSIZE)
1179 /* This string gets its own string block */ 1202 /* This string gets its own string block */
1180 { 1203 {
1181 register struct string_block *new; 1204 register struct string_block *new;
1182 allocating_for_lisp = 1; 1205 allocating_for_lisp = 1;
1206 #ifdef DOUG_LEA_MALLOC
1207 /* Prevent mmap'ing the chunk (which is potentially very large). */
1208 mallopt (M_MMAP_MAX, 0);
1209 #endif
1183 new = (struct string_block *) xmalloc (sizeof (struct string_block_head) + fullsize); 1210 new = (struct string_block *) xmalloc (sizeof (struct string_block_head) + fullsize);
1211 #ifdef DOUG_LEA_MALLOC
1212 /* Back to a reasonable maximum of mmap'ed areas. */
1213 mallopt (M_MMAP_MAX, 64);
1214 #endif
1184 allocating_for_lisp = 0; 1215 allocating_for_lisp = 0;
1185 VALIDATE_LISP_STORAGE (new, 0); 1216 VALIDATE_LISP_STORAGE (new, 0);
1186 consing_since_gc += sizeof (struct string_block_head) + fullsize; 1217 consing_since_gc += sizeof (struct string_block_head) + fullsize;
1187 new->pos = fullsize; 1218 new->pos = fullsize;
1188 new->next = large_string_blocks; 1219 new->next = large_string_blocks;
2577 #ifdef HAVE_SHM 2608 #ifdef HAVE_SHM
2578 pure_size = PURESIZE; 2609 pure_size = PURESIZE;
2579 #endif 2610 #endif
2580 all_vectors = 0; 2611 all_vectors = 0;
2581 ignore_warnings = 1; 2612 ignore_warnings = 1;
2613 #ifdef DOUG_LEA_MALLOC
2614 mallopt (M_TRIM_THRESHOLD, 128*1024); /* trim threshold */
2615 mallopt (M_MMAP_THRESHOLD, 64*1024); /* mmap threshold */
2616 mallopt (M_MMAP_MAX, 64); /* max. number of mmap'ed areas */
2617 #endif
2582 init_strings (); 2618 init_strings ();
2583 init_cons (); 2619 init_cons ();
2584 init_symbol (); 2620 init_symbol ();
2585 init_marker (); 2621 init_marker ();
2586 #ifdef LISP_FLOAT_TYPE 2622 #ifdef LISP_FLOAT_TYPE