From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6C590C4332F for ; Tue, 8 Nov 2022 10:41:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8ADEC6B0071; Tue, 8 Nov 2022 05:41:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 85DA36B0073; Tue, 8 Nov 2022 05:41:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6AFAC8E0001; Tue, 8 Nov 2022 05:41:12 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 5BBA56B0071 for ; Tue, 8 Nov 2022 05:41:12 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 2048B161148 for ; Tue, 8 Nov 2022 10:41:12 +0000 (UTC) X-FDA: 80109932784.01.E9F3C25 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf18.hostedemail.com (Postfix) with ESMTP id A34111C0006 for ; Tue, 8 Nov 2022 10:41:11 +0000 (UTC) Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 2A87uubY014601; Tue, 8 Nov 2022 10:41:10 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=message-id : date : subject : to : cc : references : from : in-reply-to : content-type : content-transfer-encoding : mime-version; s=corp-2022-7-12; bh=MzGMtyL4iDPhLZoPwteELORapkkk8jFmE+OeMNKhMSo=; b=dXPsD+FIxzOuoemM7qMcrnvpoOqUrdRZOa5FJvUIt9FvA1aQEY6svguxihjZVwupPC6J thDUxhafnS847wJ5h5Zr3bQjjtb5L202U8hBTVu0Ue1sQa5dJFYWwy+fh4T+94aDhxTe veQkPh25KrhYOjdx9pVBQW7+9ilK/Uw2Y4zFwxUkiBBFdMU2TmU8TynABmX+CK4q+ryt ilqYQaEgemKk9eZEdC0CDl4p4WL5ktXSxDkqCf2OTlhe+5UoXS+BiRKTPucJPTCoeokE MQXUDhs58S2LJ1TTgIDRPiqdga+4xVkVa8fckxFUV86mv+FcdatFa5FIZd7qyfj58ski mg== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3kngnuxuhm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 08 Nov 2022 10:41:10 +0000 Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 2A89pql4003328; Tue, 8 Nov 2022 10:41:09 GMT Received: from nam02-dm3-obe.outbound.protection.outlook.com (mail-dm3nam02lp2043.outbound.protection.outlook.com [104.47.56.43]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3kpctc0r8j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 08 Nov 2022 10:41:09 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=C0gINLQG0fGxOMbutEMh8kbaM5vhPwy1qqehcP/ri5bNhVI/gClHcyi4+N6qFZMqetZpjIChGk9MySN+usw4Nfw9M5fE2X7vYDkrFCBrzbW5IImvkQ2P+uEBcRTYNIC6eq6c2pNT186b8MQ/2gvdSnptKoy5YqnDOF2+OsONgm/q5hmqUqiTlGViLefviBiAHojZgYi8SGVKTHzXRMSqiVVoZbRr5hS6A2TSeqbOQCHBmt4OAIynZWSJ57LFMvzTMF+SDI9c26f9YTAYO2a7KxqAK0URDVDJ1hzwKmJ3Upwnozg3BfxyQAeGc7PzuZurnC9mxy5U6LNa5NIMnlqJKg== 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=MzGMtyL4iDPhLZoPwteELORapkkk8jFmE+OeMNKhMSo=; b=IuvJORjKtkSOPufktSa3XtRerrjGrS029n9IVETltaybDxzH/4oRoDyuXc6OwznQaHVDrixtrl5A/HxEaSKv1q9GTsjZkIT2o4e7TapAQnY+tXyF8KfApPOmFxyDFVVDBRAH/YjdWiCCNWk0xIxn20LuSn8WD5UHNkpq40Atfo+V7l3DgTdkhlw+LgY4mBmBFc/+gqrYpAqU2PbesQgA27XyI6E3no6znIrQ6zCrz840pKDPq4rDN81UyozPC//oEARV3NyIBLMlseiCtY7zBHY7GH4VmF46AfFIDjnI5i4oJOFxtf/JRG5VBFhTm63urQwPZdldblirEQrA1vmrUw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=MzGMtyL4iDPhLZoPwteELORapkkk8jFmE+OeMNKhMSo=; b=NlzvPZ+mVRyY5KzEr1RSexRWHBx1uXudtmaHD9wOKnq869nuPg6fWctd5zIbdY80S+h6iZbkdTSTbnjjG1qVYpQ6NFJ5fKvRkK8PELgSRUFHGPihrmknA66VLM4VRL/LGi4J4mTpUoHln6dDyKY005If9a7oFlFBMWgJPwPWSSM= Received: from BLAPR10MB4835.namprd10.prod.outlook.com (2603:10b6:208:331::11) by BLAPR10MB4948.namprd10.prod.outlook.com (2603:10b6:208:307::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5791.27; Tue, 8 Nov 2022 10:41:06 +0000 Received: from BLAPR10MB4835.namprd10.prod.outlook.com ([fe80::29f3:99bc:a5f0:10ec]) by BLAPR10MB4835.namprd10.prod.outlook.com ([fe80::29f3:99bc:a5f0:10ec%2]) with mapi id 15.20.5791.027; Tue, 8 Nov 2022 10:41:06 +0000 Message-ID: <8482a2e8-89fb-bb20-6b83-81c548bff639@oracle.com> Date: Tue, 8 Nov 2022 10:38:32 +0000 Subject: Re: [PATCH v2] mm/hugetlb_vmemmap: remap head page to newly allocated page Content-Language: en-US To: Muchun Song Cc: Linux Memory Management List , Muchun Song , Mike Kravetz , Andrew Morton References: <20221107153922.77094-1-joao.m.martins@oracle.com> <28F33F85-1DCC-49B5-95A5-B005A7B11E57@linux.dev> From: Joao Martins In-Reply-To: <28F33F85-1DCC-49B5-95A5-B005A7B11E57@linux.dev> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-ClientProxiedBy: LO4P123CA0416.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:18b::7) To BLAPR10MB4835.namprd10.prod.outlook.com (2603:10b6:208:331::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BLAPR10MB4835:EE_|BLAPR10MB4948:EE_ X-MS-Office365-Filtering-Correlation-Id: cdde49e3-1b29-49de-f168-08dac175bdc9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ET4NjBtSu6skP3DsE3doncnbRdsHD+YKKXyW0wP6sVJI1DDYXqEriOYf7NHfXc+O4+N0JACEtkwKAT2Nh260GojYwQvSVMvHCd76OHZRhDit0S8zLYgaaSte0J07G8V65uy10GA1w6hQFVM/hgJK/6eKiE8aYsKHwUiRIuxz1/ElmwIzSFIfNzWzBtx3Sr1vDs4v3aGV4wu7v/oV0aHdqD4BtMiPjj3MYBr63E1HEjrm64Wm2FcgnASStL2IU5fGfJ9+M8lYBaIW8hE3/GDaY8yog6FZ7zj2Hlz7JZuKPo5flPsJyw4B2ujmx3mhYrxTVMOrUthnovTy9V/vdN6GKz+vIuvlSarNw7/z78rajMwcxr2DMYJvp4IYIWNAsQw4ihOYRtcFMwcv/VHyO0VEkDVZRDXbPbFKDLF1JE5XGchJi12l3OJRIuSyBMwBIV/PSbwLMBGnOkYINzVnMk4iT78y4RdXr011AQcayJ49N3jJTpL9axAV6VcFqKJWe0nbYKcnubQIiFuyApK7RdiKycqJ+/+87y+Uae8ohCjJFEUCcn2g9TMBs/+967oDeNpWy5oWjq4LCpyvyAsLrL+re8uMtgPyLTb4bYkDZTEj2YRrAMHM5MstfFfYU4dJ2GiY4hIUvlpE+Q4kps/q2BVKXdBLUBI7U2Q4CHrHmM0XXGhgdU13mzDWZg6aiHAqE4hjdoNDyTI7PkN4xiuPaXF7fA+cXDg+NyVtU3G80SjPM21GzLpGjCsUUAASv/P5io6oWn7v6N9hP8/4cc7H7/TvCkpru6CYiCNFii5yKl1Nb0PlhBWoA9a69TykjUuobLlbpSoVkxLmNGbseboJcP2cpw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BLAPR10MB4835.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(346002)(39860400002)(396003)(136003)(366004)(376002)(451199015)(41300700001)(8936002)(30864003)(186003)(36756003)(5660300002)(4326008)(6512007)(2616005)(26005)(8676002)(66556008)(66476007)(66946007)(6506007)(53546011)(86362001)(38100700002)(2906002)(31696002)(83380400001)(6486002)(966005)(6666004)(6916009)(54906003)(316002)(31686004)(478600001)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?MXA1ZWJLL1JjR1FQajVZaXpXY0VFQVErclpoUm5HM3VKUCtkSXpXSjhGZm5M?= =?utf-8?B?dC9JS3BWVTFLWGRHN0srUnNUQ0ticmsrWlRlY0s5U2dhUVdXWmpqQ214RXJ2?= =?utf-8?B?MWxCYUFpTWRKcXBxaHYyWWFXVmgzNmVvckQ3M3FTeWFjVWlza2x1QVJETnBL?= =?utf-8?B?N2cyc0NtMFQzTVN3N1JZd01ObVZwNFhFT1VXN3BWdVRJQU41czdxdEdRZi9z?= =?utf-8?B?RTlNMzRrdFBudzVYOW56d3ZndUdaa01EWFpPQ0lRNTBPdWNJNnJVWkVsYWRH?= =?utf-8?B?WGZXVlBybDZNM1l4Y1RHT1o5VFI4aTZBdy9NaWJTQmJ1VTlMWE1rVUlwY2xG?= =?utf-8?B?R1JCVWhHdnc2cFRsblk1RHRwVkN5ZlFjTGpTZ00wMzU3M3VzTmYwUmtSNitm?= =?utf-8?B?Ym40NHl3MVR4Mi9qT0IvVENpUlBFR1FWS2NaeWhody9jT0xBbjNzbmZSM2xX?= =?utf-8?B?cXNrd2ZDU0R1TXNJUUFmVVIvSFE3YXpoMWNXbDU4TWRQWkgvcGJNeGlhLzlL?= =?utf-8?B?eTRieGk3TktSeExINzk5am1TZ3pqWDk5RithanJ0VG5Uby9FdG1ERklJOG9B?= =?utf-8?B?V2JrVXcrMjZTRCtoOURVa01LdzRDaVppWmpHZHBBbU1Ec2tVbnBHZEVTQnMw?= =?utf-8?B?dGVoMGVvM2J5UldIR2tIUytwMnFrZ3VKTFNFNkVCeTZTeVpXayt0dHYyRXpH?= =?utf-8?B?MHl0MWk5a3VSZE1iWEVWMnhJcUFLWjlqaGpqbHZKZGlSdGtMaFA4bXFLNzdh?= =?utf-8?B?YXlWNlRiTDdYRWsyTENiK21jbFkzSGpKcGJRY1IyckllVDE1NGN0ZEdSaG12?= =?utf-8?B?bUxpOGtUVldabG0rZnA0TkovOWloc2RYR0M1Y011cGFsOHpPZXRLVWgxQzhG?= =?utf-8?B?RGJpVTdkMFhQWnNxN0JLenQvNlBITXViSFcwOHErZEltbWZnRjlMb04wUVNz?= =?utf-8?B?N3pma1hFeUppWVVhOGorZ0xFUWdWTFdzSlJIeGxjbzhaOFhHakdsWlVvR2lt?= =?utf-8?B?WUVIclM2ZHV3TGQvSVJnaTdSNEsrZ0JjYktuMVUrUzY2YTYxWFFlYXZxcXJL?= =?utf-8?B?NkVwd25JZjNENkhRbEtQaUlxTXNsejhlYnRrMlFLRXhEL1lZZjVOcTB1SHlw?= =?utf-8?B?SGZCTFdKeVV2N2ZYUk45bmd3L29xSDcwekJqOHRxY0pSZTJQM1hiWDFMUnI0?= =?utf-8?B?cXdOTFJ0ZnB0ZkZqLzhjY1FIWFNSVW50R1lkZEdESU5ZNkZ5S0ZXT1p5TDdF?= =?utf-8?B?Yi9sLytZbG1iWnZ6eHphdzZjd3F5R0lTdm1Sd3YrcVVwdWhJYlNDaG9ZRTVZ?= =?utf-8?B?TXJTMkVxSkRqNjdHRGxjdlZ3aDRBQXRkOWNVVkJaRFl6UzZhdkI0ejFBR3ha?= =?utf-8?B?TUdMUDUzdkQ2Q0s2bDV1bzJLa1lsZ1g5ZzJUNG9DMnhmSWFKVEJra015VzZp?= =?utf-8?B?Yzc1WjFXV21kSityS2FicmpyUUtiSTZkQjJsZHRJUjdxbGRMWXordk9uN08r?= =?utf-8?B?cU5jWXk4Z25uM2JsWFd3a21NcytKVnRiWlp1M3VMRkx3aWY5VVVwTDhPYS9i?= =?utf-8?B?UTc5K09NeXo2U1hhQlRPMzNFeU5LbEpoMGR5YnpyaWhZWGpHdktONnMzOENT?= =?utf-8?B?WVZrVUg5NkZyUUNDWkc5K09GdlBMLzRvWTNBeW5NcXhKS0U0dTRDVkZNeWJp?= =?utf-8?B?U081TkR5MUNzOTM5SUY1WEp5YnprK2ZSSG11bURaaWxnR0ZqeW1paHl6dHFY?= =?utf-8?B?S3loMGdlRmpqSHFVSStnTzNaWmg3V2FweVRBbGc2RHllS2FtQ2gzWXVWaXFu?= =?utf-8?B?RzVYU3FtY3ZMdHlHRWZJM05uWm54RkNTUm10T1lJSUxwU2FSOFFCY21LTEVF?= =?utf-8?B?S0pmbGxQVGVFWjdCSit4ZDlyeHAxcTZHcXFFZENYMnJvMEZxQUN1dmxHN0Nv?= =?utf-8?B?L2V5ZHZwdW85NFFmd0NrbWtCVHVIL2drcjVlT1B4d2MrMWxlYzF2dGMycFpN?= =?utf-8?B?NStvVGlUODhnWnFvdTlNZ29POHJQMzRzUFN6TmlwTXc1azhWQXdvcnNPN3Av?= =?utf-8?B?Zk9rc1UvSzJ1dVBURXZzZkhZaENhRXA2elFjMDlKcXBWcG81ekZVWXVGcEU1?= =?utf-8?B?WHhvS2JxcTErWGJxR0lvSFVhT3M2d2RXZnhsTnhvOGg0YVpkQ1ZMU3JLZ1gv?= =?utf-8?B?T1E9PQ==?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: cdde49e3-1b29-49de-f168-08dac175bdc9 X-MS-Exchange-CrossTenant-AuthSource: BLAPR10MB4835.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Nov 2022 10:41:06.7996 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Y3AHUm71e0UggOx6bD0Lef429n7chO5Gpc2jZ1oiisNo+Zy5qTuOrGvjUYg2eWdAcxKW16KoYWssxYwmRYz33Soc51Qbzoxf0R/Yapdlw3o= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLAPR10MB4948 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-11-07_11,2022-11-08_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 mlxscore=0 spamscore=0 bulkscore=0 suspectscore=0 adultscore=0 malwarescore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2211080058 X-Proofpoint-GUID: sBfhtFNFqJ7dbGvKlYLrnlDx8AIOkDu1 X-Proofpoint-ORIG-GUID: sBfhtFNFqJ7dbGvKlYLrnlDx8AIOkDu1 ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1667904071; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=MzGMtyL4iDPhLZoPwteELORapkkk8jFmE+OeMNKhMSo=; b=a+Y3Y4/BFifJH+Sw4k24Em0klcKHNiHhG9ZxByCHLmLSXOWezKH6hIJ32559Pv7n4KHI2T 8L1J7MUTtDF+AH5eEOg7NkBNliHLaPThOYgFYgkKSNJ1FBb2oSp/NK57FvfrpVHFcQefBV pbfQK8biaYTxjISVDq+2Ij25Lq4WQ6I= ARC-Authentication-Results: i=2; imf18.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2022-7-12 header.b=dXPsD+FI; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=NlzvPZ+m; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf18.hostedemail.com: domain of joao.m.martins@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=joao.m.martins@oracle.com; dmarc=pass (policy=none) header.from=oracle.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1667904071; a=rsa-sha256; cv=pass; b=fBM6vD8szpp7nXtWrf+yuogONgpeWXjJ5vFQ++ZZVv5IYjB+cAr9jYcxBFutPqJ6/RhbCG Y/oRRugAZYt22vAjRWFMp7/DSgCdzXcddpgMVzEvI/D2VXZPcS1jxZ0vfUlgFtQLF5ZEMT FBtIJ3sv+TXTP/+x9XphDvU27Ha4iGU= X-Rspam-User: X-Stat-Signature: rgsr5aqkrroy9pxw8mjtu1wibupoy5c1 X-Rspamd-Queue-Id: A34111C0006 Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2022-7-12 header.b=dXPsD+FI; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=NlzvPZ+m; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf18.hostedemail.com: domain of joao.m.martins@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=joao.m.martins@oracle.com; dmarc=pass (policy=none) header.from=oracle.com X-Rspamd-Server: rspam07 X-HE-Tag: 1667904071-150936 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 08/11/2022 09:13, Muchun Song wrote: >> On Nov 7, 2022, at 23:39, Joao Martins wrote: >> >> Today with `hugetlb_free_vmemmap=on` the struct page memory that is freed >> back to page allocator is as following: for a 2M hugetlb page it will reuse >> the first 4K vmemmap page to remap the remaining 7 vmemmap pages, and for a >> 1G hugetlb it will remap the remaining 4095 vmemmap pages. Essentially, >> that means that it breaks the first 4K of a potentially contiguous chunk of >> memory of 32K (for 2M hugetlb pages) or 16M (for 1G hugetlb pages). For >> this reason the memory that it's free back to page allocator cannot be used >> for hugetlb to allocate huge pages of the same size, but rather only of a >> smaller huge page size: >> >> Trying to assign a 64G node to hugetlb (on a 128G 2node guest, each node >> having 64G): >> >> * Before allocation: >> Free pages count per migrate type at order 0 1 2 3 >> 4 5 6 7 8 9 10 >> ... >> Node 0, zone Normal, type Movable 340 100 32 15 >> 1 2 0 0 0 1 15558 >> >> $ echo 32768 > /sys/devices/system/node/node0/hugepages/hugepages-2048kB/nr_hugepages >> $ cat /sys/devices/system/node/node0/hugepages/hugepages-2048kB/nr_hugepages >> 31987 >> >> * After: >> >> Node 0, zone Normal, type Movable 30893 32006 31515 7 >> 0 0 0 0 0 0 0 >> >> Notice how the memory freed back are put back into 4K / 8K / 16K page >> pools. And it allocates a total of 31974 pages (63948M). >> >> To fix this behaviour rather than remapping one page (thus breaking the >> contiguous block of memory backing the struct pages) repopulate with a new >> page for the head vmemmap page. It will copying the data from the currently >> mapped vmemmap page, and then remap it to this new page. Additionally, >> change the remap_pte callback to look at the newly added walk::head_page >> which needs to be mapped as r/w compared to the tail page vmemmap reuse >> that uses r/o. >> >> The new head page is allocated by the caller of vmemmap_remap_free() given >> that on restore it should still be using the same code path as before. Note >> that, because right now one hugepage is remapped at a time, thus only one >> free 4K page at a time is needed to remap the head page. Should it fail to >> allocate said new page, it reuses the one that's already mapped just like >> before. As a result, for every 64G of contiguous hugepages it can give back >> 1G more of contiguous memory per 64G, while needing in total 128M new 4K >> pages (for 2M hugetlb) or 256k (for 1G hugetlb). >> >> After the changes, try to assign a 64G node to hugetlb (on a 128G 2node >> guest, each node with 64G): >> >> * Before allocation >> Free pages count per migrate type at order 0 1 2 3 >> 4 5 6 7 8 9 10 >> ... >> Node 0, zone Normal, type Movable 1 1 1 0 >> 0 1 0 0 1 1 15564 >> >> $ echo 32768 > /sys/devices/system/node/node0/hugepages/hugepages-2048kB/nr_hugepages >> $ cat /sys/devices/system/node/node0/hugepages/hugepages-2048kB/nr_hugepages >> 32394 >> >> * After: >> >> Node 0, zone Normal, type Movable 0 50 97 108 >> 96 81 70 46 18 0 0 > > Thanks for your work. > Thanks for the comments! >> >> >> In the example above, 407 more hugeltb 2M pages are allocated i.e. 814M out >> of the 32394 (64796M) allocated. So the memory freed back is indeed being >> used back in hugetlb and there's no massive order-0..order-2 pages >> accumulated unused. >> >> Signed-off-by: Joao Martins >> --- >> Changes since v1[0]: >> * Drop rw argument and check walk::head_page directly when there's >> no reuse_page set (similar suggestion by Muchun Song to adjust >> inside the remap_pte callback) >> * Adjust TLB flush to cover the head page vaddr too (Muchun Song) >> * Simplify the remap of head page in vmemmap_pte_range() >> * Check start is aligned to PAGE_SIZE in vmemmap_remap_free() >> >> I've kept the same structure as in v1 compared to a chunk Muchun >> pasted in the v1 thread[1] and thus I am not altering the calling >> convention of vmemmap_remap_free()/vmemmap_restore_pte(). >> The remapping of head page is not exactly a page that is reused, >> compared to the r/o tail vmemmap pages remapping. So tiny semantic change, >> albeit same outcome in pratice of changing the PTE and freeing the page, >> with different permissions. It also made it simpler to gracefully fail >> in case of page allocation failure, and logic simpler to follow IMHO. >> >> Let me know otherwise if I followed the wrong thinking. >> >> [0] https://lore.kernel.org/linux-mm/20220802180309.19340-1-joao.m.martins@oracle.com/ >> [1] https://lore.kernel.org/linux-mm/Yun1bJsnK%2F6MFc0b@FVFYT0MHHV2J/ >> >> --- >> mm/hugetlb_vmemmap.c | 59 ++++++++++++++++++++++++++++++++++++++------ >> 1 file changed, 52 insertions(+), 7 deletions(-) >> >> diff --git a/mm/hugetlb_vmemmap.c b/mm/hugetlb_vmemmap.c >> index 7898c2c75e35..4298c44578e3 100644 >> --- a/mm/hugetlb_vmemmap.c >> +++ b/mm/hugetlb_vmemmap.c >> @@ -22,6 +22,7 @@ >> * >> * @remap_pte: called for each lowest-level entry (PTE). >> * @nr_walked: the number of walked pte. >> + * @head_page: the page which replaces the head vmemmap page. >> * @reuse_page: the page which is reused for the tail vmemmap pages. >> * @reuse_addr: the virtual address of the @reuse_page page. >> * @vmemmap_pages: the list head of the vmemmap pages that can be freed >> @@ -31,6 +32,7 @@ struct vmemmap_remap_walk { >> void (*remap_pte)(pte_t *pte, unsigned long addr, >> struct vmemmap_remap_walk *walk); >> unsigned long nr_walked; >> + struct page *head_page; > > This field is unnecessary. We can reuse ->reuse_page to implement the same > functionality. I'll explain the reason later. > OK, I'll comment below >> struct page *reuse_page; >> unsigned long reuse_addr; >> struct list_head *vmemmap_pages; >> @@ -105,10 +107,26 @@ static void vmemmap_pte_range(pmd_t *pmd, unsigned long addr, >> * remapping (which is calling @walk->remap_pte). >> */ >> if (!walk->reuse_page) { >> - walk->reuse_page = pte_page(*pte); >> + struct page *page = pte_page(*pte); >> + >> + /* >> + * Copy the data from the original head, and remap to >> + * the newly allocated page. >> + */ >> + if (walk->head_page) { >> + memcpy(page_address(walk->head_page), >> + page_address(page), PAGE_SIZE); >> + walk->remap_pte(pte, addr, walk); >> + page = walk->head_page; >> + } >> + >> + walk->reuse_page = page; >> + >> /* >> - * Because the reuse address is part of the range that we are >> - * walking, skip the reuse address range. >> + * Because the reuse address is part of the range that >> + * we are walking or the head page was remapped to a >> + * new page, skip the reuse address range. >> + * . >> */ >> addr += PAGE_SIZE; >> pte++; >> @@ -204,11 +222,11 @@ static int vmemmap_remap_range(unsigned long start, unsigned long end, >> } while (pgd++, addr = next, addr != end); >> >> /* >> - * We only change the mapping of the vmemmap virtual address range >> - * [@start + PAGE_SIZE, end), so we only need to flush the TLB which >> + * We change the mapping of the vmemmap virtual address range >> + * [@start, end], so we only need to flush the TLB which >> * belongs to the range. >> */ > > This comment could go away, the reason I added it here is because it is a bit special > here. I want to tell others why we don't flush the full range from @start to @end. Now, I > think it can go away. > OK >> - flush_tlb_kernel_range(start + PAGE_SIZE, end); >> + flush_tlb_kernel_range(start, end); >> >> return 0; >> } >> @@ -244,9 +262,21 @@ static void vmemmap_remap_pte(pte_t *pte, unsigned long addr, >> * to the tail pages. >> */ >> pgprot_t pgprot = PAGE_KERNEL_RO; >> - pte_t entry = mk_pte(walk->reuse_page, pgprot); >> + struct page *reuse = walk->reuse_page; >> struct page *page = pte_page(*pte); >> + pte_t entry; >> >> + /* >> + * When there's no walk::reuse_page, it means we allocated a new head >> + * page (stored in walk::head_page) and copied from the old head page. >> + * In that case use the walk::head_page as the page to remap. >> + */ >> + if (!reuse) { >> + pgprot = PAGE_KERNEL; >> + reuse = walk->head_page; >> + } >> + >> + entry = mk_pte(reuse, pgprot); >> list_add_tail(&page->lru, walk->vmemmap_pages); >> set_pte_at(&init_mm, addr, pte, entry); >> } >> @@ -315,6 +345,21 @@ static int vmemmap_remap_free(unsigned long start, unsigned long end, >> .reuse_addr = reuse, >> .vmemmap_pages = &vmemmap_pages, >> }; >> + gfp_t gfp_mask = GFP_KERNEL|__GFP_RETRY_MAYFAIL|__GFP_NOWARN; > > It is better to add __GFP_THISNODE here for performance. And replace > __GFP_RETRY_MAYFAIL to __GFP_NORETRY to keep consistent with > hugetlb_vmemmap_restore(). > OK >> + int nid = page_to_nid((struct page *)start); >> + struct page *page = NULL; >> + >> + /* >> + * Allocate a new head vmemmap page to avoid breaking a contiguous >> + * block of struct page memory when freeing it back to page allocator >> + * in free_vmemmap_page_list(). This will allow the likely contiguous >> + * struct page backing memory to be kept contiguous and allowing for >> + * more allocations of hugepages. Fallback to the currently >> + * mapped head page in case should it fail to allocate. >> + */ >> + if (IS_ALIGNED((unsigned long)start, PAGE_SIZE)) > > I'm curious why we need this check. IIUC, this is unnecessary. > So if the start of the vmemmap range (the head page) we will remap isn't the first struct page, then we would corrupt the other struct pages in that vmemmap page unrelated to hugetlb? That was my thinking >> + page = alloc_pages_node(nid, gfp_mask, 0); >> + walk.head_page = page; >> >> /* >> * In order to make remapping routine most efficient for the huge pages, >> -- >> 2.17.2 >> > > I have implemented a version based on yours, which does not introduce > ->head_page field (Not test if it works). Seems to be simple. > Let me try out with the adjustment below > Thanks. > > diff --git a/mm/hugetlb_vmemmap.c b/mm/hugetlb_vmemmap.c > index c98805d5b815..8ee94f6a6697 100644 > --- a/mm/hugetlb_vmemmap.c > +++ b/mm/hugetlb_vmemmap.c > @@ -202,12 +202,7 @@ static int vmemmap_remap_range(unsigned long start, unsigned long end, > return ret; > } while (pgd++, addr = next, addr != end); > > - /* > - * We only change the mapping of the vmemmap virtual address range > - * [@start + PAGE_SIZE, end), so we only need to flush the TLB which > - * belongs to the range. > - */ > - flush_tlb_kernel_range(start + PAGE_SIZE, end); > + flush_tlb_kernel_range(start, end); > > return 0; > } > @@ -246,6 +241,12 @@ static void vmemmap_remap_pte(pte_t *pte, unsigned long addr, > pte_t entry = mk_pte(walk->reuse_page, pgprot); > struct page *page = pte_page(*pte); > > + /* The case of remapping the head vmemmap page. */ > + if (unlikely(addr == walk->reuse_addr)) { You replace the head_page with checking the reuse_addr , but that is set on the tail page. So if we want to rely on reuse_addr perhaps best if do: if (unlikely(addr == (walk->reuse_addr - PAGE_SIZE))) { ... } > + list_del(&walk->reuse_page->lru); > + entry = mk_pte(walk->reuse_page, PAGE_KERNEL); > + } > + > list_add_tail(&page->lru, walk->vmemmap_pages); > set_pte_at(&init_mm, addr, pte, entry); > } > @@ -310,6 +311,8 @@ static int vmemmap_remap_free(unsigned long start, unsigned long end, > .reuse_addr = reuse, > .vmemmap_pages = &vmemmap_pages, > }; > + int nid = page_to_nid((struct page *)start); > + gfp_t gfp_mask = GFP_KERNEL | __GFP_THISNODE | __GFP_NORETRY | __GFP_NOWARN; > > /* > * In order to make remapping routine most efficient for the huge pages, > @@ -326,6 +329,20 @@ static int vmemmap_remap_free(unsigned long start, unsigned long end, > */ > BUG_ON(start - reuse != PAGE_SIZE); > > + /* > + * Allocate a new head vmemmap page to avoid breaking a contiguous > + * block of struct page memory when freeing it back to page allocator > + * in free_vmemmap_page_list(). This will allow the likely contiguous > + * struct page backing memory to be kept contiguous and allowing for > + * more allocations of hugepages. Fallback to the currently > + * mapped head page in case should it fail to allocate. > + */ > + walk.reuse_page = alloc_pages_node(nid, gfp_mask, 0); > + if (walk.reuse_page) { > + copy_page(page_to_virt(walk.reuse_page), walk.reuse_addr); > + list_add(&walk.reuse_page->lru, &vmemmap_pages); > + } > + > mmap_read_lock(&init_mm); > ret = vmemmap_remap_range(reuse, end, &walk); > if (ret && walk.nr_walked) { >