Mercurial > hg > nginx
annotate src/core/ngx_palloc.c @ 3513:e60e00b4fe0c
ngx_http_split_clients_module
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Fri, 14 May 2010 09:02:10 +0000 |
parents | d788521e4b0e |
children | 59b99f217c6d |
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 |
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
|
4 */ |
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 |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
6 |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 #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
|
8 #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
|
9 |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
10 |
2049 | 11 static void *ngx_palloc_block(ngx_pool_t *pool, size_t size); |
12 static void *ngx_palloc_large(ngx_pool_t *pool, size_t size); | |
13 | |
14 | |
501 | 15 ngx_pool_t * |
16 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
|
17 { |
194
2357fa41738a
nginx-0.0.1-2003-11-21-09:30:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
18 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
|
19 |
3388 | 20 p = ngx_memalign(NGX_POOL_ALIGNMENT, size, log); |
501 | 21 if (p == NULL) { |
527 | 22 return NULL; |
194
2357fa41738a
nginx-0.0.1-2003-11-21-09:30:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
23 } |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
24 |
2049 | 25 p->d.last = (u_char *) p + sizeof(ngx_pool_t); |
26 p->d.end = (u_char *) p + size; | |
27 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
|
28 p->d.failed = 0; |
2049 | 29 |
2057
24eebb21b5d2
fix max size allocated from pool
Igor Sysoev <igor@sysoev.ru>
parents:
2056
diff
changeset
|
30 size = size - sizeof(ngx_pool_t); |
24eebb21b5d2
fix max size allocated from pool
Igor Sysoev <igor@sysoev.ru>
parents:
2056
diff
changeset
|
31 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
|
32 |
581 | 33 p->current = p; |
34 p->chain = NULL; | |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
35 p->large = NULL; |
509 | 36 p->cleanup = NULL; |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
37 p->log = log; |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
38 |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
39 return p; |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
40 } |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
41 |
156
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
42 |
501 | 43 void |
44 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
|
45 { |
509 | 46 ngx_pool_t *p, *n; |
47 ngx_pool_large_t *l; | |
48 ngx_pool_cleanup_t *c; | |
49 | |
50 for (c = pool->cleanup; c; c = c->next) { | |
51 if (c->handler) { | |
1744 | 52 ngx_log_debug1(NGX_LOG_DEBUG_ALLOC, pool->log, 0, |
53 "run cleanup: %p", c); | |
509 | 54 c->handler(c->data); |
55 } | |
56 } | |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
57 |
10
4f3879d9b6f6
nginx-0.0.1-2002-09-11-19:18:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
7
diff
changeset
|
58 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
|
59 |
461 | 60 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
|
61 |
156
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
62 if (l->alloc) { |
477 | 63 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
|
64 } |
10
4f3879d9b6f6
nginx-0.0.1-2002-09-11-19:18:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
7
diff
changeset
|
65 } |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
66 |
257
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
194
diff
changeset
|
67 #if (NGX_DEBUG) |
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
194
diff
changeset
|
68 |
128
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
69 /* |
257
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
194
diff
changeset
|
70 * we could allocate the pool->log from this pool |
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
194
diff
changeset
|
71 * so we can not use this log while the 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
|
72 */ |
126
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
104
diff
changeset
|
73 |
2049 | 74 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
|
75 ngx_log_debug2(NGX_LOG_DEBUG_ALLOC, pool->log, 0, |
2049 | 76 "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
|
77 |
b27548f540ad
nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
128
diff
changeset
|
78 if (n == NULL) { |
b27548f540ad
nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
128
diff
changeset
|
79 break; |
b27548f540ad
nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
128
diff
changeset
|
80 } |
128
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
81 } |
257
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
194
diff
changeset
|
82 |
39
83fa61cd3d2f
nginx-0.0.1-2002-12-24-20:30:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
26
diff
changeset
|
83 #endif |
128
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
84 |
2049 | 85 for (p = pool, n = pool->d.next; /* void */; p = n, n = n->d.next) { |
477 | 86 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
|
87 |
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
88 if (n == NULL) { |
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
89 break; |
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
90 } |
126
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
104
diff
changeset
|
91 } |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
92 } |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
93 |
156
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
94 |
2337 | 95 void |
96 ngx_reset_pool(ngx_pool_t *pool) | |
97 { | |
98 ngx_pool_t *p; | |
99 ngx_pool_large_t *l; | |
100 | |
101 for (l = pool->large; l; l = l->next) { | |
102 if (l->alloc) { | |
103 ngx_free(l->alloc); | |
104 } | |
105 } | |
106 | |
107 pool->large = NULL; | |
108 | |
109 for (p = pool; p; p = p->d.next) { | |
110 p->d.last = (u_char *) p + sizeof(ngx_pool_t); | |
111 } | |
112 } | |
113 | |
114 | |
501 | 115 void * |
116 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
|
117 { |
2049 | 118 u_char *m; |
119 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
|
120 |
2049 | 121 if (size <= pool->max) { |
122 | |
931
87f456ff13b0
fix segfault in "out of memory" situation
Igor Sysoev <igor@sysoev.ru>
parents:
860
diff
changeset
|
123 p = pool->current; |
87f456ff13b0
fix segfault in "out of memory" situation
Igor Sysoev <igor@sysoev.ru>
parents:
860
diff
changeset
|
124 |
2049 | 125 do { |
126 m = ngx_align_ptr(p->d.last, NGX_ALIGNMENT); | |
589 | 127 |
2049 | 128 if ((size_t) (p->d.end - m) >= size) { |
129 p->d.last = m + size; | |
1207
103988cef757
use memory optimization for i386 and amd64 only:
Igor Sysoev <igor@sysoev.ru>
parents:
1075
diff
changeset
|
130 |
2049 | 131 return m; |
589 | 132 } |
104
7db96f59bc29
nginx-0.0.1-2003-06-12-09:54:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
133 |
2049 | 134 p = p->d.next; |
135 | |
136 } while (p); | |
137 | |
138 return ngx_palloc_block(pool, size); | |
139 } | |
140 | |
141 return ngx_palloc_large(pool, size); | |
142 } | |
143 | |
144 | |
145 void * | |
146 ngx_pnalloc(ngx_pool_t *pool, size_t size) | |
147 { | |
148 u_char *m; | |
149 ngx_pool_t *p; | |
150 | |
151 if (size <= pool->max) { | |
152 | |
153 p = pool->current; | |
154 | |
155 do { | |
156 m = p->d.last; | |
157 | |
158 if ((size_t) (p->d.end - m) >= size) { | |
159 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
|
160 |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
161 return m; |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
162 } |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
163 |
2049 | 164 p = p->d.next; |
165 | |
166 } while (p); | |
167 | |
168 return ngx_palloc_block(pool, size); | |
169 } | |
170 | |
171 return ngx_palloc_large(pool, size); | |
172 } | |
173 | |
581 | 174 |
2049 | 175 static void * |
176 ngx_palloc_block(ngx_pool_t *pool, size_t size) | |
177 { | |
178 u_char *m; | |
2055 | 179 size_t psize; |
2049 | 180 ngx_pool_t *p, *new, *current; |
931
87f456ff13b0
fix segfault in "out of memory" situation
Igor Sysoev <igor@sysoev.ru>
parents:
860
diff
changeset
|
181 |
2055 | 182 psize = (size_t) (pool->d.end - (u_char *) pool); |
183 | |
3388 | 184 m = ngx_memalign(NGX_POOL_ALIGNMENT, psize, pool->log); |
2056 | 185 if (m == NULL) { |
2049 | 186 return NULL; |
187 } | |
156
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
188 |
2056 | 189 new = (ngx_pool_t *) m; |
190 | |
191 new->d.end = m + psize; | |
2055 | 192 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
|
193 new->d.failed = 0; |
2055 | 194 |
2056 | 195 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
|
196 m = ngx_align_ptr(m, NGX_ALIGNMENT); |
2056 | 197 new->d.last = m + size; |
198 | |
2049 | 199 current = pool->current; |
200 | |
201 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
|
202 if (p->d.failed++ > 4) { |
2049 | 203 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
|
204 } |
2049 | 205 } |
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 p->d.next = new; |
208 | |
209 pool->current = current ? current : new; | |
581 | 210 |
2049 | 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 |