mirror of
				https://github.com/openresty/openresty.git
				synced 2024-10-13 00:29:41 +00:00 
			
		
		
		
	apply the slab_defrag patch to the nginx core by default.
This commit is contained in:
		
							
								
								
									
										100
									
								
								patches/nginx-1.7.0-slab_defrag.patch
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										100
									
								
								patches/nginx-1.7.0-slab_defrag.patch
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,100 @@
 | 
			
		||||
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
 | 
			
		||||
@@ -118,6 +118,7 @@
 | 
			
		||||
     pool->pages->slab = pages;
 | 
			
		||||
     pool->pages->next = &pool->free;
 | 
			
		||||
     pool->pages->prev = (uintptr_t) &pool->free;
 | 
			
		||||
+    pool->pages->prev_slab = 0;
 | 
			
		||||
 
 | 
			
		||||
     pool->start = (u_char *)
 | 
			
		||||
                   ngx_align_ptr((uintptr_t) p + pages * sizeof(ngx_slab_page_t),
 | 
			
		||||
@@ -628,6 +629,7 @@
 | 
			
		||||
                 page[pages].slab = page->slab - pages;
 | 
			
		||||
                 page[pages].next = page->next;
 | 
			
		||||
                 page[pages].prev = page->prev;
 | 
			
		||||
+                page[pages].prev_slab = pages;
 | 
			
		||||
 
 | 
			
		||||
                 p = (ngx_slab_page_t *) page->prev;
 | 
			
		||||
                 p->next = &page[pages];
 | 
			
		||||
@@ -651,6 +653,7 @@
 | 
			
		||||
                 p->slab = NGX_SLAB_PAGE_BUSY;
 | 
			
		||||
                 p->next = NULL;
 | 
			
		||||
                 p->prev = NGX_SLAB_PAGE;
 | 
			
		||||
+                p->prev_slab = 0;
 | 
			
		||||
                 p++;
 | 
			
		||||
             }
 | 
			
		||||
 
 | 
			
		||||
@@ -668,7 +671,7 @@
 | 
			
		||||
 ngx_slab_free_pages(ngx_slab_pool_t *pool, ngx_slab_page_t *page,
 | 
			
		||||
     ngx_uint_t pages)
 | 
			
		||||
 {
 | 
			
		||||
-    ngx_slab_page_t  *prev;
 | 
			
		||||
+    ngx_slab_page_t  *prev, *p;
 | 
			
		||||
 
 | 
			
		||||
     page->slab = pages--;
 | 
			
		||||
 
 | 
			
		||||
@@ -682,6 +685,52 @@
 | 
			
		||||
         page->next->prev = page->prev;
 | 
			
		||||
     }
 | 
			
		||||
 
 | 
			
		||||
+    /* try to merge the following free slab (if any) */
 | 
			
		||||
+
 | 
			
		||||
+    p = &page[page->slab];
 | 
			
		||||
+    if ((u_char *) p < pool->start
 | 
			
		||||
+        && !(p->slab & NGX_SLAB_PAGE_START)
 | 
			
		||||
+        && p->next != NULL
 | 
			
		||||
+        && (p->prev & NGX_SLAB_PAGE_MASK) == NGX_SLAB_PAGE)
 | 
			
		||||
+    {
 | 
			
		||||
+        page->slab += p->slab;
 | 
			
		||||
+
 | 
			
		||||
+        /* remove the following slab from the free list */
 | 
			
		||||
+
 | 
			
		||||
+        prev = (ngx_slab_page_t *) p->prev;
 | 
			
		||||
+        prev->next = p->next;
 | 
			
		||||
+        p->next->prev = p->prev;
 | 
			
		||||
+
 | 
			
		||||
+        ngx_memzero(p, sizeof(ngx_slab_page_t));
 | 
			
		||||
+
 | 
			
		||||
+        /* adjust prev_slab in the new following slab 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) */
 | 
			
		||||
+
 | 
			
		||||
+        p = page - page->prev_slab;
 | 
			
		||||
+        if (!(p->slab & NGX_SLAB_PAGE_START)
 | 
			
		||||
+            && p->next != NULL
 | 
			
		||||
+            && (p->prev & NGX_SLAB_PAGE_MASK) == NGX_SLAB_PAGE)
 | 
			
		||||
+        {
 | 
			
		||||
+            p->slab += page->slab;
 | 
			
		||||
+
 | 
			
		||||
+            /* 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;
 | 
			
		||||
+        }
 | 
			
		||||
+    }
 | 
			
		||||
+
 | 
			
		||||
     page->prev = (uintptr_t) &pool->free;
 | 
			
		||||
     page->next = pool->free.next;
 | 
			
		||||
 
 | 
			
		||||
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
 | 
			
		||||
@@ -19,6 +19,7 @@
 | 
			
		||||
     uintptr_t         slab;
 | 
			
		||||
     ngx_slab_page_t  *next;
 | 
			
		||||
     uintptr_t         prev;
 | 
			
		||||
+    uintptr_t         prev_slab;
 | 
			
		||||
 };
 | 
			
		||||
 
 | 
			
		||||
 
 | 
			
		||||
@ -242,6 +242,10 @@ echo "$info_txt applying the setting_args_invalidates_uri patch for nginx $ver"
 | 
			
		||||
patch -p1 < $root/patches/nginx-$ver-setting_args_invalidates_uri.patch || exit 1
 | 
			
		||||
echo
 | 
			
		||||
 | 
			
		||||
echo "$info_txt applying the slab_defrag patch for nginx"
 | 
			
		||||
patch -p1 < $root/patches/nginx-$main_ver-slab_defrag.patch || exit 1
 | 
			
		||||
echo
 | 
			
		||||
 | 
			
		||||
rm -f *.patch || exit 1
 | 
			
		||||
 | 
			
		||||
cd .. || exit 1
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user