|
Packit |
345191 |
/*
|
|
Packit |
345191 |
* Copyright (C) 2016 - 2018 Intel Corporation.
|
|
Packit |
345191 |
* All rights reserved.
|
|
Packit |
345191 |
*
|
|
Packit |
345191 |
* Redistribution and use in source and binary forms, with or without
|
|
Packit |
345191 |
* modification, are permitted provided that the following conditions are met:
|
|
Packit |
345191 |
* 1. Redistributions of source code must retain the above copyright notice(s),
|
|
Packit |
345191 |
* this list of conditions and the following disclaimer.
|
|
Packit |
345191 |
* 2. Redistributions in binary form must reproduce the above copyright notice(s),
|
|
Packit |
345191 |
* this list of conditions and the following disclaimer in the documentation
|
|
Packit |
345191 |
* and/or other materials provided with the distribution.
|
|
Packit |
345191 |
*
|
|
Packit |
345191 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY EXPRESS
|
|
Packit |
345191 |
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
Packit |
345191 |
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
|
Packit |
345191 |
* EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
Packit |
345191 |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
Packit |
345191 |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
Packit |
345191 |
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
Packit |
345191 |
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
|
Packit |
345191 |
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
|
Packit |
345191 |
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
Packit |
345191 |
*/
|
|
Packit |
345191 |
|
|
Packit |
345191 |
#include "common.h"
|
|
Packit |
345191 |
#include "allocator_perf_tool/HugePageUnmap.hpp"
|
|
Packit |
345191 |
#include "allocator_perf_tool/HugePageOrganizer.hpp"
|
|
Packit |
345191 |
#include "TimerSysTime.hpp"
|
|
Packit |
345191 |
#include "Thread.hpp"
|
|
Packit |
345191 |
|
|
Packit |
345191 |
/*
|
|
Packit |
345191 |
* This test was created because of the munmap() fail in jemalloc.
|
|
Packit |
345191 |
* There are two root causes of the error:
|
|
Packit |
345191 |
* - kernel bug (munmap() fails when the size is not aligned)
|
|
Packit |
345191 |
* - heap Manager doesn’t provide size aligned to 2MB pages for munmap()
|
|
Packit |
345191 |
* Test allocates 2000MB using Huge Pages (50threads*10operations*4MBalloc_size),
|
|
Packit |
345191 |
* but it needs extra Huge Pages due to overhead caused by heap management.
|
|
Packit |
345191 |
*/
|
|
Packit |
345191 |
class HugePageTest: public :: testing::Test
|
|
Packit |
345191 |
{
|
|
Packit |
345191 |
protected:
|
|
Packit |
345191 |
void run()
|
|
Packit |
345191 |
{
|
|
Packit |
345191 |
unsigned mem_operations_num = 10;
|
|
Packit |
345191 |
size_t threads_number = 50;
|
|
Packit |
345191 |
bool touch_memory = true;
|
|
Packit |
345191 |
size_t size_1MB = 1024*1024;
|
|
Packit |
345191 |
size_t alignment = 2*size_1MB;
|
|
Packit |
345191 |
size_t alloc_size = 4*size_1MB;
|
|
Packit |
345191 |
|
|
Packit |
345191 |
std::vector<Thread *> threads;
|
|
Packit |
345191 |
std::vector<Task *> tasks;
|
|
Packit |
345191 |
|
|
Packit |
345191 |
TimerSysTime timer;
|
|
Packit |
345191 |
timer.start();
|
|
Packit |
345191 |
|
|
Packit |
345191 |
// This bug occurs more frequently under stress of multithreaded allocations.
|
|
Packit |
345191 |
for (int i=0; i
|
|
Packit |
345191 |
Task *task = new HugePageUnmap(mem_operations_num, touch_memory, alignment,
|
|
Packit |
345191 |
alloc_size, HBW_PAGESIZE_2MB);
|
|
Packit |
345191 |
tasks.push_back(task);
|
|
Packit |
345191 |
threads.push_back(new Thread(task));
|
|
Packit |
345191 |
}
|
|
Packit |
345191 |
|
|
Packit |
345191 |
float elapsed_time = timer.getElapsedTime();
|
|
Packit |
345191 |
|
|
Packit |
345191 |
ThreadsManager threads_manager(threads);
|
|
Packit |
345191 |
threads_manager.start();
|
|
Packit |
345191 |
threads_manager.barrier();
|
|
Packit |
345191 |
threads_manager.release();
|
|
Packit |
345191 |
|
|
Packit |
345191 |
//task release
|
|
Packit |
345191 |
for (int i=0; i
|
|
Packit |
345191 |
delete tasks[i];
|
|
Packit |
345191 |
}
|
|
Packit |
345191 |
|
|
Packit |
345191 |
RecordProperty("threads_number", threads_number);
|
|
Packit |
345191 |
RecordProperty("memory_operations_per_thread", mem_operations_num);
|
|
Packit |
345191 |
RecordProperty("elapsed_time", elapsed_time);
|
|
Packit |
345191 |
}
|
|
Packit |
345191 |
};
|
|
Packit |
345191 |
|
|
Packit |
345191 |
|
|
Packit |
345191 |
|
|
Packit |
345191 |
// Test passes when there is no crash.
|
|
Packit |
345191 |
TEST_F(HugePageTest, test_TC_MEMKIND_ext_UNMAP_HUGE_PAGE)
|
|
Packit |
345191 |
{
|
|
Packit |
345191 |
HugePageOrganizer huge_page_organizer(1024);
|
|
Packit |
345191 |
run();
|
|
Packit |
345191 |
}
|