Shared memory shmat/dt not working well in 2.5.x

Zlatko Calusic (zlatko.calusic@iskon.hr)
Tue, 01 Oct 2002 11:52:59 +0200


--=-=-=

Hi, Andrew, Hugh & others.

Still having problems with Oracle on 2.5.x (it can't even be started),
I devoted some time trying to pinpoint where the problem is. Reading
many traces of Oracle, and rebooting a dozen times, I finally found
that the culprit is weird behaviour of shmat/shmdt functions in 2.5,
when combined with mprotect() calls. I wrote a simple test app
(attached) and I'm also appending output of it below (running on
2.4.19 & 2.5.39 kernels, see the difference).

Hopefully, somebody will know how to help resolve that issue, so I can
finally benchmark Oracle on 2.4 vs Oracle on 2.5. ;)

Best regards,

{2.4.19} % shm-bug
First shmat & protects done: 50000000
50000000-51000000 rw-s 00000000 00:04 327974932 /SYSV01478e7f (deleted)
51000000-51001000 r--s 01000000 00:04 327974932 /SYSV01478e7f (deleted)
51001000-51081000 rw-s 01001000 00:04 327974932 /SYSV01478e7f (deleted)
51081000-51082000 r--s 01081000 00:04 327974932 /SYSV01478e7f (deleted)
51082000-51083000 rw-s 01082000 00:04 327974932 /SYSV01478e7f (deleted)
Second shmat done: 50000000
50000000-51083000 rw-s 00000000 00:04 327974932 /SYSV01478e7f (deleted)

{2.5.39} % shm-bug
First shmat & protects done: 50000000
50000000-51000000 rw-s 00000000 00:06 2457614 /SYSV01478e7f (deleted)
51000000-51001000 r--s 00000000 00:06 2457614 /SYSV01478e7f (deleted)
51001000-51081000 rw-s 00001000 00:06 2457614 /SYSV01478e7f (deleted)
51081000-51082000 r--s 00001000 00:06 2457614 /SYSV01478e7f (deleted)
51082000-51083000 rw-s 00002000 00:06 2457614 /SYSV01478e7f (deleted)
shmat 2: Invalid argument

--=-=-=
Content-Type: text/x-csrc
Content-Disposition: attachment; filename=shm-bug.c

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/mman.h>

#define SIZE 17313792

void xperror(char *error_string)
{
perror(error_string);
exit(EXIT_FAILURE);
}

int main(int argc, char **argv)
{
int shmid, *addr;
char buffer[64];

if ((shmid = shmget(21466751, SIZE, IPC_CREAT | IPC_EXCL | 0640)) < 0)
xperror("shmget");
addr = (int *) shmat(shmid, (char *) 0x50000000, 0);
if (addr == (int *) -1)
xperror("shmat 1");
if (mprotect((char *) 0x51000000, 4096, PROT_READ) < 0)
xperror("mprotect 1");
if (mprotect((char *) 0x51081000, 4096, PROT_READ) < 0)
xperror("mprotect 2");
printf("First shmat & protects done: %08lx\n", (unsigned long) addr);
sprintf(buffer, "cat /proc/%d/maps | grep /SYSV", getpid());
system(buffer);
if (shmdt(addr) < 0)
xperror("shmdt 1");
addr = (int *) shmat(shmid, (char *) 0x50000000, 0);
if (addr == (int *) -1) {
perror("shmat 2");
shmctl(shmid, IPC_RMID, NULL);
exit(EXIT_FAILURE);
}
printf("Second shmat done: %08lx\n", (unsigned long) addr);
system(buffer);
if (shmdt(addr) < 0)
xperror("shmdt 2");
shmctl(shmid, IPC_RMID, NULL);
exit(EXIT_SUCCESS);
}

--=-=-=

-- 
Zlatko

--=-=-=-- - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/