From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_NEOMUTT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 25CC0C43613 for ; Fri, 21 Jun 2019 13:07:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F03EA2083B for ; Fri, 21 Jun 2019 13:07:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=shutemov-name.20150623.gappssmtp.com header.i=@shutemov-name.20150623.gappssmtp.com header.b="PAE6OEZ8" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726969AbfFUNHo (ORCPT ); Fri, 21 Jun 2019 09:07:44 -0400 Received: from mail-ed1-f66.google.com ([209.85.208.66]:33800 "EHLO mail-ed1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726813AbfFUNHk (ORCPT ); Fri, 21 Jun 2019 09:07:40 -0400 Received: by mail-ed1-f66.google.com with SMTP id s49so10073708edb.1 for ; Fri, 21 Jun 2019 06:07:40 -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=/K0/kvf7+EWXr6rQfoz7UxMfktgW7/4j5Pgej3x77XM=; b=PAE6OEZ8NC/qeGpE32S7WnaYR8nyncYe408Jq0CgpSEX5qzdvqxgDZs5ZCZwf9z2M/ MfmA07u7v2Dcvj6N9Gc4vkUdsz3EIDYCqEMeeoBYxLeIb/y9bGSed3H8d9o3PlC4Ytxn oA+VlnKMSsS7quvovP4p8aKwmbYWhZkd0zTnk3u9Du+67+nLBJwp5bknGKkUG+ONwhjz tkTJX8Bq4oIKNeZVi+bbrVcdMW8Y1t9Y67TTb0mrmwBheAxfAtMwJDljsYfa7Ogu0jLk RAaOEsejUFYQQpQXuZEuxRWQuaGtNp10HL9BRM8wQxljKfSAywRlF4E5te+9lTIG2AOz S/QQ== 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=/K0/kvf7+EWXr6rQfoz7UxMfktgW7/4j5Pgej3x77XM=; b=f/C5O0ws7jCiGzJ6lPAzeC/d7ejCmcz8+GX39n7aY+Ik67j/b71dfkjpZp5dtUP3+I xHTDHeM+vOfnEgxIhRXYPE/cXW19Z/mRQ6h3/evAQGvtGcpy3EORgrx2JjMXZUwEVvyc 1mrU0fREaOPlP8cGcUeC73hVK/45AgiXZdNDRff6rCmeuWU52Gx3nWuFhen8vjN4V+HY xyzdT1b6iMjhbHlXv0FOhCUsKlUFHO5Lkq9gUFnqLbw+D4X1RyoqBjyhf/M2g4UU+G1v 5fxcKHAglPpb18KpWONOehHx0mkC4amDmoEVhvirizQdcjjXrg4spRXoIGyGeJiWql+Z hBmQ== X-Gm-Message-State: APjAAAU1UlTjo52T+6IbFr7dAoUw1u/KXNB0mWcYZfxPkQAM4n60qxYK zhMCNYhm8rA11nXNjt8YvaCKrw== X-Google-Smtp-Source: APXvYqwSIu9UphVAwE3sOjCJhhXK/jVAbMQD+iKQGW5Qdf6dAWE8bX5wKC8SIAJa13mOWwqqReekHg== X-Received: by 2002:a50:913c:: with SMTP id e57mr95497578eda.257.1561122459409; Fri, 21 Jun 2019 06:07:39 -0700 (PDT) Received: from box.localdomain ([86.57.175.117]) by smtp.gmail.com with ESMTPSA id e12sm813636edb.72.2019.06.21.06.07.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Jun 2019 06:07:38 -0700 (PDT) Received: by box.localdomain (Postfix, from userid 1000) id C59BE10289C; Fri, 21 Jun 2019 16:07:40 +0300 (+03) Date: Fri, 21 Jun 2019 16:07:40 +0300 From: "Kirill A. Shutemov" To: Song Liu Cc: linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, matthew.wilcox@oracle.com, kirill.shutemov@linux.intel.com, kernel-team@fb.com, 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: <20190621130740.ehobvjjj7gjiazjw@box> References: <20190620205348.3980213-1-songliubraving@fb.com> <20190620205348.3980213-7-songliubraving@fb.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190620205348.3980213-7-songliubraving@fb.com> User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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? -- Kirill A. Shutemov