From patchwork Tue Mar 21 00:24:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kirill A . Shutemov" X-Patchwork-Id: 13182055 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 BAF03C7618D for ; Tue, 21 Mar 2023 00:24:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0215B6B0075; Mon, 20 Mar 2023 20:24:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EECB36B0078; Mon, 20 Mar 2023 20:24:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DB3E26B007B; Mon, 20 Mar 2023 20:24:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id C80FE6B0075 for ; Mon, 20 Mar 2023 20:24:26 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 8302B160320 for ; Tue, 21 Mar 2023 00:24:26 +0000 (UTC) X-FDA: 80591008932.15.8331CE7 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by imf08.hostedemail.com (Postfix) with ESMTP id CF233160011 for ; Tue, 21 Mar 2023 00:24:23 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=dZNSIhQd; spf=none (imf08.hostedemail.com: domain of kirill.shutemov@linux.intel.com has no SPF policy when checking 192.55.52.115) smtp.mailfrom=kirill.shutemov@linux.intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1679358264; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=g1nxw9FDkuNo5OPi/S0DTAzQuomYTvx+Jq9KYfWry/I=; b=KxEfeCSmafM2fmkvqjYONOCBOu0Jiyiw9XFV6m/Y5Vcb3NDyJc13WNffqDcWdtHEzZDMqi 9+omFM1jtdQuzvDUSq0A1dNgkPjBCosC1GMsz6XV6v02y2b7mvQTTHwhtZnLmo0699fMaj izUpYWHaCuXdVBM4MAxQec1nXwOQZJk= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=dZNSIhQd; spf=none (imf08.hostedemail.com: domain of kirill.shutemov@linux.intel.com has no SPF policy when checking 192.55.52.115) smtp.mailfrom=kirill.shutemov@linux.intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1679358264; a=rsa-sha256; cv=none; b=8hvYJf46PRQVuQHIN0MlLJzcnmBSHVjc2oGGBzB63ehbUNpmuqPVd8zIsSGcv9msgt2dzR GPmlKfHQpySV6OBhar7EGrsYI25oUO83p7f09Kx0bVhkedp5vG8Zi0GqUHQ/UMopzboo7b KUlX3fLvCV392p4mBb5lw/LUplXCQVY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1679358263; x=1710894263; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=GRVnvzYi7pT7KDRG53bY6VEAg5OjyUVo2Ng7bX3FNaw=; b=dZNSIhQdN7idVzigCUL3l+fcvpyy97eKxmWZ/AElCs0Q4kPJ9ti7C7Rz WlTP3K/GffoOY/uFNzj5iFIX7jjx8wprz0IwKwoSuZ2TIN1v/p5TAIowG 6TE7FheIu+N9lU00cYMNTNMH0jzIULDw+z8n6bBkJ7Jxl6ALaSBaDVS7z IMSh3NruOX7BosHnIGWRIUkhMrLIcIyAaX+80syYpPbwYQpALA2GaLqhO J+SurNXsdYTT6TFVtN2KrQJ+DcyOmP1FSp1ODwZXUtvUlGoAgcntfym7G ZTqC8CNvPPobIcPBUQzIO8XNgAgWi19qginMdUZDecBOGDzEDtFRKVo3m Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10655"; a="338842240" X-IronPort-AV: E=Sophos;i="5.98,277,1673942400"; d="scan'208";a="338842240" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Mar 2023 17:24:22 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10655"; a="681299317" X-IronPort-AV: E=Sophos;i="5.98,277,1673942400"; d="scan'208";a="681299317" Received: from cbellini-mobl.ger.corp.intel.com (HELO box.shutemov.name) ([10.251.221.208]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Mar 2023 17:24:19 -0700 Received: by box.shutemov.name (Postfix, from userid 1000) id 2438D109590; Tue, 21 Mar 2023 03:24:17 +0300 (+03) From: "Kirill A. Shutemov" To: Andrew Morton , Mel Gorman , Vlastimil Babka , David Hildenbrand Cc: linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" Subject: [PATCHv2] mm/page_alloc: Make deferred page init free pages in MAX_ORDER blocks Date: Tue, 21 Mar 2023 03:24:15 +0300 Message-Id: <20230321002415.20843-1-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Rspamd-Queue-Id: CF233160011 X-Stat-Signature: yjq3q77ftubpsfbyqe98rhsjq1zqxo8x X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1679358263-668477 X-HE-Meta: U2FsdGVkX1/rt5UX+3LK1IVsBCE6kFyCrzh0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gnbe28cXIJlFG0nZ7o8WNVlImXS2ss+Q86tK5O7/0bMJOeLpQNEM/HSURQedLgpTOPrOiM0nqeIHJloP6pk= 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: Normal page init path frees pages during the boot in MAX_ORDER chunks, but deferred page init path does it in pageblock blocks. Change deferred page init path to work in MAX_ORDER blocks. For cases when MAX_ORDER is larger than pageblock, set migrate type to MIGRATE_MOVABLE for all pageblocks covered by the page. Signed-off-by: Kirill A. Shutemov Reviewed-by: Vlastimil Babka Acked-by: David Hildenbrand Acked-by: Mel Gorman Acked-by: Mike Rapoport (IBM) --- Note: the patch depends on the new definiton of MAX_ORDER. v2: - Fix commit message; --- include/linux/mmzone.h | 2 ++ mm/page_alloc.c | 19 ++++++++++--------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index 96599cb9eb62..f53fe3a7ca45 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -32,6 +32,8 @@ #endif #define MAX_ORDER_NR_PAGES (1 << MAX_ORDER) +#define IS_MAX_ORDER_ALIGNED(pfn) IS_ALIGNED(pfn, MAX_ORDER_NR_PAGES) + /* * PAGE_ALLOC_COSTLY_ORDER is the order at which allocations are deemed * costly to service. That is between allocation orders which should diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 87d760236dba..fc02a243425d 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1875,9 +1875,10 @@ static void __init deferred_free_range(unsigned long pfn, page = pfn_to_page(pfn); /* Free a large naturally-aligned chunk if possible */ - if (nr_pages == pageblock_nr_pages && pageblock_aligned(pfn)) { - set_pageblock_migratetype(page, MIGRATE_MOVABLE); - __free_pages_core(page, pageblock_order); + if (nr_pages == MAX_ORDER_NR_PAGES && IS_MAX_ORDER_ALIGNED(pfn)) { + for (i = 0; i < nr_pages; i += pageblock_nr_pages) + set_pageblock_migratetype(page + i, MIGRATE_MOVABLE); + __free_pages_core(page, MAX_ORDER); return; } @@ -1901,19 +1902,19 @@ static inline void __init pgdat_init_report_one_done(void) /* * Returns true if page needs to be initialized or freed to buddy allocator. * - * We check if a current large page is valid by only checking the validity + * We check if a current MAX_ORDER block is valid by only checking the validity * of the head pfn. */ static inline bool __init deferred_pfn_valid(unsigned long pfn) { - if (pageblock_aligned(pfn) && !pfn_valid(pfn)) + if (IS_MAX_ORDER_ALIGNED(pfn) && !pfn_valid(pfn)) return false; return true; } /* * Free pages to buddy allocator. Try to free aligned pages in - * pageblock_nr_pages sizes. + * MAX_ORDER_NR_PAGES sizes. */ static void __init deferred_free_pages(unsigned long pfn, unsigned long end_pfn) @@ -1924,7 +1925,7 @@ static void __init deferred_free_pages(unsigned long pfn, if (!deferred_pfn_valid(pfn)) { deferred_free_range(pfn - nr_free, nr_free); nr_free = 0; - } else if (pageblock_aligned(pfn)) { + } else if (IS_MAX_ORDER_ALIGNED(pfn)) { deferred_free_range(pfn - nr_free, nr_free); nr_free = 1; } else { @@ -1937,7 +1938,7 @@ static void __init deferred_free_pages(unsigned long pfn, /* * Initialize struct pages. We minimize pfn page lookups and scheduler checks - * by performing it only once every pageblock_nr_pages. + * by performing it only once every MAX_ORDER_NR_PAGES. * Return number of pages initialized. */ static unsigned long __init deferred_init_pages(struct zone *zone, @@ -1953,7 +1954,7 @@ static unsigned long __init deferred_init_pages(struct zone *zone, if (!deferred_pfn_valid(pfn)) { page = NULL; continue; - } else if (!page || pageblock_aligned(pfn)) { + } else if (!page || IS_MAX_ORDER_ALIGNED(pfn)) { page = pfn_to_page(pfn); } else { page++;