From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 B7BFB3C2D for ; Thu, 18 Jun 2026 22:17:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781821048; cv=none; b=f6Ic5p2QVhrpOmFX2vKh5yfu6J7vx16kJsdeJFb9VeZLzMsEaAOCa3hn3ePzO3YvhtxBLu1UFIJOqijSUNjdPlFamk7E2xfqm37lAzI6tu9V7Uuyu3bq9+RwXMuuCSUriNGk1Mvw+psTSvP8muTtEIeMQI4DBlxUL/wgzVR7Sn8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781821048; c=relaxed/simple; bh=G8XZ1DR9+CQ4PEZuhVaaT+BwrsUcTAxTPZDhVpMVSS4=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=Xm1JI95Yo6TxKTm+S1Mbrn0CTF6CH2RieAhcPY9udGBgAggp8Ti257K4n++fh+JdoPMH1QHxOByqmFWb7gQ1/4+EIGmXHrIfcf9+z0kzHy3qoaagRtw/XR9nD32yjcxnwZq7nkfa2+ndD3bfF79FYhD53gSPCS/41AXN3vpwYtE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VTWcS6/0; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="VTWcS6/0" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 008B11F000E9; Thu, 18 Jun 2026 22:17:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1781821047; bh=AgP8C8n7AzeVj9tEQoLceMS8hiFVWTMxZ605a6ktMpo=; h=From:To:Cc:Subject:Date; b=VTWcS6/0u0fy+q51rOfIGax1ATe4ygJ57UTUd6PSyTMWbQXGk8rY0qko1kWIXdpHz TIc7iBdWexOB2m8XhOcfP4e6l/pxd7nPTUioJ9sTwEXWGEGU0+6j0I70hR/F2jiuZK H7JhZFpARdupH1w+p3UqZsfUfqoXlHoWmlr0t2nMi5i8pjYzznlACT3wGxAi83k3Bn uVmyPB67Du3FmAGhx8aH7Rt5JFm7lJUyjqJcwpLSJrtsGMxGnsEhz7S6jymSOtHdNV EW4CykmPtNAvkeP34eO3aYOL2i3s4A0AqhG/ZV6UASfxSP6qQwU5zwbSRtoCTd090A PsXnbeN8lxLBQ== From: "Barry Song (Xiaomi)" To: akpm@linux-foundation.org, linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, "Barry Song (Xiaomi)" , Nanzhe Zhao , David Hildenbrand , Lorenzo Stoakes , Zi Yan , Baolin Wang , "Liam R . Howlett" , Nico Pache , Ryan Roberts , Dev Jain , Lance Yang , Kairui Song , Qi Zheng , Shakeel Butt , Axel Rasmussen , Yuanchu Xie , Wei Xu Subject: [RFC PATCH] mm: Avoiding split large folios if swap has no space Date: Fri, 19 Jun 2026 06:17:20 +0800 Message-Id: <20260618221720.71768-1-baohua@kernel.org> X-Mailer: git-send-email 2.39.3 (Apple Git-146) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit When swap is disabled or exhausted, swap slot allocation may fail during swapout, causing large folios to be split into small folios. The splitting is reasonable when we truly fail to obtain contiguous swap slots, but it is pointless in the no-space case. A simple way to reproduce this is to invoke MADV_PAGEOUT on a system with mTHP enabled but without swap configured. #define SIZE (16 * 1024 * 1024) int main(void) { char *buf = mmap(NULL, SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); memset(buf, 1, SIZE); madvise(buf, SIZE, MADV_PAGEOUT); munmap(buf, SIZE); return 0; } With 16KB mTHP enabled, we observe: ~ # cat /sys/kernel/mm/transparent_hugepage/hugepages-16kB/stats/split 1024 This patch checks swap space before splitting. If there is no available space, it skips splitting. After the patch, we observe: ~ # cat /sys/kernel/mm/transparent_hugepage/hugepages-16kB/stats/split 0 Reported-by: Nanzhe Zhao Cc: David Hildenbrand Cc: Lorenzo Stoakes Cc: Zi Yan Cc: Baolin Wang Cc: Liam R. Howlett Cc: Nico Pache Cc: Ryan Roberts Cc: Dev Jain Cc: Lance Yang Cc: Kairui Song Cc: Qi Zheng Cc: Shakeel Butt Cc: Axel Rasmussen Cc: Yuanchu Xie Cc: Wei Xu Signed-off-by: Barry Song (Xiaomi) --- mm/vmscan.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 299b5d9e8836..33f84a5fe7ee 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -339,8 +339,7 @@ static bool can_demote(int nid, struct scan_control *sc, return !nodes_empty(allowed_mask); } -static inline bool can_reclaim_anon_pages(struct mem_cgroup *memcg, - int nid, +static inline bool __can_reclaim_anon_pages(struct mem_cgroup *memcg, struct scan_control *sc) { if (memcg == NULL) { @@ -356,6 +355,16 @@ static inline bool can_reclaim_anon_pages(struct mem_cgroup *memcg, return true; } + return false; +} + +static inline bool can_reclaim_anon_pages(struct mem_cgroup *memcg, + int nid, + struct scan_control *sc) +{ + if (__can_reclaim_anon_pages(memcg, sc)) + return true; + /* * The page can not be swapped. * @@ -1280,6 +1289,8 @@ static unsigned int shrink_folio_list(struct list_head *folio_list, if (!folio_test_large(folio)) goto activate_locked_split; + if (!__can_reclaim_anon_pages(memcg, sc)) + goto activate_locked_split; /* Fallback to swap normal pages */ if (split_folio_to_list(folio, folio_list)) goto activate_locked; -- 2.39.3 (Apple Git-146)