From 698ffe3623f1b630ae3d0e206abd77876ecffb87 Mon Sep 17 00:00:00 2001 From: Joe Stringer Date: Tue, 4 Mar 2014 09:36:37 -0800 Subject: [PATCH] revalidator: Only revalidate high-throughput flows. Previously we would revalidate all flows if the "need_revalidate" flag was raised. This patch modifies the logic to delete low throughput flows rather than revalidate them. High-throughput flows are unaffected by this change. This patch identifies the flows based on the mean time between packets since the last dump. This change is primarily targeted at situations where: * Flow dump duration is high (~1 second) * Revalidation is triggered. (eg, by bridge reconfiguration or learning) After the need_revalidate flag is set, next time a new flow dump session starts, revalidators will begin revalidating the flows. This full revalidation is more expensive, which significantly increases the flow dump duration. At the end of this dump session, the datapath flow management algorithms kick in for the next dump: * If flow dump duration becomes too long, the flow limit is decreased. * The number of flows in the datapath then exceeds the flow_limit. * As the flow_limit is exceeded, max_idle is temporarily set to 100ms. * Revalidators delete all flows that haven't seen traffic recently. The effect of this is that many low-throughput flows are deleted after revalidation, even if they are valid. The revalidation is unnecessary for flows that would be deleted anyway, so this patch skips the revalidation step for those flows. Note that this patch will only perform this optimization if the flow has already been dumped at least once, and only if the time since the last dump is sufficiently long. This gives the flow a chance to become high-throughput. Signed-off-by: Joe Stringer Acked-by: Ethan Jackson --- v2: Acked. v1: Determine "high-throughput" by packets rather than bytes. Calculate the mean time between packets for comparison, rather than comparing the number of packets since the last dump. RFC: First post. --- ofproto/ofproto-dpif-upcall.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/ofproto/ofproto-dpif-upcall.c b/ofproto/ofproto-dpif-upcall.c index 9bf133660..0d7dd8e7f 100644 --- a/ofproto/ofproto-dpif-upcall.c +++ b/ofproto/ofproto-dpif-upcall.c @@ -1330,6 +1330,32 @@ ukey_delete(struct revalidator *revalidator, struct udpif_key *ukey) free(ukey); } +static bool +should_revalidate(uint64_t packets, long long int used) +{ + long long int metric, now, duration; + + /* Calculate the mean time between seeing these packets. If this + * exceeds the threshold, then delete the flow rather than performing + * costly revalidation for flows that aren't being hit frequently. + * + * This is targeted at situations where the dump_duration is high (~1s), + * and revalidation is triggered by a call to udpif_revalidate(). In + * these situations, revalidation of all flows causes fluctuations in the + * flow_limit due to the interaction with the dump_duration and max_idle. + * This tends to result in deletion of low-throughput flows anyway, so + * skip the revalidation and just delete those flows. */ + packets = MAX(packets, 1); + now = MAX(used, time_msec()); + duration = now - used; + metric = duration / packets; + + if (metric > 200) { + return false; + } + return true; +} + static bool revalidate_ukey(struct udpif *udpif, struct udpif_flow_dump *udump, struct udpif_key *ukey) @@ -1344,6 +1370,7 @@ revalidate_ukey(struct udpif *udpif, struct udpif_flow_dump *udump, uint32_t *udump32, *xout32; odp_port_t odp_in_port; struct xlate_in xin; + long long int last_used; int error; size_t i; bool may_learn, ok; @@ -1364,6 +1391,7 @@ revalidate_ukey(struct udpif *udpif, struct udpif_flow_dump *udump, } } + last_used = ukey->stats.used; push.used = udump->stats.used; push.tcp_flags = udump->stats.tcp_flags; push.n_packets = udump->stats.n_packets > ukey->stats.n_packets @@ -1374,6 +1402,12 @@ revalidate_ukey(struct udpif *udpif, struct udpif_flow_dump *udump, : 0; ukey->stats = udump->stats; + if (udump->need_revalidate && last_used + && !should_revalidate(push.n_packets, last_used)) { + ok = false; + goto exit; + } + if (!push.n_packets && !udump->need_revalidate) { ok = true; goto exit; -- 2.43.0