<div dir="ltr"><div><div><div><div><div><div>Hello!<br><br></div>Thanks for your help. I hope that the patch be OK now.<br></div>I don't know if the function and variable names are on nginx pattern.<br></div>Feel free to change the patch.<br>
</div>If you have any other point before accept it, will be a pleasure to fix it.<br><br>--- src/core/ngx_slab.c 2013-05-06 07:27:10.000000000 -0300<br>+++ src/core/ngx_slab.c 2013-07-31 00:21:08.043034442 -0300<br>
@@ -615,6 +615,26 @@ fail:<br> <br> <br> static ngx_slab_page_t *<br>+ngx_slab_merge_with_neighbour(ngx_slab_pool_t *pool, ngx_slab_page_t *page)<br>+{<br>+ ngx_slab_page_t *neighbour = &page[page->slab];<br>+ if (((ngx_slab_page_t *) neighbour->prev != NULL) && (neighbour->next != NULL) && ((neighbour->prev & NGX_SLAB_PAGE_MASK) == NGX_SLAB_PAGE)) {<br>
+ page->slab += neighbour->slab;<br>+<br>+ ((ngx_slab_page_t *) neighbour->prev)->next = neighbour->next;<br>+ neighbour->next->prev = neighbour->prev;<br>+<br>+ neighbour->slab = NGX_SLAB_PAGE_FREE;<br>
+ neighbour->prev = (uintptr_t) &pool->free;<br>+ neighbour->next = &pool->free;<br>+<br>+ return page;<br>+ }<br>+ return NULL;<br>+}<br>+<br>+<br>+static ngx_slab_page_t *<br>
ngx_slab_alloc_pages(ngx_slab_pool_t *pool, ngx_uint_t pages)<br> {<br> ngx_slab_page_t *page, *p;<br>@@ -657,6 +677,19 @@ ngx_slab_alloc_pages(ngx_slab_pool_t *po<br> }<br> }<br> <br>+ ngx_flag_t retry = 0;<br>
+ for (page = pool->free.next; page != &pool->free;) {<br>+ if (ngx_slab_merge_with_neighbour(pool, page)) {<br>+ retry = 1;<br>+ } else {<br>+ page = page->next;<br>+ }<br>
+ }<br>+<br>+ if (retry) {<br>+ return ngx_slab_alloc_pages(pool, pages);<br>+ }<br>+<br> ngx_slab_error(pool, NGX_LOG_CRIT, "ngx_slab_alloc() failed: no memory");<br> <br> return NULL;<br>
@@ -687,6 +720,8 @@ ngx_slab_free_pages(ngx_slab_pool_t *poo<br> page->next->prev = (uintptr_t) page;<br> <br> pool->free.next = page;<br>+<br>+ ngx_slab_merge_with_neighbour(pool, page);<br> }<br> <br>
<br><br><br></div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Jul 30, 2013 at 7:09 AM, Maxim Dounin <span dir="ltr"><<a href="mailto:mdounin@mdounin.ru" target="_blank">mdounin@mdounin.ru</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello!<br>
<br>
On Mon, Jul 29, 2013 at 04:01:37PM -0300, Wandenberg Peixoto wrote:<br>
<br>
[...]<br>
<div class="im"><br>
> What would be an alternative to not loop on pool->pages?<br>
<br>
</div>Free memory blocks are linked in pool->free list, it should be<br>
enough to look there.<br>
<br>
[...]<br>
<div class="HOEnZb"><div class="h5"><br>
--<br>
Maxim Dounin<br>
<a href="http://nginx.org/en/donation.html" target="_blank">http://nginx.org/en/donation.html</a><br>
<br>
_______________________________________________<br>
nginx-devel mailing list<br>
<a href="mailto:nginx-devel@nginx.org">nginx-devel@nginx.org</a><br>
<a href="http://mailman.nginx.org/mailman/listinfo/nginx-devel" target="_blank">http://mailman.nginx.org/mailman/listinfo/nginx-devel</a><br>
</div></div></blockquote></div><br></div>