0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-09-27 11:18:51 +02:00

ircd::fs::aio: Reorganize with symbol overriding; add conf items.

This commit is contained in:
Jason Volk 2018-12-21 12:58:53 -08:00
parent c3d95aa8de
commit a5ebc28928
5 changed files with 121 additions and 63 deletions

View file

@ -25,11 +25,15 @@ namespace ircd::fs::aio
struct kernel;
struct request;
extern const bool support;
extern const bool support_fsync;
extern const bool support_fdsync;
extern const bool SUPPORT;
extern const bool SUPPORT_FSYNC;
extern const bool SUPPORT_FDSYNC;
extern const size_t MAX_EVENTS;
extern const size_t MAX_REQPRIO;
extern conf::item<bool> enable;
extern conf::item<size_t> max_events;
extern conf::item<size_t> max_submit;
extern struct stats stats;
extern kernel *context;

View file

@ -92,6 +92,7 @@ libircd_la_LIBADD = \
# systems.
libircd_la_SOURCES = \
allocator.cc \
info.cc \
exception.cc \
util.cc \
fpe.cc \
@ -102,7 +103,6 @@ libircd_la_SOURCES = \
locale.cc \
conf.cc \
logger.cc \
info.cc \
sodium.cc \
rfc1459.cc \
rand.cc \

View file

@ -18,6 +18,74 @@ namespace ircd::fs::aio
static int reqprio(int);
}
///////////////////////////////////////////////////////////////////////////////
//
// fs/aio.h
//
// The contents of this section override weak symbols in ircd/fs.cc when this
// unit is conditionally compiled and linked on AIO-supporting platforms. On
// non-supporting platforms, or for items not listed here, the definitions in
// ircd/fs.cc are the default.
decltype(ircd::fs::aio::SUPPORT)
ircd::fs::aio::SUPPORT
{
true
};
/// True if IOCB_CMD_FSYNC is supported by AIO. If this is false then
/// fs::fsync_opts::async=true flag is ignored.
decltype(ircd::fs::aio::SUPPORT_FSYNC)
ircd::fs::aio::SUPPORT_FSYNC
{
false //TODO: get this info
};
/// True if IOCB_CMD_FDSYNC is supported by AIO. If this is false then
/// fs::fsync_opts::async=true flag is ignored.
decltype(ircd::fs::aio::SUPPORT_FDSYNC)
ircd::fs::aio::SUPPORT_FDSYNC
{
false //TODO: get this info
};
decltype(ircd::fs::aio::MAX_EVENTS)
ircd::fs::aio::MAX_EVENTS
{
128L
};
decltype(ircd::fs::aio::MAX_REQPRIO)
ircd::fs::aio::MAX_REQPRIO
{
info::aio_reqprio_max
};
//
// init
//
ircd::fs::aio::init::init()
{
assert(!context);
if(!bool(aio::enable))
return;
context = new kernel{};
}
ircd::fs::aio::init::~init()
noexcept
{
delete context;
context = nullptr;
}
///////////////////////////////////////////////////////////////////////////////
//
// ircd/aio.h
//
//
// request::fsync
//
@ -303,12 +371,6 @@ const
// kernel
//
decltype(ircd::fs::aio::kernel::MAX_EVENTS)
ircd::fs::aio::kernel::MAX_EVENTS
{
128
};
//
// kernel::kernel
//
@ -394,7 +456,6 @@ void
ircd::fs::aio::kernel::submit(request &request)
noexcept try
{
static const size_t threshold(16);
thread_local std::array<iocb *, MAX_EVENTS> queue;
thread_local size_t count;
thread_local size_t sem[2];
@ -402,7 +463,7 @@ noexcept try
assert(request.aio_data == uintptr_t(&request));
queue.at(count++) = static_cast<iocb *>(&request);
if(count >= threshold)
if(count >= size_t(max_submit))
{
syscall<SYS_io_submit>(context->idp, count, queue.data());
++stats.maxed_submits;
@ -421,7 +482,7 @@ noexcept try
return;
syscall<SYS_io_submit>(context->idp, count, queue.data());
stats.maxed_submits += count >= threshold;
stats.maxed_submits += count >= size_t(max_submit);
++stats.submits;
count = 0;
});

View file

