[ovs-dev] [PATCH v2 4/4] Prevent excessive contention of the logging mutex
anton.ivanov at cambridgegreys.com
anton.ivanov at cambridgegreys.com
Fri Feb 14 17:54:29 UTC 2020
From: Anton Ivanov <anton.ivanov at cambridgegreys.com>
The log levels for a module which specify "should I log or should
I go" can be checked witout a mutex.
We need to grab a mutex only once we know we are likely to be
logging in the first place.
This mutex is highly contended - this code is hit from 2300+
places around OVS - every time you encounter a VLOG statement.
Signed-off-by: Anton Ivanov <anton.ivanov at cambridgegreys.com>
---
lib/vlog.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/lib/vlog.c b/lib/vlog.c
index 559943d87..be28b59a1 100644
--- a/lib/vlog.c
+++ b/lib/vlog.c
@@ -1088,10 +1088,19 @@ vlog_valist(const struct vlog_module *module, enum vlog_level level,
{
bool log_to_console = module->levels[VLF_CONSOLE] >= level;
bool log_to_syslog = module->levels[VLF_SYSLOG] >= level;
- bool log_to_file;
+ bool log_to_file = module->levels[VLF_FILE] >= level;
+
+ /* Quickly exit without contending the log mutex if the module log
+ * levels do not request any logging to start off with.
+ */
+
+ if (!(log_to_console || log_to_syslog || log_to_file)) {
+ return;
+ }
ovs_mutex_lock(&log_file_mutex);
- log_to_file = module->levels[VLF_FILE] >= level && log_fd >= 0;
+ /* check only log_fd under mutex */
+ log_to_file &= (log_fd >= 0);
ovs_mutex_unlock(&log_file_mutex);
if (log_to_console || log_to_syslog || log_to_file) {
int save_errno = errno;
--
2.20.1
More information about the dev
mailing list