public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 net-next] net: advance skb_defer_disable_key check in napi_consume_skb
@ 2026-04-01  3:32 Jason Xing
  2026-04-01  3:36 ` Jason Xing
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Jason Xing @ 2026-04-01  3:32 UTC (permalink / raw)
  To: davem, edumazet, kuba, pabeni, horms; +Cc: netdev, Jason Xing

From: Jason Xing <kernelxing@tencent.com>

When net.core.skb_defer_max is adjusted to zero, napi_consume_skb
shouldn't go into deeper in skb_attempt_defer_free because that function
adds a pair of local_bh_enable/disable() which can be found in
kfree_skb_napi_cache(). Advancing the check of the static key saves more
cycles and benefits the single flow/few flows workloads.

Signed-off-by: Jason Xing <kernelxing@tencent.com>
---
v3
Link: https://lore.kernel.org/all/20260327153347.98647-1-kerneljasonxing@gmail.com/
1. use a simpler approach to avoid adding a new sysctl.

V2
Link: https://lore.kernel.org/all/20260326144249.97213-1-kerneljasonxing@gmail.com/
1. reuse proc_do_static_key() (Eric)
2. add doc (Stan)
---
 net/core/skbuff.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index 3d6978dd0aa8..c1562ba6903e 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -1519,7 +1519,8 @@ void napi_consume_skb(struct sk_buff *skb, int budget)
 
 	DEBUG_NET_WARN_ON_ONCE(!in_softirq());
 
-	if (skb->alloc_cpu != smp_processor_id() && !skb_shared(skb)) {
+	if (!static_branch_unlikely(&skb_defer_disable_key) &&
+	    skb->alloc_cpu != smp_processor_id() && !skb_shared(skb)) {
 		skb_release_head_state(skb);
 		return skb_attempt_defer_free(skb);
 	}
-- 
2.41.3


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

* Re: [PATCH v3 net-next] net: advance skb_defer_disable_key check in napi_consume_skb
  2026-04-01  3:32 [PATCH v3 net-next] net: advance skb_defer_disable_key check in napi_consume_skb Jason Xing
@ 2026-04-01  3:36 ` Jason Xing
  2026-04-03  8:47 ` kernel test robot
  2026-04-03  8:47 ` kernel test robot
  2 siblings, 0 replies; 4+ messages in thread
From: Jason Xing @ 2026-04-01  3:36 UTC (permalink / raw)
  To: davem, edumazet, kuba, pabeni, horms; +Cc: netdev, Jason Xing

On Wed, Apr 1, 2026 at 11:32 AM Jason Xing <kerneljasonxing@gmail.com> wrote:
>
> From: Jason Xing <kernelxing@tencent.com>
>
> When net.core.skb_defer_max is adjusted to zero, napi_consume_skb
> shouldn't go into deeper in skb_attempt_defer_free because that function
> adds a pair of local_bh_enable/disable() which can be found in
> kfree_skb_napi_cache(). Advancing the check of the static key saves more
> cycles and benefits the single flow/few flows workloads.
>
> Signed-off-by: Jason Xing <kernelxing@tencent.com>

