sapling/eden/fs/store/ImportPriority.h
Xavier Deguillard 69159f20d5 store: split the blob/tree/prefetch queue
Summary:
Having the same queue for all three makes the dequeue code overly complicated
as it needs to keep track of the kind of request that needs to be dequeued.
Incidently, the previous code had a bug where request in "putback" would be
requeued at the end of the queue, even though there were at the beginning of it
if they all had the same priorities.

This is theory should also improve the dequeue performance when the queue has a
mix of blobs/tree requests, but I haven't measured.

Reviewed By: genevievehelsel

Differential Revision: D30560490

fbshipit-source-id: b27e5429105c07e5f9eab482c12e5699ca3413f7
2021-09-01 14:29:27 -07:00

70 lines
2.0 KiB
C++

/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This software may be used and distributed according to the terms of the
* GNU General Public License version 2.
*/
#pragma once
#include <cstdint>
namespace facebook::eden {
enum class ImportPriorityKind : int16_t { Low = 0, Normal = 1, High = 2 };
struct ImportPriority {
ImportPriorityKind kind;
uint64_t offset : 48;
static constexpr ImportPriority kLow() {
return ImportPriority{ImportPriorityKind::Low};
}
static constexpr ImportPriority kNormal() {
return ImportPriority{ImportPriorityKind::Normal};
}
static constexpr ImportPriority kHigh() {
return ImportPriority{ImportPriorityKind::High};
}
// set half of the maximum offset as default offset to allow equal
// space for raising and lowering priority offset.
explicit constexpr ImportPriority() noexcept
: kind(ImportPriorityKind::Normal), offset(0x7FFFFFFFFFFF) {}
explicit constexpr ImportPriority(ImportPriorityKind kind) noexcept
: kind(kind), offset(0x7FFFFFFFFFFF) {}
constexpr ImportPriority(ImportPriorityKind kind, uint64_t offset) noexcept
: kind(kind), offset(offset) {}
constexpr inline int64_t value() const noexcept {
return (static_cast<int16_t>(kind) * (static_cast<uint64_t>(1) << 48)) +
offset;
}
/**
* Deprioritize ImportPriority by decreasing offset by delta.
* Note: this function maintains ImportPriorityKind, as jobs
* with higher priority kind are usually designed to be scheduled
* ealier and should not lower their kind even when deprioritized.
*/
constexpr ImportPriority getDeprioritized(uint64_t delta) const noexcept {
return ImportPriority{kind, offset > delta ? offset - delta : 0};
}
friend bool operator<(
const ImportPriority& lhs,
const ImportPriority& rhs) noexcept {
return lhs.value() < rhs.value();
}
friend bool operator>(
const ImportPriority& lhs,
const ImportPriority& rhs) noexcept {
return lhs.value() > rhs.value();
}
};
} // namespace facebook::eden