From patchwork Wed Sep 26 21:08:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 10616857 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 2197A3CF1 for ; Wed, 26 Sep 2018 21:09:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0E2CC2B7F2 for ; Wed, 26 Sep 2018 21:09:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 025002B7F8; Wed, 26 Sep 2018 21:09:22 +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=ham 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 84B152B7FC for ; Wed, 26 Sep 2018 21:09:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6A0A48E0001; Wed, 26 Sep 2018 17:09:11 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 6292F8E0008; Wed, 26 Sep 2018 17:09:11 -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 51D318E0001; Wed, 26 Sep 2018 17:09:11 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by kanga.kvack.org (Postfix) with ESMTP id 235D28E0008 for ; Wed, 26 Sep 2018 17:09:11 -0400 (EDT) Received: by mail-qt1-f197.google.com with SMTP id d12-v6so358901qtk.13 for ; Wed, 26 Sep 2018 14:09:11 -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=N0retUaey2Uezq3zIg1xlSMC2bO5x9Jzm5awr9HxXHs1nT/d2kAXbV9u/FhS/FAsZ4 LGAmGGVAqUoQ5+vsDqSM7RVmDibxwATyzbqRNOJJ5VIByQ/1NvVWmyAvnxPeXTAGhlBE HB9HyMvjbGD6z2RD4RMGS/kjPhn+uxGnAr4z8WwNej5JT6x74A1tnvBpfN0xm2M/FY6x mdrL06vAgCCvsGIcJVSGoiPty0LdLccFbYa15LCmVba4BaDd2l5EDkG8l7RQS7K9NLgz qWbb00zWIwRLg6VQ5zfCuUORQnUDeLINFEK3GhxMmvLaz8jlcZNOQ8uQ2Sjci2WXXLs/ gMJg== X-Gm-Message-State: ABuFfojLXgzdxXbxwfBXgUZY5hq8jGF2AYY87/m/3l/xWMwoyHQu8Pwk S7F88igdD84gQ4pVtMBj0UYgmEOkOQkKb2iKzACOhuxFCAspb6ePh0tBrXFvqPjh6cCnLNkFQN1 YkwS/YDdbfOkAACwgCh27Cu6OdlJixCHc/SjQtDGnPpmV55LWKQCC8WKGyOSz+EpIZcIZ7KnzSA fx8+xNLllCKh9omGDUPZCgIL8kmm+ce1ZSiiH/fON+3y7gAuLxCYCJgHDVDbeSajY2NiS5N+Esu Nsrk06lxoF6zcryi7fqTLEmq49tY9j8OLVOEu/Y1Wam4V3g1BRsU0wVo72n3rgyi361cEDHfLO2 uRADoi0g6hsSPPwFMoDR5AVyanL7JxM78dZFlOcIy4OjeialPGQFvv+eC5qwWPszXFNPlWeGgom / X-Received: by 2002:aed:2050:: with SMTP id 74-v6mr5992336qta.166.1537996150922; Wed, 26 Sep 2018 14:09:10 -0700 (PDT) X-Received: by 2002:aed:2050:: with SMTP id 74-v6mr5992303qta.166.1537996150345; Wed, 26 Sep 2018 14:09:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537996150; cv=none; d=google.com; s=arc-20160816; b=crJqnaAB+e0JsJg4Y2hrDbT3UGrXRmTOOPv1SBACNlFHS+CK28Wxdt8yk1QK1yOEgA MAvvkyMdaET4dkbP6n+7QbgWc6wbrBJf9W1Ka1mMVlb01RxpA3GdJu1c9AIgzc4WzRet bNwAFs7Oac22gW1enGhEuXWMG56pnCYTYjCRLpFVMuD/MTjSuGR5KFK9swUUXZkyHOyh zBdt+pVkc7N8TsdAWQYuC/MwH3ooK6l6qcs8pRVGGjVFb/thTVQYVoAWYBOUqL2TDRpJ QI90omlYpe4sDLZip1fEvQDjuVFGMioUiQtunmkha0SOwamm/cSQyDRIyBWCYRkuKnAw QxEQ== 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=0U7eUyWk2evSzYjNHj+qAbOVz0Qr23rM0//ZYd+fFvLMXG4CWVgPtNWkXgfjvoVBMR Y6UPMEFfQPeb7LA4VEx9fvv6+LdcCwPwBNjcVow3ZLPeCrqr5+E3vVstbeEucyaCr0U9 +zd1TecJ/8RjUMWeYXYxe4xtdEw8otAp3zv/Q62HBZZQxPUBe8cGICIkWD2E1EWhiOTj wbQXo90/R96R3ucS2kj8uzZrV+fKU6dX7C+RDjLVBcaZ9ROAaSN6NmgzO7L2wV+KFaeB Jnyr0HtZlFpIrF3dgVIp4rVlRvTvX+ZZtl4cbrjra6CpnEi+5gYnweOZbSiqEdnRhtUW C7mw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@toxicpanda-com.20150623.gappssmtp.com header.s=20150623 header.b="NSXsHzI/"; spf=neutral (google.com: 209.85.220.41 is neither permitted nor denied by best guess record for domain of josef@toxicpanda.com) smtp.mailfrom=josef@toxicpanda.com Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id z47-v6sor64108qtg.10.2018.09.26.14.09.10 for (Google Transport Security); Wed, 26 Sep 2018 14:09:10 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.41 is neither permitted nor denied by best guess record for domain of josef@toxicpanda.com) client-ip=209.85.220.41; Authentication-Results: mx.google.com; dkim=pass header.i=@toxicpanda-com.20150623.gappssmtp.com header.s=20150623 header.b="NSXsHzI/"; spf=neutral (google.com: 209.85.220.41 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=NSXsHzI/XYShoNL8eGn0laEEoasfKJMhCPMQwHJ2Yvq8bwk04MyKO9oggPZ3BkE18j olp6YBCPQkeZXNp6oFQ9wE8pCqCakgzN1+c7Yf+qmYZnyq8kxdmoMhi8XJ6C2WRQrGQy nRoPCsn5CexUjHhSeDaxBU9NGB0VSELXL9DK0C6Xgh9Ttpe1SYyyAjXUFByg3xAEnsQR o3wyXeLFBnMiBJl6O7+7dZtJdtDKFbvgEAqm2FnuF2w27uQ/bdPH0KQypM/fZS0r/kzB YsM3KwlXFUWsqcyPrPhoIeoekAN5UBtpHcpIjSVtC5HZe9iiYCCrMpVAVC43s00HglYC UBCQ== X-Google-Smtp-Source: ACcGV63X6GJlDkWL3trIfKsJDYg6xMkxeDmRSldNmGu6BvcZd3OT+4MyGR7tfq+GMXsjHNWbVQwYBQ== X-Received: by 2002:ac8:2672:: with SMTP id v47-v6mr5865520qtv.287.1537996150087; Wed, 26 Sep 2018 14:09:10 -0700 (PDT) Received: from localhost ([107.15.81.208]) by smtp.gmail.com with ESMTPSA id y143-v6sm33940qky.95.2018.09.26.14.09.09 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 26 Sep 2018 14:09:09 -0700 (PDT) From: Josef Bacik To: kernel-team@fb.com, linux-kernel@vger.kernel.org, hannes@cmpxchg.org, tj@kernel.org, linux-fsdevel@vger.kernel.org, akpm@linux-foundation.org, riel@redhat.com, linux-mm@kvack.org, linux-btrfs@vger.kernel.org Subject: [PATCH 6/9] mm: use the cached page for filemap_fault Date: Wed, 26 Sep 2018 17:08:53 -0400 Message-Id: <20180926210856.7895-7-josef@toxicpanda.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180926210856.7895-1-josef@toxicpanda.com> References: <20180926210856.7895-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);