Date: Thu, 29 Apr 1999 16:14:09 -0500 (CDT) From: Kevin Day <toasty@home.dragondata.com> To: hackers@freebsd.org Subject: mmaping /dev/mem then spawning children Message-ID: <199904292114.QAA00336@home.dragondata.com>
next in thread | raw e-mail | index | archive | help
I'm completely at a loss as to why this happens, but it just sprang up when we upgraded from 3.0-RELEASE to 3.1-RELEASE. I have a process that mmap's a device. (Our own custom driver). It then spawns some children that don't really need access to it. However, top/ps/etc show that the child is eating 32760 megabytes of ram. This also seems to happen if you mmap /dev/mem, or a few other devices. Am I just doing something stupid here, or is this an honest bug? Here's sample code to reproduce this. Compile them both, then run '1'. 1.c: #include <stdio.h> #include <unistd.h> #include <fcntl.h> #include <sys/errno.h> #include <sys/types.h> #include <sys/mman.h> void main(void) { int k; char *low; int devmem; devmem = open("/dev/mem",O_RDWR); low1mb = (char *)mmap(0, 0x800000, (PROT_READ | PROT_WRITE), MAP_INHERIT | MAP_SHARED, devmem, 0); printf("Starting 2...\n"); if (rfork(RFCFDG|RFPROC)) { usleep(100); } else { k = execl("./2", "2", (char *) 0); if (k) { printf("io returned %d errno %d\n",k, errno); } _exit(0); } } 2.c: void main(void) { while(1) sleep(10000); } I run ./1 top shows: PID USERNAME PRI NICE SIZE RES STATE TIME WCPU CPU COMMAND 899 root 10 0 748K 32760M nanslp 0:00 0.00% 0.00% 2 ps shows: root 899 0.0 53622.9 748 -7960 p1 I 6:14AM 0:00.00 2 0 899 1 0 10 0 748 -7960 nanslp I p1 0:00.00 2 -7960k.... which is about 8M (from the mmap) minus how much '2' should really be taking up. Is this a real bug? Kevin To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199904292114.QAA00336>