diff options
author | Eric Dumazet <eric.dumazet@gmail.com> | 2011-09-19 01:52:27 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2011-09-28 13:29:50 -0400 |
commit | 16e5726269611b71c930054ffe9b858c1cea88eb (patch) | |
tree | 50d25ec97d639b418964bad2f45774d657468c74 /include/net/scm.h | |
parent | a9e9fd7182332d0cf5f3e601df3e71dd431b70d7 (diff) |
af_unix: dont send SCM_CREDENTIALS by default
Since commit 7361c36c5224 (af_unix: Allow credentials to work across
user and pid namespaces) af_unix performance dropped a lot.
This is because we now take a reference on pid and cred in each write(),
and release them in read(), usually done from another process,
eventually from another cpu. This triggers false sharing.
# Events: 154K cycles
#
# Overhead Command Shared Object Symbol
# ........ ....... .................. .........................
#
10.40% hackbench [kernel.kallsyms] [k] put_pid
8.60% hackbench [kernel.kallsyms] [k] unix_stream_recvmsg
7.87% hackbench [kernel.kallsyms] [k] unix_stream_sendmsg
6.11% hackbench [kernel.kallsyms] [k] do_raw_spin_lock
4.95% hackbench [kernel.kallsyms] [k] unix_scm_to_skb
4.87% hackbench [kernel.kallsyms] [k] pid_nr_ns
4.34% hackbench [kernel.kallsyms] [k] cred_to_ucred
2.39% hackbench [kernel.kallsyms] [k] unix_destruct_scm
2.24% hackbench [kernel.kallsyms] [k] sub_preempt_count
1.75% hackbench [kernel.kallsyms] [k] fget_light
1.51% hackbench [kernel.kallsyms] [k]
__mutex_lock_interruptible_slowpath
1.42% hackbench [kernel.kallsyms] [k] sock_alloc_send_pskb
This patch includes SCM_CREDENTIALS information in a af_unix message/skb
only if requested by the sender, [man 7 unix for details how to include
ancillary data using sendmsg() system call]
Note: This might break buggy applications that expected SCM_CREDENTIAL
from an unaware write() system call, and receiver not using SO_PASSCRED
socket option.
If SOCK_PASSCRED is set on source or destination socket, we still
include credentials for mere write() syscalls.
Performance boost in hackbench : more than 50% gain on a 16 thread
machine (2 quad-core cpus, 2 threads per core)
hackbench 20 thread 2000
4.228 sec instead of 9.102 sec
Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Acked-by: Tim Chen <tim.c.chen@linux.intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include/net/scm.h')
-rw-r--r-- | include/net/scm.h | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/include/net/scm.h b/include/net/scm.h index 745460fa2f02..d456f4c71a32 100644 --- a/include/net/scm.h +++ b/include/net/scm.h | |||
@@ -49,7 +49,7 @@ static __inline__ void scm_set_cred(struct scm_cookie *scm, | |||
49 | struct pid *pid, const struct cred *cred) | 49 | struct pid *pid, const struct cred *cred) |
50 | { | 50 | { |
51 | scm->pid = get_pid(pid); | 51 | scm->pid = get_pid(pid); |
52 | scm->cred = get_cred(cred); | 52 | scm->cred = cred ? get_cred(cred) : NULL; |
53 | cred_to_ucred(pid, cred, &scm->creds); | 53 | cred_to_ucred(pid, cred, &scm->creds); |
54 | } | 54 | } |
55 | 55 | ||
@@ -73,8 +73,7 @@ static __inline__ void scm_destroy(struct scm_cookie *scm) | |||
73 | static __inline__ int scm_send(struct socket *sock, struct msghdr *msg, | 73 | static __inline__ int scm_send(struct socket *sock, struct msghdr *msg, |
74 | struct scm_cookie *scm) | 74 | struct scm_cookie *scm) |
75 | { | 75 | { |
76 | scm_set_cred(scm, task_tgid(current), current_cred()); | 76 | memset(scm, 0, sizeof(*scm)); |
77 | scm->fp = NULL; | ||
78 | unix_get_peersec_dgram(sock, scm); | 77 | unix_get_peersec_dgram(sock, scm); |
79 | if (msg->msg_controllen <= 0) | 78 | if (msg->msg_controllen <= 0) |
80 | return 0; | 79 | return 0; |