All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kuniyuki Iwashima <kuniyu@google.com>
To: "David S . Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	 Jakub Kicinski <kuba@kernel.org>,
	Paolo Abeni <pabeni@redhat.com>
Cc: Simon Horman <horms@kernel.org>,
	Kuniyuki Iwashima <kuniyu@google.com>,
	 Kuniyuki Iwashima <kuni1840@gmail.com>,
	netdev@vger.kernel.org
Subject: [PATCH v1 net-next 7/7] af_unix: Consolidate unix_schedule_gc() and wait_for_unix_gc().
Date: Sat, 15 Nov 2025 02:08:38 +0000	[thread overview]
Message-ID: <20251115020935.2643121-8-kuniyu@google.com> (raw)
In-Reply-To: <20251115020935.2643121-1-kuniyu@google.com>

unix_schedule_gc() and wait_for_unix_gc() share some code.

Let's consolidate the two.

Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
---
 net/unix/af_unix.c |  2 +-
 net/unix/af_unix.h |  2 +-
 net/unix/garbage.c | 28 +++++++++-------------------
 3 files changed, 11 insertions(+), 21 deletions(-)

diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index 34952242bd81..e518116f8171 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -733,7 +733,7 @@ static void unix_release_sock(struct sock *sk, int embrion)
 
 	/* ---- Socket is dead now and most probably destroyed ---- */
 
-	unix_schedule_gc();
+	unix_schedule_gc(NULL);
 }
 
 struct unix_peercred {
diff --git a/net/unix/af_unix.h b/net/unix/af_unix.h
index 2f1bfe3217c1..c4f1b2da363d 100644
--- a/net/unix/af_unix.h
+++ b/net/unix/af_unix.h
@@ -29,7 +29,7 @@ void unix_del_edges(struct scm_fp_list *fpl);
 void unix_update_edges(struct unix_sock *receiver);
 int unix_prepare_fpl(struct scm_fp_list *fpl);
 void unix_destroy_fpl(struct scm_fp_list *fpl);
-void unix_schedule_gc(void);
+void unix_schedule_gc(struct user_struct *user);
 
 /* SOCK_DIAG */
 long unix_inq_len(struct sock *sk);
diff --git a/net/unix/garbage.c b/net/unix/garbage.c
index fe1f74345b66..78323d43e63e 100644
--- a/net/unix/garbage.c
+++ b/net/unix/garbage.c
@@ -279,8 +279,6 @@ void unix_update_edges(struct unix_sock *receiver)
 	}
 }
 
-static void wait_for_unix_gc(struct scm_fp_list *fpl);
-
 int unix_prepare_fpl(struct scm_fp_list *fpl)
 {
 	struct unix_vertex *vertex;
@@ -302,7 +300,7 @@ int unix_prepare_fpl(struct scm_fp_list *fpl)
 	if (!fpl->edges)
 		goto err;
 
-	wait_for_unix_gc(fpl);
+	unix_schedule_gc(fpl->user);
 
 	return 0;
 
@@ -614,21 +612,9 @@ static void unix_gc(struct work_struct *work)
 
 static DECLARE_WORK(unix_gc_work, unix_gc);
 
-void unix_schedule_gc(void)
-{
-	if (READ_ONCE(unix_graph_state) == UNIX_GRAPH_NOT_CYCLIC)
-		return;
-
-	if (READ_ONCE(gc_in_progress))
-		return;
-
-	WRITE_ONCE(gc_in_progress, true);
-	queue_work(system_dfl_wq, &unix_gc_work);
-}
-
 #define UNIX_INFLIGHT_SANE_USER		(SCM_MAX_FD * 8)
 
-static void wait_for_unix_gc(struct scm_fp_list *fpl)
+void unix_schedule_gc(struct user_struct *user)
 {
 	if (READ_ONCE(unix_graph_state) == UNIX_GRAPH_NOT_CYCLIC)
 		return;
@@ -636,11 +622,15 @@ static void wait_for_unix_gc(struct scm_fp_list *fpl)
 	/* Penalise users who want to send AF_UNIX sockets
 	 * but whose sockets have not been received yet.
 	 */
-	if (READ_ONCE(fpl->user->unix_inflight) < UNIX_INFLIGHT_SANE_USER)
+	if (user &&
+	    READ_ONCE(user->unix_inflight) < UNIX_INFLIGHT_SANE_USER)
 		return;
 
-	unix_schedule_gc();
+	if (!READ_ONCE(gc_in_progress)) {
+		WRITE_ONCE(gc_in_progress, true);
+		queue_work(system_dfl_wq, &unix_gc_work);
+	}
 
-	if (READ_ONCE(unix_graph_cyclic_sccs))
+	if (user && READ_ONCE(unix_graph_cyclic_sccs))
 		flush_work(&unix_gc_work);
 }
-- 
2.52.0.rc1.455.g30608eb744-goog


  parent reply	other threads:[~2025-11-15  2:09 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-15  2:08 [PATCH v1 net-next 0/7] af_unix: GC cleanup and optimisation Kuniyuki Iwashima
2025-11-15  2:08 ` [PATCH v1 net-next 1/7] af_unix: Count cyclic SCC Kuniyuki Iwashima
2025-11-15  2:08 ` [PATCH v1 net-next 2/7] af_unix: Simplify GC state Kuniyuki Iwashima
2025-11-15  2:08 ` [PATCH v1 net-next 3/7] af_unix: Don't trigger GC from close() if unnecessary Kuniyuki Iwashima
2025-11-15  2:08 ` [PATCH v1 net-next 4/7] af_unix: Don't call wait_for_unix_gc() on every sendmsg() Kuniyuki Iwashima
2025-11-15  2:08 ` [PATCH v1 net-next 5/7] af_unix: Refine wait_for_unix_gc() Kuniyuki Iwashima
2025-11-15  2:08 ` [PATCH v1 net-next 6/7] af_unix: Remove unix_tot_inflight Kuniyuki Iwashima
2025-11-15  2:08 ` Kuniyuki Iwashima [this message]
2025-11-19  3:30 ` [PATCH v1 net-next 0/7] af_unix: GC cleanup and optimisation patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251115020935.2643121-8-kuniyu@google.com \
    --to=kuniyu@google.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=kuni1840@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.