Skip to content

Commit 97ede29

Browse files
ying-xuedavem330
authored andcommitted
tipc: convert name table read-write lock to RCU
Convert tipc name table read-write lock to RCU. After this change, a new spin lock is used to protect name table on write side while RCU is applied on read side. Signed-off-by: Ying Xue <[email protected]> Reviewed-by: Erik Hugne <[email protected]> Reviewed-by: Jon Maloy <[email protected]> Tested-by: Erik Hugne <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 834caaf commit 97ede29

File tree

4 files changed

+69
-59
lines changed

4 files changed

+69
-59
lines changed

include/linux/rculist.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,15 @@ static inline void hlist_add_behind_rcu(struct hlist_node *n,
542542
pos = hlist_entry_safe(rcu_dereference_bh((pos)->member.next),\
543543
typeof(*(pos)), member))
544544

545+
/**
546+
* hlist_for_each_entry_from_rcu - iterate over a hlist continuing from current point
547+
* @pos: the type * to use as a loop cursor.
548+
* @member: the name of the hlist_node within the struct.
549+
*/
550+
#define hlist_for_each_entry_from_rcu(pos, member) \
551+
for (; pos; \
552+
pos = hlist_entry_safe(rcu_dereference((pos)->member.next),\
553+
typeof(*(pos)), member))
545554

546555
#endif /* __KERNEL__ */
547556
#endif

net/tipc/name_distr.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ struct sk_buff *tipc_named_publish(struct publication *publ)
113113
struct sk_buff *buf;
114114
struct distr_item *item;
115115

116-
list_add_tail(&publ->local_list,
117-
&tipc_nametbl->publ_list[publ->scope]);
116+
list_add_tail_rcu(&publ->local_list,
117+
&tipc_nametbl->publ_list[publ->scope]);
118118

119119
if (publ->scope == TIPC_NODE_SCOPE)
120120
return NULL;
@@ -208,12 +208,12 @@ void tipc_named_node_up(u32 dnode)
208208

209209
__skb_queue_head_init(&head);
210210

211-
read_lock_bh(&tipc_nametbl_lock);
211+
rcu_read_lock();
212212
named_distribute(&head, dnode,
213213
&tipc_nametbl->publ_list[TIPC_CLUSTER_SCOPE]);
214214
named_distribute(&head, dnode,
215215
&tipc_nametbl->publ_list[TIPC_ZONE_SCOPE]);
216-
read_unlock_bh(&tipc_nametbl_lock);
216+
rcu_read_unlock();
217217

218218
tipc_link_xmit(&head, dnode, dnode);
219219
}
@@ -260,12 +260,12 @@ static void tipc_publ_purge(struct publication *publ, u32 addr)
260260
{
261261
struct publication *p;
262262

263-
write_lock_bh(&tipc_nametbl_lock);
263+
spin_lock_bh(&tipc_nametbl_lock);
264264
p = tipc_nametbl_remove_publ(publ->type, publ->lower,
265265
publ->node, publ->ref, publ->key);
266266
if (p)
267267
tipc_publ_unsubscribe(p, addr);
268-
write_unlock_bh(&tipc_nametbl_lock);
268+
spin_unlock_bh(&tipc_nametbl_lock);
269269

270270
if (p != publ) {
271271
pr_err("Unable to remove publication from failed node\n"
@@ -274,7 +274,7 @@ static void tipc_publ_purge(struct publication *publ, u32 addr)
274274
publ->key);
275275
}
276276

277-
kfree(p);
277+
kfree_rcu(p, rcu);
278278
}
279279

280280
void tipc_publ_notify(struct list_head *nsub_list, u32 addr)
@@ -311,7 +311,7 @@ static bool tipc_update_nametbl(struct distr_item *i, u32 node, u32 dtype)
311311
ntohl(i->key));
312312
if (publ) {
313313
tipc_publ_unsubscribe(publ, node);
314-
kfree(publ);
314+
kfree_rcu(publ, rcu);
315315
return true;
316316
}
317317
} else {
@@ -376,14 +376,14 @@ void tipc_named_rcv(struct sk_buff *buf)
376376
u32 count = msg_data_sz(msg) / ITEM_SIZE;
377377
u32 node = msg_orignode(msg);
378378

379-
write_lock_bh(&tipc_nametbl_lock);
379+
spin_lock_bh(&tipc_nametbl_lock);
380380
while (count--) {
381381
if (!tipc_update_nametbl(item, node, msg_type(msg)))
382382
tipc_named_add_backlog(item, msg_type(msg), node);
383383
item++;
384384
}
385385
tipc_named_process_backlog();
386-
write_unlock_bh(&tipc_nametbl_lock);
386+
spin_unlock_bh(&tipc_nametbl_lock);
387387
kfree_skb(buf);
388388
}
389389

@@ -399,12 +399,12 @@ void tipc_named_reinit(void)
399399
struct publication *publ;
400400
int scope;
401401

402-
write_lock_bh(&tipc_nametbl_lock);
402+
spin_lock_bh(&tipc_nametbl_lock);
403403

404404
for (scope = TIPC_ZONE_SCOPE; scope <= TIPC_NODE_SCOPE; scope++)
405-
list_for_each_entry(publ, &tipc_nametbl->publ_list[scope],
406-
local_list)
405+
list_for_each_entry_rcu(publ, &tipc_nametbl->publ_list[scope],
406+
local_list)
407407
publ->node = tipc_own_addr;
408408

409-
write_unlock_bh(&tipc_nametbl_lock);
409+
spin_unlock_bh(&tipc_nametbl_lock);
410410
}

0 commit comments

Comments
 (0)