Why named shared memory zones

Igor Sysoev is at rambler-co.ru
Mon Sep 28 19:41:55 MSD 2009


On Mon, Sep 28, 2009 at 06:25:37PM +0300, Marcus Clyne wrote:

> Hi,
> 
> Igor Sysoev wrote:
> > On Mon, Sep 28, 2009 at 03:28:44PM +0300, Marcus Clyne wrote:
> >
> >   
> >> Hi,
> >>
> >> What's the purpose/benefit of naming shared memory zones in config files?
> >>     
> >
> > Its names are used in other directives. For example, you may have
> > several proxy_cache's.
> >
> >   
> I understand their use in other directives, but I was just wondering why 
> you actually need them in the directives.
> 
> For example, if you define several proxy caches, then each one would 
> automatically use a different shared memory section.  It seems 
> unnecessary to me to use names in the config file, since they'd always 
> be different, and from what I gather, if you use the same name (and tag) 
> for two shared memory sections, then you'll get a conf error (correct me 
> if I'm wrong, though). 
> 
> I feel that having the config like
> 
> proxy_cache_path   /data/nginx/cache   levels=1:2  10m;
> 
> or even
> 
> proxy_cache_path   /data/nginx/cache   1:2  10m;
> 
> would be much neater than
> 
> proxy_cache_path   /data/nginx/cache   levels=1:2  key_zone=one:10m;
> 
> And overall wouldn't lose any information that couldn't be generated in 
> the background.

No, suppose the following:

 proxy_cache_path   /data/nginx/cache1   levels=1:2  keys_zone=ONE:10m;
 proxy_cache_path   /data/nginx/cache2   levels=1:2  keys_zone=TWO:10m;

   location / {
      proxy_cache  ONE;
   }

   location /one/ {
      proxy_cache  ONE;
   }

   location /two/ {
      proxy_cache  TWO;
   }

> > The second reason is Win32 uses named shared memory mapping.
> > However, it's lamost impossible to use shared memory in Win32 due to
> > Vista ASLR.
> >   
> If you need to have named sections, it would be easy enough to generate 
> them sequentially (e.g. ngx_shms1, ngx_shms2...) whilst reading the 
> config file.

The zone name is also logged when zone is out of space.


-- 
Igor Sysoev
http://sysoev.ru/en/





More information about the nginx mailing list