shmem: fix faulting into a hole while it's punched
authorHugh Dickins <[email protected]>
Mon, 23 Jun 2014 20:22:06 +0000 (13:22 -0700)
committerLinus Torvalds <[email protected]>
Mon, 23 Jun 2014 23:47:44 +0000 (16:47 -0700)
commitf00cdc6df7d7cfcabb5b740911e6788cb0802bdb
tree2d540f918e013b5dcca920e904c264c703c794eb
parentf72e7dcdd25229446b102e587ef2f826f76bff28
shmem: fix faulting into a hole while it's punched

Trinity finds that mmap access to a hole while it's punched from shmem
can prevent the madvise(MADV_REMOVE) or fallocate(FALLOC_FL_PUNCH_HOLE)
from completing, until the reader chooses to stop; with the puncher's
hold on i_mutex locking out all other writers until it can complete.

It appears that the tmpfs fault path is too light in comparison with its
hole-punching path, lacking an i_data_sem to obstruct it; but we don't
want to slow down the common case.

Extend shmem_fallocate()'s existing range notification mechanism, so
shmem_fault() can refrain from faulting pages into the hole while it's
punched, waiting instead on i_mutex (when safe to sleep; or repeatedly
faulting when not).

[[email protected]: coding-style fixes]
Signed-off-by: Hugh Dickins <[email protected]>
Reported-by: Sasha Levin <[email protected]>
Tested-by: Sasha Levin <[email protected]>
Cc: Dave Jones <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
mm/shmem.c