diff options
| author | Paul Eggert | 2020-01-02 18:02:32 -0800 |
|---|---|---|
| committer | Paul Eggert | 2020-01-02 18:11:25 -0800 |
| commit | dd0e4d4e16fbbba6189610c7abb73d8b0efc6e5e (patch) | |
| tree | e085817d80d71e20ec7230c9ed59a4793174f4d5 /src/lisp.h | |
| parent | d36adb544d984b91c70f6194da01344e4b2b6fc9 (diff) | |
| download | emacs-dd0e4d4e16fbbba6189610c7abb73d8b0efc6e5e.tar.gz emacs-dd0e4d4e16fbbba6189610c7abb73d8b0efc6e5e.zip | |
Let the OS clear large new objects
Prefer calloc to malloc+memset when allocating large zeroed objects.
This avoids page thrashing when (make-vector 1000000000 nil)
allocates a large nil vector, as Emacs need not touch the
vector’s pages. This wins on platforms like GNU/Linux where
calloc can fiddle with page tables to create a block of memory
that is lazily zeroed.
* src/alloc.c (lisp_malloc, lmalloc, allocate_vectorlike):
New arg CLEARIT to tell callee whether to use malloc or calloc.
All callers changed.
(allocate_clear_vector, allocate_nil_vector): New functions.
* src/alloc.c (xzalloc, make_vector):
* src/lisp.h (make_nil_vector):
Prefer calloc to malloc + memset(...,0,...).
Diffstat (limited to 'src/lisp.h')
| -rw-r--r-- | src/lisp.h | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/src/lisp.h b/src/lisp.h index 8674fe11a64..356692d53a1 100644 --- a/src/lisp.h +++ b/src/lisp.h | |||
| @@ -3942,6 +3942,7 @@ extern Lisp_Object pure_cons (Lisp_Object, Lisp_Object); | |||
| 3942 | extern Lisp_Object make_vector (ptrdiff_t, Lisp_Object); | 3942 | extern Lisp_Object make_vector (ptrdiff_t, Lisp_Object); |
| 3943 | extern void make_byte_code (struct Lisp_Vector *); | 3943 | extern void make_byte_code (struct Lisp_Vector *); |
| 3944 | extern struct Lisp_Vector *allocate_vector (ptrdiff_t); | 3944 | extern struct Lisp_Vector *allocate_vector (ptrdiff_t); |
| 3945 | extern struct Lisp_Vector *allocate_nil_vector (ptrdiff_t); | ||
| 3945 | 3946 | ||
| 3946 | /* Make an uninitialized vector for SIZE objects. NOTE: you must | 3947 | /* Make an uninitialized vector for SIZE objects. NOTE: you must |
| 3947 | be sure that GC cannot happen until the vector is completely | 3948 | be sure that GC cannot happen until the vector is completely |
| @@ -3977,9 +3978,7 @@ make_uninit_sub_char_table (int depth, int min_char) | |||
| 3977 | INLINE Lisp_Object | 3978 | INLINE Lisp_Object |
| 3978 | make_nil_vector (ptrdiff_t size) | 3979 | make_nil_vector (ptrdiff_t size) |
| 3979 | { | 3980 | { |
| 3980 | Lisp_Object vec = make_uninit_vector (size); | 3981 | return make_lisp_ptr (allocate_nil_vector (size), Lisp_Vectorlike); |
| 3981 | memclear (XVECTOR (vec)->contents, size * word_size); | ||
| 3982 | return vec; | ||
| 3983 | } | 3982 | } |
| 3984 | 3983 | ||
| 3985 | extern struct Lisp_Vector *allocate_pseudovector (int, int, int, | 3984 | extern struct Lisp_Vector *allocate_pseudovector (int, int, int, |