updated the slab_defrag patch (for nginx) a bit.

This commit is contained in:
Yichun Zhang (agentzh) 2014-05-06 14:24:24 -07:00
parent 1dbd0b24d2
commit 91549c16b4
1 changed files with 11 additions and 10 deletions

View File

@ -1,6 +1,6 @@
diff -r 7586e7b2dbe9 src/core/ngx_slab.c
--- a/src/core/ngx_slab.c Tue Feb 18 17:30:40 2014 +0400
+++ b/src/core/ngx_slab.c Tue May 06 12:32:22 2014 -0700
+++ b/src/core/ngx_slab.c Tue May 06 14:00:13 2014 -0700
@@ -118,6 +118,7 @@
pool->pages->slab = pages;
pool->pages->next = &pool->free;
@ -34,11 +34,11 @@ diff -r 7586e7b2dbe9 src/core/ngx_slab.c
page->slab = pages--;
@@ -682,6 +685,52 @@
@@ -682,6 +685,53 @@
page->next->prev = page->prev;
}
+ /* try to merge the following free slab (if any) */
+ /* try to merge the following free block (if any) */
+
+ p = &page[page->slab];
+ if ((u_char *) p < pool->start
@ -48,7 +48,7 @@ diff -r 7586e7b2dbe9 src/core/ngx_slab.c
+ {
+ page->slab += p->slab;
+
+ /* remove the following slab from the free list */
+ /* remove the following block from the free list */
+
+ prev = (ngx_slab_page_t *) p->prev;
+ prev->next = p->next;
@ -56,14 +56,15 @@ diff -r 7586e7b2dbe9 src/core/ngx_slab.c
+
+ ngx_memzero(p, sizeof(ngx_slab_page_t));
+
+ /* adjust prev_slab in the new following slab accordingly */
+ /* adjust prev_slab in the new following block accordingly */
+
+ if ((u_char *) (p + p->slab) < pool->start) {
+ p[p->slab].prev_slab = page->slab;
+ }
+ }
+
+ if (page->prev_slab) {
+ /* try to merge the preceding free slab (if any) */
+ /* try to merge the preceding free block (if any) */
+
+ p = page - page->prev_slab;
+ if (!(p->slab & NGX_SLAB_PAGE_START)
@ -71,14 +72,14 @@ diff -r 7586e7b2dbe9 src/core/ngx_slab.c
+ && (p->prev & NGX_SLAB_PAGE_MASK) == NGX_SLAB_PAGE)
+ {
+ p->slab += page->slab;
+ ngx_memzero(page, sizeof(ngx_slab_page_t));
+
+ /* adjust prev_slab in the following block accordingly */
+
+ /* adjust prev_slab in the new following slab accordingly */
+ if ((u_char *) (p + p->slab) < pool->start) {
+ p[p->slab].prev_slab = p->slab;
+ }
+
+ ngx_memzero(page, sizeof(ngx_slab_page_t));
+
+ /* skip adding "page" to the free list */
+ return;
+ }
@ -89,7 +90,7 @@ diff -r 7586e7b2dbe9 src/core/ngx_slab.c
diff -r 7586e7b2dbe9 src/core/ngx_slab.h
--- a/src/core/ngx_slab.h Tue Feb 18 17:30:40 2014 +0400
+++ b/src/core/ngx_slab.h Tue May 06 12:32:22 2014 -0700
+++ b/src/core/ngx_slab.h Tue May 06 14:00:13 2014 -0700
@@ -19,6 +19,7 @@
uintptr_t slab;
ngx_slab_page_t *next;