diff options
| author | Daniel Colascione | 2014-03-21 03:13:38 -0700 |
|---|---|---|
| committer | Daniel Colascione | 2014-03-21 03:13:38 -0700 |
| commit | f20b8315e044a3217818e64b832139668d42936d (patch) | |
| tree | ec00b2b6cfff60cff60def88fc01583e750bce9f /src | |
| parent | 6d731d4183a5a11b5885199d51c26f0ad84872e8 (diff) | |
| download | emacs-f20b8315e044a3217818e64b832139668d42936d.tar.gz emacs-f20b8315e044a3217818e64b832139668d42936d.zip | |
Allow lisp allocation via mmap in dumped emacs
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 6 | ||||
| -rw-r--r-- | src/alloc.c | 53 |
2 files changed, 35 insertions, 24 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 0de2025c0ef..cca3aa35e99 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,9 @@ | |||
| 1 | 2014-03-21 Daniel Colascione <dancol@dancol.org> | ||
| 2 | |||
| 3 | * alloc.c (lisp_align_malloc, allocate_string_data) | ||
| 4 | (allocate_vectorlike): Allow mmap allocation of lisp objects. | ||
| 5 | (pointers_fit_in_lispobj_p,mmap_lisp_allowed_p): New functions. | ||
| 6 | |||
| 1 | 2014-03-21 Eli Zaretskii <eliz@gnu.org> | 7 | 2014-03-21 Eli Zaretskii <eliz@gnu.org> |
| 2 | 8 | ||
| 3 | * w32fns.c (Fw32_shell_execute) [!CYGWIN]: Use ShellExecuteEx, to | 9 | * w32fns.c (Fw32_shell_execute) [!CYGWIN]: Use ShellExecuteEx, to |
diff --git a/src/alloc.c b/src/alloc.c index 62c3beec1d2..884de3e03e7 100644 --- a/src/alloc.c +++ b/src/alloc.c | |||
| @@ -403,6 +403,23 @@ XFLOAT_INIT (Lisp_Object f, double n) | |||
| 403 | XFLOAT (f)->u.data = n; | 403 | XFLOAT (f)->u.data = n; |
| 404 | } | 404 | } |
| 405 | 405 | ||
| 406 | static bool | ||
| 407 | pointers_fit_in_lispobj_p (void) | ||
| 408 | { | ||
| 409 | return (UINTPTR_MAX <= VAL_MAX) || USE_LSB_TAG; | ||
| 410 | } | ||
| 411 | |||
| 412 | static bool | ||
| 413 | mmap_lisp_allowed_p (void) | ||
| 414 | { | ||
| 415 | /* If we can't store all memory addresses in our lisp objects, it's | ||
| 416 | risky to let the heap use mmap and give us addresses from all | ||
| 417 | over our address space. We also can't use mmap for lisp objects | ||
| 418 | if we might dump: unexec doesn't preserve the contents of mmaped | ||
| 419 | regions. */ | ||
| 420 | return pointers_fit_in_lispobj_p () && !might_dump; | ||
| 421 | } | ||
| 422 | |||
| 406 | 423 | ||
| 407 | /************************************************************************ | 424 | /************************************************************************ |
| 408 | Malloc | 425 | Malloc |
| @@ -1073,10 +1090,8 @@ lisp_align_malloc (size_t nbytes, enum mem_type type) | |||
| 1073 | intptr_t aligned; /* int gets warning casting to 64-bit pointer. */ | 1090 | intptr_t aligned; /* int gets warning casting to 64-bit pointer. */ |
| 1074 | 1091 | ||
| 1075 | #ifdef DOUG_LEA_MALLOC | 1092 | #ifdef DOUG_LEA_MALLOC |
| 1076 | /* Prevent mmap'ing the chunk. Lisp data may not be mmap'ed | 1093 | if (!mmap_lisp_allowed_p ()) |
| 1077 | because mapped region contents are not preserved in | 1094 | mallopt (M_MMAP_MAX, 0); |
| 1078 | a dumped Emacs. */ | ||
| 1079 | mallopt (M_MMAP_MAX, 0); | ||
| 1080 | #endif | 1095 | #endif |
| 1081 | 1096 | ||
| 1082 | #ifdef USE_ALIGNED_ALLOC | 1097 | #ifdef USE_ALIGNED_ALLOC |
| @@ -1097,8 +1112,8 @@ lisp_align_malloc (size_t nbytes, enum mem_type type) | |||
| 1097 | ((void **) abase)[-1] = base; | 1112 | ((void **) abase)[-1] = base; |
| 1098 | 1113 | ||
| 1099 | #ifdef DOUG_LEA_MALLOC | 1114 | #ifdef DOUG_LEA_MALLOC |
| 1100 | /* Back to a reasonable maximum of mmap'ed areas. */ | 1115 | if (!mmap_lisp_allowed_p ()) |
| 1101 | mallopt (M_MMAP_MAX, MMAP_MAX_AREAS); | 1116 | mallopt (M_MMAP_MAX, MMAP_MAX_AREAS); |
| 1102 | #endif | 1117 | #endif |
| 1103 | 1118 | ||
| 1104 | #if ! USE_LSB_TAG | 1119 | #if ! USE_LSB_TAG |
| @@ -1733,23 +1748,15 @@ allocate_string_data (struct Lisp_String *s, | |||
| 1733 | size_t size = offsetof (struct sblock, data) + needed; | 1748 | size_t size = offsetof (struct sblock, data) + needed; |
| 1734 | 1749 | ||
| 1735 | #ifdef DOUG_LEA_MALLOC | 1750 | #ifdef DOUG_LEA_MALLOC |
| 1736 | /* Prevent mmap'ing the chunk. Lisp data may not be mmap'ed | 1751 | if (!mmap_lisp_allowed_p ()) |
| 1737 | because mapped region contents are not preserved in | 1752 | mallopt (M_MMAP_MAX, 0); |
| 1738 | a dumped Emacs. | ||
| 1739 | |||
| 1740 | In case you think of allowing it in a dumped Emacs at the | ||
| 1741 | cost of not being able to re-dump, there's another reason: | ||
| 1742 | mmap'ed data typically have an address towards the top of the | ||
| 1743 | address space, which won't fit into an EMACS_INT (at least on | ||
| 1744 | 32-bit systems with the current tagging scheme). --fx */ | ||
| 1745 | mallopt (M_MMAP_MAX, 0); | ||
| 1746 | #endif | 1753 | #endif |
| 1747 | 1754 | ||
| 1748 | b = lisp_malloc (size + GC_STRING_EXTRA, MEM_TYPE_NON_LISP); | 1755 | b = lisp_malloc (size + GC_STRING_EXTRA, MEM_TYPE_NON_LISP); |
| 1749 | 1756 | ||
| 1750 | #ifdef DOUG_LEA_MALLOC | 1757 | #ifdef DOUG_LEA_MALLOC |
| 1751 | /* Back to a reasonable maximum of mmap'ed areas. */ | 1758 | if (!mmap_lisp_allowed_p ()) |
| 1752 | mallopt (M_MMAP_MAX, MMAP_MAX_AREAS); | 1759 | mallopt (M_MMAP_MAX, MMAP_MAX_AREAS); |
| 1753 | #endif | 1760 | #endif |
| 1754 | 1761 | ||
| 1755 | b->next_free = b->data; | 1762 | b->next_free = b->data; |
| @@ -3050,10 +3057,8 @@ allocate_vectorlike (ptrdiff_t len) | |||
| 3050 | size_t nbytes = header_size + len * word_size; | 3057 | size_t nbytes = header_size + len * word_size; |
| 3051 | 3058 | ||
| 3052 | #ifdef DOUG_LEA_MALLOC | 3059 | #ifdef DOUG_LEA_MALLOC |
| 3053 | /* Prevent mmap'ing the chunk. Lisp data may not be mmap'ed | 3060 | if (!mmap_lisp_allowed_p ()) |
| 3054 | because mapped region contents are not preserved in | 3061 | mallopt (M_MMAP_MAX, 0); |
| 3055 | a dumped Emacs. */ | ||
| 3056 | mallopt (M_MMAP_MAX, 0); | ||
| 3057 | #endif | 3062 | #endif |
| 3058 | 3063 | ||
| 3059 | if (nbytes <= VBLOCK_BYTES_MAX) | 3064 | if (nbytes <= VBLOCK_BYTES_MAX) |
| @@ -3070,8 +3075,8 @@ allocate_vectorlike (ptrdiff_t len) | |||
| 3070 | } | 3075 | } |
| 3071 | 3076 | ||
| 3072 | #ifdef DOUG_LEA_MALLOC | 3077 | #ifdef DOUG_LEA_MALLOC |
| 3073 | /* Back to a reasonable maximum of mmap'ed areas. */ | 3078 | if (!mmap_lisp_allowed_p ()) |
| 3074 | mallopt (M_MMAP_MAX, MMAP_MAX_AREAS); | 3079 | mallopt (M_MMAP_MAX, MMAP_MAX_AREAS); |
| 3075 | #endif | 3080 | #endif |
| 3076 | 3081 | ||
| 3077 | consing_since_gc += nbytes; | 3082 | consing_since_gc += nbytes; |