Skip to contentSkip to conversation

net: openvswitch: do not update max_headroom if new headroom is equal to old headroom

PATCH In review Taehee Yoo 4 participants 11 messages Jul 5, 2019 – Jul 16, 2019

Subsystems (3)
lore
Share & tools
lore

Taehee Yoo

author
#0 lore raw

PATCH 1/1 net: openvswitch: do not update max_headroom if new headroom is equal to old headroom

When a vport is deleted, the maximum headroom size would be changed. If the vport which has the largest headroom is deleted, the new max_headroom would be set.
But, if the new headroom size is equal to the old headroom size, updating routine is unnecessary.

---
 net/openvswitch/datapath.c | 39 +++++++++++++++++++++++++++-----------
 1 file changed, 28 insertions(+), 11 deletions(-)
net/openvswitch/datapath.c +28 -11
index 33b388103741..892287d06c17 100644
@@ -1958,10 +1958,9 @@ static struct vport *lookup_vport(struct net *net,
 
 }
 
-/* Called with ovs_mutex */
-static void update_headroom(struct datapath *dp)
+static unsigned int ovs_get_max_headroom(struct datapath *dp)
 {
-	unsigned dev_headroom, max_headroom = 0;
+	unsigned int dev_headroom, max_headroom = 0;
 	struct net_device *dev;
 	struct vport *vport;
 	int i;
@@ -1975,10 +1974,19 @@ static void update_headroom(struct datapath *dp)
 		}
 	}
 
-	dp->max_headroom = max_headroom;
+	return max_headroom;
+}
+
+/* Called with ovs_mutex */
+static void ovs_update_headroom(struct datapath *dp, unsigned int new_headroom)
+{
+	struct vport *vport;
+	int i;
+
+	dp->max_headroom = new_headroom;
 	for (i = 0; i < DP_VPORT_HASH_BUCKETS; i++)
 		hlist_for_each_entry_rcu(vport, &dp->ports[i], dp_hash_node)
-			netdev_set_rx_headroom(vport->dev, max_headroom);
+			netdev_set_rx_headroom(vport->dev, new_headroom);
 }
 
 static int ovs_vport_cmd_new(struct sk_buff *skb, struct genl_info *info)
@@ -1989,6 +1997,7 @@ static int ovs_vport_cmd_new(struct sk_buff *skb, struct genl_info *info)
 	struct sk_buff *reply;
 	struct vport *vport;
 	struct datapath *dp;
+	unsigned int new_headroom;
 	u32 port_no;
 	int err;
 
@@ -2050,8 +2059,10 @@ static int ovs_vport_cmd_new(struct sk_buff *skb, struct genl_info *info)
 				      info->snd_portid, info->snd_seq, 0,
 				      OVS_VPORT_CMD_NEW);
 
-	if (netdev_get_fwd_headroom(vport->dev) > dp->max_headroom)
-		update_headroom(dp);
+	new_headroom = netdev_get_fwd_headroom(vport->dev);
+
+	if (new_headroom > dp->max_headroom)
+		ovs_update_headroom(dp, new_headroom);
 	else
 		netdev_set_rx_headroom(vport->dev, dp->max_headroom);
 
