mirror of
https://github.com/torvalds/linux.git
synced 2026-11-07 06:17:02 +01:00
ALSA: seq: Wait for one RCU grace period when deleting all ports
Since the port list was converted to RCU, snd_seq_delete_all_ports()
calls synchronize_rcu() once per port under register_mutex. Closing a
client with 254 ports now takes about 1.6s and every other client
open or close waits for it.
Unlink all ports first, wait for a single grace period and then free
them.
Fixes: 4c252fbc06 ("ALSA: seq: Use RCU for the client port list")
Signed-off-by: Ali Ahmet Memiş <aliamemis@disroot.org>
Link: https://patch.msgid.link/20261010222543.1470723-1-aliamemis@disroot.org
Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
parent
947037990e
commit
7ca1731b8a
|
|
@ -248,17 +248,9 @@ static void clear_subscriber_list(struct snd_seq_client *client,
|
|||
}
|
||||
|
||||
/* delete port data */
|
||||
static int port_delete(struct snd_seq_client *client,
|
||||
struct snd_seq_client_port *port)
|
||||
static void port_free(struct snd_seq_client *client,
|
||||
struct snd_seq_client_port *port)
|
||||
{
|
||||
/* set closing flag and wait for all port access are gone */
|
||||
port->closing = 1;
|
||||
/* the port has already been unlinked from the client's port list;
|
||||
* wait for a grace period so that RCU readers still traversing the
|
||||
* list can no longer take a new use_lock reference, then drain the
|
||||
* outstanding references before freeing
|
||||
*/
|
||||
synchronize_rcu();
|
||||
snd_use_lock_sync(&port->use_lock);
|
||||
|
||||
/* clear subscribers info */
|
||||
|
|
@ -272,6 +264,20 @@ static int port_delete(struct snd_seq_client *client,
|
|||
snd_BUG_ON(port->c_dest.count != 0);
|
||||
|
||||
kfree(port);
|
||||
}
|
||||
|
||||
static int port_delete(struct snd_seq_client *client,
|
||||
struct snd_seq_client_port *port)
|
||||
{
|
||||
/* set closing flag and wait for all port access are gone */
|
||||
port->closing = 1;
|
||||
/* the port has already been unlinked from the client's port list;
|
||||
* wait for a grace period so that RCU readers still traversing the
|
||||
* list can no longer take a new use_lock reference, then drain the
|
||||
* outstanding references before freeing
|
||||
*/
|
||||
synchronize_rcu();
|
||||
port_free(client, port);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -302,18 +308,25 @@ int snd_seq_delete_port(struct snd_seq_client *client, int port)
|
|||
int snd_seq_delete_all_ports(struct snd_seq_client *client)
|
||||
{
|
||||
struct snd_seq_client_port *port, *tmp;
|
||||
LIST_HEAD(deleted);
|
||||
|
||||
/* unlink and delete each port; port_delete() waits for an RCU grace
|
||||
* period before draining the port, so concurrent lockless readers can
|
||||
* no longer take a new use_lock reference on it
|
||||
/* unlink all ports first and wait for a single RCU grace period
|
||||
* before draining and freeing them, so concurrent lockless readers
|
||||
* can no longer take a new use_lock reference on any of them
|
||||
*/
|
||||
guard(mutex)(&client->ports_mutex);
|
||||
list_for_each_entry_safe(port, tmp, &client->ports_list_head, list) {
|
||||
list_del_rcu(&port->list);
|
||||
client->num_ports--;
|
||||
port->closing = 1;
|
||||
list_add_tail(&port->delete_list, &deleted);
|
||||
snd_seq_system_client_ev_port_exit(port->addr.client, port->addr.port);
|
||||
port_delete(client, port);
|
||||
}
|
||||
if (list_empty(&deleted))
|
||||
return 0;
|
||||
synchronize_rcu();
|
||||
list_for_each_entry_safe(port, tmp, &deleted, delete_list)
|
||||
port_free(client, port);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ struct snd_seq_client_port {
|
|||
struct module *owner; /* owner of this port */
|
||||
char name[64]; /* port name */
|
||||
struct list_head list; /* port list */
|
||||
struct list_head delete_list; /* used by snd_seq_delete_all_ports() */
|
||||
snd_use_lock_t use_lock;
|
||||
|
||||
/* subscribers */
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user