From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ot0-f180.google.com ([74.125.82.180]:41847 "EHLO mail-ot0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932683AbeEHPDu (ORCPT ); Tue, 8 May 2018 11:03:50 -0400 Received: by mail-ot0-f180.google.com with SMTP id t1-v6so36437155oth.8 for ; Tue, 08 May 2018 08:03:50 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <8f464b5f-a479-6bfe-3abf-b2ed6efe5eb6@infradead.org> References: <20180507083807.28792-1-mszeredi@redhat.com> <20180507083807.28792-24-mszeredi@redhat.com> <8f464b5f-a479-6bfe-3abf-b2ed6efe5eb6@infradead.org> From: Miklos Szeredi Date: Tue, 8 May 2018 17:03:49 +0200 Message-ID: Subject: Re: [PATCH v2 23/35] ovl: copy-up on MAP_SHARED To: Randy Dunlap Cc: Miklos Szeredi , overlayfs , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Sender: linux-fsdevel-owner@vger.kernel.org List-ID: On Mon, May 7, 2018 at 9:28 PM, Randy Dunlap wrote: > On 05/07/2018 01:37 AM, Miklos Szeredi wrote: >> A corner case of a corner case is when >> >> - file opened for O_RDONLY >> - which is then memory mapped SHARED >> - file opened for O_WRONLY >> - contents modified >> - contents read back though the shared mapping >> >> Unfortunately it looks very difficult to do anything about the established >> shared map after the file is copied up. >> >> Instead, when a read-only file is mapped shared, copy up the file before >> actually doing the map. This may result in unnecessary copy-ups (but so >> may copy-up on open(O_RDWR) for exampe). > > for example). > >> >> We can revisit this later if it turns out to be a performance problem in >> real life. >> >> Signed-off-by: Miklos Szeredi >> --- >> fs/overlayfs/Kconfig | 21 +++++++++++++++++++++ >> fs/overlayfs/file.c | 22 ++++++++++++++++++++++ >> fs/overlayfs/overlayfs.h | 7 +++++++ >> fs/overlayfs/ovl_entry.h | 1 + >> fs/overlayfs/super.c | 22 ++++++++++++++++++++++ >> 5 files changed, 73 insertions(+) >> >> diff --git a/fs/overlayfs/Kconfig b/fs/overlayfs/Kconfig >> index 17032631c5cf..991c0a5a0e00 100644 >> --- a/fs/overlayfs/Kconfig >> +++ b/fs/overlayfs/Kconfig >> @@ -103,3 +103,24 @@ config OVERLAY_FS_XINO_AUTO >> For more information, see Documentation/filesystems/overlayfs.txt >> >> If unsure, say N. >> + >> +config OVERLAY_FS_COPY_UP_SHARED >> + bool "Overlayfs: copy up when mapping a file shared" > > a shared file" ?? This is referring to MAP_SHARED flag of mmap(). So it's the mapping that is shared, not the file. > >> + default n >> + depends on OVERLAY_FS >> + help >> + If this option is enabled then on mapping a file with MAP_SHARED >> + overlayfs copies up the file in anticipation of it being modified (just >> + like we copy up the file on O_WRONLY and O_RDWR in anticipation of >> + modification). This does not interfere with shared library loading, as >> + that uses MAP_PRIVATE. But there might be use cases out there where >> + this impacts performance and disk usage. >> + >> + This just selects the default, the feature can also be enabled or >> + disabled in the running kernel or individually on each overlay mount. >> + >> + To get maximally standard compliant behavior, enable this option. >> + >> + To get a maximally backward compatible kernel, disable this option. >> + >> + If unsure, say N. > > For Kconfig (coding-style.rst): > Lines under a ``config`` definition are indented with one tab, while help text > is indented an additional two spaces. Not sure what went wrong there. Fixed now. Thanks, Miklos