From d5dc1ea8af7bfc2612d10c653ff5ed48e237d43b Mon Sep 17 00:00:00 2001 From: Thomas Schoebel-Theuer Date: Thu, 10 May 2018 11:16:34 +0200 Subject: [PATCH] all: differentiate traffic types --- kernel/mars_client.c | 12 +++++++++- kernel/mars_client.h | 1 + kernel/mars_net.c | 37 +++++++++++++++++++++++-------- kernel/mars_net.h | 4 ++-- kernel/mars_server.c | 6 ++--- kernel/sy_old/mars_main.c | 2 +- kernel/sy_old/mars_proc.c | 46 ++++++++++++++++++++++++++++----------- 7 files changed, 79 insertions(+), 29 deletions(-) diff --git a/kernel/mars_client.c b/kernel/mars_client.c index 76ab1e4a..e05da44c 100644 --- a/kernel/mars_client.c +++ b/kernel/mars_client.c @@ -145,9 +145,19 @@ int _setup_channel(struct client_bundle *bundle, int ch_nr) goto done; } + if (!bundle->params) { + struct sockaddr_in *_sockaddr = (void*)&sockaddr; + + int offset = (int)ntohs(_sockaddr->sin_port) - mars_net_default_port; + + if (offset < 0 || offset >= MARS_TRAFFIC_MAX) + offset = 0; + bundle->params = &mars_tcp_params[offset]; + } + status = mars_create_socket(&ch->socket, &sockaddr, - &default_tcp_params, + bundle->params, false); if (unlikely(status < 0)) { MARS_DBG("no socket, status = %d\n", status); diff --git a/kernel/mars_client.h b/kernel/mars_client.h index 89af5bb6..4dd032be 100644 --- a/kernel/mars_client.h +++ b/kernel/mars_client.h @@ -81,6 +81,7 @@ struct client_channel { struct client_bundle { char *host; char *path; + struct mars_tcp_params *params; int thread_count; int old_channel; wait_queue_head_t sender_event; diff --git a/kernel/mars_net.c b/kernel/mars_net.c index 1d3db62d..7ad50328 100644 --- a/kernel/mars_net.c +++ b/kernel/mars_net.c @@ -74,16 +74,35 @@ module_param_named(mars_port, mars_net_default_port, int, 0); * TODO: add compression / encryption. */ -struct mars_tcp_params default_tcp_params = { - .ip_tos = IPTOS_LOWDELAY, - .tcp_window_size = 8 * 1024 * 1024, // for long distance replications - .tcp_nodelay = 0, - .tcp_timeout = 2, - .tcp_keepcnt = 3, - .tcp_keepintvl = 3, // keepalive ping time - .tcp_keepidle = 4, +struct mars_tcp_params mars_tcp_params[MARS_TRAFFIC_MAX] = { + [MARS_TRAFFIC_META] = { + .ip_tos = IPTOS_LOWDELAY, + .tcp_window_size = 8 * 1024 * 1024, + .tcp_nodelay = 0, + .tcp_timeout = 2, + .tcp_keepcnt = 3, + .tcp_keepintvl = 3, + .tcp_keepidle = 4, + }, + [MARS_TRAFFIC_REPLICATION] = { + .ip_tos = IPTOS_RELIABILITY, + .tcp_window_size = 8 * 1024 * 1024, + .tcp_nodelay = 0, + .tcp_timeout = 2, + .tcp_keepcnt = 3, + .tcp_keepintvl = 3, + .tcp_keepidle = 4, + }, + [MARS_TRAFFIC_SYNC] = { + .ip_tos = IPTOS_MINCOST, + .tcp_window_size = 8 * 1024 * 1024, + .tcp_nodelay = 0, + .tcp_timeout = 2, + .tcp_keepcnt = 3, + .tcp_keepintvl = 3, + .tcp_keepidle = 4, + }, }; -EXPORT_SYMBOL(default_tcp_params); static void __setsockopt(struct socket *sock, int level, int optname, char *optval, int optsize) diff --git a/kernel/mars_net.h b/kernel/mars_net.h index 0c50d4b4..ceb78015 100644 --- a/kernel/mars_net.h +++ b/kernel/mars_net.h @@ -86,8 +86,6 @@ struct mars_tcp_params { int tcp_keepidle; }; -extern struct mars_tcp_params default_tcp_params; - enum mars_traffic_types { MARS_TRAFFIC_META, MARS_TRAFFIC_REPLICATION, @@ -95,6 +93,8 @@ enum mars_traffic_types { MARS_TRAFFIC_MAX /* this must come last */ }; +extern struct mars_tcp_params mars_tcp_params[MARS_TRAFFIC_MAX]; + enum { CMD_NOP, CMD_NOTIFY, diff --git a/kernel/mars_server.c b/kernel/mars_server.c index 20dcbd04..abf3671e 100644 --- a/kernel/mars_server.c +++ b/kernel/mars_server.c @@ -49,13 +49,13 @@ struct server_cookie { static struct server_cookie server_cookie[MARS_TRAFFIC_MAX] = { [MARS_TRAFFIC_META] = { - .server_params = &default_tcp_params, + .server_params = &mars_tcp_params[MARS_TRAFFIC_META], }, [MARS_TRAFFIC_REPLICATION] = { - .server_params = &default_tcp_params, + .server_params = &mars_tcp_params[MARS_TRAFFIC_REPLICATION], }, [MARS_TRAFFIC_SYNC] = { - .server_params = &default_tcp_params, + .server_params = &mars_tcp_params[MARS_TRAFFIC_SYNC], }, }; diff --git a/kernel/sy_old/mars_main.c b/kernel/sy_old/mars_main.c index f82b91aa..fcb9b7d0 100644 --- a/kernel/sy_old/mars_main.c +++ b/kernel/sy_old/mars_main.c @@ -2276,7 +2276,7 @@ int peer_thread(void *data) status = mars_create_socket(&peer->socket, &sockaddr, - &default_tcp_params, + &mars_tcp_params[MARS_TRAFFIC_META], false); if (unlikely(status < 0)) { MARS_INF("no connection to mars module on '%s' (%s) status = %d\n", peer->peer, real_peer, status); diff --git a/kernel/sy_old/mars_proc.c b/kernel/sy_old/mars_proc.c index 053ab4ca..9b132230 100644 --- a/kernel/sy_old/mars_proc.c +++ b/kernel/sy_old/mars_proc.c @@ -285,17 +285,25 @@ struct ctl_table io_tuning_table[] = { {} }; -static -struct ctl_table tcp_tuning_table[] = { - INT_ENTRY("ip_tos", default_tcp_params.ip_tos, 0600), - INT_ENTRY("tcp_window_size", default_tcp_params.tcp_window_size, 0600), - INT_ENTRY("tcp_nodelay", default_tcp_params.tcp_nodelay, 0600), - INT_ENTRY("tcp_timeout", default_tcp_params.tcp_timeout, 0600), - INT_ENTRY("tcp_keepcnt", default_tcp_params.tcp_keepcnt, 0600), - INT_ENTRY("tcp_keepintvl", default_tcp_params.tcp_keepintvl, 0600), - INT_ENTRY("tcp_keepidle", default_tcp_params.tcp_keepidle, 0600), - {} -}; +#define TCP_ENTRY(NAME,TRAFFIC_TYPE) \ + INT_ENTRY(#NAME, mars_tcp_params[TRAFFIC_TYPE].NAME, 0600) + +#define make_tcp_tuning_table(TRAFFIC_TYPE) \ +static \ +struct ctl_table tcp_tuning_table_##TRAFFIC_TYPE[] = { \ + TCP_ENTRY(ip_tos, TRAFFIC_TYPE), \ + TCP_ENTRY(tcp_window_size, TRAFFIC_TYPE), \ + TCP_ENTRY(tcp_nodelay, TRAFFIC_TYPE), \ + TCP_ENTRY(tcp_timeout, TRAFFIC_TYPE), \ + TCP_ENTRY(tcp_keepcnt, TRAFFIC_TYPE), \ + TCP_ENTRY(tcp_keepintvl, TRAFFIC_TYPE), \ + TCP_ENTRY(tcp_keepidle, TRAFFIC_TYPE), \ + {} \ +} + +make_tcp_tuning_table(MARS_TRAFFIC_META); +make_tcp_tuning_table(MARS_TRAFFIC_REPLICATION); +make_tcp_tuning_table(MARS_TRAFFIC_SYNC); static struct ctl_table mars_table[] = { @@ -416,9 +424,21 @@ struct ctl_table mars_table[] = { }, { _CTL_NAME - .procname = "tcp_tuning", + .procname = "tcp_tuning_0_meta_traffic", .mode = 0500, - .child = tcp_tuning_table, + .child = tcp_tuning_table_MARS_TRAFFIC_META, + }, + { + _CTL_NAME + .procname = "tcp_tuning_1_replication_traffic", + .mode = 0500, + .child = tcp_tuning_table_MARS_TRAFFIC_REPLICATION, + }, + { + _CTL_NAME + .procname = "tcp_tuning_2_sync_traffic", + .mode = 0500, + .child = tcp_tuning_table_MARS_TRAFFIC_SYNC, }, {} };