Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp2699853imm; Thu, 18 Oct 2018 20:51:03 -0700 (PDT) X-Google-Smtp-Source: ACcGV62WmK+raAqAoH0r/UQOmcOpTZdIRTt2evtSehSQkHQABuRg/e09RC/4Zen2ksInjYtUug6Z X-Received: by 2002:a62:d75e:: with SMTP id v30-v6mr786888pfl.90.1539921063378; Thu, 18 Oct 2018 20:51:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539921063; cv=none; d=google.com; s=arc-20160816; b=NRlcVX3pBka7e89Tuty0/QK4CqTs9dGGq2Uf+2t1vNPCr3Gb+NzkSmwKgPrQR6w6Z/ IqNXVjO+2ljEH/prv/TCT/V+A89WSHx6N/hjn0DEPz0P5ETVdOGQxAhAkrLK2HMmKtv+ yMnpiD9Pzz+xwN8DlwRo7w5fJOzW8moUKuVXGaALw7IAUfovR+5jhurXy5BjwLLA+qIo fyDsOpAwYRHA/GVe8oTJXqzdxh8l9u6mP/+8Lrx82VQR6dCiWmcFoMLULVPo53xsX5AV MuWXl++AsELf1rSkq5FgUT+awU89Z6wbjnmA5N6xz65wPco8u+PFEU0Z8OF5zMAAXdRG 9NjA== 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; bh=rJv6VzFbUD+lfZ16D6b4DAMW+WSn3Fl+cZ9R5RY9uNk=; b=reg5qUkW2bU+WDtVBcNvrnqar8+yp18CZ8hyF43zbgVJsbTN/IhJavRPtncA0IWpW6 T7qYUoirgnonUXQewy7cKYaC0KRxwbEq2h+Kk9sBWBSpDzJhef3w44fbsr8fwKrxEI7z wlRGihExWIFKpa1y2aBIkN61RE9sNHnym57CdhOWq78KsD1u6fdArtbHms4GXVYDHuNH /GEzht0bN4/v84l0mt6mhC/1LXplMdpEGfQNpm+LGoUj7xebBq7e4XWpJ0CABUvNaW8x 7jpVYrCMkxkedrEjvWEjk9GWzbZW5lwg7E8jCEAjeGnTF0ReK9lkImJdDBcqBtNBJgFW CgKQ== ARC-Authentication-Results: i=1; mx.google.com; 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 x21-v6si20118052pll.221.2018.10.18.20.50.46; Thu, 18 Oct 2018 20:51:03 -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; 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 S1726976AbeJSLyi (ORCPT + 99 others); Fri, 19 Oct 2018 07:54:38 -0400 Received: from ipmail03.adl2.internode.on.net ([150.101.137.141]:45215 "EHLO ipmail03.adl2.internode.on.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726478AbeJSLyi (ORCPT ); Fri, 19 Oct 2018 07:54:38 -0400 Received: from ppp59-167-129-252.static.internode.on.net (HELO dastard) ([59.167.129.252]) by ipmail03.adl2.internode.on.net with ESMTP; 19 Oct 2018 13:57:23 +1030 Received: from dave by dastard with local (Exim 4.80) (envelope-from ) id 1gDLRa-0006aP-Eq; Fri, 19 Oct 2018 14:27:22 +1100 Date: Fri, 19 Oct 2018 14:27:22 +1100 From: Dave Chinner To: Josef Bacik Cc: kernel-team@fb.com, hannes@cmpxchg.org, linux-kernel@vger.kernel.org, tj@kernel.org, akpm@linux-foundation.org, linux-fsdevel@vger.kernel.org, linux-btrfs@vger.kernel.org, riel@fb.com, linux-mm@kvack.org Subject: Re: [PATCH 4/7] mm: use the cached page for filemap_fault Message-ID: <20181019032722.GJ18822@dastard> References: <20181018202318.9131-1-josef@toxicpanda.com> <20181018202318.9131-5-josef@toxicpanda.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181018202318.9131-5-josef@toxicpanda.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Oct 18, 2018 at 04:23:15PM -0400, Josef Bacik wrote: > If we drop the mmap_sem we have to redo the vma lookup which requires > redoing the fault handler. Chances are we will just come back to the > same page, so save this page in our vmf->cached_page and reuse it in the > next loop through the fault handler. > > Signed-off-by: Josef Bacik > --- > mm/filemap.c | 30 ++++++++++++++++++++++++++++-- > 1 file changed, 28 insertions(+), 2 deletions(-) > > diff --git a/mm/filemap.c b/mm/filemap.c > index 65395ee132a0..5212ab637832 100644 > --- a/mm/filemap.c > +++ b/mm/filemap.c > @@ -2530,13 +2530,38 @@ vm_fault_t filemap_fault(struct vm_fault *vmf) > pgoff_t offset = vmf->pgoff; > int flags = vmf->flags; > pgoff_t max_off; > - struct page *page; > + struct page *page = NULL; > + struct page *cached_page = vmf->cached_page; > vm_fault_t ret = 0; > > max_off = DIV_ROUND_UP(i_size_read(inode), PAGE_SIZE); > if (unlikely(offset >= max_off)) > return VM_FAULT_SIGBUS; > > + /* > + * We may have read in the page already and have a page from an earlier > + * loop. If so we need to see if this page is still valid, and if not > + * do the whole dance over again. > + */ > + if (cached_page) { > + if (flags & FAULT_FLAG_KILLABLE) { > + error = lock_page_killable(cached_page); > + if (error) { > + up_read(&mm->mmap_sem); > + goto out_retry; > + } > + } else > + lock_page(cached_page); > + vmf->cached_page = NULL; > + if (cached_page->mapping == mapping && > + cached_page->index == offset) { > + page = cached_page; > + goto have_cached_page; > + } > + unlock_page(cached_page); > + put_page(cached_page); > + } > + Can you factor this out so the main code path doesn't get any more complex than it already is? i.e. something like: error = vmf_has_cached_page(vmf, &page); if (error) goto out_retry; if (page) goto have_cached_page; -dave. -- Dave Chinner david@fromorbit.com