@@ -2122,11 +2133,12 @@ static int ovs_vport_cmd_set(struct sk_buff *skb, struct genl_info *info)
 
 static int ovs_vport_cmd_del(struct sk_buff *skb, struct genl_info *info)
 {
-	bool must_update_headroom = false;
+	bool update_headroom = false;
 	struct nlattr **a = info->attrs;
 	struct sk_buff *reply;
 	struct datapath *dp;
 	struct vport *vport;
+	unsigned int new_headroom;
 	int err;
 
 	reply = ovs_vport_cmd_alloc_info();
@@ -2152,12 +2164,17 @@ static int ovs_vport_cmd_del(struct sk_buff *skb, struct genl_info *info)
 	/* the vport deletion may trigger dp headroom update */
 	dp = vport->dp;
 	if (netdev_get_fwd_headroom(vport->dev) == dp->max_headroom)
-		must_update_headroom = true;
+		update_headroom = true;
+
 	netdev_reset_rx_headroom(vport->dev);
 	ovs_dp_detach_port(vport);
 
-	if (must_update_headroom)
-		update_headroom(dp);
+	if (update_headroom) {
+		new_headroom = ovs_get_max_headroom(dp);
+
+		if (new_headroom < dp->max_headroom)
+			ovs_update_headroom(dp, new_headroom);
+	}
 	ovs_unlock();
 
 	ovs_notify(&dp_vport_genl_family, reply, info);
Signature · 1 line
2.17.1
maintainer
#1 lore raw

From: Taehee Yoo <[email protected]>
Date: Sat, 6 Jul 2019 01:08:09 +0900

Quoted 7 lines

When a vport is deleted, the maximum headroom size would be changed. If the vport which has the largest headroom is deleted, the new max_headroom would be set.
But, if the new headroom size is equal to the old headroom size, updating routine is unnecessary.

I'm not so sure about the logic here and I'd therefore like an OVS expert to review this.

Thanks.

#2 lore raw
Quoted 9 lines · David Miller

From: Taehee Yoo <[email protected]>
Date: Sat, 6 Jul 2019 01:08:09 +0900

Quoted 6 lines

When a vport is deleted, the maximum headroom size would be changed. If the vport which has the largest headroom is deleted, the new max_headroom would be set.
But, if the new headroom size is equal to the old headroom size, updating routine is unnecessary.

Quoted 3 lines
Quoted 1 line

I'm not so sure about the logic here and I'd therefore like an OVS expert to review this.

I'll review and test it and get back.  Pravin may have input as well.

Thanks,

- Greg

Quoted 5 lines

Thanks.
_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

#3 lore raw
Quoted 10 lines · Gregory Rose
Quoted 9 lines · David Miller

From: Taehee Yoo <[email protected]>
Date: Sat,  6 Jul 2019 01:08:09 +0900

Quoted 6 lines

When a vport is deleted, the maximum headroom size would be changed. If the vport which has the largest headroom is deleted, the new max_headroom would be set.
But, if the new headroom size is equal to the old headroom size, updating routine is unnecessary.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

I'm not so sure about the logic here and I'd therefore like an OVS expert to review this.

I'll review and test it and get back.  Pravin may have input as well.

Err, adding Pravin.

- Greg

Quoted 10 lines

Thanks,

- Greg

Quoted 5 lines

Thanks.
_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

#4 lore raw

I was bit busy for last couple of days. I will finish review by EOD today.

Thanks,
Pravin.

Quoted 37 lines · Gregory Rose
Quoted 10 lines · Gregory Rose
Quoted 9 lines · David Miller

From: Taehee Yoo <[email protected]>
Date: Sat, 6 Jul 2019 01:08:09 +0900

Quoted 6 lines

When a vport is deleted, the maximum headroom size would be changed. If the vport which has the largest headroom is deleted, the new max_headroom would be set.
But, if the new headroom size is equal to the old headroom size, updating routine is unnecessary.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

I'm not so sure about the logic here and I'd therefore like an OVS expert
to review this.

I'll review and test it and get back. Pravin may have input as well.

Err, adding Pravin.

- Greg

Quoted 10 lines

Thanks,

- Greg

Quoted 5 lines

Thanks.
_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

#5 lore raw
Quoted 4 lines · Pravin Shelar

I was bit busy for last couple of days. I will finish review by EOD today.

Thanks,
Pravin.

net-next is closed anyway so no rush, but thanks!

- Greg

Quoted 34 lines · Gregory Rose
Quoted 32 lines · Gregory Rose
Quoted 10 lines · David Miller
Quoted 9 lines

From: Taehee Yoo <[email protected]>
Date: Sat, 6 Jul 2019 01:08:09 +0900

Quoted 6 lines

When a vport is deleted, the maximum headroom size would be changed. If the vport which has the largest headroom is deleted, the new max_headroom would be set.
But, if the new headroom size is equal to the old headroom size, updating routine is unnecessary.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

I'm not so sure about the logic here and I'd therefore like an OVS expert
to review this.

I'll review and test it and get back. Pravin may have input as well.

Err, adding Pravin.

- Greg

Quoted 9 lines

Thanks,

- Greg

Quoted 5 lines

Thanks.
_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Tested-by Reviewed-by on v1 1/1
#6 lore raw
In reply to Taehee Yoo
Quoted 96 lines · Taehee Yoo

When a vport is deleted, the maximum headroom size would be changed. If the vport which has the largest headroom is deleted, the new max_headroom would be set.
But, if the new headroom size is equal to the old headroom size, updating routine is unnecessary.

---
  net/openvswitch/datapath.c | 39 +++++++++++++++++++++++++++-----------
  1 file changed, 28 insertions(+), 11 deletions(-)
net/openvswitch/datapath.c +22 -10
index 33b388103741..892287d06c17 100644
@@ -1958,10 +1958,9 @@ static struct vport *lookup_vport(struct net *net,
 
  }
 
-/* Called with ovs_mutex */
-static void update_headroom(struct datapath *dp)
+static unsigned int ovs_get_max_headroom(struct datapath *dp)
  {
-	unsigned dev_headroom, max_headroom = 0;
+	unsigned int dev_headroom, max_headroom = 0;
  	struct net_device *dev;
  	struct vport *vport;
  	int i;
@@ -1975,10 +1974,19 @@ static void update_headroom(struct datapath *dp)
  		}
  	}
 
