Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 484 lines (425 sloc) 11.843 kB
aa4ade4 @agentzh checked in the patch for nginx 1.1.2.
agentzh authored
1 diff -ur nginx-1.1.2/src/core/nginx.h nginx-1.1.2-no-pool/src/core/nginx.h
2 --- nginx-1.1.2/src/core/nginx.h 2011-05-26 15:31:40.000000000 +0800
3 +++ nginx-1.1.2-no-pool/src/core/nginx.h 2011-06-30 17:00:43.540946999 +0800
4 @@ -9,7 +9,7 @@
5
6
7 #define nginx_version 1001002
8 -#define NGINX_VERSION "1.1.2"
9 +#define NGINX_VERSION "1.1.2 (without pool)"
10 #define NGINX_VER "nginx/" NGINX_VERSION
11
12 #define NGINX_VAR "NGINX"
13 diff -ur nginx-1.1.2/src/core/ngx_array.c nginx-1.1.2-no-pool/src/core/ngx_array.c
14 --- nginx-1.1.2/src/core/ngx_array.c 2008-06-17 23:00:30.000000000 +0800
15 +++ nginx-1.1.2-no-pool/src/core/ngx_array.c 2011-06-30 17:00:43.540946999 +0800
16 @@ -39,13 +39,7 @@
17
18 p = a->pool;
19
20 - if ((u_char *) a->elts + a->size * a->nalloc == p->d.last) {
21 - p->d.last -= a->size * a->nalloc;
22 - }
23 -
24 - if ((u_char *) a + sizeof(ngx_array_t) == p->d.last) {
25 - p->d.last = (u_char *) a;
26 - }
27 + ngx_pfree(p, a);
28 }
29
30
31 @@ -64,29 +58,17 @@
32
33 p = a->pool;
34
35 - if ((u_char *) a->elts + size == p->d.last
36 - && p->d.last + a->size <= p->d.end)
37 - {
38 - /*
39 - * the array allocation is the last in the pool
40 - * and there is space for new allocation
41 - */
42 -
43 - p->d.last += a->size;
44 - a->nalloc++;
45 -
46 - } else {
47 - /* allocate a new array */
48 -
49 - new = ngx_palloc(p, 2 * size);
50 - if (new == NULL) {
51 - return NULL;
52 - }
53 -
54 - ngx_memcpy(new, a->elts, size);
55 - a->elts = new;
56 - a->nalloc *= 2;
57 + /* allocate a new array */
58 +
59 + new = ngx_palloc(p, 2 * size);
60 + if (new == NULL) {
61 + return NULL;
62 }
63 +
64 + ngx_memcpy(new, a->elts, size);
65 + a->elts = new;
66 + a->nalloc *= 2;
67 +
68 }
69
70 elt = (u_char *) a->elts + a->size * a->nelts;
71 @@ -112,31 +94,16 @@
72
73 p = a->pool;
74
75 - if ((u_char *) a->elts + a->size * a->nalloc == p->d.last
76 - && p->d.last + size <= p->d.end)
77 - {
78 - /*
79 - * the array allocation is the last in the pool
80 - * and there is space for new allocation
81 - */
82 -
83 - p->d.last += size;
84 - a->nalloc += n;
85 -
86 - } else {
87 - /* allocate a new array */
88 -
89 - nalloc = 2 * ((n >= a->nalloc) ? n : a->nalloc);
90 -
91 - new = ngx_palloc(p, nalloc * a->size);
92 - if (new == NULL) {
93 - return NULL;
94 - }
95 -
96 - ngx_memcpy(new, a->elts, a->nelts * a->size);
97 - a->elts = new;
98 - a->nalloc = nalloc;
99 + nalloc = 2 * ((n >= a->nalloc) ? n : a->nalloc);
100 +
101 + new = ngx_palloc(p, nalloc * a->size);
102 + if (new == NULL) {
103 + return NULL;
104 }
105 +
106 + ngx_memcpy(new, a->elts, a->nelts * a->size);
107 + a->elts = new;
108 + a->nalloc = nalloc;
109 }
110
111 elt = (u_char *) a->elts + a->size * a->nelts;
112 diff -ur nginx-1.1.2/src/core/ngx_palloc.c nginx-1.1.2-no-pool/src/core/ngx_palloc.c
113 --- nginx-1.1.2/src/core/ngx_palloc.c 2009-12-17 20:25:46.000000000 +0800
114 +++ nginx-1.1.2-no-pool/src/core/ngx_palloc.c 2011-06-30 17:06:36.060946999 +0800
115 @@ -8,24 +8,31 @@
116 #include <ngx_core.h>
117
118
119 -static void *ngx_palloc_block(ngx_pool_t *pool, size_t size);
120 static void *ngx_palloc_large(ngx_pool_t *pool, size_t size);
121
122
123 ngx_pool_t *
124 ngx_create_pool(size_t size, ngx_log_t *log)
125 {
126 - ngx_pool_t *p;
127 + ngx_pool_t *p;
128 + ngx_pool_data_t *d;
129
130 - p = ngx_memalign(NGX_POOL_ALIGNMENT, size, log);
131 + size = sizeof(ngx_pool_t);
132 + p = ngx_alloc(size, log);
133 if (p == NULL) {
134 return NULL;
135 }
136
137 - p->d.last = (u_char *) p + sizeof(ngx_pool_t);
138 - p->d.end = (u_char *) p + size;
139 - p->d.next = NULL;
140 - p->d.failed = 0;
141 + d = ngx_alloc(sizeof(ngx_pool_data_t), log);
142 +
143 + if (d == NULL) {
144 + return NULL;
145 + }
146 +
147 + d->next = d;
148 + d->prev = d;
149 + d->alloc = NULL;
150 + p->d = d;
151
152 size = size - sizeof(ngx_pool_t);
153 p->max = (size < NGX_MAX_ALLOC_FROM_POOL) ? size : NGX_MAX_ALLOC_FROM_POOL;
154 @@ -43,7 +50,7 @@
155 void
156 ngx_destroy_pool(ngx_pool_t *pool)
157 {
158 - ngx_pool_t *p, *n;
159 + ngx_pool_data_t *d, *n;
160 ngx_pool_large_t *l;
161 ngx_pool_cleanup_t *c;
162
163 @@ -55,7 +62,7 @@
164 }
165 }
166
167 - for (l = pool->large; l; l = l->next) {
168 + for (l = pool->large; l ; l = l->next) {
169
170 ngx_log_debug1(NGX_LOG_DEBUG_ALLOC, pool->log, 0, "free: %p", l->alloc);
171
172 @@ -71,34 +78,45 @@
173 * so we can not use this log while the free()ing the pool
174 */
175
176 - for (p = pool, n = pool->d.next; /* void */; p = n, n = n->d.next) {
177 + for (d = pool->d, n = d->next; ; d = n, n = n->next) {
178 ngx_log_debug2(NGX_LOG_DEBUG_ALLOC, pool->log, 0,
179 - "free: %p, unused: %uz", p, p->d.end - p->d.last);
180 + "free: %p", d);
181
182 - if (n == NULL) {
183 + if (n == pool->d) {
184 break;
185 }
186 }
187
188 #endif
189 + if (pool->d->next == pool->d) {
190 + ngx_free(pool->d);
191 + } else {
192 + for (d = pool->d, n = d->next; ; d = n, n = n->next) {
193 + if (d->alloc) {
194 + ngx_free(d->alloc);
195 + }
196 + ngx_free(d);
197
198 - for (p = pool, n = pool->d.next; /* void */; p = n, n = n->d.next) {
199 - ngx_free(p);
200 -
201 - if (n == NULL) {
202 - break;
203 + if (n == pool->d) {
204 + break;
205 + }
206 }
207 }
208 +
209 + ngx_free(pool);
210 }
211
212
213 void
214 ngx_reset_pool(ngx_pool_t *pool)
215 {
216 - ngx_pool_t *p;
217 - ngx_pool_large_t *l;
218 + ngx_pool_data_t *p, *tmp;
219 + ngx_pool_large_t *l;
220 +
221 + for (l = pool->large; l ; l = l->next) {
222 +
223 + ngx_log_debug1(NGX_LOG_DEBUG_ALLOC, pool->log, 0, "free: %p", l->alloc);
224
225 - for (l = pool->large; l; l = l->next) {
226 if (l->alloc) {
227 ngx_free(l->alloc);
228 }
229 @@ -106,109 +124,65 @@
230
231 pool->large = NULL;
232
233 - for (p = pool; p; p = p->d.next) {
234 - p->d.last = (u_char *) p + sizeof(ngx_pool_t);
235 + p = pool->d->next;
236 + while (p != pool->d) {
237 + tmp = p;
238 + ngx_free(p->alloc);
239 + p->prev->next = p->next;
240 + p->next->prev = p->prev;
241 + p = p->next;
242 + ngx_free(tmp);
243 }
244 -}
245
246 + ngx_free(pool->d->alloc);
247 + pool->d->alloc = NULL;
248 +
249 +}
250
251 void *
252 -ngx_palloc(ngx_pool_t *pool, size_t size)
253 +ngx_malloc(ngx_pool_t *pool, size_t size)
254 {
255 - u_char *m;
256 - ngx_pool_t *p;
257 -
258 - if (size <= pool->max) {
259 + ngx_pool_data_t *new;
260 + void *m;
261
262 - p = pool->current;
263 -
264 - do {
265 - m = ngx_align_ptr(p->d.last, NGX_ALIGNMENT);
266 -
267 - if ((size_t) (p->d.end - m) >= size) {
268 - p->d.last = m + size;
269 -
270 - return m;
271 - }
272 -
273 - p = p->d.next;
274 -
275 - } while (p);
276 + m = ngx_alloc(size, pool->log);
277 + if (m == NULL) {
278 + return NULL;
279 + }
280
281 - return ngx_palloc_block(pool, size);
282 + new = ngx_alloc(sizeof(ngx_pool_data_t), pool->log);
283 + if (new == NULL){
284 + ngx_free(m);
285 + return NULL;
286 }
287
288 - return ngx_palloc_large(pool, size);
289 + new->alloc = m;
290 + new->next = pool->d;
291 + new->prev = pool->d->prev;
292 + pool->d->prev->next = new;
293 + pool->d->prev = new;
294 + return m;
295 }
296
297 -
298 void *
299 -ngx_pnalloc(ngx_pool_t *pool, size_t size)
300 +ngx_palloc(ngx_pool_t *pool, size_t size)
301 {
302 - u_char *m;
303 - ngx_pool_t *p;
304 -
305 - if (size <= pool->max) {
306 -
307 - p = pool->current;
308 -
309 - do {
310 - m = p->d.last;
311 -
312 - if ((size_t) (p->d.end - m) >= size) {
313 - p->d.last = m + size;
314 -
315 - return m;
316 - }
317 -
318 - p = p->d.next;
319 -
320 - } while (p);
321 -
322 - return ngx_palloc_block(pool, size);
323 + if (size <= 1024) {
324 + return ngx_malloc(pool, size);
325 }
326
327 return ngx_palloc_large(pool, size);
328 }
329
330
331 -static void *
332 -ngx_palloc_block(ngx_pool_t *pool, size_t size)
333 +void *
334 +ngx_pnalloc(ngx_pool_t *pool, size_t size)
335 {
336 - u_char *m;
337 - size_t psize;
338 - ngx_pool_t *p, *new, *current;
339 -
340 - psize = (size_t) (pool->d.end - (u_char *) pool);
341 -
342 - m = ngx_memalign(NGX_POOL_ALIGNMENT, psize, pool->log);
343 - if (m == NULL) {
344 - return NULL;
345 + if (size <= 1024) {
346 + return ngx_malloc(pool, size);
347 }
348
349 - new = (ngx_pool_t *) m;
350 -
351 - new->d.end = m + psize;
352 - new->d.next = NULL;
353 - new->d.failed = 0;
354 -
355 - m += sizeof(ngx_pool_data_t);
356 - m = ngx_align_ptr(m, NGX_ALIGNMENT);
357 - new->d.last = m + size;
358 -
359 - current = pool->current;
360 -
361 - for (p = current; p->d.next; p = p->d.next) {
362 - if (p->d.failed++ > 4) {
363 - current = p->d.next;
364 - }
365 - }
366 -
367 - p->d.next = new;
368 -
369 - pool->current = current ? current : new;
370 -
371 - return m;
372 + return ngx_palloc_large(pool, size);
373 }
374
375
376 @@ -226,18 +200,7 @@
377
378 n = 0;
379
380 - for (large = pool->large; large; large = large->next) {
381 - if (large->alloc == NULL) {
382 - large->alloc = p;
383 - return p;
384 - }
385 -
386 - if (n++ > 3) {
387 - break;
388 - }
389 - }
390 -
391 - large = ngx_palloc(pool, sizeof(ngx_pool_large_t));
392 + large = ngx_malloc(pool, sizeof(ngx_pool_large_t));
393 if (large == NULL) {
394 ngx_free(p);
395 return NULL;
396 @@ -262,7 +225,7 @@
397 return NULL;
398 }
399
400 - large = ngx_palloc(pool, sizeof(ngx_pool_large_t));
401 + large = ngx_malloc(pool, sizeof(ngx_pool_large_t));
402 if (large == NULL) {
403 ngx_free(p);
404 return NULL;
405 @@ -279,17 +242,41 @@
406 ngx_int_t
407 ngx_pfree(ngx_pool_t *pool, void *p)
408 {
409 - ngx_pool_large_t *l;
410 + ngx_pool_large_t *l;
411 + ngx_pool_large_t *ll;
412 + ngx_pool_data_t *d, *n;
413
414 - for (l = pool->large; l; l = l->next) {
415 + for (l = pool->large, ll = l; l; ll = l, l = l->next) {
416 if (p == l->alloc) {
417 ngx_log_debug1(NGX_LOG_DEBUG_ALLOC, pool->log, 0,
418 "free: %p", l->alloc);
419 ngx_free(l->alloc);
420 l->alloc = NULL;
421 + if (l == pool->large) {
422 + pool->large = NULL;
423 + }
424 +
425 + ll->next = l->next;
426 + p = l;
427 + break;
428 + }
429 + }
430
431 + for (d = pool->d, n = d->next; ; d = n, n = d->next) {
432 + if (p == d->alloc) {
433 + ngx_log_debug1(NGX_LOG_DEBUG_ALLOC, pool->log, 0, "free: %p", d->alloc);
434 + if (d->alloc) {
435 + ngx_free(d->alloc);
436 + }
437 + d->alloc = NULL;
438 + d->prev->next = d->next;
439 + d->next->prev = d->prev;
440 + ngx_free(d);
441 return NGX_OK;
442 }
443 + if (d->next == pool->d) {
444 + break;
445 + }
446 }
447
448 return NGX_DECLINED;
449 Only in nginx-1.1.2-no-pool/src/core: ngx_palloc.c~
450 diff -ur nginx-1.1.2/src/core/ngx_palloc.h nginx-1.1.2-no-pool/src/core/ngx_palloc.h
451 --- nginx-1.1.2/src/core/ngx_palloc.h 2009-12-17 20:25:46.000000000 +0800
452 +++ nginx-1.1.2-no-pool/src/core/ngx_palloc.h 2011-06-30 17:00:43.540946999 +0800
453 @@ -38,6 +38,7 @@
454
455
456 typedef struct ngx_pool_large_s ngx_pool_large_t;
457 +typedef struct ngx_pool_data_s ngx_pool_data_t;
458
459 struct ngx_pool_large_s {
460 ngx_pool_large_t *next;
461 @@ -45,16 +46,15 @@
462 };
463
464
465 -typedef struct {
466 - u_char *last;
467 - u_char *end;
468 - ngx_pool_t *next;
469 - ngx_uint_t failed;
470 -} ngx_pool_data_t;
471 +struct ngx_pool_data_s{
472 + ngx_pool_data_t *next;
473 + ngx_pool_data_t *prev;
474 + void *alloc;
475 +};
476
477
478 struct ngx_pool_s {
479 - ngx_pool_data_t d;
480 + ngx_pool_data_t *d;
481 size_t max;
482 ngx_pool_t *current;
483 ngx_chain_t *chain;
Something went wrong with that request. Please try again.