OMG, I realized I just uploaded a wrong patch.... How can I withdraw this :(

The draft misses adding "#include "net-sysfs.h""... I will wait
another round of 24 hours then. Sorry for the noise.

Thanks,
Jason

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

* Re: [PATCH v3 net-next] net: advance skb_defer_disable_key check in napi_consume_skb
  2026-04-01  3:32 [PATCH v3 net-next] net: advance skb_defer_disable_key check in napi_consume_skb Jason Xing
  2026-04-01  3:36 ` Jason Xing
@ 2026-04-03  8:47 ` kernel test robot
  2026-04-03  8:47 ` kernel test robot
  2 siblings, 0 replies; 4+ messages in thread
From: kernel test robot @ 2026-04-03  8:47 UTC (permalink / raw)
  To: Jason Xing, davem, edumazet, kuba, pabeni, horms
  Cc: oe-kbuild-all, netdev, Jason Xing

Hi Jason,

kernel test robot noticed the following build errors:

[auto build test ERROR on net-next/main]

url:    https://github.com/intel-lab-lkp/linux/commits/Jason-Xing/net-advance-skb_defer_disable_key-check-in-napi_consume_skb/20260403-115110
base:   net-next/main
patch link:    https://lore.kernel.org/r/20260401033211.44463-1-kerneljasonxing%40gmail.com
patch subject: [PATCH v3 net-next] net: advance skb_defer_disable_key check in napi_consume_skb
config: mips-cu1830-neo_defconfig (https://download.01.org/0day-ci/archive/20260403/202604031603.YyNxdorw-lkp@intel.com/config)
compiler: mips-linux-gcc (GCC) 15.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260403/202604031603.YyNxdorw-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202604031603.YyNxdorw-lkp@intel.com/

All errors (new ones prefixed by >>):

   In file included from include/linux/build_bug.h:5,
                    from include/linux/container_of.h:5,
                    from include/linux/list.h:5,
                    from include/linux/module.h:12,
                    from net/core/skbuff.c:37:
   net/core/skbuff.c: In function 'napi_consume_skb':
>> net/core/skbuff.c:1522:38: error: 'skb_defer_disable_key' undeclared (first use in this function)
    1522 |         if (!static_branch_unlikely(&skb_defer_disable_key) &&
         |                                      ^~~~~~~~~~~~~~~~~~~~~
   include/linux/compiler.h:77:45: note: in definition of macro 'unlikely'
      77 | # define unlikely(x)    __builtin_expect(!!(x), 0)
         |                                             ^
   include/linux/jump_label.h:515:41: note: in expansion of macro 'unlikely_notrace'
     515 | #define static_branch_unlikely(x)       unlikely_notrace(static_key_enabled(&(x)->key))
         |                                         ^~~~~~~~~~~~~~~~
   include/linux/jump_label.h:515:58: note: in expansion of macro 'static_key_enabled'
     515 | #define static_branch_unlikely(x)       unlikely_notrace(static_key_enabled(&(x)->key))
         |                                                          ^~~~~~~~~~~~~~~~~~
   net/core/skbuff.c:1522:14: note: in expansion of macro 'static_branch_unlikely'
    1522 |         if (!static_branch_unlikely(&skb_defer_disable_key) &&
         |              ^~~~~~~~~~~~~~~~~~~~~~
   net/core/skbuff.c:1522:38: note: each undeclared identifier is reported only once for each function it appears in
    1522 |         if (!static_branch_unlikely(&skb_defer_disable_key) &&
         |                                      ^~~~~~~~~~~~~~~~~~~~~
   include/linux/compiler.h:77:45: note: in definition of macro 'unlikely'
      77 | # define unlikely(x)    __builtin_expect(!!(x), 0)
         |                                             ^
   include/linux/jump_label.h:515:41: note: in expansion of macro 'unlikely_notrace'
     515 | #define static_branch_unlikely(x)       unlikely_notrace(static_key_enabled(&(x)->key))
         |                                         ^~~~~~~~~~~~~~~~
   include/linux/jump_label.h:515:58: note: in expansion of macro 'static_key_enabled'
     515 | #define static_branch_unlikely(x)       unlikely_notrace(static_key_enabled(&(x)->key))
         |                                                          ^~~~~~~~~~~~~~~~~~
   net/core/skbuff.c:1522:14: note: in expansion of macro 'static_branch_unlikely'
    1522 |         if (!static_branch_unlikely(&skb_defer_disable_key) &&
         |              ^~~~~~~~~~~~~~~~~~~~~~


vim +/skb_defer_disable_key +1522 net/core/skbuff.c

  1500	
  1501	/**
  1502	 * napi_consume_skb() - consume skb in NAPI context, try to feed skb cache
  1503	 * @skb: buffer to free
  1504	 * @budget: NAPI budget
  1505	 *
  1506	 * Non-zero @budget must come from the @budget argument passed by the core
  1507	 * to a NAPI poll function. Note that core may pass budget of 0 to NAPI poll
  1508	 * for example when polling for netpoll / netconsole.
  1509	 *
  1510	 * Passing @budget of 0 is safe from any context, it turns this function
  1511	 * into dev_consume_skb_any().
  1512	 */
  1513	void napi_consume_skb(struct sk_buff *skb, int budget)
  1514	{
  1515		if (unlikely(!budget || !skb)) {
  1516			dev_consume_skb_any(skb);
  1517			return;
  1518		}
  1519	
  1520		DEBUG_NET_WARN_ON_ONCE(!in_softirq());
  1521	
> 1522		if (!static_branch_unlikely(&skb_defer_disable_key) &&
  1523		    skb->alloc_cpu != smp_processor_id() && !skb_shared(skb)) {
  1524			skb_release_head_state(skb);
  1525			return skb_attempt_defer_free(skb);
  1526		}
  1527	
  1528		if (!skb_unref(skb))
  1529			return;
  1530	
  1531		/* if reaching here SKB is ready to free */
  1532		trace_consume_skb(skb, __builtin_return_address(0));
  1533	
  1534		/* if SKB is a clone, don't handle this case */
  1535		if (skb->fclone != SKB_FCLONE_UNAVAILABLE) {
  1536			__kfree_skb(skb);
  1537			return;
  1538		}
  1539	
  1540		skb_release_all(skb, SKB_CONSUMED);
  1541		napi_skb_cache_put(skb);
  1542	}
  1543	EXPORT_SYMBOL(napi_consume_skb);
  1544	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

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

* Re: [PATCH v3 net-next] net: advance skb_defer_disable_key check in napi_consume_skb
  2026-04-01  3:32 [PATCH v3 net-next] net: advance skb_defer_disable_key check in napi_consume_skb Jason Xing
  2026-04-01  3:36 ` Jason Xing
  2026-04-03  8:47 ` kernel test robot
@ 2026-04-03  8:47 ` kernel test robot
  2 siblings, 0 replies; 4+ messages in thread
From: kernel test robot @ 2026-04-03  8:47 UTC (permalink / raw)
  To: Jason Xing, davem, edumazet, kuba, pabeni, horms
  Cc: llvm, oe-kbuild-all, netdev, Jason Xing

Hi Jason,

kernel test robot noticed the following build errors:

[auto build test ERROR on net-next/main]

url:    https://github.com/intel-lab-lkp/linux/commits/Jason-Xing/net-advance-skb_defer_disable_key-check-in-napi_consume_skb/20260403-115110
base:   net-next/main
patch link:    https://lore.kernel.org/r/20260401033211.44463-1-kerneljasonxing%40gmail.com
patch subject: [PATCH v3 net-next] net: advance skb_defer_disable_key check in napi_consume_skb
config: x86_64-buildonly-randconfig-005-20260403 (https://download.01.org/0day-ci/archive/20260403/202604031607.o753ScQ1-lkp@intel.com/config)
compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260403/202604031607.o753ScQ1-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202604031607.o753ScQ1-lkp@intel.com/

All errors (new ones prefixed by >>):

>> net/core/skbuff.c:1522:31: error: use of undeclared identifier 'skb_defer_disable_key'
    1522 |         if (!static_branch_unlikely(&skb_defer_disable_key) &&
         |                                      ^
>> net/core/skbuff.c:1522:31: error: use of undeclared identifier 'skb_defer_disable_key'
>> net/core/skbuff.c:1522:31: error: use of undeclared identifier 'skb_defer_disable_key'
>> net/core/skbuff.c:1522:31: error: use of undeclared identifier 'skb_defer_disable_key'
   4 errors generated.


vim +/skb_defer_disable_key +1522 net/core/skbuff.c

  1500	
  1501	/**
  1502	 * napi_consume_skb() - consume skb in NAPI context, try to feed skb cache
  1503	 * @skb: buffer to free
  1504	 * @budget: NAPI budget
  1505	 *
  1506	 * Non-zero @budget must come from the @budget argument passed by the core
  1507	 * to a NAPI poll function. Note that core may pass budget of 0 to NAPI poll
  1508	 * for example when polling for netpoll / netconsole.
  1509	 *
  1510	 * Passing @budget of 0 is safe from any context, it turns this function
  1511	 * into dev_consume_skb_any().
  1512	 */
  1513	void napi_consume_skb(struct sk_buff *skb, int budget)
  1514	{
  1515		if (unlikely(!budget || !skb)) {
  1516			dev_consume_skb_any(skb);
  1517			return;
  1518		}
  1519	
  1520		DEBUG_NET_WARN_ON_ONCE(!in_softirq());
  1521	
> 1522		if (!static_branch_unlikely(&skb_defer_disable_key) &&
  1523		    skb->alloc_cpu != smp_processor_id() && !skb_shared(skb)) {
  1524			skb_release_head_state(skb);
  1525			return skb_attempt_defer_free(skb);
  1526		}
  1527	
  1528		if (!skb_unref(skb))
  1529			return;
  1530	
  1531		/* if reaching here SKB is ready to free */
  1532		trace_consume_skb(skb, __builtin_return_address(0));
  1533	
  1534		/* if SKB is a clone, don't handle this case */
  1535		if (skb->fclone != SKB_FCLONE_UNAVAILABLE) {
  1536			__kfree_skb(skb);
  1537			return;
  1538		}
  1539	
  1540		skb_release_all(skb, SKB_CONSUMED);
  1541		napi_skb_cache_put(skb);
  1542	}
  1543	EXPORT_SYMBOL(napi_consume_skb);
  1544	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

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

end of thread, other threads:[~2026-04-03  8:48 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-01  3:32 [PATCH v3 net-next] net: advance skb_defer_disable_key check in napi_consume_skb Jason Xing
2026-04-01  3:36 ` Jason Xing
2026-04-03  8:47 ` kernel test robot
2026-04-03  8:47 ` kernel test robot

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