From patchwork Fri Aug 18 06:05:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Chris Li X-Patchwork-Id: 13357383 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D9D99C7113B for ; Fri, 18 Aug 2023 06:06:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 93D8D940009; Fri, 18 Aug 2023 02:06:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8F082280055; Fri, 18 Aug 2023 02:06:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5BD94280056; Fri, 18 Aug 2023 02:06:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 47316940055 for ; Fri, 18 Aug 2023 02:06:03 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id EE090120BD4 for ; Fri, 18 Aug 2023 06:06:02 +0000 (UTC) X-FDA: 81136189764.07.DCC9D62 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf07.hostedemail.com (Postfix) with ESMTP id 4A7B840011 for ; Fri, 18 Aug 2023 06:06:01 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=bbOTWJ6h; spf=pass (imf07.hostedemail.com: domain of chrisl@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=chrisl@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1692338761; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=iWV63Pasz5MJWOxAjAA4NmhkQQE4ntPHdjtYKMwfyVo=; b=f7uQHzwOpi/lns59wpcY6aAyWDAMtn1nB5hPsvkp9s09UxkslOlRcX1Nw2cYtmDEFN/9aB Bcx9VnkJ6KcL294HEu63VdLfL17wx3POWJhislOjFBvA1tRzqedwoOD9KouXw2VsiTP0n1 aGc6CMvkEJtFeYPkfWq3qktnLSBQDD8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692338761; a=rsa-sha256; cv=none; b=TlxTXtteKZQqBp20rAuOtM1JHwhL5ec8c5XAtAZActAW7EgCBEfYV1mqMnR2d6tIZgVYVW a3UYFTN8MOWVwbS6X31xCaqikouiXcA2FmBCdbnKSophJ+qcPpiKTBNa+1vjuMQosPEVL2 UW0+zXS2M0bbooWlUWa8OtBv9SM4Hyo= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=bbOTWJ6h; spf=pass (imf07.hostedemail.com: domain of chrisl@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=chrisl@kernel.org; dmarc=pass (policy=none) header.from=kernel.org Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 46D0E64056; Fri, 18 Aug 2023 06:06:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6090DC433CC; Fri, 18 Aug 2023 06:05:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1692338759; bh=PTFvK66aSpc/wWYXL1tG3ENdFiVUZlkQu/DReJnqKDo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=bbOTWJ6hSKJFcss5lL+TZpqq6+IGVcsiAeVbsSyFwYW+JEYg7RhWRlkI7cxWfBWZf 76/MXNfx+Co4g9cC8KsCqjeTj1uY1hjSffEqPmKzAaZ5HYLN7P8dYTYPk96SyMaT6p 3mDVpiYFix5Vwe3HjrP2w6PxKfW7tCrrw2a9HZalQ8399I/IMvWZ5vndleGZb8Lu4w jVMnbDZaGygfjf7W++mxpohOYkARhyjCsOUIcfwXM2rRQcTouyZUrWIt0dJNFHh0Md Nx8cfMGpk0/gIXyEjho2O2qu9ljHiGQWxobEmRC40zT6fPvPn6x4Jcq25ZwqVdmr2r x9InBHdTcsCKA== From: Chris Li Date: Thu, 17 Aug 2023 23:05:24 -0700 Subject: [PATCH RFC 2/2] mm/page_alloc: free_pcppages_bulk clean up MIME-Version: 1.0 Message-Id: <20230817-free_pcppages_bulk-v1-2-c14574a9f80c@kernel.org> References: <20230817-free_pcppages_bulk-v1-0-c14574a9f80c@kernel.org> In-Reply-To: <20230817-free_pcppages_bulk-v1-0-c14574a9f80c@kernel.org> To: Andrew Morton , Kemeng Shi Cc: akpm@linux-foundation.org, baolin.wang@linux.alibaba.com, mgorman@techsingularity.net, Michal Hocko , david@redhat.com, willy@infradead.org, linux-mm@kvack.org, Namhyung Kim , Greg Thelen , linux-kernel@vger.kernel.org, Chris Li X-Mailer: b4 0.12.2 X-Rspamd-Queue-Id: 4A7B840011 X-Rspam-User: X-Stat-Signature: cm31mfcx4q7qzmcrunzgwraj5dxdgji1 X-Rspamd-Server: rspam03 X-HE-Tag: 1692338761-818671 X-HE-Meta: U2FsdGVkX18EwyTxdShGjw7WeTrwOzlG5dlOcyabTxJ7EFZD/5vGGngbl7zw6NHqKiySKFvAkdXMy7RsA5U5U2LoOWukduvIr7GuPijxBpE0QCC0wjATMqYunI6c9hTNsHtLU/DrAjbhkQ4Y74Hdi2yaelJ26yonnclpC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DvuoqatMHnHBO5mDwx2bUanijMO/n5audt11oT/cHT/wOTjz0y2hhkhf1UaGBL8b36bykG7cpwz6E0HOp31NZJqkxzRYRtCb1n1Yu3ETXK7/HoCKciELqHNEqGeVQRD96l8gZ4BdE= 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: This patch does not have functional change. Just pure clean up. It removes the pindex_max and pindex_min and replaces it with a simpler loop. It uses for_each_entry_safe_reverse() to replace the loop over list_last_entry(). It produces slightly better machine code. Signed-off-by: Chris Li --- mm/page_alloc.c | 38 +++++++++++++------------------------- 1 file changed, 13 insertions(+), 25 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 347cb93081a02..d64d0f5ec70b4 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1209,11 +1209,9 @@ static void free_pcppages_bulk(struct zone *zone, int count, int pindex) { unsigned long flags; - int min_pindex = 0; - int max_pindex = NR_PCP_LISTS - 1; unsigned int order; bool isolated_pageblocks; - struct page *page; + int i; /* Ensure requested pindex is drained first. */ pindex = pindex - 1; @@ -1221,31 +1219,18 @@ static void free_pcppages_bulk(struct zone *zone, int count, spin_lock_irqsave(&zone->lock, flags); isolated_pageblocks = has_isolate_pageblock(zone); - while (count > 0) { + for (i = 0; i < NR_PCP_LISTS; i++, pindex++) { struct list_head *list; int nr_pages; + struct page *page, *next; - /* Remove pages from lists in a round-robin fashion. */ - do { - if (++pindex > max_pindex) - pindex = min_pindex; - list = &pcp->lists[pindex]; - if (!list_empty(list)) - break; - - if (pindex == max_pindex) - max_pindex--; - if (pindex == min_pindex) - min_pindex++; - } while (1); - + if (pindex == NR_PCP_LISTS) + pindex = 0; + list = pcp->lists + pindex; order = pindex_to_order(pindex); nr_pages = 1 << order; - do { - int mt; - - page = list_last_entry(list, struct page, pcp_list); - mt = get_pcppage_migratetype(page); + list_for_each_entry_safe_reverse(page, next, list, lru) { + int mt = get_pcppage_migratetype(page); /* must delete to avoid corrupting pcp list */ list_del(&page->pcp_list); @@ -1260,9 +1245,12 @@ static void free_pcppages_bulk(struct zone *zone, int count, __free_one_page(page, page_to_pfn(page), zone, order, mt, FPI_NONE); trace_mm_page_pcpu_drain(page, order, mt); - } while (count > 0 && pcp->count > 0 && !list_empty(list)); - } + if (count <= 0 || pcp->count <= 0) + goto out; + } + } +out: spin_unlock_irqrestore(&zone->lock, flags); }