Received: by 10.192.165.148 with SMTP id m20csp4414547imm; Tue, 8 May 2018 08:06:13 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrchRbmFcwYj0QKHrqF3HzKOcSC3sh4SpQOy013RERd7ubZjMx6wBryxmZli1OEK49cmLQm X-Received: by 2002:a65:4c4d:: with SMTP id l13-v6mr33372368pgr.46.1525791973250; Tue, 08 May 2018 08:06:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525791973; cv=none; d=google.com; s=arc-20160816; b=Gk7vqmnbLHTLvieb/6pSGCcmTRZJ4XvZNHgTt6iy25em/zjBLNU40hDvheWJbNcRMD Hm1xggqeunC76+Tv7tKOQjivcWexrq97XJYwLJ64yw3afDR8/XMANxYirDvFM7Gvb0Ml QESyyW4MTEOFLXiurhkRTVfmGavbTgFH0ZHttjCU/af2Gsizik0widm3PaZJG2SDh9ER gui/7WzNGvBn8BrwFoPb0o3Rxrz66QsfVCS9ElUkThwpe5GHN2AK4CXtlHcMzIRQmVL/ BOucsHdeK2uYkAVZkKYUcmOZpRE2wjoJ5AF+MuueDtoSGeJcPQCiW5lNAQdJ5IFjg2vd RkSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=7TD4lmr/IwuZhGnCXbngWcxeH8stvXwf+zhL+w2nQX4=; b=csYPIqJsDAN4+QgEAuiIEjictqFpqtARZglcS932xDQHU0+w8drQLdoRj63lEyYA69 a8fh5hIeAw5K3uxjrxPxRoEKXU2ycpauNtm+4QZha/fxBnErya12vmpsoka5/LnF6ivp KtsNW7maPWk7SKZiNwF3hsksRc6B8/CrV4N2/lthigL42ZTihIbTrk5ehRtCMv345QhT iSjcSZzJAyWkMTQYSPtdrJZNTdq3KwrhbZqA/pkKzA8dxeBtzELgsNYagPFPqoA+/NXL FID2CvNgrz+etr6TRgZx4Mew+iZNmkL6uF6WjNdQ+mtHaBi08deoXep2KHVX7GV1zWoh U/7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=temperror (no key for signature) header.i=@szeredi.hu header.s=google header.b=M3khqJTj; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ay2-v6si8683468plb.210.2018.05.08.08.05.58; Tue, 08 May 2018 08:06:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=temperror (no key for signature) header.i=@szeredi.hu header.s=google header.b=M3khqJTj; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932923AbeEHPDw (ORCPT + 99 others); Tue, 8 May 2018 11:03:52 -0400 Received: from mail-ot0-f175.google.com ([74.125.82.175]:45557 "EHLO mail-ot0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932722AbeEHPDu (ORCPT ); Tue, 8 May 2018 11:03:50 -0400 Received: by mail-ot0-f175.google.com with SMTP id 15-v6so21618422otn.12 for ; Tue, 08 May 2018 08:03:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=szeredi.hu; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=7TD4lmr/IwuZhGnCXbngWcxeH8stvXwf+zhL+w2nQX4=; b=M3khqJTj0r37ZCMGOHV6Ak014M3O2wBek6fFQnZb3xdsAHMlpL+ZTMX+L9N9MDAaej /CGJsWpZ560yeh8owevah8nLvNDVaPjahlprMdB8zVHtaYqFhoreR0P1dGDOzjikVvq0 HqxsknUNy9gbQn5F3EOsuJTrAECpLCIKe9BD0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=7TD4lmr/IwuZhGnCXbngWcxeH8stvXwf+zhL+w2nQX4=; b=IEaZxwI5stWm5Qx7lA5eYCCkRM2XfocvP0CFMZqLuWUdD1VSpqL+/g1FgKYhvpPtGb AeMgAP7WjbPRzCqrPOf8I3sv9ob7dwD8Fdw7xmL1oJmileEdPMp4snHXQGeM3v9oL553 1OhWugrdYohnp6SL3cAuUN1Jvbf4gbJ4+enUOJPIMPG8XsIXeDKYjDLR0pXzoSaDocTI hAbjczQYAm8EGFExNOACm+X5XOt6pod620JkezRvwZatBlONUhEWaFJ/4rFb+KH2huT4 w3df+jUBDdOy9DHVJcjZkxx9I9RxqjuylcJ0l4aSCHzcnEeanBI6/TBpqcBQJSqOzEVM euzQ== X-Gm-Message-State: ALQs6tD4t96W9wxc6HNtmFkXde+qx/I2rTgU9t2IVREg9BK7IAbpdI4X yXmACpe6I+eJD8CHi5DVY9ca3OaLROwCPCYa30gjSg== X-Received: by 2002:a9d:4c0e:: with SMTP id l14-v6mr7727940otf.242.1525791829851; Tue, 08 May 2018 08:03:49 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a9d:5303:0:0:0:0:0 with HTTP; Tue, 8 May 2018 08:03:49 -0700 (PDT) X-Originating-IP: [176.63.54.97] 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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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