diff options
author | Eric Wong <normalperson@yhbt.net> | 2013-01-31 04:20:35 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2013-01-31 04:35:39 +0000 |
commit | dffe6b3dc226cafb0a6107443f9d7e23095dd789 (patch) | |
tree | 7f19987f07feda681f7c1785b99a46ab118ce588 | |
parent | d68b0ad231192c6ccf701e66be66b6bc956bed2b (diff) | |
download | cmogstored-dffe6b3dc226cafb0a6107443f9d7e23095dd789.tar.gz |
We do not need all the weight of sockaddr_storage or NI_MAXHOST. cmogstored currently only supports IPv4 and IPv6[1] and (like any respectable server) will not perform reverse DNS lookups. This allows us to reduce our stack usage in some places and keep caches hotter. [1] MogileFS does not support IPv6, yet, even
-rw-r--r-- | cmogstored.h | 17 | ||||
-rw-r--r-- | http_put.c | 9 | ||||
-rw-r--r-- | inherit.c | 16 |
3 files changed, 25 insertions, 17 deletions
diff --git a/cmogstored.h b/cmogstored.h index 01b1233..df1e4f4 100644 --- a/cmogstored.h +++ b/cmogstored.h @@ -532,3 +532,20 @@ unsigned mog_process_reaped(pid_t); /* upgrade.c */ void mog_upgrade_prepare(int argc, char *argv[], char *envp[]); pid_t mog_upgrade_spawn(void); + +/* + * We only deal with ipv4 and ipv6 addresses (and no human-friendly + * hostnames/service names), so we can use smaller constants than the + * standard NI_MAXHOST/NI_MAXSERV values (1025 and 32 respectively). + * This reduces our per-thread stack usage and keeps caches hotter. + */ +#define MOG_NI_MAXHOST (INET6_ADDRSTRLEN) +#define MOG_NI_MAXSERV (sizeof(":65536")) + +/* avoid sockaddr_storage since that bigger than we need */ +union mog_sockaddr { + struct sockaddr_in in; + struct sockaddr_in6 in6; + struct sockaddr sa; + unsigned char bytes[1]; +}; @@ -440,12 +440,9 @@ static unsigned last_data_recv(int fd) MOG_NOINLINE static void read_err_dbg(struct mog_fd *mfd, ssize_t r) { - union { - struct sockaddr_storage ss; - struct sockaddr sa; - } any; - char addrbuf[INET6_ADDRSTRLEN]; - char portbuf[sizeof(":65536")]; + union mog_sockaddr any; + char addrbuf[MOG_NI_MAXHOST]; + char portbuf[MOG_NI_MAXSERV]; const char *addr; static const char no_ip[] = "unconnected"; const char *path = "(unknown)"; @@ -6,13 +6,7 @@ static Hash_table *listeners; /* yes, we'll scale to 10K listen sockets, L10K! */ struct listener { - union { - struct sockaddr_storage ss; - struct sockaddr_in in; - struct sockaddr_in6 in6; - struct sockaddr sa; - unsigned char bytes[sizeof(struct sockaddr_storage)]; - } as; + union mog_sockaddr as; socklen_t len; int fd; }; @@ -23,7 +17,7 @@ static bool listener_cmp(const void *a, const void *b) const struct listener *lb = b; return (la->len == lb->len) && - (memcmp(&la->as.ss, &lb->as.ss, lb->len) == 0); + (memcmp(&la->as.sa, &lb->as.sa, lb->len) == 0); } static size_t listener_hash(const void *x, size_t tablesize) @@ -43,11 +37,11 @@ static void register_listen_fd(int fd) struct listener tmp; struct listener *ins; int flags = NI_NUMERICSERV | NI_NUMERICSERV; - char hbuf[NI_MAXHOST]; - char sbuf[NI_MAXSERV]; + char hbuf[MOG_NI_MAXHOST]; + char sbuf[MOG_NI_MAXSERV]; int rc; - tmp.len = (socklen_t)sizeof(tmp.as.ss); + tmp.len = (socklen_t)sizeof(tmp.as); if (getsockname(fd, &tmp.as.sa, &tmp.len) != 0) die_errno("getsockname(fd=%d) failed", fd); |