From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2086.outbound.protection.outlook.com [40.107.223.86]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4EFA8AD2D for ; Mon, 30 Dec 2024 16:36:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.223.86 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735576586; cv=fail; b=GliJWrF7T+JPavAB4o16hjmbzEQAAWQw+7Dn/DhZvbljMdIbs6l7KhkojPbmG7SzDM2stfIAYJIlqfX5LuL8omNPMYfixDDGg6Isig6ZVTQg4VryHfRHEbZw9eSxbELxHGcbI2ii+RdQ6dIyU6xl0Byx92j9cBUleUhw1xDZrNk= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735576586; c=relaxed/simple; bh=SrdaiYLQEYxcPlOM3HQKVXuhI6prOzoI84bjcq2WTMM=; h=Content-Type:Date:Message-Id:Cc:To:From:Subject:References: In-Reply-To:MIME-Version; b=m0Sg8Yv61EepdDOUlemBFO/fIngxY7yWaNF3euz4FIdtxa7ybdwHzUgspgPjtxk58G3eQy+CMh341CvUBzhE4Ism/ROGAEJcdlPoTyBKtycYh/VMcX3dTsIMscXuFUYFU1WOFBnHPa49oi8Bg/hIzXdrz7HE521L7msjksmyu9w= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=eRncffrz; arc=fail smtp.client-ip=40.107.223.86 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="eRncffrz" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=CttxTHGhPve0ewqyqPK0ucduC8iAyeTOscuwQZVwJJtYtXVjGIKhJqVODskmo27htBSTsrxNrKsxac00xFwUdiuB5dsr/yJbDBKh+uIWouH2waE3N6dJHlSxtkKFtUATvScaK0lKti3vBGRRoqLyfNIB9M0ni4QeFXQf4dGu3GMd97Zxik7dTlgvNV7MtGR59uVEs2NrKLABUBJ3Z7kD+vwIV4T3HVEef6NrQjcM8Ev9PiSPs1WwPM1ZszjMtwkmgQhBEhy4I6JJtzusjf7neD4+IQltpq1bDud3JPmND4wvXcd0F59+MvlAsBWTb9vnRpSJ5XuecAbDK5TAJuGmzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=SrdaiYLQEYxcPlOM3HQKVXuhI6prOzoI84bjcq2WTMM=; b=b947ftEKtb/sDl0VvVjDttnClYrwAGzKp+adD0EggcNFabjhqpL+LDB2V7MmCrMvzg/or9uiXi7k4uxn0c1FdgY8AneZFdJ8mSFSn1EsjGAqrYh5cXuR0GeVTC+gar/uDI+jfflKr6SGlh34N7B6Y+c4UO0ZXUcWWuDCQQkuQK+8G5PK8uaZWYh9luYRJtNHCy/c4BOfr9ESe7ozJYvSiWmD2rhrMmuNC8laYVyaI/ih2RJjQUiK3xXhbUpgCJ/ymvfaAq5bEnQNHpojcmnB3pUb1FwUM3qkQz9BKwnu3IW2DdGRhPDY1qJCTZWNICX0GvG/zBNzKUcsXMaVBNJNrw== 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=SrdaiYLQEYxcPlOM3HQKVXuhI6prOzoI84bjcq2WTMM=; b=eRncffrzgrumaPJMuitevjSCRYYMfWBP2VWAT6SK+Jphe1vH+ZUXIbxM8DIbRyMht6BppzOhBRwInIPk7A0Dh2yUPPl8VGrntePOVt3h2poFgag/3zjVlOBLq945aj0utK3uE6GVX8HpfxLctuGdi+APSH4Nw+UnXWlMMO8LkcFSpMHBV6BLGxgapP2DKklF9i8zteY8VP5YivkjsL9yoALf2ii/5C5xhSRSlFAcEcNe0sgVyrJaYlcR9UowO8h+frKFdJsfdcn3ncM1WFhRK84pvhFXOLya4WWiM9uc77q+gBEnV1Py/nfKMEV+NCPXELp5GTxOsx2gZg8vYdTlhg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) by CY8PR12MB7539.namprd12.prod.outlook.com (2603:10b6:930:96::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8293.17; Mon, 30 Dec 2024 16:36:16 +0000 Received: from DS7PR12MB9473.namprd12.prod.outlook.com ([fe80::5189:ecec:d84a:133a]) by DS7PR12MB9473.namprd12.prod.outlook.com ([fe80::5189:ecec:d84a:133a%3]) with mapi id 15.20.8293.000; Mon, 30 Dec 2024 16:36:16 +0000 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Mon, 30 Dec 2024 11:36:06 -0500 Message-Id: Cc: , , , , , , , , , , , , , , , , , , , , , , , , <21cnbao@gmail.com>, , To: "Dev Jain" , "Ryan Roberts" , , , , From: "Zi Yan" Subject: Re: [RFC PATCH 12/12] selftests/mm: khugepaged: Enlighten for mTHP collapse X-Mailer: aerc 0.18.2 References: <20241216165105.56185-1-dev.jain@arm.com> <20241216165105.56185-13-dev.jain@arm.com> <7098654a-776d-413b-8aca-28f811620df7@arm.com> <07b40938-029b-42ef-a273-46b504e67eda@arm.com> <350a4f5b-c4f1-43cc-ad93-ba02c454f19c@arm.com> In-Reply-To: <350a4f5b-c4f1-43cc-ad93-ba02c454f19c@arm.com> X-ClientProxiedBy: MN0P221CA0014.NAMP221.PROD.OUTLOOK.COM (2603:10b6:208:52a::34) To DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS7PR12MB9473:EE_|CY8PR12MB7539:EE_ X-MS-Office365-Filtering-Correlation-Id: d8e691b7-8e03-4b1c-2a24-08dd28f014fd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|1800799024|366016; X-Microsoft-Antispam-Message-Info: =?utf-8?B?OWtWWUdsRHVYOW9rT3FCbkl6NnRlSnhma1p3QkRXMWJYWTN6UWpHWXVOQ21F?= =?utf-8?B?NjcxSHptak5OWG5YWkoweDgzRG5PZlZGRm9nUXZDdENVbmllc0xpbERUeERw?= =?utf-8?B?TzlCWHkxN3Rsd2RXVDVKSkRJRVRRcnVzL3pXZWJDcFlmUkZYeDhLS0ttNUZP?= =?utf-8?B?M0ZHVU5hVmZPWjU4QWxnSnRkTDlsTFAralc1eWhnM1I5TVhUemFFZFlLaHdn?= =?utf-8?B?UlNSTGR4WmZ5aVZoVHFkcHVoa1RYcTJodWVvMlJCajVNRTZBd0Y5cytnbWFE?= =?utf-8?B?SEEzY25sdldhUWFVYzFtai9KM0V2TnI0M3pWb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zWGFrVDJVS0N0WXZGU2NtS2Z3NUc2ZlpXVUdibnhrRmtFQjlEVlhpUlAx?= =?utf-8?B?bGl5amhJeVZ5UTloN1R3clhrYmtZbVQwMUpxclRSdHFDeTUxR2p5STdFdjhV?= =?utf-8?B?OU5ScUU5T1hVaWJXcXRTcWtqdktiUjRBYVhhWThYSXBPc1JoR2ZDTTBVU2R0?= =?utf-8?B?Q0dBcTRMeE53ZFM2VGV0SStDajNZSExMVytjZ2V0WXI1WnErSTE2TVhKVGJX?= =?utf-8?B?UjZqU0lPRE50QjkzNzRLcmZCOHFKSXc5NHBYY01jTGY2MDZZN05zMDFTdDUr?= =?utf-8?B?dUVyVXlUSWVTcmFMQlpqRENrT1FjSXl4eE5CWDFyMVEzamFmTElmdkxuY3R1?= =?utf-8?B?ampVQnVsWWUrT0xPM1lFaWIxbjh1WmliQ1RXVzg4ZytCc0VwZ210eTE2YU9K?= =?utf-8?B?d3lVWjI0Ym5EV0VuQk9JMEh5aGdZSG5lSitDK3JRcG14a3dLTDlwd3dQR1NZ?= =?utf-8?B?TmU3S2tLaFp4WUN5Y2NPcXB5NXhxQlk1dHYwMzJiVFFQa3Z0RFpRTWEzWm9F?= =?utf-8?B?RjRsOXFFekI2YVhrbTF0T3BPWmRVRTZoalk1WngwamFLOTVwS0JPMUc3dVdz?= =?utf-8?B?aDV0VnZ4aFFHSjRlZnI4V2VNZDV3dWRiV2RLZDJDaTVVNkR2SkhkaytjY0NL?= =?utf-8?Q?MAZdyUg1atUZd?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS7PR12MB9473.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(7416014)(376014)(1800799024)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?bHVVbGJSK3phZUdHMlZGZGdIVXRnb3hQMl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4?= =?utf-8?B?RVJ6bWd1cVRxeEpJa0hDVkZXM2VLNHlZbVB1QWVRN3J1bWJwNnBWTCtxeWM5?= =?utf-8?B?TFY0WTlWalpsM3p5OWsvQ1h3azNGUEJhdndESnNQdFlVcG5ML1diWnhqQWpU?= =?utf-8?B?UXd3ZXZ2aXNoWmNVcnFEeTF5cHA5MGVSRVUwTDBhKzJiRUJFeWxQOEJkNFBj?= =?utf-8?B?WkxaTTZSVXlvSm1SY2pRYkdqdUZGNnF5eEFKR1I2TEZic3FBZ3pGcGd3UHd5?= =?utf-8?B?QUZZV1R0d0s1NnEzeFQ4TGhrRHcxZjljY3ZsdTRPR25RQUxqditCOFRHbzhp?= =?utf-8?Q?V7+Y=3D?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: d8e691b7-8e03-4b1c-2a24-08dd28f014fd X-MS-Exchange-CrossTenant-AuthSource: DS7PR12MB9473.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Dec 2024 16:36:16.7162 (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: 2iUKE+p1Hvw5Cc4blQ5aRU69Tv9zyTtQRisvBN0GT7YkNIwYEvOO6j4Rnh1nVH9i X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB7539 On Mon Dec 30, 2024 at 2:09 AM EST, Dev Jain wrote: > > On 20/12/24 4:35 pm, Ryan Roberts wrote: > > On 18/12/2024 09:50, Dev Jain wrote: > >> On 18/12/24 2:33 pm, Ryan Roberts wrote: > >>> On 16/12/2024 16:51, Dev Jain wrote: > >>>> One of the testcases triggers a CoW on the 255th page (0-indexing) w= ith > >>>> max_ptes_shared =3D 256. This leads to 0-254 pages (255 in number) b= eing unshared, > >>>> and 257 pages shared, exceeding the constraint. Suppose we run the t= est as > >>>> ./khugepaged -s 2. Therefore, khugepaged starts collapsing the range= to order-2 > >>>> folios, since PMD-collapse will fail due to the constraint. > >>>> When the scan reaches 254-257 PTE range, because at least one PTE in= this range > >>>> is writable, with other 3 being read-only, khugepaged collapses this= into an > >>>> order-2 mTHP, resulting in 3 extra PTEs getting unshared. After this= , we > >>>> encounter > >>>> a 4-sized chunk of read-only PTEs, and mTHP collapse stops according= to the > >>>> scaled > >>>> constraint, but the number of shared PTEs have now come under the co= nstraint for > >>>> PMD-sized THPs. Therefore, the next scan of khugepaged will be able = to collapse > >>>> this range into a PMD-mapped hugepage, leading to failure of this su= btest. Fix > >>>> this by reducing the CoW range. > >>> Is this description essentially saying that it's now possible to cree= p towards > >>> collapsing to a full PMD-size block over successive scans due to roun= ding errors > >>> in the scaling? Or is this just trying an edge case and the problem d= oesn't > >>> generalize? > >> For this case, max_ptes_shared for order-2 is 256 >> (9 - 2) =3D 2, wi= thout > >> rounding errors. We cannot > >> really get a rounding problem because we are rounding down, essentiall= y either > >> keep the restriction > >> same, or making it stricter, as we go down the orders. > >> > >> But thinking again, this behaviour may generalize: essentially, let us= say that > >> the distribution > >> of none ptes vs filled ptes is very skewed for the PMD case. In a loca= l region, > >> this distribution > >> may not be skewed, and then an mTHP collapse will occur, making this e= ntire > >> region uniform. Over time this > >> may keep happening and then the region will become globally uniform to= come > >> under the PMD-constraint > >> on max_ptes_none, and eventually PMD-collapse will occur. Which may be= g the > >> question whether we want > >> to detach khugepaged orders from mTHP sysfs settings. > > We want to avoid new user controls at all costs, I think. > > > > I think an example of the problem you are describing is: Let's say we s= tart off > > with all mTHP orders enabled and max_ptes_none is 50% (so 256). We have= a 2M VMA > > aligned over a single PMD. The first 2 4K pages of the VMA are allocate= d. > > > > khugepaged will scan this VMA and decide to collapse the first 4 PTEs t= o a > > single order-2 (16K) folio; that's allowed because 50% of the PTEs were= none. > > But now on the next scan, 50% of the first 8 PTEs are none so it will c= ollapse > > to 32K. Then on the next scan it will collapse to 64K, and so on all th= e way to > > 2M. So by faulting in 2 pages originally we have now collapsed to 2M di= spite the > > control trying to prevent it, and we have done it in a very inefficient= way. > > > > If max_ptes_none was 75% you would only need every other order enabled = (I think?). > > > > In practice perhaps it's not a problem because you are only likely to h= ave 1 or > > 2 mTHP sizes enabled. But I wonder if we need to think about how to pro= tect from > > this "creep"? > > > > Perhaps only consider a large folio for collapse into a larger folio if= it > > wasn't originally collapsed by khugepaged in the first place? That woul= d need a > > folio flag... and I suspect that will cause other edge case issues if w= e think > > about it for 5 mins... > > > > Another way of thinking about it is; if all the same mTHP orders were e= nabled at > > fault time (and the allocation suceeded) we would have allocated the la= rgest > > order anyway, so the end states are the same. But the large number of > > incremental collapses that khugepaged will perform feel like a problem. > > > > I'm not quite sure what the answer is. > > Can't really think of anything else apart from decoupling khugepaged sysf= s from mTHP sysfs... One (not so effective) workaround is to add a VMA flag to make khugepaged to skip scanning a VMA that khugepaged has collapsed before and reset the flag in a future page fault. This would prevent khugepaged from doing this "creep" collapse behavior until the page tables covered by the VMA is changed. This is not perfect, since the page faults might not change the aforementioned region and later khugepaged can still perform the "creep". --=20 Best Regards, Yan, Zi