Derek Price wrote: > Why mmap? mmap allocates the number of pages you want, without the 1/2 page lossage on average that malloc() has.
> What sort of object would you > suggest I map the allocation to? My Linux man page says that the > MAP_ANONYMOUS flag (which requires no object to map) has been > supported since the 2.4 kernel, but I can find no reference to > MAP_ANONYMOUS in the POSIX spec. Different systems want it differently. I use an autoconf test to determine which way to use mmap(): 1) int flags = MAP_ANON | MAP_PRIVATE; int fd = -1; 2) int flags = MAP_ANONYMOUS | MAP_PRIVATE; int fd = -1; 3) #ifndef MAP_FILE #define MAP_FILE 0 #endif int flags = MAP_FILE | MAP_PRIVATE; int fd = open("/dev/zero",O_RDONLY,0666); if (fd<0) exit(1); These three together cover all systems that have mmap(). > (Most of this is hardly necessary for CVS since it is already caching > unused buffer datas rather than freeing them, and reusing them as they > are needed. This is actually a bad idea, because 1) It steals memory from the system. If a program doesn't use memory but still holds it, it forces other programs to do more page faults. 2) When memory is tight, it forces the system to write garbage data to swap space. 3) It slows down 'cvs' itself. Because when the page gets swapped out to disk, and the the program notices that it needs it, the OS must re-fetch the page from the swap. This usually takes ca. 10 ms. Whereas when a program munmap()s the pages that it doesn't need any more, 1) Other programs can use the free mempry. 3) When the program needs more memory, the kernel can often provide a blank page immediately, without having to wait for a swapped out page to come in. Bruno _______________________________________________ Bug-cvs mailing list Bug-cvs@gnu.org http://lists.gnu.org/mailman/listinfo/bug-cvs