Skip to content
This repository has been archived by the owner on Jun 22, 2023. It is now read-only.

Commit

Permalink
memory: add --mbind option to supress warning message when running Se…
Browse files Browse the repository at this point in the history
…astar apps on container

Add --mbind program option to supress mbind warning message, for the user who
wants to run Seastar apps on container which doesn't provides mbind() in container.
(To turn-off the message, specify "--mbind 0")

See scylladb/scylladb#2227

Signed-off-by: Takuya ASADA <[email protected]>
Message-Id: <[email protected]>
  • Loading branch information
syuu1228 authored and avikivity committed May 18, 2017
1 parent 271ee1e commit f726938
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
26 changes: 14 additions & 12 deletions core/memory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1269,7 +1269,7 @@ reclaimer::~reclaimer() {
r.erase(std::find(r.begin(), r.end(), this));
}

void configure(std::vector<resource::memory> m,
void configure(std::vector<resource::memory> m, bool mbind,
optional<std::string> hugetlbfs_path) {
size_t total = 0;
for (auto&& x : m) {
Expand All @@ -1290,16 +1290,18 @@ void configure(std::vector<resource::memory> m,
for (auto&& x : m) {
#ifdef HAVE_NUMA
unsigned long nodemask = 1UL << x.nodeid;
auto r = ::mbind(cpu_mem.mem() + pos, x.bytes,
MPOL_PREFERRED,
&nodemask, std::numeric_limits<unsigned long>::digits,
MPOL_MF_MOVE);

if (r == -1) {
char err[1000] = {};
strerror_r(errno, err, sizeof(err));
std::cerr << "WARNING: unable to mbind shard memory; performance may suffer: "
<< err << std::endl;
if (mbind) {
auto r = ::mbind(cpu_mem.mem() + pos, x.bytes,
MPOL_PREFERRED,
&nodemask, std::numeric_limits<unsigned long>::digits,
MPOL_MF_MOVE);

if (r == -1) {
char err[1000] = {};
strerror_r(errno, err, sizeof(err));
std::cerr << "WARNING: unable to mbind shard memory; performance may suffer: "
<< err << std::endl;
}
}
#endif
pos += x.bytes;
Expand Down Expand Up @@ -1639,7 +1641,7 @@ reclaimer::~reclaimer() {
void set_reclaim_hook(std::function<void (std::function<void ()>)> hook) {
}

void configure(std::vector<resource::memory> m, std::experimental::optional<std::string> hugepages_path) {
void configure(std::vector<resource::memory> m, bool mbind, std::experimental::optional<std::string> hugepages_path) {
}

statistics stats() {
Expand Down
2 changes: 1 addition & 1 deletion core/memory.hh
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ static constexpr size_t page_bits = 12;
static constexpr size_t page_size = 1 << page_bits; // 4K
static constexpr size_t huge_page_size = 512 * page_size; // 2M

void configure(std::vector<resource::memory> m,
void configure(std::vector<resource::memory> m, bool mbind,
std::experimental::optional<std::string> hugetlbfs_path = {});

void enable_abort_on_allocation_failure();
Expand Down
11 changes: 8 additions & 3 deletions core/reactor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3350,6 +3350,7 @@ smp::get_options_description()
#else
("max-io-requests", bpo::value<unsigned>(), "Maximum amount of concurrent requests to be sent to the disk. Defaults to 128 times the number of processors")
#endif
("mbind", bpo::value<bool>()->default_value(true), "enable mbind")
;
return opts;
}
Expand Down Expand Up @@ -3522,6 +3523,10 @@ void smp::configure(boost::program_options::variables_map configuration)
if (!thread_affinity && _using_dpdk) {
print("warning: --thread-affinity 0 ignored in dpdk mode\n");
}
auto mbind = configuration["mbind"].as<bool>();
if (!thread_affinity) {
mbind = false;
}

smp::count = 1;
smp::_tmain = std::this_thread::get_id();
Expand Down Expand Up @@ -3597,7 +3602,7 @@ void smp::configure(boost::program_options::variables_map configuration)
if (thread_affinity) {
smp::pin(allocations[0].cpu_id);
}
memory::configure(allocations[0].mem, hugepages_path);
memory::configure(allocations[0].mem, mbind, hugepages_path);

if (configuration.count("abort-on-seastar-bad-alloc")) {
memory::enable_abort_on_allocation_failure();
Expand Down Expand Up @@ -3657,13 +3662,13 @@ void smp::configure(boost::program_options::variables_map configuration)
unsigned i;
for (i = 1; i < smp::count; i++) {
auto allocation = allocations[i];
create_thread([configuration, hugepages_path, i, allocation, assign_io_queue, alloc_io_queue, thread_affinity, heapprof_enabled] {
create_thread([configuration, hugepages_path, i, allocation, assign_io_queue, alloc_io_queue, thread_affinity, heapprof_enabled, mbind] {
auto thread_name = seastar::format("reactor-{}", i);
pthread_setname_np(pthread_self(), thread_name.c_str());
if (thread_affinity) {
smp::pin(allocation.cpu_id);
}
memory::configure(allocation.mem, hugepages_path);
memory::configure(allocation.mem, mbind, hugepages_path);
memory::set_heap_profiling_enabled(heapprof_enabled);
sigset_t mask;
sigfillset(&mask);
Expand Down

0 comments on commit f726938

Please sign in to comment.