Skip to content

Commit 30328d4

Browse files
idoschdavem330
authored andcommitted
drop_monitor: Make drop queue length configurable
In packet alert mode, each CPU holds a list of dropped skbs that need to be processed in process context and sent to user space. To avoid exhausting the system's memory the maximum length of this queue is currently set to 1000. Allow users to tune the length of this queue according to their needs. The configured length is reported to user space when drop monitor configuration is queried. Signed-off-by: Ido Schimmel <idosch@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 444be06 commit 30328d4

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

‎include/uapi/linux/net_dropmon.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ enum net_dm_attr {
7979
NET_DM_ATTR_PAD,
8080
NET_DM_ATTR_TRUNC_LEN, /* u32 */
8181
NET_DM_ATTR_ORIG_LEN, /* u32 */
82+
NET_DM_ATTR_QUEUE_LEN, /* u32 */
8283

8384
__NET_DM_ATTR_MAX,
8485
NET_DM_ATTR_MAX = __NET_DM_ATTR_MAX - 1

‎net/core/drop_monitor.c‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ static LIST_HEAD(hw_stats_list);
7878

7979
static enum net_dm_alert_mode net_dm_alert_mode = NET_DM_ALERT_MODE_SUMMARY;
8080
static u32 net_dm_trunc_len;
81+
static u32 net_dm_queue_len = 1000;
8182

8283
struct net_dm_alert_ops {
8384
void (*kfree_skb_probe)(void *ignore, struct sk_buff *skb,
@@ -93,8 +94,6 @@ struct net_dm_skb_cb {
9394

9495
#define NET_DM_SKB_CB(__skb) ((struct net_dm_skb_cb *)&((__skb)->cb[0]))
9596

96-
#define NET_DM_QUEUE_LEN 1000
97-
9897
static struct sk_buff *reset_per_cpu_data(struct per_cpu_dm_data *data)
9998
{
10099
size_t al;
@@ -289,7 +288,7 @@ static void net_dm_packet_trace_kfree_skb_hit(void *ignore,
289288
data = this_cpu_ptr(&dm_cpu_data);
290289

291290
spin_lock_irqsave(&data->drop_queue.lock, flags);
292-
if (skb_queue_len(&data->drop_queue) < NET_DM_QUEUE_LEN)
291+
if (skb_queue_len(&data->drop_queue) < net_dm_queue_len)
293292
__skb_queue_tail(&data->drop_queue, nskb);
294293
else
295294
goto unlock_free;
@@ -643,6 +642,14 @@ static void net_dm_trunc_len_set(struct genl_info *info)
643642
net_dm_trunc_len = nla_get_u32(info->attrs[NET_DM_ATTR_TRUNC_LEN]);
644643
}
645644

645+
static void net_dm_queue_len_set(struct genl_info *info)
646+
{
647+
if (!info->attrs[NET_DM_ATTR_QUEUE_LEN])
648+
return;
649+
650+
net_dm_queue_len = nla_get_u32(info->attrs[NET_DM_ATTR_QUEUE_LEN]);
651+
}
652+
646653
static int net_dm_cmd_config(struct sk_buff *skb,
647654
struct genl_info *info)
648655
{
@@ -660,6 +667,8 @@ static int net_dm_cmd_config(struct sk_buff *skb,
660667

661668
net_dm_trunc_len_set(info);
662669

670+
net_dm_queue_len_set(info);
671+
663672
return 0;
664673
}
665674

@@ -691,6 +700,9 @@ static int net_dm_config_fill(struct sk_buff *msg, struct genl_info *info)
691700
if (nla_put_u32(msg, NET_DM_ATTR_TRUNC_LEN, net_dm_trunc_len))
692701
goto nla_put_failure;
693702

703+
if (nla_put_u32(msg, NET_DM_ATTR_QUEUE_LEN, net_dm_queue_len))
704+
goto nla_put_failure;
705+
694706
genlmsg_end(msg, hdr);
695707

696708
return 0;
@@ -763,6 +775,7 @@ static const struct nla_policy net_dm_nl_policy[NET_DM_ATTR_MAX + 1] = {
763775
[NET_DM_ATTR_UNSPEC] = { .strict_start_type = NET_DM_ATTR_UNSPEC + 1 },
764776
[NET_DM_ATTR_ALERT_MODE] = { .type = NLA_U8 },
765777
[NET_DM_ATTR_TRUNC_LEN] = { .type = NLA_U32 },
778+
[NET_DM_ATTR_QUEUE_LEN] = { .type = NLA_U32 },
766779
};
767780

768781
static const struct genl_ops dropmon_ops[] = {

0 commit comments

Comments
 (0)