From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: passt.top; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Tq85LKzC; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTPS id D92FB5A0271 for ; Thu, 17 Sep 2026 21:08:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1789672108; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=j64S7bpwxrS5e+iUpBpZvhEYYON90saSmWqApjP0m5s=; b=Tq85LKzCMcaFFxX+HeiFBRpcXSpGnk3S+bZR7//AUz3DjHfJRSQGIA1KURHVWmOoibDSMK Hy3UmR3GxuPdWfTxd3AYxYGfZSjoRpWDfIUKgILTz2rk9G0GxptpfLpM7QMwbrGgftlVdz 8fFZklRuKlXd0r2hEok+F2CTSF0NDDQ= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-501-Exf9uHStPhevPo34XC2aWQ-1; Thu, 17 Sep 2026 15:08:27 -0400 X-MC-Unique: Exf9uHStPhevPo34XC2aWQ-1 X-Mimecast-MFC-AGG-ID: Exf9uHStPhevPo34XC2aWQ_1789672105 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-49e6b5c5f44so11382955e9.2 for ; Thu, 17 Sep 2026 12:08:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789672105; x=1790276905; h=date:content-transfer-encoding:content-type:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to:content-type; bh=j64S7bpwxrS5e+iUpBpZvhEYYON90saSmWqApjP0m5s=; b=1r3n/g/sa4H4blGCDncBSJJsgaUuwN6xPFQPieAsH/7ezeflHTqPWsAEe9eRXyUGAd GFxa+o2SUN8rfx1XfhZaWYfe2ttxLivNecNN1icmRunrBYoAaJnOODrlowEXA/HiVl5b RvfIYrO+AcGerT7Az/grmwTYfH4TFOTT1lcbsiw8DM7RtOL1UtRmUp12lRiyJHPlY4x0 dYfKrREEfVDMhKTPrTSbGZ1czuharVRLc4CgQ8pCh6rkCG0jZAWgSRckGUWfBHkZN5Gu +thfJTF5wn2m/ncwRQyoVZO+hNEmFs4uU/Vu+e90j6p2Qis8QFtjBormJz//Ppr36yCQ bw9Q== X-Gm-Message-State: AFuF++k1ck8PowA4p66oJNiN4c8LwLpnb3Y8Rez9Ga8cv6tfqM4oU88q 8sPcWZXnTttnZWYyByJwluRqU19E5tou5mzynpKggqKwKOntpKEdArkB3/W4jINOVVRpszILOBF RgajwI6r/858iiSelyfEm9RYkjxAGcPAJ8huLHNiU7QEHKt3UqNnfXCQe/CPRPQ== X-Gm-Gg: AYBFou3JzqohGfYPk5oq6crnl/W3j//9Jbpj1i9DrcfrnPO1vF9JZyBzqW1g7kpb0m9 QTDoYOtFhKF3DRgrUd0Kc8bzOD4YS55olKWy37pFdQjo4yDHhWz+Pzyi5S56NWwd/65MxpYArHf 4SXrkVmJwnM8B+kR6aCgRHiYx1/BqXk/QT9wQHNlVaaMeP2wEevsJka68LmfIejY+tYueOPjRGz iqugi0iLFtAiQ9jUoL2AO5/pDbdzDMzE2IXP41/M1FTU70f8DASeGSCi6B+4jpHe5f18ZE1mGgO j1Gew1d437+5FCNOq/QQxX57GAlOn86wx+USB52DQrd6m/UjXaxUFa3jDKx/jQsnxxAe3Sw/vJ2 UqIa1KtWXs9aCjju3XGs07pwTWl9B X-Received: by 2002:a05:6000:4b11:b0:487:bcc:2c08 with SMTP id ffacd0b85a97d-4870ceede98mr9514670f8f.14.1789672104901; Thu, 17 Sep 2026 12:08:24 -0700 (PDT) X-Received: by 2002:a05:6000:4b11:b0:487:bcc:2c08 with SMTP id ffacd0b85a97d-4870ceede98mr9514649f8f.14.1789672104444; Thu, 17 Sep 2026 12:08:24 -0700 (PDT) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [176.103.220.4]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4870bf27c65sm18571783f8f.21.2026.09.17.12.08.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Sep 2026 12:08:23 -0700 (PDT) From: Stefano Brivio To: Martin Schitter Subject: Re: [PATCH v2 3/3] Optimize route dependency solver. Message-ID: <20260917210822.681fa49a@elisabeth> In-Reply-To: <20260908181631.537802-4-ms+git@mur.at> References: <20260908181631.537802-1-ms+git@mur.at> <20260908181631.537802-4-ms+git@mur.at> Organization: Red Hat X-Mailer: Claws Mail 4.2.0 (GTK 3.24.49; x86_64-pc-linux-gnu) MIME-Version: 1.0 Date: Thu, 17 Sep 2026 21:08:23 +0200 (CEST) X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: fT8MmxNkzEWVMMChLLN2qZ7erRLARK1TChayoDSmHdo_1789672105 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: QHMSMNWQ5DETZLNXOG2PNC6P35GZNDAE X-Message-ID-Hash: QHMSMNWQ5DETZLNXOG2PNC6P35GZNDAE X-MailFrom: sbrivio@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: passt-dev@passt.top X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On Tue, 8 Sep 2026 18:13:14 +0000 Martin Schitter wrote: > Avoid retransmitting routes that explicitly got reported as already > existing. Oops. I feel a bit dumb now. > Never make more resolution attempts than there are still unresolved > dependency errors. > > In the context of my current mesh network with ~700 route entries > these changes reduce the required processing time from 5.5s to 15ms. Ouch. Nice. > --- > netlink.c | 26 +++++++++++++++++++------- > 1 file changed, 19 insertions(+), 7 deletions(-) > > diff --git a/netlink.c b/netlink.c > index 65cc5d7..0e1c82a 100644 > --- a/netlink.c > +++ b/netlink.c > @@ -703,13 +703,12 @@ int nl_route_dup(int s_src, unsigned int ifi_src, > > /* Routes might have dependencies between each other, and the kernel > * processes RTM_NEWROUTE messages sequentially. For n routes, we might > - * need to send the requests up to n times to get all of them inserted. > - * Routes that have been already inserted will return -EEXIST, but we > - * can safely ignore that and repeat the requests. This avoids the need > - * to calculate dependencies: let the kernel do that. > + * need to send the requests up to n times in the worst case to get all > + * of them inserted. > */ > clock_gettime(CLOCK_MONOTONIC, &start); > - for (i = 0; i < dup_routes; i++) { > + for (i = dup_routes; i > 0; i--) { > + unsigned int dep_errors = 0; > for (nh = (struct nlmsghdr *)buf, left = nlmsgs_size; > NLMSG_OK(nh, left); > nh = NLMSG_NEXT(nh, left)) { > @@ -722,10 +721,23 @@ int nl_route_dup(int s_src, unsigned int ifi_src, > rc = nl_do(s_dst, nh, RTM_NEWROUTE, > (flags & ~NLM_F_DUMP_FILTERED) | NLM_F_CREATE, > nh->nlmsg_len); > - if (rc < 0 && rc != -EEXIST && > - rc != -ENETUNREACH && rc != -EHOSTUNREACH) > + > + if ( rc == -EEXIST) { Coding style: if (rc == -EEXIST) { > + /* Exclude existing routes from further retry attempts */ > + nh->nlmsg_type = NLMSG_NOOP; > + continue; > + } > + if ( rc == -ENETUNREACH || rc == -EHOSTUNREACH){ Coding style: if (rc == -ENETUNREACH || rc == -EHOSTUNREACH) { > + dep_errors++; > + continue; > + } > + if (rc < 0) > return rc; > } > + debug("route dependency errors: %d", dep_errors); See my comments to debug() calls in 1/3. > + /* Avoid having much more resolution attempts than > + * there are still unresolved dependency errors */ > + i = MIN(i, dep_errors++); It took me a while to understand how you do this, and I'm mostly convinced it's correct, but I'm also convinced this is equivalent to a much simpler implementation: stop when we get no errors at all for the whole bunch. That is, using dep_errors: for (i = 0; i < dup_routes; i++) { [...] if (!dep_errors) /* All inserted, done */ break; } ...right? > } > clock_gettime(CLOCK_MONOTONIC, &now); > debug("route dependency handling time: %f s", -- Stefano