aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRichard M. Stallman1992-10-11 20:39:15 +0000
committerRichard M. Stallman1992-10-11 20:39:15 +0000
commit3b672b8f44677a332e6796369f3f0c54c1d4733f (patch)
tree84e13b85c7a0dee0ec0094b2fd459feed9044ff0 /src
parent70eb2c3e2d8274e4d8dd9db8f09a265757cd95d7 (diff)
downloademacs-3b672b8f44677a332e6796369f3f0c54c1d4733f.tar.gz
emacs-3b672b8f44677a332e6796369f3f0c54c1d4733f.zip
(morecore_with_warning): Reduce warnlevel when usage drops far enough.
(memory_warnings): Renamed from malloc_init. Don't set lim_data or warnlevel. Use start_of_data if start is 0. [!emacs]: Don't include config.h or lisp.h; instead, use stddef.h. Define POINTER, SIZE, EXCEEDS_LISP_PTR. (morecore_with_warning): Use EXCEEDS_LISP_PTR.
Diffstat (limited to 'src')
-rw-r--r--src/vm-limit.c58
1 files changed, 40 insertions, 18 deletions
diff --git a/src/vm-limit.c b/src/vm-limit.c
index 496e392e5b0..91a18f6f61c 100644
--- a/src/vm-limit.c
+++ b/src/vm-limit.c
@@ -17,8 +17,18 @@ You should have received a copy of the GNU General Public License
17along with GNU Emacs; see the file COPYING. If not, write to 17along with GNU Emacs; see the file COPYING. If not, write to
18the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ 18the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
19 19
20#ifdef emacs
20#include "config.h" 21#include "config.h"
21#include "lisp.h" 22#include "lisp.h"
23#endif
24
25#ifndef emacs
26#include <stddef.h>
27typedef size_t SIZE;
28typedef void *POINTER;
29#define EXCEEDS_LISP_PTR(x) 0
30#endif
31
22#include "mem_limits.h" 32#include "mem_limits.h"
23 33
24/* 34/*
@@ -26,6 +36,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
26 0 -- no warnings issued. 36 0 -- no warnings issued.
27 1 -- 75% warning already issued. 37 1 -- 75% warning already issued.
28 2 -- 85% warning already issued. 38 2 -- 85% warning already issued.
39 3 -- 95% warning issued; keep warning frequently.
29*/ 40*/
30static int warnlevel; 41static int warnlevel;
31 42
@@ -43,53 +54,63 @@ morecore_with_warning (size)
43{ 54{
44 POINTER result; 55 POINTER result;
45 register POINTER cp; 56 register POINTER cp;
46 register unsigned int siz; 57 int five_percent;
47 58 int data_size;
48 if (!data_space_start)
49 {
50 data_space_start = start_of_data ();
51 }
52 59
53 if (lim_data == 0) 60 if (lim_data == 0)
54 get_lim_data (); 61 get_lim_data ();
62 five_percent = lim_data / 20;
55 63
56 /* Find current end of memory and issue warning if getting near max */ 64 /* Find current end of memory and issue warning if getting near max */
57 cp = sbrk (0); 65 cp = sbrk (0);
58 siz = cp - data_space_start; 66 data_size = cp - data_space_start;
59 67
60 if (warnfunction) 68 if (warnfunction)
61 switch (warnlevel) 69 switch (warnlevel)
62 { 70 {
63 case 0: 71 case 0:
64 if (siz > (lim_data / 4) * 3) 72 if (data_size > five_percent * 15)
65 { 73 {
66 warnlevel++; 74 warnlevel++;
67 (*warnfunction) ("Warning: past 75% of memory limit"); 75 (*warn_function) ("Warning: past 75% of memory limit");
68 } 76 }
69 break; 77 break;
70 78
71 case 1: 79 case 1:
72 if (siz > (lim_data / 20) * 17) 80 if (data_size > five_percent * 17)
73 { 81 {
74 warnlevel++; 82 warnlevel++;
75 (*warnfunction) ("Warning: past 85% of memory limit"); 83 (*warn_function) ("Warning: past 85% of memory limit");
76 } 84 }
77 break; 85 break;
78 86
79 case 2: 87 case 2:
80 if (siz > (lim_data / 20) * 19) 88 if (data_size > five_percent * 19)
81 { 89 {
82 warnlevel++; 90 warnlevel++;
83 (*warnfunction) ("Warning: past 95% of memory limit"); 91 (*warn_function) ("Warning: past 95% of memory limit");
84 } 92 }
85 break; 93 break;
86 94
87 default: 95 default:
88 (*warnfunction) ("Warning: past acceptable memory limits"); 96 (*warn_function) ("Warning: past acceptable memory limits");
89 break; 97 break;
90 } 98 }
91 99
92 if (EXCEEDS_ELISP_PTR (cp)) 100 /* If we go down below 70% full, issue another 75% warning
101 when we go up again. */
102 if (data_size < five_percent * 14)
103 warnlevel = 0;
104 /* If we go down below 80% full, issue another 85% warning
105 when we go up again. */
106 else if (warnlevel > 1 && data_size < five_percent * 16)
107 warnlevel = 1;
108 /* If we go down below 90% full, issue another 95% warning
109 when we go up again. */
110 else if (warnlevel > 2 && data_size < five_percent * 18)
111 warnlevel = 2;
112
113 if (EXCEEDS_LISP_PTR (cp))
93 (*warnfunction) ("Warning: memory in use exceeds lisp pointer size"); 114 (*warnfunction) ("Warning: memory in use exceeds lisp pointer size");
94 115
95 result = sbrk (size); 116 result = sbrk (size);
@@ -102,7 +123,7 @@ morecore_with_warning (size)
102 also declare where the end of pure storage is. */ 123 also declare where the end of pure storage is. */
103 124
104void 125void
105malloc_init (start, warnfun) 126memory_warnings (start, warnfun)
106 POINTER start; 127 POINTER start;
107 void (*warnfun) (); 128 void (*warnfun) ();
108{ 129{
@@ -110,8 +131,9 @@ malloc_init (start, warnfun)
110 131
111 if (start) 132 if (start)
112 data_space_start = start; 133 data_space_start = start;
113 lim_data = 0; 134 else
114 warnlevel = 0; 135 data_space_start = start_of_data ();
136
115 warnfunction = warnfun; 137 warnfunction = warnfun;
116 __morecore = &morecore_with_warning; 138 __morecore = &morecore_with_warning;
117} 139}