lkml.org 
[lkml]   [1999]   [Dec]   [20]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: 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/

\
 
 \ /
  Last update: 2005-03-22 13:55    [W:0.058 / U:0.136 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site