Mercurial > hg > nginx
comparison src/core/ngx_palloc.c @ 2939:7d8667499ddc stable-0.7
merge r2889, r2918, and r2921:
fix a pool growing and CPU usage for multi-requests keepalive connections:
*) keepalive_requests
*) try to reuse last 4 free large allocation links
*) do not test a pool block space if we can not allocated from
the block 4 times
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Mon, 15 Jun 2009 08:43:10 +0000 |
parents | 3a8a53c0c42f |
children |
comparison
equal
deleted
inserted
replaced
2938:b002fa81b00d | 2939:7d8667499ddc |
---|---|
23 } | 23 } |
24 | 24 |
25 p->d.last = (u_char *) p + sizeof(ngx_pool_t); | 25 p->d.last = (u_char *) p + sizeof(ngx_pool_t); |
26 p->d.end = (u_char *) p + size; | 26 p->d.end = (u_char *) p + size; |
27 p->d.next = NULL; | 27 p->d.next = NULL; |
28 p->d.failed = 0; | |
28 | 29 |
29 size = size - sizeof(ngx_pool_t); | 30 size = size - sizeof(ngx_pool_t); |
30 p->max = (size < NGX_MAX_ALLOC_FROM_POOL) ? size : NGX_MAX_ALLOC_FROM_POOL; | 31 p->max = (size < NGX_MAX_ALLOC_FROM_POOL) ? size : NGX_MAX_ALLOC_FROM_POOL; |
31 | 32 |
32 p->current = p; | 33 p->current = p; |
187 | 188 |
188 new = (ngx_pool_t *) m; | 189 new = (ngx_pool_t *) m; |
189 | 190 |
190 new->d.end = m + psize; | 191 new->d.end = m + psize; |
191 new->d.next = NULL; | 192 new->d.next = NULL; |
193 new->d.failed = 0; | |
192 | 194 |
193 m += sizeof(ngx_pool_data_t); | 195 m += sizeof(ngx_pool_data_t); |
194 m = ngx_align_ptr(m, NGX_ALIGNMENT); | 196 m = ngx_align_ptr(m, NGX_ALIGNMENT); |
195 new->d.last = m + size; | 197 new->d.last = m + size; |
196 | 198 |
197 current = pool->current; | 199 current = pool->current; |
198 | 200 |
199 for (p = current; p->d.next; p = p->d.next) { | 201 for (p = current; p->d.next; p = p->d.next) { |
200 if ((size_t) (p->d.end - p->d.last) < NGX_ALIGNMENT) { | 202 if (p->d.failed++ > 4) { |
201 current = p->d.next; | 203 current = p->d.next; |
202 } | 204 } |
203 } | 205 } |
204 | 206 |
205 p->d.next = new; | 207 p->d.next = new; |
212 | 214 |
213 static void * | 215 static void * |
214 ngx_palloc_large(ngx_pool_t *pool, size_t size) | 216 ngx_palloc_large(ngx_pool_t *pool, size_t size) |
215 { | 217 { |
216 void *p; | 218 void *p; |
219 ngx_uint_t n; | |
217 ngx_pool_large_t *large; | 220 ngx_pool_large_t *large; |
218 | 221 |
219 p = ngx_alloc(size, pool->log); | 222 p = ngx_alloc(size, pool->log); |
220 if (p == NULL) { | 223 if (p == NULL) { |
221 return NULL; | 224 return NULL; |
225 } | |
226 | |
227 n = 0; | |
228 | |
229 for (large = pool->large; large; large = large->next) { | |
230 if (large->alloc == NULL) { | |
231 large->alloc = p; | |
232 return p; | |
233 } | |
234 | |
235 if (n++ > 3) { | |
236 break; | |
237 } | |
222 } | 238 } |
223 | 239 |
224 large = ngx_palloc(pool, sizeof(ngx_pool_large_t)); | 240 large = ngx_palloc(pool, sizeof(ngx_pool_large_t)); |
225 if (large == NULL) { | 241 if (large == NULL) { |
226 ngx_free(p); | 242 ngx_free(p); |