0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-26 15:33:54 +01:00

ircd::fs: Use a nice-style value for request priority; default to zero.

This commit is contained in:
Jason Volk 2018-12-27 10:35:45 -08:00
parent 2f5d175957
commit e58a975750
4 changed files with 18 additions and 17 deletions

View file

@ -40,10 +40,8 @@ struct ircd::fs::read_opts
/// Offset in the file to start the read from.
off_t offset {0};
/// Request priority. Higher value request will take priority over lower
/// value. Lowest value is zero. Negative value will receive a contextual
/// value internally (generally just zero). Default is -1.
int8_t priority {-1};
/// Request priority. Lower value request will take priority over higher
int8_t priority {0};
/// Determines whether this operation is conducted via AIO. If not, a
/// direct syscall is made. Using AIO will only block one ircd::ctx while

View file

@ -39,8 +39,6 @@ struct ircd::fs::sync_opts
/// this has no effect.
bool aio {true};
/// Request priority. This value is ignored by the kernel for the
/// operations provided by this interface. It is still provided for
/// consistency and may be used internally by IRCd in the future.
int8_t priority {-1};
/// Request priority. This value is ignored for sync operations.
int8_t priority {0};
};

View file

@ -59,10 +59,8 @@ struct ircd::fs::write_opts
/// the host system later ignores the offset due to the file's openmode.
off_t offset {0};
/// Request priority. Higher value request will take priority over lower
/// value. Lowest value is zero. Negative value will receive a contextual
/// value internally (generally just zero). Default is -1.
int8_t priority {-1};
/// Request priority. Lower value request will take priority over higher.
int8_t priority {0};
/// for allocate()
bool keep_size {false};

View file

@ -658,14 +658,21 @@ catch(const std::exception &e)
// internal util
//
/// Translate an ircd::fs opts priority integer to an AIO priority integer.
/// The ircd::fs priority integer is like a nice value. The AIO value is
/// positive [0, MAX_REQPRIO]. This function takes an ircd::fs value and
/// shifts it to the AIO value.
int
ircd::fs::aio::reqprio(int input)
{
// no use for negative values yet; make them zero.
input = std::max(input, 0);
// value is reduced to system maximum.
input = std::min(input, int(ircd::info::aio_reqprio_max));
static const auto median
{
int(MAX_REQPRIO / 2)
};
input = std::max(input, 0 - median);
input = std::min(input, median);
input = MAX_REQPRIO - (input + median);
assert(input >= 0 && input <= int(MAX_REQPRIO));
return input;
}