From patchwork Mon Jun 11 14:05:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 10458063 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1F25C6020F for ; Mon, 11 Jun 2018 14:13:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DA57928571 for ; Mon, 11 Jun 2018 14:13:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D71D828508; Mon, 11 Jun 2018 14:13:36 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,T_DKIM_INVALID 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 7387428508 for ; Mon, 11 Jun 2018 14:12:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AF17C6B02D0; Mon, 11 Jun 2018 10:08:25 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id A79FB6B02D1; Mon, 11 Jun 2018 10:08:25 -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 945936B02D2; Mon, 11 Jun 2018 10:08:25 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl0-f70.google.com (mail-pl0-f70.google.com [209.85.160.70]) by kanga.kvack.org (Postfix) with ESMTP id 4F7CB6B02D0 for ; Mon, 11 Jun 2018 10:08:25 -0400 (EDT) Received: by mail-pl0-f70.google.com with SMTP id q18-v6so7471902pll.3 for ; Mon, 11 Jun 2018 07:08:25 -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:cc:subject:date :message-id:in-reply-to:references; bh=TZ3/gaq6XS6yRX727fCrlQmNfcqbJPfvdc+FduOIwpI=; b=fsnJNLyk3Hfs8sAWmZB7FFQHej8wxU8aINPPFpr6N4OTN3y4TYaDdvmfEdsYkmz5oG 1wDb6Icq27GucsBCgtjLxQuspDL7dRB+9G3Z1uBdFIysmPS0IQBBdnjTO/oNh1fPD34s JUc87pR6sbtVtHh5nJi2+hxJPIRLYh0D7XYbVmeKJz/jC7bywqSC7tfEcot/7RNS4RBY KhM6GPq2k/SsC74nGb7G46WrKiF8bQZ7aL47Tb+kHOTN6x/VGToYDiat2Dl+pcVorWqW Iy0QKps7BtVRs6Jzh3LRhGJIaNMSDMiDSqSrLh3CrAOicJ++qGxKPDSMN/7bsO46FM5n edeg== X-Gm-Message-State: APt69E034vctm5v3XjnZ21XW6m0CcpsZVRBmbq5wCMN+NZ/Oe9V/AEs6 B7pTEXE/zFAVKGtCKMwwopaSoWTuhp7ozdwv/YP5mAekoi8LuWR7FeQboNWn/elMNLAJsOtBCzi jyAu1dhb9JisMmgTB2MsF62lHIXWE2A8HuHc4dZAAYot+QU+NCZ6X7DeejDnqT7HaVg== X-Received: by 2002:a62:9bc9:: with SMTP id e70-v6mr17582971pfk.15.1528726105001; Mon, 11 Jun 2018 07:08:25 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIuqV75OE6zWfFuTp7pm40g4dsuff5MklqbLODdBuI30gY18IZOQuJdYhV8miFnKaLdCjma X-Received: by 2002:a62:9bc9:: with SMTP id e70-v6mr17576685pfk.15.1528726013239; Mon, 11 Jun 2018 07:06:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528726013; cv=none; d=google.com; s=arc-20160816; b=pFs93k8jFoMf49mx+A2qS5L0wHMBWHLFsDl+PxmHAIsm3x32u3993xYTGSfWnRJEJy Xkmgj4rT2XmQcUXUYBkfoF9Fsnn068lRs2Cpk0oFxvQMeeYuJf0y3bK96ONs93+ZGAHK tfamKNl8gD8Gb3t2utZT6XcVaZ7J4hzieD09boVsky/XuLbnq0GIDrpqLXaF6bN5cD00 H6wcZwnIGrm1qxl/I9DmQ1q/xV+hityX2pFgiupudX4DN1cgMgS4dEi2LywCPyT7iKdr 7Wm+R1btVMIw2LvxObxh7M6iKeC5d1MVP1MGhKCDH2Qg2turEOS2J8+cDelgOVrQ4fak +7EA== 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:cc:to:from :dkim-signature:arc-authentication-results; bh=TZ3/gaq6XS6yRX727fCrlQmNfcqbJPfvdc+FduOIwpI=; b=Ze2ahfPy5eqHcuwOCqvQ6SCiKHAbxGnBBj08+plyLOfNGFgcRsF4P8Mf5ipcAC5/Op /aokL+3qE//SZbz+/JKm/sTwwN9mbCEhTPyCf+lfkeix/CW1VkankGYbbI3URTAipcPg SXU5WWRfB52svwmB8TFKw5qiPBypdFY907IdVW2ARwq5NEkniPqyfEPSm/LwTEM+l/Ie i/R52AOohksCLHyE5eHNTwu2Ym0TOtxqT5Q+FOICYoxiEAg+ht+8GOtLwqVvq/KUi9nv 1xGj1Cb3zDxg82FXhX2Qww/4Q2WfxAW5eD4gNmWF16pSSDjFA2wyFNZJ3Ovi+f2NUxr7 6pUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20170209 header.b=YiYGMkML; spf=pass (google.com: best guess record for domain of willy@infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom=willy@infradead.org Received: from bombadil.infradead.org (bombadil.infradead.org. [2607:7c80:54:e::133]) by mx.google.com with ESMTPS id d2-v6si22352939pge.342.2018.06.11.07.06.52 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 11 Jun 2018 07:06:53 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of willy@infradead.org designates 2607:7c80:54:e::133 as permitted sender) client-ip=2607:7c80:54:e::133; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20170209 header.b=YiYGMkML; spf=pass (google.com: best guess record for domain of willy@infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom=willy@infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=TZ3/gaq6XS6yRX727fCrlQmNfcqbJPfvdc+FduOIwpI=; b=YiYGMkML2TP6QrHAOotEIc/Iw l7Q3bbAMEQIubujejBI60eDPOtbr+ZxiI0CKH7qkxCNs1ARFZ4YljMs8cT55WJhCxAaNdccgQTQRT sab92D61SOpyLqfjvzbCxiXLpC67uibJHdUcPFXDXA4rZLyGN06zvmk7K96YUB80nIL/KNtQbKR8J dzMrG93s6enYV7X4+niS795fg5vHqWEPauU3FprP9EApeDVop+dnmi56Hw9R6H53dVoxVrhVDA/3o LzVV5WEgiBNgGq5FEQr2VKzEQU1fXe+lh0Z+SrCDtXl7loU+o3pyHOUBDxaizXEJAD5TjfHcXzhYP EUoHcnFCw==; Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1fSNTA-0004hb-6b; Mon, 11 Jun 2018 14:06:52 +0000 From: Matthew Wilcox To: linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Matthew Wilcox , Jan Kara , Jeff Layton , Lukas Czerner , Ross Zwisler , Christoph Hellwig , Goldwyn Rodrigues , Nicholas Piggin , Ryusuke Konishi , linux-nilfs@vger.kernel.org, Jaegeuk Kim , Chao Yu , linux-f2fs-devel@lists.sourceforge.net Subject: [PATCH v13 29/72] page cache: Convert filemap_map_pages to XArray Date: Mon, 11 Jun 2018 07:05:56 -0700 Message-Id: <20180611140639.17215-30-willy@infradead.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180611140639.17215-1-willy@infradead.org> References: <20180611140639.17215-1-willy@infradead.org> 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 From: Matthew Wilcox Slight change of strategy here; if we have trouble getting hold of a page for whatever reason (eg a compound page is split underneath us), don't spin to stabilise the page, just continue the iteration, like we would if we failed to trylock the page. Since this is a speculative optimisation, it feels like we should allow the process to take an extra fault if it turns out to need this page instead of spending time to pin down a page it may not need. Signed-off-by: Matthew Wilcox --- mm/filemap.c | 42 +++++++++++++----------------------------- 1 file changed, 13 insertions(+), 29 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index 67f04bcdf9ef..4204d9df003b 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2516,45 +2516,31 @@ EXPORT_SYMBOL(filemap_fault); void filemap_map_pages(struct vm_fault *vmf, pgoff_t start_pgoff, pgoff_t end_pgoff) { - struct radix_tree_iter iter; - void **slot; struct file *file = vmf->vma->vm_file; struct address_space *mapping = file->f_mapping; pgoff_t last_pgoff = start_pgoff; unsigned long max_idx; + XA_STATE(xas, &mapping->i_pages, start_pgoff); struct page *head, *page; rcu_read_lock(); - radix_tree_for_each_slot(slot, &mapping->i_pages, &iter, start_pgoff) { - if (iter.index > end_pgoff) - break; -repeat: - page = radix_tree_deref_slot(slot); - if (unlikely(!page)) - goto next; - if (radix_tree_exception(page)) { - if (radix_tree_deref_retry(page)) { - slot = radix_tree_iter_retry(&iter); - continue; - } + xas_for_each(&xas, page, end_pgoff) { + if (xas_retry(&xas, page)) + continue; + if (xa_is_value(page)) goto next; - } head = compound_head(page); if (!page_cache_get_speculative(head)) - goto repeat; + goto next; /* The page was split under us? */ - if (compound_head(page) != head) { - put_page(head); - goto repeat; - } + if (compound_head(page) != head) + goto skip; /* Has the page moved? */ - if (unlikely(page != *slot)) { - put_page(head); - goto repeat; - } + if (unlikely(page != xas_reload(&xas))) + goto skip; if (!PageUptodate(page) || PageReadahead(page) || @@ -2573,10 +2559,10 @@ void filemap_map_pages(struct vm_fault *vmf, if (file->f_ra.mmap_miss > 0) file->f_ra.mmap_miss--; - vmf->address += (iter.index - last_pgoff) << PAGE_SHIFT; + vmf->address += (xas.xa_index - last_pgoff) << PAGE_SHIFT; if (vmf->pte) - vmf->pte += iter.index - last_pgoff; - last_pgoff = iter.index; + vmf->pte += xas.xa_index - last_pgoff; + last_pgoff = xas.xa_index; if (alloc_set_pte(vmf, NULL, page)) goto unlock; unlock_page(page); @@ -2589,8 +2575,6 @@ void filemap_map_pages(struct vm_fault *vmf, /* Huge page is mapped? No need to proceed. */ if (pmd_trans_huge(*vmf->pmd)) break; - if (iter.index == end_pgoff) - break; } rcu_read_unlock(); }