Skip to content
Merged

Style. #1102

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions include/bitcoin/database/define.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

#include <bitcoin/database/error.hpp>

// map is able to support 32 bit, but because the database
// requires a larger file this is neither validated nor supported.
// map supports 32 bit, but as database requires larger file
// this is neither validated nor supported.
////static_assert(sizeof(void*) == sizeof(uint64_t), "Not a 64 bit system!");

namespace libbitcoin {
Expand Down
12 changes: 6 additions & 6 deletions include/bitcoin/database/file/advice.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
namespace libbitcoin {
namespace database {

/// Expected read pattern of mapped storage, guiding kernel page advice. This
/// is independent of the write pattern (structural): bodies are appended
/// sequentially but read randomly by validation, so advising the kernel from
/// the write pattern invites eviction of the read set under memory pressure.
/// Expected read pattern of mapped storage, guiding kernel page advice.
/// Independent of write pattern (structural): bodies appended sequentially but
/// read randomly by validation, so advising kernel from write pattern invites
/// eviction of read set under memory pressure.
enum class advice : uint8_t
{
/// Let the operating system decide (mixed or unpredictable access).
Expand All @@ -40,8 +40,8 @@ enum class advice : uint8_t
sequential,

/// Random access (suppresses read ahead) without preload, for maps too
/// large to reside: scattered reads otherwise fault a full read-ahead
/// window each, and that manufactured cache displaces the head set.
/// large to reside: scattered reads otherwise fault full read-ahead window
/// each, and that manufactured cache displaces head set.
scattered
};

Expand Down
2 changes: 1 addition & 1 deletion include/bitcoin/database/file/rotator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ struct ofstream_wrap
};

/// Simple two file rotating stream with configurable size and file names.
/// Files are rotated after full and writes are contiguous across them.
/// Files rotated after full, writes contiguous across them.
class BCD_API rotator_sink
: public system::device<ofstream_wrap>
{
Expand Down
2 changes: 1 addition & 1 deletion include/bitcoin/database/file/utilities.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ BCD_API code copy_ex(const path& from, const path& to) NOEXCEPT;
BCD_API bool copy_directory(const path& from, const path& to) NOEXCEPT;
BCD_API code copy_directory_ex(const path& from, const path& to) NOEXCEPT;

/// Discharge directory files from the page cache (posix, otherwise no-op),
/// Discharge directory files from page cache (posix, otherwise no-op),
/// synchronizing pending writeback first. False on access/sync error.
BCD_API bool discharge_directory(const path& to) NOEXCEPT;
BCD_API code discharge_directory_ex(const path& to) NOEXCEPT;
Expand Down
41 changes: 20 additions & 21 deletions include/bitcoin/database/impl/memory/mmap.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ namespace database {
// Constructors.
// ----------------------------------------------------------------------------

// A managed head is an unstaged scalar instance under the anonymous model:
// page-tracked, transferred by its worker, released and shared by currency.
// Unstaged aggregates transfer in full, and shared heads map their files.
// Managed head, unstaged scalar instance under anonymous model: page-tracked,
// transferred by its worker, released and shared by currency. Unstaged
// aggregates transfer in full, shared heads map their files.
TEMPLATE
CLASS::mmap(const path& filename, const storage_settings& settings,
bool random, bool staged, bool shared) NOEXCEPT
Expand Down Expand Up @@ -144,15 +144,14 @@ size_t CLASS::to_capacity(size_t required) const NOEXCEPT
return std::max(minimum_, ceilinged_add(required, growth));
}

// Commitment growth target for the capacity slow paths. Unlike to_capacity
// this never floors to the configured minimum: under lazy commitment that
// floor would commit the full provisioning on first growth (the load failure
// this design exists to prevent, moved from create to first touch). Growth is
// chunked to bound slow path frequency, and clamped so that small tables do
// not over-commit (the provisioned file requires no memory until committed).
// The commit chunk is scaled to memory (bounded by commit_chunk), as the
// committed but unused overhang is otherwise up to one full chunk for every
// instance, an outsized share of a small system under memory pressure.
// Commitment growth target for capacity slow paths. Unlike to_capacity, never
// floors to configured minimum: under lazy commitment that floor would commit
// full provisioning on first growth (load failure this design prevents, moved
// from create to first touch). Growth chunked to bound slow path frequency, and
// clamped so small tables do not over-commit (provisioned file requires no
// memory until committed). Commit chunk scaled to memory (bounded by
// commit_chunk), as committed but unused overhang is otherwise up to one full
// chunk per instance, an outsized share of small system under memory pressure.
TEMPLATE
size_t CLASS::to_chunk() NOEXCEPT
{
Expand All @@ -178,20 +177,20 @@ size_t CLASS::to_growth(size_t required) const NOEXCEPT
#endif
}

// Disk provisioning: the configured minimum is a file reservation, ensuring
// that allocation within it cannot fail for space (disk full is detected at
// Disk provisioning: configured minimum is file reservation, ensuring
// allocation within it cannot fail for space (disk full detected at
// provisioning, where it remains recoverable).
TEMPLATE
size_t CLASS::to_provision() const NOEXCEPT
{
return std::max(logical_.load(), minimum_);
}

// Memory commitment follows use, not provisioning. Committing the configured
// Memory commitment follows use, not provisioning. Committing configured
// minimum would demand that much memory (Linux charges the commit) before any
// row is written, failing load on any machine smaller than its store sizing.
// Growth commits in chunks within the standing reservation (no remap), so the
// cost is a syscall per chunk over the life of the store.
// Growth commits in chunks within standing reservation (no remap), so cost is a
// syscall per chunk over life of store.
TEMPLATE
size_t CLASS::to_commitment() const NOEXCEPT
{
Expand All @@ -204,7 +203,7 @@ size_t CLASS::to_commitment() const NOEXCEPT
#endif
}

// The counter chain is the spine of the design (debug assertion only):
// Counter chain is spine of design (debug assertion only):
//
// settled_ <= frontier_ <= logical_ <= capacity_ <= file_
//
Expand All @@ -214,9 +213,9 @@ size_t CLASS::to_commitment() const NOEXCEPT
// capacity: rows claimable (committed memory).
// file: rows provisioned on disk (fallocate extent).
//
// Lower bounds are read first: the lock-free fast path can advance logical_
// concurrently, so stale-low reads of lower bounds cannot falsify the chain,
// while upper bounds only grow under locks held at every call site.
// Lower bounds read first: lock-free fast path can advance logical_
// concurrently, so stale-low reads of lower bounds cannot falsify chain, while
// upper bounds only grow under locks held at every call site.
TEMPLATE
void CLASS::check_invariants_() const NOEXCEPT
{
Expand Down
98 changes: 48 additions & 50 deletions include/bitcoin/database/impl/memory/mmap_body.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,9 @@ bool CLASS::settle_write_(size_t from, size_t to,
// ----------------------------------------------------------------------------
// private

// Convert flushed rows [from, to) to a read-only shared file mapping, page
// floored so the settle boundary page remains anonymous with its settled
// bytes retained. Releases the covered anonymous pages. Failure results in
// unmapped.
// Convert flushed rows [from, to) to read-only shared file mapping, page
// floored so settle boundary page remains anonymous with its settled bytes
// retained. Releases covered anonymous pages. Failure results in unmapped.
TEMPLATE
template <size_t Column>
bool CLASS::settle_(size_t from, size_t to) NOEXCEPT
Expand All @@ -104,11 +103,11 @@ bool CLASS::settle_(size_t from, size_t to) NOEXCEPT
return false;
}

// Demote the settled extent to reclaim-first order: cached for imminent
// re-read (validation follows archival) but reclaimed under pressure
// before active pages and anonymous heads (head residency priority).
// Ample hosts skip demotion: with nothing contesting memory it only
// converts warm cache into re-read faults (see demote_memory).
// Demote settled extent to reclaim-first order: cached for imminent re-read
// (validation follows archival) but reclaimed under pressure before active
// pages and anonymous heads (head residency priority). Ample hosts skip
// demotion: with nothing contesting memory it only converts warm cache into
// re-read faults (see demote_memory).
static const auto ample = system_memory() > demote_memory;
if (!ample && (mmap_cold(address, end - begin) == fail))
{
Expand All @@ -120,9 +119,9 @@ bool CLASS::settle_(size_t from, size_t to) NOEXCEPT
return true;
}

// Revert settled pages at/above rows to committed anonymous memory and
// restore the retained bytes below rows from the file (truncation below the
// settle boundary). Failure results in unmapped.
// Revert settled pages at/above rows to committed anonymous memory and restore
// retained bytes below rows from file (truncation below settle boundary).
// Failure results in unmapped.
TEMPLATE
template <size_t Column>
bool CLASS::unsettle_(size_t rows) NOEXCEPT
Expand Down Expand Up @@ -150,13 +149,13 @@ bool CLASS::unsettle_(size_t rows) NOEXCEPT
return true;
}

// Release cached pages of settled rows [from, to), page floored within the
// Release cached pages of settled rows [from, to), page floored within
// converted read-only mapping (its pages cannot be dirtied, and any pending
// settle write-back is synced by the release). Cost follows residency, so
// re-eviction is idempotent and free. The mapping is unaffected (a later
// read faults the page back from the file). Failure faults the store
// (advisory-class failures have no benign modes) but leaves it mapped, as
// the shared-lock caller cannot tear down under live accessors.
// settle write-back is synced by release). Cost follows residency, so
// re-eviction is idempotent and free. Mapping unaffected (later read
// faults page back from file). Failure faults store (advisory-class
// failures have no benign modes) but leaves it mapped, as shared-lock
// caller cannot tear down under live accessors.
TEMPLATE
template <size_t Column>
bool CLASS::evict_(size_t from, size_t to) NOEXCEPT
Expand All @@ -179,11 +178,11 @@ bool CLASS::evict_(size_t from, size_t to) NOEXCEPT
// ----------------------------------------------------------------------------
// private

// Delay the caller while staging exceeds its memory bound (write throttle).
// Signaled as the worker drains; a fault or worker stop releases the caller
// into the normal allocation path (which fails on fault/unload). The relieved
// state is lock-free for the common (unparked) case; notifiers synchronize on
// throttle_mutex_ so a parked caller cannot miss its signal.
// Delay caller while staging exceeds its memory bound (write throttle).
// Signaled as worker drains; fault or worker stop releases caller into normal
// allocation path (which fails on fault/unload). Relieved state lock-free for
// common (unparked) case; notifiers synchronize on throttle_mutex_ so parked
// caller cannot miss its signal.
TEMPLATE
void CLASS::throttle_() NOEXCEPT
{
Expand All @@ -203,8 +202,8 @@ void CLASS::throttle_() NOEXCEPT
throttle_cv_.wait(throttle_lock, relieved);
}

// Wake throttled callers, synchronized so a parking caller cannot miss the
// signal between its relieved check and its wait.
// Wake throttled callers, synchronized so parking caller cannot miss signal
// between its relieved check and its wait.
TEMPLATE
void CLASS::signal_() NOEXCEPT
{
Expand All @@ -217,15 +216,15 @@ void CLASS::signal_() NOEXCEPT
// ----------------------------------------------------------------------------
// private

// Pressure-paced draining (the windows model): drain intensity follows memory
// conditions, settled pages remain cached, writers delay only at the staging
// memory bound (write throttle), sustained stillness drains the residual (the
// lazy writer) so a quiescent map converges to fully settled.
// Pressure-paced draining (windows model): drain intensity follows memory
// conditions, settled pages remain cached, writers delay only at staging memory
// bound (write throttle), sustained stillness drains residual (lazy writer) so
// quiescent map converges to fully settled.
TEMPLATE
void CLASS::body_run_() NOEXCEPT
{
// Tiers derive from physical memory, pressure and compression occupancy
// (a pressure precursor: the kernel compresses without raising level).
// (pressure precursor: kernel compresses without raising level).
const auto memory = system_memory();
const auto urgent = memory / urgent_factor;
const auto active = memory / active_factor;
Expand Down Expand Up @@ -254,10 +253,10 @@ void CLASS::body_run_() NOEXCEPT
still = (top == mark) ? std::min(add1(still), idle_seconds) : zero;
mark = top;

// Scarcity is read directly: clean cache is reclaimable, so the
// kernel pressure level does not raise while free memory exhausts.
// Once current, reads are not write-ordered, so linux reclaims
// (darwin exhausts its free target without the sweep).
// Scarcity read directly: clean cache is reclaimable, so kernel
// pressure level does not raise while free memory exhausts. Once
// current, reads are not write-ordered, so linux reclaims (darwin
// exhausts its free target without sweep).
#if defined(HAVE_LINUX)
if (!current_.load() && (system_free() < scarce))
#else
Expand Down Expand Up @@ -294,9 +293,9 @@ void CLASS::body_run_() NOEXCEPT
}
}

// Settle up to chunk completed rows: write under the shared remap lock
// (completed extents are immutable, writers proceed), convert under a brief
// exclusive. Durability remains a snapshot property (no sync here).
// Settle up to chunk completed rows: write under shared remap lock (completed
// extents immutable, writers proceed), convert under brief exclusive.
// Durability remains a snapshot property (no sync here).
TEMPLATE
bool CLASS::settle_next_(size_t chunk) NOEXCEPT
{
Expand Down Expand Up @@ -335,13 +334,13 @@ bool CLASS::settle_next_(size_t chunk) NOEXCEPT
return settle_all_(target, sequence{});
}

// Evict up to chunk settled rows under memory scarcity: a wrapping sweep
// from the oldest offset (offset is write age in an append-only body, and
// re-read probability decays with it). Scarcity-driven release keeps the
// machine out of the exhausted-cache regime, where the kernel periodic
// sync walk (cost follows resident pages, not dirty) otherwise degrades
// fault service. A wrong eviction costs one cold read, so the sweep needs
// no precision. Runs under the shared remap lock (readers proceed).
// Evict up to chunk settled rows under memory scarcity: wrapping sweep
// from oldest offset (offset is write age in append-only body, and
// re-read probability decays with it). Scarcity-driven release keeps
// machine out of exhausted-cache regime, where kernel periodic sync
// walk (cost follows resident pages, not dirty) otherwise degrades
// fault service. Wrong eviction costs one cold read, so sweep needs no
// precision. Runs under shared remap lock (readers proceed).
TEMPLATE
bool CLASS::evict_next_(size_t chunk, size_t& cursor) NOEXCEPT
{
Expand All @@ -353,12 +352,11 @@ bool CLASS::evict_next_(size_t chunk, size_t& cursor) NOEXCEPT
// A truncated boundary self-heals here (the cursor clamps to a lap).
const auto end = settled_.load();

// Confine the lap to the recently settled tail: cache holds what was
// just written (and what validation just read), while the body below
// is long evicted, so a full-body lap sweeps unresident rows for most
// of its length and the tail refills faster than the cursor returns.
// A lap can hold no more than physical memory, as nothing else is
// resident to evict.
// Confine lap to recently settled tail: cache holds what was just written
// (and what validation just read), while body below is long evicted, so
// full-body lap sweeps unresident rows for most of its length and tail
// refills faster than cursor returns. Lap can hold no more than physical
// memory, as nothing else is resident to evict.
using namespace system;
const auto span = greater(chunk, limit<size_t>(system_memory() / stride));
const auto floor = (end > span) ? (end - span) : zero;
Expand Down
Loading
Loading