From 7769d75088976a3735797f9827184315d3bf21d8 Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Wed, 3 Nov 2021 08:11:36 +0300 Subject: [PATCH] Log size of remapped memory (remap_executable) --- programs/server/Server.cpp | 4 ++-- src/Common/remapExecutable.cpp | 9 +++++---- src/Common/remapExecutable.h | 6 +++++- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/programs/server/Server.cpp b/programs/server/Server.cpp index af1686bfa70..29845f23d92 100644 --- a/programs/server/Server.cpp +++ b/programs/server/Server.cpp @@ -595,8 +595,8 @@ if (ThreadFuzzer::instance().isEffective()) if (config().getBool("remap_executable", false)) { LOG_DEBUG(log, "Will remap executable in memory."); - remapExecutable(); - LOG_DEBUG(log, "The code in memory has been successfully remapped."); + size_t size = remapExecutable(); + LOG_DEBUG(log, "The code ({}) in memory has been successfully remapped.", ReadableSize(size)); } if (config().getBool("mlock_executable", false)) diff --git a/src/Common/remapExecutable.cpp b/src/Common/remapExecutable.cpp index a774b1028d5..0c1cb03457f 100644 --- a/src/Common/remapExecutable.cpp +++ b/src/Common/remapExecutable.cpp @@ -1,3 +1,5 @@ +#include "remapExecutable.h" + #if defined(__linux__) && defined(__amd64__) && defined(__SSE2__) && !defined(SANITIZER) && defined(NDEBUG) && !defined(SPLIT_SHARED_LIBRARIES) #include @@ -11,8 +13,6 @@ #include #include -#include "remapExecutable.h" - namespace DB { @@ -136,10 +136,11 @@ __attribute__((__noinline__)) void remapToHugeStep1(void * begin, size_t size) } -void remapExecutable() +size_t remapExecutable() { auto [begin, size] = getMappedArea(reinterpret_cast(remapExecutable)); remapToHugeStep1(begin, size); + return size; } } @@ -149,7 +150,7 @@ void remapExecutable() namespace DB { -void remapExecutable() {} +size_t remapExecutable() { return 0; } } diff --git a/src/Common/remapExecutable.h b/src/Common/remapExecutable.h index bad5f7adb78..b5af9c82f84 100644 --- a/src/Common/remapExecutable.h +++ b/src/Common/remapExecutable.h @@ -1,8 +1,12 @@ #pragma once + +#include + namespace DB { /// This function tries to reallocate the code of the running program in a more efficient way. -void remapExecutable(); +/// @return size of remapped area. +size_t remapExecutable(); }