* [PATCH net-next v2 2/10] bonding: rebuild the lock use for bond_mii_monitor()
@ 2013-11-08 2:07 Ding Tianhong
2013-11-08 15:28 ` Nikolay Aleksandrov
0 siblings, 1 reply; 3+ messages in thread
From: Ding Tianhong @ 2013-11-08 2:07 UTC (permalink / raw)
To: Jay Vosburgh, Andy Gospodarek, David S. Miller,
Nikolay Aleksandrov, Veaceslav Falico, Netdev
The bond_mii_monitor() still use bond lock to protect bond slave list,
it is no effect, I have 2 way to fix the problem, move the RTNL to the
top of the function, or add RCU to protect the bond_has_slaves() and
bond_miimon_inspect(), according to the Jay Vosburgh's opinion, 10 times
one second is a truely big performance loss if use RTNL to protect the
whole function, so I would take the advice and use RCU to protect the
two functions, of course it need to add more modify, the
bond_has_slave_rcu() is add for RCU use, and the bond_for_each_slave
need to replace with bond_for_each_slave_rcu in bond_miimon_inspect.
I move the peer notify before the queue_delayed_work(), and obviously
it is no need to lock the RTNL twice if call bond_miimon_commit() and
peer notify together, other path is no logic change, I think the
performance is better than before.
Suggested-by: Jay Vosburgh <fubar@us.ibm.com>
Suggested-by: Veaceslav Falico <vfalico@redhat.com>
Signed-off-by: Ding Tianhong <dingtianhong@huawei.com>
---
drivers/net/bonding/bond_main.c | 40 ++++++++++++++++++++--------------------
drivers/net/bonding/bonding.h | 6 ++++++
2 files changed, 26 insertions(+), 20 deletions(-)
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index ba18719..def489d 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -1913,7 +1913,7 @@ static int bond_miimon_inspect(struct bonding *bond)
ignore_updelay = !bond->curr_active_slave ? true : false;
- bond_for_each_slave(bond, slave, iter) {
+ bond_for_each_slave_rcu(bond, slave, iter) {
slave->new_link = BOND_LINK_NOCHANGE;
link_state = bond_check_dev_link(bond, slave->dev, 0);
@@ -2111,47 +2111,47 @@ void bond_mii_monitor(struct work_struct *work)
bool should_notify_peers = false;
unsigned long delay;
- read_lock(&bond->lock);
-
delay = msecs_to_jiffies(bond->params.miimon);
- if (!bond_has_slaves(bond))
+ rcu_read_lock();
+
+ if (!bond_has_slaves_rcu(bond)) {
+ rcu_read_unlock();
goto re_arm;
+ }
should_notify_peers = bond_should_notify_peers(bond);
if (bond_miimon_inspect(bond)) {
- read_unlock(&bond->lock);
+ rcu_read_unlock();
/* Race avoidance with bond_close cancel of workqueue */
if (!rtnl_trylock()) {
- read_lock(&bond->lock);
delay = 1;
- should_notify_peers = false;
goto re_arm;
}
- read_lock(&bond->lock);
-
bond_miimon_commit(bond);
- read_unlock(&bond->lock);
+ if (should_notify_peers)
+ call_netdevice_notifiers(NETDEV_NOTIFY_PEERS,
+ bond->dev);
+
rtnl_unlock(); /* might sleep, hold no other locks */
- read_lock(&bond->lock);
+ } else {
+ rcu_read_unlock();
+ if (should_notify_peers) {
+ if (!rtnl_trylock())
+ goto re_arm;
+ call_netdevice_notifiers(NETDEV_NOTIFY_PEERS,
+ bond->dev);
+ rtnl_unlock();
+ }
}
re_arm:
if (bond->params.miimon)
queue_delayed_work(bond->wq, &bond->mii_work, delay);
-
- read_unlock(&bond->lock);
-
- if (should_notify_peers) {
- if (!rtnl_trylock())
- return;
- call_netdevice_notifiers(NETDEV_NOTIFY_PEERS, bond->dev);
- rtnl_unlock();
- }
}
static bool bond_has_this_ip(struct bonding *bond, __be32 ip)
diff --git a/drivers/net/bonding/bonding.h b/drivers/net/bonding/bonding.h
index 046a605..deb9738 100644
--- a/drivers/net/bonding/bonding.h
+++ b/drivers/net/bonding/bonding.h
@@ -81,6 +81,12 @@
#define bond_has_slaves(bond) !list_empty(bond_slave_list(bond))
+#define bond_has_slaves_rcu(bond) \
+ ({struct list_head *__ptr = (bond_slave_list(bond)); \
+ struct list_head *__next = ACCESS_ONCE(__ptr->next); \
+ __ptr != __next; \
+ })
+
/* IMPORTANT: bond_first/last_slave can return NULL in case of an empty list */
#define bond_first_slave(bond) \
(bond_has_slaves(bond) ? \
--
1.8.2.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net-next v2 2/10] bonding: rebuild the lock use for bond_mii_monitor()
2013-11-08 2:07 [PATCH net-next v2 2/10] bonding: rebuild the lock use for bond_mii_monitor() Ding Tianhong
@ 2013-11-08 15:28 ` Nikolay Aleksandrov
2013-11-09 13:51 ` Ding Tianhong
0 siblings, 1 reply; 3+ messages in thread
From: Nikolay Aleksandrov @ 2013-11-08 15:28 UTC (permalink / raw)
To: Ding Tianhong
Cc: Jay Vosburgh, Andy Gospodarek, David S. Miller, Veaceslav Falico,
Netdev
On 11/08/2013 03:07 AM, Ding Tianhong wrote:
> The bond_mii_monitor() still use bond lock to protect bond slave list,
> it is no effect, I have 2 way to fix the problem, move the RTNL to the
> top of the function, or add RCU to protect the bond_has_slaves() and
> bond_miimon_inspect(), according to the Jay Vosburgh's opinion, 10 times
> one second is a truely big performance loss if use RTNL to protect the
> whole function, so I would take the advice and use RCU to protect the
> two functions, of course it need to add more modify, the
> bond_has_slave_rcu() is add for RCU use, and the bond_for_each_slave
> need to replace with bond_for_each_slave_rcu in bond_miimon_inspect.
>
> I move the peer notify before the queue_delayed_work(), and obviously
> it is no need to lock the RTNL twice if call bond_miimon_commit() and
> peer notify together, other path is no logic change, I think the
> performance is better than before.
>
> Suggested-by: Jay Vosburgh <fubar@us.ibm.com>
> Suggested-by: Veaceslav Falico <vfalico@redhat.com>
> Signed-off-by: Ding Tianhong <dingtianhong@huawei.com>
> ---
> drivers/net/bonding/bond_main.c | 40 ++++++++++++++++++++--------------------
> drivers/net/bonding/bonding.h | 6 ++++++
> 2 files changed, 26 insertions(+), 20 deletions(-)
>
> diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
> index ba18719..def489d 100644
> --- a/drivers/net/bonding/bond_main.c
> +++ b/drivers/net/bonding/bond_main.c
> @@ -1913,7 +1913,7 @@ static int bond_miimon_inspect(struct bonding *bond)
>
> ignore_updelay = !bond->curr_active_slave ? true : false;
>
> - bond_for_each_slave(bond, slave, iter) {
> + bond_for_each_slave_rcu(bond, slave, iter) {
> slave->new_link = BOND_LINK_NOCHANGE;
>
> link_state = bond_check_dev_link(bond, slave->dev, 0);
> @@ -2111,47 +2111,47 @@ void bond_mii_monitor(struct work_struct *work)
> bool should_notify_peers = false;
> unsigned long delay;
>
> - read_lock(&bond->lock);
> -
> delay = msecs_to_jiffies(bond->params.miimon);
>
> - if (!bond_has_slaves(bond))
> + rcu_read_lock();
> +
> + if (!bond_has_slaves_rcu(bond)) {
> + rcu_read_unlock();
In fact the bond cannot disappear while this function is running, so this test
should be able to run outside the RCU region if I'm not missing something :-)
It'll be just as useful as running inside the region, at most a free run may
happen if there's one slave and it disappears.
> goto re_arm;
> + }
>
> should_notify_peers = bond_should_notify_peers(bond);
bond_should_notify_peers() is not RCU-safe, it uses curr_active_slave directly.
>
> if (bond_miimon_inspect(bond)) {
> - read_unlock(&bond->lock);
> + rcu_read_unlock();
>
> /* Race avoidance with bond_close cancel of workqueue */
> if (!rtnl_trylock()) {
> - read_lock(&bond->lock);
> delay = 1;
> - should_notify_peers = false;
> goto re_arm;
> }
>
> - read_lock(&bond->lock);
> -
> bond_miimon_commit(bond);
>
> - read_unlock(&bond->lock);
> + if (should_notify_peers)
> + call_netdevice_notifiers(NETDEV_NOTIFY_PEERS,
> + bond->dev);
> +
> rtnl_unlock(); /* might sleep, hold no other locks */
> - read_lock(&bond->lock);
> + } else {
> + rcu_read_unlock();
> + if (should_notify_peers) {
> + if (!rtnl_trylock())
> + goto re_arm;
> + call_netdevice_notifiers(NETDEV_NOTIFY_PEERS,
> + bond->dev);
> + rtnl_unlock();
> + }
> }
>
> re_arm:
> if (bond->params.miimon)
> queue_delayed_work(bond->wq, &bond->mii_work, delay);
> -
> - read_unlock(&bond->lock);
> -
> - if (should_notify_peers) {
> - if (!rtnl_trylock())
> - return;
> - call_netdevice_notifiers(NETDEV_NOTIFY_PEERS, bond->dev);
> - rtnl_unlock();
> - }
> }
>
> static bool bond_has_this_ip(struct bonding *bond, __be32 ip)
> diff --git a/drivers/net/bonding/bonding.h b/drivers/net/bonding/bonding.h
> index 046a605..deb9738 100644
> --- a/drivers/net/bonding/bonding.h
> +++ b/drivers/net/bonding/bonding.h
> @@ -81,6 +81,12 @@
>
> #define bond_has_slaves(bond) !list_empty(bond_slave_list(bond))
>
> +#define bond_has_slaves_rcu(bond) \
> + ({struct list_head *__ptr = (bond_slave_list(bond)); \
> + struct list_head *__next = ACCESS_ONCE(__ptr->next); \
> + __ptr != __next; \
> + })
> +
This is unnecessary, bond_has_slaves() should be enough. See bond_start_xmit()
and also the list_empty comment in include/linux/rculist.h for more information why.
My bond_has_slaves() comments apply to all the patches that use it.
> /* IMPORTANT: bond_first/last_slave can return NULL in case of an empty list */
> #define bond_first_slave(bond) \
> (bond_has_slaves(bond) ? \
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net-next v2 2/10] bonding: rebuild the lock use for bond_mii_monitor()
2013-11-08 15:28 ` Nikolay Aleksandrov
@ 2013-11-09 13:51 ` Ding Tianhong
0 siblings, 0 replies; 3+ messages in thread
From: Ding Tianhong @ 2013-11-09 13:51 UTC (permalink / raw)
To: Nikolay Aleksandrov
Cc: Ding Tianhong, Jay Vosburgh, Andy Gospodarek, David S. Miller,
Veaceslav Falico, Netdev
于 2013/11/8 23:28, Nikolay Aleksandrov 写道:
> On 11/08/2013 03:07 AM, Ding Tianhong wrote:
> In fact the bond cannot disappear while this function is running, so this test
> should be able to run outside the RCU region if I'm not missing something :-)
> It'll be just as useful as running inside the region, at most a free run may
> happen if there's one slave and it disappears.
>
>
> This is unnecessary, bond_has_slaves() should be enough. See bond_start_xmit()
> and also the list_empty comment in include/linux/rculist.h for more information why.
> My bond_has_slaves() comments apply to all the patches that use it.
>
>
yes, you are right, I make a silly mistake, the bond list itself is no
need to copy, it
dose not occur any problem if it be changed.
The curr_active_slave needs copy for peer, as it may be changed at
monitor running.
Regards.
Ding
> --
> To unsubscribe from this list: send the line "unsubscribe netdev" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-11-09 14:01 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-11-08 2:07 [PATCH net-next v2 2/10] bonding: rebuild the lock use for bond_mii_monitor() Ding Tianhong
2013-11-08 15:28 ` Nikolay Aleksandrov
2013-11-09 13:51 ` Ding Tianhong
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).