Skip to content

ADR-00051: The syscall pool takes jobs by priority, and by wait between high and normal

Field Value
Status accepted
Date 2026-12-01

Context and Problem Statement

The runtime split and async I/O proposal gave Lore a bounded syscall pool for file operations, and ADR-00045 its share of a thread limit. Neither decided the order in which the pool runs its jobs. It ran them from one first-in, first-out queue behind a mutex that every submission and every take locked.

Some jobs hold back more work than others. When lore clone walks the revision tree, a block load stands between the walk and every file in that block. A large file is written as a pipeline of fragment fetches and writes, and cloning ends when the last one is written. With one queue, block loads waited behind the writes of files the walk had already handed out, and large files waited behind small ones until the end. Under many submitters the mutex also convoyed.

In what order should the pool take its jobs, and how does a caller say where a job goes?

Decision Drivers

  • An operation that holds back other work runs first.
  • Neither of two kinds of bulk work starves the other.
  • No lock, one allocation and one clock read per job.
  • The pool keeps its size, its limits and its behaviour: lending, idle hooks, keep-alive, recovery from a refused thread, panics resumed on the awaiter, a dropped task's work run to the end, and PoolStats.
  • Priorities can be tuned again operation by operation, with nothing in lore-io that names a caller.

Considered Options

  • One first-in, first-out queue
  • A top-priority queue taken first, beside one queue for everything else
  • Three priority queues, with a cap on the threads that run high-priority jobs
  • Three priority queues, with a rule on the depths of the high and normal queues
  • Three priority queues, with a rule on the waits of the high and normal queues

Decision Outcome

Chosen option: "Three priority queues, with a rule on the waits of the high and normal queues", because it was the only option that won every measured pair.

The pool has a top, a high and a normal priority queue, each first in, first out, and none takes a lock. A pool thread takes a top-priority job whenever one is queued. Otherwise it takes the oldest normal-priority job once that job has waited more than W times as long as the oldest high-priority job, and the oldest high-priority job until then. W is 24 unless LORE_IO_POOL_WAIT_WEIGHT sets it, from 1 to 100.

A job runs at the higher of two priorities:

  • Its operation's default. A read only looks: it reads, checks or lists, or opens a file to read. It defaults to high, since a write usually waits on a read. A write changes something, and defaults to normal.
  • The scope its future runs in. lore_io::top_priority and lore_io::high_priority lift every job a future submits while it is polled, and lore_io::carry_priority carries the scope into a task spawned inside it.

Priorities order the syscall pool's jobs only. On the uring and iocp backends, positional reads and writes, and on uring syncs, don't go through the pool.

The starting assignment, to be tuned again as measurements show what holds work back:

  • Top: the revision tree's block loads when cloning walks the tree or the dependencies of the files it clones, the loads of the root, of a linked tree's state and root, and of dependency data and paths, and the index loads of the immutable and mutable stores.
  • High: every other read, and the writes of a file larger than one fragment, from its create through each fragment's fetch and write.
  • Normal: every other write.

Consequences

  • Good, because no job takes a lock. Against the mutex-based pool, lore-io's micro-benchmark on Linux ran 1.95 times the jobs per second with 256 submitters and 2.6 times with 16, at 0.65 and 0.71 times the CPU per job, and 1.9 times with one submitter. Jobs of 200 µs ran at the same rate, at 0.94 times the CPU.
  • Good, because moving an operation to another priority changes its default or one call site, and nothing in the pool.
  • Bad, because a queue that takes no lock allocates a block of about 1,000 bytes per 31 jobs: 1.03 allocations per job with one submitter, against 1.00 before, and 1.04 with 256.
  • Bad, because while high-priority jobs are queued, a normal-priority job waits until its wait passes W times that of the oldest of them: 6-7 s at the longest while cloning, against about 1.8 s at high.
  • Bad, because a scope lifts everything its future awaits inline, and doesn't reach a task spawned without carry_priority.
  • Bad, because top has no wait rule. deserialize_all_buckets loads every bucket of a store's index at once, for compaction, garbage collection, verification and the packfile upgrade, and such a pass run while cloning queues all its loads ahead of every high- and normal-priority job. Capping how many run at once is a follow-up.
  • Neutral, because a job is stamped with the time of the latest take rather than a clock read, so its wait can read longer than it was by the time since that take, plus up to about 10 µs, or, for a job submitted while a thread was idle, shorter.

Pros and Cons of the Options

One first-in, first-out queue

  • Good, because it is the simplest.
  • Bad, because block loads wait behind the writes the walk handed out, and large files' writes fall to the end.

A top-priority queue taken first, beside one queue for everything else

  • Good, because block loads no longer wait behind writes.
  • Bad, because cloning took 14.1% longer, with the large files' writes at the end.

Three priority queues, with a cap on the threads that run high-priority jobs

  • Good, because a cap bounds what large files take from small ones.
  • Bad, because no cap won: 4 of 16 threads took 7.2% longer, 8 of 16 0.4% longer, and 16 of 16 12.1% longer.

Three priority queues, with a rule on the depths of the high and normal queues

  • Good, because a queue's depth is known without a clock.
  • Bad, because a queue whose submitters wait on their own jobs stops growing, so either queue can starve without a further guard. Cloning took 9.4-21% longer.

Three priority queues, with a rule on the waits of the high and normal queues

  • Good, because neither queue starves: the wait of a queue no thread takes from keeps growing.
  • Good, because it won every pair, at W of 16, 24 and 32.
  • Bad, because it reads the clock once per job.

More Information

The options were measured cloning test view B (2,828,654 files, 504.56 GiB) on a Windows cloud VM writing to NTFS with 16 pool threads, each arm against a control from the same build, with a cloning order that hands large files out as it walks them. In those builds every read was at normal priority. The wait rule took 2.7% less time on average over four pairs: -3.2% and -0.8% at W of 24, -3.1% at 16 and -3.8% at 32. W of 16 to 32 did not separate, and a higher W lengthened the longest normal-priority wait, from 5.4 s at 16 to 7.1 s at 32. With a cloning order that hands large files out with their directories, the wait rule took 4.0% longer. As built, with reads at high and index loads at top, cloning measured level with the same order without the queues.

Revisit W and the assignment when another platform or filesystem is measured, or when an operation is found to hold back other work.