Mercurial > emacs
annotate src/vm-limit.c @ 69212:16877a343711
(mh-image-load-path): Rename variable to mh-image-directory.
(mh-image-load-path): Access mh-image-directory instead of
mh-image-load-path.
author | Bill Wohler <wohler@newt.com> |
---|---|
date | Tue, 28 Feb 2006 21:47:19 +0000 |
parents | 01f2a79bee28 |
children | 7e58bc915ffe d1c5430c5bff |
rev | line source |
---|---|
734 | 1 /* Functions for memory limit warnings. |
64770
a0d1312ede66
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64084
diff
changeset
|
2 Copyright (C) 1990, 1992, 2002, 2003, 2004, |
68651
3bd95f4f2941
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64770
diff
changeset
|
3 2005, 2006 Free Software Foundation, Inc. |
734 | 4 |
5 This file is part of GNU Emacs. | |
6 | |
7 GNU Emacs is free software; you can redistribute it and/or modify | |
8 it under the terms of the GNU General Public License as published by | |
1398
70d0cd4c5bff
mem_limits.h is now called mem-limits.h.
Roland McGrath <roland@gnu.org>
parents:
1392
diff
changeset
|
9 the Free Software Foundation; either version 2, or (at your option) |
734 | 10 any later version. |
11 | |
12 GNU Emacs is distributed in the hope that it will be useful, | |
13 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 GNU General Public License for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
18 along with GNU Emacs; see the file COPYING. If not, write to | |
64084 | 19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
20 Boston, MA 02110-1301, USA. */ | |
734 | 21 |
1392
ad64a94cd81c
(morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
734
diff
changeset
|
22 #ifdef emacs |
4696
1fc792473491
Include <config.h> instead of "config.h".
Roland McGrath <roland@gnu.org>
parents:
3935
diff
changeset
|
23 #include <config.h> |
734 | 24 #include "lisp.h" |
1392
ad64a94cd81c
(morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
734
diff
changeset
|
25 #endif |
ad64a94cd81c
(morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
734
diff
changeset
|
26 |
ad64a94cd81c
(morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
734
diff
changeset
|
27 #ifndef emacs |
ad64a94cd81c
(morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
734
diff
changeset
|
28 #include <stddef.h> |
ad64a94cd81c
(morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
734
diff
changeset
|
29 typedef size_t SIZE; |
ad64a94cd81c
(morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
734
diff
changeset
|
30 typedef void *POINTER; |
ad64a94cd81c
(morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
734
diff
changeset
|
31 #define EXCEEDS_LISP_PTR(x) 0 |
ad64a94cd81c
(morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
734
diff
changeset
|
32 #endif |
ad64a94cd81c
(morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
734
diff
changeset
|
33 |
1398
70d0cd4c5bff
mem_limits.h is now called mem-limits.h.
Roland McGrath <roland@gnu.org>
parents:
1392
diff
changeset
|
34 #include "mem-limits.h" |
734 | 35 |
69019
01f2a79bee28
[HAVE_GETRLIMIT]: Include sys/resource.h.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
36 #ifdef HAVE_GETRLIMIT |
01f2a79bee28
[HAVE_GETRLIMIT]: Include sys/resource.h.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
37 #include <sys/resource.h> |
01f2a79bee28
[HAVE_GETRLIMIT]: Include sys/resource.h.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
38 #endif |
01f2a79bee28
[HAVE_GETRLIMIT]: Include sys/resource.h.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
39 |
734 | 40 /* |
41 Level number of warnings already issued. | |
42 0 -- no warnings issued. | |
43 1 -- 75% warning already issued. | |
44 2 -- 85% warning already issued. | |
1392
ad64a94cd81c
(morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
734
diff
changeset
|
45 3 -- 95% warning issued; keep warning frequently. |
734 | 46 */ |
47 static int warnlevel; | |
48 | |
49 /* Function to call to issue a warning; | |
50 0 means don't issue them. */ | |
1400
af08281c0cbe
(warnfunction): Renamed to warn_function (was used inconsistently).
Roland McGrath <roland@gnu.org>
parents:
1398
diff
changeset
|
51 static void (*warn_function) (); |
734 | 52 |
53 /* Get more memory space, complaining if we're near the end. */ | |
54 | |
1416
60bb5e719468
(morecore_with_warning): Removed.
Roland McGrath <roland@gnu.org>
parents:
1400
diff
changeset
|
55 static void |
60bb5e719468
(morecore_with_warning): Removed.
Roland McGrath <roland@gnu.org>
parents:
1400
diff
changeset
|
56 check_memory_limits () |
734 | 57 { |
30062
9a026d470bc9
(check_memory_limits) [REL_ALLOC]: Use real_morecore
Andrew Innes <andrewi@gnu.org>
parents:
24366
diff
changeset
|
58 #ifdef REL_ALLOC |
9a026d470bc9
(check_memory_limits) [REL_ALLOC]: Use real_morecore
Andrew Innes <andrewi@gnu.org>
parents:
24366
diff
changeset
|
59 extern POINTER (*real_morecore) (); |
9a026d470bc9
(check_memory_limits) [REL_ALLOC]: Use real_morecore
Andrew Innes <andrewi@gnu.org>
parents:
24366
diff
changeset
|
60 #endif |
1417
3a1576d52874
(check_memory_limits): Declare __morecore.
Roland McGrath <roland@gnu.org>
parents:
1416
diff
changeset
|
61 extern POINTER (*__morecore) (); |
3a1576d52874
(check_memory_limits): Declare __morecore.
Roland McGrath <roland@gnu.org>
parents:
1416
diff
changeset
|
62 |
30062
9a026d470bc9
(check_memory_limits) [REL_ALLOC]: Use real_morecore
Andrew Innes <andrewi@gnu.org>
parents:
24366
diff
changeset
|
63 |
734 | 64 register POINTER cp; |
3935
cecc2b59e875
(check_memory_limits): Use unsigned long to hold memory size values.
Richard M. Stallman <rms@gnu.org>
parents:
1417
diff
changeset
|
65 unsigned long five_percent; |
cecc2b59e875
(check_memory_limits): Use unsigned long to hold memory size values.
Richard M. Stallman <rms@gnu.org>
parents:
1417
diff
changeset
|
66 unsigned long data_size; |
734 | 67 |
69019
01f2a79bee28
[HAVE_GETRLIMIT]: Include sys/resource.h.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
68 #ifdef HAVE_GETRLIMIT |
01f2a79bee28
[HAVE_GETRLIMIT]: Include sys/resource.h.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
69 struct rlimit { |
01f2a79bee28
[HAVE_GETRLIMIT]: Include sys/resource.h.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
70 rlim_t rlim_cur; |
01f2a79bee28
[HAVE_GETRLIMIT]: Include sys/resource.h.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
71 rlim_t rlim_max; |
01f2a79bee28
[HAVE_GETRLIMIT]: Include sys/resource.h.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
72 } rlimit; |
01f2a79bee28
[HAVE_GETRLIMIT]: Include sys/resource.h.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
73 |
01f2a79bee28
[HAVE_GETRLIMIT]: Include sys/resource.h.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
74 getrlimit (RLIMIT_DATA, &rlimit); |
01f2a79bee28
[HAVE_GETRLIMIT]: Include sys/resource.h.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
75 |
01f2a79bee28
[HAVE_GETRLIMIT]: Include sys/resource.h.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
76 five_percent = rlimit.rlim_max / 20; |
01f2a79bee28
[HAVE_GETRLIMIT]: Include sys/resource.h.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
77 data_size = rlimit.rlim_cur; |
01f2a79bee28
[HAVE_GETRLIMIT]: Include sys/resource.h.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
78 |
01f2a79bee28
[HAVE_GETRLIMIT]: Include sys/resource.h.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
79 #else /* not HAVE_GETRLIMIT */ |
01f2a79bee28
[HAVE_GETRLIMIT]: Include sys/resource.h.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
80 |
734 | 81 if (lim_data == 0) |
82 get_lim_data (); | |
1392
ad64a94cd81c
(morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
734
diff
changeset
|
83 five_percent = lim_data / 20; |
734 | 84 |
85 /* Find current end of memory and issue warning if getting near max */ | |
30062
9a026d470bc9
(check_memory_limits) [REL_ALLOC]: Use real_morecore
Andrew Innes <andrewi@gnu.org>
parents:
24366
diff
changeset
|
86 #ifdef REL_ALLOC |
9a026d470bc9
(check_memory_limits) [REL_ALLOC]: Use real_morecore
Andrew Innes <andrewi@gnu.org>
parents:
24366
diff
changeset
|
87 if (real_morecore) |
9a026d470bc9
(check_memory_limits) [REL_ALLOC]: Use real_morecore
Andrew Innes <andrewi@gnu.org>
parents:
24366
diff
changeset
|
88 cp = (char *) (*real_morecore) (0); |
9a026d470bc9
(check_memory_limits) [REL_ALLOC]: Use real_morecore
Andrew Innes <andrewi@gnu.org>
parents:
24366
diff
changeset
|
89 else |
9a026d470bc9
(check_memory_limits) [REL_ALLOC]: Use real_morecore
Andrew Innes <andrewi@gnu.org>
parents:
24366
diff
changeset
|
90 #endif |
1416
60bb5e719468
(morecore_with_warning): Removed.
Roland McGrath <roland@gnu.org>
parents:
1400
diff
changeset
|
91 cp = (char *) (*__morecore) (0); |
1400
af08281c0cbe
(warnfunction): Renamed to warn_function (was used inconsistently).
Roland McGrath <roland@gnu.org>
parents:
1398
diff
changeset
|
92 data_size = (char *) cp - (char *) data_space_start; |
734 | 93 |
69019
01f2a79bee28
[HAVE_GETRLIMIT]: Include sys/resource.h.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
94 #endif /* not HAVE_GETRLIMIT */ |
01f2a79bee28
[HAVE_GETRLIMIT]: Include sys/resource.h.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
95 |
1400
af08281c0cbe
(warnfunction): Renamed to warn_function (was used inconsistently).
Roland McGrath <roland@gnu.org>
parents:
1398
diff
changeset
|
96 if (warn_function) |
734 | 97 switch (warnlevel) |
98 { | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
30062
diff
changeset
|
99 case 0: |
1392
ad64a94cd81c
(morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
734
diff
changeset
|
100 if (data_size > five_percent * 15) |
734 | 101 { |
102 warnlevel++; | |
1392
ad64a94cd81c
(morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
734
diff
changeset
|
103 (*warn_function) ("Warning: past 75% of memory limit"); |
734 | 104 } |
105 break; | |
106 | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
30062
diff
changeset
|
107 case 1: |
1392
ad64a94cd81c
(morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
734
diff
changeset
|
108 if (data_size > five_percent * 17) |
734 | 109 { |
110 warnlevel++; | |
1392
ad64a94cd81c
(morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
734
diff
changeset
|
111 (*warn_function) ("Warning: past 85% of memory limit"); |
734 | 112 } |
113 break; | |
114 | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
30062
diff
changeset
|
115 case 2: |
1392
ad64a94cd81c
(morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
734
diff
changeset
|
116 if (data_size > five_percent * 19) |
734 | 117 { |
118 warnlevel++; | |
1392
ad64a94cd81c
(morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
734
diff
changeset
|
119 (*warn_function) ("Warning: past 95% of memory limit"); |
734 | 120 } |
121 break; | |
122 | |
123 default: | |
1392
ad64a94cd81c
(morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
734
diff
changeset
|
124 (*warn_function) ("Warning: past acceptable memory limits"); |
734 | 125 break; |
126 } | |
127 | |
1392
ad64a94cd81c
(morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
734
diff
changeset
|
128 /* If we go down below 70% full, issue another 75% warning |
ad64a94cd81c
(morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
734
diff
changeset
|
129 when we go up again. */ |
ad64a94cd81c
(morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
734
diff
changeset
|
130 if (data_size < five_percent * 14) |
ad64a94cd81c
(morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
734
diff
changeset
|
131 warnlevel = 0; |
ad64a94cd81c
(morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
734
diff
changeset
|
132 /* If we go down below 80% full, issue another 85% warning |
ad64a94cd81c
(morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
734
diff
changeset
|
133 when we go up again. */ |
ad64a94cd81c
(morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
734
diff
changeset
|
134 else if (warnlevel > 1 && data_size < five_percent * 16) |
ad64a94cd81c
(morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
734
diff
changeset
|
135 warnlevel = 1; |
ad64a94cd81c
(morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
734
diff
changeset
|
136 /* If we go down below 90% full, issue another 95% warning |
ad64a94cd81c
(morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
734
diff
changeset
|
137 when we go up again. */ |
ad64a94cd81c
(morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
734
diff
changeset
|
138 else if (warnlevel > 2 && data_size < five_percent * 18) |
ad64a94cd81c
(morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
734
diff
changeset
|
139 warnlevel = 2; |
ad64a94cd81c
(morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
734
diff
changeset
|
140 |
ad64a94cd81c
(morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
734
diff
changeset
|
141 if (EXCEEDS_LISP_PTR (cp)) |
1400
af08281c0cbe
(warnfunction): Renamed to warn_function (was used inconsistently).
Roland McGrath <roland@gnu.org>
parents:
1398
diff
changeset
|
142 (*warn_function) ("Warning: memory in use exceeds lisp pointer size"); |
734 | 143 } |
144 | |
145 /* Cause reinitialization based on job parameters; | |
146 also declare where the end of pure storage is. */ | |
147 | |
148 void | |
1392
ad64a94cd81c
(morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
734
diff
changeset
|
149 memory_warnings (start, warnfun) |
734 | 150 POINTER start; |
151 void (*warnfun) (); | |
152 { | |
1416
60bb5e719468
(morecore_with_warning): Removed.
Roland McGrath <roland@gnu.org>
parents:
1400
diff
changeset
|
153 extern void (* __after_morecore_hook) (); /* From gmalloc.c */ |
734 | 154 |
155 if (start) | |
156 data_space_start = start; | |
1392
ad64a94cd81c
(morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
734
diff
changeset
|
157 else |
ad64a94cd81c
(morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
734
diff
changeset
|
158 data_space_start = start_of_data (); |
ad64a94cd81c
(morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
734
diff
changeset
|
159 |
1400
af08281c0cbe
(warnfunction): Renamed to warn_function (was used inconsistently).
Roland McGrath <roland@gnu.org>
parents:
1398
diff
changeset
|
160 warn_function = warnfun; |
1416
60bb5e719468
(morecore_with_warning): Removed.
Roland McGrath <roland@gnu.org>
parents:
1400
diff
changeset
|
161 __after_morecore_hook = check_memory_limits; |
24366
274b79aeb3b7
(memory_warnings) [WINDOWSNT]: Reset lim_data on each
Andrew Innes <andrewi@gnu.org>
parents:
14186
diff
changeset
|
162 |
274b79aeb3b7
(memory_warnings) [WINDOWSNT]: Reset lim_data on each
Andrew Innes <andrewi@gnu.org>
parents:
14186
diff
changeset
|
163 #ifdef WINDOWSNT |
274b79aeb3b7
(memory_warnings) [WINDOWSNT]: Reset lim_data on each
Andrew Innes <andrewi@gnu.org>
parents:
14186
diff
changeset
|
164 /* Force data limit to be recalculated on each run. */ |
274b79aeb3b7
(memory_warnings) [WINDOWSNT]: Reset lim_data on each
Andrew Innes <andrewi@gnu.org>
parents:
14186
diff
changeset
|
165 lim_data = 0; |
274b79aeb3b7
(memory_warnings) [WINDOWSNT]: Reset lim_data on each
Andrew Innes <andrewi@gnu.org>
parents:
14186
diff
changeset
|
166 #endif |
734 | 167 } |
52401 | 168 |
169 /* arch-tag: eab04eda-1f69-447a-8d9f-95f0a3983ca5 | |
170 (do not change this comment) */ |