Messages in this thread | | | From | "Stephen C. Tweedie" <> | Date | Tue, 21 Dec 1999 02:00:51 +0000 (GMT) | Subject | Re: VFS?VM - mmap/write deadlock |
| |
Hi,
On Fri, 17 Dec 1999 18:14:13 +0100 (CET), Ingo Molnar <mingo@chiara.csoma.elte.hu> said:
> actually it was originally noticed by David Miller and mentioned by me :) > The deadlock scenario is when you:
> ptr = mmap(file, 4096, 0) > write (file, ptr, 4096);
> the write() generates a pagefault which deadlocks on the page lock. (the > process gets 'stuck'.)
I've just been talking with Ben LaHaise about this, and a complete fix really will need to ensure that the semaphore taken out by write_page() against truncates happening during the write-back _has_ to be compatible with any locks taken inside the generic write path.
That basically means that we have to use shared semaphores to protect against truncate() both in the VM and in generic_file_write. If we do that we cannot use the same semaphore to make O_APPEND atomic.
We can't even special case O_APPEND writes and writes beyond i_size to take an exclusive lock on the same semaphore, because it is legitimate to write() from a buffer pointer beyond the end of file in a mmap region. (You'll eventually get a SIGBUS when the copy_from_user occurs, but if you exclusive-lock the semaphore on this event and shared-lock the same semaphore in write_page, you've deadlocked before you detect the SIGBUS condition.)
Using two semaphores seems to be necessary: one to guard against truncates (we take it shared any time we want to make sure i_size doesn't shrink from under our feet), and a separate lock to make O_APPEND atomic. O_APPEND writes, and truncates, will take the second semaphore exclusively: nobody else needs it at all.
--Stephen
- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/
| |