linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm: shmem: fix too little space for tmpfs only fallback 4KB
@ 2025-09-08 12:31 Vernon Yang
  2025-09-08 23:22 ` Andrew Morton
  2025-09-09  5:58 ` Baolin Wang
  0 siblings, 2 replies; 8+ messages in thread
From: Vernon Yang @ 2025-09-08 12:31 UTC (permalink / raw)
  To: hughd, baolin.wang, akpm, da.gomez; +Cc: linux-mm, linux-kernel, Vernon Yang

From: Vernon Yang <yanglincheng@kylinos.cn>

When the system memory is sufficient, allocating memory is always
successful, but when tmpfs size is low (e.g. 1MB), it falls back
directly from 2MB to 4KB, and other small granularity (8KB ~ 1024KB)
will not be tried.

Therefore add check whether the remaining space of tmpfs is sufficient
for allocation. If there is too little space left, try smaller large
folio.

Fixes: acd7ccb284b8 ("mm: shmem: add large folio support for tmpfs")
Signed-off-by: Vernon Yang <yanglincheng@kylinos.cn>
---
 mm/shmem.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/mm/shmem.c b/mm/shmem.c
index 8c592c6db2a0..b20affd57b23 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -1820,6 +1820,7 @@ static unsigned long shmem_suitable_orders(struct inode *inode, struct vm_fault
 					   unsigned long orders)
 {
 	struct vm_area_struct *vma = vmf ? vmf->vma : NULL;
+	struct shmem_sb_info *sbinfo = SHMEM_SB(inode->i_sb);
 	pgoff_t aligned_index;
 	unsigned long pages;
 	int order;
@@ -1835,6 +1836,18 @@ static unsigned long shmem_suitable_orders(struct inode *inode, struct vm_fault
 	while (orders) {
 		pages = 1UL << order;
 		aligned_index = round_down(index, pages);
+
+		/*
+		 * Check whether the remaining space of tmpfs is sufficient for
+		 * allocation. If there is too little space left, try smaller
+		 * large folio.
+		 */
+		if (sbinfo->max_blocks && percpu_counter_read(&sbinfo->used_blocks)
+						+ pages > sbinfo->max_blocks) {
+			order = next_order(&orders, order);
+			continue;
+		}
+
 		/*
 		 * Check for conflict before waiting on a huge allocation.
 		 * Conflict might be that a huge page has just been allocated
-- 
2.51.0



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2025-09-22  3:10 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-09-08 12:31 [PATCH] mm: shmem: fix too little space for tmpfs only fallback 4KB Vernon Yang
2025-09-08 23:22 ` Andrew Morton
2025-09-09 14:16   ` Vernon Yang
2025-09-09  5:58 ` Baolin Wang
2025-09-09 12:29   ` Vernon Yang
2025-09-22  1:46     ` Baolin Wang
2025-09-22  2:51       ` Vernon Yang
2025-09-22  3:09         ` Baolin Wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox