aboutsummaryrefslogtreecommitdiffstats
path: root/src/ralloc.c
diff options
context:
space:
mode:
authorRoland McGrath1992-10-12 21:07:25 +0000
committerRoland McGrath1992-10-12 21:07:25 +0000
commitbbc60227beb7a3013276b11049e3710d59d82eae (patch)
tree2070121601fa544f4c41cb69dffbcff2cac9a39f /src/ralloc.c
parentda396c5e1f1ca2c18c036d4d0e177e34f7ca33b5 (diff)
downloademacs-bbc60227beb7a3013276b11049e3710d59d82eae.tar.gz
emacs-bbc60227beb7a3013276b11049e3710d59d82eae.zip
(sbrk): Removed decl.
(real_morecore): New static variable. (warnlevel, warn_function, check_memory_limits): Removed. (obtain): Don't call check_memory_limits. (obtain, relinquish, r_alloc_sbrk): Use (*real_morecore) in place of sbrk; it returns 0 for errors, not -1. (r_alloc_init): Set real_morecore to old value of __morecore. Don't initialize lim_data or warnlevel, and don't call get_lim_data. (memory_warnings): Function removed.
Diffstat (limited to 'src/ralloc.c')
-rw-r--r--src/ralloc.c107
1 files changed, 9 insertions, 98 deletions
diff --git a/src/ralloc.c b/src/ralloc.c
index 5131402bdf2..f2d0ecf14fa 100644
--- a/src/ralloc.c
+++ b/src/ralloc.c
@@ -59,8 +59,8 @@ static void r_alloc_init ();
59 59
60/* Declarations for working with the malloc, ralloc, and system breaks. */ 60/* Declarations for working with the malloc, ralloc, and system breaks. */
61 61
62/* System call to set the break value. */ 62/* Function to set the real break value. */
63extern POINTER sbrk (); 63static POINTER (*real_morecore) ();
64 64
65/* The break value, as seen by malloc (). */ 65/* The break value, as seen by malloc (). */
66static POINTER virtual_break_value; 66static POINTER virtual_break_value;
@@ -78,70 +78,6 @@ static POINTER page_break_value;
78#define ROUNDUP(size) (((unsigned int) (size) + PAGE - 1) & ~(PAGE - 1)) 78#define ROUNDUP(size) (((unsigned int) (size) + PAGE - 1) & ~(PAGE - 1))
79#define ROUND_TO_PAGE(addr) (addr & (~(PAGE - 1))) 79#define ROUND_TO_PAGE(addr) (addr & (~(PAGE - 1)))
80 80
81/* Managing "almost out of memory" warnings. */
82
83/* Level of warnings issued. */
84static int warnlevel;
85
86/* Function to call to issue a warning;
87 0 means don't issue them. */
88static void (*warn_function) ();
89
90static void
91check_memory_limits (address)
92 POINTER address;
93{
94 SIZE data_size = address - data_space_start;
95 int five_percent = lim_data / 20;
96
97 switch (warnlevel)
98 {
99 case 0:
100 if (data_size > five_percent * 15)
101 {
102 warnlevel++;
103 (*warn_function) ("Warning: past 75% of memory limit");
104 }
105 break;
106
107 case 1:
108 if (data_size > five_percent * 17)
109 {
110 warnlevel++;
111 (*warn_function) ("Warning: past 85% of memory limit");
112 }
113 break;
114
115 case 2:
116 if (data_size > five_percent * 19)
117 {
118 warnlevel++;
119 (*warn_function) ("Warning: past 95% of memory limit");
120 }
121 break;
122
123 default:
124 (*warn_function) ("Warning: past acceptable memory limits");
125 break;
126 }
127
128 /* If we go down below 70% full, issue another 75% warning
129 when we go up again. */
130 if (data_size < five_percent * 14)
131 warnlevel = 0;
132 /* If we go down below 80% full, issue another 85% warning
133 when we go up again. */
134 else if (warnlevel > 1 && data_size < five_percent * 16)
135 warnlevel = 1;
136 /* If we go down below 90% full, issue another 95% warning
137 when we go up again. */
138 else if (warnlevel > 2 && data_size < five_percent * 18)
139 warnlevel = 2;
140
141 if (EXCEEDS_LISP_PTR (address))
142 memory_full ();
143}
144
145/* Functions to get and return memory from the system. */ 81/* Functions to get and return memory from the system. */
146 82
147/* Obtain SIZE bytes of space. If enough space is not presently available 83/* Obtain SIZE bytes of space. If enough space is not presently available
@@ -160,10 +96,7 @@ obtain (size)
160 { 96 {
161 SIZE get = ROUNDUP (size - already_available); 97 SIZE get = ROUNDUP (size - already_available);
162 98
163 if (warn_function) 99 if ((*real_morecore) (get) == 0)
164 check_memory_limits (page_break_value);
165
166 if (((int) sbrk (get)) < 0)
167 return 0; 100 return 0;
168 101
169 page_break_value += get; 102 page_break_value += get;
@@ -202,8 +135,8 @@ relinquish (size)
202 135
203 if (new_page_break != page_break_value) 136 if (new_page_break != page_break_value)
204 { 137 {
205 if (((int) (sbrk ((char *) new_page_break 138 if ((*real_morecore) ((char *) new_page_break
206 - (char *) page_break_value))) < 0) 139 - (char *) page_break_value) == 0)
207 abort (); 140 abort ();
208 141
209 page_break_value = new_page_break; 142 page_break_value = new_page_break;
@@ -373,7 +306,7 @@ r_alloc_sbrk (size)
373 POINTER ptr; 306 POINTER ptr;
374 307
375 if (! use_relocatable_buffers) 308 if (! use_relocatable_buffers)
376 return sbrk (size); 309 return (*real_morecore) (size);
377 310
378 if (size > 0) 311 if (size > 0)
379 { 312 {
@@ -499,38 +432,16 @@ r_alloc_init ()
499 return; 432 return;
500 433
501 r_alloc_initialized = 1; 434 r_alloc_initialized = 1;
435 real_morecore = __morecore;
502 __morecore = r_alloc_sbrk; 436 __morecore = r_alloc_sbrk;
503 437
504 virtual_break_value = break_value = sbrk (0); 438 virtual_break_value = break_value = (*real_morecore) (0);
505 if (break_value == (POINTER)NULL) 439 if (break_value == NULL)
506 abort (); 440 abort ();
507#if 0 /* The following is unreasonable because warn_func may be 0. */
508 (*warn_func)("memory initialization got 0 from sbrk(0).");
509#endif
510 441
511 page_break_value = (POINTER) ROUNDUP (break_value); 442 page_break_value = (POINTER) ROUNDUP (break_value);
512 /* Clear the rest of the last page; this memory is in our address space 443 /* Clear the rest of the last page; this memory is in our address space
513 even though it is after the sbrk value. */ 444 even though it is after the sbrk value. */
514 bzero (break_value, (page_break_value - break_value)); 445 bzero (break_value, (page_break_value - break_value));
515 use_relocatable_buffers = 1; 446 use_relocatable_buffers = 1;
516
517 lim_data = 0;
518 warnlevel = 0;
519
520 get_lim_data ();
521}
522
523/* This is the name Emacs expects to call. */
524
525void
526memory_warnings (start, warn_func)
527 POINTER start;
528 void (*warn_func) ();
529{
530 if (start)
531 data_space_start = start;
532 else
533 data_space_start = start_of_data ();
534
535 warn_function = warn_func;
536} 447}