context: disable mlock warnings by default

Make this a tunable option instead.
This commit is contained in:
Wim Taymans 2021-02-08 10:59:02 +01:00
parent cd2a7aebaf
commit 210950dc0a
7 changed files with 25 additions and 9 deletions

View file

@ -346,6 +346,7 @@ struct client {
unsigned int thread_entered:1;
unsigned int has_transport:1;
unsigned int allow_mlock:1;
unsigned int warn_mlock:1;
unsigned int timeowner_pending:1;
unsigned int timeowner_conditional:1;
@ -1807,7 +1808,8 @@ static int client_node_port_use_buffers(void *object,
}
if (c->allow_mlock && mlock(d->data, d->maxsize) < 0) {
if (errno != ENOMEM || !mlock_warned) {
pw_log_warn(NAME" %p: Failed to mlock memory %p %u: %s", c,
pw_log(c->warn_mlock ? SPA_LOG_LEVEL_WARN : SPA_LOG_LEVEL_DEBUG,
NAME" %p: Failed to mlock memory %p %u: %s", c,
d->data, d->maxsize,
errno == ENOMEM ?
"This is not a problem but for best performance, "
@ -2410,6 +2412,8 @@ jack_client_t * jack_client_open (const char *client_name,
NULL),
0);
client->allow_mlock = client->context.context->defaults.mem_allow_mlock;
client->warn_mlock = client->context.context->defaults.mem_warn_mlock;
spa_list_init(&client->context.free_objects);
pthread_mutex_init(&client->context.lock, NULL);
spa_list_init(&client->context.nodes);

View file

@ -5,6 +5,7 @@ properties = {
#context.data-loop.library.name.system = support/libspa-support
#link.max-buffers = 64
link.max-buffers = 16 # version < 3 clients can't handle more
#mem.warn-mlock = false
#mem.allow-mlock = true
#mem.mlock-all = false
#log.level = 2

View file

@ -1218,7 +1218,7 @@ 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;
data->warn_mlock = data->context->defaults.mem_warn_mlock;
if ((str = pw_properties_get(node->properties, "mem.warn-mlock")) != NULL)
data->warn_mlock = pw_properties_parse_bool(str);

View file

@ -57,6 +57,7 @@
#define DEFAULT_VIDEO_RATE_NUM 25u
#define DEFAULT_VIDEO_RATE_DENOM 1u
#define DEFAULT_LINK_MAX_BUFFERS 64u
#define DEFAULT_MEM_WARN_MLOCK false
#define DEFAULT_MEM_ALLOW_MLOCK true
/** \cond */
@ -168,6 +169,7 @@ static void fill_defaults(struct pw_context *this)
this->defaults.video_rate.num = get_default_int(p, "default.video.rate.num", DEFAULT_VIDEO_RATE_NUM);
this->defaults.video_rate.denom = get_default_int(p, "default.video.rate.denom", DEFAULT_VIDEO_RATE_DENOM);
this->defaults.link_max_buffers = get_default_int(p, "link.max-buffers", DEFAULT_LINK_MAX_BUFFERS);
this->defaults.mem_warn_mlock = get_default_bool(p, "mem.warn-mlock", DEFAULT_MEM_WARN_MLOCK);
this->defaults.mem_allow_mlock = get_default_bool(p, "mem.allow-mlock", DEFAULT_MEM_ALLOW_MLOCK);
this->defaults.clock_max_quantum = SPA_CLAMP(this->defaults.clock_max_quantum,

View file

@ -151,6 +151,7 @@ struct filter {
unsigned int draining:1;
unsigned int allow_mlock:1;
unsigned int warn_mlock:1;
unsigned int process_rt:1;
};
static int get_param_index(uint32_t id)
@ -1023,6 +1024,7 @@ filter_new(struct pw_context *context, const char *name,
impl->context = context;
impl->allow_mlock = context->defaults.mem_allow_mlock;
impl->warn_mlock = context->defaults.mem_warn_mlock;
return impl;
@ -1235,15 +1237,17 @@ pw_filter_connect(struct pw_filter *filter,
uint32_t n_params)
{
struct filter *impl = SPA_CONTAINER_OF(filter, struct filter, this);
const char *str;
int res;
uint32_t i;
pw_log_debug(NAME" %p: connect", filter);
impl->flags = flags;
impl->warn_mlock = SPA_FLAG_IS_SET(flags, PW_FILTER_FLAG_RT_PROCESS);
pw_properties_set(filter->properties, "mem.warn-mlock",
impl->warn_mlock ? "true" : "false");
impl->process_rt = SPA_FLAG_IS_SET(flags, PW_FILTER_FLAG_RT_PROCESS);
if ((str = pw_properties_get(filter->properties, "mem.warn-mlock")) != NULL)
impl->warn_mlock = pw_properties_parse_bool(str);
impl->impl_node.iface = SPA_INTERFACE_INIT(
SPA_TYPE_INTERFACE_Node,
@ -1258,7 +1262,7 @@ pw_filter_connect(struct pw_filter *filter,
impl->info = SPA_NODE_INFO_INIT();
impl->info.max_input_ports = MAX_PORTS;
impl->info.max_output_ports = MAX_PORTS;
impl->info.flags = impl->warn_mlock ? SPA_NODE_FLAG_RT : 0;
impl->info.flags = impl->process_rt ? SPA_NODE_FLAG_RT : 0;
impl->info.props = &filter->properties->dict;
impl->params[0] = SPA_PARAM_INFO(SPA_PARAM_EnumFormat, 0);
impl->params[1] = SPA_PARAM_INFO(SPA_PARAM_Meta, 0);

View file

@ -56,7 +56,8 @@ struct defaults {
struct spa_rectangle video_size;
struct spa_fraction video_rate;
uint32_t link_max_buffers;
unsigned int mem_allow_mlock;
unsigned int mem_warn_mlock:1;
unsigned int mem_allow_mlock:1;
};
struct ratelimit {

View file

@ -144,6 +144,7 @@ struct stream {
unsigned int draining:1;
unsigned int drained:1;
unsigned int allow_mlock:1;
unsigned int warn_mlock:1;
unsigned int process_rt:1;
};
@ -594,7 +595,7 @@ static int map_data(struct stream *impl, struct spa_data *data, int prot)
if (impl->allow_mlock && mlock(data->data, data->maxsize) < 0) {
if (errno != ENOMEM || !mlock_warned) {
pw_log(impl->process_rt ? SPA_LOG_LEVEL_WARN : SPA_LOG_LEVEL_DEBUG,
pw_log(impl->warn_mlock ? SPA_LOG_LEVEL_WARN : SPA_LOG_LEVEL_DEBUG,
NAME" %p: Failed to mlock memory %p %u: %s", impl,
data->data, data->maxsize,
errno == ENOMEM ?
@ -1209,6 +1210,7 @@ stream_new(struct pw_context *context, const char *name,
impl->context = context;
impl->allow_mlock = context->defaults.mem_allow_mlock;
impl->warn_mlock = context->defaults.mem_warn_mlock;
spa_hook_list_append(&impl->context->driver_listener_list,
&impl->context_listener,
@ -1557,7 +1559,9 @@ pw_stream_connect(struct pw_stream *stream,
pw_properties_set(stream->properties, PW_KEY_NODE_DONT_RECONNECT, "true");
impl->process_rt = SPA_FLAG_IS_SET(flags, PW_STREAM_FLAG_RT_PROCESS);
pw_properties_set(stream->properties, "mem.warn-mlock", impl->process_rt ? "true" : "false");
if ((str = pw_properties_get(stream->properties, "mem.warn-mlock")) != NULL)
impl->warn_mlock = pw_properties_parse_bool(str);
if ((pw_properties_get(stream->properties, PW_KEY_MEDIA_CLASS) == NULL)) {
const char *media_type = pw_properties_get(stream->properties, PW_KEY_MEDIA_TYPE);