Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp3077144pxp; Tue, 22 Mar 2022 11:32:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwIVWW7yx66D4h9va7YjuXfAUTtthI0S8rLjbo6EkV752WqEOjxeIMT4a5pokDKWQaVwOLl X-Received: by 2002:a65:6657:0:b0:381:1b99:3f04 with SMTP id z23-20020a656657000000b003811b993f04mr22563640pgv.512.1647973951905; Tue, 22 Mar 2022 11:32:31 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1647973951; cv=pass; d=google.com; s=arc-20160816; b=nxlguP7PPS3T2D/h3zSdBTCEvW0BgyUPvB3mUoOUbSvuni5svmfxYR3GDLAZo6beor CawP/24AyC0FZjc+H1J/03SCkgns8eoBnjuSqx597GeAEYrJM3q4qch31W4SQoNhnxR5 adOTl5OKvKXsT1kNhsx3evQSo7EmasNBbLztfG99ryzRgcjW3BW4iWH75ikMBaAnyr4L nni+nWPcSmR6wTokgIWfTnG7lOZQmjM0B6caYFj9g9UayusrgqiwSzlaMIXPgZXfchNM JbH9Sr3XxRYEwkN6FmbeAKXGmC7+OL+OBK6E4xOeL/emjh2R5yaD7WSQtPyOmNGM7jr0 wIsg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=ru8E4LFHVf+kw8xPFqzeSG8fntHfmGzeug5xEkvbnmc=; b=XdqjOUtVnQrbHtwuqKliGfRJyObH5hlQXHUorfRIvYtYk0151Tl5YkYEWcmSYKFBvU bU3rc3LzQ7Evhc++T9rfToDz8/9yGH72vOJLp50YbBYlTFIfoXLVXOkl2GXPPoYBdoDa 0d7ohCGi0nvlTfMVUnTOGOY9fBxYApAaW+3ZtyBfsqvhNoqhIWgbATz/ZLVmscWXa4JF VSEEDqsOYYw64vy6pe9CpZRfHi2Bn33CFqFuJ28t2rKf9EbTzoC1rOvMSZd5J0Fwgez5 AbTfUvoEzo49N4Qcum7Isg4hLW1GW4fmSSZXGP2LAPfKumH5KrSdHnHytC9RPqI1WPcd fWLg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b="Jfji/lc/"; arc=pass (i=1 spf=pass spfdomain=nvidia.com dkim=pass dkdomain=nvidia.com dmarc=pass fromdomain=nvidia.com); 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=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v1-20020a637a01000000b003816043f053si17100107pgc.584.2022.03.22.11.32.17; Tue, 22 Mar 2022 11:32:31 -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=@Nvidia.com header.s=selector2 header.b="Jfji/lc/"; arc=pass (i=1 spf=pass spfdomain=nvidia.com dkim=pass dkdomain=nvidia.com dmarc=pass fromdomain=nvidia.com); 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=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237839AbiCVO21 (ORCPT + 99 others); Tue, 22 Mar 2022 10:28:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239724AbiCVOYv (ORCPT ); Tue, 22 Mar 2022 10:24:51 -0400 Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam07on2056.outbound.protection.outlook.com [40.107.212.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84BAB98F59; Tue, 22 Mar 2022 07:20:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UqszyVg4L2jxi3/9Akd8QMlk3wp2afWA+1nFAKerUnVptSdqRlwhmgXKLrtlyT5+JzQVY5gp4D1rvYw9vQ2c6B2WlfiJlrwsaTPPRdVGYhEU3GI5YN7bNHsfgD3gvi/qedkOXCyuIUZ5Kx3PRDqC8CGb2tn5b7ZYewbTqGu3CEnpTQvBMAbVAHPJ+6luE1N3EtSSKjGBe1SrJuIEn0Dk9SfNuCBoi1I2+lnpNCGSiUJ175vU9DE2UQ+xf51B4raCiRcuyVhTWGgSdUBweTENpun/b4CVER/pRu988qoq7og3VJcsDZsl23EEvE5Ju0rsynxp/rhI4TwWiWZq3UxF0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ru8E4LFHVf+kw8xPFqzeSG8fntHfmGzeug5xEkvbnmc=; b=oapFzjROHSFoImDEtcFu1XPxzc2Ua2K9PDw3RltjgvB3Qo8MzLLJZd38r4tfuKxH1Ti+aRIr/VVRu7WLm0NfEJwr6NB74DzEA7LOvwcN+OJoj336g8ZLyvlr1I5u6o7kbpOcHm+mJulZrIgP5fSOlnLfueopgb9ajoiYAAShQBKXoPPDC4cji/EgZo3nDKdVubGlMXJd8CwepXVG3iSt/qE3dVwj0uYkq18eUMWXIMNNfbCPL98NWWhjIRfrbfVbtQNUs1+/CQ5+epGWw1ExEPNKn6R0n76P+oCnNFql0a847LZRm66HVGYS3zuy+V5BX4zscZZD+QsvYqsPWfjKhQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ru8E4LFHVf+kw8xPFqzeSG8fntHfmGzeug5xEkvbnmc=; b=Jfji/lc/DbeXQAoCT1tQIB8dOfql/kwL32EMvQ7V3Mnatd1XCGzS4Ga9W8C8oeCCZbyWiM7mg59ysQTmQhwSCTLnQVNLL8FP+fH0yvmWSV0DxJ1UiAtpAPOZEuERtWdBx0swPj1+YmZsQ2yAfD0kxA2wgewc/lRbcvkGDuc1NAd5Lu8ywkxkvJftlA0VBeBAsY26xVsRNKcGsaXt5FvyaVB89XcZqqfqxeqiXQ9tzCqak136i3B453JwzGhvKVJlWgPQkN8cguMJX4OYFpiX5MuoafnOMC6j1PWw1I+S24tWt5M3H9kqXiPhoBuAmkvhkIKItEvcChY+pbsyVKHaCQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from MN2PR12MB3823.namprd12.prod.outlook.com (2603:10b6:208:168::26) by SN1PR12MB2415.namprd12.prod.outlook.com (2603:10b6:802:26::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5081.14; Tue, 22 Mar 2022 14:19:38 +0000 Received: from MN2PR12MB3823.namprd12.prod.outlook.com ([fe80::40a6:6e1d:b057:a036]) by MN2PR12MB3823.namprd12.prod.outlook.com ([fe80::40a6:6e1d:b057:a036%6]) with mapi id 15.20.5081.023; Tue, 22 Mar 2022 14:19:38 +0000 From: Zi Yan To: Roman Gushchin Cc: Matthew Wilcox , linux-mm@kvack.org, Shuah Khan , Yang Shi , Miaohe Lin , Hugh Dickins , "Kirill A . Shutemov" , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: Re: [RFC PATCH 4/5] mm: truncate: split huge page cache page to a non-zero order if possible. Date: Tue, 22 Mar 2022 10:19:35 -0400 X-Mailer: MailMate (1.14r5870) Message-ID: In-Reply-To: References: <20220321142128.2471199-1-zi.yan@sent.com> <20220321142128.2471199-5-zi.yan@sent.com> Content-Type: multipart/signed; boundary="=_MailMate_35D1A03D-315B-42D0-8538-3E47809BB42E_="; micalg=pgp-sha512; protocol="application/pgp-signature" X-ClientProxiedBy: MN2PR11CA0009.namprd11.prod.outlook.com (2603:10b6:208:23b::14) To MN2PR12MB3823.namprd12.prod.outlook.com (2603:10b6:208:168::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 802ecee5-96e9-4bd6-fcc4-08da0c0eff3e X-MS-TrafficTypeDiagnostic: SN1PR12MB2415:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: FgUZwmb2OfKLeSbWR2Xgiq23Yc/Uy3fY1yF08l3ZoXawVRlv9kkcJsmqe4aePwpRZf1HR98IKcgGXb0DbrfzwX+KSDjn0+x1GbKBOx9U61qyySc29FvZADAs0rQv1vIt6Ob6btpyZPC6LHFxUr0Yqt1qyodoMhe7ihbN9YchlZj20svnuRkqFzzYQSHs8W71+/uXt4pZ0ZH+oJc/Awj/R58T+sGAx2rCogRuZcHx/38n1KnAKrwZT07fbsOtFw/uf3BQb4MH4aZ2CbFm7/gdP+fj3/1oH7k7DdJDNIm7fMKnClz+a2fSZAtDAuCoXpUlNWgkTda9pEAIbjM+zvtbOSlc8J858JKqfP/WVTanQ5cVBOS8laUzlN6CvD+WD20469B0M9JKtMevcc5LgEEG6jixyZcxYYsJyBwY91VWPVfLwv7T+1m88tF5gXB6nzPAVuA75KnB2qlBnIXXT++nkX0MIObr8Dzrgb0ewLrfpvWez1qOUo/GQM8/araSvQTaqXKdOS5hJFoQUxF9kEezi/KACIKVDZxdefBEl3GA3W7Hai+F+KiqL3jXIpE7kci1wVjWEMwzfdCWr2ePy5hZ4QGfRaGc6ltq3hf8aVC4QbyccSqB8JzpnYbjXMMT4p9eu477eEF4bhGJ78M9Z9U0KxS27z8xewFOeNhaSXFaO315RA4jgK1wBFK59jAwTV7vAVoKG/OmfCT8++90/1ZNCQuqzylOR49F4EV/pvBjwiDg6zPS9Bl6H8eLPSOTwXu0 X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MN2PR12MB3823.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(316002)(86362001)(38100700002)(33656002)(6486002)(54906003)(6916009)(5660300002)(235185007)(7416002)(8676002)(66946007)(66556008)(66476007)(2906002)(21480400003)(83380400001)(2616005)(4326008)(6666004)(508600001)(6506007)(6512007)(186003)(26005)(53546011)(36756003)(8936002)(14583001)(72826004)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?g0gzXN1veKgmX1ChY6eEodiUWPChH4BLNh7mNYfIfQYa/l+uajqU59Oy8nlD?= =?us-ascii?Q?C9qtK9J5IM/hEjQZyH9KIOUlUOGRDbxfUE9F6WFfmG85z8KeDmV1j09olD/w?= =?us-ascii?Q?WDxD8sdsEJLLQTpel2sq1TYoIFPyU/yhlgxdxazXmxV+JZ/rpzSUspRMT9Oz?= =?us-ascii?Q?bGB76TLtN92RGqR0lBvFYqmwYFHMruRgXIn4bea4OuG9CfX5WcsJeLKDTsoO?= =?us-ascii?Q?McW6+p8M0wTzHaWnMvYFR0RHkleJM/RtniPIxct+w1X0D/FdF9TZhwzUG8QI?= =?us-ascii?Q?S6H3RcjDzZAo9mVh48MIuVTexd3nj+OwOo0uWYA0xVx4n+IOQGPC1KToG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0tghkQpMancOFBm1a2jP0rxwspoOn45VnQh4ZV/?= =?us-ascii?Q?f6m9Cb0sH4NmAQIYNYhtxDCJwl6v7SIygnuUvhNxfUmo4kWvBW949U9pHj1M?= =?us-ascii?Q?8O3O0OuDQpJl+3cVyMkvZ/xamM0ZimggGj5PXeqW9a16JvjcP54k9VF0M3/y?= =?us-ascii?Q?fJ3fd13pnwUx8xEGn4PS5Uxl1odA8qaK6ryDflYSYBRkwNax2ZMEoHeSGDW1?= =?us-ascii?Q?Ot8pmmo/uutzuYYJaON4iCDly9epJgkl?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 802ecee5-96e9-4bd6-fcc4-08da0c0eff3e X-MS-Exchange-CrossTenant-AuthSource: MN2PR12MB3823.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Mar 2022 14:19:37.8989 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: GgWwr4ycQ0OIWqgJr+Zsy+qk4MwlG+ZNV8iNit3j1H5rddeKc4MSjOURu3ITh7bz X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB2415 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, 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 --=_MailMate_35D1A03D-315B-42D0-8538-3E47809BB42E_= Content-Type: text/plain On 21 Mar 2022, at 18:32, Roman Gushchin wrote: > On Mon, Mar 21, 2022 at 10:21:27AM -0400, Zi Yan wrote: >> From: Zi Yan >> >> To minimize the number of pages after a huge page truncation, we do not >> need to split it all the way down to order-0. The huge page has at most >> three parts, the part before offset, the part to be truncated, the part >> remaining at the end. Find the greatest common power of two multiplier of >> the non-zero values of them as the new order, so we can split the huge >> page to this order and keep the remaining pages as large and as few as >> possible. > > Would you mind please to describe the algorithm in more details? Sure. During truncation, there can be three parts in a huge page: 1. the _offset_ from the beginning of the huge page, 2. the _length_ of the to-be-truncated part, 3. the _remaining_ part after the to-be-truncated part. the size of the split huge page need to be the greatest common divisor of the non-zero ones of three after being rounded down to power of two. OK, I actually find there is a gcd function. I think the algorithm can simplified to new_order = ilog2(gcd(gcd(offset, length), remaining)) - PAGE_SHIFT; I will update the code, the commit message, and the comment in the next version. Thank you for the comment. -- Best Regards, Yan, Zi --=_MailMate_35D1A03D-315B-42D0-8538-3E47809BB42E_= Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQJDBAEBCgAtFiEE6rR4j8RuQ2XmaZol4n+egRQHKFQFAmI52vcPHHppeUBudmlk aWEuY29tAAoJEOJ/noEUByhUomsP/2bJIPAzwm05+PkUnEXdMV1zzJ5A5NEhlmuP NRdFKhKvSjipK2qU4Q0h6kmtESTbxZmnVbaU6g8KvBWrtuDliOJyf7ika1uUV+Va 2t1yziumrX9mlUFGfzca36O70pj2EkDCBuYPntV/VAJG35trMApLMeXktr+y2wGp 0T3mZcs8OR0vKLVm6rmYT020f4l7xtShIGi9wpAZIhYHkFblKZpbRxstgk3V1HRY XgpVLA2z+GKX/X0x+9ochEIHLUa2XxkJfmRHFNeywyD3Kunw7YIXrSLWz6NkOJkK wR1ok7xFoCcF8GsLnMs1peN5Rikb55+GLWBW70ZzreynebKFihRklhLnMEaNGN4p lRj8pbnyPkAsuSiXLVSzsUFO1ZRz3PCKdCE67synoziIV7KEmbylbNxNFJ/wWYsi UjqOIXfcxRyWuCCx6OSXbxrCANvZIAv5su9N6VX6jA8d9vl8ZPKYgA1UxOHPO1Kw aAOm2Qa6KiqWJ7BL2WJnbkHrJbyCI8opnRE8D+YWn1N5x28tPWhnt2ljzO0T1XFi mVwW38mNuGZKRoavVcYKmYiUJ6eA/+/vwttKWC/g9KvbPlaACSq65H6oVzc6L85+ UnjQ9bRODLcVKW/fnZneqznRhuu+CKgOTtHUFJXuekveAomvy/0IhPJpAXv698eW J+gLaRwj =etv0 -----END PGP SIGNATURE----- --=_MailMate_35D1A03D-315B-42D0-8538-3E47809BB42E_=--