From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mta0.migadu.com (out-169.mta0.migadu.com [91.218.175.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 01225489865 for ; Fri, 2 Oct 2026 09:57:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790935035; cv=none; b=a6BvvIH5JFA6F5snSguVy63TcpAqCMAvMREyeFwb9KIELQ29+LBBS/QJMuoEdYOg7LX3M6UtqFhLYHisKZzVSyu/4J/txTrUUsw+T9k+gi/oXCmOABtsm0e/8Ep7BgHs4TKET6NPXisYylLqMRzMM5eq7lrzc5ryt5Y40n7/1L4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790935035; c=relaxed/simple; bh=O3Mn4KnTxiYaTlhEiHGB+/12dl1tDr6TCxd6G0YbQtw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Q2c99XbKOb9luZWu4LLpdd2y5wHONgI67DENtSv0VnxQ2LdfEjbxzDjbhBWJXyfoGtDivqWHq/5I5ni18EkbesRwNzZexNpzdszrTbz7odgF/2rmpd7r4Lw+qdmkzjCwS3v3DL+SLfW/mDTY+FcHEOGmnuFsqBeu98O2KmSvJxo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=Yt3V/HcN; arc=none smtp.client-ip=91.218.175.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="Yt3V/HcN" X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=O3Mn4KnTxiYaTlhEiHGB+/12dl1tDr6TCxd6G0YbQtw=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1790935031; v=1; x=1791539831; b=Yt3V/HcNbmcUwemCHOSvedDAbZZPykz2HBT8iGsDw6wpQkgc76n4u5oeY9f34TWwL6LIi4iy fTV5+hX1goo+Dp1QnOoM7lqLcccilIBDdA5zTR378xVaNZfh1qSdkVEV9XDG85Ky/IyvypGJPia dlZOHJ/w3+a/V50IANYe814g= X-Envelope-To: linux-kernel@vger.kernel.org Received: by mta10.migadu.com with ESMTPS id 32c8d113bd9f3403; Fri, 02 Oct 2026 09:57:10 +0000 X-Mizu-Trace-ID: 32c8d113bd9f3403 X-Migadu-Flow: FLOW_OUT From: Usama Arif To: Andrew Morton , david@kernel.org, chrisl@kernel.org, kasong@tencent.com, ljs@kernel.org, ziy@nvidia.com, linux-mm@kvack.org Cc: ying.huang@linux.alibaba.com, Baoquan He , willy@infradead.org, youngjun.park@lge.com, hannes@cmpxchg.org, riel@surriel.com, shakeel.butt@linux.dev, alex@ghiti.fr, kas@kernel.org, baohua@kernel.org, dev.jain@arm.com, baolin.wang@linux.alibaba.com, Nico Pache , Liam R. Howlett , ryan.roberts@arm.com, Vlastimil Babka , lance.yang@linux.dev, linux-kernel@vger.kernel.org, nphamcs@gmail.com, shikemeng@huaweicloud.com, yosry@kernel.org, qi.zheng@linux.dev, luizcap@redhat.com, kernel-team@meta.com, Usama Arif Subject: [PATCH v8 21/30] mm/madvise: skip PMD swap entries for MADV_COLD and MADV_PAGEOUT Date: Fri, 2 Oct 2026 02:52:35 -0700 Message-ID: <20261002095503.3585565-22-usama.arif@linux.dev> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261002095503.3585565-1-usama.arif@linux.dev> References: <20261002095503.3585565-1-usama.arif@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit A swapped-out THP has no resident folio to deactivate or reclaim, which is also the conclusion the PTE path reaches when it walks the swap entries and skips every one. madvise_cold_or_pageout_pte_range() gets there the long way round: pmd_trans_huge() is false for a PMD swap entry, so it falls out of the huge branch and tries to map a PTE table that a non-present PMD does not have. The entry can also appear after that first, lockless test, so re-check under the PMD lock; otherwise a PMD that turned into a swap entry while pmd_trans_huge_lock() was being taken trips the VM_WARN_ON_ONCE() that expects a migration or device-private entry. Signed-off-by: Usama Arif --- mm/madvise.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/mm/madvise.c b/mm/madvise.c index 70acb39b8b3dd..d3b5ed7e3cffb 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -385,6 +385,15 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd, !can_do_file_pageout(vma); #ifdef CONFIG_TRANSPARENT_HUGEPAGE + /* + * Swapped-out THPs have no resident folio to deactivate or reclaim. + * Avoid descending into or splitting a PMD swap entry. + */ + if (pmd_is_swap_entry(*pmd)) { + walk->action = ACTION_CONTINUE; + return 0; + } + if (pmd_trans_huge(*pmd)) { pmd_t orig_pmd; unsigned long next = pmd_addr_end(addr, end); @@ -395,6 +404,9 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd, return 0; orig_pmd = *pmd; + if (pmd_is_swap_entry(orig_pmd)) + goto huge_unlock; + if (unlikely(!pmd_present(orig_pmd))) { VM_WARN_ON_ONCE(!pmd_is_migration_entry(orig_pmd) && !pmd_is_device_private_entry(orig_pmd)); -- 2.53.0-Meta