Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp679860pxa; Wed, 19 Aug 2020 11:50:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxQk1I8PXFHGbewW9GTvfLvSeYtB552kuCf0WLXbAULq7/zOMZ8hYqKYG23J222E6q0IGSE X-Received: by 2002:a05:6402:325:: with SMTP id q5mr26515123edw.343.1597863010356; Wed, 19 Aug 2020 11:50:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597863010; cv=none; d=google.com; s=arc-20160816; b=iLI9bIYtAs5R6L1YsU60XhWuJcjryT2H/TWGqZVlN1kpO4MQeRzy1Qa9sohL71g+qS J2cpVWk6OSz2RqDh3YUFRHplLFSuH2IZcco9IXwJyYS4dxUZTT46nFQDA3jy8qaHRnVT VsRaVJmqS+ogFbtpxQg75jvWzP7JvPMZG8ucLlPzOD/OBXpNFURF1Ld83PEbLwcpDee6 ZYs7pwQro+mOdZgwuS18WgW/RBM05wcc5TYw4bVMt+Q/2v4l8Ul49SnkbOSWZl9/16rX uBxGoaB4WQvLuhGA3aHFz7Fs8RcoBzdCVGfrqMzB8kMQ1YgfCuD63ro9JVALXw8kggfZ PEPw== 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=yHlibx9T0xrkfaCUzHO6K9mta5VlhggyQEWPghnljAs=; b=n4PgXFTGHKSN0BXVxuyiZ7QQV3p5Y7jeXgm0MYT1TQu2hGGC/e33zQ3f11PHsNzt9O +JBAnsOvvQy0z2Bb5R+dA1bEm/5B3qQ7Wo5Oer5TujbxhlfolNBYZ/kEyrJbpsZNrvhb i+PJzkRbhTZOrmr9XyU8xMmHKFOkLAjgsKBfTausJ5JQr1AAd89mPZTmLKoxW95rQl7U lLBpG4tN4K9zrOVjug5qiQzvPJkUGwqnrCjc3QcQH4n9vf7555V9EatxAEvylkZglovV vPCuj3eneWnGGhbgySnAFCAa+B/HScR5fq6QEo3JUyo1CXQxi0SnIQKbkro/GKb2/3l9 m9YA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=casper.20170209 header.b=mtqG2R5K; 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 rl11si17615882ejb.519.2020.08.19.11.49.45; Wed, 19 Aug 2020 11:50:10 -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=mtqG2R5K; 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 S1726853AbgHSStH (ORCPT + 99 others); Wed, 19 Aug 2020 14:49:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725804AbgHSStF (ORCPT ); Wed, 19 Aug 2020 14:49:05 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE68CC061757; Wed, 19 Aug 2020 11:49:04 -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=yHlibx9T0xrkfaCUzHO6K9mta5VlhggyQEWPghnljAs=; b=mtqG2R5K+Yx4dE8Kn6VbN3423G kIyD7iHdEs9//9zn4d+MqCrVYAzK+wcoAiner0u6ns9sOmIc5tfRAgo27IXLWgMP6nwGY0e6y6pmA 3HyU19g7ZHaw31ZJ8zxxv6IAybbAuxOaFrkQK2spsvcHh6QuyTpP2yNUbuYLJtWlcWRvqXSIlF0jI 9Vy40hmXVmrp6grQd7r+oJ7KtTvTI521d9fNWtfKyyqTvGJ4P+MhRWJZc+95qtI0mQz6V/ZnZbfe4 Kgct1GcrVAvfxOQF0Ag9wTk4R925hXyZsT3fcWZRlbRDSahohQn09B2qh4/GBAkF9CnxwnjMmjRTs EKPHJUnA==; Received: from willy by casper.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1k8T8n-0006T8-TC; Wed, 19 Aug 2020 18:48:53 +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 3/8] mm: Optimise madvise WILLNEED Date: Wed, 19 Aug 2020 19:48:45 +0100 Message-Id: <20200819184850.24779-4-willy@infradead.org> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200819184850.24779-1-willy@infradead.org> References: <20200819184850.24779-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) --- 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