]> git.kaiwu.me - nginx.git/commitdiff
Core: slab log_nomem flag.
authorMaxim Dounin <mdounin@mdounin.ru>
Mon, 31 Mar 2014 17:38:30 +0000 (21:38 +0400)
committerMaxim Dounin <mdounin@mdounin.ru>
Mon, 31 Mar 2014 17:38:30 +0000 (21:38 +0400)
The flag allows to suppress "ngx_slab_alloc() failed: no memory" messages
from a slab allocator, e.g., if an LRU expiration is used by a consumer
and allocation failures aren't fatal.

The flag is now used in the SSL session cache code, and in the limit_req
module.

src/core/ngx_slab.c
src/core/ngx_slab.h
src/event/ngx_event_openssl.c
src/http/modules/ngx_http_limit_req_module.c

index 6d18abb722d7f567f4d0b324f84115e27b693a85..be7927ce0676d1f8c557830e613f5bb228a208a5 100644 (file)
@@ -129,6 +129,7 @@ ngx_slab_init(ngx_slab_pool_t *pool)
         pool->pages->slab = pages;
     }
 
+    pool->log_nomem = 1;
     pool->log_ctx = &pool->zero;
     pool->zero = '\0';
 }
@@ -658,7 +659,10 @@ ngx_slab_alloc_pages(ngx_slab_pool_t *pool, ngx_uint_t pages)
         }
     }
 
-    ngx_slab_error(pool, NGX_LOG_CRIT, "ngx_slab_alloc() failed: no memory");
+    if (pool->log_nomem) {
+        ngx_slab_error(pool, NGX_LOG_CRIT,
+                       "ngx_slab_alloc() failed: no memory");
+    }
 
     return NULL;
 }
index c5e420bfa8e31a1a467d4127b2583f7e91b08ae0..5735e3bb3b9e430e0c7aa2ea043a3340737291d1 100644 (file)
@@ -39,6 +39,8 @@ typedef struct {
     u_char           *log_ctx;
     u_char            zero;
 
+    unsigned          log_nomem:1;
+
     void             *data;
     void             *addr;
 } ngx_slab_pool_t;
index 28e7aa5096bdbbc85d7a4011bf1b40e2836936e5..e7b58136b58c42d00dac25c8f109d2221c357631 100644 (file)
@@ -1834,6 +1834,8 @@ ngx_ssl_session_cache_init(ngx_shm_zone_t *shm_zone, void *data)
     ngx_sprintf(shpool->log_ctx, " in SSL session shared cache \"%V\"%Z",
                 &shm_zone->shm.name);
 
+    shpool->log_nomem = 0;
+
     return NGX_OK;
 }
 
@@ -1986,7 +1988,7 @@ failed:
     ngx_shmtx_unlock(&shpool->mutex);
 
     ngx_log_error(NGX_LOG_ALERT, c->log, 0,
-                  "could not add new SSL session to the session cache");
+                  "could not allocate new session%s", shpool->log_ctx);
 
     return 0;
 }
index d4c1ff6c382a03715246717da41d7ca067965ed7..74f7fdaa75fd5697a427cd4a82f8dacf92c0069e 100644 (file)
@@ -451,6 +451,8 @@ ngx_http_limit_req_lookup(ngx_http_limit_req_limit_t *limit, ngx_uint_t hash,
 
         node = ngx_slab_alloc_locked(ctx->shpool, size);
         if (node == NULL) {
+            ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0,
+                          "could not allocate node%s", ctx->shpool->log_ctx);
             return NGX_ERROR;
         }
     }
@@ -674,6 +676,8 @@ ngx_http_limit_req_init_zone(ngx_shm_zone_t *shm_zone, void *data)
     ngx_sprintf(ctx->shpool->log_ctx, " in limit_req zone \"%V\"%Z",
                 &shm_zone->shm.name);
 
+    ctx->shpool->log_nomem = 0;
+
     return NGX_OK;
 }