Skip to content

Commit

Permalink
use hugepages without size specification
Browse files Browse the repository at this point in the history
hugepages can now be used without specifiying the exact size during the
use_hugepages() call. we now parse /proc/meminfo to determine the number
of hugepages available.
  • Loading branch information
mpetri committed Sep 17, 2013
1 parent 445a6ab commit 7775245
Showing 1 changed file with 15 additions and 21 deletions.
36 changes: 15 additions & 21 deletions examples/hugepages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,38 @@ using namespace std;
using namespace std::chrono;
using timer = std::chrono::high_resolution_clock;

template<class tCsa>
void do_something(const tCsa& csa)
template<class t_cst>
void do_something(const t_cst& cst)
{
uint64_t sum=0;
auto start = timer::now();
for (size_t i=0; i<csa.size() and i<10000000; ++i) {
sum+=csa.lf[i];
for (size_t i=0; i<cst.csa.size() and i<50000000; ++i) {
sum+=cst.csa.lf[i];
}
auto stop = timer::now();
cout << "runtime in s: " << duration_cast<seconds>(stop-start).count() << endl;
cout <<"sum="<<sum<<endl;
cout << "runtime in seconds: " << duration_cast<seconds>(stop-start).count() << endl;
cout << "sum="<<sum<<endl;
}

int main(int argc, char** argv)
{
if (argc < 2) {
cout << "Usage: " << argv[0] << " file" << endl;
cout << "Usage: " << argv[0] << " file <use_hugepages>" << endl;
cout << " (1) Creates a CST for a byte file. " << endl;
cout << " (2) Runs a benchmark with enabled/disabled 1GB=hugepages." << endl;
cout << " (2) Runs a benchmark with enabled/disabled hugepages." << endl;
return 1;
}

if (argc==3) {
memory_manager::use_hugepages(500*1024*1024);
// memory_manager::use_hugepages(500ULL*1024ULL*1024ULL);
// use all available hugepages if nothing is specified
memory_manager::use_hugepages();
}

memory_monitor::start();

csa_wt<> csa;
cst_sct3<> cst;
auto start = timer::now();
construct(csa, argv[1], 1);
construct(cst, argv[1], 1);
auto stop = timer::now();
cout << "construction in s: " << duration_cast<seconds>(stop-start).count() << endl;
do_something(csa); // before it is mapped

memory_monitor::stop();

std::ofstream ofs("cst-construction.json");
memory_monitor::write_memory_log<JSON>(ofs);
ofs.close();
cout << "construction time in seconds: " << duration_cast<seconds>(stop-start).count() << endl;
do_something(cst); // before it is mapped
}

0 comments on commit 7775245

Please sign in to comment.