mmapping large files hits swap in 2.4?
Hija,
I'm currently looking into optimizing GIMPs own swapping algorithm by replacing naive file operations by mmap-based ones. Unfortunately my test machine (PPC, 256MB) gets hit really hard by mmapping files over 100MB into memory: The swap utilization grows up to the file size and the machine is completely unresponsive for several seconds up to a few minutes. Seemingly the writes to the mmaped area first hit the swap and then are read from there again to fit the designated file.
I'm doing something along the lines of:
area = mmap (0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
I also tried MAP_PRIVATE and MAP_LOCKED both with a private and a shared mapping, but to no avail.
This is kernel version 2.4.19-rc3 (in the benh-variant).
Is there anything I can do to improve the situation or is it just the kernel or the architecture?
Signature · 2 lines
Servus,
DanielQuoted 10 lines · Daniel Egger
Hija,
I'm currently looking into optimizing GIMPs own swapping algorithm by replacing naive file operations by mmap-based ones. Unfortunately my test machine (PPC, 256MB) gets hit really hard by mmapping files over 100MB into memory: The swap utilization grows up to the file size and the machine is completely unresponsive for several seconds up to a few minutes. Seemingly the writes to the mmaped area first hit the swap and then are read from there again to fit the designated file.
Quoted 2 lines
I'm doing something along the lines of:
area = mmap (0, size,PROT_READ|PROT_WRITE,MAP_SHARED, fd, 0);
seems like you are doing something else, like hitting all of the file.
# uname -a Linux sirizidl.dialin.rrze.uni-erlangen.de 2.4.18 #27 Wed Jul 24 17:25:39 CEST 2002 m68k unknown
main()
{
char *area;
int fd=open("/msrc/linux/distr/cd.image", O_RDWR);
area = mmap (0, 168088*4096, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (area == -1) perror("mmap");
}
# time ./mmap real 0m0.035s user 0m0.020s sys 0m0.020s
Richard
Am Sam, 2002-08-10 um 14.12 schrieb Richard Zidlicky:
Quoted 6 lines
seems like you are doing something else, like hitting all of the file.
# uname -a Linux sirizidl.dialin.rrze.uni-erlangen.de 2.4.18 #27 Wed Jul 24 17:25:39 CEST 2002 m68k unknown
Quoted 7 lines
main()
{
char *area;
int fd=open("/msrc/linux/distr/cd.image",O_RDWR);
area = mmap (0, 168088*4096,PROT_READ|PROT_WRITE,MAP_SHARED, fd, 0); if (area == -1)perror("mmap");
}
Heh. Well of course I'm also trying to use the memory I mmaped. :) It is just that it seems the mmaped region is not really bakked by the underlying file but by swap space which was exactly what I was trying to avoid by using a file.
Signature · 2 lines
Servus,
DanielQuoted 16 lines · Daniel Egger
Am Sam, 2002-08-10 um 14.12 schrieb Richard Zidlicky:
Quoted 6 lines
seems like you are doing something else, like hitting all of the file.
# uname -a Linux sirizidl.dialin.rrze.uni-erlangen.de 2.4.18 #27 Wed Jul 24 17:25:39 CEST 2002 m68k unknownQuoted 7 lines
main()
{
char *area;
int fd=open("/msrc/linux/distr/cd.image",O_RDWR);
area = mmap (0, 168088*4096,PROT_READ|PROT_WRITE,MAP_SHARED, fd, 0); if (area == -1)perror("mmap");
}
Quoted 4 lines
Heh. Well of course I'm also trying to use the memory I mmaped. :) It is just that it seems the mmaped region is not really bakked by the underlying file but by swap space which was exactly what I was trying to avoid by using a file.
still works as expected for me, accessing a 650 MB file with only about 350 MB swap is no problem. It takes some time on that old m68k box but clearly dominated by HD read time.. a compilation runing in the background doesn't seem to make any difference at all.
Richard