Save the next session timeout when sweeping sessions for cleanup so that
we can avoid unnecessary runs of the sweeping algorithm.
Type: fix
Change-Id: I736d00f2dfe242af10f963fbe34b11128f8b0613
Signed-off-by: Klement Sekera <ksekera@cisco.com>
/* *INDENT-OFF* */
vec_foreach (tsm, sm->per_thread_data)
{
/* *INDENT-OFF* */
vec_foreach (tsm, sm->per_thread_data)
{
+ tsm->min_session_timeout = 0;
if (sm->endpoint_dependent)
{
clib_bihash_init_16_8 (&tsm->in2out_ed, "in2out-ed",
if (sm->endpoint_dependent)
{
clib_bihash_init_16_8 (&tsm->in2out_ed, "in2out-ed",
/* real thread index */
u32 thread_index;
/* real thread index */
u32 thread_index;
+
+ /* discovered minimum session timeout time */
+ u64 min_session_timeout;
} snat_main_per_thread_data_t;
struct snat_main_s;
} snat_main_per_thread_data_t;
struct snat_main_s;
(f64) nat44_session_get_timeout (sm, s);
if (now < sess_timeout_time)
(f64) nat44_session_get_timeout (sm, s);
if (now < sess_timeout_time)
+ {
+ tsm->min_session_timeout =
+ clib_min (sess_timeout_time, tsm->min_session_timeout);
+ continue;
+ }
nat44_session_cleanup (s, thread_index);
}
nat44_session_cleanup (s, thread_index);
}
if (PREDICT_TRUE (pool_elts (tsm->sessions) < sm->max_translations))
return;
if (PREDICT_TRUE (pool_elts (tsm->sessions) < sm->max_translations))
return;
- // there is no place so we try to cleanup all users in this thread
- /* *INDENT-OFF* */
- pool_foreach (u, tsm->users,
- ({
- nat44_user_try_cleanup (u, thread_index, now);
- }));
- /* *INDENT-ON* */
+ if (now >= tsm->min_session_timeout)
+ {
+ tsm->min_session_timeout = ~0;
+ // there is no place so we try to cleanup all users in this thread
+ /* *INDENT-OFF* */
+ pool_foreach (u, tsm->users,
+ ({ nat44_user_try_cleanup (u, thread_index, now); }));
+ /* *INDENT-ON* */
+ if (~0 == tsm->min_session_timeout)
+ {
+ tsm->min_session_timeout = 0;
+ }
+ }
- // each time user creates a new session we try to cleanup expired sessions
- nat44_user_try_cleanup (pool_elt_at_index (tsm->users, value.value),
- thread_index, now);
+ if (now >= tsm->min_session_timeout)
+ {
+ tsm->min_session_timeout = ~0;
+ // each time user creates a new session we try to cleanup expired sessions
+ nat44_user_try_cleanup (pool_elt_at_index (tsm->users, value.value),
+ thread_index, now);
+ if (~0 == tsm->min_session_timeout)
+ {
+ tsm->min_session_timeout = 0;
+ }
+ }
}
static_always_inline void
}
static_always_inline void