page_pool: a couple of assorted optimizations
Subsystems (26)
v4 cover page_pool: a couple of assorted optimizations
That initially was a spin-off of the IAVF PP series[0], but has grown (and shrunk) since then a bunch. In fact, it consists of three semi-independent blocks:
* #1-2: Compile-time optimization. Split page_pool.h into 2 headers to not overbloat the consumers not needing complex inline helpers and then stop including it in skbuff.h at all. The first patch is also prereq for the whole series.
* #3: Improve cacheline locality for users of the Page Pool frag API.
* #4-6: Use direct cache recycling more aggressively, when it is safe obviously. In addition, make sure nobody wants to use Page Pool API with disabled interrupts.
Patches #1 and #5 are authored by Yunsheng and Jakub respectively, with small modifications from my side as per ML discussions.
For the perf numbers for #3-6, please see individual commit messages.
Also available on my GH with many more Page Pool goodies[1].
[0] https://lore.kernel.org/netdev/[email protected]
[1] https://github.com/alobakin/linux/commits/iavf-pp-frag
Alexander Lobakin (4):
net: skbuff: don't include <net/page_pool/types.h> to <linux/skbuff.h>
page_pool: place frag_* fields in one cacheline
net: skbuff: avoid accessing page_pool if !napi_safe when returning
page
net: skbuff: always try to recycle PP pages directly when in softirq
Jakub Kicinski (1):
page_pool: add a lockdep check for recycling in hardirq
Yunsheng Lin (1):
page_pool: split types and declarations from page_pool.h
MAINTAINERS | 2 +-
drivers/net/ethernet/broadcom/bnxt/bnxt.c | 2 +-
drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c | 2 +-
drivers/net/ethernet/engleder/tsnep_main.c | 1 +
drivers/net/ethernet/freescale/fec_main.c | 1 +
.../net/ethernet/hisilicon/hns3/hns3_enet.c | 1 +
.../net/ethernet/hisilicon/hns3/hns3_enet.h | 2 +-
drivers/net/ethernet/marvell/mvneta.c | 2 +-
drivers/net/ethernet/marvell/mvpp2/mvpp2.h | 2 +-
.../net/ethernet/marvell/mvpp2/mvpp2_main.c | 1 +
.../marvell/octeontx2/nic/otx2_common.c | 1 +
.../ethernet/marvell/octeontx2/nic/otx2_pf.c | 1 +
drivers/net/ethernet/mediatek/mtk_eth_soc.c | 1 +
drivers/net/ethernet/mediatek/mtk_eth_soc.h | 2 +-
.../ethernet/mellanox/mlx5/core/en/params.c | 1 +
.../net/ethernet/mellanox/mlx5/core/en/trap.c | 1 -
.../net/ethernet/mellanox/mlx5/core/en/xdp.c | 1 +
.../net/ethernet/mellanox/mlx5/core/en_main.c | 2 +-
.../net/ethernet/mellanox/mlx5/core/en_rx.c | 2 +-
.../ethernet/mellanox/mlx5/core/en_stats.c | 2 +-
.../ethernet/microchip/lan966x/lan966x_fdma.c | 1 +
.../ethernet/microchip/lan966x/lan966x_main.h | 2 +-
drivers/net/ethernet/socionext/netsec.c | 2 +-
drivers/net/ethernet/stmicro/stmmac/stmmac.h | 2 +-
.../net/ethernet/stmicro/stmmac/stmmac_main.c | 1 +
drivers/net/ethernet/ti/cpsw.c | 2 +-
drivers/net/ethernet/ti/cpsw_new.c | 2 +-
drivers/net/ethernet/ti/cpsw_priv.c | 2 +-
drivers/net/ethernet/wangxun/libwx/wx_lib.c | 2 +-
drivers/net/veth.c | 2 +-
drivers/net/wireless/mediatek/mt76/mac80211.c | 1 -
drivers/net/wireless/mediatek/mt76/mt76.h | 1 +
drivers/net/xen-netfront.c | 2 +-
include/linux/lockdep.h | 7 +
include/linux/skbuff.h | 5 +-
.../net/{page_pool.h => page_pool/helpers.h} | 242 +-----------------
include/net/page_pool/types.h | 236 +++++++++++++++++
include/trace/events/page_pool.h | 2 +-
net/bpf/test_run.c | 2 +-
net/core/page_pool.c | 43 +---
net/core/skbuff.c | 49 +++-
net/core/xdp.c | 2 +-
42 files changed, 335 insertions(+), 305 deletions(-)
rename include/net/{page_pool.h => page_pool/helpers.h} (51%)
create mode 100644 include/net/page_pool/types.h---
From v3[2]:
* rebase again after the bpf-next merge ._.;
* #5: pick the Acked-by from Jesper.
From v2[3]:
* just rebase on top of Jakub's kdoc changes landed last minute.
From v1[4]:
* move the "avoid calling no-op DMA sync ops" piece out of the series -- will join some other or transform into something else (Jakub et al.);
* #1: restore accidentally removed path in MAINTAINERS (Yunsheng);
* #1: prefer include/net/page_pool/ over include/net/page_pool/* in MAINTAINERS (Yunsheng);
* #2: rename page_pool_return_skb_page() to napi_pp_put_page() -- the old name seems to not make any sense for some time already (Yunsheng);
* #2: guard napi_pp_put_page() with CONFIG_PAGE_POOL in skbuff.c (to not compile it when there are no users) (Yunsheng).
From RFC v2[5]:
* drop the dependency on the hybrid allocation series (and thus the "RFC" prefix) -- it wasn't a strict dep and it's not in the trees yet;
* add [slightly reworked] Yunsheng's patch which splits page_pool.h into 2 headers -- merge conflict hell otherwise.
Also fix a typo while nobody looks (Simon);
* #3 (former #2): word the commitmsg a bit better, mention the main reason for the change more clearly (Ilias);
* add Jakub's hardirq assertion as a prereq for the last patch;
* #9 (former #7): add comment mentioning that the hardirq case is not checked due to the assertion checking it later (yes, it is illegal to use Page Pool with the interrupts disabled or when in TH) (Jakub).
From RFC v1[6]:
* #1: move the entire function to skbuff.c, don't try to split it (Alex);
* #2-4: new;
* #5: use internal flags field added in #4 and don't modify driver-defined structure (Alex, Jakub);
* #6: new;
* drop "add new NAPI state" as a redundant complication;
* #7: replace the check for the new NAPI state to just in_softirq(), should be fine (Jakub).
[2] https://lore.kernel.org/netdev/[email protected]
[3] https://lore.kernel.org/netdev/[email protected]
[4] https://lore.kernel.org/netdev/[email protected]
[5] https://lore.kernel.org/netdev/[email protected]
[6] https://lore.kernel.org/netdev/[email protected]
Signature · 1 line
2.41.0
PATCH v4 1/6 page_pool: split types and declarations from page_pool.h
From: Yunsheng Lin <[email protected]>
Split types and pure function declarations from page_pool.h and add them in page_page/types.h, so that C sources can include page_pool.h and headers should generally only include page_pool/types.h as suggested by jakub.
Rename page_pool.h to page_pool/helpers.h to have both in one place.
---
MAINTAINERS | 2 +-
drivers/net/ethernet/broadcom/bnxt/bnxt.c | 2 +-
drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c | 2 +-
drivers/net/ethernet/engleder/tsnep_main.c | 1 +
drivers/net/ethernet/freescale/fec_main.c | 1 +
.../net/ethernet/hisilicon/hns3/hns3_enet.c | 1 +
.../net/ethernet/hisilicon/hns3/hns3_enet.h | 2 +-
drivers/net/ethernet/marvell/mvneta.c | 2 +-
drivers/net/ethernet/marvell/mvpp2/mvpp2.h | 2 +-
.../net/ethernet/marvell/mvpp2/mvpp2_main.c | 1 +
.../marvell/octeontx2/nic/otx2_common.c | 1 +
.../ethernet/marvell/octeontx2/nic/otx2_pf.c | 1 +
drivers/net/ethernet/mediatek/mtk_eth_soc.c | 1 +
drivers/net/ethernet/mediatek/mtk_eth_soc.h | 2 +-
.../ethernet/mellanox/mlx5/core/en/params.c | 1 +
.../net/ethernet/mellanox/mlx5/core/en/trap.c | 1 -
.../net/ethernet/mellanox/mlx5/core/en/xdp.c | 1 +
.../net/ethernet/mellanox/mlx5/core/en_main.c | 2 +-
.../net/ethernet/mellanox/mlx5/core/en_rx.c | 2 +-
.../ethernet/mellanox/mlx5/core/en_stats.c | 2 +-
.../ethernet/microchip/lan966x/lan966x_fdma.c | 1 +
.../ethernet/microchip/lan966x/lan966x_main.h | 2 +-
drivers/net/ethernet/socionext/netsec.c | 2 +-
drivers/net/ethernet/stmicro/stmmac/stmmac.h | 2 +-
.../net/ethernet/stmicro/stmmac/stmmac_main.c | 1 +
drivers/net/ethernet/ti/cpsw.c | 2 +-
drivers/net/ethernet/ti/cpsw_new.c | 2 +-
drivers/net/ethernet/ti/cpsw_priv.c | 2 +-
drivers/net/ethernet/wangxun/libwx/wx_lib.c | 2 +-
drivers/net/veth.c | 2 +-
drivers/net/wireless/mediatek/mt76/mac80211.c | 1 -
drivers/net/wireless/mediatek/mt76/mt76.h | 1 +
drivers/net/xen-netfront.c | 2 +-
include/linux/skbuff.h | 2 +-
.../net/{page_pool.h => page_pool/helpers.h} | 242 +-----------------
include/net/page_pool/types.h | 238 +++++++++++++++++
include/trace/events/page_pool.h | 2 +-
net/bpf/test_run.c | 2 +-
net/core/page_pool.c | 2 +-
net/core/skbuff.c | 2 +-
net/core/xdp.c | 2 +-
41 files changed, 280 insertions(+), 264 deletions(-)
rename include/net/{page_pool.h => page_pool/helpers.h} (51%)
create mode 100644 include/net/page_pool/types.hMAINTAINERS +1 -1
@@ -16020,7 +16020,7 @@ M: Ilias Apalodimas <[email protected]> L: [email protected] S: Supported F: Documentation/networking/page_pool.rst -F: include/net/page_pool.h +F: include/net/page_pool/ F: include/trace/events/page_pool.h F: net/core/page_pool.c
drivers/net/ethernet/broadcom/bnxt/bnxt.c +1 -1
@@ -54,7 +54,7 @@#include <net/pkt_cls.h> #include <linux/hwmon.h> #include <linux/hwmon-sysfs.h> -#include <net/page_pool.h> +#include <net/page_pool/helpers.h> #include <linux/align.h> #include <net/netdev_queues.h>
drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c +1 -1
@@ -15,7 +15,7 @@#include <linux/bpf.h> #include <linux/bpf_trace.h> #include <linux/filter.h> -#include <net/page_pool.h> +#include <net/page_pool/helpers.h> #include "bnxt_hsi.h" #include "bnxt.h" #include "bnxt_xdp.h"
drivers/net/ethernet/engleder/tsnep_main.c +1 -0
@@ -28,6 +28,7 @@#include <linux/iopoll.h> #include <linux/bpf.h> #include <linux/bpf_trace.h> +#include <net/page_pool/helpers.h> #include <net/xdp_sock_drv.h> #define TSNEP_RX_OFFSET (max(NET_SKB_PAD, XDP_PACKET_HEADROOM) + NET_IP_ALIGN)
drivers/net/ethernet/freescale/fec_main.c +1 -0
@@ -38,6 +38,7 @@#include <linux/in.h> #include <linux/ip.h> #include <net/ip.h> +#include <net/page_pool/helpers.h> #include <net/selftests.h> #include <net/tso.h> #include <linux/tcp.h>
drivers/net/ethernet/hisilicon/hns3/hns3_enet.c +1 -0
@@ -18,6 +18,7 @@#include <net/gre.h> #include <net/gro.h> #include <net/ip6_checksum.h> +#include <net/page_pool/helpers.h> #include <net/pkt_cls.h> #include <net/pkt_sched.h> #include <net/tcp.h>
drivers/net/ethernet/hisilicon/hns3/hns3_enet.h +1 -1
@@ -6,7 +6,7 @@#include <linux/dim.h> #include <linux/if_vlan.h> -#include <net/page_pool.h> +#include <net/page_pool/types.h> #include <asm/barrier.h> #include "hnae3.h"
drivers/net/ethernet/marvell/mvneta.c +1 -1
@@ -37,7 +37,7 @@#include <net/ip.h> #include <net/ipv6.h> #include <net/tso.h> -#include <net/page_pool.h> +#include <net/page_pool/helpers.h> #include <net/pkt_sched.h> #include <linux/bpf_trace.h>
drivers/net/ethernet/marvell/mvpp2/mvpp2.h +1 -1
@@ -16,7 +16,7 @@#include <linux/phy.h> #include <linux/phylink.h> #include <net/flow_offload.h> -#include <net/page_pool.h> +#include <net/page_pool/types.h> #include <linux/bpf.h> #include <net/xdp.h>
drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c +1 -0
@@ -35,6 +35,7 @@#include <uapi/linux/ppp_defs.h> #include <net/ip.h> #include <net/ipv6.h> +#include <net/page_pool/helpers.h> #include <net/tso.h> #include <linux/bpf_trace.h>
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +1 -0
@@ -7,6 +7,7 @@#include <linux/interrupt.h> #include <linux/pci.h> +#include <net/page_pool/helpers.h> #include <net/tso.h> #include <linux/bitfield.h>
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +1 -0
@@ -16,6 +16,7 @@#include <linux/bpf.h> #include <linux/bpf_trace.h> #include <linux/bitfield.h> +#include <net/page_pool/types.h> #include "otx2_reg.h" #include "otx2_common.h"
drivers/net/ethernet/mediatek/mtk_eth_soc.c +1 -0
@@ -26,6 +26,7 @@#include <linux/bitfield.h> #include <net/dsa.h> #include <net/dst_metadata.h> +#include <net/page_pool/helpers.h> #include "mtk_eth_soc.h" #include "mtk_wed.h"
drivers/net/ethernet/mediatek/mtk_eth_soc.h +1 -1
@@ -18,7 +18,7 @@#include <linux/rhashtable.h> #include <linux/dim.h> #include <linux/bitfield.h> -#include <net/page_pool.h> +#include <net/page_pool/types.h> #include <linux/bpf_trace.h> #include "mtk_ppe.h"
drivers/net/ethernet/mellanox/mlx5/core/en/params.c +1 -0
@@ -6,6 +6,7 @@#include "en/port.h" #include "en_accel/en_accel.h" #include "en_accel/ipsec.h" +#include <net/page_pool/types.h> #include <net/xdp_sock_drv.h> static u8 mlx5e_mpwrq_min_page_shift (struct mlx5_core_dev *mdev)
drivers/net/ethernet/mellanox/mlx5/core/en/trap.c +0 -1
@@ -1,7 +1,6 @@// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB /* Copyright (c) 2020 Mellanox Technologies */ -#include <net/page_pool.h> #include "en/txrx.h" #include "en/params.h" #include "en/trap.h"
drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c +1 -0
@@ -35,6 +35,7 @@#include "en/xdp.h" #include "en/params.h" #include <linux/bitfield.h> +#include <net/page_pool/helpers.h> int mlx5e_xdp_max_mtu (struct mlx5e_params *params,struct mlx5e_xsk_param *xsk) {
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +1 -1
@@ -38,7 +38,7 @@#include <linux/debugfs.h> #include <linux/if_bridge.h> #include <linux/filter.h> -#include <net/page_pool.h> +#include <net/page_pool/types.h> #include <net/pkt_sched.h> #include <net/xdp_sock_drv.h> #include "eswitch.h"
drivers/net/ethernet/mellanox/mlx5/core/en_rx.c +1 -1
@@ -36,7 +36,7 @@#include <linux/bitmap.h> #include <linux/filter.h> #include <net/ip6_checksum.h> -#include <net/page_pool.h> +#include <net/page_pool/helpers.h> #include <net/inet_ecn.h> #include <net/gro.h> #include <net/udp.h>
drivers/net/ethernet/mellanox/mlx5/core/en_stats.c +1 -1
@@ -38,7 +38,7 @@#include "en/port.h" #ifdef CONFIG_PAGE_POOL_STATS -#include <net/page_pool.h> +#include <net/page_pool/helpers.h> #endif static unsigned int stats_grps_num (struct mlx5e_priv *priv)
drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c +1 -0
@@ -2,6 +2,7 @@#include <linux/bpf.h> #include <linux/filter.h> +#include <net/page_pool/helpers.h> #include "lan966x_main.h"
drivers/net/ethernet/microchip/lan966x/lan966x_main.h +1 -1
@@ -10,7 +10,7 @@#include <linux/phy.h> #include <linux/phylink.h> #include <linux/ptp_clock_kernel.h> -#include <net/page_pool.h> +#include <net/page_pool/types.h> #include <net/pkt_cls.h> #include <net/pkt_sched.h> #include <net/switchdev.h>
drivers/net/ethernet/socionext/netsec.c +1 -1
@@ -15,7 +15,7 @@#include <linux/bpf_trace.h> #include <net/tcp.h> -#include <net/page_pool.h> +#include <net/page_pool/helpers.h> #include <net/ip6_checksum.h> #define NETSEC_REG_SOFT_RST 0x104
drivers/net/ethernet/stmicro/stmmac/stmmac.h +1 -1
@@ -21,7 +21,7 @@#include <linux/ptp_clock_kernel.h> #include <linux/net_tstamp.h> #include <linux/reset.h> -#include <net/page_pool.h> +#include <net/page_pool/types.h> #include <net/xdp.h> #include <uapi/linux/bpf.h>
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +1 -0
@@ -39,6 +39,7 @@#include <linux/phylink.h> #include <linux/udp.h> #include <linux/bpf_trace.h> +#include <net/page_pool/helpers.h> #include <net/pkt_cls.h> #include <net/xdp_sock_drv.h> #include "stmmac_ptp.h"
drivers/net/ethernet/ti/cpsw.c +1 -1
@@ -31,7 +31,7 @@#include <linux/if_vlan.h> #include <linux/kmemleak.h> #include <linux/sys_soc.h> -#include <net/page_pool.h> +#include <net/page_pool/helpers.h> #include <linux/bpf.h> #include <linux/bpf_trace.h>
drivers/net/ethernet/ti/cpsw_new.c +1 -1
@@ -30,7 +30,7 @@#include <linux/sys_soc.h> #include <net/switchdev.h> -#include <net/page_pool.h> +#include <net/page_pool/helpers.h> #include <net/pkt_cls.h> #include <net/devlink.h>
drivers/net/ethernet/ti/cpsw_priv.c +1 -1
@@ -18,7 +18,7 @@#include <linux/platform_device.h> #include <linux/pm_runtime.h> #include <linux/skbuff.h> -#include <net/page_pool.h> +#include <net/page_pool/helpers.h> #include <net/pkt_cls.h> #include <net/pkt_sched.h>
drivers/net/ethernet/wangxun/libwx/wx_lib.c +1 -1
@@ -3,7 +3,7 @@#include <linux/etherdevice.h> #include <net/ip6_checksum.h> -#include <net/page_pool.h> +#include <net/page_pool/helpers.h> #include <net/inet_ecn.h> #include <linux/iopoll.h> #include <linux/sctp.h>
drivers/net/veth.c +1 -1
@@ -26,7 +26,7 @@#include <linux/ptr_ring.h> #include <linux/bpf_trace.h> #include <linux/net_tstamp.h> -#include <net/page_pool.h> +#include <net/page_pool/helpers.h> #define DRV_NAME "veth"#define DRV_VERSION "1.0"
drivers/net/wireless/mediatek/mt76/mac80211.c +0 -1
@@ -4,7 +4,6 @@*/ #include <linux/sched.h> #include <linux/of.h> -#include <net/page_pool.h> #include "mt76.h" #define CHAN2G (_idx, _freq) { \
drivers/net/wireless/mediatek/mt76/mt76.h +1 -0
@@ -15,6 +15,7 @@#include <linux/average.h> #include <linux/soc/mediatek/mtk_wed.h> #include <net/mac80211.h> +#include <net/page_pool/helpers.h> #include "util.h" #include "testmode.h"
drivers/net/xen-netfront.c +1 -1
@@ -45,7 +45,7 @@#include <linux/slab.h> #include <net/ip.h> #include <linux/bpf.h> -#include <net/page_pool.h> +#include <net/page_pool/types.h> #include <linux/bpf_trace.h> #include <xen/xen.h>
include/linux/skbuff.h +1 -1
@@ -32,7 +32,7 @@#include <linux/if_packet.h> #include <linux/llist.h> #include <net/flow.h> -#include <net/page_pool.h> +#include <net/page_pool/types.h> #if IS_ENABLED (CONFIG_NF_CONNTRACK )#include <linux/netfilter/nf_conntrack_common.h> #endif
include/net/page_pool/helpers.h renamed from include/net/page_pool.h +5 -237
295 lines not on this page · raw message
include/net/page_pool/types.h new file +238 -0
238 lines not on this page · raw message
include/trace/events/page_pool.h +1 -1
@@ -9,7 +9,7 @@#include <linux/tracepoint.h> #include <trace/events/mmflags.h> -#include <net/page_pool.h> +#include <net/page_pool/types.h> TRACE_EVENT(page_pool_release,
net/bpf/test_run.c +1 -1
@@ -15,7 +15,7 @@#include <net/sock.h> #include <net/tcp.h> #include <net/net_namespace.h> -#include <net/page_pool.h> +#include <net/page_pool/helpers.h> #include <linux/error-injection.h> #include <linux/smp.h> #include <linux/sock_diag.h>
net/core/page_pool.c +1 -1
@@ -10,7 +10,7 @@#include <linux/slab.h> #include <linux/device.h> -#include <net/page_pool.h> +#include <net/page_pool/helpers.h> #include <net/xdp.h> #include <linux/dma-direction.h>
net/core/skbuff.c +1 -1
@@ -73,7 +73,7 @@#include <net/mpls.h> #include <net/mptcp.h> #include <net/mctp.h> -#include <net/page_pool.h> +#include <net/page_pool/types.h> #include <net/dropreason.h> #include <linux/uaccess.h>
net/core/xdp.c +1 -1
@@ -14,7 +14,7 @@#include <linux/idr.h> #include <linux/rhashtable.h> #include <linux/bug.h> -#include <net/page_pool.h> +#include <net/page_pool/helpers.h> #include <net/xdp.h> #include <net/xdp_priv.h> /* struct xdp_mem_allocator */
Signature · 1 line
2.41.0
PATCH v4 2/6 net: skbuff: don't include <net/page_pool/types.h> to <linux/skbuff.h>
In reply to Alexander LobakinCurrently, touching <net/page_pool/types.h> triggers a rebuild of more than half of the kernel. That's because it's included in <linux/skbuff.h>. And each new include to page_pool/types.h adds more [useless] data for the toolchain to process per each source file from that pile.
In commit 6a5bcd84e886 ("page_pool: Allow drivers to hint on SKB recycling"), Matteo included it to be able to call a couple of functions defined there. Then, in commit 57f05bc2ab24 ("page_pool: keep pp info as long as page pool owns the page") one of the calls was removed, so only one was left. It's the call to page_pool_return_skb_page() in napi_frag_unref(). The function is external and doesn't have any dependencies. Having very niche page_pool_types.h included only for that looks like an overkill.
As %PP_SIGNATURE is not local to page_pool.c (was only in the early submissions), nothing holds this function there. Teleport page_pool_return_skb_page() to skbuff.c, just next to the main consumer, skb_pp_recycle(), and rename it to napi_pp_put_page(), as it doesn't work with skbs at all and the former name tells nothing. The #if guards here are only to not compile and have it in the vmlinux when not needed -- both call sites are already guarded.
Now, touching page_pool_types.h only triggers rebuilding of the drivers using it and a couple of core networking files.
--- include/linux/skbuff.h | 5 ++-- include/net/page_pool/types.h | 2 -- net/core/page_pool.c | 39 ------------------------------ net/core/skbuff.c | 45 +++++++++++++++++++++++++++++++++-- 4 files changed, 46 insertions(+), 45 deletions(-)
include/linux/skbuff.h +3 -2
@@ -32,7 +32,6 @@#include <linux/if_packet.h> #include <linux/llist.h> #include <net/flow.h> -#include <net/page_pool/types.h> #if IS_ENABLED (CONFIG_NF_CONNTRACK )#include <linux/netfilter/nf_conntrack_common.h> #endif
@@ -3421,13 +3420,15 @@ static inline void skb_frag_ref(struct sk_buff *skb, int f)__skb_frag_ref (&skb_shinfo (skb)->frags[f]); } +bool napi_pp_put_page (struct page *page,bool napi_safe); +static inline void napi_frag_unref (skb_frag_t *frag,bool recycle,bool napi_safe) {struct page *page =skb_frag_page (frag);#ifdef CONFIG_PAGE_POOL -if (recycle &&page_pool_return_skb_page (page, napi_safe)) +if (recycle &&napi_pp_put_page (page, napi_safe))return ;#endif put_page (page);
include/net/page_pool/types.h +0 -2
@@ -185,8 +185,6 @@ struct page_pool {struct page *page_pool_alloc_pages (struct page_pool *pool,gfp_t gfp);struct page *page_pool_alloc_frag (struct page_pool *pool,unsigned int *offset,unsigned int size,gfp_t gfp); -bool page_pool_return_skb_page (struct page *page,bool napi_safe); -struct page_pool *page_pool_create (const struct page_pool_params *params);struct xdp_mem_info ;
net/core/page_pool.c +0 -39
@@ -935,42 +935,3 @@ void page_pool_update_nid(struct page_pool *pool, int new_nid) } }EXPORT_SYMBOL (page_pool_update_nid); - -bool page_pool_return_skb_page (struct page *page,bool napi_safe) -{ -struct napi_struct *napi; -struct page_pool *pp; -bool allow_direct; - - page =compound_head (page); - -/* page->pp_magic is OR'ed with PP_SIGNATURE after the allocation -* in order to preserve any existing bits, such as bit 0 for the -* head page of compound page and bit 1 for pfmemalloc page, so -* mask those bits for freeing side when doing below checking, -* and page_is_pfmemalloc() is checked in __page_pool_put_page() -* to avoid recycling the pfmemalloc page. -*/ -if (unlikely ((page->pp_magic & ~0x3UL ) !=PP_SIGNATURE )) -return false; - - pp = page->pp; - -/* Allow direct recycle if we have reasons to believe that we are -* in the same context as the consumer would run, so there's -* no possible race. -*/ - napi =READ_ONCE (pp->p.napi); - allow_direct = napi_safe && napi && -READ_ONCE (napi->list_owner) ==smp_processor_id (); - -/* Driver set this to memory recycling info. Reset it on recycle. -* This will *not* work for NIC using a split-page memory model. -* The page will be returned to the pool here regardless of the -* 'flipped' fragment being in use or not. -*/ -page_pool_put_full_page (pp, page, allow_direct); - -return true; -} -EXPORT_SYMBOL (page_pool_return_skb_page);
net/core/skbuff.c +43 -2
61 lines not on this page · raw message
Signature · 1 line
2.41.0
PATCH v4 3/6 page_pool: place frag_* fields in one cacheline
In reply to Alexander LobakinOn x86_64, frag_* fields of struct page_pool are scattered across two cachelines despite the summary size of 24 bytes. All three fields are used in pretty much the same places, but the last field, ::frag_users, is pushed out to the next CL, provoking unwanted false-sharing on hotpath (frags allocation code).
There are some holes and cold members to move around. Move frag_* one block up, placing them right after &page_pool_params perfectly at the beginning of CL2. This doesn't do any meaningful to the second block, as those are some destroy-path cold structures, and doesn't do anything to ::alloc_stats, which still starts at 200-byte offset, 8 bytes after CL3 (still fitting into 1 cacheline).
On my setup, this yields 1-2% of Mpps when using PP frags actively. When it comes to 32-bit architectures with 32-byte CL: &page_pool_params plus ::pad is 44 bytes, the block taken care of is 16 bytes within one CL, so there should be at least no regressions from the actual change. ::pages_state_hold_cnt is not related directly to that triple, but is paired currently with ::frags_offset and decoupling them would mean either two 4-byte holes or more invasive layout changes.
--- include/net/page_pool/types.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
include/net/page_pool/types.h +5 -5
@@ -123,16 +123,16 @@ struct page_pool_stats {struct page_pool {struct page_pool_params p; +long frag_users; +struct page *frag_page; +unsigned int frag_offset; +u32 pages_state_hold_cnt; +struct delayed_work release_dw;void (*disconnect)(void *pool);unsigned long defer_start;unsigned long defer_warn; -u32 pages_state_hold_cnt; -unsigned int frag_offset; -struct page *frag_page; -long frag_users; -#ifdef CONFIG_PAGE_POOL_STATS /* these stats are incremented while in softirq context */ struct page_pool_alloc_stats alloc_stats;
Signature · 1 line
2.41.0
PATCH v4 4/6 net: skbuff: avoid accessing page_pool if !napi_safe when returning page
In reply to Alexander LobakinCurrently, pp->p.napi is always read, but the actual variable it gets assigned to is read-only when @napi_safe is true. For the !napi_safe cases, which yet is still a pack, it's an unneeded operation. Moreover, it can lead to premature or even redundant page_pool cacheline access. For example, when page_pool_is_last_frag() returns false (with the recent frag improvements).
Thus, read it only when @napi_safe is true. This also allows moving @napi inside the condition block itself. Constify it while we are here, because why not.
--- net/core/skbuff.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
net/core/skbuff.c +7 -5
@@ -882,9 +882,8 @@ static void skb_clone_fraglist(struct sk_buff *skb)#if IS_ENABLED (CONFIG_PAGE_POOL )bool napi_pp_put_page (struct page *page,bool napi_safe) { -struct napi_struct *napi; +bool allow_direct = false;struct page_pool *pp; -bool allow_direct; page =compound_head (page);
@@ -904,9 +903,12 @@ bool napi_pp_put_page(struct page *page, bool napi_safe)* in the same context as the consumer would run, so there's * no possible race. */ - napi =READ_ONCE (pp->p.napi); - allow_direct = napi_safe && napi && -READ_ONCE (napi->list_owner) ==smp_processor_id (); +if (napi_safe) { +const struct napi_struct *napi =READ_ONCE (pp->p.napi); + + allow_direct = napi && +READ_ONCE (napi->list_owner) ==smp_processor_id (); + }/* Driver set this to memory recycling info. Reset it on recycle. * This will *not* work for NIC using a split-page memory model.
Signature · 1 line
2.41.0
PATCH v4 5/6 page_pool: add a lockdep check for recycling in hardirq
In reply to Alexander LobakinFrom: Jakub Kicinski <[email protected]>
Page pool use in hardirq is prohibited, add debug checks to catch misuses. IIRC we previously discussed using DEBUG_NET_WARN_ON_ONCE() for this, but there were concerns that people will have DEBUG_NET enabled in perf testing. I don't think anyone enables lockdep in perf testing, so use lockdep to avoid pushback and arguing :)
--- include/linux/lockdep.h | 7 +++++++ net/core/page_pool.c | 2 ++ 2 files changed, 9 insertions(+)
include/linux/lockdep.h +7 -0
@@ -625,6 +625,12 @@ do { \WARN_ON_ONCE (__lockdep_enabled && !this_cpu_read (hardirq_context)); \ } while (0) +#define lockdep_assert_no_hardirq () \ +do { \ + WARN_ON_ONCE(__lockdep_enabled && (this_cpu_read(hardirq_context) || \ + !this_cpu_read(hardirqs_enabled))); \ +} while (0) +#define lockdep_assert_preemption_enabled () \ do { \ WARN_ON_ONCE(IS_ENABLED(CONFIG_PREEMPT_COUNT) && \
@@ -659,6 +665,7 @@ do { \# define lockdep_assert_irqs_enabled () do { } while (0)# define lockdep_assert_irqs_disabled () do { } while (0)# define lockdep_assert_in_irq () do { } while (0) +# define lockdep_assert_no_hardirq () do { } while (0)# define lockdep_assert_preemption_enabled () do { } while (0)# define lockdep_assert_preemption_disabled () do { } while (0)
net/core/page_pool.c +2 -0
@@ -587,6 +587,8 @@ static __always_inline struct page * __page_pool_put_page(struct page_pool *pool, struct page *page, unsigned int dma_sync_size, bool allow_direct) { +lockdep_assert_no_hardirq (); +/* This allocator is optimized for the XDP mode that uses * one-frame-per-page, but have fallbacks that act like the * regular page allocator APIs.
Signature · 1 line
2.41.0
PATCH v4 6/6 net: skbuff: always try to recycle PP pages directly when in softirq
In reply to Alexander LobakinCommit 8c48eea3adf3 ("page_pool: allow caching from safely localized NAPI") allowed direct recycling of skb pages to their PP for some cases, but unfortunately missed a couple of other majors.
For example, %XDP_DROP in skb mode. The netstack just calls kfree_skb(), which unconditionally passes false as @napi_safe. Thus, all pages go through ptr_ring and locks, although most of time we're actually inside the NAPI polling this PP is linked with, so that it would be perfectly safe to recycle pages directly.
Let's address such. If @napi_safe is true, we're fine, don't change anything for this path. But if it's false, check whether we are in the softirq context. It will most likely be so and then if ->list_owner is our current CPU, we're good to use direct recycling, even though @napi_safe is false -- concurrent access is excluded. in_softirq() protection is needed mostly due to we can hit this place in the process context (not the hardirq though).
For the mentioned xdp-drop-skb-mode case, the improvement I got is 3-4% in Mpps. As for page_pool stats, recycle_ring is now 0 and alloc_slow counter doesn't change most of time, which means the MM layer is not even called to allocate any new pages.
--- net/core/skbuff.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/core/skbuff.c +3 -1
@@ -902,8 +902,10 @@ bool napi_pp_put_page(struct page *page, bool napi_safe)/* Allow direct recycle if we have reasons to believe that we are * in the same context as the consumer would run, so there's * no possible race. +* __page_pool_put_page() makes sure we're not in hardirq context +* and interrupts are enabled prior to accessing the cache. */ -if (napi_safe) { +if (napi_safe ||in_softirq ()) {const struct napi_struct *napi =READ_ONCE (pp->p.napi); allow_direct = napi &&
Signature · 1 line
2.41.0
Re: [PATCH net-next v4 5/6] page_pool: add a lockdep check for recycling in hardirq
In reply to Alexander LobakinQuoted 47 lines · Alexander Lobakin
From: Jakub Kicinski <[email protected]>
Page pool use in hardirq is prohibited, add debug checks to catch misuses. IIRC we previously discussed using
DEBUG_NET_WARN_ON_ONCE()for this, but there were concerns that people will haveDEBUG_NETenabled in perf testing. I don't think anyone enables lockdep in perf testing, so use lockdep to avoid pushback and arguing :)Signed-off-by Jakub Kicinski <[email protected]>Signed-off-by Alexander Lobakin <[email protected]>--- include/linux/lockdep.h | 7 +++++++ net/core/page_pool.c | 2 ++ 2 files changed, 9 insertions(+)include/linux/lockdep.h +7
-0@@ -625,6 +625,12 @@ do { \WARN_ON_ONCE (__lockdep_enabled && !this_cpu_read (hardirq_context)); \ } while (0) +#define lockdep_assert_no_hardirq () \ +do { \ + WARN_ON_ONCE(__lockdep_enabled && (this_cpu_read(hardirq_context) || \ + !this_cpu_read(hardirqs_enabled))); \ +} while (0) +#define lockdep_assert_preemption_enabled () \ do { \ WARN_ON_ONCE(IS_ENABLED(CONFIG_PREEMPT_COUNT) && \@@ -659,6 +665,7 @@ do { \# define lockdep_assert_irqs_enabled () do { } while (0)# define lockdep_assert_irqs_disabled () do { } while (0)# define lockdep_assert_in_irq () do { } while (0) +# define lockdep_assert_no_hardirq () do { } while (0)# define lockdep_assert_preemption_enabled () do { } while (0)# define lockdep_assert_preemption_disabled () do { } while (0)net/core/page_pool.c +0
-0
net/core/page_pool.c static __always_inline struct page * · line 594
Quoted 8 lines
net/core/page_pool.c +2
-0@@ -587,6 +587,8 @@ static __always_inline struct page * __page_pool_put_page(struct page_pool *pool, struct page *page, unsigned int dma_sync_size, bool allow_direct) { +lockdep_assert_no_hardirq (); +/* This allocator is optimized for the XDP mode that uses * one-frame-per-page, but have fallbacks that act like the * regular page allocator APIs.
So two points.
First could we look at moving this inside the if statement just before we return the page, as there isn't a risk until we get into that path of needing a lock.
Secondly rather than returning an error is there any reason why we couldn't just look at not returning page and instead just drop into the release path which wouldn't take the locks in the first place? Either that or I would even be good with some combination of the two where we threw a warning, but still just dropped the page so we reduce our risk further of actually locking things up.
Quoted 29 lines · Alexander Lobakin
That initially was a spin-off of the IAVF PP series[0], but has grown (and shrunk) since then a bunch. In fact, it consists of three semi-independent blocks:
* #1-2: Compile-time optimization. Split
page_pool.hinto 2 headers to not overbloat the consumers not needing complex inline helpers and then stop including it inskbuff.hat all. The first patch is also prereq for the whole series.
* #3: Improve cacheline locality for users of the Page Pool frag API.
* #4-6: Use direct cache recycling more aggressively, when it is safe obviously. In addition, make sure nobody wants to use Page Pool API with disabled interrupts.Patches #1 and #5 are authored by Yunsheng and Jakub respectively, with small modifications from my side as per ML discussions.
For the perf numbers for #3-6, please see individual commit messages.Also available on my GH with many more Page Pool goodies[1].
[0] https://lore.kernel.org/netdev/[email protected]
[1] https://github.com/alobakin/linux/commits/iavf-pp-fragAlexander Lobakin (4):
net: skbuff: don't include <net/page_pool/types.h> to <linux/skbuff.h>
page_pool: place frag_* fields in one cacheline
net: skbuff: avoid accessingpage_poolif !napi_safe when returning
page
net: skbuff: always try to recycle PP pages directly when in softirq
Quoted 5 lines
Jakub Kicinski (1):
page_pool: add a lockdep check for recycling in hardirqYunsheng Lin (1):
page_pool: split types and declarations frompage_pool.h
So the series mostly looks good to me. My only concern would be with path 5 since I am not sure why we are just throwing a WARN_ON when we could just take action on the info to prevent the problem in the first place. That said the change doesn't hurt anything as-is so I would be good with us thinking about changing that as a follow-up.
Jakub Kicinski
maintainerRe: [PATCH net-next v4 1/6] page_pool: split types and declarations from page_pool.h
In reply to Alexander LobakinQuoted 6 lines · On Fri, 4 Aug 2023 20:05:24 +0200 Alexander Lobakin wrote:
Split types and pure function declarations from
page_pool.hand add them inpage_page/types.h, so that C sources can includepage_pool.hand headers should generally only includepage_pool/types.has suggested by jakub.
Renamepage_pool.htopage_pool/helpers.hto have both in one place.
I had to touch this one up a little when merging to fix build for the merged-in-meantime mana driver and also update the patch in Documentation.
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 13 lines · On Fri, 4 Aug 2023 20:05:23 +0200 you wrote:
That initially was a spin-off of the IAVF PP series[0], but has grown (and shrunk) since then a bunch. In fact, it consists of three semi-independent blocks:
* #1-2: Compile-time optimization. Split
page_pool.hinto 2 headers to not overbloat the consumers not needing complex inline helpers and then stop including it inskbuff.hat all. The first patch is also prereq for the whole series.
* #3: Improve cacheline locality for users of the Page Pool frag API.
* #4-6: Use direct cache recycling more aggressively, when it is safe obviously. In addition, make sure nobody wants to use Page Pool API with disabled interrupts.
Quoted 1 line
[...]
Here is the summary with links:
- [net-next,v4,1/6] page_pool: split types and declarations from page_pool.h
https://git.kernel.org/netdev/net-next/c/a9ca9f9ceff3 - [net-next,v4,2/6] net: skbuff: don't include <net/page_pool/types.h> to <linux/skbuff.h> https://git.kernel.org/netdev/net-next/c/75eaf63ea7af - [net-next,v4,3/6] page_pool: place frag_* fields in one cacheline https://git.kernel.org/netdev/net-next/c/06d0fbdad612 - [net-next,v4,4/6] net: skbuff: avoid accessing page_pool if !napi_safe when returning page https://git.kernel.org/netdev/net-next/c/5b899c33b3b8 - [net-next,v4,5/6] page_pool: add a lockdep check for recycling in hardirq https://git.kernel.org/netdev/net-next/c/ff4e538c8c3e - [net-next,v4,6/6] net: skbuff: always try to recycle PP pages directly when in softirq https://git.kernel.org/netdev/net-next/c/4a36d0180c45
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
Re: [PATCH net-next v4 5/6] page_pool: add a lockdep check for recycling in hardirq
In reply to Alexander DuyckFrom: Alexander Duyck <[email protected]>
Date: Tue, 8 Aug 2023 06:45:26 -0700
Quoted 73 lines
Quoted 71 lines · Alexander Lobakin
From: Alexander H Duyck <[email protected]>
Date: Mon, 07 Aug 2023 07:48:54 -0700Quoted 66 lines · Alexander Lobakin
Quoted 47 lines
From: Jakub Kicinski <[email protected]>
Page pool use in hardirq is prohibited, add debug checks to catch misuses. IIRC we previously discussed using
DEBUG_NET_WARN_ON_ONCE()for this, but there were concerns that people will haveDEBUG_NETenabled in perf testing. I don't think anyone enables lockdep in perf testing, so use lockdep to avoid pushback and arguing :)Signed-off-by Jakub Kicinski <[email protected]>Signed-off-by Alexander Lobakin <[email protected]>--- include/linux/lockdep.h | 7 +++++++ net/core/page_pool.c | 2 ++ 2 files changed, 9 insertions(+)include/linux/lockdep.h +7
-0@@ -625,6 +625,12 @@ do { \WARN_ON_ONCE (__lockdep_enabled && !this_cpu_read (hardirq_context)); \ } while (0) +#define lockdep_assert_no_hardirq () \ +do { \ + WARN_ON_ONCE(__lockdep_enabled && (this_cpu_read(hardirq_context) || \ + !this_cpu_read(hardirqs_enabled))); \ +} while (0) +#define lockdep_assert_preemption_enabled () \ do { \ WARN_ON_ONCE(IS_ENABLED(CONFIG_PREEMPT_COUNT) && \@@ -659,6 +665,7 @@ do { \# define lockdep_assert_irqs_enabled () do { } while (0)# define lockdep_assert_irqs_disabled () do { } while (0)# define lockdep_assert_in_irq () do { } while (0) +# define lockdep_assert_no_hardirq () do { } while (0)# define lockdep_assert_preemption_enabled () do { } while (0)# define lockdep_assert_preemption_disabled () do { } while (0)net/core/page_pool.c +0
-0net/core/page_pool.c static __always_inline struct page * · line 594
Quoted 8 lines
net/core/page_pool.c +2
-0@@ -587,6 +587,8 @@ static __always_inline struct page * __page_pool_put_page(struct page_pool *pool, struct page *page, unsigned int dma_sync_size, bool allow_direct) { +lockdep_assert_no_hardirq (); +/* This allocator is optimized for the XDP mode that uses * one-frame-per-page, but have fallbacks that act like the * regular page allocator APIs. So two points.
First could we look at moving this inside the if statement just before we return the page, as there isn't a risk until we get into that path of needing a lock.
Secondly rather than returning an error is there any reason why we couldn't just look at not returning page and instead just drop into the release path which wouldn't take the locks in the first place? Either
Quoted 8 lines
Quoted 2 lines
That is exception path to quickly catch broken drivers and fix them, why bother? It's not something we have to live with.
My concern is that the current "fix" consists of stalling a Tx ring. We need to have a way to allow forward progress when somebody mixes
xdp_frameand skb traffic as I suspect we will end up with a number of devices doing this since they cannot handle recycling the pages in hardirq context.
You could've seen that several vendors already disabled recycling XDP buffers when in hardirq (= netpoll) in their drivers. hardirq is in general not for networking-related operations.
Quoted 6 lines
The only reason why the skbs don't have the problem is that they are queued and then cleaned up in the
net_tx_action. That is why I wonder if we shouldn't look at adding some sort of support for doing something like that withxdp_frameas well. Something like adev_kfree_pp_page_anyto go along with thedev_kfree_skb_any.
I still don't get why we may need to clean XDP buffers in hardirq, maybe someone could give me some links to read why we may need this and how that happens? netpoll is a very specific thing for some debug operations, isn't it? XDP shouldn't in general be enabled when this happens, should it?
(unrelated: 6:58 AM West Coast, you use to wake up early or traveling?
:D)
Thanks,
Olek
Re: [PATCH net-next v4 5/6] page_pool: add a lockdep check for recycling in hardirq
Quoted 86 lines · Alexander Lobakin
From: Alexander Duyck <[email protected]>
Date: Tue, 8 Aug 2023 06:45:26 -0700Quoted 73 lines
Quoted 71 lines · Alexander Lobakin
From: Alexander H Duyck <[email protected]>
Date: Mon, 07 Aug 2023 07:48:54 -0700Quoted 66 lines · Alexander Lobakin
Quoted 47 lines
From: Jakub Kicinski <[email protected]>
Page pool use in hardirq is prohibited, add debug checks to catch misuses. IIRC we previously discussed using
DEBUG_NET_WARN_ON_ONCE()for this, but there were concerns that people will haveDEBUG_NETenabled in perf testing. I don't think anyone enables lockdep in perf testing, so use lockdep to avoid pushback and arguing :)Signed-off-by Jakub Kicinski <[email protected]>Signed-off-by Alexander Lobakin <[email protected]>--- include/linux/lockdep.h | 7 +++++++ net/core/page_pool.c | 2 ++ 2 files changed, 9 insertions(+)include/linux/lockdep.h +7
-0@@ -625,6 +625,12 @@ do { \WARN_ON_ONCE (__lockdep_enabled && !this_cpu_read (hardirq_context)); \ } while (0) +#define lockdep_assert_no_hardirq () \ +do { \ + WARN_ON_ONCE(__lockdep_enabled && (this_cpu_read(hardirq_context) || \ + !this_cpu_read(hardirqs_enabled))); \ +} while (0) +#define lockdep_assert_preemption_enabled () \ do { \ WARN_ON_ONCE(IS_ENABLED(CONFIG_PREEMPT_COUNT) && \@@ -659,6 +665,7 @@ do { \# define lockdep_assert_irqs_enabled () do { } while (0)# define lockdep_assert_irqs_disabled () do { } while (0)# define lockdep_assert_in_irq () do { } while (0) +# define lockdep_assert_no_hardirq () do { } while (0)# define lockdep_assert_preemption_enabled () do { } while (0)# define lockdep_assert_preemption_disabled () do { } while (0)net/core/page_pool.c +0
-0net/core/page_pool.c static __always_inline struct page * · line 594
Quoted 8 lines
net/core/page_pool.c +2
-0@@ -587,6 +587,8 @@ static __always_inline struct page * __page_pool_put_page(struct page_pool *pool, struct page *page, unsigned int dma_sync_size, bool allow_direct) { +lockdep_assert_no_hardirq (); +/* This allocator is optimized for the XDP mode that uses * one-frame-per-page, but have fallbacks that act like the * regular page allocator APIs. So two points.
First could we look at moving this inside the if statement just before we return the page, as there isn't a risk until we get into that path of needing a lock.
Secondly rather than returning an error is there any reason why we couldn't just look at not returning page and instead just drop into the release path which wouldn't take the locks in the first place? Either
Quoted 8 lines
Quoted 2 lines
That is exception path to quickly catch broken drivers and fix them, why bother? It's not something we have to live with.
My concern is that the current "fix" consists of stalling a Tx ring. We need to have a way to allow forward progress when somebody mixes
xdp_frameand skb traffic as I suspect we will end up with a number of devices doing this since they cannot handle recycling the pages in hardirq context.
Quoted 3 lines
You could've seen that several vendors already disabled recycling XDP buffers when in hardirq (= netpoll) in their drivers. hardirq is in general not for networking-related operations.
The whole idea behind the netpoll cleanup is to get the Tx buffers out of the way so that we can transmit even after the system has crashed. The idea isn't to transmit XDP buffers, but to get the buffers out of the way in the cases where somebody is combining both xdp_frame and sk_buff on the same queue due to a limited number of rings being present on the device.
My concern is that at some point in the near future somebody is going to have a system crash and instead of being able to get the crash log message out via their netconsole it is going to get cut off because the driver stopped cleaning the Tx ring because somebody was also using it as an XDP redirect destination.
Quoted 7 lines
Quoted 6 lines
The only reason why the skbs don't have the problem is that they are queued and then cleaned up in the
net_tx_action. That is why I wonder if we shouldn't look at adding some sort of support for doing something like that withxdp_frameas well. Something like adev_kfree_pp_page_anyto go along with thedev_kfree_skb_any.
Quoted 5 lines
I still don't get why we may need to clean XDP buffers in hardirq, maybe someone could give me some links to read why we may need this and how that happens? netpoll is a very specific thing for some debug operations, isn't it? XDP shouldn't in general be enabled when this happens, should it?
I think I kind of explained it above. It isn't so much about cleaning the XDP buffers as getting them off of the ring and out of the way. If we block a Tx queue because of an XDP buffer then we cannot use that Tx queue. I would be good with us just deferring the cleanup like we do with an sk_buff in dev_kfree_skb_irq, the only issue is we don't have the ability to put them on a queue since they don't have prev/next pointers.
I suppose an alternative to cleaning them might be to make a mandatory requirement that you cannot support netpoll and mix xdp_frame and sk_buff on the same queue. If we enforced that then my concern about them blocking a queue would be addressed.
Quoted 2 lines
(unrelated: 6:58 AM West Coast, you use to wake up early or traveling?
:D)
I am usually up pretty early, especially this time of year. Sunrise here is 6AM and I am usually up a little before that.. :)
From: Patchwork-Bot+netdevbpf <[email protected]>
Date: Mon, 07 Aug 2023 20:20:23 +0000
Quoted 4 lines
Hello:
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Just got back from the long weekend and saw that mail, nice :D Thanks!
Quoted 31 lines · On Fri, 4 Aug 2023 20:05:23 +0200 you wrote:
Quoted 13 lines
That initially was a spin-off of the IAVF PP series[0], but has grown (and shrunk) since then a bunch. In fact, it consists of three semi-independent blocks:
* #1-2: Compile-time optimization. Split
page_pool.hinto 2 headers to not overbloat the consumers not needing complex inline helpers and then stop including it inskbuff.hat all. The first patch is also prereq for the whole series.
* #3: Improve cacheline locality for users of the Page Pool frag API.
* #4-6: Use direct cache recycling more aggressively, when it is safe obviously. In addition, make sure nobody wants to use Page Pool API with disabled interrupts.Quoted 1 line
[...]
Here is the summary with links:
- [net-next,v4,1/6]page_pool: split types and declarations frompage_pool.hhttps://git.kernel.org/netdev/net-next/c/a9ca9f9ceff3 - [net-next,v4,2/6] net: skbuff: don't include <net/page_pool/types.h> to <linux/skbuff.h> https://git.kernel.org/netdev/net-next/c/75eaf63ea7af - [net-next,v4,3/6] page_pool: place frag_* fields in one cacheline https://git.kernel.org/netdev/net-next/c/06d0fbdad612 - [net-next,v4,4/6] net: skbuff: avoid accessing page_pool if !napi_safe when returning page https://git.kernel.org/netdev/net-next/c/5b899c33b3b8 - [net-next,v4,5/6] page_pool: add a lockdep check for recycling in hardirq https://git.kernel.org/netdev/net-next/c/ff4e538c8c3e - [net-next,v4,6/6] net: skbuff: always try to recycle PP pages directly when in softirq https://git.kernel.org/netdev/net-next/c/4a36d0180c45
Quoted 1 line
You are awesome, thank you!
Thanks,
Olek
Re: [PATCH net-next v4 5/6] page_pool: add a lockdep check for recycling in hardirq
In reply to Alexander DuyckFrom: Alexander Duyck <[email protected]>
Date: Tue, 8 Aug 2023 07:52:32 -0700
Quoted 5 lines
Quoted 3 lines · Alexander Lobakin
From: Alexander Duyck <[email protected]>
Date: Tue, 8 Aug 2023 06:45:26 -0700
[...]
Quoted 17 lines
Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
Secondly rather than returning an error is there any reason why we couldn't just look at not returning page and instead just drop into the release path which wouldn't take the locks in the first place? Either
Quoted 8 lines
Quoted 2 lines
That is exception path to quickly catch broken drivers and fix them, why bother? It's not something we have to live with.
My concern is that the current "fix" consists of stalling a Tx ring. We need to have a way to allow forward progress when somebody mixes
xdp_frameand skb traffic as I suspect we will end up with a number of devices doing this since they cannot handle recycling the pages in hardirq context.Quoted 3 lines
You could've seen that several vendors already disabled recycling XDP buffers when in hardirq (= netpoll) in their drivers. hardirq is in general not for networking-related operations.
Quoted 6 lines
The whole idea behind the netpoll cleanup is to get the Tx buffers out of the way so that we can transmit even after the system has crashed. The idea isn't to transmit XDP buffers, but to get the buffers out of the way in the cases where somebody is combining both
xdp_frameandsk_buffon the same queue due to a limited number of rings being present on the device.
I see now, thanks a lot!
Quoted 28 lines
My concern is that at some point in the near future somebody is going to have a system crash and instead of being able to get the crash log message out via their netconsole it is going to get cut off because the driver stopped cleaning the Tx ring because somebody was also using it as an XDP redirect destination.
Quoted 7 lines
Quoted 6 lines
The only reason why the skbs don't have the problem is that they are queued and then cleaned up in the
net_tx_action. That is why I wonder if we shouldn't look at adding some sort of support for doing something like that withxdp_frameas well. Something like adev_kfree_pp_page_anyto go along with thedev_kfree_skb_any.Quoted 5 lines
I still don't get why we may need to clean XDP buffers in hardirq, maybe someone could give me some links to read why we may need this and how that happens? netpoll is a very specific thing for some debug operations, isn't it? XDP shouldn't in general be enabled when this happens, should it?
I think I kind of explained it above. It isn't so much about cleaning the XDP buffers as getting them off of the ring and out of the way. If we block a Tx queue because of an XDP buffer then we cannot use that Tx queue. I would be good with us just deferring the cleanup like we do with an
sk_buffindev_kfree_skb_irq, the only issue is we don't have the ability to put them on a queue since they don't have prev/next pointers.
Quoted 4 lines
I suppose an alternative to cleaning them might be to make a mandatory requirement that you cannot support netpoll and mix
xdp_frameandsk_buffon the same queue. If we enforced that then my concern about them blocking a queue would be addressed.
I'm leaning more towards this one TBH. I don't feel sole netpoll as a solid argument for introducing XDP frame deferred queues :s
Quoted 6 lines
Quoted 3 lines
(unrelated: 6:58 AM West Coast, you use to wake up early or traveling?
:D)I am usually up pretty early, especially this time of year. Sunrise here is 6AM and I am usually up a little before that.. :)
Nice!
Thanks,
Olek
Re: [PATCH net-next v4 5/6] page_pool: add a lockdep check for recycling in hardirq
In reply to Alexander H DuyckFrom: Alexander H Duyck <[email protected]>
Date: Mon, 07 Aug 2023 07:48:54 -0700
Quoted 59 lines · Alexander Lobakin
Quoted 47 lines
From: Jakub Kicinski <[email protected]>
Page pool use in hardirq is prohibited, add debug checks to catch misuses. IIRC we previously discussed using
DEBUG_NET_WARN_ON_ONCE()for this, but there were concerns that people will haveDEBUG_NETenabled in perf testing. I don't think anyone enables lockdep in perf testing, so use lockdep to avoid pushback and arguing :)Signed-off-by Jakub Kicinski <[email protected]>Signed-off-by Alexander Lobakin <[email protected]>--- include/linux/lockdep.h | 7 +++++++ net/core/page_pool.c | 2 ++ 2 files changed, 9 insertions(+)include/linux/lockdep.h +7
-0@@ -625,6 +625,12 @@ do { \WARN_ON_ONCE (__lockdep_enabled && !this_cpu_read (hardirq_context)); \ } while (0) +#define lockdep_assert_no_hardirq () \ +do { \ + WARN_ON_ONCE(__lockdep_enabled && (this_cpu_read(hardirq_context) || \ + !this_cpu_read(hardirqs_enabled))); \ +} while (0) +#define lockdep_assert_preemption_enabled () \ do { \ WARN_ON_ONCE(IS_ENABLED(CONFIG_PREEMPT_COUNT) && \@@ -659,6 +665,7 @@ do { \# define lockdep_assert_irqs_enabled () do { } while (0)# define lockdep_assert_irqs_disabled () do { } while (0)# define lockdep_assert_in_irq () do { } while (0) +# define lockdep_assert_no_hardirq () do { } while (0)# define lockdep_assert_preemption_enabled () do { } while (0)# define lockdep_assert_preemption_disabled () do { } while (0)net/core/page_pool.c +0
-0net/core/page_pool.c static __always_inline struct page * · line 594
Quoted 8 lines
net/core/page_pool.c +2
-0@@ -587,6 +587,8 @@ static __always_inline struct page * __page_pool_put_page(struct page_pool *pool, struct page *page, unsigned int dma_sync_size, bool allow_direct) { +lockdep_assert_no_hardirq (); +/* This allocator is optimized for the XDP mode that uses * one-frame-per-page, but have fallbacks that act like the * regular page allocator APIs. So two points.
Quoted 7 lines
First could we look at moving this inside the if statement just before we return the page, as there isn't a risk until we get into that path of needing a lock.
Secondly rather than returning an error is there any reason why we couldn't just look at not returning page and instead just drop into the release path which wouldn't take the locks in the first place? Either
That is exception path to quickly catch broken drivers and fix them, why bother? It's not something we have to live with.
Quoted 3 lines
that or I would even be good with some combination of the two where we threw a warning, but still just dropped the page so we reduce our risk further of actually locking things up.
Thanks,
Olek
Re: [PATCH net-next v4 5/6] page_pool: add a lockdep check for recycling in hardirq
Quoted 67 lines · Alexander Lobakin
From: Alexander H Duyck <[email protected]>
Date: Mon, 07 Aug 2023 07:48:54 -0700Quoted 63 lines · Alexander Lobakin
Quoted 47 lines
From: Jakub Kicinski <[email protected]>
Page pool use in hardirq is prohibited, add debug checks to catch misuses. IIRC we previously discussed using
DEBUG_NET_WARN_ON_ONCE()for this, but there were concerns that people will haveDEBUG_NETenabled in perf testing. I don't think anyone enables lockdep in perf testing, so use lockdep to avoid pushback and arguing :)Signed-off-by Jakub Kicinski <[email protected]>Signed-off-by Alexander Lobakin <[email protected]>--- include/linux/lockdep.h | 7 +++++++ net/core/page_pool.c | 2 ++ 2 files changed, 9 insertions(+)include/linux/lockdep.h +7
-0@@ -625,6 +625,12 @@ do { \WARN_ON_ONCE (__lockdep_enabled && !this_cpu_read (hardirq_context)); \ } while (0) +#define lockdep_assert_no_hardirq () \ +do { \ + WARN_ON_ONCE(__lockdep_enabled && (this_cpu_read(hardirq_context) || \ + !this_cpu_read(hardirqs_enabled))); \ +} while (0) +#define lockdep_assert_preemption_enabled () \ do { \ WARN_ON_ONCE(IS_ENABLED(CONFIG_PREEMPT_COUNT) && \@@ -659,6 +665,7 @@ do { \# define lockdep_assert_irqs_enabled () do { } while (0)# define lockdep_assert_irqs_disabled () do { } while (0)# define lockdep_assert_in_irq () do { } while (0) +# define lockdep_assert_no_hardirq () do { } while (0)# define lockdep_assert_preemption_enabled () do { } while (0)# define lockdep_assert_preemption_disabled () do { } while (0)net/core/page_pool.c +0
-0net/core/page_pool.c static __always_inline struct page * · line 594
Quoted 8 lines
net/core/page_pool.c +2
-0@@ -587,6 +587,8 @@ static __always_inline struct page * __page_pool_put_page(struct page_pool *pool, struct page *page, unsigned int dma_sync_size, bool allow_direct) { +lockdep_assert_no_hardirq (); +/* This allocator is optimized for the XDP mode that uses * one-frame-per-page, but have fallbacks that act like the * regular page allocator APIs. So two points.
First could we look at moving this inside the if statement just before we return the page, as there isn't a risk until we get into that path of needing a lock.
Quoted 6 lines
Quoted 3 lines
Secondly rather than returning an error is there any reason why we couldn't just look at not returning page and instead just drop into the release path which wouldn't take the locks in the first place? Either
That is exception path to quickly catch broken drivers and fix them, why bother? It's not something we have to live with.
My concern is that the current "fix" consists of stalling a Tx ring. We need to have a way to allow forward progress when somebody mixes xdp_frame and skb traffic as I suspect we will end up with a number of devices doing this since they cannot handle recycling the pages in hardirq context.
The only reason why the skbs don't have the problem is that they are queued and then cleaned up in the net_tx_action. That is why I wonder if we shouldn't look at adding some sort of support for doing something like that with xdp_frame as well. Something like a dev_kfree_pp_page_any to go along with the dev_kfree_skb_any.
Re: [PATCH net-next v4 5/6] page_pool: add a lockdep check for recycling in hardirq
In reply to Alexander LobakinQuoted 66 lines · Alexander Lobakin
From: Alexander Duyck <[email protected]>
Date: Tue, 8 Aug 2023 07:52:32 -0700Quoted 5 lines
Quoted 3 lines · Alexander Lobakin
From: Alexander Duyck <[email protected]>
Date: Tue, 8 Aug 2023 06:45:26 -0700[...]
Quoted 17 lines
Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
Secondly rather than returning an error is there any reason why we couldn't just look at not returning page and instead just drop into the release path which wouldn't take the locks in the first place? Either
Quoted 8 lines
Quoted 2 lines
That is exception path to quickly catch broken drivers and fix them, why bother? It's not something we have to live with.
My concern is that the current "fix" consists of stalling a Tx ring. We need to have a way to allow forward progress when somebody mixes
xdp_frameand skb traffic as I suspect we will end up with a number of devices doing this since they cannot handle recycling the pages in hardirq context.Quoted 3 lines
You could've seen that several vendors already disabled recycling XDP buffers when in hardirq (= netpoll) in their drivers. hardirq is in general not for networking-related operations.
Quoted 6 lines
The whole idea behind the netpoll cleanup is to get the Tx buffers out of the way so that we can transmit even after the system has crashed. The idea isn't to transmit XDP buffers, but to get the buffers out of the way in the cases where somebody is combining both
xdp_frameandsk_buffon the same queue due to a limited number of rings being present on the device.I see now, thanks a lot!
Quoted 28 lines
My concern is that at some point in the near future somebody is going to have a system crash and instead of being able to get the crash log message out via their netconsole it is going to get cut off because the driver stopped cleaning the Tx ring because somebody was also using it as an XDP redirect destination.
Quoted 7 lines
Quoted 6 lines
The only reason why the skbs don't have the problem is that they are queued and then cleaned up in the
net_tx_action. That is why I wonder if we shouldn't look at adding some sort of support for doing something like that withxdp_frameas well. Something like adev_kfree_pp_page_anyto go along with thedev_kfree_skb_any.Quoted 5 lines
I still don't get why we may need to clean XDP buffers in hardirq, maybe someone could give me some links to read why we may need this and how that happens? netpoll is a very specific thing for some debug operations, isn't it? XDP shouldn't in general be enabled when this happens, should it?
I think I kind of explained it above. It isn't so much about cleaning the XDP buffers as getting them off of the ring and out of the way. If we block a Tx queue because of an XDP buffer then we cannot use that Tx queue. I would be good with us just deferring the cleanup like we do with an
sk_buffindev_kfree_skb_irq, the only issue is we don't have the ability to put them on a queue since they don't have prev/next pointers.
Quoted 7 lines
Quoted 4 lines
I suppose an alternative to cleaning them might be to make a mandatory requirement that you cannot support netpoll and mix
xdp_frameandsk_buffon the same queue. If we enforced that then my concern about them blocking a queue would be addressed.I'm leaning more towards this one TBH. I don't feel sole netpoll as a solid argument for introducing XDP frame deferred queues :s
That was kind of my line of thought as well. That is why I was thinking that instead of bothering with a queue it might work just as well to just throw all recycling out the window and just call put_page if we are dealing with XDP in netpoll and just force it into the free path. Then it becomes more of an "_any" type handler.