From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from CY7PR03CU001.outbound.protection.outlook.com (mail-westcentralusazon11010043.outbound.protection.outlook.com [40.93.198.43]) (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 0664D23ABBE for ; Thu, 30 Jul 2026 06:34:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.93.198.43 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785393292; cv=fail; b=bYfoLVNopBw30eTzIvzGR8V65DLQEwrWxCikIl9BuAxNmS5ICe2RJJ6Ts9kEmIPRAQdM6YYBiZkYkGLFHWGANUJnZW4JXA1OVObHvGJDY08QrPgG7zOIXbSn90Kcv9ok/Uca+22HgaAkZl+FYEHDFiIF8wD5wRMShwtuDKnxIm0= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785393292; c=relaxed/simple; bh=4Vgirs+zQh59Mhf9lm+2HuNOwrRmKcnhPWKMuM29d8A=; h=Message-ID:Date:MIME-Version:Subject:To:CC:References:From: In-Reply-To:Content-Type; b=d/YjDFEQwI6/ZT1azw0LFGfOuIENcTCcAShHwy05x1F5yvpBbUjffhBkNH1R30ZVXIT8gxgUBWAZ1RMoaJKxj8T4ap5kl2bqjP0VMYFew19eJPOLOHCenkhN+1TRFDgLkfgtmKq/05OF28G6/djRcmGHy5WN+5nXb46YEyTGB68= 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=1jBLNkqU; arc=fail smtp.client-ip=40.93.198.43 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="1jBLNkqU" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=cgOahkw7jF6YvP7moj7UEoSYcPb5h9/PwT7S9Oc0e9Ki4kBy3Tpy8+5SLGtLeXesNWCzTTepSabUps2Bm47KCtVEzRUsDd4C5qscNS3czFlYuNwlEudN8FkaZWgXXXybd92EhSRzIJSFfbnj0z+jp2L22LT/HXvrrxy0r1zT/S0wP6KUaM5AAwxeM9r9mZ/Ve1skW7kaEjxXv+eD5XBsbMof71Rdp22UZSspRzJqpVZHdPYPf+0sgRDcsHWpq0GJkciyaP4R4hTHBmG+o6hFkptlhEtwKuXCeD5q5oBnXI7bTHUQ9UHYO7T2ucCpzZ9vbjXiTpFaFksiuFXiqEAa+w== 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=bglS7oomxZfgdvHoNj18LEuXieYUwHYBmfu7vu8Wias=; b=LH+4mmzVp+6ehukfh/GQMYdVE/c9AtuZLTlRd/y4I9Tv/F9S8UhUlSvuuEQUeKCpTXUOBfWiM5FAJcO36KOhybOF7y4tCbm8lDNtiKS5wFBpa+tVwgReIN7Us3euCyKA2HC7jhplf23R4Dts0/vqWRpWEbHxNHFbxxll2mRBgJpL0woDhpTJpjNgpwruEpkrb89s+eXV+UaESJzcBWXwBAHz82YO1MEl3PA7M1xrYkDDkDhY6lVEXHKdsbzQSlAQ9zw1/Vc6Q6IOThZ9RLZHSzBCuS0xbIts0s7R9Ugg7X/CQAVC7NE2yzRT/NJdPkYMxcPfQwtgb3zuXiC/rNsmJA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org 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=bglS7oomxZfgdvHoNj18LEuXieYUwHYBmfu7vu8Wias=; b=1jBLNkqU4aDdMthuf2+uGEnBRAQ/zbcMZQxLO0FTXh03r/jEST3lQNSlaFt2m28d1PME71hmw0I0taL2By3QzkELj9axyQKxbtPEdo6cnpngJ1lV8Nn/hhQKPQ00o3yXNPFzEhBcTjoH8H3qec9EFxqYom76L34SpXfkEeJ5sgw= Received: from DS1PR07CA0017.namprd07.prod.outlook.com (2603:10b6:8:44d::14) by IA1PR12MB8261.namprd12.prod.outlook.com (2603:10b6:208:3f7::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.270.13; Thu, 30 Jul 2026 06:34:46 +0000 Received: from CH3PEPF00000014.namprd21.prod.outlook.com (2603:10b6:8:44d:cafe::c) by DS1PR07CA0017.outlook.office365.com (2603:10b6:8:44d::14) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.270.14 via Frontend Transport; Thu, 30 Jul 2026 06:34:45 +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 CH3PEPF00000014.mail.protection.outlook.com (10.167.244.119) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.292.1 via Frontend Transport; Thu, 30 Jul 2026 06:34:45 +0000 Received: from satlexmb10.amd.com (10.181.42.219) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.41; Thu, 30 Jul 2026 01:34:45 -0500 Received: from satlexmb07.amd.com (10.181.42.216) by satlexmb10.amd.com (10.181.42.219) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.41; Thu, 30 Jul 2026 01:34:44 -0500 Received: from [172.31.176.217] (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server id 15.2.2562.41 via Frontend Transport; Thu, 30 Jul 2026 01:34:36 -0500 Message-ID: <48ee7e99-d66a-43c9-8068-689113a744de@amd.com> Date: Thu, 30 Jul 2026 12:04:31 +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: [PATCH v8 2/8] mm: migrate: Add promote_misplaced_memcg_folios() To: , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , References: <20260728054356.291998-1-bharata@amd.com> <20260728054356.291998-3-bharata@amd.com> Content-Language: en-US From: Bharata B Rao In-Reply-To: <20260728054356.291998-3-bharata@amd.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PEPF00000014:EE_|IA1PR12MB8261:EE_ X-MS-Office365-Filtering-Correlation-Id: f34424d4-51f8-4f96-dfca-08deee04a550 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700016|23010399003|376014|7416014|1800799024|82310400026|56012099006|4143699003|11063799006|10067099003|6133799003|22082099003|18002099003; X-Microsoft-Antispam-Message-Info: E9oidyqqUvJcqYdVInu7dcAyNoKBRqt89cSTOuRvnFNUovpIL5F2SLbzDgZSu7sM/+X8D760xnLzMavovtDxa5EGC3iOoEY78wGC4UUevY3TLcNmjv2GoCgfDeoruLWXXK69p24w07Ts57oxatofCypoVbFyy1Um0qvnX0UqDs7JF5VrHPnxHRuk0tH27mRKr3dRqP5roMsj5UtJC3syXE1a2S44fyG9RwggshxE5hrfNhkTdVUq9mtXBcMI7aewhjWkP99DxvUHUaasF6oyN2b3VhCRNDLaeMxipriCtiml5LJ60I4l/WWgOCNb4/m0ez5V1iSyG+LiUv5RZIQeTnSFHKRbMNo+bH/NGtztiHfcaJD5OgR0hsprl8A+1cRXf0BDRgkbwamer3bKJt56HU4cVIWBgJabBCPu2Iss2dTCrZGOubFHXQhv+N2ueSSW8bKnL+NfgL1LaQyPfJ6P5RgzyWMH7Mol7tl55PcHvaeODAusfxEpm9aWeU5Kiwhsp+8FDVxh1SODKl40PqNMtdy/AyT2WFThgCIrjT7NP7SCrgs+J/RI2c0J0b2EJXmG92pOBDgIG2uDe3oHiGUPW98OHK+8I7fVampwiiqZ5AHmbKH9cG8nq7xlBHoPCh47igTb/+XcYonCiCSoKUxeZdLjK6m7CCMCFdIa0qNaLXCJJL7byvBwdsFATbAJjL4cgPUqqA4K5jzUjRFMwU1Thw== 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)(36860700016)(23010399003)(376014)(7416014)(1800799024)(82310400026)(56012099006)(4143699003)(11063799006)(10067099003)(6133799003)(22082099003)(18002099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: AStGOysqFt+tEBF/XflP324Yd8q4+tojKqrvpTTUZKQbG6JRw82tbmVlG+LqkP6hD3vxMzdM3u9d/dmfc8lhgWHLRUHpCtx+Xa8TWI/iNwhuWNRaUQsEpTSisU1DIjiuVN3FnZRMzHi2EkhcaVLpTThfk844UaBnatPtHj/du6iK+/GhWHX2zo7T5MHs1sIiS2LEcYZUU77CYOzFRX+VClqu0mP7JjRvyXb8xDuvfELEdpnT0XP+3j78F+iSLFupeZk51+50e1HL1gtaBTEEY65CJDpyRJ6zEQVO/9COWF7vr1ltvIkPWO7m1rJZGSXQEYSDrDMmPDti2RguGLJz+5HfFGuHM/K7Qz+HPkUHbK2MtsDAr4EtuddTHVvBgbbZpAhTpdAiXafhYc1eFsrNcpIZHFhKWq7YN7dJiPeoAkOX/ba5e3Q5nsvMGvoKjQCy X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jul 2026 06:34:45.3472 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f34424d4-51f8-4f96-dfca-08deee04a550 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: CH3PEPF00000014.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB8261 [Reply to Shashiko review] On 28-Jul-26 11:13 AM, Bharata B Rao wrote: > diff --git a/mm/migrate.c b/mm/migrate.c > index ab7227376757..58a8a0cf6fa3 100644 > --- a/mm/migrate.c > +++ b/mm/migrate.c > @@ -2773,4 +2773,62 @@ int migrate_misplaced_folio(struct folio *folio, int node) > BUG_ON(!list_empty(&migratepages)); > return nr_remaining ? -EAGAIN : 0; > } > + > +/** > + * promote_misplaced_memcg_folios() - Batch variant of migrate_misplaced_folio > + * Attempts to promote a folio list to the specified destination. > + * @folio_list: Isolated list of folios to be batch-promoted. > + * @node: The NUMA node ID to where the folios should be promoted. > + * > + * Caller is expected to have isolated the folios by calling > + * migrate_misplaced_folio_prepare(), which will result in an > + * elevated reference count on the folios. 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 function will un-isolate the folios, drop the elevated reference > + * and remove them from the list before returning. This should be called > + * only for batched promotion of hot pages from lower tier nodes. > + * > + * Return: 0 on success and -EAGAIN on failure or partial promotion. > + * On return, @folio_list will be empty regardless of success/failure. > + */ > +int promote_misplaced_memcg_folios(struct list_head *folio_list, int node) > +{ > + struct mem_cgroup *memcg = NULL; > + unsigned int nr_succeeded = 0; > + struct folio *first; > + int nr_remaining; > + > + if (list_empty(folio_list)) > + return 0; > + > + first = list_first_entry(folio_list, struct folio, lru); > +#ifdef CONFIG_DEBUG_VM > + { > + struct folio *f; > + > + list_for_each_entry(f, folio_list, lru) > + VM_WARN_ON_ONCE(folio_memcg(f) != folio_memcg(first)); > Does this iteration need to hold the RCU read lock? > Looking at folio_memcg(), it calls obj_cgroup_memcg(), which executes a > lockdep assertion requiring either rcu_read_lock or cgroup_mutex. Calling it > without these locks will cause a lockdep splat when CONFIG_PROVE_LOCKING is > enabled. > Additionally, without the RCU lock, can the returned memcg pointer be > concurrently updated due to memcg reparenting? If so, this race might cause > folio_memcg(f) and folio_memcg(first) to evaluate to different pointers > even if both folios belong to the same original memcg, potentially triggering > a spurious VM_WARN_ON_ONCE(). That list walk needs RCU read lock protection. Will fix. Regards, Bharata.