af_unix: Skip GC if no cycle exists.
We do not need to run GC if there is no possible cyclic reference. We use unix_graph_maybe_cyclic to decide if we should run GC. If a fd of an AF_UNIX socket is passed to an already inflight AF_UNIX socket, they could form a cyclic reference. Then, we set true to unix_graph_maybe_cyclic and later run Tarjan's algorithm to group them into SCC. Once we run Tarjan's algorithm, we are 100% sure whether cyclic references exist or not. If there is no cycle, we set false to unix_graph_maybe_cyclic and can skip the entire garbage collection next time. When finalising SCC, we set true to unix_graph_maybe_cyclic if SCC consists of multiple vertices. Even if SCC is a single vertex, a cycle might exist as self-fd passing. Given the corner case is rare, we detect it by checking all edges of the vertex and set true to unix_graph_maybe_cyclic. With this change, __unix_gc() is just a spin_lock() dance in the normal usage. Signed-off-by:Kuniyuki Iwashima <kuniyu@amazon.com> Acked-by:
Paolo Abeni <pabeni@redhat.com> Link: https://lore.kernel.org/r/20240325202425.60930-11-kuniyu@amazon.com Signed-off-by:
Jakub Kicinski <kuba@kernel.org>
-
mentioned in commit 90357d1c
-
mentioned in commit 74e8ea09
-
mentioned in commit f1f659f7
-
mentioned in commit ee7b6234
-
mentioned in commit c4d444fe
-
mentioned in commit 7d41ec4f
-
mentioned in commit 5abe7db2
-
mentioned in commit 958677c3
-
mentioned in commit 8fb66a4b
-
mentioned in commit 971f3d24
-
mentioned in commit b7624c7c
-
mentioned in commit d0c38a8e
-
mentioned in commit 9b8b8d24
-
mentioned in commit 80171b6f
-
mentioned in commit faa27aaa
-
mentioned in commit 526a828b
-
mentioned in commit 755c8521
-
mentioned in commit b86a6d17
-
mentioned in commit c1dfb69b
-
mentioned in commit a1f6360e
-
mentioned in commit 50d12079
-
mentioned in commit e517bec9
-
mentioned in commit fd5ee724
-
mentioned in commit 04dee958
-
mentioned in commit f9977b17
-
mentioned in commit ae9eb29d
-
mentioned in commit eecd71b3
-
mentioned in commit 120862ef
-
mentioned in commit 7f1124bd
-
mentioned in commit 42f3c6b6
-
mentioned in commit 1ece39eb
-
mentioned in commit 21e02756
-
mentioned in commit ef01075f
-
mentioned in commit deb71636
-
mentioned in commit a1df7869
-
mentioned in commit 5868adbb
-
mentioned in commit 6ff5694a
-
mentioned in commit 3d5f1dd7
-
mentioned in commit 673aab11
-
mentioned in commit bbdca1d2
-
mentioned in commit d5b4e976
-
mentioned in commit 6a291de4
-
mentioned in commit 5f860fda
-
mentioned in commit 7fc416f7
-
mentioned in commit b31a5408
-
mentioned in commit 7e4da6be
-
mentioned in commit ad3cbbd0
-
mentioned in commit 1e4d62ad
-
mentioned in commit 95a397ac