Mercurial > hg > nginx-quic
annotate src/core/ngx_palloc.c @ 5668:64958ea92fd2
Missed comma fixed. A couple of Latin symbols plugged into
Russian text changed to Russian counterparts.
author | Maxim Konovalov <maxim@nginx.com> |
---|---|
date | Wed, 23 Apr 2014 16:00:59 +0000 |
parents | 320abeb364e6 |
children | c45c9812cf11 |
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; |
2049 | 184 ngx_pool_t *p, *new, *current; |
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 | |
2049 | 203 current = pool->current; |
204 | |
205 for (p = 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
|
206 if (p->d.failed++ > 4) { |
2049 | 207 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
|
208 } |
2049 | 209 } |
194
2357fa41738a
nginx-0.0.1-2003-11-21-09:30:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
210 |
2049 | 211 p->d.next = new; |
212 | |
213 pool->current = current ? current : new; | |
581 | 214 |
2049 | 215 return m; |
216 } | |
156
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
217 |
2049 | 218 |
219 static void * | |
220 ngx_palloc_large(ngx_pool_t *pool, size_t size) | |
221 { | |
222 void *p; | |
2917
62010fa37ead
try to reuse last 4 free large allocation links
Igor Sysoev <igor@sysoev.ru>
parents:
2592
diff
changeset
|
223 ngx_uint_t n; |
2049 | 224 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
|
225 |
3328
c16e1213bf96
large allocation should not be aligned to a page size
Igor Sysoev <igor@sysoev.ru>
parents:
3177
diff
changeset
|
226 p = ngx_alloc(size, pool->log); |
501 | 227 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
|
228 return NULL; |
f48d579daf78
nginx-0.0.3-2004-06-08-20:26:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
229 } |
2129 | 230 |
2917
62010fa37ead
try to reuse last 4 free large allocation links
Igor Sysoev <igor@sysoev.ru>
parents:
2592
diff
changeset
|
231 n = 0; |
62010fa37ead
try to reuse last 4 free large allocation links
Igor Sysoev <igor@sysoev.ru>
parents:
2592
diff
changeset
|
232 |
62010fa37ead
try to reuse last 4 free large allocation links
Igor Sysoev <igor@sysoev.ru>
parents:
2592
diff
changeset
|
233 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
|
234 if (large->alloc == NULL) { |
62010fa37ead
try to reuse last 4 free large allocation links
Igor Sysoev <igor@sysoev.ru>
parents:
2592
diff
changeset
|
235 large->alloc = p; |
62010fa37ead
try to reuse last 4 free large allocation links
Igor Sysoev <igor@sysoev.ru>
parents:
2592
diff
changeset
|
236 return p; |
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 if (n++ > 3) { |
62010fa37ead
try to reuse last 4 free large allocation links
Igor Sysoev <igor@sysoev.ru>
parents:
2592
diff
changeset
|
240 break; |
62010fa37ead
try to reuse last 4 free large allocation links
Igor Sysoev <igor@sysoev.ru>
parents:
2592
diff
changeset
|
241 } |
62010fa37ead
try to reuse last 4 free large allocation links
Igor Sysoev <igor@sysoev.ru>
parents:
2592
diff
changeset
|
242 } |
62010fa37ead
try to reuse last 4 free large allocation links
Igor Sysoev <igor@sysoev.ru>
parents:
2592
diff
changeset
|
243 |
2129 | 244 large = ngx_palloc(pool, sizeof(ngx_pool_large_t)); |
245 if (large == NULL) { | |
246 ngx_free(p); | |
247 return NULL; | |
248 } | |
249 | |
250 large->alloc = p; | |
251 large->next = pool->large; | |
252 pool->large = large; | |
253 | |
254 return p; | |
255 } | |
256 | |
257 | |
258 void * | |
259 ngx_pmemalign(ngx_pool_t *pool, size_t size, size_t alignment) | |
260 { | |
261 void *p; | |
262 ngx_pool_large_t *large; | |
263 | |
264 p = ngx_memalign(alignment, size, pool->log); | |
265 if (p == NULL) { | |
266 return NULL; | |
267 } | |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
268 |
629 | 269 large = ngx_palloc(pool, sizeof(ngx_pool_large_t)); |
270 if (large == NULL) { | |
1317 | 271 ngx_free(p); |
629 | 272 return NULL; |
156
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
273 } |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
274 |
156
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
275 large->alloc = p; |
629 | 276 large->next = pool->large; |
277 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
|
278 |
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
279 return p; |
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
280 } |
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
281 |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
282 |
501 | 283 ngx_int_t |
284 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
|
285 { |
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
286 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
|
287 |
156
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
288 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
|
289 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
|
290 ngx_log_debug1(NGX_LOG_DEBUG_ALLOC, pool->log, 0, |
461 | 291 "free: %p", l->alloc); |
477 | 292 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
|
293 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
|
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_OK; |
156
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
296 } |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
297 } |
436
9549fc9508e5
nginx-0.0.11-2004-09-23-10:32:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
429
diff
changeset
|
298 |
9549fc9508e5
nginx-0.0.11-2004-09-23-10:32:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
429
diff
changeset
|
299 return NGX_DECLINED; |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
300 } |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
301 |
156
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
302 |
501 | 303 void * |
304 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
|
305 { |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
306 void *p; |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
307 |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
308 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
|
309 if (p) { |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
310 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
|
311 } |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
312 |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
313 return p; |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
314 } |
346
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
315 |
509 | 316 |
317 ngx_pool_cleanup_t * | |
563 | 318 ngx_pool_cleanup_add(ngx_pool_t *p, size_t size) |
509 | 319 { |
320 ngx_pool_cleanup_t *c; | |
321 | |
322 c = ngx_palloc(p, sizeof(ngx_pool_cleanup_t)); | |
323 if (c == NULL) { | |
324 return NULL; | |
325 } | |
326 | |
563 | 327 if (size) { |
328 c->data = ngx_palloc(p, size); | |
329 if (c->data == NULL) { | |
330 return NULL; | |
331 } | |
332 | |
333 } else { | |
334 c->data = NULL; | |
335 } | |
336 | |
337 c->handler = NULL; | |
509 | 338 c->next = p->cleanup; |
339 | |
340 p->cleanup = c; | |
341 | |
563 | 342 ngx_log_debug1(NGX_LOG_DEBUG_ALLOC, p->log, 0, "add cleanup: %p", c); |
343 | |
509 | 344 return c; |
345 } | |
346 | |
347 | |
348 void | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2337
diff
changeset
|
349 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
|
350 { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2337
diff
changeset
|
351 ngx_pool_cleanup_t *c; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2337
diff
changeset
|
352 ngx_pool_cleanup_file_t *cf; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2337
diff
changeset
|
353 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2337
diff
changeset
|
354 for (c = p->cleanup; c; c = c->next) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2337
diff
changeset
|
355 if (c->handler == ngx_pool_cleanup_file) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2337
diff
changeset
|
356 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2337
diff
changeset
|
357 cf = c->data; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2337
diff
changeset
|
358 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2337
diff
changeset
|
359 if (cf->fd == fd) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2337
diff
changeset
|
360 c->handler(cf); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2337
diff
changeset
|
361 c->handler = NULL; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2337
diff
changeset
|
362 return; |
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 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2337
diff
changeset
|
366 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2337
diff
changeset
|
367 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2337
diff
changeset
|
368 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2337
diff
changeset
|
369 void |
509 | 370 ngx_pool_cleanup_file(void *data) |
371 { | |
372 ngx_pool_cleanup_file_t *c = data; | |
373 | |
1744 | 374 ngx_log_debug1(NGX_LOG_DEBUG_ALLOC, c->log, 0, "file cleanup: fd:%d", |
375 c->fd); | |
563 | 376 |
509 | 377 if (ngx_close_file(c->fd) == NGX_FILE_ERROR) { |
378 ngx_log_error(NGX_LOG_ALERT, c->log, ngx_errno, | |
379 ngx_close_file_n " \"%s\" failed", c->name); | |
380 } | |
381 } | |
382 | |
383 | |
1075
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
384 void |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
385 ngx_pool_delete_file(void *data) |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
386 { |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
387 ngx_pool_cleanup_file_t *c = data; |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
388 |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
389 ngx_err_t err; |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
390 |
1744 | 391 ngx_log_debug2(NGX_LOG_DEBUG_ALLOC, c->log, 0, "file cleanup: fd:%d %s", |
392 c->fd, c->name); | |
1075
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
393 |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
394 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
|
395 err = ngx_errno; |
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 if (err != NGX_ENOENT) { |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
398 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
|
399 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
|
400 } |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
401 } |
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 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
|
404 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
|
405 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
|
406 } |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
407 } |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
408 |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
409 |
346
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
410 #if 0 |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
411 |
501 | 412 static void * |
413 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
|
414 { |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
415 void *p; |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
416 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
|
417 |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
418 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
|
419 return NULL; |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
420 } |
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 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
|
423 |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
424 slot->tries++; |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
425 |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
426 if (slot->number) { |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
427 p = slot->block; |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
428 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
|
429 slot->number--; |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
430 return p; |
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 |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
433 return NULL; |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
434 } |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
435 |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
436 #endif |