OpenVZ Forum

Home » Mailing lists » Devel » [PATCH 3/3][UNIX] The unix_nr_socks limit can be exceeded
[PATCH 3/3][UNIX] The unix_nr_socks limit can be exceeded [message #22917] Wed, 07 November 2007 14:01 Go to previous message
Pavel Emelianov is currently offline  Pavel Emelianov
Messages: 1149
Registered: September 2006
Senior Member
The unix_nr_socks value is limited with the 2 * get_max_files() value,
as seen from the unix_create1(). However, the check and the actual
increment are separated with the GFP_KERNEL allocation, so this limit
can be exceeded under a memory pressure - task may go to sleep freeing
the pages and some other task will be allowed to allocate a new sock
and so on and so forth.

So make the increment before the check (similar thing is done in the
sock_kmalloc) and go to kmalloc after this.

Signed-off-by: Pavel Emelyanov <>


diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index ab9048a..e835da8 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -599,15 +599,14 @@ static struct sock * unix_create1(struct net *net, struct socket *sock)
 	struct sock *sk = NULL;
 	struct unix_sock *u;
-	if (atomic_read(&unix_nr_socks) >= 2*get_max_files())
+	atomic_inc(&unix_nr_socks);
+	if (atomic_read(&unix_nr_socks) > 2 * get_max_files())
 		goto out;
 	sk = sk_alloc(net, PF_UNIX, GFP_KERNEL, &unix_proto);
 	if (!sk)
 		goto out;
-	atomic_inc(&unix_nr_socks);
@@ -625,6 +624,8 @@ static struct sock * unix_create1(struct net *net, struct socket *sock)
 	unix_insert_socket(unix_sockets_unbound, sk);
+	if (sk == NULL)
+		atomic_dec(&unix_nr_socks);
 	return sk;
Read Message
Read Message
Previous Topic: [PATCH 2/3][UNIX] Convert socks to unix_socks in scan_inflight, not in callbacks
Next Topic: [PATCH] netns: init dev_base_lock only once
Goto Forum:

Current Time: Sun Jul 21 10:59:06 GMT 2024

Total time taken to generate the page: 0.02294 seconds