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, reuse it by leveraging the existing recirc_ref_equal function to safely acquire a reference count.
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: Sunyang Wu <[email protected]> Signed-off-by: Bin Shen <[email protected]> --- ofproto/ofproto-dpif-rid.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ofproto/ofproto-dpif-rid.c b/ofproto/ofproto-dpif-rid.c index f01468025..c67726cb6 100644 --- a/ofproto/ofproto-dpif-rid.c +++ b/ofproto/ofproto-dpif-rid.c @@ -233,9 +233,17 @@ static struct recirc_id_node * recirc_alloc_id__(const struct frozen_state *state, uint32_t hash) { ovs_assert(state->action_set_len <= state->ofpacts_len); + struct recirc_id_node *node = NULL; + struct recirc_id_node *existing_node = NULL; - struct recirc_id_node *node = xzalloc(sizeof *node); + /* First try to find an existing node with the same state. */ + existing_node = recirc_ref_equal(state, hash); + if (existing_node) { + return existing_node; + } + /* No existing node found, create a new one. */ + node = xzalloc(sizeof *node); node->hash = hash; ovs_refcount_init(&node->refcount); frozen_state_clone(CONST_CAST(struct frozen_state *, &node->state), state); -- 2.19.0.rc0.windows.1 _______________________________________________ dev mailing list [email protected] https://mail.openvswitch.org/mailman/listinfo/ovs-dev
