Skip to content

Commit ac2be03

Browse files
congwanggregkh
authored andcommitted
net_sched: get rid of rcu_barrier() in tcf_block_put_ext()
commit efbf789 upstream. Both Eric and Paolo noticed the rcu_barrier() we use in tcf_block_put_ext() could be a performance bottleneck when we have a lot of tc classes. Paolo provided the following to demonstrate the issue: tc qdisc add dev lo root htb for I in `seq 1 1000`; do tc class add dev lo parent 1: classid 1:$I htb rate 100kbit tc qdisc add dev lo parent 1:$I handle $((I + 1)): htb for J in `seq 1 10`; do tc filter add dev lo parent $((I + 1)): u32 match ip src 1.1.1.$J done done time tc qdisc del dev root real 0m54.764s user 0m0.023s sys 0m0.000s The rcu_barrier() there is to ensure we free the block after all chains are gone, that is, to queue tcf_block_put_final() at the tail of workqueue. We can achieve this ordering requirement by refcnt'ing tcf block instead, that is, the tcf block is freed only when the last chain in this block is gone. This also simplifies the code. Paolo reported after this patch we get: real 0m0.017s user 0m0.000s sys 0m0.017s Tested-by: Paolo Abeni <[email protected]> Cc: Eric Dumazet <[email protected]> Cc: Jiri Pirko <[email protected]> Cc: Jamal Hadi Salim <[email protected]> Signed-off-by: Cong Wang <[email protected]> Signed-off-by: David S. Miller <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 1c8e7e6 commit ac2be03

File tree

2 files changed

+9
-21
lines changed

2 files changed

+9
-21
lines changed

include/net/sch_generic.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,6 @@ struct tcf_chain {
273273

274274
struct tcf_block {
275275
struct list_head chain_list;
276-
struct work_struct work;
277276
};
278277

279278
static inline void qdisc_cb_private_validate(const struct sk_buff *skb, int sz)

net/sched/cls_api.c

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,12 @@ static void tcf_chain_flush(struct tcf_chain *chain)
211211

212212
static void tcf_chain_destroy(struct tcf_chain *chain)
213213
{
214+
struct tcf_block *block = chain->block;
215+
214216
list_del(&chain->list);
215217
kfree(chain);
218+
if (list_empty(&block->chain_list))
219+
kfree(block);
216220
}
217221

218222
static void tcf_chain_hold(struct tcf_chain *chain)
@@ -276,26 +280,12 @@ int tcf_block_get(struct tcf_block **p_block,
276280
}
277281
EXPORT_SYMBOL(tcf_block_get);
278282

279-
static void tcf_block_put_final(struct work_struct *work)
280-
{
281-
struct tcf_block *block = container_of(work, struct tcf_block, work);
282-
struct tcf_chain *chain, *tmp;
283-
284-
rtnl_lock();
285-
286-
/* At this point, all the chains should have refcnt == 1. */
287-
list_for_each_entry_safe(chain, tmp, &block->chain_list, list)
288-
tcf_chain_put(chain);
289-
rtnl_unlock();
290-
kfree(block);
291-
}
292-
293283
/* XXX: Standalone actions are not allowed to jump to any chain, and bound
294284
* actions should be all removed after flushing.
295285
*/
296286
void tcf_block_put(struct tcf_block *block)
297287
{
298-
struct tcf_chain *chain;
288+
struct tcf_chain *chain, *tmp;
299289

300290
if (!block)
301291
return;
@@ -310,12 +300,11 @@ void tcf_block_put(struct tcf_block *block)
310300
list_for_each_entry(chain, &block->chain_list, list)
311301
tcf_chain_flush(chain);
312302

313-
INIT_WORK(&block->work, tcf_block_put_final);
314-
/* Wait for RCU callbacks to release the reference count and make
315-
* sure their works have been queued before this.
303+
/* At this point, all the chains should have refcnt >= 1. Block will be
304+
* freed after all chains are gone.
316305
*/
317-
rcu_barrier();
318-
tcf_queue_work(&block->work);
306+
list_for_each_entry_safe(chain, tmp, &block->chain_list, list)
307+
tcf_chain_put(chain);
319308
}
320309
EXPORT_SYMBOL(tcf_block_put);
321310

0 commit comments

Comments
 (0)