From: Andrew Morton <akpm@osdl.org>
To: Nick Piggin <nickpiggin@yahoo.com.au>,
Nick Piggin <npiggin@suse.de>,
Linux Memory Management <linux-mm@kvack.org>,
Linux Kernel <linux-kernel@vger.kernel.org>
Subject: [patch 2/6] revert "generic_file_buffered_write(): deadlock on vectored write"
Date: Tue, 10 Oct 2006 23:17:56 -0700 [thread overview]
Message-ID: <20061010231756.16b22ce2.akpm@osdl.org> (raw)
In-Reply-To: <20061010231150.fb9e30f5.akpm@osdl.org>
From: Andrew Morton <akpm@osdl.org>
Revert 6527c2bdf1f833cc18e8f42bd97973d583e4aa83
This patch fixed the following bug:
When prefaulting in the pages in generic_file_buffered_write(), we only
faulted in the pages for the firts segment of the iovec. If the second of
successive segment described a mmapping of the page into which we're
write()ing, and that page is not up-to-date, the fault handler tries to lock
the already-locked page (to bring it up to date) and deadlocks.
An exploit for this bug is in writev-deadlock-demo.c, in
http://www.zip.com.au/~akpm/linux/patches/stuff/ext3-tools.tar.gz.
(These demos assume blocksize < PAGE_CACHE_SIZE).
The problem with this fix is that it takes the kernel back to doing a single
prepare_write()/commit_write() per iovec segment. So in the worst case we'll
run prepare_write+commit_write 1024 times where we previously would have run
it once.
<insert numbers obtained via ext3-tools's writev-speed.c here>
And apparently this change killed NFS overwrite performance, because, I
suppose, it talks to the server for each prepare_write+commit_write.
So just back that patch out - we'll be fixing the deadlock by other means.
Signed-off-by: Andrew Morton <akpm@osdl.org>
---
mm/filemap.c | 18 +++++++-----------
1 file changed, 7 insertions(+), 11 deletions(-)
diff -puN mm/filemap.c~revert-generic_file_buffered_write-deadlock-on-vectored-write mm/filemap.c
--- a/mm/filemap.c~revert-generic_file_buffered_write-deadlock-on-vectored-write
+++ a/mm/filemap.c
@@ -2091,21 +2091,14 @@ generic_file_buffered_write(struct kiocb
do {
unsigned long index;
unsigned long offset;
+ unsigned long maxlen;
size_t copied;
offset = (pos & (PAGE_CACHE_SIZE -1)); /* Within page */
index = pos >> PAGE_CACHE_SHIFT;
bytes = PAGE_CACHE_SIZE - offset;
-
- /* Limit the size of the copy to the caller's write size */
- bytes = min(bytes, count);
-
- /*
- * Limit the size of the copy to that of the current segment,
- * because fault_in_pages_readable() doesn't know how to walk
- * segments.
- */
- bytes = min(bytes, cur_iov->iov_len - iov_base);
+ if (bytes > count)
+ bytes = count;
/*
* Bring in the user page that we will copy from _first_.
@@ -2113,7 +2106,10 @@ generic_file_buffered_write(struct kiocb
* same page as we're writing to, without it being marked
* up-to-date.
*/
- fault_in_pages_readable(buf, bytes);
+ maxlen = cur_iov->iov_len - iov_base;
+ if (maxlen > bytes)
+ maxlen = bytes;
+ fault_in_pages_readable(buf, maxlen);
page = __grab_cache_page(mapping,index,&cached_page,&lru_pvec);
if (!page) {
_
next prev parent reply other threads:[~2006-10-11 6:18 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-10-10 14:21 [rfc] 2.6.19-rc1-git5: consolidation of file backed fault handlers Nick Piggin
2006-10-10 14:21 ` [patch 1/5] mm: fault vs invalidate/truncate check Nick Piggin
2006-10-10 14:21 ` [patch 2/5] mm: fault vs invalidate/truncate race fix Nick Piggin
2006-10-11 4:38 ` Andrew Morton
2006-10-11 5:39 ` Nick Piggin
2006-10-11 6:00 ` Andrew Morton
2006-10-11 9:21 ` Nick Piggin
2006-10-11 16:21 ` Linus Torvalds
2006-10-11 16:57 ` SPAM: " Nick Piggin
2006-10-11 17:11 ` Linus Torvalds
2006-10-11 17:21 ` SPAM: " Nick Piggin
2006-10-11 17:38 ` Linus Torvalds
2006-10-12 3:33 ` Nick Piggin
2006-10-12 15:37 ` Linus Torvalds
2006-10-12 15:40 ` Nick Piggin
2006-10-11 5:13 ` Andrew Morton
2006-10-11 5:50 ` Nick Piggin
2006-10-11 6:10 ` Andrew Morton
2006-10-11 6:17 ` [patch 1/6] revert "generic_file_buffered_write(): handle zero length iovec segments" Andrew Morton
[not found] ` <20061010231150.fb9e30f5.akpm@osdl.org>
2006-10-11 6:17 ` Andrew Morton [this message]
[not found] ` <20061010231243.bc8b834c.akpm@osdl.org>
2006-10-11 6:17 ` [patch 3/6] generic_file_buffered_write() cleanup Andrew Morton
[not found] ` <20061010231339.a79c1fae.akpm@osdl.org>
2006-10-11 6:18 ` [patch 4/6] generic_file_buffered_write(): fix page prefaulting Andrew Morton
[not found] ` <20061010231424.db88931f.akpm@osdl.org>
2006-10-11 6:18 ` [patch 5/6] generic_file_buffered_write(): max_len cleanup Andrew Morton
[not found] ` <20061010231514.c1da7355.akpm@osdl.org>
2006-10-11 6:18 ` [patch 6/6] fix pagecache write deadlocks Andrew Morton
2006-10-21 1:53 ` [patch 2/5] mm: fault vs invalidate/truncate race fix Benjamin Herrenschmidt
2006-10-10 14:22 ` [patch 3/5] mm: fault handler to replace nopage and populate Nick Piggin
2006-10-10 14:22 ` [patch 4/5] mm: add vm_insert_pfn helpler Nick Piggin
2006-10-11 10:12 ` Thomas Hellstrom
2006-10-11 11:24 ` Nick Piggin
2006-10-11 21:30 ` Thomas Hellström
2006-10-10 14:22 ` [patch 5/5] mm: merge nopfn with fault handler Nick Piggin
2006-10-10 14:26 ` [rfc] 2.6.19-rc1-git5: consolidation of file backed fault handlers Nick Piggin
2006-10-10 14:33 ` Christoph Hellwig
2006-10-10 15:01 ` Nick Piggin
2006-10-10 16:09 ` Arjan van de Ven
2006-10-11 0:46 ` SPAM: " Nick Piggin
2006-10-10 15:07 ` Arjan van de Ven
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20061010231756.16b22ce2.akpm@osdl.org \
--to=akpm@osdl.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=nickpiggin@yahoo.com.au \
--cc=npiggin@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).