From patchwork Thu Oct 18 20:23:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 10648091 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C2AF6112B for ; Thu, 18 Oct 2018 20:23:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B174A28D72 for ; Thu, 18 Oct 2018 20:23:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A526E28D8C; Thu, 18 Oct 2018 20:23:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4C38628D68 for ; Thu, 18 Oct 2018 20:23:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727232AbeJSE0Q (ORCPT ); Fri, 19 Oct 2018 00:26:16 -0400 Received: from mail-qt1-f196.google.com ([209.85.160.196]:34093 "EHLO mail-qt1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726678AbeJSE0P (ORCPT ); Fri, 19 Oct 2018 00:26:15 -0400 Received: by mail-qt1-f196.google.com with SMTP id o17-v6so35927178qtr.1 for ; Thu, 18 Oct 2018 13:23:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references; bh=hGTHjPlv3HOhn5TB2Ipo9k7piqoFCis94sG3VyiCA5k=; b=nT39Y/I3v+R7DJdgx+w05J/2Y+m3MDiWnk1nL7t4/7+CM7XiPVYhj3l2z9w5ARkDux SFUAlxO8JdvxirqMmPZTGRvyXzf/F1gf27MRw/gbTBAQeYjmUZFp91y8pO5oLUh9paj3 4Mg/pRVwYZoQ+VQkybYJi/38gUFMY+wk3NRr5cxlCblJoaTeZtKimCERIJSs/YPNhsQw Yj4RoxkBR9WrEqUR55b9S912+TOdECaPpCVpoCo8EWzHw4uHPszCM0G+xVZCMip+v2kq ZdJGjXwHzmN0UQp67pYVQo+e1u4jv2h70jkcXBy0hGhY7XII8xnk9N7bqGUI5ApV7HA9 xy2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=hGTHjPlv3HOhn5TB2Ipo9k7piqoFCis94sG3VyiCA5k=; b=WJ4tBfQJfAVoO9P+9DmDhVBfgJncNgGGVdTaJk6vPNP3U2RwJs7K0SQ/GsPX8wY7Tr lXJbh3UQY0gcMO+6RW/OND4CuYT2Xxs8wg9s4mUAmNi+D6BZwAsBUfGRb32inKVtzFT5 0zI6QxsCcbvqVo04FI46TuAw6L6s3G8K+0oAY4zkP8ZhXWckJ1xWKgPX+4cbuRDc61pu WM3EVUYao/WH5gwenATtMAQtT28Ji7NWaJJ2pXYXRUW/e4sojnMIJah34+SRoRtpc/Xr 3FKXqnQQiB34dfAbP3y8Km+BPViWpJ0ftt8r2b7d87nXfRx4XJrtw322vtyJ5M/3U6Zy 3LeQ== X-Gm-Message-State: ABuFfoi/9SNWyWZSOTzkkUcibhw3z7X+wfzlwD8W8hEuVXkshsVDguIr hE6zeP62vCAlUHyOZux11tb3Gw== X-Google-Smtp-Source: ACcGV60ajb9VJhgqek0PPLPRGAIgXrsXiS83GVhmSwgELdoGf1qud/rSb0MUwUUr9Cw3VlbImR7Ugg== X-Received: by 2002:a0c:b137:: with SMTP id q52mr11208025qvc.58.1539894214457; Thu, 18 Oct 2018 13:23:34 -0700 (PDT) Received: from localhost ([107.15.81.208]) by smtp.gmail.com with ESMTPSA id i79-v6sm14094657qke.17.2018.10.18.13.23.33 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 18 Oct 2018 13:23:33 -0700 (PDT) From: Josef Bacik To: kernel-team@fb.com, hannes@cmpxchg.org, linux-kernel@vger.kernel.org, tj@kernel.org, david@fromorbit.com, akpm@linux-foundation.org, linux-fsdevel@vger.kernel.org, linux-btrfs@vger.kernel.org, riel@fb.com, linux-mm@kvack.org Subject: [PATCH 4/7] mm: use the cached page for filemap_fault Date: Thu, 18 Oct 2018 16:23:15 -0400 Message-Id: <20181018202318.9131-5-josef@toxicpanda.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20181018202318.9131-1-josef@toxicpanda.com> References: <20181018202318.9131-1-josef@toxicpanda.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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); + } + /* * Do we have something in the page cache already? */ @@ -2587,6 +2612,7 @@ vm_fault_t filemap_fault(struct vm_fault *vmf) put_page(page); goto retry_find; } +have_cached_page: VM_BUG_ON_PAGE(page->index != offset, page); /* @@ -2677,7 +2703,7 @@ vm_fault_t filemap_fault(struct vm_fault *vmf) if (fpin) fput(fpin); if (page) - put_page(page); + vmf->cached_page = page; return ret | VM_FAULT_RETRY; } EXPORT_SYMBOL(filemap_fault);