Monday 15 June 2015

c - Posix shared memory cause bus error -



c - Posix shared memory cause bus error -

i used posix shared memory in mips. programme complain:

i: 516095 i: 516096 bus error

the same programme execute in x86 ok. want kernel max back upwards shared memory size.

int ret; int bufsize = 517120; shmfd = shm_open(name_shm, o_rdwr|o_creat|o_excl, file_op); shm_unlink(name_shm); if(shmfd < 0) { sys_err("create share memory failed: %s\n", strerror(errno)); exit(-1); } ret = ftruncate(shmfd, bufsize); if(ret < 0) { sys_err("alloc share memory failed: %s\n", strerror(errno)); exit(-1); } char *ptr = mmap(null, bufsize, prot_read|prot_write, map_shared, shmfd, 0); if(ptr == map_failed) { sys_err("mmap failed: %s\n", strerror(errno)); exit(-1); } struct stat buf; fstat(shmfd, &buf); printf("size: %d, total: %d\n", buf.st_size, bufsize); int i; for(i = 0; < bufsize; i++) { printf("i: %d\n", i); ptr[i] = 0; }

i have check ipcs, man says :

the linux ipcs utility not compatible posix ipcs utility.

root@anywifi:~# ipcs -lm ------ shared memory limits -------- max number of segments = 4096 max seg size (kbytes) = 3 max total shared memory (pages) = 2097152 min seg size (bytes) = 1 root@anywifi:~# cat /proc/sys/kernel/shmmax 3740 root@anywifi:~# cat /proc/sys/kernel/shmall 2097152 root@anywifi:~# cat /proc/sys/kernel/shmmni 4096

max seg size 3k, programme can utilize (516096 / 1024 = 504k)?

i confused sysv ipc vs posix ipc?

shm_unlink() called after shm_open() hence removes shared memory object name, and, 1 time processes have unmapped object, de-allocates , destroys contents of associated memory region. after successful shm_unlink(), attempts shm_open() object same name fail (unless o_creat specified, in case new, distinct object created).

so getting bus error, fatal failure in execution of machine language instruction resulting processor detecting anomalous status on bus. perchance due to- invalid address alignment (accessing mullti-byte number @ odd address) or accessing memory location outside address space not exist.

additionally, may need check resource limits , set right limits required programme (if smaller), using sysctl command

$ipcs -l ------ shared memory limits -------- max number of segments = 4096 max seg size (kbytes) = 32768 max total shared memory (kbytes) = 8388608 min seg size (bytes) = 1 ------ semaphore limits -------- max number of arrays = 128 max semaphores per array = 250 max semaphores scheme wide = 32000 max ops per semop phone call = 32 semaphore max value = 32767 ------ messages limits -------- max queues scheme wide = 15747 max size of message (bytes) = 8192 default max size of queue (bytes) = 16384

c linux linux-kernel posix ipc

No comments:

Post a Comment