Skip to content

Commit

Permalink
smp: disable mlock on overcommit
Browse files Browse the repository at this point in the history
Memory locking keeps pages in physical memory, and decreases the amount of pages available for swapping on an overcommit setup. Thus, it can decrease fairness, increase memory pressure, and cause OOMs. So, it is less suitable for a cooperative overcommit setup.

This change disables memory locking on overcommit (overprovisioned - I hope I can rename that config). Also, it reuses the mlock variable. I assume that this change shouldn't break reasonable configs.
  • Loading branch information
tomershafir committed Dec 11, 2024
1 parent 665fed0 commit cc1b6bb
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions include/seastar/core/reactor_config.hh
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ struct reactor_options : public program_options::option_group {
/// * \ref idle_poll_time_us = 0
/// * \ref smp_options::thread_affinity = 0
/// * \ref poll_aio = 0
/// * \ref smp_options::lock_memory = 0
program_options::value<> overprovisioned;
/// \brief Abort when seastar allocator cannot allocate memory.
program_options::value<> abort_on_seastar_bad_alloc;
Expand Down
2 changes: 2 additions & 0 deletions include/seastar/core/smp_options.hh
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ struct smp_options : public program_options::option_group {
/// Path to accessible hugetlbfs mount (typically /dev/hugepages/something).
program_options::value<std::string> hugepages;
/// Lock all memory (prevents swapping).
///
/// Disable for overprovisioned environments.
program_options::value<bool> lock_memory;
/// Pin threads to their cpus (disable for overprovisioning).
///
Expand Down
6 changes: 3 additions & 3 deletions src/core/reactor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3814,7 +3814,7 @@ smp_options::smp_options(program_options::option_group* parent_group)
, memory(*this, "memory", std::nullopt, "memory to use, in bytes (ex: 4G) (default: all)")
, reserve_memory(*this, "reserve-memory", {}, "memory reserved to OS (if --memory not specified)")
, hugepages(*this, "hugepages", {}, "path to accessible hugetlbfs mount (typically /dev/hugepages/something)")
, lock_memory(*this, "lock-memory", {}, "lock all memory (prevents swapping)")
, lock_memory(*this, "lock-memory", {}, "lock all memory (prevents swapping). Disable for overprovisioned environments")
, thread_affinity(*this, "thread-affinity", true, "pin threads to their cpus (disable for overprovisioning)")
#ifdef SEASTAR_HAVE_HWLOC
, num_io_groups(*this, "num-io-groups", {}, "Number of IO groups. Each IO group will be responsible for a fraction of the IO requests. Defaults to the number of NUMA nodes")
Expand Down Expand Up @@ -4332,7 +4332,7 @@ void smp::configure(const smp_options& smp_opts, const reactor_options& reactor_
hugepages_path = smp_opts.hugepages.get_value();
}
auto mlock = false;
if (smp_opts.lock_memory) {
if (smp_opts.lock_memory && !reactor_opts.overprovisioned) {
mlock = smp_opts.lock_memory.get_value();
}
if (mlock) {
Expand Down Expand Up @@ -4603,7 +4603,7 @@ void smp::configure(const smp_options& smp_opts, const reactor_options& reactor_

engine().configure(reactor_opts);

if (smp_opts.lock_memory && smp_opts.lock_memory.get_value() && layout && !layout->ranges.empty()) {
if (mlock && layout && !layout->ranges.empty()) {
smp::setup_prefaulter(resources, std::move(*layout));
}
}
Expand Down

0 comments on commit cc1b6bb

Please sign in to comment.