Klaus Demo nginx / a2c8d9a
improve ngx_slab_alloc() error logging Igor Sysoev 13 years ago
6 changed file(s) with 68 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
6262 ngx_uint_t pages);
6363 static void ngx_slab_free_pages(ngx_slab_pool_t *pool, ngx_slab_page_t *page,
6464 ngx_uint_t pages);
65 static void ngx_slab_error(ngx_slab_pool_t *pool, ngx_uint_t level,
66 char *text);
6567
6668
6769 static ngx_uint_t ngx_slab_max_size;
128130 pages -= m;
129131 pool->pages->slab = pages;
130132 }
133
134 pool->log_ctx = &pool->zero;
135 pool->zero = '\0';
131136 }
132137
133138
414419 ngx_log_debug1(NGX_LOG_DEBUG_ALLOC, ngx_cycle->log, 0, "slab free: %p", p);
415420
416421 if ((u_char *) p < pool->start || (u_char *) p > pool->end) {
417 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0,
418 "ngx_slab_free(): outside of pool");
422 ngx_slab_error(pool, NGX_LOG_ALERT, "ngx_slab_free(): outside of pool");
419423 goto fail;
420424 }
421425
563567 }
564568
565569 if (slab == NGX_SLAB_PAGE_FREE) {
566 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0,
567 "ngx_slab_free(): page is already free");
570 ngx_slab_error(pool, NGX_LOG_ALERT,
571 "ngx_slab_free(): page is already free");
568572 goto fail;
569573 }
570574
571575 if (slab == NGX_SLAB_PAGE_BUSY) {
572 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0,
573 "ngx_slab_free(): pointer to wrong page");
576 ngx_slab_error(pool, NGX_LOG_ALERT,
577 "ngx_slab_free(): pointer to wrong page");
574578 goto fail;
575579 }
576580
596600
597601 wrong_chunk:
598602
599 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0,
600 "ngx_slab_free(): pointer to wrong chunk");
603 ngx_slab_error(pool, NGX_LOG_ALERT,
604 "ngx_slab_free(): pointer to wrong chunk");
601605
602606 goto fail;
603607
604608 chunk_already_free:
605609
606 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0,
607 "ngx_slab_free(): chunk is already free");
610 ngx_slab_error(pool, NGX_LOG_ALERT,
611 "ngx_slab_free(): chunk is already free");
608612
609613 fail:
610614
655659 }
656660 }
657661
658 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, NGX_ENOMEM,
659 "ngx_slab_alloc(): failed");
662 ngx_slab_error(pool, NGX_LOG_CRIT, "ngx_slab_alloc() failed: no memory");
660663
661664 return NULL;
662665 }
687690
688691 pool->free.next = page;
689692 }
693
694
695 static void
696 ngx_slab_error(ngx_slab_pool_t *pool, ngx_uint_t level, char *text)
697 {
698 ngx_log_error(level, ngx_cycle->log, 0, "%s%s", text, pool->log_ctx);
699 }
3333 u_char *end;
3434
3535 ngx_shmtx_t mutex;
36
37 u_char *log_ctx;
38 u_char zero;
3639 } ngx_slab_pool_t;
3740
3841
14111411 static ngx_int_t
14121412 ngx_ssl_session_cache_init(ngx_shm_zone_t *shm_zone, void *data)
14131413 {
1414 size_t len;
14141415 ngx_slab_pool_t *shpool;
14151416 ngx_ssl_session_cache_t *cache;
14161417
14301431 ngx_ssl_session_rbtree_insert_value);
14311432
14321433 ngx_queue_init(&cache->expire_queue);
1434
1435 len = sizeof(" in SSL session shared cache \"\"") + shm_zone->name.len;
1436
1437 shpool->log_ctx = ngx_slab_alloc(shpool, len);
1438 if (shpool->log_ctx == NULL) {
1439 return NGX_ERROR;
1440 }
1441
1442 ngx_sprintf(shpool->log_ctx, " in SSL session shared cache \"%V\"%Z",
1443 &shm_zone->name);
14331444
14341445 shm_zone->data = cache;
14351446
456456 {
457457 ngx_http_limit_req_ctx_t *octx = data;
458458
459 size_t len;
459460 ngx_rbtree_node_t *sentinel;
460461 ngx_http_limit_req_ctx_t *ctx;
461462
499500
500501 ngx_queue_init(ctx->queue);
501502
503 len = sizeof(" in limit_req zone \"\"") + shm_zone->name.len;
504
505 ctx->shpool->log_ctx = ngx_slab_alloc(ctx->shpool, len);
506 if (ctx->shpool->log_ctx == NULL) {
507 return NGX_ERROR;
508 }
509
510 ngx_sprintf(ctx->shpool->log_ctx, " in limit_req zone \"%V\"%Z",
511 &shm_zone->name);
512
502513 return NGX_OK;
503514 }
504515
320320 {
321321 ngx_http_limit_zone_ctx_t *octx = data;
322322
323 size_t len;
323324 ngx_slab_pool_t *shpool;
324325 ngx_rbtree_node_t *sentinel;
325326 ngx_http_limit_zone_ctx_t *ctx;
355356 ngx_rbtree_init(ctx->rbtree, sentinel,
356357 ngx_http_limit_zone_rbtree_insert_value);
357358
359 len = sizeof(" in limit_zone \"\"") + shm_zone->name.len;
360
361 shpool->log_ctx = ngx_slab_alloc(shpool, len);
362 if (shpool->log_ctx == NULL) {
363 return NGX_ERROR;
364 }
365
366 ngx_sprintf(shpool->log_ctx, " in limit_zone \"%V\"%Z", &shm_zone->name);
367
358368 return NGX_OK;
359369 }
360370
3232 {
3333 ngx_http_file_cache_t *ocache = data;
3434
35 size_t len;
3536 ngx_rbtree_node_t *sentinel;
3637 ngx_http_file_cache_t *cache;
3738
7778 }
7879
7980 ngx_queue_init(cache->queue);
81
82 len = sizeof(" in cache keys zone \"\"") + shm_zone->name.len;
83
84 cache->shpool->log_ctx = ngx_slab_alloc(cache->shpool, len);
85 if (cache->shpool->log_ctx == NULL) {
86 return NGX_ERROR;
87 }
88
89 ngx_sprintf(cache->shpool->log_ctx, " in cache keys zone \"%V\"%Z",
90 &shm_zone->name);
8091
8192 cache->created = ngx_time();
8293