af_unix: Allocate struct unix_vertex for each inflight AF_UNIX fd.
We will replace the garbage collection algorithm for AF_UNIX, where we will consider each inflight AF_UNIX socket as a vertex and its file descriptor as an edge in a directed graph. This patch introduces a new struct unix_vertex representing a vertex in the graph and adds its pointer to struct unix_sock. When we send a fd using the SCM_RIGHTS message, we allocate struct scm_fp_list to struct scm_cookie in scm_fp_copy(). Then, we bump each refcount of the inflight fds' struct file and save them in scm_fp_list.fp. After that, unix_attach_fds() inexplicably clones scm_fp_list of scm_cookie and sets it to skb. (We will remove this part after replacing GC.) Here, we add a new function call in unix_attach_fds() to preallocate struct unix_vertex per inflight AF_UNIX fd and link each vertex to skb's scm_fp_list.vertices. When sendmsg() succeeds later, if the socket of the inflight fd is still not inflight yet, we will set the preallocated vertex to struct unix_sock.vertex and link it to a global list unix_unvisited_vertices under spin_lock(&unix_gc_lock). If the socket is already inflight, we free the preallocated vertex. This is to avoid taking the lock unnecessarily when sendmsg() could fail later. In the following patch, we will similarly allocate another struct per edge, which will finally be linked to the inflight socket's unix_vertex.edges. And then, we will count the number of edges as unix_vertex.out_degree. Signed-off-by:Kuniyuki Iwashima <kuniyu@amazon.com> Acked-by:
Paolo Abeni <pabeni@redhat.com> Link: https://lore.kernel.org/r/20240325202425.60930-2-kuniyu@amazon.com Signed-off-by:
Jakub Kicinski <kuba@kernel.org>
Loading
-
mentioned in commit 28f3e682
-
mentioned in commit 07bb421f
-
mentioned in commit 5797dc55
-
mentioned in commit 9b8fee51
-
mentioned in commit 4dbe8ccd
-
mentioned in commit e663f543
-
mentioned in commit 7231e4ad
-
mentioned in commit 9f5796a4
-
mentioned in commit a490a386
-
mentioned in commit 9b0889c4
-
mentioned in commit 24f186b6
-
mentioned in commit b462a3c3
-
mentioned in commit 70ebcdd6
-
mentioned in commit eb41bcd1
-
mentioned in commit c22eff0f
-
mentioned in commit 14b3011d
-
mentioned in commit b503e3ca
-
mentioned in commit 85c823d3
-
mentioned in commit a302bd6d
-
mentioned in commit 7a16663c
-
mentioned in commit b534d0ef
-
mentioned in commit 9e842f62
-
mentioned in commit 83671ac4
-
mentioned in commit ffef32dd
Please sign in to comment