Re: [PATCH] mm: replace mmap_sem for mm->exe_file serialization

From: Cyrill Gorcunov
Date: Thu Feb 26 2015 - 15:51:59 EST


On Thu, Feb 26, 2015 at 11:36:57AM -0800, Davidlohr Bueso wrote:
> We currently use the mmap_sem to serialize the mm exe_file.
> This is atrocious and a clear example of the misuses this
> lock has all over the place, making any significant changes
> to the address space locking that much more complex and tedious.
> This also has to do of how we used to check for the vma's vm_file
> being VM_EXECUTABLE (much of which was replaced by 2dd8ad81e31).
>
> This patch, therefore, removes the mmap_sem dependency and
> introduces a specific lock for the exe_file (rwlock_t, as it is
> read mostly and protects a trivial critical region). As mentioned,
> the motivation is to cleanup mmap_sem (as opposed to exe_file
> performance). A nice side effect of this is that we avoid taking
> the mmap_sem (shared) in fork paths for the exe_file handling
> (note that readers block when the rwsem is taken exclusively by
> another thread).
>
> Now that callers have been updated and standardized[1, 2] around
> the get_mm_set_exe_file() interface, changing the locking scheme
> is quite straightforward. The exception being the prctl calls
> (ie PR_SET_MM_EXE_FILE). Because this caller actually _updates_
> the mm->exe_file, we need to handle it in the same patch that changes
> the locking rules. For this we need to reorganize prctl_set_mm_exe_file,
> such that:
>
> o mmap_sem is taken when actually needed.
>
> o a new set_mm_exe_file_locked() function is introduced to be used by
> prctl. We now need to explicitly acquire the exe_file_lock as before
> it was implicit in holding the mmap_sem for write.
>
> o a new __prctl_set_mm_exe_file() helper is created, which actually
> does the exe_file handling for the mm side -- needing the write
> lock for updating the mm->flags (*sigh*). In the future we could
> have a unique mm::exe_file_struct and keep track of MMF_EXE_FILE_CHANGED
> on our own.
>
> mm: improve handling of mm->exe_file
> [1] Part 1: https://lkml.org/lkml/2015/2/18/721
> [2] Part 2: https://lkml.org/lkml/2015/2/25/679
>
> Applies on top of linux-next (20150225).
>
> Signed-off-by: Davidlohr Bueso <dbueso@xxxxxxx>

Hi Davidlohr, it would be interesting to know if the cleanup
bring some performance benefit?
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/