From patchwork Tue Sep 12 16:28:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13875 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9ecd:0:b0:3f2:4152:657d with SMTP id t13csp620856vqx; Tue, 12 Sep 2023 12:05:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGDVXNAbKS04KcaUvsIpH1/rX747WZysxh856vapsUy2Tz6mI3ESQGbtjIWVZROHmrZUbvF X-Received: by 2002:a05:6e02:1ca4:b0:349:3503:253b with SMTP id x4-20020a056e021ca400b003493503253bmr562189ill.17.1694545536000; Tue, 12 Sep 2023 12:05:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694545535; cv=none; d=google.com; s=arc-20160816; b=Ktnw1f+x4rWVj2NtDwsoLlRKdywS6T3NvNCVqxwbvASwBQGDHzG1Do7jpIAeLXIs4L 3/endrQak+C0WqQsasVj5V0lJiawvUVYw3J8ZU+Mnzp0mVTnF4igPIZ+ha2pgR4YBaFZ G6DJ/tKKocoFcbZw67GUzxKQdURbOpsUPBUkyAUg1Aavs7FvshjErlRURDuzelAU6h5g sFCS0K3/MY/DD8YAVZETYcwu9ZDkzRVTVpjUHvP0aWR07ac4ouy8AtQBTSJgL30PQIZU RnYcftX6M4oyCJw0+DEYJtY6ww7v//N9bn50pTh+Ct1Q9WtAWQKbBYTIQKNFZSGMQLYG pCFw== 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:1 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 morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id z8-20020a633308000000b00564c67e66fbsi8370549pgz.842.2023.09.12.12.05.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 12:05:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; 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:1 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 morse.vger.email (Postfix) with ESMTP id 4CB068024DE9; Tue, 12 Sep 2023 09:28:50 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236784AbjILQ2k (ORCPT + 37 others); Tue, 12 Sep 2023 12:28:40 -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 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 (morse.vger.email [0.0.0.0]); Tue, 12 Sep 2023 09:28:50 -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 morse.vger.email X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776859779753405192 X-GMAIL-MSGID: 1776859779753405192 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 === To support >0 order folio compaction, the patchset changes how free pages used 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 cleared, 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 for a new page, one of the free pages, based on the requested page order, is then processed and given out. Optimizations === 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 === 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@arm.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(-)