Mercurial > hg > nginx-quic
annotate src/core/ngx_palloc.c @ 5905:2f7e557eab5b
Cache: proxy_cache_lock_age and friends.
Once this age is reached, the cache lock is discarded and another
request can acquire the lock. Requests which failed to acquire
the lock are not allowed to cache the response.
author | Roman Arutyunyan <arut@nginx.com> |
---|---|
date | Tue, 18 Nov 2014 20:41:12 +0300 |
parents | c45c9812cf11 |
children | 6be7e59fdd2c |
rev | line source |
---|---|
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
436
diff
changeset
|
1 |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
436
diff
changeset
|
2 /* |
444
42d11f017717
nginx-0.1.0-2004-09-29-20:00:49 import; remove years from copyright
Igor Sysoev <igor@sysoev.ru>
parents:
441
diff
changeset
|
3 * Copyright (C) Igor Sysoev |
4412 | 4 * Copyright (C) Nginx, Inc. |
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
436
diff
changeset
|
5 */ |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
436
diff
changeset
|
6 |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
8 #include <ngx_config.h> |
100
7ebc8b7fb816
nginx-0.0.1-2003-06-03-19:42:58 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
9 #include <ngx_core.h> |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
10 |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
11 |
2049 | 12 static void *ngx_palloc_block(ngx_pool_t *pool, size_t size); |
13 static void *ngx_palloc_large(ngx_pool_t *pool, size_t size); | |
14 | |
15 | |
501 | 16 ngx_pool_t * |
17 ngx_create_pool(size_t size, ngx_log_t *log) | |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
18 { |
194
2357fa41738a
nginx-0.0.1-2003-11-21-09:30:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
19 ngx_pool_t *p; |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
20 |
3388 | 21 p = ngx_memalign(NGX_POOL_ALIGNMENT, size, log); |
501 | 22 if (p == NULL) { |
527 | 23 return NULL; |
194
2357fa41738a
nginx-0.0.1-2003-11-21-09:30:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
24 } |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
25 |
2049 | 26 p->d.last = (u_char *) p + sizeof(ngx_pool_t); |
27 p->d.end = (u_char *) p + size; | |
28 p->d.next = NULL; | |
2920
cb7d05c097db
do not test a pool block space if we can not allocated from the block 4 times
Igor Sysoev <igor@sysoev.ru>
parents:
2917
diff
changeset
|
29 p->d.failed = 0; |
2049 | 30 |
2057
24eebb21b5d2
fix max size allocated from pool
Igor Sysoev <igor@sysoev.ru>
parents:
2056
diff
changeset
|
31 size = size - sizeof(ngx_pool_t); |
24eebb21b5d2
fix max size allocated from pool
Igor Sysoev <igor@sysoev.ru>
parents:
2056
diff
changeset
|
32 p->max = (size < NGX_MAX_ALLOC_FROM_POOL) ? size : NGX_MAX_ALLOC_FROM_POOL; |
24eebb21b5d2
fix max size allocated from pool
Igor Sysoev <igor@sysoev.ru>
parents:
2056
diff
changeset
|
33 |
581 | 34 p->current = p; |
35 p->chain = NULL; | |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
36 p->large = NULL; |
509 | 37 p->cleanup = NULL; |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
38 p->log = log; |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
39 |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
40 return p; |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
41 } |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
42 |
156
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
43 |
501 | 44 void |
45 ngx_destroy_pool(ngx_pool_t *pool) | |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
46 { |
509 | 47 ngx_pool_t *p, *n; |
48 ngx_pool_large_t *l; | |
49 ngx_pool_cleanup_t *c; | |
50 | |
51 for (c = pool->cleanup; c; c = c->next) { | |
52 if (c->handler) { | |
1744 | 53 ngx_log_debug1(NGX_LOG_DEBUG_ALLOC, pool->log, 0, |
54 "run cleanup: %p", c); | |
509 | 55 c->handler(c->data); |
56 } | |
57 } | |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
58 |
10
4f3879d9b6f6
nginx-0.0.1-2002-09-11-19:18:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
7
diff
changeset
|
59 for (l = pool->large; l; l = l->next) { |
257
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
194
diff
changeset
|
60 |
461 | 61 ngx_log_debug1(NGX_LOG_DEBUG_ALLOC, pool->log, 0, "free: %p", l->alloc); |
257
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
194
diff
changeset
|
62 |
156
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
63 if (l->alloc) { |
477 | 64 ngx_free(l->alloc); |
156
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
65 } |
10
4f3879d9b6f6
nginx-0.0.1-2002-09-11-19:18:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
7
diff
changeset
|
66 } |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
67 |
257
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
194
diff
changeset
|
68 #if (NGX_DEBUG) |
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
194
diff
changeset
|
69 |
128
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
70 /* |
257
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
194
diff
changeset
|
71 * we could allocate the pool->log from this pool |
4133
59b99f217c6d
Replaced "can not" with "cannot" and "could not" in a bunch of places.
Ruslan Ermilov <ru@nginx.com>
parents:
3388
diff
changeset
|
72 * so we cannot use this log while free()ing the pool |
128
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
73 */ |
126
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
104
diff
changeset
|
74 |
2049 | 75 for (p = pool, n = pool->d.next; /* void */; p = n, n = n->d.next) { |
436
9549fc9508e5
nginx-0.0.11-2004-09-23-10:32:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
429
diff
changeset
|
76 ngx_log_debug2(NGX_LOG_DEBUG_ALLOC, pool->log, 0, |
2049 | 77 "free: %p, unused: %uz", p, p->d.end - p->d.last); |
133
b27548f540ad
nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
128
diff
changeset
|
78 |
b27548f540ad
nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
128
diff
changeset
|
79 if (n == NULL) { |
b27548f540ad
nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
128
diff
changeset
|
80 break; |
b27548f540ad
nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
128
diff
changeset
|
81 } |
128
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
82 } |
257
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
194
diff
changeset
|
83 |
39
83fa61cd3d2f
nginx-0.0.1-2002-12-24-20:30:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
26
diff
changeset
|
84 #endif |
128
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
85 |
2049 | 86 for (p = pool, n = pool->d.next; /* void */; p = n, n = n->d.next) { |
477 | 87 ngx_free(p); |
128
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
88 |
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
89 if (n == NULL) { |
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
90 break; |
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
91 } |
126
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
104
diff
changeset
|
92 } |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
93 } |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
94 |
156
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
95 |
2337 | 96 void |
97 ngx_reset_pool(ngx_pool_t *pool) | |
98 { | |
99 ngx_pool_t *p; | |
100 ngx_pool_large_t *l; | |
101 | |
102 for (l = pool->large; l; l = l->next) { | |
103 if (l->alloc) { | |
104 ngx_free(l->alloc); | |
105 } | |
106 } | |
107 | |
108 for (p = pool; p; p = p->d.next) { | |
109 p->d.last = (u_char *) p + sizeof(ngx_pool_t); | |
5521
320abeb364e6
Core: improved ngx_reset_pool() (ticket #490).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
110 p->d.failed = 0; |
2337 | 111 } |
5521
320abeb364e6
Core: improved ngx_reset_pool() (ticket #490).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
112 |
320abeb364e6
Core: improved ngx_reset_pool() (ticket #490).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
113 pool->current = pool; |
320abeb364e6
Core: improved ngx_reset_pool() (ticket #490).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
114 pool->chain = NULL; |
320abeb364e6
Core: improved ngx_reset_pool() (ticket #490).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
115 pool->large = NULL; |
2337 | 116 } |
117 | |
118 | |
501 | 119 void * |
120 ngx_palloc(ngx_pool_t *pool, size_t size) | |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
121 { |
2049 | 122 u_char *m; |
123 ngx_pool_t *p; | |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
124 |
2049 | 125 if (size <= pool->max) { |
126 | |
931
87f456ff13b0
fix segfault in "out of memory" situation
Igor Sysoev <igor@sysoev.ru>
parents:
860
diff
changeset
|
127 p = pool->current; |
87f456ff13b0
fix segfault in "out of memory" situation
Igor Sysoev <igor@sysoev.ru>
parents:
860
diff
changeset
|
128 |
2049 | 129 do { |
130 m = ngx_align_ptr(p->d.last, NGX_ALIGNMENT); | |
589 | 131 |
2049 | 132 if ((size_t) (p->d.end - m) >= size) { |
133 p->d.last = m + size; | |
1207
103988cef757
use memory optimization for i386 and amd64 only:
Igor Sysoev <igor@sysoev.ru>
parents:
1075
diff
changeset
|
134 |
2049 | 135 return m; |
589 | 136 } |
104
7db96f59bc29
nginx-0.0.1-2003-06-12-09:54:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
137 |
2049 | 138 p = p->d.next; |
139 | |
140 } while (p); | |
141 | |
142 return ngx_palloc_block(pool, size); | |
143 } | |
144 | |
145 return ngx_palloc_large(pool, size); | |
146 } | |
147 | |
148 | |
149 void * | |
150 ngx_pnalloc(ngx_pool_t *pool, size_t size) | |
151 { | |
152 u_char *m; | |
153 ngx_pool_t *p; | |
154 | |
155 if (size <= pool->max) { | |
156 | |
157 p = pool->current; | |
158 | |
159 do { | |
160 m = p->d.last; | |
161 | |
162 if ((size_t) (p->d.end - m) >= size) { | |
163 p->d.last = m + size; | |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
164 |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
165 return m; |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
166 } |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
167 |
2049 | 168 p = p->d.next; |
169 | |
170 } while (p); | |
171 | |
172 return ngx_palloc_block(pool, size); | |
173 } | |
174 | |
175 return ngx_palloc_large(pool, size); | |
176 } | |
177 | |
581 | 178 |
2049 | 179 static void * |
180 ngx_palloc_block(ngx_pool_t *pool, size_t size) | |
181 { | |
182 u_char *m; | |
2055 | 183 size_t psize; |
5742
c45c9812cf11
Core: removed meaningless check from ngx_palloc_block().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5521
diff
changeset
|
184 ngx_pool_t *p, *new; |
931
87f456ff13b0
fix segfault in "out of memory" situation
Igor Sysoev <igor@sysoev.ru>
parents:
860
diff
changeset
|
185 |
2055 | 186 psize = (size_t) (pool->d.end - (u_char *) pool); |
187 | |
3388 | 188 m = ngx_memalign(NGX_POOL_ALIGNMENT, psize, pool->log); |
2056 | 189 if (m == NULL) { |
2049 | 190 return NULL; |
191 } | |
156
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
192 |
2056 | 193 new = (ngx_pool_t *) m; |
194 | |
195 new->d.end = m + psize; | |
2055 | 196 new->d.next = NULL; |
2920
cb7d05c097db
do not test a pool block space if we can not allocated from the block 4 times
Igor Sysoev <igor@sysoev.ru>
parents:
2917
diff
changeset
|
197 new->d.failed = 0; |
2055 | 198 |
2056 | 199 m += sizeof(ngx_pool_data_t); |
2289
857c161d2768
align first allocation from additional pool block, this fixes bus error on sun4v
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
200 m = ngx_align_ptr(m, NGX_ALIGNMENT); |
2056 | 201 new->d.last = m + size; |
202 | |
5742
c45c9812cf11
Core: removed meaningless check from ngx_palloc_block().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5521
diff
changeset
|
203 for (p = pool->current; p->d.next; p = p->d.next) { |
2920
cb7d05c097db
do not test a pool block space if we can not allocated from the block 4 times
Igor Sysoev <igor@sysoev.ru>
parents:
2917
diff
changeset
|
204 if (p->d.failed++ > 4) { |
5742
c45c9812cf11
Core: removed meaningless check from ngx_palloc_block().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5521
diff
changeset
|
205 pool->current = p->d.next; |
194
2357fa41738a
nginx-0.0.1-2003-11-21-09:30:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
206 } |
2049 | 207 } |
194
2357fa41738a
nginx-0.0.1-2003-11-21-09:30:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
208 |
2049 | 209 p->d.next = new; |
210 | |
211 return m; | |
212 } | |
156
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
213 |
2049 | 214 |
215 static void * | |
216 ngx_palloc_large(ngx_pool_t *pool, size_t size) | |
217 { | |
218 void *p; | |
2917
62010fa37ead
try to reuse last 4 free large allocation links
Igor Sysoev <igor@sysoev.ru>
parents:
2592
diff
changeset
|
219 ngx_uint_t n; |
2049 | 220 ngx_pool_large_t *large; |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
221 |
3328
c16e1213bf96
large allocation should not be aligned to a page size
Igor Sysoev <igor@sysoev.ru>
parents:
3177
diff
changeset
|
222 p = ngx_alloc(size, pool->log); |
501 | 223 if (p == NULL) { |
347
f48d579daf78
nginx-0.0.3-2004-06-08-20:26:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
224 return NULL; |
f48d579daf78
nginx-0.0.3-2004-06-08-20:26:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
225 } |
2129 | 226 |
2917
62010fa37ead
try to reuse last 4 free large allocation links
Igor Sysoev <igor@sysoev.ru>
parents:
2592
diff
changeset
|
227 n = 0; |
62010fa37ead
try to reuse last 4 free large allocation links
Igor Sysoev <igor@sysoev.ru>
parents:
2592
diff
changeset
|
228 |
62010fa37ead
try to reuse last 4 free large allocation links
Igor Sysoev <igor@sysoev.ru>
parents:
2592
diff
changeset
|
229 for (large = pool->large; large; large = large->next) { |
62010fa37ead
try to reuse last 4 free large allocation links
Igor Sysoev <igor@sysoev.ru>
parents:
2592
diff
changeset
|
230 if (large->alloc == NULL) { |
62010fa37ead
try to reuse last 4 free large allocation links
Igor Sysoev <igor@sysoev.ru>
parents:
2592
diff
changeset
|
231 large->alloc = p; |
62010fa37ead
try to reuse last 4 free large allocation links
Igor Sysoev <igor@sysoev.ru>
parents:
2592
diff
changeset
|
232 return p; |
62010fa37ead
try to reuse last 4 free large allocation links
Igor Sysoev <igor@sysoev.ru>
parents:
2592
diff
changeset
|
233 } |
62010fa37ead
try to reuse last 4 free large allocation links
Igor Sysoev <igor@sysoev.ru>
parents:
2592
diff
changeset
|
234 |
62010fa37ead
try to reuse last 4 free large allocation links
Igor Sysoev <igor@sysoev.ru>
parents:
2592
diff
changeset
|
235 if (n++ > 3) { |
62010fa37ead
try to reuse last 4 free large allocation links
Igor Sysoev <igor@sysoev.ru>
parents:
2592
diff
changeset
|
236 break; |
62010fa37ead
try to reuse last 4 free large allocation links
Igor Sysoev <igor@sysoev.ru>
parents:
2592
diff
changeset
|
237 } |
62010fa37ead
try to reuse last 4 free large allocation links
Igor Sysoev <igor@sysoev.ru>
parents:
2592
diff
changeset
|
238 } |
62010fa37ead
try to reuse last 4 free large allocation links
Igor Sysoev <igor@sysoev.ru>
parents:
2592
diff
changeset
|
239 |
2129 | 240 large = ngx_palloc(pool, sizeof(ngx_pool_large_t)); |
241 if (large == NULL) { | |
242 ngx_free(p); | |
243 return NULL; | |
244 } | |
245 | |
246 large->alloc = p; | |
247 large->next = pool->large; | |
248 pool->large = large; | |
249 | |
250 return p; | |
251 } | |
252 | |
253 | |
254 void * | |
255 ngx_pmemalign(ngx_pool_t *pool, size_t size, size_t alignment) | |
256 { | |
257 void *p; | |
258 ngx_pool_large_t *large; | |
259 | |
260 p = ngx_memalign(alignment, size, pool->log); | |
261 if (p == NULL) { | |
262 return NULL; | |
263 } | |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
264 |
629 | 265 large = ngx_palloc(pool, sizeof(ngx_pool_large_t)); |
266 if (large == NULL) { | |
1317 | 267 ngx_free(p); |
629 | 268 return NULL; |
156
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
269 } |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
270 |
156
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
271 large->alloc = p; |
629 | 272 large->next = pool->large; |
273 pool->large = large; | |
156
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
274 |
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
275 return p; |
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
276 } |
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
277 |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
278 |
501 | 279 ngx_int_t |
280 ngx_pfree(ngx_pool_t *pool, void *p) | |
156
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
281 { |
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
282 ngx_pool_large_t *l; |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
283 |
156
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
284 for (l = pool->large; l; l = l->next) { |
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
285 if (p == l->alloc) { |
257
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
194
diff
changeset
|
286 ngx_log_debug1(NGX_LOG_DEBUG_ALLOC, pool->log, 0, |
461 | 287 "free: %p", l->alloc); |
477 | 288 ngx_free(l->alloc); |
156
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
289 l->alloc = NULL; |
436
9549fc9508e5
nginx-0.0.11-2004-09-23-10:32:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
429
diff
changeset
|
290 |
9549fc9508e5
nginx-0.0.11-2004-09-23-10:32:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
429
diff
changeset
|
291 return NGX_OK; |
156
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
292 } |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
293 } |
436
9549fc9508e5
nginx-0.0.11-2004-09-23-10:32:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
429
diff
changeset
|
294 |
9549fc9508e5
nginx-0.0.11-2004-09-23-10:32:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
429
diff
changeset
|
295 return NGX_DECLINED; |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
296 } |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
297 |
156
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
298 |
501 | 299 void * |
300 ngx_pcalloc(ngx_pool_t *pool, size_t size) | |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
301 { |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
302 void *p; |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
303 |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
304 p = ngx_palloc(pool, size); |
39
83fa61cd3d2f
nginx-0.0.1-2002-12-24-20:30:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
26
diff
changeset
|
305 if (p) { |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
306 ngx_memzero(p, size); |
39
83fa61cd3d2f
nginx-0.0.1-2002-12-24-20:30:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
26
diff
changeset
|
307 } |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
308 |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
309 return p; |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
310 } |
346
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
311 |
509 | 312 |
313 ngx_pool_cleanup_t * | |
563 | 314 ngx_pool_cleanup_add(ngx_pool_t *p, size_t size) |
509 | 315 { |
316 ngx_pool_cleanup_t *c; | |
317 | |
318 c = ngx_palloc(p, sizeof(ngx_pool_cleanup_t)); | |
319 if (c == NULL) { | |
320 return NULL; | |
321 } | |
322 | |
563 | 323 if (size) { |
324 c->data = ngx_palloc(p, size); | |
325 if (c->data == NULL) { | |
326 return NULL; | |
327 } | |
328 | |
329 } else { | |
330 c->data = NULL; | |
331 } | |
332 | |
333 c->handler = NULL; | |
509 | 334 c->next = p->cleanup; |
335 | |
336 p->cleanup = c; | |
337 | |
563 | 338 ngx_log_debug1(NGX_LOG_DEBUG_ALLOC, p->log, 0, "add cleanup: %p", c); |
339 | |
509 | 340 return c; |
341 } | |
342 | |
343 | |
344 void | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2337
diff
changeset
|
345 ngx_pool_run_cleanup_file(ngx_pool_t *p, ngx_fd_t fd) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2337
diff
changeset
|
346 { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2337
diff
changeset
|
347 ngx_pool_cleanup_t *c; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2337
diff
changeset
|
348 ngx_pool_cleanup_file_t *cf; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2337
diff
changeset
|
349 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2337
diff
changeset
|
350 for (c = p->cleanup; c; c = c->next) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2337
diff
changeset
|
351 if (c->handler == ngx_pool_cleanup_file) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2337
diff
changeset
|
352 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2337
diff
changeset
|
353 cf = c->data; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2337
diff
changeset
|
354 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2337
diff
changeset
|
355 if (cf->fd == fd) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2337
diff
changeset
|
356 c->handler(cf); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2337
diff
changeset
|
357 c->handler = NULL; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2337
diff
changeset
|
358 return; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2337
diff
changeset
|
359 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2337
diff
changeset
|
360 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2337
diff
changeset
|
361 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2337
diff
changeset
|
362 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2337
diff
changeset
|
363 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2337
diff
changeset
|
364 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2337
diff
changeset
|
365 void |
509 | 366 ngx_pool_cleanup_file(void *data) |
367 { | |
368 ngx_pool_cleanup_file_t *c = data; | |
369 | |
1744 | 370 ngx_log_debug1(NGX_LOG_DEBUG_ALLOC, c->log, 0, "file cleanup: fd:%d", |
371 c->fd); | |
563 | 372 |
509 | 373 if (ngx_close_file(c->fd) == NGX_FILE_ERROR) { |
374 ngx_log_error(NGX_LOG_ALERT, c->log, ngx_errno, | |
375 ngx_close_file_n " \"%s\" failed", c->name); | |
376 } | |
377 } | |
378 | |
379 | |
1075
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
380 void |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
381 ngx_pool_delete_file(void *data) |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
382 { |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
383 ngx_pool_cleanup_file_t *c = data; |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
384 |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
385 ngx_err_t err; |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
386 |
1744 | 387 ngx_log_debug2(NGX_LOG_DEBUG_ALLOC, c->log, 0, "file cleanup: fd:%d %s", |
388 c->fd, c->name); | |
1075
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
389 |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
390 if (ngx_delete_file(c->name) == NGX_FILE_ERROR) { |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
391 err = ngx_errno; |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
392 |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
393 if (err != NGX_ENOENT) { |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
394 ngx_log_error(NGX_LOG_CRIT, c->log, err, |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
395 ngx_delete_file_n " \"%s\" failed", c->name); |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
396 } |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
397 } |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
398 |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
399 if (ngx_close_file(c->fd) == NGX_FILE_ERROR) { |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
400 ngx_log_error(NGX_LOG_ALERT, c->log, ngx_errno, |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
401 ngx_close_file_n " \"%s\" failed", c->name); |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
402 } |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
403 } |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
404 |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
405 |
346
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
406 #if 0 |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
407 |
501 | 408 static void * |
409 ngx_get_cached_block(size_t size) | |
346
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
410 { |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
411 void *p; |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
412 ngx_cached_block_slot_t *slot; |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
413 |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
414 if (ngx_cycle->cache == NULL) { |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
415 return NULL; |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
416 } |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
417 |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
418 slot = &ngx_cycle->cache[(size + ngx_pagesize - 1) / ngx_pagesize]; |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
419 |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
420 slot->tries++; |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
421 |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
422 if (slot->number) { |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
423 p = slot->block; |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
424 slot->block = slot->block->next; |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
425 slot->number--; |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
426 return p; |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
427 } |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
428 |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
429 return NULL; |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
430 } |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
431 |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
432 #endif |