mirror of
https://github.com/nginx/nginx.git
synced 2025-06-07 17:52:38 +08:00
improve ngx_slab_alloc() error logging
This commit is contained in:
parent
04fe40023a
commit
a2c8d9a0a8
@ -63,6 +63,8 @@ static ngx_slab_page_t *ngx_slab_alloc_pages(ngx_slab_pool_t *pool,
|
|||||||
ngx_uint_t pages);
|
ngx_uint_t pages);
|
||||||
static void ngx_slab_free_pages(ngx_slab_pool_t *pool, ngx_slab_page_t *page,
|
static void ngx_slab_free_pages(ngx_slab_pool_t *pool, ngx_slab_page_t *page,
|
||||||
ngx_uint_t pages);
|
ngx_uint_t pages);
|
||||||
|
static void ngx_slab_error(ngx_slab_pool_t *pool, ngx_uint_t level,
|
||||||
|
char *text);
|
||||||
|
|
||||||
|
|
||||||
static ngx_uint_t ngx_slab_max_size;
|
static ngx_uint_t ngx_slab_max_size;
|
||||||
@ -129,6 +131,9 @@ ngx_slab_init(ngx_slab_pool_t *pool)
|
|||||||
pages -= m;
|
pages -= m;
|
||||||
pool->pages->slab = pages;
|
pool->pages->slab = pages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pool->log_ctx = &pool->zero;
|
||||||
|
pool->zero = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -415,8 +420,7 @@ ngx_slab_free_locked(ngx_slab_pool_t *pool, void *p)
|
|||||||
ngx_log_debug1(NGX_LOG_DEBUG_ALLOC, ngx_cycle->log, 0, "slab free: %p", p);
|
ngx_log_debug1(NGX_LOG_DEBUG_ALLOC, ngx_cycle->log, 0, "slab free: %p", p);
|
||||||
|
|
||||||
if ((u_char *) p < pool->start || (u_char *) p > pool->end) {
|
if ((u_char *) p < pool->start || (u_char *) p > pool->end) {
|
||||||
ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0,
|
ngx_slab_error(pool, NGX_LOG_ALERT, "ngx_slab_free(): outside of pool");
|
||||||
"ngx_slab_free(): outside of pool");
|
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -564,13 +568,13 @@ ngx_slab_free_locked(ngx_slab_pool_t *pool, void *p)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (slab == NGX_SLAB_PAGE_FREE) {
|
if (slab == NGX_SLAB_PAGE_FREE) {
|
||||||
ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0,
|
ngx_slab_error(pool, NGX_LOG_ALERT,
|
||||||
"ngx_slab_free(): page is already free");
|
"ngx_slab_free(): page is already free");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (slab == NGX_SLAB_PAGE_BUSY) {
|
if (slab == NGX_SLAB_PAGE_BUSY) {
|
||||||
ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0,
|
ngx_slab_error(pool, NGX_LOG_ALERT,
|
||||||
"ngx_slab_free(): pointer to wrong page");
|
"ngx_slab_free(): pointer to wrong page");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
@ -597,14 +601,14 @@ done:
|
|||||||
|
|
||||||
wrong_chunk:
|
wrong_chunk:
|
||||||
|
|
||||||
ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0,
|
ngx_slab_error(pool, NGX_LOG_ALERT,
|
||||||
"ngx_slab_free(): pointer to wrong chunk");
|
"ngx_slab_free(): pointer to wrong chunk");
|
||||||
|
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
chunk_already_free:
|
chunk_already_free:
|
||||||
|
|
||||||
ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0,
|
ngx_slab_error(pool, NGX_LOG_ALERT,
|
||||||
"ngx_slab_free(): chunk is already free");
|
"ngx_slab_free(): chunk is already free");
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
@ -656,8 +660,7 @@ ngx_slab_alloc_pages(ngx_slab_pool_t *pool, ngx_uint_t pages)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, NGX_ENOMEM,
|
ngx_slab_error(pool, NGX_LOG_CRIT, "ngx_slab_alloc() failed: no memory");
|
||||||
"ngx_slab_alloc(): failed");
|
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -688,3 +691,10 @@ ngx_slab_free_pages(ngx_slab_pool_t *pool, ngx_slab_page_t *page,
|
|||||||
|
|
||||||
pool->free.next = page;
|
pool->free.next = page;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
ngx_slab_error(ngx_slab_pool_t *pool, ngx_uint_t level, char *text)
|
||||||
|
{
|
||||||
|
ngx_log_error(level, ngx_cycle->log, 0, "%s%s", text, pool->log_ctx);
|
||||||
|
}
|
||||||
|
@ -34,6 +34,9 @@ typedef struct {
|
|||||||
u_char *end;
|
u_char *end;
|
||||||
|
|
||||||
ngx_shmtx_t mutex;
|
ngx_shmtx_t mutex;
|
||||||
|
|
||||||
|
u_char *log_ctx;
|
||||||
|
u_char zero;
|
||||||
} ngx_slab_pool_t;
|
} ngx_slab_pool_t;
|
||||||
|
|
||||||
|
|
||||||
|
@ -1412,6 +1412,7 @@ ngx_ssl_session_cache(ngx_ssl_t *ssl, ngx_str_t *sess_ctx,
|
|||||||
static ngx_int_t
|
static ngx_int_t
|
||||||
ngx_ssl_session_cache_init(ngx_shm_zone_t *shm_zone, void *data)
|
ngx_ssl_session_cache_init(ngx_shm_zone_t *shm_zone, void *data)
|
||||||
{
|
{
|
||||||
|
size_t len;
|
||||||
ngx_slab_pool_t *shpool;
|
ngx_slab_pool_t *shpool;
|
||||||
ngx_ssl_session_cache_t *cache;
|
ngx_ssl_session_cache_t *cache;
|
||||||
|
|
||||||
@ -1432,6 +1433,16 @@ ngx_ssl_session_cache_init(ngx_shm_zone_t *shm_zone, void *data)
|
|||||||
|
|
||||||
ngx_queue_init(&cache->expire_queue);
|
ngx_queue_init(&cache->expire_queue);
|
||||||
|
|
||||||
|
len = sizeof(" in SSL session shared cache \"\"") + shm_zone->name.len;
|
||||||
|
|
||||||
|
shpool->log_ctx = ngx_slab_alloc(shpool, len);
|
||||||
|
if (shpool->log_ctx == NULL) {
|
||||||
|
return NGX_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
ngx_sprintf(shpool->log_ctx, " in SSL session shared cache \"%V\"%Z",
|
||||||
|
&shm_zone->name);
|
||||||
|
|
||||||
shm_zone->data = cache;
|
shm_zone->data = cache;
|
||||||
|
|
||||||
return NGX_OK;
|
return NGX_OK;
|
||||||
|
@ -457,6 +457,7 @@ ngx_http_limit_req_init_zone(ngx_shm_zone_t *shm_zone, void *data)
|
|||||||
{
|
{
|
||||||
ngx_http_limit_req_ctx_t *octx = data;
|
ngx_http_limit_req_ctx_t *octx = data;
|
||||||
|
|
||||||
|
size_t len;
|
||||||
ngx_rbtree_node_t *sentinel;
|
ngx_rbtree_node_t *sentinel;
|
||||||
ngx_http_limit_req_ctx_t *ctx;
|
ngx_http_limit_req_ctx_t *ctx;
|
||||||
|
|
||||||
@ -500,6 +501,16 @@ ngx_http_limit_req_init_zone(ngx_shm_zone_t *shm_zone, void *data)
|
|||||||
|
|
||||||
ngx_queue_init(ctx->queue);
|
ngx_queue_init(ctx->queue);
|
||||||
|
|
||||||
|
len = sizeof(" in limit_req zone \"\"") + shm_zone->name.len;
|
||||||
|
|
||||||
|
ctx->shpool->log_ctx = ngx_slab_alloc(ctx->shpool, len);
|
||||||
|
if (ctx->shpool->log_ctx == NULL) {
|
||||||
|
return NGX_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
ngx_sprintf(ctx->shpool->log_ctx, " in limit_req zone \"%V\"%Z",
|
||||||
|
&shm_zone->name);
|
||||||
|
|
||||||
return NGX_OK;
|
return NGX_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -321,6 +321,7 @@ ngx_http_limit_zone_init_zone(ngx_shm_zone_t *shm_zone, void *data)
|
|||||||
{
|
{
|
||||||
ngx_http_limit_zone_ctx_t *octx = data;
|
ngx_http_limit_zone_ctx_t *octx = data;
|
||||||
|
|
||||||
|
size_t len;
|
||||||
ngx_slab_pool_t *shpool;
|
ngx_slab_pool_t *shpool;
|
||||||
ngx_rbtree_node_t *sentinel;
|
ngx_rbtree_node_t *sentinel;
|
||||||
ngx_http_limit_zone_ctx_t *ctx;
|
ngx_http_limit_zone_ctx_t *ctx;
|
||||||
@ -356,6 +357,15 @@ ngx_http_limit_zone_init_zone(ngx_shm_zone_t *shm_zone, void *data)
|
|||||||
ngx_rbtree_init(ctx->rbtree, sentinel,
|
ngx_rbtree_init(ctx->rbtree, sentinel,
|
||||||
ngx_http_limit_zone_rbtree_insert_value);
|
ngx_http_limit_zone_rbtree_insert_value);
|
||||||
|
|
||||||
|
len = sizeof(" in limit_zone \"\"") + shm_zone->name.len;
|
||||||
|
|
||||||
|
shpool->log_ctx = ngx_slab_alloc(shpool, len);
|
||||||
|
if (shpool->log_ctx == NULL) {
|
||||||
|
return NGX_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
ngx_sprintf(shpool->log_ctx, " in limit_zone \"%V\"%Z", &shm_zone->name);
|
||||||
|
|
||||||
return NGX_OK;
|
return NGX_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,6 +33,7 @@ ngx_http_file_cache_init(ngx_shm_zone_t *shm_zone, void *data)
|
|||||||
{
|
{
|
||||||
ngx_http_file_cache_t *ocache = data;
|
ngx_http_file_cache_t *ocache = data;
|
||||||
|
|
||||||
|
size_t len;
|
||||||
ngx_rbtree_node_t *sentinel;
|
ngx_rbtree_node_t *sentinel;
|
||||||
ngx_http_file_cache_t *cache;
|
ngx_http_file_cache_t *cache;
|
||||||
|
|
||||||
@ -79,6 +80,16 @@ ngx_http_file_cache_init(ngx_shm_zone_t *shm_zone, void *data)
|
|||||||
|
|
||||||
ngx_queue_init(cache->queue);
|
ngx_queue_init(cache->queue);
|
||||||
|
|
||||||
|
len = sizeof(" in cache keys zone \"\"") + shm_zone->name.len;
|
||||||
|
|
||||||
|
cache->shpool->log_ctx = ngx_slab_alloc(cache->shpool, len);
|
||||||
|
if (cache->shpool->log_ctx == NULL) {
|
||||||
|
return NGX_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
ngx_sprintf(cache->shpool->log_ctx, " in cache keys zone \"%V\"%Z",
|
||||||
|
&shm_zone->name);
|
||||||
|
|
||||||
cache->created = ngx_time();
|
cache->created = ngx_time();
|
||||||
|
|
||||||
return NGX_OK;
|
return NGX_OK;
|
||||||
|
Loading…
Reference in New Issue
Block a user