* [PATCH net-next v2 0/2] net/smc: introduce ringbufs usage statistics @ 2024-08-07 7:59 Wen Gu 2024-08-07 7:59 ` [PATCH net-next v2 1/2] net/smc: introduce statistics for allocated ringbufs of link group Wen Gu 2024-08-07 7:59 ` [PATCH net-next v2 2/2] net/smc: introduce statistics for ringbufs usage of net namespace Wen Gu 0 siblings, 2 replies; 12+ messages in thread From: Wen Gu @ 2024-08-07 7:59 UTC (permalink / raw) To: wenjia, jaka, davem, edumazet, kuba, pabeni Cc: alibuda, tonylu, guwen, linux-kernel, linux-s390, netdev Currently, we have histograms that show the sizes of ringbufs that ever used by SMC connections. However, they are always incremental and since SMC allows the reuse of ringbufs, we cannot know the actual amount of ringbufs being allocated or actively used. So this patch set introduces statistics for the amount of ringbufs that actually allocated by link group and actively used by connections of a certain net namespace, so that we can react based on these memory usage information, e.g. active fallback to TCP. With appropriate adaptations of smc-tools, we can obtain these ringbufs usage information: $ smcr -d linkgroup LG-ID : 00000500 LG-Role : SERV LG-Type : ASYML VLAN : 0 PNET-ID : Version : 1 Conns : 0 Sndbuf : 12910592 B <- RMB : 12910592 B <- or $ smcr -d stats [...] RX Stats Data transmitted (Bytes) 869225943 (869.2M) Total requests 18494479 Buffer usage (Bytes) 12910592 (12.31M) <- [...] TX Stats Data transmitted (Bytes) 12760884405 (12.76G) Total requests 36988338 Buffer usage (Bytes) 12910592 (12.31M) <- [...] [...] Wen Gu (2): net/smc: introduce statistics for allocated ringbufs of link group net/smc: introduce statistics for ringbufs usage of net namespace include/uapi/linux/smc.h | 6 ++++ net/smc/smc_core.c | 72 ++++++++++++++++++++++++++++++++++------ net/smc/smc_core.h | 2 ++ net/smc/smc_stats.c | 8 +++++ net/smc/smc_stats.h | 28 +++++++++++----- 5 files changed, 96 insertions(+), 20 deletions(-) -- 2.32.0.3.g01195cf9f ^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH net-next v2 1/2] net/smc: introduce statistics for allocated ringbufs of link group 2024-08-07 7:59 [PATCH net-next v2 0/2] net/smc: introduce ringbufs usage statistics Wen Gu @ 2024-08-07 7:59 ` Wen Gu 2024-08-13 0:41 ` Jakub Kicinski 2024-08-07 7:59 ` [PATCH net-next v2 2/2] net/smc: introduce statistics for ringbufs usage of net namespace Wen Gu 1 sibling, 1 reply; 12+ messages in thread From: Wen Gu @ 2024-08-07 7:59 UTC (permalink / raw) To: wenjia, jaka, davem, edumazet, kuba, pabeni Cc: alibuda, tonylu, guwen, linux-kernel, linux-s390, netdev Currently we have the statistics on sndbuf/RMB sizes of all connections that have ever been on the link group, namely smc_stats_memsize. However these statistics are incremental and since the ringbufs of link group are allowed to be reused, we cannot know the actual allocated buffers through these. So here introduces the statistic on actual allocated ringbufs of the link group, it will be incremented when a new ringbuf is added into buf_list and decremented when it is deleted from buf_list. Signed-off-by: Wen Gu <guwen@linux.alibaba.com> --- include/uapi/linux/smc.h | 4 ++++ net/smc/smc_core.c | 50 ++++++++++++++++++++++++++++++++++++---- net/smc/smc_core.h | 2 ++ 3 files changed, 52 insertions(+), 4 deletions(-) diff --git a/include/uapi/linux/smc.h b/include/uapi/linux/smc.h index b531e3ef011a..d27b8dc50f90 100644 --- a/include/uapi/linux/smc.h +++ b/include/uapi/linux/smc.h @@ -127,6 +127,8 @@ enum { SMC_NLA_LGR_R_NET_COOKIE, /* u64 */ SMC_NLA_LGR_R_PAD, /* flag */ SMC_NLA_LGR_R_BUF_TYPE, /* u8 */ + SMC_NLA_LGR_R_SNDBUF_ALLOC, /* u64 */ + SMC_NLA_LGR_R_RMB_ALLOC, /* u64 */ __SMC_NLA_LGR_R_MAX, SMC_NLA_LGR_R_MAX = __SMC_NLA_LGR_R_MAX - 1 }; @@ -162,6 +164,8 @@ enum { SMC_NLA_LGR_D_V2_COMMON, /* nest */ SMC_NLA_LGR_D_EXT_GID, /* u64 */ SMC_NLA_LGR_D_PEER_EXT_GID, /* u64 */ + SMC_NLA_LGR_D_SNDBUF_ALLOC, /* u64 */ + SMC_NLA_LGR_D_DMB_ALLOC, /* u64 */ __SMC_NLA_LGR_D_MAX, SMC_NLA_LGR_D_MAX = __SMC_NLA_LGR_D_MAX - 1 }; diff --git a/net/smc/smc_core.c b/net/smc/smc_core.c index 71fb334d8234..b1ff44d72fe4 100644 --- a/net/smc/smc_core.c +++ b/net/smc/smc_core.c @@ -221,6 +221,35 @@ static void smc_lgr_unregister_conn(struct smc_connection *conn) write_unlock_bh(&lgr->conns_lock); } +static void smc_lgr_buf_list_add(struct smc_link_group *lgr, + bool is_rmb, + struct list_head *buf_list, + struct smc_buf_desc *buf_desc) +{ + list_add(&buf_desc->list, buf_list); + if (is_rmb) { + lgr->alloc_rmbs += buf_desc->len; + lgr->alloc_rmbs += + lgr->is_smcd ? sizeof(struct smcd_cdc_msg) : 0; + } else { + lgr->alloc_sndbufs += buf_desc->len; + } +} + +static void smc_lgr_buf_list_del(struct smc_link_group *lgr, + bool is_rmb, + struct smc_buf_desc *buf_desc) +{ + list_del(&buf_desc->list); + if (is_rmb) { + lgr->alloc_rmbs -= buf_desc->len; + lgr->alloc_rmbs -= + lgr->is_smcd ? sizeof(struct smcd_cdc_msg) : 0; + } else { + lgr->alloc_sndbufs -= buf_desc->len; + } +} + int smc_nl_get_sys_info(struct sk_buff *skb, struct netlink_callback *cb) { struct smc_nl_dmp_ctx *cb_ctx = smc_nl_dmp_ctx(cb); @@ -363,6 +392,12 @@ static int smc_nl_fill_lgr(struct smc_link_group *lgr, smc_target[SMC_MAX_PNETID_LEN] = 0; if (nla_put_string(skb, SMC_NLA_LGR_R_PNETID, smc_target)) goto errattr; + if (nla_put_u64_64bit(skb, SMC_NLA_LGR_R_SNDBUF_ALLOC, + lgr->alloc_sndbufs, SMC_NLA_LGR_R_PAD)) + goto errattr; + if (nla_put_u64_64bit(skb, SMC_NLA_LGR_R_RMB_ALLOC, + lgr->alloc_rmbs, SMC_NLA_LGR_R_PAD)) + goto errattr; if (lgr->smc_version > SMC_V1) { v2_attrs = nla_nest_start(skb, SMC_NLA_LGR_R_V2_COMMON); if (!v2_attrs) @@ -541,6 +576,12 @@ static int smc_nl_fill_smcd_lgr(struct smc_link_group *lgr, goto errattr; if (nla_put_u32(skb, SMC_NLA_LGR_D_CHID, smc_ism_get_chid(lgr->smcd))) goto errattr; + if (nla_put_u64_64bit(skb, SMC_NLA_LGR_D_SNDBUF_ALLOC, + lgr->alloc_sndbufs, SMC_NLA_LGR_D_PAD)) + goto errattr; + if (nla_put_u64_64bit(skb, SMC_NLA_LGR_D_DMB_ALLOC, + lgr->alloc_rmbs, SMC_NLA_LGR_D_PAD)) + goto errattr; memcpy(smc_pnet, lgr->smcd->pnetid, SMC_MAX_PNETID_LEN); smc_pnet[SMC_MAX_PNETID_LEN] = 0; if (nla_put_string(skb, SMC_NLA_LGR_D_PNETID, smc_pnet)) @@ -1138,7 +1179,7 @@ static void smcr_buf_unuse(struct smc_buf_desc *buf_desc, bool is_rmb, lock = is_rmb ? &lgr->rmbs_lock : &lgr->sndbufs_lock; down_write(lock); - list_del(&buf_desc->list); + smc_lgr_buf_list_del(lgr, is_rmb, buf_desc); up_write(lock); smc_buf_free(lgr, is_rmb, buf_desc); @@ -1377,7 +1418,7 @@ static void __smc_lgr_free_bufs(struct smc_link_group *lgr, bool is_rmb) buf_list = &lgr->sndbufs[i]; list_for_each_entry_safe(buf_desc, bf_desc, buf_list, list) { - list_del(&buf_desc->list); + smc_lgr_buf_list_del(lgr, is_rmb, buf_desc); smc_buf_free(lgr, is_rmb, buf_desc); } } @@ -2414,7 +2455,7 @@ static int __smc_buf_create(struct smc_sock *smc, bool is_smcd, bool is_rmb) SMC_STAT_RMB_SIZE(smc, is_smcd, is_rmb, bufsize); buf_desc->used = 1; down_write(lock); - list_add(&buf_desc->list, buf_list); + smc_lgr_buf_list_add(lgr, is_rmb, buf_list, buf_desc); up_write(lock); break; /* found */ } @@ -2496,7 +2537,8 @@ int smc_buf_create(struct smc_sock *smc, bool is_smcd) rc = __smc_buf_create(smc, is_smcd, true); if (rc && smc->conn.sndbuf_desc) { down_write(&smc->conn.lgr->sndbufs_lock); - list_del(&smc->conn.sndbuf_desc->list); + smc_lgr_buf_list_del(smc->conn.lgr, false, + smc->conn.sndbuf_desc); up_write(&smc->conn.lgr->sndbufs_lock); smc_buf_free(smc->conn.lgr, false, smc->conn.sndbuf_desc); smc->conn.sndbuf_desc = NULL; diff --git a/net/smc/smc_core.h b/net/smc/smc_core.h index d93cf51dbd7c..0db4e5f79ac4 100644 --- a/net/smc/smc_core.h +++ b/net/smc/smc_core.h @@ -281,6 +281,8 @@ struct smc_link_group { struct rw_semaphore sndbufs_lock; /* protects tx buffers */ struct list_head rmbs[SMC_RMBE_SIZES]; /* rx buffers */ struct rw_semaphore rmbs_lock; /* protects rx buffers */ + u64 alloc_sndbufs; /* stats of tx buffers */ + u64 alloc_rmbs; /* stats of rx buffers */ u8 id[SMC_LGR_ID_SIZE]; /* unique lgr id */ struct delayed_work free_work; /* delayed freeing of an lgr */ -- 2.32.0.3.g01195cf9f ^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH net-next v2 1/2] net/smc: introduce statistics for allocated ringbufs of link group 2024-08-07 7:59 ` [PATCH net-next v2 1/2] net/smc: introduce statistics for allocated ringbufs of link group Wen Gu @ 2024-08-13 0:41 ` Jakub Kicinski 2024-08-13 9:55 ` Wen Gu 0 siblings, 1 reply; 12+ messages in thread From: Jakub Kicinski @ 2024-08-13 0:41 UTC (permalink / raw) To: Wen Gu Cc: wenjia, jaka, davem, edumazet, pabeni, alibuda, tonylu, linux-kernel, linux-s390, netdev On Wed, 7 Aug 2024 15:59:38 +0800 Wen Gu wrote: > + if (nla_put_u64_64bit(skb, SMC_NLA_LGR_R_SNDBUF_ALLOC, > + lgr->alloc_sndbufs, SMC_NLA_LGR_R_PAD)) nla_put_uint() -- pw-bot: cr ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH net-next v2 1/2] net/smc: introduce statistics for allocated ringbufs of link group 2024-08-13 0:41 ` Jakub Kicinski @ 2024-08-13 9:55 ` Wen Gu 2024-08-13 14:40 ` Jakub Kicinski 0 siblings, 1 reply; 12+ messages in thread From: Wen Gu @ 2024-08-13 9:55 UTC (permalink / raw) To: Jakub Kicinski Cc: wenjia, jaka, davem, edumazet, pabeni, alibuda, tonylu, linux-kernel, linux-s390, netdev On 2024/8/13 08:41, Jakub Kicinski wrote: > On Wed, 7 Aug 2024 15:59:38 +0800 Wen Gu wrote: >> + if (nla_put_u64_64bit(skb, SMC_NLA_LGR_R_SNDBUF_ALLOC, >> + lgr->alloc_sndbufs, SMC_NLA_LGR_R_PAD)) > > nla_put_uint() Hi, Jakub. Thank you for reminder. I read the commit log and learned the advantages of this helper. But it seems that the support for corresponding user-space helpers hasn't kept up yet, e.g. can't find a helper like nla_get_uint in latest libnl. ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH net-next v2 1/2] net/smc: introduce statistics for allocated ringbufs of link group 2024-08-13 9:55 ` Wen Gu @ 2024-08-13 14:40 ` Jakub Kicinski 2024-08-13 15:13 ` Ido Schimmel 2024-08-14 3:10 ` Wen Gu 0 siblings, 2 replies; 12+ messages in thread From: Jakub Kicinski @ 2024-08-13 14:40 UTC (permalink / raw) To: Wen Gu Cc: wenjia, jaka, davem, edumazet, pabeni, alibuda, tonylu, linux-kernel, linux-s390, netdev On Tue, 13 Aug 2024 17:55:17 +0800 Wen Gu wrote: > On 2024/8/13 08:41, Jakub Kicinski wrote: > > On Wed, 7 Aug 2024 15:59:38 +0800 Wen Gu wrote: > >> + if (nla_put_u64_64bit(skb, SMC_NLA_LGR_R_SNDBUF_ALLOC, > >> + lgr->alloc_sndbufs, SMC_NLA_LGR_R_PAD)) > > > > nla_put_uint() > > Hi, Jakub. Thank you for reminder. > > I read the commit log and learned the advantages of this helper. > But it seems that the support for corresponding user-space helpers > hasn't kept up yet, e.g. can't find a helper like nla_get_uint in > latest libnl. Add it, then. ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH net-next v2 1/2] net/smc: introduce statistics for allocated ringbufs of link group 2024-08-13 14:40 ` Jakub Kicinski @ 2024-08-13 15:13 ` Ido Schimmel 2024-08-14 3:12 ` Wen Gu 2024-08-14 3:10 ` Wen Gu 1 sibling, 1 reply; 12+ messages in thread From: Ido Schimmel @ 2024-08-13 15:13 UTC (permalink / raw) To: Jakub Kicinski Cc: Wen Gu, wenjia, jaka, davem, edumazet, pabeni, alibuda, tonylu, linux-kernel, linux-s390, netdev, danieller On Tue, Aug 13, 2024 at 07:40:42AM -0700, Jakub Kicinski wrote: > On Tue, 13 Aug 2024 17:55:17 +0800 Wen Gu wrote: > > On 2024/8/13 08:41, Jakub Kicinski wrote: > > > On Wed, 7 Aug 2024 15:59:38 +0800 Wen Gu wrote: > > >> + if (nla_put_u64_64bit(skb, SMC_NLA_LGR_R_SNDBUF_ALLOC, > > >> + lgr->alloc_sndbufs, SMC_NLA_LGR_R_PAD)) > > > > > > nla_put_uint() > > > > Hi, Jakub. Thank you for reminder. > > > > I read the commit log and learned the advantages of this helper. > > But it seems that the support for corresponding user-space helpers > > hasn't kept up yet, e.g. can't find a helper like nla_get_uint in > > latest libnl. > > Add it, then. Danielle added one to libmnl: https://git.netfilter.org/libmnl/commit/?id=102942be401a99943b2c68981b238dadfa788f2d Intention is to use it in ethtool once it appears in a released version of libmnl. ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH net-next v2 1/2] net/smc: introduce statistics for allocated ringbufs of link group 2024-08-13 15:13 ` Ido Schimmel @ 2024-08-14 3:12 ` Wen Gu 2024-08-14 14:48 ` Jakub Kicinski 0 siblings, 1 reply; 12+ messages in thread From: Wen Gu @ 2024-08-14 3:12 UTC (permalink / raw) To: Ido Schimmel, Jakub Kicinski Cc: wenjia, jaka, davem, edumazet, pabeni, alibuda, tonylu, linux-kernel, linux-s390, netdev, danieller On 2024/8/13 23:13, Ido Schimmel wrote: > On Tue, Aug 13, 2024 at 07:40:42AM -0700, Jakub Kicinski wrote: >> On Tue, 13 Aug 2024 17:55:17 +0800 Wen Gu wrote: >>> On 2024/8/13 08:41, Jakub Kicinski wrote: >>>> On Wed, 7 Aug 2024 15:59:38 +0800 Wen Gu wrote: >>>>> + if (nla_put_u64_64bit(skb, SMC_NLA_LGR_R_SNDBUF_ALLOC, >>>>> + lgr->alloc_sndbufs, SMC_NLA_LGR_R_PAD)) >>>> >>>> nla_put_uint() >>> >>> Hi, Jakub. Thank you for reminder. >>> >>> I read the commit log and learned the advantages of this helper. >>> But it seems that the support for corresponding user-space helpers >>> hasn't kept up yet, e.g. can't find a helper like nla_get_uint in >>> latest libnl. >> >> Add it, then. > > Danielle added one to libmnl: > > https://git.netfilter.org/libmnl/commit/?id=102942be401a99943b2c68981b238dadfa788f2d > > Intention is to use it in ethtool once it appears in a released version > of libmnl. Thanks, that is a good example. ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH net-next v2 1/2] net/smc: introduce statistics for allocated ringbufs of link group 2024-08-14 3:12 ` Wen Gu @ 2024-08-14 14:48 ` Jakub Kicinski 2024-08-15 6:51 ` Wen Gu 0 siblings, 1 reply; 12+ messages in thread From: Jakub Kicinski @ 2024-08-14 14:48 UTC (permalink / raw) To: Wen Gu Cc: Ido Schimmel, wenjia, jaka, davem, edumazet, pabeni, alibuda, tonylu, linux-kernel, linux-s390, netdev, danieller On Wed, 14 Aug 2024 11:12:41 +0800 Wen Gu wrote: > > Danielle added one to libmnl: > > > > https://git.netfilter.org/libmnl/commit/?id=102942be401a99943b2c68981b238dadfa788f2d > > > > Intention is to use it in ethtool once it appears in a released version > > of libmnl. > > Thanks, that is a good example. FWIW - technically the kernel version of a uint / sint are only either 32b or 64b, because smaller types get padded to 4bytes in netlink messages, anyway. But doesn't hurt for the get. For the put make sure you don't narrow down too much. ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH net-next v2 1/2] net/smc: introduce statistics for allocated ringbufs of link group 2024-08-14 14:48 ` Jakub Kicinski @ 2024-08-15 6:51 ` Wen Gu 0 siblings, 0 replies; 12+ messages in thread From: Wen Gu @ 2024-08-15 6:51 UTC (permalink / raw) To: Jakub Kicinski Cc: Ido Schimmel, wenjia, jaka, davem, edumazet, pabeni, alibuda, tonylu, linux-kernel, linux-s390, netdev, danieller On 2024/8/14 22:48, Jakub Kicinski wrote: > On Wed, 14 Aug 2024 11:12:41 +0800 Wen Gu wrote: >>> Danielle added one to libmnl: >>> >>> https://git.netfilter.org/libmnl/commit/?id=102942be401a99943b2c68981b238dadfa788f2d >>> >>> Intention is to use it in ethtool once it appears in a released version >>> of libmnl. >> >> Thanks, that is a good example. > > FWIW - technically the kernel version of a uint / sint are only either > 32b or 64b, because smaller types get padded to 4bytes in netlink > messages, anyway. But doesn't hurt for the get. For the put make sure > you don't narrow down too much. Understand. Thanks. ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH net-next v2 1/2] net/smc: introduce statistics for allocated ringbufs of link group 2024-08-13 14:40 ` Jakub Kicinski 2024-08-13 15:13 ` Ido Schimmel @ 2024-08-14 3:10 ` Wen Gu 2024-08-14 14:50 ` Jakub Kicinski 1 sibling, 1 reply; 12+ messages in thread From: Wen Gu @ 2024-08-14 3:10 UTC (permalink / raw) To: Jakub Kicinski Cc: wenjia, jaka, davem, edumazet, pabeni, alibuda, tonylu, linux-kernel, linux-s390, netdev On 2024/8/13 22:40, Jakub Kicinski wrote: > On Tue, 13 Aug 2024 17:55:17 +0800 Wen Gu wrote: >> On 2024/8/13 08:41, Jakub Kicinski wrote: >>> On Wed, 7 Aug 2024 15:59:38 +0800 Wen Gu wrote: >>>> + if (nla_put_u64_64bit(skb, SMC_NLA_LGR_R_SNDBUF_ALLOC, >>>> + lgr->alloc_sndbufs, SMC_NLA_LGR_R_PAD)) >>> >>> nla_put_uint() >> >> Hi, Jakub. Thank you for reminder. >> >> I read the commit log and learned the advantages of this helper. >> But it seems that the support for corresponding user-space helpers >> hasn't kept up yet, e.g. can't find a helper like nla_get_uint in >> latest libnl. > > Add it, then. OK. So I guess we should use nla_put_uint for all 64bit cases from now on? ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH net-next v2 1/2] net/smc: introduce statistics for allocated ringbufs of link group 2024-08-14 3:10 ` Wen Gu @ 2024-08-14 14:50 ` Jakub Kicinski 0 siblings, 0 replies; 12+ messages in thread From: Jakub Kicinski @ 2024-08-14 14:50 UTC (permalink / raw) To: Wen Gu Cc: wenjia, jaka, davem, edumazet, pabeni, alibuda, tonylu, linux-kernel, linux-s390, netdev On Wed, 14 Aug 2024 11:10:33 +0800 Wen Gu wrote: > >> Hi, Jakub. Thank you for reminder. > >> > >> I read the commit log and learned the advantages of this helper. > >> But it seems that the support for corresponding user-space helpers > >> hasn't kept up yet, e.g. can't find a helper like nla_get_uint in > >> latest libnl. > > > > Add it, then. > > OK. So I guess we should use nla_put_uint for all 64bit cases from now on? Yes, actually I'd go further and say all ints should use the variable size types, unless we are guaranteed they will never be larger than 32b (e.g. ifindex is used in many places in uAPI as 31b already, we can't grow it), or the field is explicitly fixed size (e.g. protocol header fields defined by standards). ^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH net-next v2 2/2] net/smc: introduce statistics for ringbufs usage of net namespace 2024-08-07 7:59 [PATCH net-next v2 0/2] net/smc: introduce ringbufs usage statistics Wen Gu 2024-08-07 7:59 ` [PATCH net-next v2 1/2] net/smc: introduce statistics for allocated ringbufs of link group Wen Gu @ 2024-08-07 7:59 ` Wen Gu 1 sibling, 0 replies; 12+ messages in thread From: Wen Gu @ 2024-08-07 7:59 UTC (permalink / raw) To: wenjia, jaka, davem, edumazet, kuba, pabeni Cc: alibuda, tonylu, guwen, linux-kernel, linux-s390, netdev The buffer size histograms in smc_stats, namely rx/tx_rmbsize, record the sizes of ringbufs for all connections that have ever appeared in the net namespace. They are incremental and we cannot know the actual ringbufs usage from these. So here introduces statistics for current ringbufs usage of existing smc connections in the net namespace into smc_stats, it will be incremented when new connection uses a ringbuf and decremented when the ringbuf is unused. Signed-off-by: Wen Gu <guwen@linux.alibaba.com> --- include/uapi/linux/smc.h | 2 ++ net/smc/smc_core.c | 22 +++++++++++++++------- net/smc/smc_stats.c | 8 ++++++++ net/smc/smc_stats.h | 28 +++++++++++++++++++--------- 4 files changed, 44 insertions(+), 16 deletions(-) diff --git a/include/uapi/linux/smc.h b/include/uapi/linux/smc.h index d27b8dc50f90..304e202c03bb 100644 --- a/include/uapi/linux/smc.h +++ b/include/uapi/linux/smc.h @@ -253,6 +253,8 @@ enum { SMC_NLA_STATS_T_TX_BYTES, /* u64 */ SMC_NLA_STATS_T_RX_CNT, /* u64 */ SMC_NLA_STATS_T_TX_CNT, /* u64 */ + SMC_NLA_STATS_T_RX_RMB_USAGE, /* u64 */ + SMC_NLA_STATS_T_TX_RMB_USAGE, /* u64 */ __SMC_NLA_STATS_T_MAX, SMC_NLA_STATS_T_MAX = __SMC_NLA_STATS_T_MAX - 1 }; diff --git a/net/smc/smc_core.c b/net/smc/smc_core.c index b1ff44d72fe4..72c6c7363f93 100644 --- a/net/smc/smc_core.c +++ b/net/smc/smc_core.c @@ -1207,22 +1207,30 @@ static void smcd_buf_detach(struct smc_connection *conn) static void smc_buf_unuse(struct smc_connection *conn, struct smc_link_group *lgr) { + struct smc_sock *smc = container_of(conn, struct smc_sock, conn); + bool is_smcd = lgr->is_smcd; + int bufsize; + if (conn->sndbuf_desc) { - if (!lgr->is_smcd && conn->sndbuf_desc->is_vm) { + bufsize = conn->sndbuf_desc->len; + if (!is_smcd && conn->sndbuf_desc->is_vm) { smcr_buf_unuse(conn->sndbuf_desc, false, lgr); } else { - memzero_explicit(conn->sndbuf_desc->cpu_addr, conn->sndbuf_desc->len); + memzero_explicit(conn->sndbuf_desc->cpu_addr, bufsize); WRITE_ONCE(conn->sndbuf_desc->used, 0); } + SMC_STAT_RMB_SIZE(smc, is_smcd, false, false, bufsize); } if (conn->rmb_desc) { - if (!lgr->is_smcd) { + bufsize = conn->rmb_desc->len; + if (!is_smcd) { smcr_buf_unuse(conn->rmb_desc, true, lgr); } else { - memzero_explicit(conn->rmb_desc->cpu_addr, - conn->rmb_desc->len + sizeof(struct smcd_cdc_msg)); + bufsize += sizeof(struct smcd_cdc_msg); + memzero_explicit(conn->rmb_desc->cpu_addr, bufsize); WRITE_ONCE(conn->rmb_desc->used, 0); } + SMC_STAT_RMB_SIZE(smc, is_smcd, true, false, bufsize); } } @@ -2431,7 +2439,7 @@ static int __smc_buf_create(struct smc_sock *smc, bool is_smcd, bool is_rmb) buf_desc = smc_buf_get_slot(bufsize_comp, lock, buf_list); if (buf_desc) { buf_desc->is_dma_need_sync = 0; - SMC_STAT_RMB_SIZE(smc, is_smcd, is_rmb, bufsize); + SMC_STAT_RMB_SIZE(smc, is_smcd, is_rmb, true, bufsize); SMC_STAT_BUF_REUSE(smc, is_smcd, is_rmb); break; /* found reusable slot */ } @@ -2452,7 +2460,7 @@ static int __smc_buf_create(struct smc_sock *smc, bool is_smcd, bool is_rmb) } SMC_STAT_RMB_ALLOC(smc, is_smcd, is_rmb); - SMC_STAT_RMB_SIZE(smc, is_smcd, is_rmb, bufsize); + SMC_STAT_RMB_SIZE(smc, is_smcd, is_rmb, true, bufsize); buf_desc->used = 1; down_write(lock); smc_lgr_buf_list_add(lgr, is_rmb, buf_list, buf_desc); diff --git a/net/smc/smc_stats.c b/net/smc/smc_stats.c index ca14c0f3a07d..3f2ebc6c06ba 100644 --- a/net/smc/smc_stats.c +++ b/net/smc/smc_stats.c @@ -218,6 +218,14 @@ static int smc_nl_fill_stats_tech_data(struct sk_buff *skb, smc_tech->tx_bytes, SMC_NLA_STATS_PAD)) goto errattr; + if (nla_put_u64_64bit(skb, SMC_NLA_STATS_T_RX_RMB_USAGE, + smc_tech->rx_rmbuse, + SMC_NLA_STATS_PAD)) + goto errattr; + if (nla_put_u64_64bit(skb, SMC_NLA_STATS_T_TX_RMB_USAGE, + smc_tech->tx_rmbuse, + SMC_NLA_STATS_PAD)) + goto errattr; if (nla_put_u64_64bit(skb, SMC_NLA_STATS_T_RX_CNT, smc_tech->rx_cnt, SMC_NLA_STATS_PAD)) diff --git a/net/smc/smc_stats.h b/net/smc/smc_stats.h index 9d32058db2b5..6ac465380431 100644 --- a/net/smc/smc_stats.h +++ b/net/smc/smc_stats.h @@ -79,6 +79,8 @@ struct smc_stats_tech { u64 tx_bytes; u64 rx_cnt; u64 tx_cnt; + u64 rx_rmbuse; + u64 tx_rmbuse; }; struct smc_stats { @@ -135,38 +137,46 @@ do { \ } \ while (0) -#define SMC_STAT_RMB_SIZE_SUB(_smc_stats, _tech, k, _len) \ +#define SMC_STAT_RMB_SIZE_SUB(_smc_stats, _tech, k, _is_add, _len) \ do { \ + typeof(_smc_stats) stats = (_smc_stats); \ + typeof(_is_add) is_a = (_is_add); \ typeof(_len) _l = (_len); \ typeof(_tech) t = (_tech); \ int _pos; \ int m = SMC_BUF_MAX - 1; \ if (_l <= 0) \ break; \ - _pos = fls((_l - 1) >> 13); \ - _pos = (_pos <= m) ? _pos : m; \ - this_cpu_inc((*(_smc_stats)).smc[t].k ## _rmbsize.buf[_pos]); \ + if (is_a) { \ + _pos = fls((_l - 1) >> 13); \ + _pos = (_pos <= m) ? _pos : m; \ + this_cpu_inc((*stats).smc[t].k ## _rmbsize.buf[_pos]); \ + this_cpu_add((*stats).smc[t].k ## _rmbuse, _l); \ + } else { \ + this_cpu_sub((*stats).smc[t].k ## _rmbuse, _l); \ + } \ } \ while (0) #define SMC_STAT_RMB_SUB(_smc_stats, type, t, key) \ this_cpu_inc((*(_smc_stats)).smc[t].rmb ## _ ## key.type ## _cnt) -#define SMC_STAT_RMB_SIZE(_smc, _is_smcd, _is_rx, _len) \ +#define SMC_STAT_RMB_SIZE(_smc, _is_smcd, _is_rx, _is_add, _len) \ do { \ struct net *_net = sock_net(&(_smc)->sk); \ struct smc_stats __percpu *_smc_stats = _net->smc.smc_stats; \ + typeof(_is_add) is_add = (_is_add); \ typeof(_is_smcd) is_d = (_is_smcd); \ typeof(_is_rx) is_r = (_is_rx); \ typeof(_len) l = (_len); \ if ((is_d) && (is_r)) \ - SMC_STAT_RMB_SIZE_SUB(_smc_stats, SMC_TYPE_D, rx, l); \ + SMC_STAT_RMB_SIZE_SUB(_smc_stats, SMC_TYPE_D, rx, is_add, l); \ if ((is_d) && !(is_r)) \ - SMC_STAT_RMB_SIZE_SUB(_smc_stats, SMC_TYPE_D, tx, l); \ + SMC_STAT_RMB_SIZE_SUB(_smc_stats, SMC_TYPE_D, tx, is_add, l); \ if (!(is_d) && (is_r)) \ - SMC_STAT_RMB_SIZE_SUB(_smc_stats, SMC_TYPE_R, rx, l); \ + SMC_STAT_RMB_SIZE_SUB(_smc_stats, SMC_TYPE_R, rx, is_add, l); \ if (!(is_d) && !(is_r)) \ - SMC_STAT_RMB_SIZE_SUB(_smc_stats, SMC_TYPE_R, tx, l); \ + SMC_STAT_RMB_SIZE_SUB(_smc_stats, SMC_TYPE_R, tx, is_add, l); \ } \ while (0) -- 2.32.0.3.g01195cf9f ^ permalink raw reply related [flat|nested] 12+ messages in thread
end of thread, other threads:[~2024-08-15 6:51 UTC | newest] Thread overview: 12+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2024-08-07 7:59 [PATCH net-next v2 0/2] net/smc: introduce ringbufs usage statistics Wen Gu 2024-08-07 7:59 ` [PATCH net-next v2 1/2] net/smc: introduce statistics for allocated ringbufs of link group Wen Gu 2024-08-13 0:41 ` Jakub Kicinski 2024-08-13 9:55 ` Wen Gu 2024-08-13 14:40 ` Jakub Kicinski 2024-08-13 15:13 ` Ido Schimmel 2024-08-14 3:12 ` Wen Gu 2024-08-14 14:48 ` Jakub Kicinski 2024-08-15 6:51 ` Wen Gu 2024-08-14 3:10 ` Wen Gu 2024-08-14 14:50 ` Jakub Kicinski 2024-08-07 7:59 ` [PATCH net-next v2 2/2] net/smc: introduce statistics for ringbufs usage of net namespace Wen Gu
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).