From 3903e12659b57760a8ffe3140747daa13d01068d Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Wed, 9 Feb 2022 13:37:59 +0000 Subject: Add a simple MallocMmapGuard --- .../src/tests/shutdownguard/shutdownguard_test.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'staging_vespalib/src/tests/shutdownguard') diff --git a/staging_vespalib/src/tests/shutdownguard/shutdownguard_test.cpp b/staging_vespalib/src/tests/shutdownguard/shutdownguard_test.cpp index 79777cdd53f..0fb2dfdda4b 100644 --- a/staging_vespalib/src/tests/shutdownguard/shutdownguard_test.cpp +++ b/staging_vespalib/src/tests/shutdownguard/shutdownguard_test.cpp @@ -1,6 +1,7 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include #include +#include #include #include #include @@ -8,12 +9,8 @@ using namespace vespalib; -TEST_SETUP(Test); - -int -Test::Main() +TEST("test shutdown guard") { - TEST_INIT("shutdownguard_test"); { ShutdownGuard farFuture(1000000s); std::this_thread::sleep_for(20ms); @@ -37,5 +34,10 @@ Test::Main() } EXPECT_TRUE(i < 800); } - TEST_DONE(); } + +TEST("test malloc mmap guard") { + MallocMmapGuard guard(0x100000); +} + +TEST_MAIN() { TEST_RUN_ALL(); } \ No newline at end of file -- cgit v1.2.3 From 5f96af6e4995a7a38445f3d24482baaedeec0668 Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Wed, 9 Feb 2022 16:33:49 +0000 Subject: Let default limit be 1G, and add extra comment about usage and non-usage. --- staging_vespalib/src/tests/shutdownguard/shutdownguard_test.cpp | 2 +- staging_vespalib/src/vespa/vespalib/util/malloc_mmap_guard.cpp | 3 ++- staging_vespalib/src/vespa/vespalib/util/malloc_mmap_guard.h | 5 +++-- vespamalloc/src/vespamalloc/malloc/threadpool.hpp | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) (limited to 'staging_vespalib/src/tests/shutdownguard') diff --git a/staging_vespalib/src/tests/shutdownguard/shutdownguard_test.cpp b/staging_vespalib/src/tests/shutdownguard/shutdownguard_test.cpp index 0fb2dfdda4b..348e9bbd503 100644 --- a/staging_vespalib/src/tests/shutdownguard/shutdownguard_test.cpp +++ b/staging_vespalib/src/tests/shutdownguard/shutdownguard_test.cpp @@ -40,4 +40,4 @@ TEST("test malloc mmap guard") { MallocMmapGuard guard(0x100000); } -TEST_MAIN() { TEST_RUN_ALL(); } \ No newline at end of file +TEST_MAIN() { TEST_RUN_ALL(); } diff --git a/staging_vespalib/src/vespa/vespalib/util/malloc_mmap_guard.cpp b/staging_vespalib/src/vespa/vespalib/util/malloc_mmap_guard.cpp index 2b932981823..0ced160fda2 100644 --- a/staging_vespalib/src/vespa/vespalib/util/malloc_mmap_guard.cpp +++ b/staging_vespalib/src/vespa/vespalib/util/malloc_mmap_guard.cpp @@ -1,5 +1,6 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "malloc_mmap_guard.h" +#include #include #include #include @@ -16,7 +17,7 @@ MallocMmapGuard::MallocMmapGuard(size_t mmapLimit) : MallocMmapGuard::~MallocMmapGuard() { assert(_threadId == std::this_thread::get_id()); - mallopt(M_MMAP_THRESHOLD, -1); + mallopt(M_MMAP_THRESHOLD, 1_Gi); } } diff --git a/staging_vespalib/src/vespa/vespalib/util/malloc_mmap_guard.h b/staging_vespalib/src/vespa/vespalib/util/malloc_mmap_guard.h index 3cf26202f9b..03e6d38c03c 100644 --- a/staging_vespalib/src/vespa/vespalib/util/malloc_mmap_guard.h +++ b/staging_vespalib/src/vespa/vespalib/util/malloc_mmap_guard.h @@ -7,7 +7,9 @@ namespace vespalib { /** * Provides a hint to malloc implementation that all allocations in the scope of this guard - * will use mmap directly for allocation larger than the givem limit. + * will use mmap directly for allocation larger than the given limit. + * NB !! Note that guards can not be nested. Intention is to use around third party libraries where + * you do not control allocation yourself. * The effect is implementation dependent. vespamalloc applies this only for the calling thread. **/ class MallocMmapGuard @@ -24,4 +26,3 @@ private: }; } // namespace vespalib - diff --git a/vespamalloc/src/vespamalloc/malloc/threadpool.hpp b/vespamalloc/src/vespamalloc/malloc/threadpool.hpp index a3691a496dd..e9b9fabebdc 100644 --- a/vespamalloc/src/vespamalloc/malloc/threadpool.hpp +++ b/vespamalloc/src/vespamalloc/malloc/threadpool.hpp @@ -86,7 +86,7 @@ mallocHelper(size_t exactSize, template ThreadPoolT::ThreadPoolT() : _allocPool(nullptr), - _mmapLimit(-1), + _mmapLimit(0x40000000), _threadId(0), _osThreadId(0) { -- cgit v1.2.3