From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 8F8BA5A005E for ; Wed, 16 Nov 2022 05:42:26 +0100 (CET) Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4NBr4R1f3fz4xbd; Wed, 16 Nov 2022 15:42:15 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1668573735; bh=oV3P+aXfVGBmzCk0pNGZT453MFgzPMKie6C093w9Nlc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kOlYgvGQWg1uT5TNRRANxeNJzQj3vM1nQKt2P5XQSIMnEBJKis4jN2KoQ80losW6C RQmt1fQOdbHyL8VGFLBvZxwCG1y0ZmYtVARqDiAiSxQ/zBc98E8zQ+W0yJ7XurkTS/ 6ztnEJ62Mn5q6lmCf8gr+6Hif3SN9/rl76msa/08= From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH 11/32] tcp: Unify tcp_defer_handler and tcp_splice_defer_handler() Date: Wed, 16 Nov 2022 15:41:51 +1100 Message-Id: <20221116044212.3876516-12-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221116044212.3876516-1-david@gibson.dropbear.id.au> References: <20221116044212.3876516-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: 3ZU3K5L4XOUGTDPSGYN4VJDTJ2E3M7MR X-Message-ID-Hash: 3ZU3K5L4XOUGTDPSGYN4VJDTJ2E3M7MR X-MailFrom: dgibson@gandalf.ozlabs.org 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: David Gibson X-Mailman-Version: 3.3.3 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: These two functions each step through non-spliced and spliced connections respectively and clean up entries for closed connections. To avoid scanning the connection table twice, we merge these into a single function which scans the unified table and performs the appropriate sort of cleanup action on each one. Signed-off-by: David Gibson --- tcp.c | 20 +++++++++++--------- tcp_conn.h | 1 + tcp_splice.c | 24 +----------------------- tcp_splice.h | 1 - 4 files changed, 13 insertions(+), 33 deletions(-) diff --git a/tcp.c b/tcp.c index 01b08c8..598634f 100644 --- a/tcp.c +++ b/tcp.c @@ -1527,21 +1527,23 @@ void tcp_defer_handler(struct ctx *c) { int max_conns = c->tcp.conn_count / 100 * TCP_CONN_PRESSURE; int max_files = c->nofile / 100 * TCP_FILE_PRESSURE; - struct tcp_tap_conn *conn; + union tcp_conn *conn; tcp_l2_flags_buf_flush(c); tcp_l2_data_buf_flush(c); - tcp_splice_defer_handler(c); - - if (c->tcp.conn_count < MIN(max_files, max_conns)) + if ((c->tcp.conn_count < MIN(max_files, max_conns)) && + (c->tcp.splice_conn_count < MIN(max_files / 6, max_conns))) return; - for (conn = CONN(c->tcp.conn_count - 1); conn >= CONN(0); conn--) { - if (conn->c.spliced) - continue; - if (conn->events == CLOSED) - tcp_conn_destroy(c, conn); + for (conn = tc + c->tcp.conn_count - 1; conn >= tc; conn--) { + if (conn->c.spliced) { + if (conn->splice.flags & CLOSING) + tcp_splice_destroy(c, &conn->splice); + } else { + if (conn->tap.events == CLOSED) + tcp_conn_destroy(c, &conn->tap); + } } } diff --git a/tcp_conn.h b/tcp_conn.h index 4295f7d..634e259 100644 --- a/tcp_conn.h +++ b/tcp_conn.h @@ -200,5 +200,6 @@ extern union tcp_conn tc[]; void tcp_splice_conn_update(struct ctx *c, struct tcp_splice_conn *new); void tcp_table_compact(struct ctx *c, union tcp_conn *hole); +void tcp_splice_destroy(struct ctx *c, struct tcp_splice_conn *conn); #endif /* TCP_CONN_H */ diff --git a/tcp_splice.c b/tcp_splice.c index c986a9c..ad2b216 100644 --- a/tcp_splice.c +++ b/tcp_splice.c @@ -111,7 +111,6 @@ static void tcp_splice_conn_epoll_events(uint16_t events, *b |= (events & B_OUT_WAIT) ? EPOLLOUT : 0; } -static void tcp_splice_destroy(struct ctx *c, struct tcp_splice_conn *conn); static int tcp_splice_epoll_ctl(const struct ctx *c, struct tcp_splice_conn *conn); @@ -257,7 +256,7 @@ void tcp_splice_conn_update(struct ctx *c, struct tcp_splice_conn *new) * @c: Execution context * @conn: Connection pointer */ -static void tcp_splice_destroy(struct ctx *c, struct tcp_splice_conn *conn) +void tcp_splice_destroy(struct ctx *c, struct tcp_splice_conn *conn) { if (conn->events & SPLICE_ESTABLISHED) { /* Flushing might need to block: don't recycle them. */ @@ -849,24 +848,3 @@ void tcp_splice_timer(struct ctx *c) tcp_splice_pipe_refill(c); } - -/** - * tcp_splice_defer_handler() - Close connections without timer on file pressure - * @c: Execution context - */ -void tcp_splice_defer_handler(struct ctx *c) -{ - int max_conns = c->tcp.conn_count / 100 * TCP_SPLICE_CONN_PRESSURE; - int max_files = c->nofile / 100 * TCP_SPLICE_FILE_PRESSURE; - struct tcp_splice_conn *conn; - - if (c->tcp.conn_count < MIN(max_files / 6, max_conns)) - return; - - for (conn = CONN(c->tcp.conn_count - 1); conn >= CONN(0); conn--) { - if (!conn->c.spliced) - continue; - if (conn->flags & CLOSING) - tcp_splice_destroy(c, conn); - } -} diff --git a/tcp_splice.h b/tcp_splice.h index e8c70e9..82e057c 100644 --- a/tcp_splice.h +++ b/tcp_splice.h @@ -10,6 +10,5 @@ void tcp_sock_handler_splice(struct ctx *c, union epoll_ref ref, uint32_t events); void tcp_splice_init(struct ctx *c); void tcp_splice_timer(struct ctx *c); -void tcp_splice_defer_handler(struct ctx *c); #endif /* TCP_SPLICE_H */ -- 2.38.1