From patchwork Fri Mar 17 15:35:01 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: 13179214 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 D7062C74A5B for ; Fri, 17 Mar 2023 15:35:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 71D9C6B007B; Fri, 17 Mar 2023 11:35:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6CD706B007D; Fri, 17 Mar 2023 11:35:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 595596B007E; Fri, 17 Mar 2023 11:35:12 -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 471A86B007B for ; Fri, 17 Mar 2023 11:35:12 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 1512D1601AF for ; Fri, 17 Mar 2023 15:35:12 +0000 (UTC) X-FDA: 80578788864.25.F5DAF47 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by imf13.hostedemail.com (Postfix) with ESMTP id 0BD7120029 for ; Fri, 17 Mar 2023 15:35:08 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=YvErZCSf; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf13.hostedemail.com: domain of kirill.shutemov@linux.intel.com has no SPF policy when checking 134.134.136.31) smtp.mailfrom=kirill.shutemov@linux.intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1679067310; 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=sQ2SfhcXxdWT45ndNqrB/5lAygUf8kJ/kk3MCzBpCGU=; b=tC3IGs4XiSuOq+Fk9TWYZdEyeUL1I/Hw4lYiFxLVWU9DhclaT4sZnMtM0ELF5wa8wXdMJw ES3LaKbWf1JvY8M90cz68cUDiMKVpLUawFlwht4l6mOQ3uEVAGH3G2axEOn7X2W0PTET5Q FSRJf83nBXtrjZ660vi1TBuxzmHkbSQ= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=YvErZCSf; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf13.hostedemail.com: domain of kirill.shutemov@linux.intel.com has no SPF policy when checking 134.134.136.31) smtp.mailfrom=kirill.shutemov@linux.intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1679067310; a=rsa-sha256; cv=none; b=fEBd/ITRj5GjZd6a3omJ5Mr1UsnHOBZcTrqbiRdMBx/9ORIhcoK/6BM6ZM72KigvMTLX74 NIo2zOa3th/fng8qVqjW5uy+jibzPFhkduS/bWArNx+hwJRr2lGQW5QV7peHDC2zTTAqjt aYgQ8ogf5ZNbRRx3hgyV71MGcW3q5r4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1679067309; x=1710603309; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=JJhHmMEgTKijBL3qP7Bc1Wtdy27vQcYTHcBz2RcuKB8=; b=YvErZCSfK9kTaLIkv8IjqcaT0fZBDQFKDpTv6gwj66C1zlpkFWsHi697 iLMI+T/Y+RjbPJHkxWuWHdRWUxe8cl2bCQVvv7gXB/C6/U1MD/c8Xt67+ GMqPwAur2iWxTcksshoC6+W18ai/jSqKpxN3J/FxUpNZxncxig/hJOiqE 4BNOqkksliMq9RMW7uWSQh1Ner2Mb82oEBcmYQEeFM21++GRvQgwYkWOz cnlGc4Ae4yyfs60IVC6ZduhcKqC4PE2/pB6JY+BThODeS0adLOU89JRdN 2lmaIslaX+Uv66G1uoGlwkVMzdIeM5BQ1omBW3UgmtNM+yaYoIpraPWyK w==; X-IronPort-AV: E=McAfee;i="6600,9927,10652"; a="400864276" X-IronPort-AV: E=Sophos;i="5.98,268,1673942400"; d="scan'208";a="400864276" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Mar 2023 08:35:07 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10652"; a="769392505" X-IronPort-AV: E=Sophos;i="5.98,268,1673942400"; d="scan'208";a="769392505" Received: from pczabans-mobl.ger.corp.intel.com (HELO box.shutemov.name) ([10.252.33.98]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Mar 2023 08:35:04 -0700 Received: by box.shutemov.name (Postfix, from userid 1000) id 3A10E10D47D; Fri, 17 Mar 2023 18:35:02 +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: [PATCH] mm/page_alloc: Make deferred page init free pages in MAX_ORDER blocks Date: Fri, 17 Mar 2023 18:35:01 +0300 Message-Id: <20230317153501.19807-1-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 0BD7120029 X-Stat-Signature: za8fje1dgoyj4p7699jyhcxt7efee81x X-HE-Tag: 1679067308-898933 X-HE-Meta: U2FsdGVkX1/g7LPnDZNZy3I3A40Le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rv/XudV0Ge3U8mQwsexdMH9PocC0QO82EH2stJjQhbnfbhOaXCsJLOAed9FOegOmITJgAWz012zHTlTNMceLhs0OoI= 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 pageblock is larger than MAX_ORDER, set migrate type to MIGRATE_MOVABLE for all pageblocks covered by the page. Signed-off-by: Kirill A. Shutemov Acked-by: Mel Gorman --- Note: the patch depends on the new definiton of MAX_ORDER. --- 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++;