Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp696100ybi; Fri, 21 Jun 2019 06:41:06 -0700 (PDT) X-Google-Smtp-Source: APXvYqyi6WHTncMxSUdyRybfdH/8zgOkhQjzPH6J3BdJCD15JNHxFkNmjes/TkN4UBdu+xtNuVjA X-Received: by 2002:a17:902:7891:: with SMTP id q17mr76460412pll.236.1561124466502; Fri, 21 Jun 2019 06:41:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561124466; cv=none; d=google.com; s=arc-20160816; b=EBOHVuuwSb2tvsY+mE3UOgcV8DQIiVM9AGVOWZEM/XVMnfAa16t2jGVwecwEDR6/Yu PVsiNV8nCHXYSge6VRGndPBOGEMs8Q3zc5GXHAOua0N6OLHaeLoN/YvI18LNrMLt9XEM mCWgcY9LQlIF9YgTl3T4NSSZUqSNMx3wnH/qvrFNcnAIeqQNILP1DTHij1ExL/9rijhg +YOHdYcnxxxn7cNWwNsp4n857Z0OEbxKEgxlwzH2+QwLcUh9vlZA2IHdrDdbkPjPUi5J D/zXf83gclukFpuglz5PVx7cdczba8AcxdZrCmuIphrAs/XUT6KD5kDyYj1ckXfj9JcB wqlQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=AdpAsciClW5VStBwxplQLFyT5xLaWG5vW4nBjzS9ue8=; b=FqHcqmCfSPLrtSu0tt/E8XhOf/ln3XcP3/JczsgKOziWNowOweWWAGd1NhwxXR9OLr 9mm1seHQj/XqR4mc1bfAs9KuhB+xBtjNhLL1RBI8yAWKOUZYbBXY4Eemn3NkFyj2ptEh ADT/1F74TJ2m5Mzma/dx0DsjkNSs1uMlw4MVCJEHUElTQJ4caTr3if2wdQfOAN56WQiL SEbMpz/WKtg3kgrPea+NFXdrE25UbSuuKGSTvCS66xE7CYl/aiPtkcS620Hnt/WdmzTE u5Jhn4ydsYeYqIyzeLNqnjSfRNSRRcxBpFw6+sAxFDue5Ce2RaPEFSMHjdG9jydr4jHI TpMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=MMv0Ydn9; 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 j4si2568939pgh.251.2019.06.21.06.40.51; Fri, 21 Jun 2019 06:41:06 -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=pass header.i=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=MMv0Ydn9; 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 S1726382AbfFUNju (ORCPT + 99 others); Fri, 21 Jun 2019 09:39:50 -0400 Received: from mail-ed1-f67.google.com ([209.85.208.67]:35609 "EHLO mail-ed1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726178AbfFUNjt (ORCPT ); Fri, 21 Jun 2019 09:39:49 -0400 Received: by mail-ed1-f67.google.com with SMTP id w20so2568952edd.2 for ; Fri, 21 Jun 2019 06:39:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov-name.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=AdpAsciClW5VStBwxplQLFyT5xLaWG5vW4nBjzS9ue8=; b=MMv0Ydn948bMlAsUr3EOQTiiiIsndLshwaLg99cYJeSWvgk03QQ2LSLT1DwHnI+ttt fYLpn0rHMLs5dRVqs577Vdjp9fQVNg1AI7YMotlVBRgN2G+jxYa30fNPDT4cxuIBbnbv dvkhiikckPj8I9WO4qszbrxQqjT4JDmftO4ZkqoU6ylL3W02f46VZgCH18TT1nSpqoIR iYL16BfVrpSfbVFU4fdiZv/1CJyG5zDKZV62sGCL+E2XVUEGFbl4jyZB5dUrvDb+Wm2X ESnK59f5G2A768/OcKoYqJIV3GVjhBwChxmegwrnBe1M3OaBl4qF1jOpFlqBJ6y5eTG+ g4KQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=AdpAsciClW5VStBwxplQLFyT5xLaWG5vW4nBjzS9ue8=; b=SnXyjwC/+oOaRx5+CI1cAeM/59SpwKEpBuzPsnIPOWI8mp4JT8AhK6XRfxg1YeUlR/ FDQ+XCciQh4VkYnuAxWzzm9mtBXraE0Z7Qbr+lpFO9IqprkwaeTfiEpcyMlWl+nlf+H3 k/oc21ZEzZJPAU2mX6+H6CDxhcbAB4Ep4mBeU6fcGW3aTMwYD2Dp6u7Q+CG2f2GkQJoQ /rAWdmOFObohBSulcGkc5UjLvk+5mP9ceeTENwNcjegbdgZ6u4x696gF7pMnzvQe2l2s vpZr01wCUXTorq28ioSo3yMIcq+VDBZmsM8/SDRvc2rdlj9blbYvAswXoN6sTlXS15E4 lvHg== X-Gm-Message-State: APjAAAX0E8w3jrf4HXcqaQy818ri8uca0HWSLduK0D4Evn60JuQ5/Nk3 Vk5qjRFjmCOj4anqQD6ZbsAebA== X-Received: by 2002:a50:974b:: with SMTP id d11mr110357427edb.24.1561124387072; Fri, 21 Jun 2019 06:39:47 -0700 (PDT) Received: from box.localdomain ([86.57.175.117]) by smtp.gmail.com with ESMTPSA id c49sm856113eda.74.2019.06.21.06.39.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Jun 2019 06:39:46 -0700 (PDT) Received: by box.localdomain (Postfix, from userid 1000) id 779E810289C; Fri, 21 Jun 2019 16:39:48 +0300 (+03) Date: Fri, 21 Jun 2019 16:39:48 +0300 From: "Kirill A. Shutemov" To: Song Liu Cc: Linux-MM , "linux-fsdevel@vger.kernel.org" , LKML , "matthew.wilcox@oracle.com" , "kirill.shutemov@linux.intel.com" , Kernel Team , "william.kucharski@oracle.com" , "akpm@linux-foundation.org" Subject: Re: [PATCH v5 6/6] mm,thp: avoid writes to file with THP in pagecache Message-ID: <20190621133948.2pvagzfwpwwk6rho@box> References: <20190620205348.3980213-1-songliubraving@fb.com> <20190620205348.3980213-7-songliubraving@fb.com> <20190621130740.ehobvjjj7gjiazjw@box> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 21, 2019 at 01:10:54PM +0000, Song Liu wrote: > > > > On Jun 21, 2019, at 6:07 AM, Kirill A. Shutemov wrote: > > > > On Thu, Jun 20, 2019 at 01:53:48PM -0700, Song Liu wrote: > >> In previous patch, an application could put part of its text section in > >> THP via madvise(). These THPs will be protected from writes when the > >> application is still running (TXTBSY). However, after the application > >> exits, the file is available for writes. > >> > >> This patch avoids writes to file THP by dropping page cache for the file > >> when the file is open for write. A new counter nr_thps is added to struct > >> address_space. In do_last(), if the file is open for write and nr_thps > >> is non-zero, we drop page cache for the whole file. > >> > >> Signed-off-by: Song Liu > >> --- > >> fs/inode.c | 3 +++ > >> fs/namei.c | 22 +++++++++++++++++++++- > >> include/linux/fs.h | 31 +++++++++++++++++++++++++++++++ > >> mm/filemap.c | 1 + > >> mm/khugepaged.c | 4 +++- > >> 5 files changed, 59 insertions(+), 2 deletions(-) > >> > >> diff --git a/fs/inode.c b/fs/inode.c > >> index df6542ec3b88..518113a4e219 100644 > >> --- a/fs/inode.c > >> +++ b/fs/inode.c > >> @@ -181,6 +181,9 @@ int inode_init_always(struct super_block *sb, struct inode *inode) > >> mapping->flags = 0; > >> mapping->wb_err = 0; > >> atomic_set(&mapping->i_mmap_writable, 0); > >> +#ifdef CONFIG_READ_ONLY_THP_FOR_FS > >> + atomic_set(&mapping->nr_thps, 0); > >> +#endif > >> mapping_set_gfp_mask(mapping, GFP_HIGHUSER_MOVABLE); > >> mapping->private_data = NULL; > >> mapping->writeback_index = 0; > >> diff --git a/fs/namei.c b/fs/namei.c > >> index 20831c2fbb34..de64f24b58e9 100644 > >> --- a/fs/namei.c > >> +++ b/fs/namei.c > >> @@ -3249,6 +3249,22 @@ static int lookup_open(struct nameidata *nd, struct path *path, > >> return error; > >> } > >> > >> +/* > >> + * The file is open for write, so it is not mmapped with VM_DENYWRITE. If > >> + * it still has THP in page cache, drop the whole file from pagecache > >> + * before processing writes. This helps us avoid handling write back of > >> + * THP for now. > >> + */ > >> +static inline void release_file_thp(struct file *file) > >> +{ > >> +#ifdef CONFIG_READ_ONLY_THP_FOR_FS > >> + struct inode *inode = file_inode(file); > >> + > >> + if (inode_is_open_for_write(inode) && filemap_nr_thps(inode->i_mapping)) > >> + truncate_pagecache(inode, 0); > >> +#endif > >> +} > >> + > >> /* > >> * Handle the last step of open() > >> */ > >> @@ -3418,7 +3434,11 @@ static int do_last(struct nameidata *nd, > >> goto out; > >> opened: > >> error = ima_file_check(file, op->acc_mode); > >> - if (!error && will_truncate) > >> + if (error) > >> + goto out; > >> + > >> + release_file_thp(file); > > > > What protects against re-fill the file with THP in parallel? > > khugepaged would only process vma with VM_DENYWRITE. So once the > file is open for write (i_write_count > 0), khugepage will not > collapse the pages. I have not look at the patch very closely. Do you only create THP by khugepaged? Not in fault path? -- Kirill A. Shutemov