On 6/16/05, Zoran Vasiljevic <[EMAIL PROTECTED]> wrote: > > Am 16.06.2005 um 18:18 schrieb Zoran Vasiljevic: > > > > > One can even explore the memmap machinery and see if we can > > entirely drop the temp-file and use the system paging for that: > > so if the input exceeds the maxinput, we just mmap /dev/zero file > > I believe something like that should be possible but will have to > > double-check if this is true. > > > > I knew it ("man mmap" on solaris): > > > When MAP_ANON is set in flags, and fd is set to -1, mmap() > provides a direct path to return anonymous pages to the > caller. This operation is equivalent to passing mmap() an > open file descriptor on /dev/zero with MAP_ANON elided from > the flags argument. > > I'd have to see if this is really working on Linux, Mac and Win.
I believe this is pretty common, but I'm not sure if this is what you want. An anonymous mapping is still going to account against the processes memory budget, and I don't think it's going to be any more likely to be swapped out than malloc'ed memory. In fact, on Linux (well, glibc) if you ask malloc for a chunk of memory over a certain size then mmap is used internally. I think the advantage is reduced memory fragmentation, but there is some overhead for small sizes and you have to allocate in multiples of the page size (4k). tempfs would be a better bet. Modern Linux systems have this mounted at /dev/shm. I think this is a Solaris thing. This is a very low overhead file system where the file data springs into existence when you ask for it. So, no files, no overhead. Under memory pressure it's sent to swap. It was designed for sharing memory between processes using mmap, but it's handy for /tmp and some other things. You could try setting the TMPDIR environment variable to some tempfs file system if you wanted to experiment with this.