net: netprio_cgroup: rework update socket logic
Subsystems (3)
PATCH 1/1 net: netprio_cgroup: rework update socket logic
Instead of updating the sk_cgrp_prioidx struct field on every send this only updates the field when a task is moved via cgroup infrastructure.
This allows sockets that may be used by a kernel worker thread to be managed. For example in the iscsi case today a user can put iscsid in a netprio cgroup and control traffic will be sent with the correct sk_cgrp_prioidx value set but as soon as data is sent the kernel worker thread isssues a send and sk_cgrp_prioidx is updated with the kernel worker threads value which is the default case.
It seems more correct to only update the field when the user explicitly sets it via control group infrastructure. This allows the users to manage sockets that may be used with other threads.
---
include/linux/net.h | 1 + include/net/netprio_cgroup.h | 4 ++- net/core/netprio_cgroup.c | 53 ++++++++++++++++++++++++++++++++++++++++++ net/core/sock.c | 6 ++--- net/socket.c | 5 ++-- 5 files changed, 61 insertions(+), 8 deletions(-)
include/linux/net.h +1 -0
@@ -248,6 +248,7 @@ extern int sock_recvmsg(struct socket *sock, struct msghdr *msg, size_t size, int flags);extern int sock_map_fd (struct socket *sock,int flags);extern struct socket *sockfd_lookup (int fd,int *err); +extern struct socket *sock_from_file (struct file *file,int *err);#define sockfd_put (sock) fput(sock->file)extern int net_ratelimit (void );
include/net/netprio_cgroup.h +2 -2
@@ -35,7 +35,7 @@ struct cgroup_netprio_state {extern int net_prio_subsys_id;#endif -extern void sock_update_netprioidx (struct sock *sk); +extern void sock_update_netprioidx (struct sock *sk,struct task_struct *task);#if IS_BUILTIN (CONFIG_NETPRIO_CGROUP )
@@ -82,7 +82,7 @@ static inline u32 task_netprioidx(struct task_struct *p)#endif /* CONFIG_NETPRIO_CGROUP */ #else -#define sock_update_netprioidx (sk) +#define sock_update_netprioidx (sk, task)#endif #endif /* _NET_CLS_CGROUP_H */
net/core/netprio_cgroup.c +53 -0
71 lines not on this page · raw message
net/core/sock.c +3 -3
@@ -1180,12 +1180,12 @@ void sock_update_classid(struct sock *sk) }EXPORT_SYMBOL (sock_update_classid); -void sock_update_netprioidx (struct sock *sk) +void sock_update_netprioidx (struct sock *sk,struct task_struct *task) {if (in_interrupt ())return ; - sk->sk_cgrp_prioidx =task_netprioidx (current); + sk->sk_cgrp_prioidx =task_netprioidx (task); }EXPORT_SYMBOL_GPL (sock_update_netprioidx);#endif
@@ -1215,7 +1215,7 @@ struct sock *sk_alloc(struct net *net, int family, gfp_t priority,atomic_set (&sk->sk_wmem_alloc,1 );sock_update_classid (sk); -sock_update_netprioidx (sk); +sock_update_netprioidx (sk, current); }return sk;
net/socket.c +2 -3
@@ -398,7 +398,7 @@ int sock_map_fd(struct socket *sock, int flags) }EXPORT_SYMBOL (sock_map_fd); -static struct socket *sock_from_file (struct file *file,int *err) +struct socket *sock_from_file (struct file *file,int *err) {if (file->f_op == &socket_file_ops)return file->private_data;/* set in sock_map_fd */
@@ -406,6 +406,7 @@ static struct socket *sock_from_file(struct file *file, int *err) *err = -ENOTSOCK ;return NULL ; } +EXPORT_SYMBOL (sock_from_file);/** * sockfd_lookup - Go from a file number to its socket slot
@@ -554,8 +555,6 @@ static inline int __sock_sendmsg_nosec(struct kiocb *iocb, struct socket *sock,sock_update_classid (sock->sk); -sock_update_netprioidx (sock->sk); - si->sock = sock; si->scm =NULL ; si->msg = msg;
Quoted 12 lines · John Fastabend
Instead of updating the
sk_cgrp_prioidxstruct field on every send this only updates the field when a task is moved via cgroup infrastructure.This allows sockets that may be used by a kernel worker thread to be managed. For example in the iscsi case today a user can put iscsid in a netprio cgroup and control traffic will be sent with the correct
sk_cgrp_prioidxvalue set but as soon as data is sent the kernel worker thread isssues a send andsk_cgrp_prioidxis updated with the kernel worker threads value which is the default case.
Quoted 5 lines
It seems more correct to only update the field when the user explicitly sets it via control group infrastructure. This allows the users to manage sockets that may be used with other threads.
Signed-off-by John Fastabend <[email protected]>
I like the idea, but IIRC last time we tried this I think it caused problems with processes that shared sockets. That is to say, if you have a parent and child process that dup an socket descriptior, and put them in separate cgroups, you get unpredictable results, as the socket gets assigned a priority based on the last processed that moved cgroups.
Neil
Quoted 1 line
Quoted 17 lines · Neil Horman
Quoted 16 lines · John Fastabend
Instead of updating the
sk_cgrp_prioidxstruct field on every send this only updates the field when a task is moved via cgroup infrastructure.This allows sockets that may be used by a kernel worker thread to be managed. For example in the iscsi case today a user can put iscsid in a netprio cgroup and control traffic will be sent with the correct
sk_cgrp_prioidxvalue set but as soon as data is sent the kernel worker thread isssues a send andsk_cgrp_prioidxis updated with the kernel worker threads value which is the default case.It seems more correct to only update the field when the user explicitly sets it via control group infrastructure. This allows the users to manage sockets that may be used with other threads.
Quoted 9 lines
Quoted 1 line
Signed-off-by John Fastabend <[email protected]>I like the idea, but IIRC last time we tried this I think it caused problems with processes that shared sockets. That is to say, if you have a parent and child process that dup an socket descriptior, and put them in separate cgroups, you get unpredictable results, as the socket gets assigned a priority based on the last processed that moved cgroups.
Neil
Shared sockets creates strange behavior as it exists today. If a dup of the socket fd is created the private data is still shared right. So in this case the sk_cgrp_prioidx value is going to get updated by both threads and then it is a race to see what it happens to be set to in the xmit path.
With this patch at least the behavior is deterministic. Without it I can create the above scenario but have no way to determine what the skb priority will actually be set to.
.John
Neil Horman
Acked-byQuoted 34 lines · John Fastabend
Quoted 17 lines · Neil Horman
Quoted 16 lines · John Fastabend
Instead of updating the
sk_cgrp_prioidxstruct field on every send this only updates the field when a task is moved via cgroup infrastructure.This allows sockets that may be used by a kernel worker thread to be managed. For example in the iscsi case today a user can put iscsid in a netprio cgroup and control traffic will be sent with the correct
sk_cgrp_prioidxvalue set but as soon as data is sent the kernel worker thread isssues a send andsk_cgrp_prioidxis updated with the kernel worker threads value which is the default case.It seems more correct to only update the field when the user explicitly sets it via control group infrastructure. This allows the users to manage sockets that may be used with other threads.
Quoted 9 lines
Quoted 1 line
Signed-off-by John Fastabend <[email protected]>I like the idea, but IIRC last time we tried this I think it caused problems with processes that shared sockets. That is to say, if you have a parent and child process that dup an socket descriptior, and put them in separate cgroups, you get unpredictable results, as the socket gets assigned a priority based on the last processed that moved cgroups.
Neil
Shared sockets creates strange behavior as it exists today. If a dup of the socket fd is created the private data is still shared right. So in this case the
sk_cgrp_prioidxvalue is going to get updated by both threads and then it is a race to see what it happens to be set to in the xmit path.
Quoted 6 lines
With this patch at least the behavior is deterministic. Without it I can create the above scenario but have no way to determine what the skb priority will actually be set to.
.John
Ok, I can buy that. Lets give this a try:
From: Neil Horman <[email protected]>
Date: Sat, 21 Jul 2012 13:18:55 -0400
Quoted 39 lines · John Fastabend
Quoted 38 lines · Neil Horman
Quoted 17 lines · John Fastabend
Quoted 16 lines
Instead of updating the
sk_cgrp_prioidxstruct field on every send this only updates the field when a task is moved via cgroup infrastructure.This allows sockets that may be used by a kernel worker thread to be managed. For example in the iscsi case today a user can put iscsid in a netprio cgroup and control traffic will be sent with the correct
sk_cgrp_prioidxvalue set but as soon as data is sent the kernel worker thread isssues a send andsk_cgrp_prioidxis updated with the kernel worker threads value which is the default case.It seems more correct to only update the field when the user explicitly sets it via control group infrastructure. This allows the users to manage sockets that may be used with other threads.
Quoted 9 lines
Quoted 1 line
Signed-off-by John Fastabend <[email protected]>I like the idea, but IIRC last time we tried this I think it caused problems with processes that shared sockets. That is to say, if you have a parent and child process that dup an socket descriptior, and put them in separate cgroups, you get unpredictable results, as the socket gets assigned a priority based on the last processed that moved cgroups.
Neil
Shared sockets creates strange behavior as it exists today. If a dup of the socket fd is created the private data is still shared right. So in this case the
sk_cgrp_prioidxvalue is going to get updated by both threads and then it is a race to see what it happens to be set to in the xmit path.With this patch at least the behavior is deterministic. Without it I can create the above scenario but have no way to determine what the skb priority will actually be set to.
Quoted 6 lines
Quoted 2 lines
.John
Ok, I can buy that. Lets give this a try:
Acked-by Neil Horman <[email protected]>
Applied.