系统相关
首页 > 系统相关> > ngx——内存池管理

ngx——内存池管理

作者:互联网

1. 有哪些内存池

init_cycle.pool : 用于初始化时使用,初始化后一定被释放

   196 main(int argc, char *const *argv)
   253     init_cycle.pool = ngx_create_pool(1024, log);
   292     cycle = ngx_init_cycle(&init_cycle);

cycle->pool : 伴随整个工作周期,直到 重新加载配置
conf->temp_pool : 当配置解析完后,释放
conf->pool : 等于 cycle->pool
ngx_temp_pool : 30s后释放

    38 ngx_cycle_t *
    39 ngx_init_cycle(ngx_cycle_t *old_cycle)
    40 {
    69     pool = ngx_create_pool(NGX_CYCLE_POOL_SIZE, log);
    81     cycle->pool = pool;

   260     conf.temp_pool = ngx_create_pool(NGX_CYCLE_POOL_SIZE, log);
   269     conf.pool = pool;

   767     ngx_destroy_pool(conf.temp_pool);


   778     if (ngx_temp_pool == NULL) {
   779         ngx_temp_pool = ngx_create_pool(128, cycle->log);
   788         if (ngx_array_init(&ngx_old_cycles, ngx_temp_pool, n,
   789                            sizeof(ngx_cycle_t *))
   790             != NGX_OK)
   791         {
   792             exit(1);
   793         }
  797         ngx_cleaner_event.handler = ngx_clean_old_cycles;
   801     }
   802
   803     ngx_temp_pool->log = cycle->log;
   804
   805     old = ngx_array_push(&ngx_old_cycles);
   806     if (old == NULL) {
   807         exit(1);
   808     }
   809     *old = old_cycle;
   811     if (!ngx_cleaner_event.timer_set) {
   812         ngx_add_timer(&ngx_cleaner_event, 30000);
   813         ngx_cleaner_event.timer_set = 1;
   814     }
   815
   816     return cycle;
  1365 static void
  1366 ngx_clean_old_cycles(ngx_event_t *ev)
  1367 {
  1379     cycle = ngx_old_cycles.elts;
  1380     for (i = 0; i < ngx_old_cycles.nelts; i++) {
  1405         ngx_destroy_pool(cycle[i]->pool);
  1407     }
  1415         ngx_destroy_pool(ngx_temp_pool);

标签:old,temp,管理,init,内存,ngx,pool,cycle
来源: https://www.cnblogs.com/yangxinrui/p/16203377.html