Tested with "trap" function

This commit is contained in:
Alexey Milovidov 2020-05-30 23:02:44 +03:00
parent 9a41eb14a6
commit b95b6ec0ee
2 changed files with 28 additions and 3 deletions

View File

@ -170,15 +170,18 @@ static void getNotEnoughMemoryMessage(std::string & msg)
#if defined(__linux__)
try
{
static constexpr size_t buf_size = 4096;
char buf[buf_size];
UInt64 max_map_count = 0;
{
ReadBufferFromFile file("/proc/sys/vm/max_map_count");
ReadBufferFromFile file("/proc/sys/vm/max_map_count", buf_size, -1, buf);
readText(max_map_count, file);
}
UInt64 num_maps = 0;
{
ReadBufferFromFile file("/proc/self/maps");
ReadBufferFromFile file("/proc/self/maps", buf_size, -1, buf);
while (!file.eof())
{
char * next_pos = find_first_symbols<'\n'>(file.position(), file.buffer().end());
@ -201,7 +204,8 @@ static void getNotEnoughMemoryMessage(std::string & msg)
"\nIt looks like that the process is near the limit on number of virtual memory mappings."
"\nCurrent number of mappings (/proc/self/maps): {}."
"\nLimit on number of mappings (/proc/sys/vm/max_map_count): {}."
"\nYou should increase the limit for vm.max_map_count in /etc/sysctl.conf",
"\nYou should increase the limit for vm.max_map_count in /etc/sysctl.conf"
"\n",
num_maps, max_map_count);
}
}

View File

@ -7,11 +7,13 @@
#include <DataTypes/DataTypesNumber.h>
#include <Columns/ColumnString.h>
#include <Interpreters/Context.h>
#include <ext/scope_guard.h>
#include <thread>
#include <memory>
#include <cstdlib>
#include <unistd.h>
#include <sys/mman.h>
namespace DB
@ -132,6 +134,25 @@ public:
{
(void)context.getCurrentQueryId();
}
else if (mode == "mmap many")
{
std::vector<void *> maps;
SCOPE_EXIT(
{
//for (void * map : maps)
// munmap(map, 4096);
});
while (true)
{
void * hint = reinterpret_cast<void *>(
std::uniform_int_distribution<intptr_t>(0x100000000000UL, 0x700000000000UL)(thread_local_rng));
void * map = mmap(hint, 4096, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (MAP_FAILED == map)
throwFromErrno("Allocator: Cannot mmap", ErrorCodes::CANNOT_ALLOCATE_MEMORY);
maps.push_back(map);
}
}
else
throw Exception("Unknown trap mode", ErrorCodes::BAD_ARGUMENTS);
}