Commit ba988f87 authored by Chaitanya Huilgol's avatar Chaitanya Huilgol Committed by Ilya Dryomov

libceph: tcp_nodelay support

TCP_NODELAY socket option set on connection sockets,
disables Nagle’s algorithm and improves latency characteristics.
tcp_nodelay(default)/notcp_nodelay option flags provided to
enable/disable setting the socket option.
Signed-off-by: default avatarChaitanya Huilgol <chaitanya.huilgol@sandisk.com>
[idryomov@redhat.com: NO_TCP_NODELAY -> TCP_NODELAY, minor adjustments]
Signed-off-by: default avatarIlya Dryomov <idryomov@redhat.com>
parent cf32bd9c
...@@ -30,8 +30,9 @@ ...@@ -30,8 +30,9 @@
#define CEPH_OPT_MYIP (1<<2) /* specified my ip */ #define CEPH_OPT_MYIP (1<<2) /* specified my ip */
#define CEPH_OPT_NOCRC (1<<3) /* no data crc on writes */ #define CEPH_OPT_NOCRC (1<<3) /* no data crc on writes */
#define CEPH_OPT_NOMSGAUTH (1<<4) /* not require cephx message signature */ #define CEPH_OPT_NOMSGAUTH (1<<4) /* not require cephx message signature */
#define CEPH_OPT_TCP_NODELAY (1<<5) /* TCP_NODELAY on TCP sockets */
#define CEPH_OPT_DEFAULT (0) #define CEPH_OPT_DEFAULT (CEPH_OPT_TCP_NODELAY)
#define ceph_set_opt(client, opt) \ #define ceph_set_opt(client, opt) \
(client)->options->flags |= CEPH_OPT_##opt; (client)->options->flags |= CEPH_OPT_##opt;
......
...@@ -57,6 +57,7 @@ struct ceph_messenger { ...@@ -57,6 +57,7 @@ struct ceph_messenger {
atomic_t stopping; atomic_t stopping;
bool nocrc; bool nocrc;
bool tcp_nodelay;
/* /*
* the global_seq counts connections i (attempt to) initiate * the global_seq counts connections i (attempt to) initiate
...@@ -264,7 +265,8 @@ extern void ceph_messenger_init(struct ceph_messenger *msgr, ...@@ -264,7 +265,8 @@ extern void ceph_messenger_init(struct ceph_messenger *msgr,
struct ceph_entity_addr *myaddr, struct ceph_entity_addr *myaddr,
u64 supported_features, u64 supported_features,
u64 required_features, u64 required_features,
bool nocrc); bool nocrc,
bool tcp_nodelay);
extern void ceph_con_init(struct ceph_connection *con, void *private, extern void ceph_con_init(struct ceph_connection *con, void *private,
const struct ceph_connection_operations *ops, const struct ceph_connection_operations *ops,
......
...@@ -239,6 +239,8 @@ enum { ...@@ -239,6 +239,8 @@ enum {
Opt_nocrc, Opt_nocrc,
Opt_cephx_require_signatures, Opt_cephx_require_signatures,
Opt_nocephx_require_signatures, Opt_nocephx_require_signatures,
Opt_tcp_nodelay,
Opt_notcp_nodelay,
}; };
static match_table_t opt_tokens = { static match_table_t opt_tokens = {
...@@ -259,6 +261,8 @@ static match_table_t opt_tokens = { ...@@ -259,6 +261,8 @@ static match_table_t opt_tokens = {
{Opt_nocrc, "nocrc"}, {Opt_nocrc, "nocrc"},
{Opt_cephx_require_signatures, "cephx_require_signatures"}, {Opt_cephx_require_signatures, "cephx_require_signatures"},
{Opt_nocephx_require_signatures, "nocephx_require_signatures"}, {Opt_nocephx_require_signatures, "nocephx_require_signatures"},
{Opt_tcp_nodelay, "tcp_nodelay"},
{Opt_notcp_nodelay, "notcp_nodelay"},
{-1, NULL} {-1, NULL}
}; };
...@@ -457,6 +461,7 @@ ceph_parse_options(char *options, const char *dev_name, ...@@ -457,6 +461,7 @@ ceph_parse_options(char *options, const char *dev_name,
case Opt_nocrc: case Opt_nocrc:
opt->flags |= CEPH_OPT_NOCRC; opt->flags |= CEPH_OPT_NOCRC;
break; break;
case Opt_cephx_require_signatures: case Opt_cephx_require_signatures:
opt->flags &= ~CEPH_OPT_NOMSGAUTH; opt->flags &= ~CEPH_OPT_NOMSGAUTH;
break; break;
...@@ -464,6 +469,13 @@ ceph_parse_options(char *options, const char *dev_name, ...@@ -464,6 +469,13 @@ ceph_parse_options(char *options, const char *dev_name,
opt->flags |= CEPH_OPT_NOMSGAUTH; opt->flags |= CEPH_OPT_NOMSGAUTH;
break; break;
case Opt_tcp_nodelay:
opt->flags |= CEPH_OPT_TCP_NODELAY;
break;
case Opt_notcp_nodelay:
opt->flags &= ~CEPH_OPT_TCP_NODELAY;
break;
default: default:
BUG_ON(token); BUG_ON(token);
} }
...@@ -518,10 +530,12 @@ struct ceph_client *ceph_create_client(struct ceph_options *opt, void *private, ...@@ -518,10 +530,12 @@ struct ceph_client *ceph_create_client(struct ceph_options *opt, void *private,
/* msgr */ /* msgr */
if (ceph_test_opt(client, MYIP)) if (ceph_test_opt(client, MYIP))
myaddr = &client->options->my_addr; myaddr = &client->options->my_addr;
ceph_messenger_init(&client->msgr, myaddr, ceph_messenger_init(&client->msgr, myaddr,
client->supported_features, client->supported_features,
client->required_features, client->required_features,
ceph_test_opt(client, NOCRC)); ceph_test_opt(client, NOCRC),
ceph_test_opt(client, TCP_NODELAY));
/* subsystems */ /* subsystems */
err = ceph_monc_init(&client->monc, client); err = ceph_monc_init(&client->monc, client);
......
...@@ -510,6 +510,16 @@ static int ceph_tcp_connect(struct ceph_connection *con) ...@@ -510,6 +510,16 @@ static int ceph_tcp_connect(struct ceph_connection *con)
return ret; return ret;
} }
if (con->msgr->tcp_nodelay) {
int optval = 1;
ret = kernel_setsockopt(sock, SOL_TCP, TCP_NODELAY,
(char *)&optval, sizeof(optval));
if (ret)
pr_err("kernel_setsockopt(TCP_NODELAY) failed: %d",
ret);
}
sk_set_memalloc(sock->sk); sk_set_memalloc(sock->sk);
con->sock = sock; con->sock = sock;
...@@ -2922,7 +2932,8 @@ void ceph_messenger_init(struct ceph_messenger *msgr, ...@@ -2922,7 +2932,8 @@ void ceph_messenger_init(struct ceph_messenger *msgr,
struct ceph_entity_addr *myaddr, struct ceph_entity_addr *myaddr,
u64 supported_features, u64 supported_features,
u64 required_features, u64 required_features,
bool nocrc) bool nocrc,
bool tcp_nodelay)
{ {
msgr->supported_features = supported_features; msgr->supported_features = supported_features;
msgr->required_features = required_features; msgr->required_features = required_features;
...@@ -2937,6 +2948,7 @@ void ceph_messenger_init(struct ceph_messenger *msgr, ...@@ -2937,6 +2948,7 @@ void ceph_messenger_init(struct ceph_messenger *msgr,
get_random_bytes(&msgr->inst.addr.nonce, sizeof(msgr->inst.addr.nonce)); get_random_bytes(&msgr->inst.addr.nonce, sizeof(msgr->inst.addr.nonce));
encode_my_addr(msgr); encode_my_addr(msgr);
msgr->nocrc = nocrc; msgr->nocrc = nocrc;
msgr->tcp_nodelay = tcp_nodelay;
atomic_set(&msgr->stopping, 0); atomic_set(&msgr->stopping, 0);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment