From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTP id 2ED2F5A026F for ; Sat, 30 Dec 2023 11:33:13 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1703932391; 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=ESnhhrFqGwZTa13l6LZ70I32ol3NHRpBfeG0sO7UmgY=; b=NnDH2Huadwv9YSA2YhFyEe3DMuiPE3VFWn4x/PpZKcIddEGezkxUBR4hiZb/7wP1EndvY+ jmLnTJ8/4uEVsfiKNCSlA9rU7eDf5o3F2llnj5fE36MHOJwO2TzwFONBVCO2YXfc2gEwpW PI4z/OJpeZU2zqtt+QoOBa1iWN72k+o= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-386-miUymS9MOm2lks3MyyVEYA-1; Sat, 30 Dec 2023 05:33:08 -0500 X-MC-Unique: miUymS9MOm2lks3MyyVEYA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EA7178353E0; Sat, 30 Dec 2023 10:33:07 +0000 (UTC) Received: from elisabeth (unknown [10.39.208.24]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 15EB940C6EB9; Sat, 30 Dec 2023 10:33:06 +0000 (UTC) Date: Sat, 30 Dec 2023 11:33:04 +0100 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH v3 13/13] flow: Avoid moving flow entries to compact table Message-ID: <20231230113304.37c60a9a@elisabeth> In-Reply-To: <20231228192525.7ba1ee48@elisabeth> References: <20231221061549.976358-1-david@gibson.dropbear.id.au> <20231221061549.976358-14-david@gibson.dropbear.id.au> <20231228192525.7ba1ee48@elisabeth> Organization: Red Hat MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: YL2BFJRE2GQG5PA2QY7N4PX7KIVTPJWI X-Message-ID-Hash: YL2BFJRE2GQG5PA2QY7N4PX7KIVTPJWI 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 Thu, 28 Dec 2023 19:25:25 +0100 Stefano Brivio wrote: > > On Thu, 21 Dec 2023 17:15:49 +1100 > > David Gibson wrote: > > > > [...] > > [...] > > I wonder if we really have to keep track of the number of (non-)entries > in the free "block", and if we have to be explicit about the two cases. > > I'm trying to find out if we can simplify the whole thing with slightly > different variants, for example: So... I think the version with (explicit) blocks has this fundamental advantage, on deletion: > > + flow->f.type = FLOW_TYPE_NONE; > > + /* Put it back in a length 1 free block, don't attempt to fully reverse > > + * flow_alloc()s steps. This will get folded together the next time > > + * flow_defer_handler runs anyway() */ > > + flow->free.n = 1; > > + flow->free.next = flow_first_free; > > + flow_first_free = FLOW_IDX(flow); which is doable even without explicit blocks, but much harder to follow. Other than the comments I have, I would go ahead with your approach. My attempt below in case you're interested. The comment at the end of flow_del() shows the issue I'm facing: struct flow_free_block { /* Must be first element */ struct flow_common f; unsigned next_free; unsigned next_used; }; static union flow *flow_alloc(void) { union flow *flow; if (flow_first_free >= FLOW_MAX) return NULL; flow = flowtab + flow_first_free; flow_first_free = flow->free.next_free; memset(flow, 0, sizeof(*flow)); /* TODO: select region */ return flow; } static void flow_del(union flow *del) { union flow *left, *right, *next_used = NULL, *first_free; del->f.type = FLOW_TYPE_NONE; left = (FLOW_IDX(del) > 0) ? FLOW(FLOW_IDX(del) - 1) : NULL; right = (FLOW_IDX(del) < FLOW_MAX - 1) ? FLOW(FLOW_IDX(del) + 1) : NULL; first_free = flow_first_free < FLOW_MAX ? FLOW(flow_first_free) : NULL; if (right) { if (right->f.type == FLOW_TYPE_NONE) del->free.next_used = right->free.next_used; else del->free.next_used = right; } else { del->free.next_used = FLOW_MAX; } if (left && left->f.type == FLOW_TYPE_NONE) { left->free.next_free = FLOW_IDX(del); left->free.next_used = del->free.next_used; return; } if (flow_first_free == FLOW_MAX) { flow_first_free = FLOW_IDX(del); } else if (flow_first_free > FLOW_IDX(del)) { flow_first_free = FLOW_IDX(del); del->free.next_free = flow_first_free; } else if (flow_first_free < FLOW_IDX(del)) { ; /* Walk free slots from flow_first_free until FLOW_IDX(del) to * find insertion point... but that makes deletion at most O(n), * perhaps O(log(n)), certainly not O(1). * * Or just link out-of-order for the moment, and fix this up in * flow_next(), but then "blocks" help representing this. */ } } static union flow *flow_next(union flow *whence) { if (FLOW_IDX(whence) >= FLOW_MAX - 1) return NULL; if (whence->f.type != FLOW_TYPE_NONE) whence++; if (whence->f.type == FLOW_TYPE_NONE) return whence->free.next_used; return whence; } -- Stefano