Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp2806640rdb; Tue, 12 Sep 2023 12:39:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGjQtDe2HdtY1TzMbKaw0NeQW5gio19nRYqAst2EZ+ypZXl+pnhfaDy/5vxhbmNsTnverlK X-Received: by 2002:a17:903:11c8:b0:1c3:bbad:9b7b with SMTP id q8-20020a17090311c800b001c3bbad9b7bmr800372plh.29.1694547546302; Tue, 12 Sep 2023 12:39:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694547546; cv=none; d=google.com; s=arc-20160816; b=qAJrB6MB5JmUpnHxzn8s+H7S8i5zHYqnh4n/DkVFnzR5KS3jZJuXDcYeOEZgiJnWey dT1sa+RBSDEI220zW5bN68+1wQiAfuMOeZPw1scmkYdCcsa+13IJ6qDgGQDztNS+HXnN 5cjkdf8hQVvYDuQe0zbzCFctfGH2O/Pdr5LkLh+kibi4FG5ejKvraU9JPNhjnFAipZtb 6YMoOZKMhr/o3D8Z+gq90WWRHKKgIxt0dSt+7SfUEkYAnIqoja9ae1ceAG1T/zTq+kd3 borKQZIYlQrl8s2OUD7EUodkQtNv4V8ICo2FnbwBu3tSM9c4GleQhbqaMve21JF4xc58 TPQg== 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:feedback-id:dkim-signature :dkim-signature; bh=5t1ioQ/11KphbqzXH7SCYin9Bo5ArvfTJo+4zOQ+tUo=; fh=bUDnJOBC0/apF/24NaPi+H6rvMB40CebS5Pe6QbQjAo=; b=pYPQYkrIXZisefv0Kf5E2R2XR7yUwvJYncPkuOCDDyCaJOIRuWWrn2rylCDWjR8W8G /drMV6OFO7T1eNZYHSri7h8qZbucKHMHUPDMb9taT9P+1/z7VrqLjxiT9VBC2VI7r1zd PMtXGBdqOHv1qtCGNqzrDUtzavy4Ul3oOMjdvJPWoY0grmz5YtMV8JAFZgEmVYPHU/rw SseB5TjEqN/PT66MFwX5nfTgEV1WYLNicmfT/CiYwAU/hOc65P6HBeiSx5VSqJ3QFkw2 3PQdffJBk1PMKM72gyulOm7Jp8+9bv2FDikBsJjYkt14+wZ1bStx9hSLad0VTXQk5p/t qdcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sent.com header.s=fm1 header.b=yPxIE70a; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b="M3g/WjBO"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id ku3-20020a170903288300b001bbb8a61d3dsi8312273plb.562.2023.09.12.12.39.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 12:39:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@sent.com header.s=fm1 header.b=yPxIE70a; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b="M3g/WjBO"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sent.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 681D0801B8BB; Tue, 12 Sep 2023 09:29:21 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236779AbjILQ2j (ORCPT + 99 others); Tue, 12 Sep 2023 12:28:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236772AbjILQ2h (ORCPT ); Tue, 12 Sep 2023 12:28:37 -0400 Received: from out2-smtp.messagingengine.com (out2-smtp.messagingengine.com [66.111.4.26]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 670C4115 for ; Tue, 12 Sep 2023 09:28:33 -0700 (PDT) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 8F5BD5C020E; Tue, 12 Sep 2023 12:28:32 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Tue, 12 Sep 2023 12:28:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sent.com; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:message-id:mime-version:reply-to:reply-to:sender :subject:subject:to:to; s=fm1; t=1694536112; x=1694622512; bh=5t 1ioQ/11KphbqzXH7SCYin9Bo5ArvfTJo+4zOQ+tUo=; b=yPxIE70aHJyQBG+Cz7 r1pUm8bA7QZYChGe1yn5GyPCFUsWuCw8vTMgKJmPWCfBljM6LYkcMmbYqPU3v8W1 McvyoyJHw0npjr6fTKnw0sr9TRsbFbyXlgtwcNGKqStMbESs4XwQQ3D38KA/YrbS KgFz6ASTZTmJ2PXCS9mzxogr12O+bxO3FvfD89UhJc33NzdB6GfVoNxgLx0OMEIF 69l0gbGaX8ewEojdkEH+NzlFLMBXBGOZWc5wFtP3yZ0i7P9AgnvXf9zqCsLe03PD JLnF3CucRaTXVr0Otp/U/SQ0xXWS/FxTmkwt6s/fXU9X18/LyA1VsRX/BMDCe1oU PYvw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id: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=fm1; t=1694536112; x=1694622512; bh=5 t1ioQ/11KphbqzXH7SCYin9Bo5ArvfTJo+4zOQ+tUo=; b=M3g/WjBOWlHh3VsRR 8pDFfruMUOVnACEwfCjQWnnoCfpyyBSB4X5h+mfZkTim3kdPSAQySOdddZl8FbLN QQI+5pCliiBxHNtQFzOJvD1abGwpoVL7Q5LwiM8lByN4baeMu8Znx+Z616roydOz TG6AW7aQ3ZmDGMhu80YKMaSdz9wjkzd6Sni1cbTmQXqB6OzL8YEVG9KNPyxFPjBK crlzO7e5y5aLclGd/KAstXTbSsN+rkdJXFEJze9ClEiTpRx4VoHxOmJMczbncWj7 6czUo77It5UygNrbHbwUf3QkLnQePOc/mK/rS9TCCPdF2ps+xfUy0ju0mwyZanQ+ mf9gw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrudeiiedguddtvdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefhvfevufffkfforhgggfestdhqredtredttdenucfhrhhomhepkghiucgj rghnuceoiihirdihrghnsehsvghnthdrtghomheqnecuggftrfgrthhtvghrnhepudevud egfeffgffhteehjeeuheejueelvdehhfekhfduieeggfduvdevkeevieevnecuffhomhgr ihhnpehkvghrnhgvlhdrohhrghdptghomhhprggtthhiohhnrdhmmhdpshhplhhithdrmh hmpdhprghgvghsrdhmmhdpfhholhhiohhsrdhmmhenucevlhhushhtvghrufhiiigvpedt necurfgrrhgrmhepmhgrihhlfhhrohhmpeiiihdrhigrnhesshgvnhhtrdgtohhm X-ME-Proxy: Feedback-ID: iccd040f4:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 12 Sep 2023 12:28:29 -0400 (EDT) From: Zi Yan To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Zi Yan , Ryan Roberts , Andrew Morton , "Matthew Wilcox (Oracle)" , David Hildenbrand , "Yin, Fengwei" , Yu Zhao , Vlastimil Babka , Johannes Weiner , Baolin Wang , Kemeng Shi , Mel Gorman , Rohan Puri , Mcgrof Chamberlain , Adam Manzanares , John Hubbard Subject: [RFC PATCH 0/4] Enable >0 order folio memory compaction Date: Tue, 12 Sep 2023 12:28:11 -0400 Message-Id: <20230912162815.440749-1-zi.yan@sent.com> X-Mailer: git-send-email 2.40.1 Reply-To: Zi Yan MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Tue, 12 Sep 2023 09:29:21 -0700 (PDT) X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email From: Zi Yan Hi all, This patchset enables >0 order folio memory compaction, which is one of the prerequisitions for large folio support[1]. It is on top of mm-everything-2023-09-11-22-56. Overview =3D=3D=3D To support >0 order folio compaction, the patchset changes how free pages u= sed for migration are kept during compaction. Free pages used to be split into order-0 pages that are post allocation processed (i.e., PageBuddy flag clea= red, page order stored in page->private is zeroed, and page reference is set to = 1). Now all free pages are kept in a MAX_ORDER+1 array of page lists based on their order without post allocation process. When migrate_pages() asks f= or a new page, one of the free pages, based on the requested page order, is then processed and given out. Optimizations =3D=3D=3D 1. Free page split is added to increase migration success rate in case a source page does not have a matched free page in the free page lists. Free page merge is possible but not implemented, since existing PFN-based buddy page merge algorithm requires the identification of buddy pages, but free pages kept for memory compaction cannot have PageBuddy set to avoid confusing other PFN scanners. 2. Sort source pages in ascending order before migration is added to reduce free page split. Otherwise, high order free pages might be prematurely split, causing undesired high order folio migration failures. TODOs =3D=3D=3D 1. Refactor free page post allocation and free page preparation code so that compaction_alloc() and compaction_free() can call functions instead of hard coding. 2. One possible optimization is to allow migrate_pages() to continue even if get_new_folio() returns a NULL. In general, that means there is not enough memory. But in >0 order folio compaction case, that means there is no suitable free page at source page order. It might be better to skip that page and finish the rest of migration to achieve a better compaction result. 3. Another possible optimization is to enable free page merge. It is possible that a to-be-migrated page causes free page split then fails to migrate eventually. We would lose a high order free page without free page merge function. But a way of identifying free pages for memory compaction is needed to reuse existing PFN-based buddy page merge. 4. The implemented >0 order folio compaction algorithm is quite naive and does not consider all possible situations. A better algorithm can improve compaction success rate. Feel free to give comments and ask questions. Thanks. [1] https://lore.kernel.org/linux-mm/f8d47176-03a8-99bf-a813-b5942830fd73@a= rm.com/ Zi Yan (4): mm/compaction: add support for >0 order folio memory compaction. mm/compaction: optimize >0 order folio compaction with free page split. mm/compaction: optimize >0 order folio compaction by sorting source pages. mm/compaction: enable compacting >0 order folios. mm/compaction.c | 205 +++++++++++++++++++++++++++++++++++++++--------- mm/internal.h | 7 +- 2 files changed, 176 insertions(+), 36 deletions(-) --=20 2.40.1