sockfs: switch to ->free_inode()
Subsystems (4)
PATCH 1/1 sockfs: switch to ->free_inode()
we do have an RCU-delayed part there already (freeing the wq), so it's not like the pipe situation; moreover, it might be worth considering coallocating wq with the rest of struct sock_alloc. ->sk_wq in struct sock would remain a pointer as it is, but the object it normally points to would be coallocated with struct socket...
--- net/socket.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
net/socket.c +3 -3
@@ -258,12 +258,12 @@ static struct inode *sock_alloc_inode(struct super_block *sb)return &ei->vfs_inode; } -static void sock_destroy_inode (struct inode *inode) +static void sock_free_inode (struct inode *inode) {struct socket_alloc *ei; ei = container_of(inode, struct socket_alloc, vfs_inode); -kfree_rcu (ei->socket.wq, rcu); +kfree (ei->socket.wq);kmem_cache_free (sock_inode_cachep, ei); }
@@ -288,7 +288,7 @@ static void init_inodecache(void)static const struct super_operations sockfs_ops = { .alloc_inode = sock_alloc_inode, - .destroy_inode = sock_destroy_inode, + .free_inode = sock_free_inode, .statfs = simple_statfs, };
Signature · 1 line
2.11.0
PATCH 1/1 coallocate socket_wq with socket itself
socket->wq is assign-once, set when we are initializing both struct socket it's in and struct socket_wq it points to. As the matter of fact, the only reason for separate allocation was the ability to RCU-delay freeing of socket_wq. RCU-delaying the freeing of socket itself gets rid of that need, so we can just fold struct socket_wq into the end of struct socket and simplify the life both for sock_alloc_inode() (one allocation instead of two) and for tun/tap oddballs, where we used to embed struct socket and struct socket_wq into the same structure (now - embedding just the struct socket).
Note that reference to struct socket_wq in struct sock does remain a reference - that's unchanged.
--- drivers/net/tap.c | 5 ++--- drivers/net/tun.c | 8 +++----- include/linux/if_tap.h | 1 - include/linux/net.h | 4 ++-- include/net/sock.h | 4 ++-- net/core/sock.c | 2 +- net/socket.c | 19 +++++-------------- 7 files changed, 15 insertions(+), 28 deletions(-)
drivers/net/tap.c +2 -3
@@ -520,8 +520,7 @@ static int tap_open(struct inode *inode, struct file *file) goto err; } -RCU_INIT_POINTER (q->sock.wq, &q->wq); -init_waitqueue_head (&q->wq.wait); +init_waitqueue_head (&q->sock.wq.wait); q->sock.type =SOCK_RAW ; q->sock.state =SS_CONNECTED ; q->sock.file = file;
@@ -579,7 +578,7 @@ static __poll_t tap_poll(struct file *file, poll_table *wait) goto out; mask =0 ; -poll_wait (file, &q->wq.wait, wait); +poll_wait (file, &q->sock.wq.wait, wait);if (!ptr_ring_empty (&q->ring)) mask |=EPOLLIN |EPOLLRDNORM ;
drivers/net/tun.c +3 -5
@@ -160,7 +160,6 @@ struct tun_pcpu_stats {struct tun_file {struct sock sk;struct socket socket; -struct socket_wq wq;struct tun_struct __rcu *tun;struct fasync_struct *fasync;/* only used for fasnyc */
@@ -2165,7 +2164,7 @@ static void *tun_ring_recv(struct tun_file *tfile, int noblock, int *err) goto out; } -add_wait_queue (&tfile->wq.wait, &wait); +add_wait_queue (&tfile->socket.wq.wait, &wait);while (1 ) {set_current_state (TASK_INTERRUPTIBLE );
@@ -2185,7 +2184,7 @@ static void *tun_ring_recv(struct tun_file *tfile, int noblock, int *err) }__set_current_state (TASK_RUNNING ); -remove_wait_queue (&tfile->wq.wait, &wait); +remove_wait_queue (&tfile->socket.wq.wait, &wait); out: *err = error;
@@ -3415,8 +3414,7 @@ static int tun_chr_open(struct inode *inode, struct file * file) tfile->flags =0 ; tfile->ifindex =0 ; -init_waitqueue_head (&tfile->wq.wait); -RCU_INIT_POINTER (tfile->socket.wq, &tfile->wq); +init_waitqueue_head (&tfile->socket.wq.wait); tfile->socket.file = file; tfile->socket.ops = &tun_socket_ops;
include/linux/if_tap.h +0 -1
@@ -62,7 +62,6 @@ struct tap_dev {struct tap_queue {struct sock sk;struct socket sock; -struct socket_wq wq;int vnet_hdr_sz;struct tap_dev __rcu *tap;struct file *file;
include/linux/net.h +2 -2
@@ -116,11 +116,11 @@ struct socket {unsigned long flags; -struct socket_wq *wq; -struct file *file;struct sock *sk;const struct proto_ops *ops; + +struct socket_wq wq; };struct vm_area_struct ;
include/net/sock.h +2 -2
@@ -1822,7 +1822,7 @@ static inline void sock_graft(struct sock *sk, struct socket *parent) {WARN_ON (parent->sk);write_lock_bh (&sk->sk_callback_lock); -rcu_assign_pointer (sk->sk_wq, parent->wq); +rcu_assign_pointer (sk->sk_wq, &parent->wq); parent->sk = sk;sk_set_socket (sk, parent); sk->sk_uid =SOCK_INODE (parent)->i_uid;
@@ -2100,7 +2100,7 @@ static inline void sock_poll_wait(struct file *filp, struct socket *sock, poll_table *p) {if (!poll_does_not_wait (p)) { -poll_wait (filp, &sock->wq->wait, p); +poll_wait (filp, &sock->wq.wait, p);/* We need to be sure we are in sync with the * socket flags modification. *
net/core/sock.c +1 -1
@@ -2847,7 +2847,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)if (sock) { sk->sk_type = sock->type; -RCU_INIT_POINTER (sk->sk_wq, sock->wq); +RCU_INIT_POINTER (sk->sk_wq, &sock->wq); sock->sk = sk; sk->sk_uid =SOCK_INODE (sock)->i_uid; }else {
net/socket.c +5 -14
@@ -234,20 +234,13 @@ static struct kmem_cache *sock_inode_cachep __ro_after_init;static struct inode *sock_alloc_inode (struct super_block *sb) {struct socket_alloc *ei; -struct socket_wq *wq; ei =kmem_cache_alloc (sock_inode_cachep,GFP_KERNEL );if (!ei)return NULL ; - wq =kmalloc (sizeof (*wq),GFP_KERNEL ); -if (!wq) { -kmem_cache_free (sock_inode_cachep, ei); -return NULL ; - } -init_waitqueue_head (&wq->wait); - wq->fasync_list =NULL ; - wq->flags =0 ; - ei->socket.wq = wq; +init_waitqueue_head (&ei->socket.wq.wait); + ei->socket.wq.fasync_list =NULL ; + ei->socket.wq.flags =0 ; ei->socket.state =SS_UNCONNECTED ; ei->socket.flags =0 ;
@@ -263,7 +256,6 @@ static void sock_free_inode(struct inode *inode)struct socket_alloc *ei; ei = container_of(inode, struct socket_alloc, vfs_inode); -kfree (ei->socket.wq);kmem_cache_free (sock_inode_cachep, ei); }
@@ -599,7 +591,7 @@ static void __sock_release(struct socket *sock, struct inode *inode)module_put (owner); } -if (sock->wq->fasync_list) +if (sock->wq.fasync_list)pr_err ("%s: fasync list not empty!\n" , __func__);if (!sock->file) {
@@ -1288,13 +1280,12 @@ static int sock_fasync(int fd, struct file *filp, int on) {struct socket *sock = filp->private_data;struct sock *sk = sock->sk; -struct socket_wq *wq; +struct socket_wq *wq = &sock->wq;if (sk ==NULL )return -EINVAL ;lock_sock (sk); - wq = sock->wq;fasync_helper (fd, filp, on, &wq->fasync_list);if (!wq->fasync_list)
Signature · 1 line
2.11.0
Re: [PATCH] coallocate socket_wq with socket itself
From: Al Viro <[email protected]>
Date: Fri, 5 Jul 2019 20:14:16 +0100
Quoted 11 lines
socket->wqis assign-once, set when we are initializing both struct socket it's in and structsocket_wqit points to. As the matter of fact, the only reason for separate allocation was the ability to RCU-delay freeing ofsocket_wq. RCU-delaying the freeing of socket itself gets rid of that need, so we can just fold structsocket_wqinto the end of struct socket and simplify the life both forsock_alloc_inode()(one allocation instead of two) and for tun/tap oddballs, where we used to embed struct socket and structsocket_wqinto the same structure (now - embedding just the struct socket).
Quoted 4 lines
Note that reference to struct
socket_wqin struct sock does remain a reference - that's unchanged.Signed-off-by Al Viro <[email protected]>
Applied.
From: Al Viro <[email protected]>
Date: Fri, 5 Jul 2019 20:13:22 +0100
Quoted 8 lines
we do have an RCU-delayed part there already (freeing the wq), so it's not like the pipe situation; moreover, it might be worth considering coallocating wq with the rest of struct
sock_alloc. ->sk_wq in struct sock would remain a pointer as it is, but the object it normally points to would be coallocated with struct socket...Signed-off-by Al Viro <[email protected]>
Applied.