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: 10648103 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 B282717D4 for ; Thu, 18 Oct 2018 20:23:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A55B328D8F for ; Thu, 18 Oct 2018 20:23:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 98E9028D94; Thu, 18 Oct 2018 20:23:45 +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=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4057028D8F for ; Thu, 18 Oct 2018 20:23:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D49A76B000D; Thu, 18 Oct 2018 16:23:35 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id CCEF56B0010; Thu, 18 Oct 2018 16:23:35 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AFCC46B0266; Thu, 18 Oct 2018 16:23:35 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by kanga.kvack.org (Postfix) with ESMTP id 822F96B000D for ; Thu, 18 Oct 2018 16:23:35 -0400 (EDT) Received: by mail-qk1-f198.google.com with SMTP id x75-v6so32189886qka.18 for ; Thu, 18 Oct 2018 13:23:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:subject:date:message-id :in-reply-to:references; bh=hGTHjPlv3HOhn5TB2Ipo9k7piqoFCis94sG3VyiCA5k=; b=KDEFwCI+ntS9vyKBxmx4bFZtVI26oBm+VnQsnEE3dx3EoZFZ+qLZ6ASaGvzi+dlx33 ufJRlm8tks389GOutGOoa6i4Dfvxa1klHrPg7C3LCf2QuEeovZB2eu7CW5m19RJQf4yB MT+h/h6lQzgf9srFWdzDt+pnJUd7zD2xxpq8BdLqYexfkyqMvOzSdbaTZmkMrm9/m9c8 0wvXdjhF2GWRc4vpAurErar2+HgePlDDn0YkqshoE6sU3dG1eo2VQdSaTR5WavYUF7YT uzUJ9gIJMe4jLnxQGQVYt2zkQ68eeNQuiVtHEG8pteZFFAq2VmJPI/jwl4AvmKbhhRAu kptQ== X-Gm-Message-State: ABuFfog1fYrtxztkZ4GwD5x1MZYWYOPH5Xtk9q5ZvC2qccPbbE9jX4eO 0STmmTT7QEmG0zLdWj1r+XXiIIH/UqezmU/bqMZAWc2QcUqMmIq9YoIK7OrlsCwUdQO6XlJUMeF 5nX74CYRtNw6TH//WXgH9PmxJ5fuC8sqZJQxsJmh+WHx07UQNTz9xG4Aa8F18s4eKDmru2XzBCI nubsbqiwPkkDcFzD/EQ+JirzlNvEOkKyptyw3X4R7JMdrN/HbHo7iB7zoIFGdZGbJNJ1pqHBo8x KVsN9AjJQ/We9fYzlZlw/4rLomjD9WQU3VgZ81C+I+iXou/zb0Ak+5NtCQ1a1Srfqeqn1q4UD9F fdhF/U58udZQjoacow8Q+LxaG0WwRl+uQzg0uIGFLhHQjDcGZJZe95qQaXdbDUG+mMlsamhMBxk C X-Received: by 2002:ac8:39c5:: with SMTP id v63-v6mr31093767qte.273.1539894215312; Thu, 18 Oct 2018 13:23:35 -0700 (PDT) X-Received: by 2002:ac8:39c5:: with SMTP id v63-v6mr31093733qte.273.1539894214713; Thu, 18 Oct 2018 13:23:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539894214; cv=none; d=google.com; s=arc-20160816; b=ZD1bXwEy2SARsWvKn0g5gNUwrHGLwCEAesUs0CDC5NEjxmOhgOU6AAV/RlPOvkLWxx LhUheTq5GDarQKcCsCBeog6cKnDKxLvmMc1hDrMdZ3RmyWQM1K5mL5VqzuASPHAKtO5O M+6LEYadjCkjqkSbwVzmDaszsl3N7Ny4NzzUMcUN7L4aHuzC9KKe/YnTjzhmysB/pmy3 pTYh23NxsXcm/k8csvD+X5ITd2gFFOjrcJYfzZHYb1m5Uy3A2FQTgfuJP72VnZHeGp3p Yuc6XeIDrf/oTw8L0cwhbgTvPI0AXHtaIojHT2njAfhEg0Wkw3xoXWjpcszenFcPot2m imwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=hGTHjPlv3HOhn5TB2Ipo9k7piqoFCis94sG3VyiCA5k=; b=VWHHmfjT3UN161mGqfcqCBAiGocDgde05pSHj7mn41SKSJxvhP+e6EZn/5d5a+KNrN wm7C895Vn5wenUQvRBncokpnHvSgv5X1UDEu/kcPVylq8ROkujDBe6jv3EmrD4E7M3yg 4843VntDhOApc9z1OQhrqvwq8uzkH7P15xE2s0C9/LQoBfLmMwkHhPhYJfp7YEUT7FO2 GpJnJcR5xBzviF93vtEv5gxQ65OH7qWY6jBAXCNI6EZTIwrz+V/wN24/ahw3XNL6ie9P oF5Byq6a4H2VHgp0ZY72lxBEz5hfZ9LaSbMEaf6hOVUuRnW+0beDyw9bc1YdoCxlXvmt /tSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@toxicpanda-com.20150623.gappssmtp.com header.s=20150623 header.b="nT39Y/I3"; spf=neutral (google.com: 209.85.220.65 is neither permitted nor denied by best guess record for domain of josef@toxicpanda.com) smtp.mailfrom=josef@toxicpanda.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id f35sor14318138qvd.54.2018.10.18.13.23.34 for (Google Transport Security); Thu, 18 Oct 2018 13:23:34 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.65 is neither permitted nor denied by best guess record for domain of josef@toxicpanda.com) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@toxicpanda-com.20150623.gappssmtp.com header.s=20150623 header.b="nT39Y/I3"; spf=neutral (google.com: 209.85.220.65 is neither permitted nor denied by best guess record for domain of josef@toxicpanda.com) smtp.mailfrom=josef@toxicpanda.com 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-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> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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);