Skip to contentSkip to conversation

mm/vmalloc: Do not warn on -ENOMEM from va_alloc()

PATCH Applied Uladzislau Rezki (Sony) 3 participants 4 messages Aug 2 – Aug 3

Subsystems (2)
lore
Share & tools
lore

Uladzislau Rezki (Sony)

author maintainer
#0 lore raw

PATCH 1/1 mm/vmalloc: Do not warn on -ENOMEM from va_alloc()

Since vmalloc() accepts non-blocking GFP flags, allocation requests may fail when callers pass restrictive GFP masks.

va_clip() may return -ENOMEM when its GFP_NOWAIT fallback allocation fails during NE_FIT_TYPE splitting. This is an expected failure, so va_alloc() should return the error without triggering a kernel splat.

---
 mm/vmalloc.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
mm/vmalloc.c +6 -7
index 1afca3568b9b..7a0cbba3d29d 100644
@@ -1817,8 +1817,10 @@ va_alloc(struct vmap_area *va,
 
 	/* Update the free vmap_area. */
 	ret = va_clip(root, head, va, nva_start_addr, size);
-	if (WARN_ON_ONCE(ret))
+	if (ret) {
+		WARN_ON_ONCE(ret != -ENOMEM);
 		return ret;
+	}
 
 	return nva_start_addr;
 }
@@ -1891,12 +1893,9 @@ preload_this_cpu_lock(spinlock_t *lock, gfp_t gfp_mask, int node)
 
 	/*
 	 * Preload this CPU with one extra vmap_area object. It is used
-	 * when fit type of free area is NE_FIT_TYPE. It guarantees that
-	 * a CPU that does an allocation is preloaded.
-	 *
-	 * We do it in non-atomic context, thus it allows us to use more
-	 * permissive allocation masks to be more stable under low memory
-	 * condition and high memory pressure.
+	 * when fit type of free area is NE_FIT_TYPE. It is best effort
+	 * pre-loading. If it fails va_clip() may return -ENOMEM from its
+	 * GFP_NOWAIT fallback.
 	 */
 	if (!this_cpu_read(ne_fit_preload_node))
 		va = kmem_cache_alloc_node(vmap_area_cachep, gfp_mask, node);
Signature · 1 line
2.47.3
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Uladzislau Rezki (Sony)

Since vmalloc() accepts non-blocking GFP flags, allocation requests may fail when callers pass restrictive GFP masks.

va_clip() may return -ENOMEM when its GFP_NOWAIT fallback allocation fails during NE_FIT_TYPE splitting. This is an expected failure, so va_alloc() should return the error without triggering a kernel splat.

Dropping WARN_ON_ONCE() just for -ENOMEM while preserving this warning for other returned errors does make sense.

Quoted 2 lines
Reported-by [email protected]

Very small nit.

If there is actual link for the problem report, probably it could be added as an Link: or Closes: here.

Quoted 1 line
Quoted 39 lines
---
 mm/vmalloc.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
mm/vmalloc.c +6 -7
index 1afca3568b9b..7a0cbba3d29d 100644
@@ -1817,8 +1817,10 @@ va_alloc(struct vmap_area *va,
 
 	/* Update the free vmap_area. */
 	ret = va_clip(root, head, va, nva_start_addr, size);
-	if (WARN_ON_ONCE(ret))
+	if (ret) {
+		WARN_ON_ONCE(ret != -ENOMEM);
 		return ret;
+	}
 
 	return nva_start_addr;
 }
@@ -1891,12 +1893,9 @@ preload_this_cpu_lock(spinlock_t *lock, gfp_t gfp_mask, int node)
 
 	/*
 	 * Preload this CPU with one extra vmap_area object. It is used
-	 * when fit type of free area is NE_FIT_TYPE. It guarantees that
-	 * a CPU that does an allocation is preloaded.
-	 *
-	 * We do it in non-atomic context, thus it allows us to use more
-	 * permissive allocation masks to be more stable under low memory
-	 * condition and high memory pressure.
+	 * when fit type of free area is NE_FIT_TYPE. It is best effort
+	 * pre-loading. If it fails va_clip() may return -ENOMEM from its
+	 * GFP_NOWAIT fallback.
 	 */
 	if (!this_cpu_read(ne_fit_preload_node))
 		va = kmem_cache_alloc_node(vmap_area_cachep, gfp_mask, node);
Signature · 1 line
2.47.3
author maintainer
#2 lore raw
Quoted 13 lines · Anshuman Khandual
Quoted 7 lines · Uladzislau Rezki (Sony)

Since vmalloc() accepts non-blocking GFP flags, allocation requests may fail when callers pass restrictive GFP masks.

va_clip() may return -ENOMEM when its GFP_NOWAIT fallback allocation fails during NE_FIT_TYPE splitting. This is an expected failure, so va_alloc() should return the error without triggering a kernel splat.

Dropping WARN_ON_ONCE() just for -ENOMEM while preserving this warning for other returned errors does make sense.

Quoted 1 line
Quoted 7 lines
Quoted 1 line
Reported-by [email protected]

Very small nit.

If there is actual link for the problem report, probably it could be added as an Link: or Closes: here.

I hope Andrew can help here. If not i will resend!

Thank you!

--
Uladzislau Rezki

Reviewed-by on v1 1/1
#3 lore raw
In reply to Uladzislau Rezki (Sony)
Quoted 36 lines · Uladzislau Rezki (Sony)

Since vmalloc() accepts non-blocking GFP flags, allocation requests may fail when callers pass restrictive GFP masks.

va_clip() may return -ENOMEM when its GFP_NOWAIT fallback allocation fails during NE_FIT_TYPE splitting. This is an expected failure, so va_alloc() should return the error without triggering a kernel splat.

---
 mm/vmalloc.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
mm/vmalloc.c +3 -3
index 1afca3568b9b..7a0cbba3d29d 100644
@@ -1817,8 +1817,10 @@ va_alloc(struct vmap_area *va,
 
 	/* Update the free vmap_area. */
 	ret = va_clip(root, head, va, nva_start_addr, size);
-	if (WARN_ON_ONCE(ret))
+	if (ret) {
+		WARN_ON_ONCE(ret != -ENOMEM);
 		return ret;
+	}
 
 	return nva_start_addr;
 }
@@ -1891,12 +1893,9 @@ preload_this_cpu_lock(spinlock_t *lock, gfp_t gfp_mask, int node)
 
 	/*
 	 * Preload this CPU with one extra vmap_area object. It is used
-	 * when fit type of free area is NE_FIT_TYPE. It guarantees that
-	 * a CPU that does an allocation is preloaded.

mm/vmalloc.c preload_this_cpu_lock(spinlock_t *lock, gfp_t gfp_mask, int node) · line 1901

Quoted 10 lines
mm/vmalloc.c +3 -4
-	 *
-	 * We do it in non-atomic context, thus it allows us to use more
-	 * permissive allocation masks to be more stable under low memory
-	 * condition and high memory pressure.
+	 * when fit type of free area is NE_FIT_TYPE. It is best effort
+	 * pre-loading. If it fails va_clip() may return -ENOMEM from its
+	 * GFP_NOWAIT fallback.
 	 */
 	if (!this_cpu_read(ne_fit_preload_node))
 		va = kmem_cache_alloc_node(vmap_area_cachep, gfp_mask, node);

LGTM,