Welcome! Log In Create A New Profile

Advanced

Re: Shared Memory Structure?

Maxim Dounin
May 04, 2016 09:42AM
Hello!

On Tue, May 03, 2016 at 05:45:05AM -0400, ben5192 wrote:

> I am storing things in a shared memory zone allocated with
> ngx_shared_memory_add and allocating each slab with ngx_slab_alloc_locked
> (as these items don’t need to be locked particularly). The problem I'm
> having is that I add the shared memory with exactly the amount I need.
> However, the final large thing to be allocated fails, but after this a lot
> more smaller things are also allocated without any problem. There is enough
> space for it but it has a problem with a large chunk when space is getting
> tight.
> Does anyone know why this is or how to fix it? My guess was that nginx
> structures the shared memory in a way that means there is enough memory
> (which I have made sure there is) but it is not continuous.
> Thanks.

Shared memory size as specified in a ngx_shared_memory_add() call is the
total size of the memory region to be allocated by nginx. As long
as you use it with slab allocator - various slab allocator
structures are allocated in this memory region, starting with
the ngx_slab_pool_t structure, and followed by multiple
ngx_slab_page_t structures.

If you want to use shared memory for an allocation with a known
size, you have to add some memory to account these internal
structures. Note that it may be not trivial to calculate how may
extra memory you'll need - see the slab allocator code for
details. Adding at least 8 * ngx_pagesize should be a good
idea.

--
Maxim Dounin
http://nginx.org/

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

Shared Memory Structure?

ben5192 May 03, 2016 05:45AM

Re: Shared Memory Structure?

Maxim Dounin May 04, 2016 09:42AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 304
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready