Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1237190imm; Wed, 26 Sep 2018 14:10:17 -0700 (PDT) X-Google-Smtp-Source: ACcGV62jUlgp33MeZwrCfJNrZwH41xwgr1KHS2LW1ZRjebw7wn0xnTqg7B1/3axg0Norx25pWs5V X-Received: by 2002:a17:902:934a:: with SMTP id g10-v6mr1602816plp.288.1537996217851; Wed, 26 Sep 2018 14:10:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537996217; cv=none; d=google.com; s=arc-20160816; b=umtMzuk3hB2bkDS/SCv/AZCNKpEbjLjSVhdMZVbVpgJcxI8XGNk5fcy87/31qBNnsb 95aQQJRck6MgyW5GUmm+UEIhfhDi/LxqspZ4rUWbkxitFn+ql0AcCB3STqGNc4Dx+Oic WUkAcd+BLTR/3ayFYoCtGLrlrapv5pXeCWqoDyOLJBJAOHikr8VGwxRDt87OIhV+BAli Sw2vwUqnzytp9WDid1El4eLhAES67q+PhwXc4JQ8FfTCWgu+vfN7VLx45KGD6Gm8AoLi SONOiURXveBSJHv8o5vf9JQf2QvJVQKCM+Zp9w0hseb6+octyyzCaR3NRIoRmqn5D02d l9Gw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:to:from:dkim-signature; bh=hGTHjPlv3HOhn5TB2Ipo9k7piqoFCis94sG3VyiCA5k=; b=Efxai5gbwxdzzaaZI2EGSt8Mm+AJ/8OFlvUDNCjpQJvTrsWoKWw8Pp4OTNSKlPT5Q0 3hB/aGcQRGDmZHtd5DGFSXTsCVrWN4S/XFo/XMPH4Z9XnYhUnE0x1zVzFzWrd+PhHilB XB6wYsd7He7ytIR49p/hoXz2/+Eis2IaTl0++SYP65CAuaP2j0Lj05UW7/KloqnBB1k9 wCMUPwmbvyLVJkICnszNrRBJdWoY1pCRIu//+GaArEQN1pAomAZ7dzQAoqXDEcOxPCFE 2sg9tfSGJ4OYTqlwafg3TIj0ZMFhhNX1RTGpRNR+nqO0j4VSbmo73XbyupuvTv+8f2vD TURg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@toxicpanda-com.20150623.gappssmtp.com header.s=20150623 header.b="NSXsHzI/"; 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 u26-v6si55262pge.590.2018.09.26.14.10.03; Wed, 26 Sep 2018 14:10:17 -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; dkim=pass header.i=@toxicpanda-com.20150623.gappssmtp.com header.s=20150623 header.b="NSXsHzI/"; 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 S1727304AbeI0DYC (ORCPT + 99 others); Wed, 26 Sep 2018 23:24:02 -0400 Received: from mail-qt1-f172.google.com ([209.85.160.172]:39257 "EHLO mail-qt1-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727271AbeI0DYB (ORCPT ); Wed, 26 Sep 2018 23:24:01 -0400 Received: by mail-qt1-f172.google.com with SMTP id c25-v6so493426qtp.6 for ; Wed, 26 Sep 2018 14:09:10 -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=NSXsHzI/XYShoNL8eGn0laEEoasfKJMhCPMQwHJ2Yvq8bwk04MyKO9oggPZ3BkE18j olp6YBCPQkeZXNp6oFQ9wE8pCqCakgzN1+c7Yf+qmYZnyq8kxdmoMhi8XJ6C2WRQrGQy nRoPCsn5CexUjHhSeDaxBU9NGB0VSELXL9DK0C6Xgh9Ttpe1SYyyAjXUFByg3xAEnsQR o3wyXeLFBnMiBJl6O7+7dZtJdtDKFbvgEAqm2FnuF2w27uQ/bdPH0KQypM/fZS0r/kzB YsM3KwlXFUWsqcyPrPhoIeoekAN5UBtpHcpIjSVtC5HZe9iiYCCrMpVAVC43s00HglYC UBCQ== 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=dZEtKAp+mfaAR5zPC9+nOl3Z2hPq98tsFGUI1RG4kK0oJGD6kaQT0+r3iu6yhOXzmw kPG5I9UP69qxoHJcuM13WrasujChbOfmRJBpgolRqh49kTxBt5d648B5mS1yWvlFtcZW /saTBL+p01z/aFEjS+NIpUOQovRSFhjEBmDIRPbH51FIgN/pJmKDF01Jfl81PV2xbqh4 rZpDLPx0hY+aLdsxjni4yuf+tk4QvKRVOdLfT+CdcloVGr/6J2PclPiqn4G/DQOx3cwu lQavhxk+7GaRSRYLmeMAytZ4L92PWjQSh4KYNZiIhYUdPd2/pZeIGbNje7oE3zI+eppo hp8Q== X-Gm-Message-State: ABuFfohmbufzKGeFgZpmrhxmSLpkQWzAMHrEZ1v4twVBd5HHSj2E4H5j tV1xixz3V7Yz90dhQ2npyAANRQ== 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> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); -- 2.14.3