]> git.kaiwu.me - nginx.git/commitdiff
Slab: fixed initialization on win32.
authorRuslan Ermilov <ru@nginx.com>
Tue, 8 Aug 2017 12:16:01 +0000 (15:16 +0300)
committerRuslan Ermilov <ru@nginx.com>
Tue, 8 Aug 2017 12:16:01 +0000 (15:16 +0300)
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.

src/core/nginx.c
src/core/ngx_slab.c
src/core/ngx_slab.h

index abaa50d618496073d97c8c13b601da9447317f4b..c3a29cc40d86a663bd4a6cb7cd8299a7f8cf3d18 100644 (file)
@@ -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;
     }
index 9e7796d50ea72a32d7bc3d3b16eb97870d82082c..40238705394392f9e898e7230fa398cf0a36da1b 100644 (file)
@@ -82,6 +82,19 @@ static ngx_uint_t  ngx_slab_exact_size;
 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)
 {
@@ -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);
index eff893c3e322672d98a93573c9bb6f998c6d4aa1..d1876bbec947d85e721160631d919c52d00558d3 100644 (file)
@@ -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);