diff options
author | Henrik Edin <henrik.edin@mongodb.com> | 2019-02-07 17:22:04 -0500 |
---|---|---|
committer | Henrik Edin <henrik.edin@mongodb.com> | 2019-02-12 10:03:36 -0500 |
commit | 530a26bc5387de3dd131a18801a6c3253c4f3220 (patch) | |
tree | 6528c61a2938ee5ed9ec5a661084ee2b65fe8804 /src/mongo | |
parent | 7941c8a7424590247f3d6b3bdbad7cff50b8b90c (diff) | |
download | mongo-530a26bc5387de3dd131a18801a6c3253c4f3220.tar.gz |
SERVER-39456 Remove tcmallocEnableMarkThreadTemporarilyIdle implementation.r4.1.8
An error message was added with explaination if this is attempted to be set.
Diffstat (limited to 'src/mongo')
-rw-r--r-- | src/mongo/transport/SConscript | 1 | ||||
-rw-r--r-- | src/mongo/transport/service_executor_adaptive.cpp | 6 | ||||
-rw-r--r-- | src/mongo/transport/service_executor_reserved.cpp | 12 | ||||
-rw-r--r-- | src/mongo/transport/service_executor_synchronous.cpp | 4 | ||||
-rw-r--r-- | src/mongo/transport/thread_idle_callback.cpp | 64 | ||||
-rw-r--r-- | src/mongo/transport/thread_idle_callback.h | 55 | ||||
-rw-r--r-- | src/mongo/util/tcmalloc_server_status_section.cpp | 57 |
7 files changed, 7 insertions, 192 deletions
diff --git a/src/mongo/transport/SConscript b/src/mongo/transport/SConscript index f3dba05d40e..e1ef60374a3 100644 --- a/src/mongo/transport/SConscript +++ b/src/mongo/transport/SConscript @@ -116,7 +116,6 @@ tlEnv.Library( 'service_executor_adaptive.cpp', 'service_executor_reserved.cpp', 'service_executor_synchronous.cpp', - 'thread_idle_callback.cpp', ], LIBDEPS=[ '$BUILD_DIR/mongo/db/service_context', diff --git a/src/mongo/transport/service_executor_adaptive.cpp b/src/mongo/transport/service_executor_adaptive.cpp index 649382086b1..b3787002382 100644 --- a/src/mongo/transport/service_executor_adaptive.cpp +++ b/src/mongo/transport/service_executor_adaptive.cpp @@ -40,7 +40,6 @@ #include "mongo/db/server_parameters.h" #include "mongo/transport/service_entry_point_utils.h" #include "mongo/transport/service_executor_task_names.h" -#include "mongo/transport/thread_idle_callback.h" #include "mongo/util/concurrency/thread_name.h" #include "mongo/util/duration.h" #include "mongo/util/log.h" @@ -238,11 +237,6 @@ Status ServiceExecutorAdaptive::schedule(ServiceExecutorAdaptive::Task task, task(); _localThreadState->threadMetrics[static_cast<size_t>(taskName)] ._totalSpentExecuting.addAndFetch(_localTimer.sinceStartTicks()); - - if ((flags & ServiceExecutor::kMayYieldBeforeSchedule) && - (_localThreadState->markIdleCounter++ & 0xf)) { - markThreadIdle(); - } }; // Dispatching a task on the io_context will run the task immediately, and may run it diff --git a/src/mongo/transport/service_executor_reserved.cpp b/src/mongo/transport/service_executor_reserved.cpp index beeb7618bd0..d52a38920b7 100644 --- a/src/mongo/transport/service_executor_reserved.cpp +++ b/src/mongo/transport/service_executor_reserved.cpp @@ -38,7 +38,6 @@ #include "mongo/stdx/thread.h" #include "mongo/transport/service_entry_point_utils.h" #include "mongo/transport/service_executor_task_names.h" -#include "mongo/transport/thread_idle_callback.h" #include "mongo/util/log.h" #include "mongo/util/processinfo.h" @@ -170,17 +169,6 @@ Status ServiceExecutorReserved::schedule(Task task, } if (!_localWorkQueue.empty()) { - /* - * In perf testing we found that yielding after running a each request produced - * at 5% performance boost in microbenchmarks if the number of worker threads - * was greater than the number of available cores. - */ - if (flags & ScheduleFlags::kMayYieldBeforeSchedule) { - if ((_localThreadIdleCounter++ & 0xf) == 0) { - markThreadIdle(); - } - } - // Execute task directly (recurse) if allowed by the caller as it produced better // performance in testing. Try to limit the amount of recursion so we don't blow up the // stack, even though this shouldn't happen with this executor that uses blocking network diff --git a/src/mongo/transport/service_executor_synchronous.cpp b/src/mongo/transport/service_executor_synchronous.cpp index 24d99bc2208..c75655da1f5 100644 --- a/src/mongo/transport/service_executor_synchronous.cpp +++ b/src/mongo/transport/service_executor_synchronous.cpp @@ -38,7 +38,6 @@ #include "mongo/stdx/thread.h" #include "mongo/transport/service_entry_point_utils.h" #include "mongo/transport/service_executor_task_names.h" -#include "mongo/transport/thread_idle_callback.h" #include "mongo/util/log.h" #include "mongo/util/processinfo.h" @@ -99,9 +98,6 @@ Status ServiceExecutorSynchronous::schedule(Task task, * was greater than the number of available cores. */ if (flags & ScheduleFlags::kMayYieldBeforeSchedule) { - if ((_localThreadIdleCounter++ & 0xf) == 0) { - markThreadIdle(); - } if (_numRunningWorkerThreads.loadRelaxed() > _numHardwareCores) { stdx::this_thread::yield(); } diff --git a/src/mongo/transport/thread_idle_callback.cpp b/src/mongo/transport/thread_idle_callback.cpp deleted file mode 100644 index 0e5452825e8..00000000000 --- a/src/mongo/transport/thread_idle_callback.cpp +++ /dev/null @@ -1,64 +0,0 @@ - -/** - * Copyright (C) 2018-present MongoDB, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * <http://www.mongodb.com/licensing/server-side-public-license>. - * - * As a special exception, the copyright holders give permission to link the - * code of portions of this program with the OpenSSL library under certain - * conditions as described in each individual source file and distribute - * linked combinations including the program with the OpenSSL library. You - * must comply with the Server Side Public License in all respects for - * all of the code used other than as permitted herein. If you modify file(s) - * with this exception, you may extend this exception to your version of the - * file(s), but you are not obligated to do so. If you do not wish to do so, - * delete this exception statement from your version. If you delete this - * exception statement from all source files in the program, then also delete - * it in the license file. - */ - -#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kDefault - -#include "mongo/platform/basic.h" - -#include "mongo/transport/thread_idle_callback.h" - -#include "mongo/util/assert_util.h" -#include "mongo/util/log.h" - -namespace mongo { -namespace { - -ThreadIdleCallback threadIdleCallback; - -} // namespace - -void registerThreadIdleCallback(ThreadIdleCallback callback) { - invariant(!threadIdleCallback); - threadIdleCallback = callback; -} - -void markThreadIdle() { - if (!threadIdleCallback) { - return; - } - try { - threadIdleCallback(); - } catch (...) { - severe() << "Exception escaped from threadIdleCallback"; - fassertFailedNoTrace(28603); - } -} - -} // namespace mongo diff --git a/src/mongo/transport/thread_idle_callback.h b/src/mongo/transport/thread_idle_callback.h deleted file mode 100644 index c7bd5ff96b1..00000000000 --- a/src/mongo/transport/thread_idle_callback.h +++ /dev/null @@ -1,55 +0,0 @@ - -/** - * Copyright (C) 2018-present MongoDB, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * <http://www.mongodb.com/licensing/server-side-public-license>. - * - * As a special exception, the copyright holders give permission to link the - * code of portions of this program with the OpenSSL library under certain - * conditions as described in each individual source file and distribute - * linked combinations including the program with the OpenSSL library. You - * must comply with the Server Side Public License in all respects for - * all of the code used other than as permitted herein. If you modify file(s) - * with this exception, you may extend this exception to your version of the - * file(s), but you are not obligated to do so. If you do not wish to do so, - * delete this exception statement from your version. If you delete this - * exception statement from all source files in the program, then also delete - * it in the license file. - */ - -#pragma once - -namespace mongo { - -/** - * Type of callback functions that can be invoked when markThreadIdle() runs. These functions *must - * not throw*. - */ -typedef void (*ThreadIdleCallback)(); - -/** - * Informs the registered listener that this thread believes it may go idle for an extended period. - * The caller should avoid calling markThreadIdle at a high rate, as it can both be moderately - * costly itself and in terms of distributed overhead for subsequent malloc/free calls. - */ -void markThreadIdle(); - -/** - * Allows for registering callbacks for when threads go idle and become active. This is used by - * TCMalloc to return freed memory to its central freelist at appropriate points, so it won't happen - * during critical sections while holding locks. Calling this is not thread-safe. - */ -void registerThreadIdleCallback(ThreadIdleCallback callback); - -} // namespace mongo diff --git a/src/mongo/util/tcmalloc_server_status_section.cpp b/src/mongo/util/tcmalloc_server_status_section.cpp index ebd02e64a73..04cec0908b6 100644 --- a/src/mongo/util/tcmalloc_server_status_section.cpp +++ b/src/mongo/util/tcmalloc_server_status_section.cpp @@ -43,62 +43,19 @@ #include "mongo/db/server_parameters.h" #include "mongo/db/service_context.h" #include "mongo/transport/service_entry_point.h" -#include "mongo/transport/thread_idle_callback.h" #include "mongo/util/log.h" namespace mongo { namespace { -// If many clients are used, the per-thread caches become smaller and chances of -// rebalancing of free space during critical sections increases. In such situations, -// it is better to release memory when it is likely the thread will be blocked for -// a long time. -const int kManyClients = 40; -MONGO_COMPILER_VARIABLE_UNUSED stdx::mutex tcmallocCleanupLock; - -MONGO_EXPORT_SERVER_PARAMETER(tcmallocEnableMarkThreadTemporarilyIdle, bool, false); - -/** - * Callback to allow TCMalloc to release freed memory to the central list at - * favorable times. Ideally would do some milder cleanup or scavenge... - */ -void threadStateChange() { - - if (!tcmallocEnableMarkThreadTemporarilyIdle.load()) { - return; - } - - if (getGlobalServiceContext()->getServiceEntryPoint()->numOpenSessions() <= kManyClients) - return; - -#if MONGO_HAVE_GPERFTOOLS_GET_THREAD_CACHE_SIZE - size_t threadCacheSizeBytes = MallocExtension::instance()->GetThreadCacheSize(); - - static const size_t kMaxThreadCacheSizeBytes = 0x10000; - if (threadCacheSizeBytes < kMaxThreadCacheSizeBytes) { - // This number was chosen a bit magically. - // At 1000 threads and the current (64mb) thread local cache size, we're "full". - // So we may want this number to scale with the number of current clients. - return; - } - - LOG(1) << "thread over memory limit, cleaning up, current: " << (threadCacheSizeBytes / 1024) - << "k"; - - // We synchronize as the tcmalloc central list uses a spinlock, and we can cause a really - // terrible runaway if we're not careful. - stdx::lock_guard<stdx::mutex> lk(tcmallocCleanupLock); -#endif - MallocExtension::instance()->MarkThreadTemporarilyIdle(); -} - -// Register threadStateChange callback -MONGO_INITIALIZER(TCMallocThreadIdleListener)(InitializerContext*) { - if (!RUNNING_ON_VALGRIND) - registerThreadIdleCallback(&threadStateChange); - return Status::OK(); -} +MONGO_EXPORT_SERVER_PARAMETER(tcmallocEnableMarkThreadTemporarilyIdle, bool, false) + ->withValidator([](const bool& potentialNewValue) { + return Status(ErrorCodes::BadValue, + "tcmallocEnableMarkThreadTemporarilyIdle has been removed. Setting this " + "parameter has no effect and it will be removed in a future version of " + "MongoDB."); + }); class TCMallocServerStatusSection : public ServerStatusSection { public: |