From patchwork Thu Oct 7 19:21:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Matthew Wilcox (Oracle)" X-Patchwork-Id: 12542669 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B7C0EC433EF for ; Thu, 7 Oct 2021 19:23:09 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 46E696101E for ; Thu, 7 Oct 2021 19:23:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 46E696101E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 7B9E76B006C; Thu, 7 Oct 2021 15:23:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 769F56B0071; Thu, 7 Oct 2021 15:23:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 632306B0072; Thu, 7 Oct 2021 15:23:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0131.hostedemail.com [216.40.44.131]) by kanga.kvack.org (Postfix) with ESMTP id 557956B006C for ; Thu, 7 Oct 2021 15:23:08 -0400 (EDT) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 1DC5E39BB5 for ; Thu, 7 Oct 2021 19:23:08 +0000 (UTC) X-FDA: 78670614456.24.A82D740 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf28.hostedemail.com (Postfix) with ESMTP id B86889001B55 for ; Thu, 7 Oct 2021 19:23:06 +0000 (UTC) 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: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:In-Reply-To:References; bh=c5biXh/53+5ikGkxdoYWgJx/1z0TuA4942Vbwiwif9s=; b=ox6Ij/PGO7Xmz11xbtdnFc3Oc7 VgXQvCFaeMuxPLLIWeh9kVO2f43f5lAqFXOcetl5CshpBprgVceWsLTO6iKPjIKQ0eKPgqbm6hj+H dGME8R20hJO8a4/U7j0mJqK4tV9SCLYBvKEelSiUJSD1M3zzrAEuZo8a20gcBj8CkUKtmfDPXV0b0 lZc9VrMmdJ29e223w/Wba1aia2au8ErsUlWlfVPatW7nk/C0p395jmjPzqknTj6AIZuRb9M4tGv4B Z0hz2SsWu3NB6PoXzJHPxMkYb2ApSL3LztrJUl09IOtyVaZc4L7j//TNpeyuH+g7NvBcdUjlk+C+p Wja0cYCQ==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1mYYxZ-002M81-1H; Thu, 07 Oct 2021 19:21:48 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton , Mel Gorman , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: "Matthew Wilcox (Oracle)" Subject: [PATCH v2] mm: Optimise put_pages_list() Date: Thu, 7 Oct 2021 20:21:37 +0100 Message-Id: <20211007192138.561673-1-willy@infradead.org> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: B86889001B55 X-Stat-Signature: bmrqwhq8kz4pjdiihiongbpmwycp5tyy Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b="ox6Ij/PG"; dmarc=none; spf=none (imf28.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org X-HE-Tag: 1633634586-917391 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: Instead of calling put_page() one page at a time, pop pages off the list if their refcount was too high and pass the remainder to put_unref_page_list(). This should be a speed improvement, but I have no measurements to support that. Current callers do not care about performance, but I hope to add some which do. Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Anthony Yznaga --- v2: - Handle compound pages (Mel) - Comment why we don't need to handle PageLRU - Added call to __ClearPageWaiters(), matching that in release_pages() mm/swap.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/mm/swap.c b/mm/swap.c index af3cad4e5378..9f334d503fd2 100644 --- a/mm/swap.c +++ b/mm/swap.c @@ -134,18 +134,27 @@ EXPORT_SYMBOL(__put_page); * put_pages_list() - release a list of pages * @pages: list of pages threaded on page->lru * - * Release a list of pages which are strung together on page.lru. Currently - * used by read_cache_pages() and related error recovery code. + * Release a list of pages which are strung together on page.lru. */ void put_pages_list(struct list_head *pages) { - while (!list_empty(pages)) { - struct page *victim; + struct page *page, *next; - victim = lru_to_page(pages); - list_del(&victim->lru); - put_page(victim); + list_for_each_entry_safe(page, next, pages, lru) { + if (!put_page_testzero(page)) { + list_del(&page->lru); + continue; + } + if (PageHead(page)) { + list_del(&page->lru); + __put_compound_page(page); + continue; + } + /* Cannot be PageLRU because it's passed to us using the lru */ + __ClearPageWaiters(page); } + + free_unref_page_list(pages); } EXPORT_SYMBOL(put_pages_list);