nginx

changeset 5634:5024d29354f1

Core: slab log_nomem flag. 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.
author Maxim Dounin <mdounin@mdounin.ru>
date Mon, 31 Mar 2014 21:38:30 +0400
parents b74f1106f920
children c348dea081fb
files 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
diffstat 4 files changed, 14 insertions(+), 2 deletions(-) [+]
line diff
     1.1 --- a/src/core/ngx_slab.c	Mon Mar 31 21:38:28 2014 +0400
     1.2 +++ b/src/core/ngx_slab.c	Mon Mar 31 21:38:30 2014 +0400
     1.3 @@ -129,6 +129,7 @@
     1.4          pool->pages->slab = pages;
     1.5      }
     1.6  
     1.7 +    pool->log_nomem = 1;
     1.8      pool->log_ctx = &pool->zero;
     1.9      pool->zero = '\0';
    1.10  }
    1.11 @@ -658,7 +659,10 @@
    1.12          }
    1.13      }
    1.14  
    1.15 -    ngx_slab_error(pool, NGX_LOG_CRIT, "ngx_slab_alloc() failed: no memory");
    1.16 +    if (pool->log_nomem) {
    1.17 +        ngx_slab_error(pool, NGX_LOG_CRIT,
    1.18 +                       "ngx_slab_alloc() failed: no memory");
    1.19 +    }
    1.20  
    1.21      return NULL;
    1.22  }
     2.1 --- a/src/core/ngx_slab.h	Mon Mar 31 21:38:28 2014 +0400
     2.2 +++ b/src/core/ngx_slab.h	Mon Mar 31 21:38:30 2014 +0400
     2.3 @@ -39,6 +39,8 @@
     2.4      u_char           *log_ctx;
     2.5      u_char            zero;
     2.6  
     2.7 +    unsigned          log_nomem:1;
     2.8 +
     2.9      void             *data;
    2.10      void             *addr;
    2.11  } ngx_slab_pool_t;
     3.1 --- a/src/event/ngx_event_openssl.c	Mon Mar 31 21:38:28 2014 +0400
     3.2 +++ b/src/event/ngx_event_openssl.c	Mon Mar 31 21:38:30 2014 +0400
     3.3 @@ -1834,6 +1834,8 @@
     3.4      ngx_sprintf(shpool->log_ctx, " in SSL session shared cache \"%V\"%Z",
     3.5                  &shm_zone->shm.name);
     3.6  
     3.7 +    shpool->log_nomem = 0;
     3.8 +
     3.9      return NGX_OK;
    3.10  }
    3.11  
    3.12 @@ -1986,7 +1988,7 @@
    3.13      ngx_shmtx_unlock(&shpool->mutex);
    3.14  
    3.15      ngx_log_error(NGX_LOG_ALERT, c->log, 0,
    3.16 -                  "could not add new SSL session to the session cache");
    3.17 +                  "could not allocate new session%s", shpool->log_ctx);
    3.18  
    3.19      return 0;
    3.20  }
     4.1 --- a/src/http/modules/ngx_http_limit_req_module.c	Mon Mar 31 21:38:28 2014 +0400
     4.2 +++ b/src/http/modules/ngx_http_limit_req_module.c	Mon Mar 31 21:38:30 2014 +0400
     4.3 @@ -451,6 +451,8 @@
     4.4  
     4.5          node = ngx_slab_alloc_locked(ctx->shpool, size);
     4.6          if (node == NULL) {
     4.7 +            ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0,
     4.8 +                          "could not allocate node%s", ctx->shpool->log_ctx);
     4.9              return NGX_ERROR;
    4.10          }
    4.11      }
    4.12 @@ -674,6 +676,8 @@
    4.13      ngx_sprintf(ctx->shpool->log_ctx, " in limit_req zone \"%V\"%Z",
    4.14                  &shm_zone->shm.name);
    4.15  
    4.16 +    ctx->shpool->log_nomem = 0;
    4.17 +
    4.18      return NGX_OK;
    4.19  }
    4.20