[nginx] Slab: fixed initialization on win32.

Ruslan Ermilov ru at nginx.com
Tue Aug 8 12:16:23 UTC 2017


details:   http://hg.nginx.org/nginx/rev/69f9ee0342db
branches:  
changeset: 7081:69f9ee0342db
user:      Ruslan Ermilov <ru at nginx.com>
date:      Tue Aug 08 15:16:01 2017 +0300
description:
Slab: fixed initialization on win32.

On Windows, a worker process does not call ngx_slab_init() from
ngx_init_zone_pool(), so ngx_slab_max_size, ngx_slab_exact_size,
and ngx_slab_exact_shift were left uninitialized.

diffstat:

 src/core/nginx.c    |   6 ++++++
 src/core/ngx_slab.c |  23 +++++++++++++----------
 src/core/ngx_slab.h |   1 +
 3 files changed, 20 insertions(+), 10 deletions(-)

diffs (67 lines):

diff -r ac120e797d28 -r 69f9ee0342db src/core/nginx.c
--- a/src/core/nginx.c	Fri Aug 04 17:03:10 2017 +0300
+++ b/src/core/nginx.c	Tue Aug 08 15:16:01 2017 +0300
@@ -273,6 +273,12 @@ main(int argc, char *const *argv)
         return 1;
     }
 
+    /*
+     * ngx_slab_sizes_init() requires ngx_pagesize set in ngx_os_init()
+     */
+
+    ngx_slab_sizes_init();
+
     if (ngx_add_inherited_sockets(&init_cycle) != NGX_OK) {
         return 1;
     }
diff -r ac120e797d28 -r 69f9ee0342db src/core/ngx_slab.c
--- a/src/core/ngx_slab.c	Fri Aug 04 17:03:10 2017 +0300
+++ b/src/core/ngx_slab.c	Tue Aug 08 15:16:01 2017 +0300
@@ -83,6 +83,19 @@ static ngx_uint_t  ngx_slab_exact_shift;
 
 
 void
+ngx_slab_sizes_init(void)
+{
+    ngx_uint_t  n;
+
+    ngx_slab_max_size = ngx_pagesize / 2;
+    ngx_slab_exact_size = ngx_pagesize / (8 * sizeof(uintptr_t));
+    for (n = ngx_slab_exact_size; n >>= 1; ngx_slab_exact_shift++) {
+        /* void */
+    }
+}
+
+
+void
 ngx_slab_init(ngx_slab_pool_t *pool)
 {
     u_char           *p;
@@ -91,16 +104,6 @@ ngx_slab_init(ngx_slab_pool_t *pool)
     ngx_uint_t        i, n, pages;
     ngx_slab_page_t  *slots, *page;
 
-    /* STUB */
-    if (ngx_slab_max_size == 0) {
-        ngx_slab_max_size = ngx_pagesize / 2;
-        ngx_slab_exact_size = ngx_pagesize / (8 * sizeof(uintptr_t));
-        for (n = ngx_slab_exact_size; n >>= 1; ngx_slab_exact_shift++) {
-            /* void */
-        }
-    }
-    /**/
-
     pool->min_size = (size_t) 1 << pool->min_shift;
 
     slots = ngx_slab_slots(pool);
diff -r ac120e797d28 -r 69f9ee0342db src/core/ngx_slab.h
--- a/src/core/ngx_slab.h	Fri Aug 04 17:03:10 2017 +0300
+++ b/src/core/ngx_slab.h	Tue Aug 08 15:16:01 2017 +0300
@@ -59,6 +59,7 @@ typedef struct {
 } ngx_slab_pool_t;
 
 
+void ngx_slab_sizes_init(void);
 void ngx_slab_init(ngx_slab_pool_t *pool);
 void *ngx_slab_alloc(ngx_slab_pool_t *pool, size_t size);
 void *ngx_slab_alloc_locked(ngx_slab_pool_t *pool, size_t size);


More information about the nginx-devel mailing list