diff --git a/src/Interpreters/ThreadStatusExt.cpp b/src/Interpreters/ThreadStatusExt.cpp index d1d206009c5..62c328e2fde 100644 --- a/src/Interpreters/ThreadStatusExt.cpp +++ b/src/Interpreters/ThreadStatusExt.cpp @@ -35,6 +35,27 @@ void ThreadStatus::attachQueryContext(Context & query_context_) { query_context = &query_context_; query_id = query_context->getCurrentQueryId(); + + const Settings & settings = query_context->getSettingsRef(); + + untracked_memory_limit = settings.max_untracked_memory; + if (settings.memory_profiler_step && settings.memory_profiler_step < UInt64(untracked_memory_limit)) + untracked_memory_limit = settings.memory_profiler_step; + +#if defined(OS_LINUX) + /// Set "nice" value if required. + Int32 new_os_thread_priority = settings.os_thread_priority; + if (new_os_thread_priority && hasLinuxCapability(CAP_SYS_NICE)) + { + LOG_TRACE(log, "Setting nice to {}", new_os_thread_priority); + + if (0 != setpriority(PRIO_PROCESS, thread_id, new_os_thread_priority)) + throwFromErrno("Cannot 'setpriority'", ErrorCodes::CANNOT_SET_THREAD_PRIORITY); + + os_thread_priority = new_os_thread_priority; + } +#endif + if (!global_context) global_context = &query_context->getGlobalContext();