nginx_shared_memory_layout
Overview
Shared memory is memory that can be accessed by different processes, as each process’s page table maps to the same physical page, nginx tracks all used shared memory as a list in each cycle. for each shared memory, mmap() is called by master processed after parse conf if same shared memory(same name, name is the key) can’t be reused, otherwise, just copy shared memory address from old cycle to new cycle, save that shared memory address, reused shared memory is not freed during reconfigure, later on fork worker process.
Shared memory
Data structure and API
structure
1 | struct ngx_shm_zone_s { |
API
1 | /* add a ngx_shm_zone_t to the cycle shared_memory list, shared memory is not mapped now */ |
organize all shared memory
This picture shows how shared memory is tracked by each cycle, reused old one(same name, size, tag) or create new one if cant’ be reused.