From patchwork Sun Jun 17 02:00:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 10468205 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 028FA600CC for ; Sun, 17 Jun 2018 02:01:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E8F7528BD0 for ; Sun, 17 Jun 2018 02:01:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DDE1528BDB; Sun, 17 Jun 2018 02:01:34 +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 719D828BE0 for ; Sun, 17 Jun 2018 02:01:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 897476B000E; Sat, 16 Jun 2018 22:01:03 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 7E8196B000C; Sat, 16 Jun 2018 22:01:03 -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 3A62A6B000E; Sat, 16 Jun 2018 22:01:03 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl0-f72.google.com (mail-pl0-f72.google.com [209.85.160.72]) by kanga.kvack.org (Postfix) with ESMTP id C18F76B000E for ; Sat, 16 Jun 2018 22:01:02 -0400 (EDT) Received: by mail-pl0-f72.google.com with SMTP id bf1-v6so7722907plb.2 for ; Sat, 16 Jun 2018 19:01:02 -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=Yeiu2kmNiusFRVYFnSwKz/rR6RSVxilKq9nNpzSrFOE=; b=Mu5jle/PrYXRvRHD/i4Sy6U1nZqG5gcDIzL9RI8/EFEsbjkd/OEBFa63JS1gbG2Ui9 A+l9LO0l/SUgQshpO3aUUXO0va6EOFjtSLBa1u8lPo20UBjgYHKFSqNl+GhuMkqYOTIO 5hIyTcrAL1U5SQUsysOzv4aOwKP2HjtvLAOMe8zbkRi2ofRCL4iRPIejGNsw71vJseWP 9UR0wDbrw9dfJOk6iE83XFL6vLQgaF0UMfT+mU9iGdXfPG2yFhHCks6eG6TYAB+uaw52 ENeaf7uUj94X3BAJs0BvZqQJJKopOu3jOsBVSEeN/q4sY6h0hFGW5hyoe2D0ncR8jBmN Di9Q== X-Gm-Message-State: APt69E2vuvir355d586oph+Mx1zlkg9YPZueCMNwNXAjAfmWzbfsxGiw ++HWXCFQPvvdb4h5GcGCTQJtfA2kfTKj7lHUnoFGTDcGBZyNa0vRFu93dcX4w8CBrE6LWvXqL3H 4ceyXXocliX3eO/M36WRp6eu0mPEPgP9SGc8PmDEW1dhHp5Otb3Qr5A9k7OaHMO7leg== X-Received: by 2002:a62:ff1d:: with SMTP id b29-v6mr8106068pfn.181.1529200862435; Sat, 16 Jun 2018 19:01:02 -0700 (PDT) X-Google-Smtp-Source: ADUXVKL0JkzYUZEBcdY2sCiS8/eKTBLVixlpTMJPmv/frrxd1qemUPef0WlIrTa0jPU0hebyaZMK X-Received: by 2002:a62:ff1d:: with SMTP id b29-v6mr8106033pfn.181.1529200861382; Sat, 16 Jun 2018 19:01:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529200861; cv=none; d=google.com; s=arc-20160816; b=HsFwh0ESe+ffOfO0Mys+aZCh2sh00kGTqBjzmvH3KAbMwg+N0zhyt72M2md19xj1rw baHEsqYYNohJAOLiC5z+rIBGLP0VaZzk4TM385VMHGk0OtKK6RA8NSN76HjhAAjeBkKd LO4hhemR+0bUGNkqjG23Q6PrXKT/J+2HSxmN2HpPi2zz00TgUu9z8IJRLNxeQEK1voco iUUF7br4tRgPvbs3hJpkvBte6UrmiKPFM+Y2d+KzZb4OEvM+Vsusn223tCADCNEbSrvE JYNrztUseSjQ9ufLdFH93rMvB22PL0CX+FBQpKhyltAu/4i7YwWsiIo2HanCMSlA0AIO H+yA== 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=Yeiu2kmNiusFRVYFnSwKz/rR6RSVxilKq9nNpzSrFOE=; b=XrLK7KdACSTkm77UBk5NlveC+EpY/8izWWJhgyIeKlcTtaZ7ZkoAF0tLf6m2dqiqqU BDBEkj8p2fwRaUqv/Y5xWZI98sH2rkv1JlERSKEG0BqOZMMeiS2ADg3+h164YWd7BbX4 B6EfI8zTPAaMYbz7K95WA/mlax4GNhBqFI1A2/R96JCgSOs45lEe7ZE01kILJ211U0cV L7KaZcKt0bOAgkUrwx4ReKKHUR5ZgmXAEvJ1ifZqhqFqiqK+rcMz3x7Z0mL2SDeBXBtm fLrs10TY3qiu7+1MoV4W/XyTnea2f4/067gmpkIHBtaIzUrd/ycjEafCWPZ3ELsqb2e5 5o7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20170209 header.b=m+LOI1px; 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 d39-v6si8380827pla.46.2018.06.16.19.01.01 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 16 Jun 2018 19:01:01 -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=m+LOI1px; 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=Yeiu2kmNiusFRVYFnSwKz/rR6RSVxilKq9nNpzSrFOE=; b=m+LOI1px17ZSX5HKevG2D55D6 WGE20+eKIdSX26zGYKp1NJ6fKmQVz9TeDZYY2DXweQpbJxgCHb3Hi5OE61FnLqgC9mCXy7ziofOeN 9wrsRmwJGlNfGUUIX6s0jhoqytilmgM4katZytiJIuds+7k9iRJY0mVTVXPc+G9txr3bE2z8iCKPR w42OLBaGlBN/PWDF3t3EbBHftT2tyegU/WqWin9w+H/PFRZHu2IFFTXmhaTQ1DIOhMzcU2q4yNL0F sqRF1xwdUMq+DK8WxDBpeTFS51/Fu9NqDsrxJA8BmxnEyzJ3C93MWVLru6U1HWrEECsEWSazm8sIQ LaP1JPyjg==; Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1fUN00-0001Iu-NL; Sun, 17 Jun 2018 02:01:00 +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 v14 30/74] page cache: Convert filemap_map_pages to XArray Date: Sat, 16 Jun 2018 19:00:08 -0700 Message-Id: <20180617020052.4759-31-willy@infradead.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180617020052.4759-1-willy@infradead.org> References: <20180617020052.4759-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 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(); }