Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1515023pxp; Thu, 17 Mar 2022 10:37:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy0kj9jPYvettQkVrgPEgfRCozdUK+QK30WR3LvQCgcJVtBqF7Viz8mugXGJeJAEDeOv1aI X-Received: by 2002:a17:906:99d1:b0:6df:a04c:8819 with SMTP id s17-20020a17090699d100b006dfa04c8819mr2934248ejn.661.1647538667901; Thu, 17 Mar 2022 10:37:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647538667; cv=none; d=google.com; s=arc-20160816; b=zKaNBtpo4oiTPzacGjk/ByuSnbgT7e3ubXFsz9h/adZsnt4Wf144+DnFjLnrehswVq 2rt4NcO0NUz/6xzMtIl+EytkIRzoSCz0fImyB7WlQzoAeBmnr3KpLAL7DdcUzyQidBJd hgMQ3orzt/Er5yGee0nYVJDydiARFr/4uWmocxV4+jLFLu7U51VTUaYsx0XrdFbAOoz9 P9xuEAF9elYDEEJwNeWv8uouPGb/q+PTcO5Ragt70EUSlT7+0XIYxndO1si+Z+L+IqGb 2BRiTzz1/ljfYrxUssWuQm6l/11aNa0Oqw+iIV3G00IMHNHNmxfESlIeI8FlDOLPnhLG 3f9A== 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:reply-to :message-id:date:subject:cc:to:from:dkim-signature:dkim-signature; bh=CBY5vO+va2Zc2XbVGFNeciCFi/umhOLunZ1gGYGvWFU=; b=nM6OE3d1r340dROf4xudZgN5rRgBwewd8MUGyi8HYgmDrNLuNYP5bWAP+Utcp992Yk n6FrFoArB5YtKdKWRjuxFGe/fq19LlQY9m+tG6Ckw8JWCT1TdXMp03sIIPE5upT21Gpy BqC13z9A4qvrDnzM1xq56IQ5bDv/n1Dz6heHyZlW5wustPR9R1IacEfboVd55sNzSTA3 4WT/eQrbDcFtzxQ/FHRE7eDmRvM4DC5B1oz3OyOOoAGb5s0C214efd7Iz+0tST84NB7C XtnQ042uAxHGzcenKVR3VhXoCm56ldWk6spZwvSIG+5Z9xnaMvNtxaFDMhUGYRE40+AI uFCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sent.com header.s=fm3 header.b=yMeUHG9l; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=EjsD2XT+; 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=sent.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k1-20020a170906680100b006cfd2d1105fsi3392172ejr.531.2022.03.17.10.37.14; Thu, 17 Mar 2022 10:37:47 -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=@sent.com header.s=fm3 header.b=yMeUHG9l; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=EjsD2XT+; 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=sent.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235961AbiCQPjG (ORCPT + 99 others); Thu, 17 Mar 2022 11:39:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33998 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234843AbiCQPjE (ORCPT ); Thu, 17 Mar 2022 11:39:04 -0400 Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 229D820C194 for ; Thu, 17 Mar 2022 08:37:47 -0700 (PDT) Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 880825C052B; Thu, 17 Mar 2022 11:37:46 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Thu, 17 Mar 2022 11:37:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sent.com; h=cc :cc:content-transfer-encoding:date:date:from:from:in-reply-to :message-id:mime-version:reply-to:reply-to:sender:subject :subject:to:to; s=fm3; bh=CBY5vO+va2Zc2XbVGFNeciCFi/umhOLunZ1gGY GvWFU=; b=yMeUHG9lq9BhmhQ5fQTv1MksPhU2a0v/p6iPol8Qct0fD9cXj612z1 +t4DIZYbVqLHVxjEeMO/YOzoTSpvMLZvJFa1Mqs5e+aSvT5PSIjK/1QB7OSu70ai E7aRBvhw2NE09urdHmBPP1w3SQHaNpKJMgHtiIND8CaobJEK8pvYwgf5yVXWZ4XW jfboV/hDJfavaW+L+z3auBw1NenmebLZMFgDufaeorW5IDs/bie2VfiIvp2n+5fV REhO2oasmY0toRnxglBQ4YGSC6gFrlow+Yw/rREFZvI00MQU+pPcOnP6aWUecyWT QPPO0hXJmvEljnG3Reedn6c++jjIxO7Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :from:from:in-reply-to:message-id:mime-version:reply-to:reply-to :sender:subject:subject:to:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; bh=CBY5vO+va2Zc2XbVGFNeciCFi/umh OLunZ1gGYGvWFU=; b=EjsD2XT+zMxBLmgNVJkByzrpLjZ5DIvX//6iX1cRnf56c TDHXES0v2Dj7/Y3sQNzA4UwjpF3t17RsiTdEh+LHs0Ce2zBDp1ShH8iwSY+CFITH h4/vGvpFnpehiy/7jZBuGSH8mle5vCKmF2eBj0i1QvNOecJ5V5kRN0idwo9DqxOo ePtsKIAtgaVgzuN/99h66LWOqAnvVqkl2h0zbwhHu22ZnLsLCJKF9ZxCA1lPKXc3 xtzEhxiaqtHkvohvTbBtsezNYw0DmZTPBphq2KNd/HbPa0L6Rk+n19J0CzIJL00O vqPrBaIsSz9Q7z+Fpf9vjjAXV2f7HixNPepanG+OA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvvddrudefgedgjeejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkfforhgggfestdhqredtredttdenucfhrhhomhepkghiucgjrghn uceoiihirdihrghnsehsvghnthdrtghomheqnecuggftrfgrthhtvghrnhepteeiiedtje fghfefueekjedvueeftddvudelhfetudffiefgfeetheeghfdvgedunecuffhomhgrihhn pehkvghrnhgvlhdrohhrghenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmh grihhlfhhrohhmpeiiihdrhigrnhesshgvnhhtrdgtohhm X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 17 Mar 2022 11:37:45 -0400 (EDT) From: Zi Yan To: David Hildenbrand , linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, Vlastimil Babka , Mel Gorman , Eric Ren , Mike Rapoport , Oscar Salvador , Christophe Leroy , Zi Yan Subject: [PATCH v8 0/5] Use pageblock_order for cma and alloc_contig_range alignment. Date: Thu, 17 Mar 2022 11:37:28 -0400 Message-Id: <20220317153733.2171277-1-zi.yan@sent.com> X-Mailer: git-send-email 2.35.1 Reply-To: Zi Yan MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE 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 From: Zi Yan Hi David, This patchset tries to remove the MAX_ORDER-1 alignment requirement for CMA and alloc_contig_range(). It prepares for my upcoming changes to make MAX_ORDER adjustable at boot time[1]. It is on top of mmotm-2022-03-16-17-4= 2. Changelog =3D=3D=3D V8 --- 1. Cleaned up has_unmovable_pages() to remove page argument. V7 --- 1. Added page validity check in isolate_single_pageblock() to avoid out of zone pages. 2. Fixed a bug in split_free_page() to split and free pages in correct page order. V6 --- 1. Resolved compilation error/warning reported by kernel test robot. 2. Tried to solve the coding concerns from Christophe Leroy. 3. Shortened lengthy lines (pointed out by Christoph Hellwig). V5 --- 1. Moved isolation address alignment handling in start_isolate_page_range(). 2. Rewrote and simplified how alloc_contig_range() works at pageblock granularity (Patch 3). Only two pageblock migratetypes need to be saved = and restored. start_isolate_page_range() might need to migrate pages in this version, but it prevents the caller from worrying about max(MAX_ORDER_NR_PAEGS, pageblock_nr_pages) alignment after the page ran= ge is isolated. V4 --- 1. Dropped two irrelevant patches on non-lru compound page handling, as it is not supported upstream. 2. Renamed migratetype_has_fallback() to migratetype_is_mergeable(). 3. Always check whether two pageblocks can be merged in __free_one_page() when order is >=3D pageblock_order, as the case (not mergeable pageblocks are isolated, CMA, and HIGHATOMIC) becomes more com= mon. 3. Moving has_unmovable_pages() is now a separate patch. 4. Removed MAX_ORDER-1 alignment requirement in the comment in virtio_mem c= ode. Description =3D=3D=3D The MAX_ORDER - 1 alignment requirement comes from that alloc_contig_range() isolates pageblocks to remove free memory from buddy allocator but isolating only a subset of pageblocks within a page spanning across multiple pagebloc= ks causes free page accounting issues. Isolated page might not be put into the right free list, since the code assumes the migratetype of the first pagebl= ock as the whole free page migratetype. This is based on the discussion at [2]. To remove the requirement, this patchset: 1. isolates pages at pageblock granularity instead of max(MAX_ORDER_NR_PAEGS, pageblock_nr_pages); 2. splits free pages across the specified range or migrates in-use pages across the specified range then splits the freed page to avoid free page accounting issues (it happens when multiple pageblocks within a single p= age have different migratetypes); 3. only checks unmovable pages within the range instead of MAX_ORDER - 1 al= igned range during isolation to avoid alloc_contig_range() failure when pagebl= ocks within a MAX_ORDER - 1 aligned range are allocated separately. 4. returns pages not in the range as it did before. One optimization might come later: 1. make MIGRATE_ISOLATE a separate bit to be able to restore the original migratetypes when isolation fails in the middle of the range. Feel free to give comments and suggestions. Thanks. [1] https://lore.kernel.org/linux-mm/20210805190253.2795604-1-zi.yan@sent.c= om/ [2] https://lore.kernel.org/linux-mm/d19fb078-cb9b-f60f-e310-fdeea1b947d2@r= edhat.com/ Zi Yan (5): mm: page_isolation: move has_unmovable_pages() to mm/page_isolation.c mm: page_isolation: check specified range for unmovable pages mm: make alloc_contig_range work at pageblock granularity mm: cma: use pageblock_order as the single alignment drivers: virtio_mem: use pageblock size as the minimum virtio_mem size. drivers/virtio/virtio_mem.c | 6 +- include/linux/cma.h | 4 +- include/linux/mmzone.h | 5 +- include/linux/page-isolation.h | 14 +- mm/internal.h | 6 + mm/memory_hotplug.c | 3 +- mm/page_alloc.c | 246 +++++++-------------------- mm/page_isolation.c | 296 +++++++++++++++++++++++++++++++-- 8 files changed, 367 insertions(+), 213 deletions(-) --=20 2.35.1