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: 72556 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp1514171wrt; Mon, 20 Mar 2023 17:39:17 -0700 (PDT) X-Google-Smtp-Source: AK7set8bdk8rdlAEfIx/x+eU1XLZJ4ingEt25QaHECvE8N5I/AAn8wrkufwTe0Ur9z/BmYYI5d7H X-Received: by 2002:a17:90b:314e:b0:237:99b9:c415 with SMTP id ip14-20020a17090b314e00b0023799b9c415mr447047pjb.38.1679359156867; Mon, 20 Mar 2023 17:39:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679359156; cv=none; d=google.com; s=arc-20160816; b=A39pH0VG2Otg2BlKpAQkBZxmGLREgiXl1EXzdS24BXXglsEvFSpz5G5YPIveImpyoy 6GNGOZbBP/9ypgbnhwoG76+O3hwwkp2LSlPXNGh5HhIZ98swHuQyhsIUFSf4ImMtbVo/ RK7yZLzpTH8FtkFRCXuw58SbtcYW5Lqyif8VCPloqhpyCoGriyx+dW9KJIJ64fSctG5o asdThWaV8Mcz8bvqRl1qFnYmeXGCsVGpUzCUJcL6OnLNBwpivIf7VPKHHzbPUx7emu3R NQL7ngfS7TDryxeWOnhIMkJpxfJbvn0rDYnYpDKMyqyrSdNF4gnREbid4R7JCBKwXTN6 HPRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=g1nxw9FDkuNo5OPi/S0DTAzQuomYTvx+Jq9KYfWry/I=; b=VdPQ2qOt2PIVOoE7xy8EOoeRUfdB2xtosEd1o3oSA7nnyHsLouRKzaDFZHJXhGQOdB NJ5r/wDyeYmBbkI0dSrwRWqHykY2aVkqSPcyp9aQfAaURUZBuhr3ovXGKQXj2fp+KPGz Tp1sGqZ8mjDpP0x6o7DRPJPahtv2x6HCIGI9DBMWilOrry5ERB1//Wlu0EHw1RN/FdkD pMTsm7aGMLMJfJb7UoX4l1sNIUHCrLSB+ytIY0shSNJfnM6u2QcnWT+FZeNulrkfnWhO W/xdcTFxMVjcHVEn7V37ngPCLwU5iH/txr+9icPdTPMMpQq25GI0CYOdi/Ip8oo6Arfw u6rg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=m+CSHdlu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h2-20020a17090acf0200b0023499c3ddedsi16973526pju.15.2023.03.20.17.39.01; Mon, 20 Mar 2023 17:39:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=m+CSHdlu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229629AbjCUAYZ (ORCPT + 99 others); Mon, 20 Mar 2023 20:24:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229458AbjCUAYX (ORCPT ); Mon, 20 Mar 2023 20:24:23 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 944791207F; Mon, 20 Mar 2023 17:24:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1679358262; x=1710894262; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=GRVnvzYi7pT7KDRG53bY6VEAg5OjyUVo2Ng7bX3FNaw=; b=m+CSHdluqnT+vLAT+5fIcyHDdo5faCZ0rT9+lmaPIvKCEk2yreF7x3BP 58Cn8Jdj13MtP4Hxfbf72TBXLEE1Si2+Z2UQM+Qvo/PYEGb1FoF4tssGV tqmTjTwwKOsUHK1PVbYLcpKmP/bTeuvepfKJydqKeA+NZwcdQ1PhkjRJg ZJU0mCvvzu6ItQudKueDejJwHfTm58MULHdId+H3+OkyNSvKd9j2ufZW4 VlFC1hBbxnuNxg+njmCdXIUlB8PpUUpb96cmje3BsMkXH7cmFfopZzTgH echaK0qeRJSukQoRaqBz6IaLeNRSzaPoe4O4q/Mbcg1pxNVPuQUHwadsw A==; X-IronPort-AV: E=McAfee;i="6600,9927,10655"; a="338842236" X-IronPort-AV: E=Sophos;i="5.98,277,1673942400"; d="scan'208";a="338842236" 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-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760935707169639248?= X-GMAIL-MSGID: =?utf-8?q?1760935707169639248?= 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++;