Re: [PATCH] Introduce a method to catch mmap_region (was: Recent kernel "mount" slow)

Al Viro
2012-11-28T19:43:27Z

On Wed, Nov 28, 2012 at 11:15:12AM -0800, Linus Torvalds wrote:
> No, this is crap.
>
> We don't introduce random hooks like this just because the block layer
> has shit-for-brains and cannot be bothered to do things right.
>
> The fact is, the whole locking in the block layer open routine is
> total and utter crap. It doesn't lock the right thing, even with your
> change *anyway* (or with the change Jens had). Absolutely nothing in
> "mmap_region()" cares at all about the block-size anywhere - it's
> generic, after all - so locking around it is f*cking pointless. There
> is no way in hell that the caller of ->mmap can *ever* care about the
> block size, since it never even looks at it.
>
> Don't do random crap like this.
>
> Why does the code think that mmap matters so much anyway? As you say,
> the mmap itself does *nothing*. It has no impact for the block size.

... and here I was, trying to massage a reply into form that would be
at least borderline printable... Anyway, this is certainly the wrong
way to go. We want to catch if the damn thing is mapped and mapping_mapped()
leaves a race? Fine, so let's not use mapping_mapped() at all. Have a
private vm_operations - a copy of generic_file_vm_ops with ->open()/->close()
added to it. Incrementing/decrementing a per-block_device atomic counter,
with increment side done under your rwsem, to make sure that 0->positive
transition doesn't change in critical section of set_blocksize(). And don't
use generic_file_mmap(), just do file_accessed() and set ->vm_ops to that
local copy.