From: David Gibson <david@gibson.dropbear.id.au>
To: passt-dev@passt.top, Stefano Brivio <sbrivio@redhat.com>
Cc: David Gibson <david@gibson.dropbear.id.au>
Subject: [PATCH 07/14] tcp: Improved helpers to update connections after moving
Date: Mon, 14 Nov 2022 17:17:04 +1100 [thread overview]
Message-ID: <20221114061711.1655510-8-david@gibson.dropbear.id.au> (raw)
In-Reply-To: <20221114061711.1655510-1-david@gibson.dropbear.id.au>
When we compact the connection tables (both spliced and non-spliced) we
need to move entries from one slot to another. That requires some updates
in the entries themselves. Add helpers to make all the necessary updates
for the spliced and non-spliced cases. This will simplify later cleanups.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
tcp.c | 16 +++++++++-------
tcp_splice.c | 17 ++++++++++++++---
2 files changed, 23 insertions(+), 10 deletions(-)
diff --git a/tcp.c b/tcp.c
index 1acb0c6..44e1640 100644
--- a/tcp.c
+++ b/tcp.c
@@ -1291,11 +1291,13 @@ static void tcp_hash_remove(const struct tcp_tap_conn *conn)
}
/**
- * tcp_hash_update() - Update pointer for given connection
- * @old: Old connection pointer
- * @new: New connection pointer
+ * tcp_tap_conn_update() - Update tcp_tap_conn when being moved in the table
+ * @c: Execution context
+ * @old: Old location of tcp_tap_conn
+ * @new: New location of tcp_tap_conn
*/
-static void tcp_hash_update(struct tcp_tap_conn *old, struct tcp_tap_conn *new)
+static void tcp_tap_conn_update(struct ctx *c, struct tcp_tap_conn *old,
+ struct tcp_tap_conn *new)
{
struct tcp_tap_conn *entry, *prev = NULL;
int b = old->hash_bucket;
@@ -1314,6 +1316,8 @@ static void tcp_hash_update(struct tcp_tap_conn *old, struct tcp_tap_conn *new)
debug("TCP: hash table update: old index %li, new index %li, sock %i, "
"bucket: %i, old: %p, new: %p",
CONN_IDX(old), CONN_IDX(new), new->sock, b, old, new);
+
+ tcp_epoll_ctl(c, new);
}
/**
@@ -1361,9 +1365,7 @@ static void tcp_table_compact(struct ctx *c, struct tcp_tap_conn *hole)
memcpy(hole, from, sizeof(*hole));
to = hole;
- tcp_hash_update(from, to);
-
- tcp_epoll_ctl(c, to);
+ tcp_tap_conn_update(c, from, to);
debug("TCP: hash table compaction: old index %li, new index %li, "
"sock %i, from: %p, to: %p",
diff --git a/tcp_splice.c b/tcp_splice.c
index c4d4e6f..42133af 100644
--- a/tcp_splice.c
+++ b/tcp_splice.c
@@ -242,6 +242,19 @@ static void conn_event_do(const struct ctx *c, struct tcp_splice_conn *conn,
conn_event_do(c, conn, event); \
} while (0)
+
+/**
+ * tcp_splice_conn_update() - Update tcp_splice_conn when being moved in the table
+ * @c: Execution context
+ * @new: New location of tcp_splice_conn
+ */
+static void tcp_splice_conn_update(struct ctx *c, struct tcp_splice_conn *new)
+{
+ tcp_splice_epoll_ctl(c, new);
+ if (tcp_splice_epoll_ctl(c, new))
+ conn_flag(c, new, CLOSING);
+}
+
/**
* tcp_table_splice_compact - Compact spliced connection table
* @c: Execution context
@@ -269,9 +282,7 @@ static void tcp_table_splice_compact(struct ctx *c,
debug("TCP (spliced): index %li moved to %li",
CONN_IDX(move), CONN_IDX(hole));
- tcp_splice_epoll_ctl(c, hole);
- if (tcp_splice_epoll_ctl(c, hole))
- conn_flag(c, hole, CLOSING);
+ tcp_splice_conn_update(c, hole);
}
/**
--
@@ -242,6 +242,19 @@ static void conn_event_do(const struct ctx *c, struct tcp_splice_conn *conn,
conn_event_do(c, conn, event); \
} while (0)
+
+/**
+ * tcp_splice_conn_update() - Update tcp_splice_conn when being moved in the table
+ * @c: Execution context
+ * @new: New location of tcp_splice_conn
+ */
+static void tcp_splice_conn_update(struct ctx *c, struct tcp_splice_conn *new)
+{
+ tcp_splice_epoll_ctl(c, new);
+ if (tcp_splice_epoll_ctl(c, new))
+ conn_flag(c, new, CLOSING);
+}
+
/**
* tcp_table_splice_compact - Compact spliced connection table
* @c: Execution context
@@ -269,9 +282,7 @@ static void tcp_table_splice_compact(struct ctx *c,
debug("TCP (spliced): index %li moved to %li",
CONN_IDX(move), CONN_IDX(hole));
- tcp_splice_epoll_ctl(c, hole);
- if (tcp_splice_epoll_ctl(c, hole))
- conn_flag(c, hole, CLOSING);
+ tcp_splice_conn_update(c, hole);
}
/**
--
2.38.1
next prev parent reply other threads:[~2022-11-14 6:17 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-14 6:16 [PATCH 00/14] RFC: tcp: Don't use separate listening sockets for spliced and non-spliced connections David Gibson
2022-11-14 6:16 ` [PATCH 01/14] style: Minor corrections to function comments David Gibson
2022-11-14 6:16 ` [PATCH 02/14] tcp: Remove unused TCP_MAX_SOCKS constant David Gibson
2022-11-14 6:17 ` [PATCH 03/14] tcp: Better helpers for converting between connection pointer and index David Gibson
2022-11-14 6:17 ` [PATCH 04/14] tcp_splice: Helpers for converting from index to/from tcp_splice_conn David Gibson
2022-11-14 6:17 ` [PATCH 05/14] tcp: Move connection state structures into a shared header David Gibson
2022-11-14 6:17 ` [PATCH 06/14] tcp: Add connection union type David Gibson
2022-11-14 6:17 ` David Gibson [this message]
2022-11-14 6:17 ` [PATCH 08/14] tcp: Unify spliced and non-spliced connection tables David Gibson
2022-11-14 6:17 ` [PATCH 09/14] tcp: Unify tcp_defer_handler and tcp_splice_defer_handler() David Gibson
2022-11-14 6:17 ` [PATCH 10/14] tcp: Partially unify tcp_timer() and tcp_splice_timer() David Gibson
2022-11-14 6:17 ` [PATCH 11/14] tcp: Unify the IN_EPOLL flag David Gibson
2022-11-14 6:17 ` [PATCH 12/14] tcp: Separate helpers to create ns listening sockets David Gibson
2022-11-14 6:17 ` [PATCH 13/14] tcp: Unify part of spliced and non-spliced conn_from_sock path David Gibson
2022-11-14 6:17 ` [PATCH 14/14] tcp: Use the same sockets to listen for spliced and non-spliced connections David Gibson
2022-11-15 1:22 ` [PATCH 00/14] RFC: tcp: Don't use separate listening sockets " Stefano Brivio
2022-11-15 4:57 ` David Gibson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221114061711.1655510-8-david@gibson.dropbear.id.au \
--to=david@gibson.dropbear.id.au \
--cc=passt-dev@passt.top \
--cc=sbrivio@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://passt.top/passt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).