User: crestani
Date: 06/03/26 17:24:29
Modified: xemacs/src ChangeLog alloc.c mc-alloc.c mc-alloc.h
Log:
2006-03-26 Marcus Crestani <crestani(a)xemacs.org>
* alloc.c (malloc_warning): Move function into scope of
MALLOC_END, add MALLOC_END.
* alloc.c (memory_full): Add memory shortage indication, adjust
error messages.
* mc-alloc.c: Add memory_shortage.
* mc-alloc.c (expand_heap): If memory is short, allocate only the
needed pages, not more.
* mc-alloc.h: Add memory_shortage.
Revision Changes Path
1.934 +11 -0 XEmacs/xemacs/src/ChangeLog
Index: ChangeLog
===================================================================
RCS file: /pack/xemacscvs/XEmacs/xemacs/src/ChangeLog,v
retrieving revision 1.933
retrieving revision 1.934
diff -u -p -r1.933 -r1.934
--- ChangeLog 2006/03/26 14:33:37 1.933
+++ ChangeLog 2006/03/26 15:24:25 1.934
@@ -1,5 +1,16 @@
2006-03-26 Marcus Crestani <crestani(a)xemacs.org>
+ * alloc.c (malloc_warning): Move function into scope of
+ MALLOC_END, add MALLOC_END.
+ * alloc.c (memory_full): Add memory shortage indication, adjust
+ error messages.
+ * mc-alloc.c: Add memory_shortage.
+ * mc-alloc.c (expand_heap): If memory is short, allocate only the
+ needed pages, not more.
+ * mc-alloc.h: Add memory_shortage.
+
+2006-03-26 Marcus Crestani <crestani(a)xemacs.org>
+
* alloc.c (make_uninit_string): Use set_lispstringp_direct.
* lisp.h (set_lispstringp_direct): New.
1.125 +60 -40 XEmacs/xemacs/src/alloc.c
Index: alloc.c
===================================================================
RCS file: /pack/xemacscvs/XEmacs/xemacs/src/alloc.c,v
retrieving revision 1.124
retrieving revision 1.125
diff -u -p -r1.124 -r1.125
--- alloc.c 2006/03/26 14:33:38 1.124
+++ alloc.c 2006/03/26 15:24:26 1.125
@@ -231,46 +231,6 @@ release_breathing_space (void)
}
#endif /* not NEW_GC */
-/* malloc calls this if it finds we are near exhausting storage */
-void
-malloc_warning (const char *str)
-{
- if (ignore_malloc_warnings)
- return;
-
- warn_when_safe
- (Qmemory, Qemergency,
- "%s\n"
- "Killing some buffers may delay running out of memory.\n"
- "However, certainly by the time you receive the 95%% warning,\n"
- "you should clean up, kill this Emacs, and start a new one.",
- str);
-}
-
-/* Called if malloc returns zero */
-DOESNT_RETURN
-memory_full (void)
-{
- fprintf (stderr, "##### M E M O R Y F U L L #####\n");
- /* Force a GC next time eval is called.
- It's better to loop garbage-collecting (we might reclaim enough
- to win) than to loop beeping and barfing "Memory exhausted"
- */
- consing_since_gc = gc_cons_threshold + 1;
- recompute_need_to_garbage_collect ();
-#ifndef NEW_GC
- release_breathing_space ();
-#endif /* not NEW_GC */
-
- /* Flush some histories which might conceivably contain garbalogical
- inhibitors. */
- if (!NILP (Fboundp (Qvalues)))
- Fset (Qvalues, Qnil);
- Vcommand_history = Qnil;
-
- out_of_memory ("Memory exhausted", Qunbound);
-}
-
static void
set_alloc_mins_and_maxes (void *val, Bytecount size)
{
@@ -352,6 +312,66 @@ malloc_after (void *val, Bytecount size)
if (!val && size != 0)
memory_full ();
set_alloc_mins_and_maxes (val, size);
+}
+
+/* malloc calls this if it finds we are near exhausting storage */
+void
+malloc_warning (const char *str)
+{
+ if (ignore_malloc_warnings)
+ return;
+
+ /* Remove the malloc lock here, because warn_when_safe may allocate
+ again. It is safe to remove the malloc lock here, because malloc
+ is already finished (malloc_warning is called via
+ after_morecore_hook -> check_memory_limits -> save_warn_fun ->
+ malloc_warning). */
+ MALLOC_END ();
+
+ warn_when_safe
+ (Qmemory, Qemergency,
+ "%s\n"
+ "Killing some buffers may delay running out of memory.\n"
+ "However, certainly by the time you receive the 95%% warning,\n"
+ "you should clean up, kill this Emacs, and start a new one.",
+ str);
+}
+
+/* Called if malloc returns zero */
+DOESNT_RETURN
+memory_full (void)
+{
+ /* Force a GC next time eval is called.
+ It's better to loop garbage-collecting (we might reclaim enough
+ to win) than to loop beeping and barfing "Memory exhausted"
+ */
+ consing_since_gc = gc_cons_threshold + 1;
+ recompute_need_to_garbage_collect ();
+#ifdef NEW_GC
+ /* Put mc-alloc into memory shortage mode. This may keep XEmacs
+ alive until the garbage collector can free enough memory to get
+ us out of the memory exhaustion. If already in memory shortage
+ mode, we are in a loop and hopelessly lost. */
+ if (memory_shortage)
+ {
+ fprintf (stderr, "Memory full, cannot recover.\n");
+ ABORT ();
+ }
+ fprintf (stderr,
+ "Memory full, try to recover.\n"
+ "You should clean up, kill this Emacs, and start a new one.\n");
+ memory_shortage++;
+#else /* not NEW_GC */
+ release_breathing_space ();
+#endif /* not NEW_GC */
+
+ /* Flush some histories which might conceivably contain garbalogical
+ inhibitors. */
+ if (!NILP (Fboundp (Qvalues)))
+ Fset (Qvalues, Qnil);
+ Vcommand_history = Qnil;
+
+ out_of_memory ("Memory exhausted", Qunbound);
}
/* like malloc, calloc, realloc, free but:
1.10 +8 -3 XEmacs/xemacs/src/mc-alloc.c
Index: mc-alloc.c
===================================================================
RCS file: /pack/xemacscvs/XEmacs/xemacs/src/mc-alloc.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -p -r1.9 -r1.10
--- mc-alloc.c 2006/03/26 14:05:30 1.9
+++ mc-alloc.c 2006/03/26 15:24:26 1.10
@@ -411,6 +411,8 @@ mc_allocator_globals_type mc_allocator_g
/* MC Allocator */
/************************************************************************/
+/* Set to 1 if memory becomes short. */
+EMACS_INT memory_shortage;
/*--- misc functions ---------------------------------------------------*/
@@ -1136,9 +1138,12 @@ expand_heap (EMACS_INT needed_pages)
void *real_start;
/* determine number of pages the heap should grow */
- n_pages = needed_pages + (HEAP_SIZE / (PAGE_SIZE * HEAP_GROWTH_DIVISOR));
- if (n_pages < MIN_HEAP_INCREASE)
- n_pages = MIN_HEAP_INCREASE;
+ if (memory_shortage)
+ n_pages = needed_pages;
+ else
+ n_pages = max (MIN_HEAP_INCREASE,
+ needed_pages
+ + (HEAP_SIZE / (PAGE_SIZE * HEAP_GROWTH_DIVISOR)));
/* get the real values */
real_size = (n_pages * PAGE_SIZE) + PAGE_SIZE;
1.6 +2 -0 XEmacs/xemacs/src/mc-alloc.h
Index: mc-alloc.h
===================================================================
RCS file: /pack/xemacscvs/XEmacs/xemacs/src/mc-alloc.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -p -r1.5 -r1.6
--- mc-alloc.h 2006/03/26 14:05:30 1.5
+++ mc-alloc.h 2006/03/26 15:24:27 1.6
@@ -27,6 +27,8 @@ Boston, MA 02111-1307, USA. */
BEGIN_C_DECLS
+/* Set to 1 if memory becomes short. */
+extern EMACS_INT memory_shortage;
/* Internal Allocator Functions: */