Skip to contentSkip to conversation

SMP alternatives

PATCH [email protected] 2 participants 2 messages Nov 24, 2005

lore
Share & tools
lore
#0 lore raw
Quoted 5 lines

I suspect that with MAP_SHARED + PROT_WRITE being pretty uncommon anyway, we can probably find trivial patterns in the kernel. Like only one process holding that file open - which is what you get with things that use mmap() to write a new file (I think "ld" used to have a config option to write files that way, for example).

Just a bit of practical experience: I use mmap() to write data a LOT, because msync(MS_ASYNC) is the most portable way to do an async write.

There are two applications. First, helping the OS not fill up with dirty pages. It's basically a way of saying "this page is not going to be dirtied again for a long time".

Secondly, to reduce the latency of synchronous writes. If I need to log operations durably, it helps to

1) fill the log pages, using MS_ASYNC as soon as the page is full
2) when committing a batch, use MS_SYNC to force data to disk
3) report batch successfully committed to stable storage

The aio_ routines are less widely supported some implementations have very high overhead. They would allow me to keep working while a commit is in progress, but the above is simple and reduces the burstiness of I/O considerably.

#1 lore raw
Quoted 9 lines · On Thu, 24 Nov 2005, [email protected] wrote:
Quoted 6 lines

I suspect that with MAP_SHARED + PROT_WRITE being pretty uncommon anyway, we can probably find trivial patterns in the kernel. Like only one process holding that file open - which is what you get with things that use mmap() to write a new file (I think "ld" used to have a config option to write files that way, for example).

Just a bit of practical experience: I use mmap() to write data a LOT, because msync(MS_ASYNC) is the most portable way to do an async write.

Sure. But I suspect that nobody else has that file open when you do so?

In other words, even your usage is something where the OS could tell that you don't actually need atomic operations. It certainly gets slightly more complicated (we'd need to trigger some special stuff if another process does an mmap on it), but it's not conceptually very difficult to just notice automatically and do the right thing(tm).

Now, if two programs are using mmap() to write to the same file at the same time, then the kernel can't tell any more. But in that case, you probably _do_ want atomic ops to be guaranteed, so not disabling them is the right thing to do there.

Linus