Skip to content

Commit e7f1332

Browse files
Pravin B Shelarjessegross
authored andcommitted
openvswitch: Move flow table rehashing to flow install.
Rehashing in ovs-workqueue can cause ovs-mutex lock contentions in case of heavy flow setups where both needs ovs-mutex. So by moving rehashing to flow-setup we can eliminate contention. This also simplify ovs locking and reduces dependence on workqueue. Signed-off-by: Pravin B Shelar <pshelar@nicira.com> Signed-off-by: Jesse Gross <jesse@nicira.com>
1 parent 272b98c commit e7f1332

2 files changed

Lines changed: 13 additions & 39 deletions

File tree

‎net/openvswitch/datapath.c‎

Lines changed: 11 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@
6060

6161

6262
#define REHASH_FLOW_INTERVAL (10 * 60 * HZ)
63-
static void rehash_flow_table(struct work_struct *work);
64-
static DECLARE_DELAYED_WORK(rehash_flow_wq, rehash_flow_table);
6563

6664
int ovs_net_id __read_mostly;
6765

@@ -1289,22 +1287,25 @@ static int ovs_flow_cmd_new_or_set(struct sk_buff *skb, struct genl_info *info)
12891287
/* Check if this is a duplicate flow */
12901288
flow = ovs_flow_lookup(table, &key);
12911289
if (!flow) {
1290+
struct flow_table *new_table = NULL;
12921291
struct sw_flow_mask *mask_p;
1292+
12931293
/* Bail out if we're not allowed to create a new flow. */
12941294
error = -ENOENT;
12951295
if (info->genlhdr->cmd == OVS_FLOW_CMD_SET)
12961296
goto err_unlock_ovs;
12971297

12981298
/* Expand table, if necessary, to make room. */
1299-
if (ovs_flow_tbl_need_to_expand(table)) {
1300-
struct flow_table *new_table;
1301-
1299+
if (ovs_flow_tbl_need_to_expand(table))
13021300
new_table = ovs_flow_tbl_expand(table);
1303-
if (!IS_ERR(new_table)) {
1304-
rcu_assign_pointer(dp->table, new_table);
1305-
ovs_flow_tbl_destroy(table, true);
1306-
table = ovsl_dereference(dp->table);
1307-
}
1301+
else if (time_after(jiffies, dp->last_rehash + REHASH_FLOW_INTERVAL))
1302+
new_table = ovs_flow_tbl_rehash(table);
1303+
1304+
if (new_table && !IS_ERR(new_table)) {
1305+
rcu_assign_pointer(dp->table, new_table);
1306+
ovs_flow_tbl_destroy(table, true);
1307+
table = ovsl_dereference(dp->table);
1308+
dp->last_rehash = jiffies;
13081309
}
13091310

13101311
/* Allocate flow. */
@@ -2336,32 +2337,6 @@ static int dp_register_genl(void)
23362337
return err;
23372338
}
23382339

2339-
static void rehash_flow_table(struct work_struct *work)
2340-
{
2341-
struct datapath *dp;
2342-
struct net *net;
2343-
2344-
ovs_lock();
2345-
rtnl_lock();
2346-
for_each_net(net) {
2347-
struct ovs_net *ovs_net = net_generic(net, ovs_net_id);
2348-
2349-
list_for_each_entry(dp, &ovs_net->dps, list_node) {
2350-
struct flow_table *old_table = ovsl_dereference(dp->table);
2351-
struct flow_table *new_table;
2352-
2353-
new_table = ovs_flow_tbl_rehash(old_table);
2354-
if (!IS_ERR(new_table)) {
2355-
rcu_assign_pointer(dp->table, new_table);
2356-
ovs_flow_tbl_destroy(old_table, true);
2357-
}
2358-
}
2359-
}
2360-
rtnl_unlock();
2361-
ovs_unlock();
2362-
schedule_delayed_work(&rehash_flow_wq, REHASH_FLOW_INTERVAL);
2363-
}
2364-
23652340
static int __net_init ovs_init_net(struct net *net)
23662341
{
23672342
struct ovs_net *ovs_net = net_generic(net, ovs_net_id);
@@ -2419,8 +2394,6 @@ static int __init dp_init(void)
24192394
if (err < 0)
24202395
goto error_unreg_notifier;
24212396

2422-
schedule_delayed_work(&rehash_flow_wq, REHASH_FLOW_INTERVAL);
2423-
24242397
return 0;
24252398

24262399
error_unreg_notifier:
@@ -2437,7 +2410,6 @@ static int __init dp_init(void)
24372410

24382411
static void dp_cleanup(void)
24392412
{
2440-
cancel_delayed_work_sync(&rehash_flow_wq);
24412413
dp_unregister_genl(ARRAY_SIZE(dp_genl_families));
24422414
unregister_netdevice_notifier(&ovs_dp_device_notifier);
24432415
unregister_pernet_device(&ovs_net_ops);

‎net/openvswitch/datapath.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ struct dp_stats_percpu {
6262
* ovs_mutex and RCU.
6363
* @stats_percpu: Per-CPU datapath statistics.
6464
* @net: Reference to net namespace.
65+
* @last_rehash: Timestamp of last rehash.
6566
*
6667
* Context: See the comment on locking at the top of datapath.c for additional
6768
* locking information.
@@ -83,6 +84,7 @@ struct datapath {
8384
/* Network namespace ref. */
8485
struct net *net;
8586
#endif
87+
unsigned long last_rehash;
8688
};
8789

8890
/**

0 commit comments

Comments
 (0)