unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Enlarge MAX_ALLOCA?
@ 2014-06-19 16:02 Eli Zaretskii
  2014-06-19 16:23 ` David Kastrup
  2014-06-19 18:28 ` Stefan Monnier
  0 siblings, 2 replies; 33+ messages in thread
From: Eli Zaretskii @ 2014-06-19 16:02 UTC (permalink / raw)
  To: emacs-devel

Does anyone see problems with the change below, which raises the bar
for 'alloca' to 64KB?  Are there any systems out there that we care
about whose stack is so small as to make this dangerous?

Why 64KB?  Because that's the size of the work area coding.c allocates
whenever it needs to encode or decode something.  It turns out we do
this a lot, e.g., every redisplay calls file-readable-p on the icon
image files, which needs to encode the file name.  While the work area
is immediately free'd, I think allocating such a large buffer so much
has a potential of creating an unnecessary memory pressure on 'malloc',
and perhaps cause excess fragmentation and/or enlarge memory footprint
in some cases.

Thoughts?

=== modified file 'src/lisp.h'
--- src/lisp.h	2014-06-17 16:09:19 +0000
+++ src/lisp.h	2014-06-19 15:37:17 +0000
@@ -4425,7 +4425,7 @@ extern void init_system_name (void);
 /* SAFE_ALLOCA normally allocates memory on the stack, but if size is
    larger than MAX_ALLOCA, use xmalloc to avoid overflowing the stack.  */
 
-enum MAX_ALLOCA { MAX_ALLOCA = 16 * 1024 };
+enum MAX_ALLOCA { MAX_ALLOCA = 64 * 1024 };
 
 extern void *record_xmalloc (size_t) ATTRIBUTE_ALLOC_SIZE ((1));
 
@@ -4434,7 +4434,7 @@ extern void *record_xmalloc (size_t) ATT
 
 /* SAFE_ALLOCA allocates a simple buffer.  */
 
-#define SAFE_ALLOCA(size) ((size) < MAX_ALLOCA	\
+#define SAFE_ALLOCA(size) ((size) <= MAX_ALLOCA	\
 			   ? alloca (size)	\
 			   : (sa_must_free = true, record_xmalloc (size)))
 
@@ -4469,7 +4469,7 @@ extern void *record_xmalloc (size_t) ATT
 
 #define SAFE_ALLOCA_LISP(buf, nelt)			       \
   do {							       \
-    if ((nelt) < MAX_ALLOCA / word_size)		       \
+    if ((nelt) <= MAX_ALLOCA / word_size)		       \
       (buf) = alloca ((nelt) * word_size);		       \
     else if ((nelt) < min (PTRDIFF_MAX, SIZE_MAX) / word_size) \
       {							       \




^ permalink raw reply	[flat|nested] 33+ messages in thread

end of thread, other threads:[~2014-06-28 14:38 UTC | newest]

Thread overview: 33+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-19 16:02 Enlarge MAX_ALLOCA? Eli Zaretskii
2014-06-19 16:23 ` David Kastrup
2014-06-19 16:48   ` Eli Zaretskii
2014-06-19 17:04     ` David Kastrup
2014-06-19 17:14       ` Eli Zaretskii
2014-06-19 17:36         ` David Kastrup
2014-06-19 17:51           ` Eli Zaretskii
2014-06-19 18:21   ` Stefan Monnier
2014-06-19 21:13     ` David Kastrup
2014-06-20  7:10       ` Eli Zaretskii
2014-06-20  8:08         ` David Kastrup
2014-06-20  8:38     ` Dmitry Antipov
2014-06-20  8:56       ` Eli Zaretskii
2014-06-20  9:26       ` Andreas Schwab
2014-06-20  9:38         ` David Kastrup
2014-06-19 18:28 ` Stefan Monnier
2014-06-19 18:38   ` Eli Zaretskii
2014-06-19 20:37     ` Stefan Monnier
2014-06-20  7:08       ` Eli Zaretskii
2014-06-20 13:02         ` Stefan Monnier
2014-06-20 13:18           ` Eli Zaretskii
2014-06-20 14:43             ` Stefan Monnier
2014-06-20 14:50               ` Eli Zaretskii
2014-06-20 15:15               ` Herring, Davis
2014-06-20 15:44                 ` Dmitry Antipov
2014-06-20 18:36                   ` Eli Zaretskii
2014-06-21 13:01     ` K. Handa
2014-06-21 13:59       ` Eli Zaretskii
2014-06-21 17:08         ` Stefan Monnier
2014-06-22  9:22         ` K. Handa
2014-06-28 14:15           ` K. Handa
2014-06-28 14:38             ` Eli Zaretskii
2014-06-21 15:19       ` David Kastrup

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).