Mercurial > emacs
annotate src/vm-limit.c @ 53326:fe8e63ae41d9
(Qmouse_click, Qevent_kind): Remove unused externs.
author | Kim F. Storm <storm@cua.dk> |
---|---|
date | Sat, 27 Dec 2003 23:16:53 +0000 |
parents | 695cf19ef79e |
children | a8fa7c632ee4 375f2633d815 |
rev | line source |
---|---|
734 | 1 /* Functions for memory limit warnings. |
1398
70d0cd4c5bff
mem_limits.h is now called mem-limits.h.
Roland McGrath <roland@gnu.org>
parents:
1392
diff
changeset
|
2 Copyright (C) 1990, 1992 Free Software Foundation, Inc. |
734 | 3 |
4 This file is part of GNU Emacs. | |
5 | |
6 GNU Emacs is free software; you can redistribute it and/or modify | |
7 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
|
8 the Free Software Foundation; either version 2, or (at your option) |
734 | 9 any later version. |
10 | |
11 GNU Emacs is distributed in the hope that it will be useful, | |
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 GNU General Public License for more details. | |
15 | |
16 You should have received a copy of the GNU General Public License | |
17 along with GNU Emacs; see the file COPYING. If not, write to | |
14186
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
4696
diff
changeset
|
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
4696
diff
changeset
|
19 Boston, MA 02111-1307, USA. */ |
734 | 20 |
1392
ad64a94cd81c
(morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
734
diff
changeset
|
21 #ifdef emacs |
4696
1fc792473491
Include <config.h> instead of "config.h".
Roland McGrath <roland@gnu.org>
parents:
3935
diff
changeset
|
22 #include <config.h> |
734 | 23 #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
|
24 #endif |
ad64a94cd81c
(morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
734
diff
changeset
|
25 |
ad64a94cd81c
(morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
734
diff
changeset
|
26 #ifndef emacs |
ad64a94cd81c
(morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
734
diff
changeset
|
27 #include <stddef.h> |
ad64a94cd81c
(morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
734
diff
changeset
|
28 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
|
29 typedef void *POINTER; |
ad64a94cd81c
(morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
734
diff
changeset
|
30 #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
|
31 #endif |
ad64a94cd81c
(morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
734
diff
changeset
|
32 |
1398
70d0cd4c5bff
mem_limits.h is now called mem-limits.h.
Roland McGrath <roland@gnu.org>
parents:
1392
diff
changeset
|
33 #include "mem-limits.h" |
734 | 34 |
35 /* | |
36 Level number of warnings already issued. | |
37 0 -- no warnings issued. | |
38 1 -- 75% warning already issued. | |
39 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
|
40 3 -- 95% warning issued; keep warning frequently. |
734 | 41 */ |
42 static int warnlevel; | |
43 | |
44 /* Function to call to issue a warning; | |
45 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
|
46 static void (*warn_function) (); |
734 | 47 |
48 /* Get more memory space, complaining if we're near the end. */ | |
49 | |
1416
60bb5e719468
(morecore_with_warning): Removed.
Roland McGrath <roland@gnu.org>
parents:
1400
diff
changeset
|
50 static void |
60bb5e719468
(morecore_with_warning): Removed.
Roland McGrath <roland@gnu.org>
parents:
1400
diff
changeset
|
51 check_memory_limits () |
734 | 52 { |
30062
9a026d470bc9
(check_memory_limits) [REL_ALLOC]: Use real_morecore
Andrew Innes <andrewi@gnu.org>
parents:
24366
diff
changeset
|
53 #ifdef REL_ALLOC |
9a026d470bc9
(check_memory_limits) [REL_ALLOC]: Use real_morecore
Andrew Innes <andrewi@gnu.org>
parents:
24366
diff
changeset
|
54 extern POINTER (*real_morecore) (); |
9a026d470bc9
(check_memory_limits) [REL_ALLOC]: Use real_morecore
Andrew Innes <andrewi@gnu.org>
parents:
24366
diff
changeset
|
55 #endif |
1417
3a1576d52874
(check_memory_limits): Declare __morecore.
Roland McGrath <roland@gnu.org>
parents:
1416
diff
changeset
|
56 extern POINTER (*__morecore) (); |
3a1576d52874
(check_memory_limits): Declare __morecore.
Roland McGrath <roland@gnu.org>
parents:
1416
diff
changeset
|
57 |
30062
9a026d470bc9
(check_memory_limits) [REL_ALLOC]: Use real_morecore
Andrew Innes <andrewi@gnu.org>
parents:
24366
diff
changeset
|
58 |
734 | 59 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
|
60 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
|
61 unsigned long data_size; |
734 | 62 |
63 if (lim_data == 0) | |
64 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
|
65 five_percent = lim_data / 20; |
734 | 66 |
67 /* 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
|
68 #ifdef REL_ALLOC |
9a026d470bc9
(check_memory_limits) [REL_ALLOC]: Use real_morecore
Andrew Innes <andrewi@gnu.org>
parents:
24366
diff
changeset
|
69 if (real_morecore) |
9a026d470bc9
(check_memory_limits) [REL_ALLOC]: Use real_morecore
Andrew Innes <andrewi@gnu.org>
parents:
24366
diff
changeset
|
70 cp = (char *) (*real_morecore) (0); |
9a026d470bc9
(check_memory_limits) [REL_ALLOC]: Use real_morecore
Andrew Innes <andrewi@gnu.org>
parents:
24366
diff
changeset
|
71 else |
9a026d470bc9
(check_memory_limits) [REL_ALLOC]: Use real_morecore
Andrew Innes <andrewi@gnu.org>
parents:
24366
diff
changeset
|
72 #endif |
1416
60bb5e719468
(morecore_with_warning): Removed.
Roland McGrath <roland@gnu.org>
parents:
1400
diff
changeset
|
73 cp = (char *) (*__morecore) (0); |
1400
af08281c0cbe
(warnfunction): Renamed to warn_function (was used inconsistently).
Roland McGrath <roland@gnu.org>
parents:
1398
diff
changeset
|
74 data_size = (char *) cp - (char *) data_space_start; |
734 | 75 |
1400
af08281c0cbe
(warnfunction): Renamed to warn_function (was used inconsistently).
Roland McGrath <roland@gnu.org>
parents:
1398
diff
changeset
|
76 if (warn_function) |
734 | 77 switch (warnlevel) |
78 { | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
30062
diff
changeset
|
79 case 0: |
1392
ad64a94cd81c
(morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
734
diff
changeset
|
80 if (data_size > five_percent * 15) |
734 | 81 { |
82 warnlevel++; | |
1392
ad64a94cd81c
(morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
734
diff
changeset
|
83 (*warn_function) ("Warning: past 75% of memory limit"); |
734 | 84 } |
85 break; | |
86 | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
30062
diff
changeset
|
87 case 1: |
1392
ad64a94cd81c
(morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
734
diff
changeset
|
88 if (data_size > five_percent * 17) |
734 | 89 { |
90 warnlevel++; | |
1392
ad64a94cd81c
(morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
734
diff
changeset
|
91 (*warn_function) ("Warning: past 85% of memory limit"); |
734 | 92 } |
93 break; | |
94 | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
30062
diff
changeset
|
95 case 2: |
1392
ad64a94cd81c
(morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
734
diff
changeset
|
96 if (data_size > five_percent * 19) |
734 | 97 { |
98 warnlevel++; | |
1392
ad64a94cd81c
(morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
734
diff
changeset
|
99 (*warn_function) ("Warning: past 95% of memory limit"); |
734 | 100 } |
101 break; | |
102 | |
103 default: | |
1392
ad64a94cd81c
(morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
734
diff
changeset
|
104 (*warn_function) ("Warning: past acceptable memory limits"); |
734 | 105 break; |
106 } | |
107 | |
1392
ad64a94cd81c
(morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
734
diff
changeset
|
108 /* 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
|
109 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
|
110 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
|
111 warnlevel = 0; |
ad64a94cd81c
(morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
734
diff
changeset
|
112 /* 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
|
113 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
|
114 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
|
115 warnlevel = 1; |
ad64a94cd81c
(morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
734
diff
changeset
|
116 /* 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
|
117 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
|
118 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
|
119 warnlevel = 2; |
ad64a94cd81c
(morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
734
diff
changeset
|
120 |
ad64a94cd81c
(morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
734
diff
changeset
|
121 if (EXCEEDS_LISP_PTR (cp)) |
1400
af08281c0cbe
(warnfunction): Renamed to warn_function (was used inconsistently).
Roland McGrath <roland@gnu.org>
parents:
1398
diff
changeset
|
122 (*warn_function) ("Warning: memory in use exceeds lisp pointer size"); |
734 | 123 } |
124 | |
125 /* Cause reinitialization based on job parameters; | |
126 also declare where the end of pure storage is. */ | |
127 | |
128 void | |
1392
ad64a94cd81c
(morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
734
diff
changeset
|
129 memory_warnings (start, warnfun) |
734 | 130 POINTER start; |
131 void (*warnfun) (); | |
132 { | |
1416
60bb5e719468
(morecore_with_warning): Removed.
Roland McGrath <roland@gnu.org>
parents:
1400
diff
changeset
|
133 extern void (* __after_morecore_hook) (); /* From gmalloc.c */ |
734 | 134 |
135 if (start) | |
136 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
|
137 else |
ad64a94cd81c
(morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
734
diff
changeset
|
138 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
|
139 |
1400
af08281c0cbe
(warnfunction): Renamed to warn_function (was used inconsistently).
Roland McGrath <roland@gnu.org>
parents:
1398
diff
changeset
|
140 warn_function = warnfun; |
1416
60bb5e719468
(morecore_with_warning): Removed.
Roland McGrath <roland@gnu.org>
parents:
1400
diff
changeset
|
141 __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
|
142 |
274b79aeb3b7
(memory_warnings) [WINDOWSNT]: Reset lim_data on each
Andrew Innes <andrewi@gnu.org>
parents:
14186
diff
changeset
|
143 #ifdef WINDOWSNT |
274b79aeb3b7
(memory_warnings) [WINDOWSNT]: Reset lim_data on each
Andrew Innes <andrewi@gnu.org>
parents:
14186
diff
changeset
|
144 /* 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
|
145 lim_data = 0; |
274b79aeb3b7
(memory_warnings) [WINDOWSNT]: Reset lim_data on each
Andrew Innes <andrewi@gnu.org>
parents:
14186
diff
changeset
|
146 #endif |
734 | 147 } |
52401 | 148 |
149 /* arch-tag: eab04eda-1f69-447a-8d9f-95f0a3983ca5 | |
150 (do not change this comment) */ |