Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932470Ab2K1Vaw (ORCPT ); Wed, 28 Nov 2012 16:30:52 -0500 Received: from mx1.redhat.com ([209.132.183.28]:46365 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932404Ab2K1Vat (ORCPT ); Wed, 28 Nov 2012 16:30:49 -0500 Date: Wed, 28 Nov 2012 16:29:40 -0500 (EST) From: Mikulas Patocka X-X-Sender: mpatocka@file.rdu.redhat.com To: Linus Torvalds cc: Jens Axboe , Jeff Chua , Lai Jiangshan , Jan Kara , lkml , linux-fsdevel Subject: Re: [PATCH] Introduce a method to catch mmap_region (was: Recent kernel "mount" slow) In-Reply-To: Message-ID: References: <50AF7901.20401@kernel.dk> <50B46E05.70906@kernel.dk> <50B4B313.3030707@kernel.dk> <50B5CC5A.8060607@kernel.dk> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3078 Lines: 78 On Wed, 28 Nov 2012, Linus Torvalds wrote: > On Wed, Nov 28, 2012 at 12:03 PM, Linus Torvalds > wrote: > > > > mmap() is in *no* way special. The exact same thing happens for > > regular read/write. Yet somehow the mmap code is special-cased, while > > the normal read-write code is not. > > I just double-checked, because it's been a long time since I actually > looked at the code. > > But yeah, block device read/write uses the pure page cache functions. > IOW, it has the *exact* same IO engine as mmap() would have. > > So here's my suggestion: > > - get rid of *all* the locking in aio_read/write and the splice paths > - get rid of all the stupid mmap games > > - instead, add them to the functions that actually use > "blkdev_get_block()" and "blkdev_get_blocks()" and nowhere else. > > That's a fairly limited number of functions: > blkdev_{read,write}page(), blkdev_direct_IO() and > blkdev_write_{begin,end}() > > Doesn't that sounds simpler? And more logical: it protects the actual > places that use the block size of the device. > > I dunno. Maybe there is some fundamental reason why the above is > broken, but it seems to be a much simpler approach. Sure, you need to > guarantee that the people who get the write-lock cannot possibly cause > IO while holding it, but since the only reason to get the write lock > would be to change the block size, that should be pretty simple, no? > > Yeah, yeah, I'm probably missing something fundamental, but the above > sounds like the simple approach to fixing things. Aiming for having > the block size read-lock be taken by the things that pass in the > block-size itself. > > It would be nice for things to be logical and straightforward. > > Linus The problem with this approach is that it is very easy to miss points where it is assumed that the block size doesn't change - and if you miss a point, it results in a hidden bug that has a little possibility of being found. For example, __block_write_full_page and __block_write_begin do if (!page_has_buffers(page)) { create_empty_buffers... } and then they do WARN_ON(bh->b_size != blocksize) err = get_block(inode, block, bh, 1) ... so if the buffers were left over from some previous call to create_empty_buffers with a different blocksize, that WARN_ON is trigged. And it's not only a harmless warning - now bh->b_size is left set to the old block size, but bh->b_blocknr is set to a number, that was calculated according to the new block size - and when you submit that buffer with submit_bh, it is written to the wrong place! Now, prove that there are no more bugs like this. Locking the whole read/write/mmap operations is crude, but at least it can be done without thorough review of all the memory management code. Mikulas -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/