devlink: Add shared memory pool eswitch attribute
Subsystems (5)
RFC PATCH v3 1/2 devlink: Add shared memory pool eswitch attribute
Add eswitch attribute spool_size for shared memory pool size.
When using switchdev mode, the representor ports handles the slow path traffic, the traffic that can't be offloaded will be redirected to the representor port for processing. Memory consumption of the representor port's rx buffer can grow to several GB when scaling to 1k VFs reps. For example, in mlx5 driver, each RQ, with a typical 1K descriptors, consumes 3MB of DMA memory for packet buffer in WQEs, and with four channels, it consumes 4 * 3MB * 1024 = 12GB of memory. And since rep ports are for slow path traffic, most of these rx DMA memory are idle.
Add spool_size configuration, allowing multiple representor ports to share a rx memory buffer pool. When enabled, individual representor doesn't need to allocate its dedicated rx buffer, but just pointing its rq to the memory pool. This could make the memory being better utilized. The spool_size represents the number of bytes of the memory pool. Users can adjust it based on how many reps, total system memory, or performance expectation.
An example use case:
$ devlink dev eswitch set pci/0000:08:00.0 mode switchdev \ spool-size 4096000 $ devlink dev eswitch show pci/0000:08:00.0 pci/0000:08:00.0: mode legacy inline-mode none encap-mode basic \ spool-size 4096000
Disable the shared memory pool by setting spool_size to 0.
---
v3: feedback from Jakub
- introduce 1 attribute instead of 2
- use spool_size == 0 to disable
- spool_size as byte unit, not counts
Question about ENODOCS:
where to add this? the only document about devlink attr is at iproute2 Do I add a new file Documentation/networking/devlink/devlink-eswitch-attr.rst?
--- Documentation/netlink/specs/devlink.yaml | 4 ++++ include/net/devlink.h | 3 +++ include/uapi/linux/devlink.h | 1 + net/devlink/dev.c | 21 +++++++++++++++++++++ net/devlink/netlink_gen.c | 5 +++-- 5 files changed, 32 insertions(+), 2 deletions(-)
Documentation/netlink/specs/devlink.yaml +4 -0
@@ -429,6 +429,9 @@ attribute-sets: name: eswitch-encap-mode type: u8 enum: eswitch-encap-mode + - + name: eswitch-spool-size + type: u32 - name: resource-list type: nest
@@ -1555,6 +1558,7 @@ operations: - eswitch-mode - eswitch-inline-mode - eswitch-encap-mode + - eswitch-spool-size - name: eswitch-set
include/net/devlink.h +3 -0
@@ -1327,6 +1327,9 @@ struct devlink_ops {int (*eswitch_encap_mode_set)(struct devlink *devlink,enum devlink_eswitch_encap_mode encap_mode,struct netlink_ext_ack *extack); +int (*eswitch_spool_size_get)(struct devlink *devlink,u32 *p_size); +int (*eswitch_spool_size_set)(struct devlink *devlink,u32 size, +struct netlink_ext_ack *extack);int (*info_get)(struct devlink *devlink,struct devlink_info_req *req,struct netlink_ext_ack *extack);/**
include/uapi/linux/devlink.h +1 -0
@@ -614,6 +614,7 @@ enum devlink_attr {DEVLINK_ATTR_REGION_DIRECT ,/* flag */ +DEVLINK_ATTR_ESWITCH_SPOOL_SIZE ,/* u32 */ /* add new attributes above here, update the policy in devlink.c */ __DEVLINK_ATTR_MAX,
net/devlink/dev.c +21 -0
@@ -633,6 +633,7 @@ static int devlink_nl_eswitch_fill(struct sk_buff *msg, struct devlink *devlink, {const struct devlink_ops *ops = devlink->ops;enum devlink_eswitch_encap_mode encap_mode; +u32 spool_size;u8 inline_mode;void *hdr;int err =0 ;
@@ -674,6 +675,15 @@ static int devlink_nl_eswitch_fill(struct sk_buff *msg, struct devlink *devlink, goto nla_put_failure; } +if (ops->eswitch_spool_size_get) { + err = ops->eswitch_spool_size_get (devlink, &spool_size); +if (err) + goto nla_put_failure; + err =nla_put_u32 (msg,DEVLINK_ATTR_ESWITCH_SPOOL_SIZE , spool_size); +if (err) + goto nla_put_failure; + } +genlmsg_end (msg, hdr);return 0 ;
@@ -708,10 +718,21 @@ int devlink_nl_eswitch_set_doit(struct sk_buff *skb, struct genl_info *info)struct devlink *devlink = info->user_ptr[0 ];const struct devlink_ops *ops = devlink->ops;enum devlink_eswitch_encap_mode encap_mode; +u32 spool_size;u8 inline_mode;int err =0 ;u16 mode; +if (info->attrs[DEVLINK_ATTR_ESWITCH_SPOOL_SIZE ]) { +if (!ops->eswitch_spool_size_set) +return -EOPNOTSUPP ; + spool_size =nla_get_u32 (info->attrs[DEVLINK_ATTR_ESWITCH_SPOOL_SIZE ]); + err = ops->eswitch_spool_size_set (devlink, spool_size, + info->extack); +if (err) +return err; + } +if (info->attrs[DEVLINK_ATTR_ESWITCH_MODE ]) {if (!ops->eswitch_mode_set)return -EOPNOTSUPP ;
net/devlink/netlink_gen.c +3 -2
@@ -194,12 +194,13 @@ static const struct nla_policy devlink_eswitch_get_nl_policy[DEVLINK_ATTR_DEV_NA };/* DEVLINK_CMD_ESWITCH_SET - do */ -static const struct nla_policy devlink_eswitch_set_nl_policy[DEVLINK_ATTR_ESWITCH_ENCAP_MODE +1 ] = { +static const struct nla_policy devlink_eswitch_set_nl_policy[DEVLINK_ATTR_ESWITCH_SPOOL_SIZE +1 ] = { [DEVLINK_ATTR_BUS_NAME ] = { .type =NLA_NUL_STRING , }, [DEVLINK_ATTR_DEV_NAME ] = { .type =NLA_NUL_STRING , }, [DEVLINK_ATTR_ESWITCH_MODE ] =NLA_POLICY_MAX (NLA_U16 ,1 ), [DEVLINK_ATTR_ESWITCH_INLINE_MODE ] =NLA_POLICY_MAX (NLA_U16 ,3 ), [DEVLINK_ATTR_ESWITCH_ENCAP_MODE ] =NLA_POLICY_MAX (NLA_U8 ,1 ), + [DEVLINK_ATTR_ESWITCH_SPOOL_SIZE ] = { .type =NLA_U32 , }, };/* DEVLINK_CMD_DPIPE_TABLE_GET - do */
@@ -787,7 +788,7 @@ const struct genl_split_ops devlink_nl_ops[74] = { .doit = devlink_nl_eswitch_set_doit, .post_doit = devlink_nl_post_doit, .policy = devlink_eswitch_set_nl_policy, - .maxattr = DEVLINK_ATTR_ESWITCH_ENCAP_MODE, + .maxattr = DEVLINK_ATTR_ESWITCH_SPOOL_SIZE, .flags = GENL_ADMIN_PERM | GENL_CMD_CAP_DO, }, {
Signature · 1 line
2.38.1
RFC PATCH v3 2/2 net/mlx5e: Add eswitch shared descriptor devlink
Add devlink spool_size attribe support for eswitch shared memory pool. This is used to configure the shared memory pool for eswitch.
--- .../net/ethernet/mellanox/mlx5/core/devlink.c | 2 + .../net/ethernet/mellanox/mlx5/core/eswitch.h | 5 ++ .../mellanox/mlx5/core/eswitch_offloads.c | 49 +++++++++++++++++++ 3 files changed, 56 insertions(+)
drivers/net/ethernet/mellanox/mlx5/core/devlink.c +2 -0
@@ -312,6 +312,8 @@ static const struct devlink_ops mlx5_devlink_ops = { .eswitch_inline_mode_get = mlx5_devlink_eswitch_inline_mode_get, .eswitch_encap_mode_set = mlx5_devlink_eswitch_encap_mode_set, .eswitch_encap_mode_get = mlx5_devlink_eswitch_encap_mode_get, + .eswitch_spool_size_set = mlx5_devlink_eswitch_spool_size_set, + .eswitch_spool_size_get = mlx5_devlink_eswitch_spool_size_get, .rate_leaf_tx_share_set = mlx5_esw_devlink_rate_leaf_tx_share_set, .rate_leaf_tx_max_set = mlx5_esw_devlink_rate_leaf_tx_max_set, .rate_node_tx_share_set = mlx5_esw_devlink_rate_node_tx_share_set,
drivers/net/ethernet/mellanox/mlx5/core/eswitch.h +5 -0
@@ -378,6 +378,8 @@ struct mlx5_eswitch {struct mlx5_esw_functions esw_funcs;struct {u32 large_group_num; +u32 shared_rx_ring_counts; +bool enable_shared_rx_ring; } params;struct blocking_notifier_head n_head;struct xarray paired;
@@ -549,6 +551,9 @@ int mlx5_devlink_eswitch_encap_mode_set(struct devlink *devlink, struct netlink_ext_ack *extack);int mlx5_devlink_eswitch_encap_mode_get (struct devlink *devlink,enum devlink_eswitch_encap_mode *encap); +int mlx5_devlink_eswitch_spool_size_set (struct devlink *devlink,u32 size, +struct netlink_ext_ack *extack); +int mlx5_devlink_eswitch_spool_size_get (struct devlink *devlink,u32 *size);int mlx5_devlink_port_fn_hw_addr_get (struct devlink_port *port,u8 *hw_addr,int *hw_addr_len,struct netlink_ext_ack *extack);
drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c +49 -0
55 lines not on this page · raw message
Signature · 1 line
2.38.1
Jiri Pirko
maintainerQuoted 35 lines · Thu, Mar 07, 2024 at 12:12:52AM CET, [email protected] wrote:
Add eswitch attribute
spool_sizefor shared memory pool size.When using switchdev mode, the representor ports handles the slow path traffic, the traffic that can't be offloaded will be redirected to the representor port for processing. Memory consumption of the representor port's rx buffer can grow to several GB when scaling to 1k VFs reps. For example, in mlx5 driver, each RQ, with a typical 1K descriptors, consumes 3MB of DMA memory for packet buffer in WQEs, and with four channels, it consumes 4 * 3MB * 1024 = 12GB of memory. And since rep ports are for slow path traffic, most of these rx DMA memory are idle.
Add
spool_sizeconfiguration, allowing multiple representor ports to share a rx memory buffer pool. When enabled, individual representor doesn't need to allocate its dedicated rx buffer, but just pointing its rq to the memory pool. This could make the memory being better utilized. Thespool_sizerepresents the number of bytes of the memory pool. Users can adjust it based on how many reps, total system memory, or performance expectation.An example use case:
$ devlink dev eswitch set pci/0000:08:00.0 mode switchdev \ spool-size 4096000 $ devlink dev eswitch show pci/0000:08:00.0 pci/0000:08:00.0: mode legacy inline-mode none encap-mode basic \ spool-size 4096000Disable the shared memory pool by setting
spool_sizeto 0.Signed-off-by William Tu <[email protected]>---
v3: feedback from Jakub
- introduce 1 attribute instead of 2
- usespool_size== 0 to disable
-spool_sizeas byte unit, not counts
Quoted 3 lines
Question about ENODOCS:
where to add this? the only document about devlink attr is at iproute2 Do I add a new fileDocumentation/networking/devlink/devlink-eswitch-attr.rst?
Yeah. Please document the existing attrs as well while you are at it.
Quoted 49 lines
---
Documentation/netlink/specs/devlink.yaml | 4 ++++ include/net/devlink.h | 3 +++ include/uapi/linux/devlink.h | 1 + net/devlink/dev.c | 21 +++++++++++++++++++++ net/devlink/netlink_gen.c | 5 +++-- 5 files changed, 32 insertions(+), 2 deletions(-)Documentation/netlink/specs/devlink.yaml +4
-0@@ -429,6 +429,9 @@ attribute-sets: name: eswitch-encap-mode type: u8 enum: eswitch-encap-mode + - + name: eswitch-spool-size + type: u32 - name: resource-list type: nest@@ -1555,6 +1558,7 @@ operations: - eswitch-mode - eswitch-inline-mode - eswitch-encap-mode + - eswitch-spool-size - name: eswitch-setinclude/net/devlink.h +3
-0@@ -1327,6 +1327,9 @@ struct devlink_ops {int (*eswitch_encap_mode_set)(struct devlink *devlink,enum devlink_eswitch_encap_mode encap_mode,struct netlink_ext_ack *extack); +int (*eswitch_spool_size_get)(struct devlink *devlink,u32 *p_size); +int (*eswitch_spool_size_set)(struct devlink *devlink,u32 size, +struct netlink_ext_ack *extack);int (*info_get)(struct devlink *devlink,struct devlink_info_req *req,struct netlink_ext_ack *extack);/** include/uapi/linux/devlink.h +0
-0
include/uapi/linux/devlink.h enum devlink_attr { · line 618
Quoted 5 lines
include/uapi/linux/devlink.h +1
-0@@ -614,6 +614,7 @@ enum devlink_attr {DEVLINK_ATTR_REGION_DIRECT ,/* flag */ + DEVLINK_ATTR_ESWITCH_SPOOL_SIZE, /* u32 *//* add new attributes above here, update the policy in devlink.c */
While at it, could you please update this comment? It should say:
/* Add new attributes above here, update the spec in
* Documentation/netlink/specs/devlink.yaml and re-generate
* net/devlink/netlink_gen.c. */
As a separate patch please.
Quoted 31 lines
include/uapi/linux/devlink.h +0
-0__DEVLINK_ATTR_MAX,net/devlink/dev.c +10
-0@@ -633,6 +633,7 @@ static int devlink_nl_eswitch_fill(struct sk_buff *msg, struct devlink *devlink, {const struct devlink_ops *ops = devlink->ops;enum devlink_eswitch_encap_mode encap_mode; +u32 spool_size;u8 inline_mode;void *hdr;int err =0 ;@@ -674,6 +675,15 @@ static int devlink_nl_eswitch_fill(struct sk_buff *msg, struct devlink *devlink, goto nla_put_failure; } +if (ops->eswitch_spool_size_get) { + err = ops->eswitch_spool_size_get (devlink, &spool_size); +if (err) + goto nla_put_failure; + err =nla_put_u32 (msg,DEVLINK_ATTR_ESWITCH_SPOOL_SIZE , spool_size); +if (err) + goto nla_put_failure; + } +genlmsg_end (msg, hdr);return 0 ;
net/devlink/dev.c int devlink_nl_eswitch_set_doit(struct sk_buff *skb, struct genl_info *info) · line 727
Quoted 10 lines
net/devlink/dev.c +3
-0@@ -708,10 +718,21 @@ int devlink_nl_eswitch_set_doit(struct sk_buff *skb, struct genl_info *info)struct devlink *devlink = info->user_ptr[0 ];const struct devlink_ops *ops = devlink->ops;enum devlink_eswitch_encap_mode encap_mode; +u32 spool_size;u8 inline_mode;int err =0 ;u16 mode; +if (info->attrs[DEVLINK_ATTR_ESWITCH_SPOOL_SIZE ]) { +if (!ops->eswitch_spool_size_set)
Fill up extack msg here please.
Quoted 43 lines
net/devlink/dev.c +8
-0+return -EOPNOTSUPP ; + spool_size =nla_get_u32 (info->attrs[DEVLINK_ATTR_ESWITCH_SPOOL_SIZE ]); + err = ops->eswitch_spool_size_set (devlink, spool_size, + info->extack); +if (err) +return err; + } +if (info->attrs[DEVLINK_ATTR_ESWITCH_MODE ]) {if (!ops->eswitch_mode_set)return -EOPNOTSUPP ;net/devlink/netlink_gen.c +3
-2@@ -194,12 +194,13 @@ static const struct nla_policy devlink_eswitch_get_nl_policy[DEVLINK_ATTR_DEV_NA };/* DEVLINK_CMD_ESWITCH_SET - do */ -static const struct nla_policy devlink_eswitch_set_nl_policy[DEVLINK_ATTR_ESWITCH_ENCAP_MODE +1 ] = { +static const struct nla_policy devlink_eswitch_set_nl_policy[DEVLINK_ATTR_ESWITCH_SPOOL_SIZE +1 ] = { [DEVLINK_ATTR_BUS_NAME ] = { .type =NLA_NUL_STRING , }, [DEVLINK_ATTR_DEV_NAME ] = { .type =NLA_NUL_STRING , }, [DEVLINK_ATTR_ESWITCH_MODE ] =NLA_POLICY_MAX (NLA_U16 ,1 ), [DEVLINK_ATTR_ESWITCH_INLINE_MODE ] =NLA_POLICY_MAX (NLA_U16 ,3 ), [DEVLINK_ATTR_ESWITCH_ENCAP_MODE ] =NLA_POLICY_MAX (NLA_U8 ,1 ), + [DEVLINK_ATTR_ESWITCH_SPOOL_SIZE ] = { .type =NLA_U32 , }, };/* DEVLINK_CMD_DPIPE_TABLE_GET - do */ @@ -787,7 +788,7 @@ const struct genl_split_ops devlink_nl_ops[74] = { .doit = devlink_nl_eswitch_set_doit, .post_doit = devlink_nl_post_doit, .policy = devlink_eswitch_set_nl_policy, - .maxattr = DEVLINK_ATTR_ESWITCH_ENCAP_MODE, + .maxattr = DEVLINK_ATTR_ESWITCH_SPOOL_SIZE, .flags = GENL_ADMIN_PERM | GENL_CMD_CAP_DO, }, {Signature · 1 line
2.38.1
Quoted 39 lines · Jiri Pirko
External email: Use caution opening links or attachments
Quoted 35 lines · Thu, Mar 07, 2024 at 12:12:52AM CET, [email protected] wrote:
Add eswitch attribute
spool_sizefor shared memory pool size.When using switchdev mode, the representor ports handles the slow path traffic, the traffic that can't be offloaded will be redirected to the representor port for processing. Memory consumption of the representor port's rx buffer can grow to several GB when scaling to 1k VFs reps. For example, in mlx5 driver, each RQ, with a typical 1K descriptors, consumes 3MB of DMA memory for packet buffer in WQEs, and with four channels, it consumes 4 * 3MB * 1024 = 12GB of memory. And since rep ports are for slow path traffic, most of these rx DMA memory are idle.
Add
spool_sizeconfiguration, allowing multiple representor ports to share a rx memory buffer pool. When enabled, individual representor doesn't need to allocate its dedicated rx buffer, but just pointing its rq to the memory pool. This could make the memory being better utilized. Thespool_sizerepresents the number of bytes of the memory pool. Users can adjust it based on how many reps, total system memory, or performance expectation.An example use case:
$ devlink dev eswitch set pci/0000:08:00.0 mode switchdev \ spool-size 4096000 $ devlink dev eswitch show pci/0000:08:00.0 pci/0000:08:00.0: mode legacy inline-mode none encap-mode basic \ spool-size 4096000Disable the shared memory pool by setting
spool_sizeto 0.Signed-off-by William Tu <[email protected]>---
v3: feedback from Jakub
- introduce 1 attribute instead of 2
- usespool_size== 0 to disable
-spool_sizeas byte unit, not counts
Quoted 4 lines
Quoted 3 lines
Question about ENODOCS:
where to add this? the only document about devlink attr is at iproute2 Do I add a new fileDocumentation/networking/devlink/devlink-eswitch-attr.rst?Yeah. Please document the existing attrs as well while you are at it.
done.
Quoted 54 lines
Quoted 54 lines
---
Documentation/netlink/specs/devlink.yaml | 4 ++++ include/net/devlink.h | 3 +++ include/uapi/linux/devlink.h | 1 + net/devlink/dev.c | 21 +++++++++++++++++++++ net/devlink/netlink_gen.c | 5 +++-- 5 files changed, 32 insertions(+), 2 deletions(-)Documentation/netlink/specs/devlink.yaml +4
-0@@ -429,6 +429,9 @@ attribute-sets: name: eswitch-encap-mode type: u8 enum: eswitch-encap-mode + - + name: eswitch-spool-size + type: u32 - name: resource-list type: nest@@ -1555,6 +1558,7 @@ operations: - eswitch-mode - eswitch-inline-mode - eswitch-encap-mode + - eswitch-spool-size - name: eswitch-setinclude/net/devlink.h +3
-0@@ -1327,6 +1327,9 @@ struct devlink_ops {int (*eswitch_encap_mode_set)(struct devlink *devlink,enum devlink_eswitch_encap_mode encap_mode,struct netlink_ext_ack *extack); +int (*eswitch_spool_size_get)(struct devlink *devlink,u32 *p_size); +int (*eswitch_spool_size_set)(struct devlink *devlink,u32 size, +struct netlink_ext_ack *extack);int (*info_get)(struct devlink *devlink,struct devlink_info_req *req,struct netlink_ext_ack *extack);/** include/uapi/linux/devlink.h +0
-0@@ -614,6 +614,7 @@ enum devlink_attr { DEVLINK_ATTR_REGION_DIRECT, /* flag */
Quoted 7 lines
include/uapi/linux/devlink.h enum devlink_attr { · line 618
Quoted 2 lines
include/uapi/linux/devlink.h +1
-0+ DEVLINK_ATTR_ESWITCH_SPOOL_SIZE, /* u32 *//* add new attributes above here, update the policy in devlink.c */ While at it, could you please update this comment? It should say:
/* Add new attributes above here, update the spec in
*Documentation/netlink/specs/devlink.yamland re-generate
*net/devlink/netlink_gen.c. */
As a separate patch please.
done.
Quoted 39 lines
Quoted 39 lines
include/uapi/linux/devlink.h +0
-0__DEVLINK_ATTR_MAX,net/devlink/dev.c +11
-0@@ -633,6 +633,7 @@ static int devlink_nl_eswitch_fill(struct sk_buff *msg, struct devlink *devlink, {const struct devlink_ops *ops = devlink->ops;enum devlink_eswitch_encap_mode encap_mode; +u32 spool_size;u8 inline_mode;void *hdr;int err =0 ;@@ -674,6 +675,15 @@ static int devlink_nl_eswitch_fill(struct sk_buff *msg, struct devlink *devlink, goto nla_put_failure; } +if (ops->eswitch_spool_size_get) { + err = ops->eswitch_spool_size_get (devlink, &spool_size); +if (err) + goto nla_put_failure; + err =nla_put_u32 (msg,DEVLINK_ATTR_ESWITCH_SPOOL_SIZE , spool_size); +if (err) + goto nla_put_failure; + } +genlmsg_end (msg, hdr);return 0 ;@@ -708,10 +718,21 @@ int devlink_nl_eswitch_set_doit(struct sk_buff *skb, struct genl_info *info)struct devlink *devlink = info->user_ptr[0 ];const struct devlink_ops *ops = devlink->ops;enum devlink_eswitch_encap_mode encap_mode; +u32 spool_size;u8 inline_mode;int err =0 ;u16 mode;
Quoted 4 lines
net/devlink/dev.c int devlink_nl_eswitch_set_doit(struct sk_buff *skb, struct genl_info *info) · line 727
Quoted 2 lines
net/devlink/dev.c +2
-0+if (info->attrs[DEVLINK_ATTR_ESWITCH_SPOOL_SIZE ]) { +if (!ops->eswitch_spool_size_set)Fill up extack msg here please.
Will do it in next version, thanks
William
Quoted 9 lines · On Thu, 7 Mar 2024 01:12:52 +0200 William Tu wrote:
When using switchdev mode, the representor ports handles the slow path traffic, the traffic that can't be offloaded will be redirected to the representor port for processing. Memory consumption of the representor port's rx buffer can grow to several GB when scaling to 1k VFs reps. For example, in mlx5 driver, each RQ, with a typical 1K descriptors, consumes 3MB of DMA memory for packet buffer in WQEs, and with four channels, it consumes 4 * 3MB * 1024 = 12GB of memory. And since rep ports are for slow path traffic, most of these rx DMA memory are idle.
Quoted 7 lines
Add
spool_sizeconfiguration, allowing multiple representor ports to share a rx memory buffer pool. When enabled, individual representor doesn't need to allocate its dedicated rx buffer, but just pointing its rq to the memory pool. This could make the memory being better utilized. Thespool_sizerepresents the number of bytes of the memory pool. Users can adjust it based on how many reps, total system memory, or performance expectation.
We may need to wordsmith the docs once present but in general, FWIW: