In the recirc_alloc_id__ function, when attempting to allocate a recirc ID for new flow metadata, first check if a node with the same state already exists. If a matching node is found, safely acquire a reference count using ovs_refcount_try_ref_rcu() to avoid potential reference counting race conditions in concurrent environments.
This optimization prevents duplicate creation of nodes with identical states, improves resource utilization, and ensures correctness in multi-threaded environments through RCU-safe reference counting operations. Signed-off-by: Bin Shen <[email protected]> Signed-off-by: Sunyang Wu <[email protected]> --- ofproto/ofproto-dpif-rid.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ofproto/ofproto-dpif-rid.c b/ofproto/ofproto-dpif-rid.c index f01468025..a9b691ad7 100644 --- a/ofproto/ofproto-dpif-rid.c +++ b/ofproto/ofproto-dpif-rid.c @@ -241,6 +241,13 @@ recirc_alloc_id__(const struct frozen_state *state, uint32_t hash) frozen_state_clone(CONST_CAST(struct frozen_state *, &node->state), state); ovs_mutex_lock(&mutex); + struct recirc_id_node *old_node; + old_node = recirc_find_equal(state, hash); + if (old_node && ovs_refcount_try_ref_rcu(&old_node->refcount)) { + xfree(node); + ovs_mutex_unlock(&mutex); + return old_node; + } for (;;) { /* Claim the next ID. The ID space should be sparse enough for the allocation to succeed at the first try. We do skip the first -- 2.19.0.rc0.windows.1 _______________________________________________ dev mailing list [email protected] https://mail.openvswitch.org/mailman/listinfo/ovs-dev
