# shared memory



## xazzz (Feb 18, 2009)

I'm trying to setup shared memory by building a new kernel and I'm a bit confused by the result.

I want to have 4G of shared memory (which is 2^32 bytes).

First of all, there's 16G of RAM and 20G of swap, so there is enough for what I want to do.

In the kernel options, I set SHMMAXPGS to 1048576 which with 4K pages should end up at 4G for the SHMMAX option. I also set SHMALL to 1048576

When I'm compiling the kernel, I got 
cc1: warnings being treated as errors
/usr/src/sys/kern/sysv_shm.c:168: warning: integer overflow in expression
*** Error code 1

Looking into sysv_shm.c, I figure out that SHMMAX (the line at which there's a compilation error) is of type unsigned long (u_long) which should accomodate 2^64 bytes.

But anyway, maybe I was wrong and it's only 2^32 bytes so I change SHMMAXPGS to 524288 which is 2^32 and I still have the same problem. So I try 2^32-1 (524287) and it worked.

But this value only given approximatively 2G of shared memory.

My question is what wrong? the data type should accommodate such size (4G), but I can compile the new kernel

Thanks


----------



## SirDice (Feb 18, 2009)

Why don't you use sysctl to set those parameters?


----------



## xazzz (Feb 18, 2009)

sysctl accept any value even if is does not make sense. I'm able to set the shared memory (SHMMAX) to 14G, but when I make the system call to get 3G, it tell me that I can't have it. I can even put it to 100G and it will let me do, but it does mean that it's available


----------



## SirDice (Feb 18, 2009)

Not sure exactly how they're related but you may need to set shmall too. The xine install seems to want them both:


```
kern.ipc.shmmax=67108864
kern.ipc.shmall=32768
```

Edit:


> Like Soviet central planners there are two important settings. Like most people I knew about shmmax, but it is sly, it is not the maximum amount of memory which can be allocated, it is the maximum size of any shared memory chunk.
> Shmmax is how big a bite you want per bite from free memory.


http://www.pythian.com/blogs/245/the-mysterious-world-of-shmmax-and-shmall
(linux but the principle should be the same)


----------



## xazzz (Feb 18, 2009)

shmmax is setup at compilation as shmmaxpgs * page_size that why you dont set it up.

But the problem is not the setting of those parameters, but the limits at which they can be setup


----------



## xazzz (Feb 18, 2009)

Sorry, forgot to say.

I'm building amd64 kernel

and also, SHMALL is equal SHMMAXPGS


----------



## jamjoe (May 22, 2009)

Don't know if this is relevant to you any longer but I've just had the same problem on 7.1-RELEASE and an amd64 kernel.

It seems that if you don't define SHMMAX explicitly in your configuration file, the 

#define SHMMAX (SHMMAXPGS*PAGE_SIZE)

statement in the .c file defaults to an int.

After adding

options SHMMAX=2457600001 (in my case)
options SHMMAXPGS=600000
(etc)

the kernel compiled without a hitch.

j


----------

