ccxhwmy commented on issue #5837: URL: https://github.com/apache/apisix/issues/5837#issuecomment-1173399044
> > I found that nginx adopts a way of pre-allocating memory for shared DICT, the smallest granularity is page, ranther than allocat per use. The value of `ngx.shared.DICT.capacity` is accurate, but `ngx.shared.DICT.free_space` is the value left after the acquired pre-allocated memory, so there is a certain inconsistency in fine-grained `ngx.shared.DICT.free_space` accurate. > > Is there some docs or code that explain this? This is useful info. I checked the C code of `ngx.shared.DICT`, the ffi call function of `free_space` is `ngx_http_lua_ffi_shdict_free_space`, and the caluculation method is `bytes = ctx->shpool->pfree * ngx_pagesize;`. The ffi calling process of `set` is `ngx_http_lua_ffi_shdict_store->ngx_slab_alloc_locked->ngx_slab_alloc_pages`, it will judge whether the memory previously malloc is enough, if it is enough, it will not malloc memory. `pfree` will only be modified when entering `ngx_slab_alloc_pages` to malloc memory. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@apisix.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org