diff options
author | Benety Goh <benety@mongodb.com> | 2017-07-03 10:44:27 -0400 |
---|---|---|
committer | Benety Goh <benety@mongodb.com> | 2017-07-03 10:44:27 -0400 |
commit | 5a933be9235b7d02bb5c790c7ff7eba3a867c43a (patch) | |
tree | 20bd1fba88db73c6ad32906bdc72bd5b35e6d028 /src | |
parent | 3fd1d565b0dd8863be687843746b2cd7e5860377 (diff) | |
download | mongo-5a933be9235b7d02bb5c790c7ff7eba3a867c43a.tar.gz |
Revert "SERVER-29462 Align locks in mongo::Paritioned to avoid false sharing"
This reverts commit edc858ca3a32974c07f027e6860a52ac6e89039b.
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/db/catalog/util/partitioned.h | 18 | ||||
-rw-r--r-- | src/mongo/util/with_alignment.h | 65 |
2 files changed, 5 insertions, 78 deletions
diff --git a/src/mongo/db/catalog/util/partitioned.h b/src/mongo/db/catalog/util/partitioned.h index ab960cc7cc1..475ea415f48 100644 --- a/src/mongo/db/catalog/util/partitioned.h +++ b/src/mongo/db/catalog/util/partitioned.h @@ -29,7 +29,6 @@ #pragma once #include <algorithm> -#include <array> #include <cstdlib> #include <iterator> #include <memory> @@ -40,9 +39,7 @@ #include "mongo/platform/atomic_word.h" #include "mongo/stdx/memory.h" #include "mongo/stdx/mutex.h" -#include "mongo/stdx/new.h" #include "mongo/util/assert_util.h" -#include "mongo/util/with_alignment.h" namespace mongo { @@ -103,8 +100,6 @@ struct Partitioner { namespace partitioned_detail { -using CacheAlignedMutex = CacheAligned<stdx::mutex>; - template <typename Key, typename Value> Key getKey(const std::pair<Key, Value>& pair) { return std::get<0>(pair); @@ -115,10 +110,9 @@ Key getKey(const Key& key) { return key; } -template <typename T> -inline std::vector<stdx::unique_lock<stdx::mutex>> lockAllPartitions(T& mutexes) { +inline std::vector<stdx::unique_lock<stdx::mutex>> lockAllPartitions( + std::vector<stdx::mutex>& mutexes) { std::vector<stdx::unique_lock<stdx::mutex>> result; - result.reserve(mutexes.size()); std::transform(mutexes.begin(), mutexes.end(), std::back_inserter(result), [](auto&& mutex) { return stdx::unique_lock<stdx::mutex>{mutex}; }); @@ -381,14 +375,12 @@ public: /** * Constructs a partitioned version of a AssociativeContainer, with `nPartitions` partitions. */ - Partitioned() = default; + Partitioned() : _mutexes(nPartitions), _partitions(nPartitions) {} private: // These two vectors parallel each other, but we keep them separate so that we can return an // iterator over `_partitions` from within All. - mutable std::array<partitioned_detail::CacheAlignedMutex, nPartitions> _mutexes; - - using CacheAlignedAssociativeContainer = CacheAligned<AssociativeContainer>; - std::array<CacheAlignedAssociativeContainer, nPartitions> _partitions; + mutable std::vector<stdx::mutex> _mutexes; + std::vector<AssociativeContainer> _partitions; }; } // namespace mongo diff --git a/src/mongo/util/with_alignment.h b/src/mongo/util/with_alignment.h deleted file mode 100644 index b1128f527ff..00000000000 --- a/src/mongo/util/with_alignment.h +++ /dev/null @@ -1,65 +0,0 @@ -/** - * Copyright (C) 2017 MongoDB Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * 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 - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * 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 GNU Affero General 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 - -#include <algorithm> - -#include "mongo/stdx/new.h" - -namespace mongo { - -/** - * Creates a new type with the same interface as T, but having the - * given alignment. Note that if the given alignment is less than - * alignof(T), the program is ill-formed. To ensure that your program - * is well formed, see WithAligmentAtLeast, which will not reduce - * alignment below the natural alignment of T. - */ -template <typename T, size_t alignment> -struct alignas(alignment) WithAlignment : T { - using T::T; -}; - -/** - * Creates a new type with the same interface as T, but having an - * alignment greater than or equal to the given alignment. To ensure - * that the program remains well formed, the alignment will not be - * reduced below the natural alignment for T. - */ -template <typename T, size_t alignment> -using WithAlignmentAtLeast = WithAlignment<T, std::max(alignof(T), alignment)>; - -/** - * Creates a new type with the same interface as T but guaranteed to - * be aligned to at least the size of a cache line. - */ -template <typename T> -using CacheAligned = WithAlignmentAtLeast<T, stdx::hardware_destructive_interference_size>; - -} // namespace mongo |