Mercurial > emacs
annotate src/vm-limit.c @ 80699:2ba6b3010dbe
(holiday-julian): Fix a problem with holidays in the last fortnight in
Julian October (sync from trunk 2008-03-31).
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Sun, 10 Aug 2008 20:05:45 +0000 |
parents | d1b49c04a897 |
children |
rev | line source |
---|---|
734 | 1 /* Functions for memory limit warnings. |
75227
e90d04cd455a
Update copyright for years from Emacs 21 to present (mainly adding
Glenn Morris <rgm@gnu.org>
parents:
69397
diff
changeset
|
2 Copyright (C) 1990, 1992, 2001, 2002, 2003, 2004, |
79759 | 3 2005, 2006, 2007, 2008 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 | |
78260
922696f363b0
Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents:
75227
diff
changeset
|
9 the Free Software Foundation; either version 3, 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 */ |
69390
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
47 enum warnlevel { not_warned, warned_75, warned_85, warned_95 }; |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
48 |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
49 static enum warnlevel warnlevel; |
734 | 50 |
51 /* Function to call to issue a warning; | |
52 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
|
53 static void (*warn_function) (); |
734 | 54 |
69390
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
55 /* Start of data space; can be changed by calling malloc_init. */ |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
56 static POINTER data_space_start; |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
57 |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
58 /* Number of bytes of writable memory we can expect to be able to get. */ |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
59 static unsigned long lim_data; |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
60 |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
61 |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
62 #ifdef NO_LIM_DATA |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
63 static void |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
64 get_lim_data () |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
65 { |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
66 lim_data = -1; |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
67 } |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
68 #else /* not NO_LIM_DATA */ |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
69 |
80675
d1b49c04a897
(get_lim_data) [HAVE_GETRLIMIT && RLIMIT_AS]: Define.
Chong Yidong <cyd@stupidchicken.com>
parents:
80673
diff
changeset
|
70 #if defined (HAVE_GETRLIMIT) && defined (RLIMIT_AS) |
d1b49c04a897
(get_lim_data) [HAVE_GETRLIMIT && RLIMIT_AS]: Define.
Chong Yidong <cyd@stupidchicken.com>
parents:
80673
diff
changeset
|
71 static void |
d1b49c04a897
(get_lim_data) [HAVE_GETRLIMIT && RLIMIT_AS]: Define.
Chong Yidong <cyd@stupidchicken.com>
parents:
80673
diff
changeset
|
72 get_lim_data () |
d1b49c04a897
(get_lim_data) [HAVE_GETRLIMIT && RLIMIT_AS]: Define.
Chong Yidong <cyd@stupidchicken.com>
parents:
80673
diff
changeset
|
73 { |
d1b49c04a897
(get_lim_data) [HAVE_GETRLIMIT && RLIMIT_AS]: Define.
Chong Yidong <cyd@stupidchicken.com>
parents:
80673
diff
changeset
|
74 struct rlimit rlimit; |
d1b49c04a897
(get_lim_data) [HAVE_GETRLIMIT && RLIMIT_AS]: Define.
Chong Yidong <cyd@stupidchicken.com>
parents:
80673
diff
changeset
|
75 |
d1b49c04a897
(get_lim_data) [HAVE_GETRLIMIT && RLIMIT_AS]: Define.
Chong Yidong <cyd@stupidchicken.com>
parents:
80673
diff
changeset
|
76 getrlimit (RLIMIT_AS, &rlimit); |
d1b49c04a897
(get_lim_data) [HAVE_GETRLIMIT && RLIMIT_AS]: Define.
Chong Yidong <cyd@stupidchicken.com>
parents:
80673
diff
changeset
|
77 if (rlimit.rlim_cur == RLIM_INFINITY) |
d1b49c04a897
(get_lim_data) [HAVE_GETRLIMIT && RLIMIT_AS]: Define.
Chong Yidong <cyd@stupidchicken.com>
parents:
80673
diff
changeset
|
78 lim_data = -1; |
d1b49c04a897
(get_lim_data) [HAVE_GETRLIMIT && RLIMIT_AS]: Define.
Chong Yidong <cyd@stupidchicken.com>
parents:
80673
diff
changeset
|
79 else |
d1b49c04a897
(get_lim_data) [HAVE_GETRLIMIT && RLIMIT_AS]: Define.
Chong Yidong <cyd@stupidchicken.com>
parents:
80673
diff
changeset
|
80 lim_data = rlimit.rlim_cur; |
d1b49c04a897
(get_lim_data) [HAVE_GETRLIMIT && RLIMIT_AS]: Define.
Chong Yidong <cyd@stupidchicken.com>
parents:
80673
diff
changeset
|
81 } |
d1b49c04a897
(get_lim_data) [HAVE_GETRLIMIT && RLIMIT_AS]: Define.
Chong Yidong <cyd@stupidchicken.com>
parents:
80673
diff
changeset
|
82 |
d1b49c04a897
(get_lim_data) [HAVE_GETRLIMIT && RLIMIT_AS]: Define.
Chong Yidong <cyd@stupidchicken.com>
parents:
80673
diff
changeset
|
83 #else /* not HAVE_GETRLIMIT */ |
d1b49c04a897
(get_lim_data) [HAVE_GETRLIMIT && RLIMIT_AS]: Define.
Chong Yidong <cyd@stupidchicken.com>
parents:
80673
diff
changeset
|
84 |
69390
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
85 #ifdef USG |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
86 |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
87 static void |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
88 get_lim_data () |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
89 { |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
90 extern long ulimit (); |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
91 |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
92 lim_data = -1; |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
93 |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
94 /* Use the ulimit call, if we seem to have it. */ |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
95 #if !defined (ULIMIT_BREAK_VALUE) || defined (GNU_LINUX) |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
96 lim_data = ulimit (3, 0); |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
97 #endif |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
98 |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
99 /* If that didn't work, just use the macro's value. */ |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
100 #ifdef ULIMIT_BREAK_VALUE |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
101 if (lim_data == -1) |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
102 lim_data = ULIMIT_BREAK_VALUE; |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
103 #endif |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
104 |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
105 lim_data -= (long) data_space_start; |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
106 } |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
107 |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
108 #else /* not USG */ |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
109 #ifdef WINDOWSNT |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
110 |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
111 static void |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
112 get_lim_data () |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
113 { |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
114 extern unsigned long reserved_heap_size; |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
115 lim_data = reserved_heap_size; |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
116 } |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
117 |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
118 #else |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
119 #if !defined (BSD4_2) && !defined (__osf__) |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
120 |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
121 #ifdef MSDOS |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
122 void |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
123 get_lim_data () |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
124 { |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
125 _go32_dpmi_meminfo info; |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
126 |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
127 _go32_dpmi_get_free_memory_information (&info); |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
128 lim_data = info.available_memory; |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
129 } |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
130 #else /* not MSDOS */ |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
131 static void |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
132 get_lim_data () |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
133 { |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
134 lim_data = vlimit (LIM_DATA, -1); |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
135 } |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
136 #endif /* not MSDOS */ |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
137 |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
138 #else /* BSD4_2 */ |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
139 |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
140 static void |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
141 get_lim_data () |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
142 { |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
143 struct rlimit XXrlimit; |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
144 |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
145 getrlimit (RLIMIT_DATA, &XXrlimit); |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
146 #ifdef RLIM_INFINITY |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
147 lim_data = XXrlimit.rlim_cur & RLIM_INFINITY; /* soft limit */ |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
148 #else |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
149 lim_data = XXrlimit.rlim_cur; /* soft limit */ |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
150 #endif |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
151 } |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
152 #endif /* BSD4_2 */ |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
153 #endif /* not WINDOWSNT */ |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
154 #endif /* not USG */ |
80675
d1b49c04a897
(get_lim_data) [HAVE_GETRLIMIT && RLIMIT_AS]: Define.
Chong Yidong <cyd@stupidchicken.com>
parents:
80673
diff
changeset
|
155 #endif /* not HAVE_GETRLIMIT */ |
69390
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
156 #endif /* not NO_LIM_DATA */ |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
157 |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
158 /* Verify amount of memory available, complaining if we're near the end. */ |
734 | 159 |
1416
60bb5e719468
(morecore_with_warning): Removed.
Roland McGrath <roland@gnu.org>
parents:
1400
diff
changeset
|
160 static void |
60bb5e719468
(morecore_with_warning): Removed.
Roland McGrath <roland@gnu.org>
parents:
1400
diff
changeset
|
161 check_memory_limits () |
734 | 162 { |
30062
9a026d470bc9
(check_memory_limits) [REL_ALLOC]: Use real_morecore
Andrew Innes <andrewi@gnu.org>
parents:
24366
diff
changeset
|
163 #ifdef REL_ALLOC |
9a026d470bc9
(check_memory_limits) [REL_ALLOC]: Use real_morecore
Andrew Innes <andrewi@gnu.org>
parents:
24366
diff
changeset
|
164 extern POINTER (*real_morecore) (); |
9a026d470bc9
(check_memory_limits) [REL_ALLOC]: Use real_morecore
Andrew Innes <andrewi@gnu.org>
parents:
24366
diff
changeset
|
165 #endif |
1417
3a1576d52874
(check_memory_limits): Declare __morecore.
Roland McGrath <roland@gnu.org>
parents:
1416
diff
changeset
|
166 extern POINTER (*__morecore) (); |
3a1576d52874
(check_memory_limits): Declare __morecore.
Roland McGrath <roland@gnu.org>
parents:
1416
diff
changeset
|
167 |
734 | 168 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
|
169 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
|
170 unsigned long data_size; |
69390
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
171 enum warnlevel new_warnlevel; |
734 | 172 |
173 if (lim_data == 0) | |
174 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
|
175 five_percent = lim_data / 20; |
734 | 176 |
177 /* 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
|
178 #ifdef REL_ALLOC |
9a026d470bc9
(check_memory_limits) [REL_ALLOC]: Use real_morecore
Andrew Innes <andrewi@gnu.org>
parents:
24366
diff
changeset
|
179 if (real_morecore) |
9a026d470bc9
(check_memory_limits) [REL_ALLOC]: Use real_morecore
Andrew Innes <andrewi@gnu.org>
parents:
24366
diff
changeset
|
180 cp = (char *) (*real_morecore) (0); |
9a026d470bc9
(check_memory_limits) [REL_ALLOC]: Use real_morecore
Andrew Innes <andrewi@gnu.org>
parents:
24366
diff
changeset
|
181 else |
9a026d470bc9
(check_memory_limits) [REL_ALLOC]: Use real_morecore
Andrew Innes <andrewi@gnu.org>
parents:
24366
diff
changeset
|
182 #endif |
1416
60bb5e719468
(morecore_with_warning): Removed.
Roland McGrath <roland@gnu.org>
parents:
1400
diff
changeset
|
183 cp = (char *) (*__morecore) (0); |
1400
af08281c0cbe
(warnfunction): Renamed to warn_function (was used inconsistently).
Roland McGrath <roland@gnu.org>
parents:
1398
diff
changeset
|
184 data_size = (char *) cp - (char *) data_space_start; |
734 | 185 |
69390
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
186 if (!warn_function) |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
187 return; |
734 | 188 |
69390
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
189 /* What level of warning does current memory usage demand? */ |
80673
f6abfb31fb9c
(check_memory_limits): Don't use getrlimit on cygwin. Don't use
Chong Yidong <cyd@stupidchicken.com>
parents:
79759
diff
changeset
|
190 new_warnlevel |
f6abfb31fb9c
(check_memory_limits): Don't use getrlimit on cygwin. Don't use
Chong Yidong <cyd@stupidchicken.com>
parents:
79759
diff
changeset
|
191 = (data_size > five_percent * 19) ? warned_95 |
f6abfb31fb9c
(check_memory_limits): Don't use getrlimit on cygwin. Don't use
Chong Yidong <cyd@stupidchicken.com>
parents:
79759
diff
changeset
|
192 : (data_size > five_percent * 17) ? warned_85 |
f6abfb31fb9c
(check_memory_limits): Don't use getrlimit on cygwin. Don't use
Chong Yidong <cyd@stupidchicken.com>
parents:
79759
diff
changeset
|
193 : (data_size > five_percent * 15) ? warned_75 |
f6abfb31fb9c
(check_memory_limits): Don't use getrlimit on cygwin. Don't use
Chong Yidong <cyd@stupidchicken.com>
parents:
79759
diff
changeset
|
194 : not_warned; |
69390
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
195 |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
196 /* If we have gone up a level, give the appropriate warning. */ |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
197 if (new_warnlevel > warnlevel || new_warnlevel == warned_95) |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
198 { |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
199 warnlevel = new_warnlevel; |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
200 switch (warnlevel) |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
201 { |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
202 case warned_75: |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
203 (*warn_function) ("Warning: past 75% of memory limit"); |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
204 break; |
734 | 205 |
69390
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
206 case warned_85: |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
207 (*warn_function) ("Warning: past 85% of memory limit"); |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
208 break; |
734 | 209 |
69390
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
210 case warned_95: |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
211 (*warn_function) ("Warning: past 95% of memory limit"); |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
212 } |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
213 } |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
214 /* Handle going down in usage levels, with some hysteresis. */ |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
215 else |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
216 { |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
217 /* If we go down below 70% full, issue another 75% warning |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
218 when we go up again. */ |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
219 if (data_size < five_percent * 14) |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
220 warnlevel = not_warned; |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
221 /* If we go down below 80% full, issue another 85% warning |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
222 when we go up again. */ |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
223 else if (warnlevel > warned_75 && data_size < five_percent * 16) |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
224 warnlevel = warned_75; |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
225 /* If we go down below 90% full, issue another 95% warning |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
226 when we go up again. */ |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
227 else if (warnlevel > warned_85 && data_size < five_percent * 18) |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
228 warnlevel = warned_85; |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
229 } |
1392
ad64a94cd81c
(morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
734
diff
changeset
|
230 |
ad64a94cd81c
(morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
734
diff
changeset
|
231 if (EXCEEDS_LISP_PTR (cp)) |
1400
af08281c0cbe
(warnfunction): Renamed to warn_function (was used inconsistently).
Roland McGrath <roland@gnu.org>
parents:
1398
diff
changeset
|
232 (*warn_function) ("Warning: memory in use exceeds lisp pointer size"); |
734 | 233 } |
69390
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
234 |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
235 /* Enable memory usage warnings. |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
236 START says where the end of pure storage is. |
7e58bc915ffe
(get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents:
69019
diff
changeset
|
237 WARNFUN specifies the function to call to issue a warning. */ |
734 | 238 |
239 void | |
1392
ad64a94cd81c
(morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
734
diff
changeset
|
240 memory_warnings (start, warnfun) |
734 | 241 POINTER start; |
242 void (*warnfun) (); | |
243 { | |
1416
60bb5e719468
(morecore_with_warning): Removed.
Roland McGrath <roland@gnu.org>
parents:
1400
diff
changeset
|
244 extern void (* __after_morecore_hook) (); /* From gmalloc.c */ |
734 | 245 |
246 if (start) | |
247 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
|
248 else |
ad64a94cd81c
(morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
734
diff
changeset
|
249 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
|
250 |
1400
af08281c0cbe
(warnfunction): Renamed to warn_function (was used inconsistently).
Roland McGrath <roland@gnu.org>
parents:
1398
diff
changeset
|
251 warn_function = warnfun; |
1416
60bb5e719468
(morecore_with_warning): Removed.
Roland McGrath <roland@gnu.org>
parents:
1400
diff
changeset
|
252 __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
|
253 |
274b79aeb3b7
(memory_warnings) [WINDOWSNT]: Reset lim_data on each
Andrew Innes <andrewi@gnu.org>
parents:
14186
diff
changeset
|
254 /* 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
|
255 lim_data = 0; |
734 | 256 } |
52401 | 257 |
258 /* arch-tag: eab04eda-1f69-447a-8d9f-95f0a3983ca5 | |
259 (do not change this comment) */ |