From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from BL2PR02CU003.outbound.protection.outlook.com (mail-eastusazon11011027.outbound.protection.outlook.com [52.101.52.27]) (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 E93A339283C for ; Wed, 22 Apr 2026 03:27:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.52.27 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776828439; cv=fail; b=Y3BnxGfvd3KZ2nHzGLanQkAp5XCXJg36Lfg3Fo3wNXU4SOl4qb9hLsbw+2refaTKzFwLSJLsB4e/5xNuv159EC8ibB2bRhiyU0BXHPRQxM7w3s7aVzzmGKkIDPNoPApN/F1ypK3MYrRh8oBa36H+/qE45OBzg+7+FqI7NHfJToA= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776828439; c=relaxed/simple; bh=XgnaUUsXaFiJwtG6t97CXTd982EKnBaDLsG5VkNWP88=; h=Message-ID:Date:MIME-Version:Subject:To:CC:References:From: In-Reply-To:Content-Type; b=oTZxfQFMcchc97ksDy/BPV8hlx4+CeMI26QBGKtiO5sa8PfhRMAAD6+1rP/q07G1pOYVKz3A0B2Q/OOb/CbRT/I7Cii4MXKKdk2FmaxFMPB1G+p09TrSq3ec1bu2w+kwuCO80lj3zZcr6vzXKsEtLHcncu4ngmOVVGftHjwUzHk= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=bx4s9f5z; arc=fail smtp.client-ip=52.101.52.27 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="bx4s9f5z" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=WLYI06uSZmTviDILwj/LI7d4W6gY2GG0NN1UwlXZD+j4GJpXdn2Arr+1FVNzf8esL+mwMifP9J0fG9I+bfXYvvPNejnWCPjMOGUExE+6CGqu6ZnOJm2PdfcU0ipxJ02N3YSoMMdwxV7MS44qB/eljRuug13l4fPCpq4cEUSLlECZxFlCE48FEp1MmcVhj1gpZtQuk9RGgoGMcG5umdo4OEexeq4nFAmPk4b/0DiBiC1jUGyadxIaxvsX4+TNHLbDaqqwnQHJcWxvsvcAe6YYhglpGXJJ33oBVW17bV1i2RFgGwbalNbfe0r2wrlU+/EwYoBplDBRHQOsxkSiV6hQww== 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=cGuw0qKrR6NId16vPHAs4eDAPBIuuGDuK4dVXJGJvYg=; b=LNTVIi/0Il6zmgGZNoxeyYBSb3wBaIF65vWbKyBQa45hd2VkqzK129gcEh4tWuSpTkxbkWiDjtiLTVTqGIwF2aaMhpweqzi4OzB7ig7KQtwQvm+3tkRvdF5grGS7BZd0ZQdAFPfB27Y1NQEG3VfAGBUZG/Nuh6b6ULC8+rOKDE4wNsHOWDznCJbbVMi8KCqA4xs1vK5dPZZ6vV/+UQn6RmSMn+gdLMGgLmRyti/fqNZ7hSoH/dLunHMaTunzQXWTkm09gQzrAIIuyCU/CuVA7aYSPXgIeelmjmsNmBILj960nt+Zi8sGHEpt40RXU0gz9z8rH7LnXXZA0cZGj2ITRw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=gourry.net smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=cGuw0qKrR6NId16vPHAs4eDAPBIuuGDuK4dVXJGJvYg=; b=bx4s9f5zbC2RvaG1qzd4A2bvGTBQmq3pX2VtKyUK51wcRjndwGopNZZ1YrmEePFiI0BmOMlVgNnxcZkAWaG0Whvhs/PM/E9darTKIThLLv5Dx7ZPJPIkU2dniNeF6HhFRfWeRdsKn1zf5gzoKMd3n/nuiDlDjV3c7PlpxhD2Rq0= Received: from CH2PR11CA0022.namprd11.prod.outlook.com (2603:10b6:610:54::32) by DM6PR12MB4073.namprd12.prod.outlook.com (2603:10b6:5:217::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9846.12; Wed, 22 Apr 2026 03:27:12 +0000 Received: from CH2PEPF00000149.namprd02.prod.outlook.com (2603:10b6:610:54:cafe::5c) by CH2PR11CA0022.outlook.office365.com (2603:10b6:610:54::32) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9791.48 via Frontend Transport; Wed, 22 Apr 2026 03:27:12 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by CH2PEPF00000149.mail.protection.outlook.com (10.167.244.106) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9846.18 via Frontend Transport; Wed, 22 Apr 2026 03:27:12 +0000 Received: from SATLEXMB03.amd.com (10.181.40.144) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.2562.17; Tue, 21 Apr 2026 22:27:07 -0500 Received: from satlexmb08.amd.com (10.181.42.217) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Tue, 21 Apr 2026 22:27:07 -0500 Received: from [10.252.223.214] (10.180.168.240) by satlexmb08.amd.com (10.181.42.217) with Microsoft SMTP Server id 15.2.2562.17 via Frontend Transport; Tue, 21 Apr 2026 22:27:00 -0500 Message-ID: Date: Wed, 22 Apr 2026 08:56:59 +0530 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC PATCH v6 2/5] mm: migrate: Add migrate_misplaced_folios_batch() To: Gregory Price , Donet Tom CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , References: <20260323095104.238982-1-bharata@amd.com> <20260323095104.238982-3-bharata@amd.com> <24cd6a95-1304-4732-9273-43c73ea858b2@linux.ibm.com> Content-Language: en-US From: Bharata B Rao In-Reply-To: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit Received-SPF: None (SATLEXMB03.amd.com: bharata@amd.com does not designate permitted sender hosts) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PEPF00000149:EE_|DM6PR12MB4073:EE_ X-MS-Office365-Filtering-Correlation-Id: 9b26db1f-89f2-4445-86e5-08dea01f0af4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|36860700016|376014|7416014|82310400026|18002099003|22082099003|56012099003; X-Microsoft-Antispam-Message-Info: +UezyyWpQpS35qRIlpli0zeahKh2dLfV62lpZeM1UhcEyCnL4KdYs9yBRIKb499ukkUMbbHs7CbfYNkFiU34NDhgs4I9hvPSREqL5AziwCF0aZOgIIfGnFGEYoEPhbj2JTjQ3DezMqbbg9nM65xy3eNFQqtyazyPM/EwykDMDjTBoNInguCWoZgGFOFJj9D5FWrkE4Rm62gotBNe9gEp1Dp94U0Gnkv7eodr8cuso3iMRWM6wO+PnLnXtV0MmdmVsnT2UsAOvMVCN6KzQpeYTfb4R2E3BUKtskyWU6/yQnrFXw9lyOjGUY7ZxigFLEH72OuTtbCSFb1FOfpNI4ukbik0pJuFbB5m9wwBA136Ki8H/7PWJmwgdoEWGEpMUTGG3wf/27Evxg54yKCUTEQoRATdctiF5zO3aq5VG3Kgkh182c8v/zYZQhn+0hTgIBpDRdO6CIKRhxyEYrGhbpFRlqwNo9qushxWEUwJA6j1tJHED5bySRNUOpCZFSeqlUKmFBHmRED7Z4N7dxqzLH+4w63ZIQm6R8il2mc8Tjge/pcAf/5uS2mA65VhA/8Agzu/3ZZxtlsmECxDfc9EIpfBtbMwMhR+pGG7Yyomg1YoSARFLB+wnZxMcMWQDK9jW5ySZ2Q+NlPf3oPQBKZHxY876xS5Fu2jJSBLLWHXTQtxww5fj4tfOkqUbag+2jll+AyeMN4nqHfubb+n146nEKVthN5t495Xcj+kvf41Kpa0B6S/OmFHdJ1gdLn1/p9PIQ30A95Myw1bTtGjCKyVP0Coqw== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(1800799024)(36860700016)(376014)(7416014)(82310400026)(18002099003)(22082099003)(56012099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 2j4o7E8RvJZLhr5nx11w3SEzSc9UQye6VhuUOy9XRedeML3QvLFYuXaxEpX7M5Hs4gfPNWVCi5anUpd4KFKxh1eIMpLWuY+LdLqKcQPlNXMA7O8S7Ki3T0m+J5sOgW717NXeTSTh4tQKC8R/7NMf6uMz8pxp5tFUZ4XBVPAHyrkphdN1/WtWh1ygmWgkzUGoWeFOBWuoHnotBuxcbCAF/gfnp5OQ+sXPOQGj24N01viTcMkFDwJmszg27cRTsiqi9Nr36Tb31O4Sg61tAeG6oniRQBOw3aCHZtuRorZVAekCVVQkWWj27pGvzNXRupTwkHIuoq9MArXcD4LQva1zWd0N/r06vWf2a0SykgNedIdK015G3NoWFNJPuvN2gXjjD/xcXApWRoJALYzh93o71FvI6Vfpz5zHu1WIDDp+UpyNj9B3J7QULIEgdGsII1b9 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Apr 2026 03:27:12.0816 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9b26db1f-89f2-4445-86e5-08dea01f0af4 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CH2PEPF00000149.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4073 On 21-Apr-26 9:35 PM, Gregory Price wrote: > On Tue, Apr 21, 2026 at 08:55:02PM +0530, Donet Tom wrote: >>> +/** >>> + * migrate_misplaced_folios_batch() - Batch variant of migrate_misplaced_folio >>> + * Attempts to migrate a folio list to the specified destination. >>> + * @folio_list: Isolated list of folios to be batch-migrated. >>> + * @node: The NUMA node ID to where the folios should be migrated. >>> + * >>> + * Caller is expected to have isolated the folios by calling >>> + * migrate_misplaced_folio_prepare(), which will result in an >>> + * elevated reference count on the folio. All the isolated folios >>> + * in the list must belong to the same memcg so that NUMA_PAGE_MIGRATE >>> + * stat can be attributed correctly to the memcg. ^ This is the expectation from the caller. pghot caller ensures this. I could add a debug check in this routine to verify if that is indeed so. >>> + * >>> + * This function will un-isolate the folios, drop the elevated reference >>> + * and remove them from the list before returning. This is called >>> + * only for batched promotion of hot pages from lower tier nodes. >>> + * >>> + * Return: 0 on success and -EAGAIN on failure or partial migration. >>> + * On return, @folio_list will be empty regardless of success/failure. >>> + */ >>> +int migrate_misplaced_folios_batch(struct list_head *folio_list, int node) >>> +{ >>> + pg_data_t *pgdat = NODE_DATA(node); >>> + struct mem_cgroup *memcg = NULL; >>> + unsigned int nr_succeeded = 0; >>> + int nr_remaining; >>> + >>> + if (!list_empty(folio_list)) { >>> >> We seem to proceed even when the list is empty. Should we instead return >> early in that case? >> > > Well that seems utterly reasonable, yes you are right. Right. Earlier migrate_pages() may have handled empty source list, but with memcg-awareness in this routine, it is better to return right away. > >>> + struct folio *first = list_first_entry(folio_list, struct folio, lru); >>> + memcg = get_mem_cgroup_from_folio(first); >> >> >> I had a small question—are we ensuring that a single list contains folios >> from the same memcg? >> > > It has been a long while since i originally wrote this commit. > > I believe I originally wrote this I used it in the context of > folio_mark_accessed() driven promotions - trying to get some semblance > of NUMA balancing for unmapped page cache pages. > > These folios got put into a task workqueue that then got processed on > the way out of the kernel. > > I think I made the assumption at the time that the folios would all > belong to the same memcg - I have since learned that this almost > certainly is not the case. > > That means a bulk migration may have to first process the folios into > lists by memcg before migrating them. > > So this commit likely needs to be redone. See above. Regards, Bharata.