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 1EFDB5A026D for ; Tue, 2 Jan 2024 19:13:52 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704219231; 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=vF6hv6Zn0UXN9PwJQiuFcLT9dOcIvfzTRZ4MsOPJ7ow=; b=CrfPvVg7g4uWeIV0+9C0x5XbvRGBQNvs9k30nuDCcC+riQYzhixAxENHrxhjVhJVR8piCJ I4CRPpqa4j48mycx/QjiTdH8vImr75XM4SzDMHlYTpEz7E31NPxDPBiLwheUe+dEw+NvYP wDfeO0youiipWKxJnf37ADZ/6G4OC+0= 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-524-IdSM0sJeM8ChAX-rWS6Rwg-1; Tue, 02 Jan 2024 13:13:44 -0500 X-MC-Unique: IdSM0sJeM8ChAX-rWS6Rwg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (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 EE02183B825; Tue, 2 Jan 2024 18:13:43 +0000 (UTC) Received: from elisabeth (unknown [10.39.208.16]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 268F33C2F; Tue, 2 Jan 2024 18:13:42 +0000 (UTC) Date: Tue, 2 Jan 2024 19:13:41 +0100 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH v3 13/13] flow: Avoid moving flow entries to compact table Message-ID: <20240102191341.7c91dd44@elisabeth> In-Reply-To: References: <20231221061549.976358-1-david@gibson.dropbear.id.au> <20231221061549.976358-14-david@gibson.dropbear.id.au> <20231228192525.7ba1ee48@elisabeth> <20231230113304.37c60a9a@elisabeth> Organization: Red Hat MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: PLJEUSSVAZ5JZCFRDG76ON2KH22BRLGT X-Message-ID-Hash: PLJEUSSVAZ5JZCFRDG76ON2KH22BRLGT 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 Mon, 1 Jan 2024 23:01:17 +1100 David Gibson wrote: > On Sat, Dec 30, 2023 at 11:33:04AM +0100, Stefano Brivio wrote: > > 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. > > Remember this is not a general deletion, only a "cancel" of the most > recent allocation. Oh, I thought that was only the case for this series and you would use that as actual deletion in another pending series (which I haven't finished reviewing yet). But now I'm not sure anymore why I was thinking this... Anyway... do we really need it, then? Can't we just mark the "failed" flows as whatever means "closed" for a specific protocol, and clean them up later, instead of calling cancel() right away? > To reduce fragmentation we are keeping the linked > list of free clusters in strictly ascending order. The logic above is > only correct if the entry we're freeing is before any other free entry > in the table. That will be the case for the most recent allocation, > because we always allocatte the first free entry in the table. I see now. This isn't entirely clear from the "Theory of Operation", on the other hand it's probably a bad idea to overload that description with all these details. > > 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; > fg > > > > 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). > > Exactly. I can't see any way (short of far more complex data > structures) around having a linear scan somewhere, although you can > kind of choose whether it happens on alloc or free. > > The idea of my implementation is to have it at free time - but to > merge it with an existing linear scan so it won't have an additional > cost. Right, yes, I see now. This idea is also not terribly clear from the description, by the way, but I don't have a good proposal right now. -- Stefano