From nobody Wed Dec 17 03:27:47 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E592B1E2838; Wed, 21 May 2025 14:50:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747839042; cv=none; b=CNvwy5KQKjOKuDBazPxxdUtDdRt5VQrOhOuJ2ts4axsH+TTQYmscAHcwQn858bX9IN63vxPu7hMgvjZBna7bbJ0xrVt31ooDENuT5S+GcUmig+eYmJWdP+3PSIJD6GE72oLv/ZISCe5L2Jei/rYzaUau0pHYrzoLJjRZK0WcJZU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747839042; c=relaxed/simple; bh=Xv8DFqpPzl8U7cumbdw7UaBSqzhuHGhsvgbA9jOrjW0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ugwXflJ01fDSUUegK5J+l5J8s2BJIU59OINq/ciml8nkUaFJCD9tw0a9a62R9uoJLFZvZdrKBusVHln2yUeEfa4Q3axzTj4dAzaX7scHVxDrQCTQH2Hj4zhaHG2qNIESgYpFf5a5OiNvlNJQ86T5B2hgBlBdj+jI0k6Sa/JWuIU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FCx1sjJV; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="FCx1sjJV" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8C0D6C4CEE4; Wed, 21 May 2025 14:50:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1747839041; bh=Xv8DFqpPzl8U7cumbdw7UaBSqzhuHGhsvgbA9jOrjW0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FCx1sjJVBOX0nGpVYdPy8Ck2pEn0ZvSN9SR5QZFNax0vIDriFzl4mh+8uHlyC++0g RfMTN6tIAGBqoYIMt4LslBnA/QXz1naYTqDwb5VvcMJyN0hroxGHn5vrwLr7RVrJek +B53MFzuUQRWarJX3yZch0M1O1W0HsWsHiRmzDp2bAuVhhcv8Ljp9u7+DyZi8BXaD1 sSh7xZZA2CpXXgfck663nO0byOOmcQMcqQHPKwf7o3zv1sj/mmgYbjkk7JMTNwW9mJ JuFqoBXbDKIa1oS6ApF5x+2ugVovdozcXY1+/pGoyhMlkiO3MU89VRh4G+OfEpOj2/ VJKhaMATtcS9w== From: Lee Jones To: lee@kernel.org, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Kuniyuki Iwashima , Jens Axboe , Sasha Levin , Michal Luczaj , Rao Shoaib , Pavel Begunkov , linux-kernel@vger.kernel.org, netdev@vger.kernel.org Cc: stable@vger.kernel.org Subject: [PATCH v6.6 10/26] af_unix: Bulk update unix_tot_inflight/unix_inflight when queuing skb. Date: Wed, 21 May 2025 14:45:18 +0000 Message-ID: <20250521144803.2050504-11-lee@kernel.org> X-Mailer: git-send-email 2.49.0.1112.g889b7c5bd8-goog In-Reply-To: <20250521144803.2050504-1-lee@kernel.org> References: <20250521144803.2050504-1-lee@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Kuniyuki Iwashima [ Upstream commit 22c3c0c52d32f41cc38cd936ea0c93f22ced3315 ] Currently, we track the number of inflight sockets in two variables. unix_tot_inflight is the total number of inflight AF_UNIX sockets on the host, and user->unix_inflight is the number of inflight fds per user. We update them one by one in unix_inflight(), which can be done once in batch. Also, sendmsg() could fail even after unix_inflight(), then we need to acquire unix_gc_lock only to decrement the counters. Let's bulk update the counters in unix_add_edges() and unix_del_edges(), which is called only for successfully passed fds. Signed-off-by: Kuniyuki Iwashima Acked-by: Paolo Abeni Link: https://lore.kernel.org/r/20240325202425.60930-5-kuniyu@amazon.com Signed-off-by: Jakub Kicinski (cherry picked from commit 22c3c0c52d32f41cc38cd936ea0c93f22ced3315) Signed-off-by: Lee Jones --- net/unix/garbage.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/net/unix/garbage.c b/net/unix/garbage.c index b5b4a200dbf3b..f7041fc230008 100644 --- a/net/unix/garbage.c +++ b/net/unix/garbage.c @@ -144,6 +144,7 @@ static void unix_free_vertices(struct scm_fp_list *fpl) } =20 DEFINE_SPINLOCK(unix_gc_lock); +unsigned int unix_tot_inflight; =20 void unix_add_edges(struct scm_fp_list *fpl, struct unix_sock *receiver) { @@ -168,7 +169,10 @@ void unix_add_edges(struct scm_fp_list *fpl, struct un= ix_sock *receiver) unix_add_edge(fpl, edge); } while (i < fpl->count_unix); =20 + WRITE_ONCE(unix_tot_inflight, unix_tot_inflight + fpl->count_unix); out: + WRITE_ONCE(fpl->user->unix_inflight, fpl->user->unix_inflight + fpl->coun= t); + spin_unlock(&unix_gc_lock); =20 fpl->inflight =3D true; @@ -191,7 +195,10 @@ void unix_del_edges(struct scm_fp_list *fpl) unix_del_edge(fpl, edge); } while (i < fpl->count_unix); =20 + WRITE_ONCE(unix_tot_inflight, unix_tot_inflight - fpl->count_unix); out: + WRITE_ONCE(fpl->user->unix_inflight, fpl->user->unix_inflight - fpl->coun= t); + spin_unlock(&unix_gc_lock); =20 fpl->inflight =3D false; @@ -234,7 +241,6 @@ void unix_destroy_fpl(struct scm_fp_list *fpl) unix_free_vertices(fpl); } =20 -unsigned int unix_tot_inflight; static LIST_HEAD(gc_candidates); static LIST_HEAD(gc_inflight_list); =20 @@ -255,13 +261,8 @@ void unix_inflight(struct user_struct *user, struct fi= le *filp) WARN_ON_ONCE(list_empty(&u->link)); } u->inflight++; - - /* Paired with READ_ONCE() in wait_for_unix_gc() */ - WRITE_ONCE(unix_tot_inflight, unix_tot_inflight + 1); } =20 - WRITE_ONCE(user->unix_inflight, user->unix_inflight + 1); - spin_unlock(&unix_gc_lock); } =20 @@ -278,13 +279,8 @@ void unix_notinflight(struct user_struct *user, struct= file *filp) u->inflight--; if (!u->inflight) list_del_init(&u->link); - - /* Paired with READ_ONCE() in wait_for_unix_gc() */ - WRITE_ONCE(unix_tot_inflight, unix_tot_inflight - 1); } =20 - WRITE_ONCE(user->unix_inflight, user->unix_inflight - 1); - spin_unlock(&unix_gc_lock); } =20 --=20 2.49.0.1112.g889b7c5bd8-goog