-	dp->max_headroom = max_headroom;
+	return max_headroom;
+}
+
+/* Called with ovs_mutex */
+static void ovs_update_headroom(struct datapath *dp, unsigned int new_headroom)
+{
+	struct vport *vport;
+	int i;
+
+	dp->max_headroom = new_headroom;
  	for (i = 0; i < DP_VPORT_HASH_BUCKETS; i++)
  		hlist_for_each_entry_rcu(vport, &dp->ports[i], dp_hash_node)
-			netdev_set_rx_headroom(vport->dev, max_headroom);
+			netdev_set_rx_headroom(vport->dev, new_headroom);
  }
 
  static int ovs_vport_cmd_new(struct sk_buff *skb, struct genl_info *info)
@@ -1989,6 +1997,7 @@ static int ovs_vport_cmd_new(struct sk_buff *skb, struct genl_info *info)
  	struct sk_buff *reply;
  	struct vport *vport;
  	struct datapath *dp;
+	unsigned int new_headroom;
  	u32 port_no;
  	int err;
 
@@ -2050,8 +2059,10 @@ static int ovs_vport_cmd_new(struct sk_buff *skb, struct genl_info *info)
  				      info->snd_portid, info->snd_seq, 0,
  				      OVS_VPORT_CMD_NEW);
 
-	if (netdev_get_fwd_headroom(vport->dev) > dp->max_headroom)
-		update_headroom(dp);
+	new_headroom = netdev_get_fwd_headroom(vport->dev);
+
+	if (new_headroom > dp->max_headroom)
+		ovs_update_headroom(dp, new_headroom);
  	else
  		netdev_set_rx_headroom(vport->dev, dp->max_headroom);
 
