Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1292061pxk; Thu, 10 Sep 2020 11:40:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxokn8RbcDnFSLbK0B4tg91rAfbC04bO2J78JS5DjNgLQDjC2CEmgOWu5/ix3AAy6IR5Kkw X-Received: by 2002:a17:906:1b04:: with SMTP id o4mr10823463ejg.332.1599763249109; Thu, 10 Sep 2020 11:40:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599763249; cv=none; d=google.com; s=arc-20160816; b=g7ZNOYlaV2lqFnK7ER/3f98kvxKo8CKrQZ12sxYZLIaRtchE0eSdOQjA9JHoLl+cyn 3tty+KGmHL6bRdF8QPa3Ym+7nS2uXyGmNtRupoacCGRoE7PibmrG4dK9qcKqjwEPS6Lx CSP9jXJNUjpeAre/kMmW8U88ONQUCJ0vd8V05gMNWU4wuUB+9d0TdW/Ac5+ke2o69vLR UeBxPjKlUzj8AOSt6A9WpG4bDFAfCrv2u4x701ar8nv8ln2lRl2WYmcnJaCDM0f4+pFj 8Ar+6sz7dc35cQC1stKA1BzBTmVJvmnVEru6vV8Sn82IE81Y/u/qKVyaIn6/MSpLIJr4 KcpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=5pz6pk0hQVCAmUCzXhhMl6SI7ek8eXmhvDqxhMsMWZA=; b=pw1W+0bgFOAfYSA6s8l+0PSav6c46XD1Nt+Nm103loZzsGhzHOhQ5vIJholMtOAHYt exQDZC/hMzQbMmfnlzmGYsPQIQuW8QHLq0O7lcvbQ3YPtHwQfHKuIEdlVGfoaeFWysFH eIh3rhsNJtwnoEn8qaBo7nCadlNPrJo8BodxZwf8Z9gnNQ+X+z3nUtHd3M2GtIpo5ejY wDfMk2/2p5bELpyh6EIEynB06xWXg/gafzousq0EFb3Mg+lz1qNQtCVIbBiM0r39SVCd Wb/piLxwAHLiti/Yaj9RXm5qvIOw85O0ABvy1rCpywSd2S/QwNH1cbV8qniEjPF8dleu 9tzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=casper.20170209 header.b=Z0ig8BZO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bo9si3922178edb.583.2020.09.10.11.40.25; Thu, 10 Sep 2020 11:40:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=casper.20170209 header.b=Z0ig8BZO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727058AbgIJSjg (ORCPT + 99 others); Thu, 10 Sep 2020 14:39:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726515AbgIJSdh (ORCPT ); Thu, 10 Sep 2020 14:33:37 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8BBD7C061756; Thu, 10 Sep 2020 11:33:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=5pz6pk0hQVCAmUCzXhhMl6SI7ek8eXmhvDqxhMsMWZA=; b=Z0ig8BZOOs874Iqk+s8Hjq2poV GfUU0UHAUN9Q10UU2Qc227BQGYSAuBuImaK2JLeoDFbGlpRzkAAOn6+/YaptLDl2FRANNaxYmEE3w mM4+ZjVmKwqOk3NY3DlezWO3uDRW1yESEcjvvUwqea0D+xOlNL846Qr76zhGuKKjx9HOj3KgtZscS jit7EaGeKPNdD6jg3LNu0n3gynAd6wlhzi9Hsj3R5Mi0n4mt1NX4STEfYrPFDWo1mhNjNsHg18nlj vZc8Lz/HCP7Iav4W1Li83NNG/RE38e7EQqq6JJ3V+y6qbzdR40ePerF8p7gTuN16/gueZ/fX6Ngp1 qzZoxrDw==; Received: from willy by casper.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1kGRNo-0005GA-TG; Thu, 10 Sep 2020 18:33:20 +0000 From: "Matthew Wilcox (Oracle)" To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , Andrew Morton , Hugh Dickins , William Kucharski , Jani Nikula , Alexey Dobriyan , Johannes Weiner , Chris Wilson , Matthew Auld , Huang Ying , intel-gfx@lists.freedesktop.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/8] mm: Optimise madvise WILLNEED Date: Thu, 10 Sep 2020 19:33:13 +0100 Message-Id: <20200910183318.20139-4-willy@infradead.org> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200910183318.20139-1-willy@infradead.org> References: <20200910183318.20139-1-willy@infradead.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Instead of calling find_get_entry() for every page index, use an XArray iterator to skip over NULL entries, and avoid calling get_page(), because we only want the swap entries. Signed-off-by: Matthew Wilcox (Oracle) Acked-by: Johannes Weiner --- mm/madvise.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/mm/madvise.c b/mm/madvise.c index dd1d43cf026d..96189acd6969 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -224,25 +224,28 @@ static void force_shm_swapin_readahead(struct vm_area_struct *vma, unsigned long start, unsigned long end, struct address_space *mapping) { - pgoff_t index; + XA_STATE(xas, &mapping->i_pages, linear_page_index(vma, start)); + pgoff_t end_index = end / PAGE_SIZE; struct page *page; - swp_entry_t swap; - for (; start < end; start += PAGE_SIZE) { - index = ((start - vma->vm_start) >> PAGE_SHIFT) + vma->vm_pgoff; + rcu_read_lock(); + xas_for_each(&xas, page, end_index) { + swp_entry_t swap; - page = find_get_entry(mapping, index); - if (!xa_is_value(page)) { - if (page) - put_page(page); + if (!xa_is_value(page)) continue; - } + rcu_read_unlock(); + swap = radix_to_swp_entry(page); page = read_swap_cache_async(swap, GFP_HIGHUSER_MOVABLE, NULL, 0, false); if (page) put_page(page); + + rcu_read_lock(); + xas_reset(&xas); } + rcu_read_unlock(); lru_add_drain(); /* Push any new pages onto the LRU now */ } -- 2.28.0