@ -27,9 +27,6 @@ namespace ircd::fs::aio
/// an extern instance pointer at fs::aio::context maintained by fs::aio::init.
struct ircd::fs::aio::kernel
{
/// Maximum number of events we can submit to kernel
static const size_t MAX_EVENTS;
/// Internal semaphore for synchronization of this object
ctx::dock dock;

View file

@ -507,16 +507,16 @@ ircd::fs::flush(const fd &fd,
int(fd),
opts.metadata,
opts.aio,
opts.metadata? aio::support_fdsync : aio::support_fsync
opts.metadata? aio::SUPPORT_FDSYNC : aio::SUPPORT_FSYNC
};
#ifdef IRCD_USE_AIO
if(aio::context && opts.aio)
{
if(!opts.metadata && aio::support_fdsync)
if(!opts.metadata && aio::SUPPORT_FDSYNC)
return aio::fdsync(fd, opts);
if(aio::support_fsync)
if(aio::SUPPORT_FSYNC)
return aio::fsync(fd, opts);
}
#endif
@ -960,32 +960,30 @@ ircd::fs::write(const fd &fd,
// fs/aio.h
//
/// True if AIO is supported by this build and runtime.
decltype(ircd::fs::aio::support)
ircd::fs::aio::support
{
#ifdef IRCD_USE_AIO
true
#else
false
#endif
};
//
// These symbols can be overriden by ircd/aio.cc if it is compiled and linked;
// otherwise on non-supporting platforms these will be the defaults here.
//
/// True if IOCB_CMD_FSYNC is supported by AIO. If this is false then
/// fs::fsync_opts::async=true flag is ignored.
decltype(ircd::fs::aio::support_fsync)
ircd::fs::aio::support_fsync
{
false //TODO: get this info from system
};
decltype(ircd::fs::aio::SUPPORT)
extern __attribute__((weak))
ircd::fs::aio::SUPPORT;
/// True if IOCB_CMD_FDSYNC is supported by AIO. If this is false then
/// fs::fsync_opts::async=true flag is ignored.
decltype(ircd::fs::aio::support_fdsync)
ircd::fs::aio::support_fdsync
{
false //TODO: get this info from system
};
decltype(ircd::fs::aio::SUPPORT_FSYNC)
extern __attribute__((weak))
ircd::fs::aio::SUPPORT_FSYNC;
decltype(ircd::fs::aio::SUPPORT_FDSYNC)
extern __attribute__((weak))
ircd::fs::aio::SUPPORT_FDSYNC;
decltype(ircd::fs::aio::MAX_REQPRIO)
extern __attribute__((weak))
ircd::fs::aio::MAX_REQPRIO;
decltype(ircd::fs::aio::MAX_EVENTS)
extern __attribute__((weak))
ircd::fs::aio::MAX_EVENTS;
/// Conf item to control whether AIO is enabled or bypassed.
decltype(ircd::fs::aio::enable)
@ -996,6 +994,22 @@ ircd::fs::aio::enable
{ "persist", false },
};
decltype(ircd::fs::aio::max_events)
ircd::fs::aio::max_events
{
{ "name", "ircd.fs.aio.max_events" },
{ "default", long(aio::MAX_EVENTS) },
{ "persist", false },
};
decltype(ircd::fs::aio::max_submit)
ircd::fs::aio::max_submit
{
{ "name", "ircd.fs.aio.max_submit" },
{ "default", 16L },
{ "persist", false },
};
/// Global stats structure
decltype(ircd::fs::aio::stats)
ircd::fs::aio::stats;
@ -1008,16 +1022,7 @@ ircd::fs::aio::context;
// init
//
#ifdef IRCD_USE_AIO
ircd::fs::aio::init::init()
{
assert(!context);
if(!bool(aio::enable))
return;
context = new kernel{};
}
#else
__attribute__((weak))
ircd::fs::aio::init::init()
{
assert(!context);
@ -1026,22 +1031,13 @@ ircd::fs::aio::init::init()
"No support for asynchronous local filesystem IO..."
};
}
#endif
#ifdef IRCD_USE_AIO
ircd::fs::aio::init::~init()
noexcept
{
delete context;
context = nullptr;
}
#else
__attribute__((weak))
ircd::fs::aio::init::~init()
noexcept
{
assert(!context);
}
#endif
///////////////////////////////////////////////////////////////////////////////
//