@@ -2122,11 +2133,12 @@ static int ovs_vport_cmd_set(struct sk_buff *skb, struct genl_info *info)
 
  static int ovs_vport_cmd_del(struct sk_buff *skb, struct genl_info *info)
  {
-	bool must_update_headroom = false;
+	bool update_headroom = false;
  	struct nlattr **a = info->attrs;
  	struct sk_buff *reply;
  	struct datapath *dp;
  	struct vport *vport;
+	unsigned int new_headroom;
  	int err;
 
  	reply = ovs_vport_cmd_alloc_info();
@@ -2152,12 +2164,17 @@ static int ovs_vport_cmd_del(struct sk_buff *skb, struct genl_info *info)
  	/* the vport deletion may trigger dp headroom update */
  	dp = vport->dp;
  	if (netdev_get_fwd_headroom(vport->dev) == dp->max_headroom)
-		must_update_headroom = true;
+		update_headroom = true;
+
  	netdev_reset_rx_headroom(vport->dev);
  	ovs_dp_detach_port(vport);
 
-	if (must_update_headroom)

net/openvswitch/datapath.c static int ovs_vport_cmd_del(struct sk_buff *skb, struct genl_info *info) · line 2180

Quoted 10 lines
net/openvswitch/datapath.c +6 -1
-		update_headroom(dp);
+	if (update_headroom) {
+		new_headroom = ovs_get_max_headroom(dp);
+
+		if (new_headroom < dp->max_headroom)
+			ovs_update_headroom(dp, new_headroom);
+	}
  	ovs_unlock();
 
  	ovs_notify(&dp_vport_genl_family, reply, info);

I did a compile test and ran the OVS kernel self-test suite.  Looks OK to me.

maintainer
#7 lore raw
In reply to Taehee Yoo

From: Taehee Yoo <[email protected]>
Date: Sat, 6 Jul 2019 01:08:09 +0900

Quoted 7 lines

When a vport is deleted, the maximum headroom size would be changed. If the vport which has the largest headroom is deleted, the new max_headroom would be set.
But, if the new headroom size is equal to the old headroom size, updating routine is unnecessary.

I don't think Taehee should be punished because it took several days to get someone to look at and review and/or test this patch and meanwhile the net-next tree closed down.

I ask for maintainer review as both a courtesy and a way to lessen my workload. But if that means patches rot for days in patchwork I'm just going to apply them after my own review.

So I'm applying this now.

#8 lore raw
Quoted 14 lines · David Miller

From: Taehee Yoo <[email protected]>
Date: Sat, 6 Jul 2019 01:08:09 +0900

Quoted 7 lines

When a vport is deleted, the maximum headroom size would be changed. If the vport which has the largest headroom is deleted, the new max_headroom would be set.
But, if the new headroom size is equal to the old headroom size, updating routine is unnecessary.

I don't think Taehee should be punished because it took several days to get someone to look at and review and/or test this patch and meanwhile the net-next tree closed down.

Quoted 6 lines

I ask for maintainer review as both a courtesy and a way to lessen my workload. But if that means patches rot for days in patchwork I'm just going to apply them after my own review.

So I'm applying this now.

My apologies Dave.  I did test and review the patch, perhaps you didn't see it.  In any case, you're right, Taehee was owed a more timely review and I missed it.

Thanks for applying the patch.

- Greg

#9 lore raw
In reply to Taehee Yoo
Quoted 8 lines · Taehee Yoo

When a vport is deleted, the maximum headroom size would be changed. If the vport which has the largest headroom is deleted, the new max_headroom would be set.
But, if the new headroom size is equal to the old headroom size, updating routine is unnecessary.

Sorry for late reply. This patch looks good to me too.

I am curious about reason to avoid adjustment to headroom. why are you trying to avoid unnecessary changes to headroom.

Thanks,
Pravin.

author
#10 lore raw
Quoted 1 line · Pravin Shelar

Hi Pravin,

Quoted 8 lines · Taehee Yoo
Quoted 7 lines

When a vport is deleted, the maximum headroom size would be changed. If the vport which has the largest headroom is deleted, the new max_headroom would be set.
But, if the new headroom size is equal to the old headroom size, updating routine is unnecessary.

Quoted 7 lines
Quoted 1 line

Sorry for late reply. This patch looks good to me too.

I am curious about reason to avoid adjustment to headroom. why are you trying to avoid unnecessary changes to headroom.

Thank you for the review!
The intention of this patch is to remove unnecessary overhead. There is no other reason.

Thanks!

Quoted 2 lines

Thanks,
Pravin.