mirror of
https://github.com/trapexit/mergerfs.git
synced 2026-10-25 18:40:18 -04:00
Inline ioprio disabled fast path
- Expose the ioprio enabled flag as an atomic for relaxed inline checks - Inline SetFrom construction so disabled read/write paths avoid a function call - Move priority application into a slow helper used only when ioprio is enabled
This commit is contained in:
parent
30d59d4458
commit
5f7fa17ad8
2 changed files with 33 additions and 14 deletions
|
|
@ -32,8 +32,12 @@ enum
|
||||||
IOPRIO_WHO_PROCESS = 1
|
IOPRIO_WHO_PROCESS = 1
|
||||||
};
|
};
|
||||||
|
|
||||||
|
namespace ioprio
|
||||||
|
{
|
||||||
|
std::atomic<bool> _enabled{false};
|
||||||
|
}
|
||||||
|
|
||||||
thread_local int ioprio::SetFrom::thread_prio = -1;
|
thread_local int ioprio::SetFrom::thread_prio = -1;
|
||||||
bool _enabled = false;
|
|
||||||
|
|
||||||
int
|
int
|
||||||
ioprio::get(const int who_)
|
ioprio::get(const int who_)
|
||||||
|
|
@ -69,22 +73,14 @@ ioprio::set(const int who_,
|
||||||
void
|
void
|
||||||
ioprio::enable(const bool enable_)
|
ioprio::enable(const bool enable_)
|
||||||
{
|
{
|
||||||
_enabled = enable_;
|
_enabled.store(enable_,std::memory_order_relaxed);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
void
|
||||||
ioprio::enabled()
|
ioprio::SetFrom::_slow_apply(const pid_t pid_)
|
||||||
{
|
|
||||||
return _enabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
ioprio::SetFrom::SetFrom(const pid_t pid_)
|
|
||||||
{
|
{
|
||||||
int client_prio;
|
int client_prio;
|
||||||
|
|
||||||
if(!_enabled)
|
|
||||||
return;
|
|
||||||
|
|
||||||
client_prio = ioprio::get(pid_);
|
client_prio = ioprio::get(pid_);
|
||||||
if(client_prio < 0)
|
if(client_prio < 0)
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -18,13 +18,27 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
|
||||||
namespace ioprio
|
namespace ioprio
|
||||||
{
|
{
|
||||||
|
// Exposed so the disabled-path check in SetFrom can inline into
|
||||||
|
// every fuse_read/fuse_write as an atomic load + branch, with no
|
||||||
|
// function overhead.
|
||||||
|
extern std::atomic<bool> _enabled;
|
||||||
|
|
||||||
|
[[gnu::always_inline]]
|
||||||
|
inline
|
||||||
|
bool
|
||||||
|
enabled()
|
||||||
|
{
|
||||||
|
return _enabled.load(std::memory_order_relaxed);
|
||||||
|
}
|
||||||
|
|
||||||
void enable(const bool);
|
void enable(const bool);
|
||||||
bool enabled();
|
|
||||||
|
|
||||||
int get(const int who);
|
int get(const int who);
|
||||||
int set(const int who, const int ioprio);
|
int set(const int who, const int ioprio);
|
||||||
|
|
@ -33,6 +47,15 @@ namespace ioprio
|
||||||
{
|
{
|
||||||
static thread_local int thread_prio;
|
static thread_local int thread_prio;
|
||||||
|
|
||||||
SetFrom(const pid_t pid);
|
[[gnu::always_inline]]
|
||||||
|
inline
|
||||||
|
SetFrom(const pid_t pid_)
|
||||||
|
{
|
||||||
|
if(ioprio::enabled())
|
||||||
|
_slow_apply(pid_);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
void _slow_apply(const pid_t);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue