| Summary: | mmap() too much ==> hang system | ||
|---|---|---|---|
| Product: | Base System | Reporter: | ivan <ivan> |
| Component: | kern | Assignee: | freebsd-bugs (Nobody) <bugs> |
| Status: | Closed FIXED | ||
| Severity: | Affects Only Me | ||
| Priority: | Normal | ||
| Version: | 3.0-RELEASE | ||
| Hardware: | Any | ||
| OS: | Any | ||
State Changed From-To: open->feedback Does this problem still occur in newer versions of FreeBSD, such as 4.3-RELEASE? State Changed From-To: feedback->closed E-mail sent to originator bounces. If this is indeed a problem with newer versions of FreeBSD, a new PR should be opened. |
Writing to a mmap() region that is larger than the amount of physical RAM in the machine causes a hang. System no longer responds and a reboot is needed to restore the system. How-To-Repeat: Compile the following program. Run it with a mmap() size that is larger than the amount of physucal RAM in the machine. #include <unistd.h> #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <sys/mman.h> int main(int argc, char * argv[]) { int fd = -1, x = 0; char * map = NULL; off_t size = 0; if (argc < 3) { fprintf(stderr, "Usage: %s file size_in_megabytes\n", argv[0]); return -1; } if ((fd = open(argv[1], O_CREAT|O_RDWR, 0664)) == -1) { fprintf(stderr, "Could not open %s\n", argv[1]); return -1; } size = atoi(argv[2]); size = size * 1024 * 1024; if (lseek(fd, size, SEEK_SET) != size) { fprintf(stderr, "Could not seek\n"); return -1; } write(fd, &size, 1); if ((map = mmap(0, size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0)) == NULL) { fprintf(stderr, "Could not mmap\n"); return -1; } fprintf(stdout, "Writing:"); for (x=0; x<size; x++) { map[x] = 1; if ((x % (1024*1024)) == 0) { fprintf(stdout, "."); fflush(stdout); } } fprintf(stdout, "done\n"); munmap(map, size); return 0; }