Revert "remove mlock and use MAP_LOCKED"

This reverts commit ab91e94b59.

When no memory can be locked, the mmap fails with -EAGAIN.

Fixes #592
This commit is contained in:
Wim Taymans 2021-01-19 14:47:44 +01:00
parent 8c84c96fe1
commit abfc67a3ca
4 changed files with 64 additions and 21 deletions

View file

@ -44,6 +44,8 @@
#define MAX_MIX 4096
/** \cond */
static bool mlock_warned = false;
struct buffer {
uint32_t id;
struct spa_buffer *buf;
@ -77,6 +79,7 @@ struct node_data {
unsigned int do_free:1;
unsigned int have_transport:1;
unsigned int allow_mlock:1;
unsigned int warn_mlock:1;
struct pw_client_node *client_node;
struct spa_hook client_node_listener;
@ -615,8 +618,6 @@ client_node_port_use_buffers(void *object,
}
prot = PW_MEMMAP_FLAG_READWRITE;
if (data->allow_mlock)
prot |= PW_MEMMAP_FLAG_LOCKED;
/* clear previous buffers */
clear_buffers(data, mix);
@ -643,6 +644,17 @@ client_node_port_use_buffers(void *object,
bid->id = i;
bid->mem = mm;
if (data->allow_mlock && mlock(mm->ptr, mm->size) < 0)
if (errno != ENOMEM || !mlock_warned) {
pw_log(data->warn_mlock ? SPA_LOG_LEVEL_WARN : SPA_LOG_LEVEL_DEBUG,
"Failed to mlock memory %p %u: %s",
mm->ptr, mm->size,
errno == ENOMEM ?
"This is not a problem but for best performance, "
"consider increasing RLIMIT_MEMLOCK" : strerror(errno));
mlock_warned |= errno == ENOMEM;
}
size = sizeof(struct spa_buffer);
for (j = 0; j < buffers[i].buffer->n_metas; j++)
size += sizeof(struct spa_meta);
@ -1206,6 +1218,10 @@ static struct pw_proxy *node_export(struct pw_core *core, void *object, bool do_
if ((str = pw_properties_get(node->properties, "mem.allow-mlock")) != NULL)
data->allow_mlock = pw_properties_parse_bool(str);
data->warn_mlock = true;
if ((str = pw_properties_get(node->properties, "mem.warn-mlock")) != NULL)
data->warn_mlock = pw_properties_parse_bool(str);
node->exported = true;
spa_list_init(&data->free_mix);