diff options
| author | Richard M. Stallman | 1997-04-09 03:59:08 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1997-04-09 03:59:08 +0000 |
| commit | d165822189d59c8272052873803734de19bb929c (patch) | |
| tree | 513ad6aea557fc4c5b3a646e937cac337b1b9b1d /src/alloc.c | |
| parent | b05a95cbefcc974fb7188d787bf2a9c30d3849ca (diff) | |
| download | emacs-d165822189d59c8272052873803734de19bb929c.tar.gz emacs-d165822189d59c8272052873803734de19bb929c.zip | |
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.
Diffstat (limited to 'src/alloc.c')
| -rw-r--r-- | src/alloc.c | 42 |
1 files changed, 39 insertions, 3 deletions
diff --git a/src/alloc.c b/src/alloc.c index ad9e2dd1401..3468e8a9e3e 100644 --- a/src/alloc.c +++ b/src/alloc.c | |||
| @@ -37,6 +37,10 @@ Boston, MA 02111-1307, USA. */ | |||
| 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__ |
| @@ -47,6 +51,7 @@ extern char *sbrk (); | |||
| 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 | ||
| @@ -208,12 +213,18 @@ display_malloc_warning () | |||
| 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. */ |
| @@ -333,7 +344,7 @@ emacs_blocked_free (ptr) | |||
| 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; |
| @@ -363,7 +374,11 @@ emacs_blocked_malloc (size) | |||
| 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; |
| @@ -731,8 +746,16 @@ allocate_vectorlike (len) | |||
| 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) |
| @@ -1180,7 +1203,15 @@ make_uninit_string (length) | |||
| 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; |
| @@ -2579,6 +2610,11 @@ init_alloc_once () | |||
| 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 (); |