[Devel] [PATCH RHEL9 COMMIT] net/skbuff: WARN if kmalloc_reserve() fails to allocate memory.

Konstantin Khorenko khorenko at virtuozzo.com
Wed Oct 20 11:40:35 MSK 2021


The commit is pushed to "branch-rh9-5.14.vz9.1.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh9-5.14.0-4.vz9.10.12
------>
commit d6ebfdb69d93c9fd011963694e25008e8ee33fcc
Author: Andrey Ryabinin <ryabinin.a.a at gmail.com>
Date:   Wed Oct 20 11:40:35 2021 +0300

    net/skbuff: WARN if kmalloc_reserve() fails to allocate memory.
    
    Commit c93bdd0e03e8 ("netvm: allow skb allocation to use PFMEMALLOC reserves")
    removed memory allocation failure message in cases when pfmemalloc
    reserves are not allowed to use. Warning makes easier to observe network
    performance issues which might happen due to allocation failures.
    
    So remove __GFP_NOWARN unless we can use fallback allocation with __GFP_MEMALLOC.
    Also remove __GFP_NOMEMALLOC when usage of memory reserves isn't allowed.
    Many allocations on receive path use plain GFP_ATOMIC without __GFP_NOMEMALLOC.
    Such allocations have greater chance to succeed because plain GFP_ATOMIC can use
    1/4 of memory reserves, while GFP_ATOMIC|__GFP_NOMEMALLOC can't. So it's seems
    more reasonable to use GFP_ATOMIC all across receive path so all allocations
    have similar chance of succeeding.
    
    https://pmc.acronis.com/browse/VSTOR-21390
    Signed-off-by: Andrey Ryabinin <aryabinin at virtuozzo.com>
    
    Cherry-picked from vz7 commit e887ea717df6 ("net/skuff: WARN if
    kmalloc_reserve() fails to allocate memory.")
    
    Added to VZ8 in the scope of https://jira.sw.ru/browse/PSBM-127844.
    Signed-off-by: Evgenii Shatokhin <eshatokhin at virtuozzo.com>
    
    (cherry picked from vz8 commit daeac323f7b05f5d3bc728bdf8b8ba559f4be62b)
    Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko at virtuozzo.com>
---
 net/core/skbuff.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index fc7942c0dddc..8e50179b69fb 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -347,14 +347,16 @@ static void *kmalloc_reserve(size_t size, gfp_t flags, int node,
 {
 	void *obj;
 	bool ret_pfmemalloc = false;
+	gfp_t alloc_flags = flags;
 
 	/*
 	 * Try a regular allocation, when that fails and we're not entitled
 	 * to the reserves, fail.
 	 */
-	obj = kmalloc_node_track_caller(size,
-					flags | __GFP_NOMEMALLOC | __GFP_NOWARN,
-					node);
+	if (gfp_pfmemalloc_allowed(flags))
+		alloc_flags |= __GFP_NOMEMALLOC | __GFP_NOWARN;
+
+	obj = kmalloc_node_track_caller(size, alloc_flags, node);
 	if (obj || !(gfp_pfmemalloc_allowed(flags)))
 		goto out;
 


More information about the Devel mailing list