Skip to content

iocost: add cost.boost cgroup interface - #2176

Open
ecjtusbs wants to merge 1 commit into
deepin-community:linux-6.18.yfrom
ecjtusbs:linux-6.18.y
Open

ecjtusbs wants to merge 1 commit into
deepin-community:linux-6.18.yfrom
ecjtusbs:linux-6.18.y

Conversation

@ecjtusbs

@ecjtusbs ecjtusbs commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Introduce a new per-cgroup file "cost.boost" that allows temporarily boosting an io.cost cgroup. Writing a duration in microseconds to the file enables boost mode for that cgroup. When a cgroup is boosted, iocost skips surplus evaluation for it and restores its inuse weight to active, ensuring the boosted cgroup keeps its full IO share during the boost period.

Summary by Sourcery

Add temporary per-cgroup IO cost boosting through the new cost.boost interface.

New Features:

  • Add a per-cgroup cost.boost interface for temporarily preserving a cgroup’s full IO share for a specified duration.

Enhancements:

  • Limit boost durations to one minute and report the remaining boost time through the cgroup interface.

Introduce a new per-cgroup file "cost.boost" that allows temporarily
boosting an io.cost cgroup.  Writing a duration in microseconds to the
file enables boost mode for that cgroup.  When a cgroup is boosted,
iocost skips surplus evaluation for it and restores its inuse weight
to active, ensuring the boosted cgroup keeps its full IO share during
the boost period.

Signed-off-by: ecjtusbs <ecjtusbs@foxmail.com>
@sourcery-ai

sourcery-ai Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Introduces a non-root cost.boost interface that accepts a bounded duration in microseconds, tracks the boost with a deadline, and modifies the iocost timer path to preserve the cgroup’s active IO weight while boosting.

Sequence diagram for the cost.boost cgroup interface

sequenceDiagram
    actor User
    participant CgroupFS
    participant Iocost
    participant IocostTimer

    User->>CgroupFS: write cost.boost duration_us
    CgroupFS->>Iocost: ioc_boost_write(buf)
    Iocost->>Iocost: kstrtou64(strim(buf), 10, duration_us)
    alt duration_us > MAX_BOOST_US
        Iocost-->>CgroupFS: -EINVAL
    else duration_us == 0
        Iocost->>Iocost: WRITE_ONCE(boost_deadline, 0)
        Iocost-->>CgroupFS: nbytes
    else valid duration
        Iocost->>Iocost: WRITE_ONCE(boost_deadline, deadline)
        Iocost-->>CgroupFS: nbytes
    end

    IocostTimer->>Iocost: ioc_timer_fn()
    Iocost->>Iocost: READ_ONCE(boost_deadline)
    alt boost_deadline > now
        Iocost->>Iocost: __propagate_weights(iocg, active, active, true, now)
        Iocost-->>IocostTimer: skip surplus evaluation
    else boost expired
        Iocost->>Iocost: surplus evaluation
    end
Loading

File-Level Changes

Change Details Files
Add a bounded per-cgroup boost control with duration-based state tracking and visibility.
  • Expose a non-root cost.boost cgroup file.
  • Parse boost durations in microseconds, reject values above 60 seconds, and support zero to disable boosting.
  • Store a monotonic-nanosecond deadline and report remaining microseconds when read.
block/blk-iocost.c
Integrate boost state into iocost weight evaluation so boosted cgroups retain their active IO share.
  • Skip surplus evaluation while the boost deadline is active.
  • Restore inuse to active weights when needed, unless virtual debt prevents propagation.
  • Use lockless deadline reads for timer-path coordination with cgroup file writes.
block/blk-iocost.c

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign mingcongbai for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 3 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="block/blk-iocost.c" line_range="2321-2324" />
<code_context>

+		/* skip surplus evaluation if this cgroup is boosted */
+		{
+			struct blkcg_gq *blkg = iocg_to_blkg(iocg);
+			struct ioc_cgrp *iocc = blkcg_to_iocc(blkg->blkcg);
+
+			if (READ_ONCE(iocc->boost_deadline) > now.now_ns) {
+				if (iocg->inuse != iocg->active &&
+				    !iocg->abs_vdebt) {
</code_context>
<issue_to_address>
**Parent boosts miss descendant IO**

When a non-root cgroup with active descendants is boosted, `ioc_timer_fn` checks only each active leaf’s own cgroup deadline, so it never applies the parent’s boost to its descendants and their IO shares remain unboosted.

Have timer evaluation apply ancestor boost deadlines to active descendants.
</issue_to_address>

### Comment 2
<location path="block/blk-iocost.c" line_range="3562" />
<code_context>
+	if (duration_us == 0) {
+		WRITE_ONCE(iocc->boost_deadline, 0);
+	} else {
+		u64 deadline = ktime_get_ns() + duration_us * NSEC_PER_USEC;
+
+		WRITE_ONCE(iocc->boost_deadline, deadline);
</code_context>
<issue_to_address>
**Short boosts have no effect**

When the requested duration expires before the next periodic timer evaluation, the write stores only a deadline, and the timer applies the boost only when it observes that deadline; if it misses the interval, the cgroup’s weight is not restored during the boost and the requested share change has no effect.

Apply the boost when it is written or guarantee a timer evaluation before it expires.

Also at `block/blk-iocost.c:2324-2333`, `block/blk-iocost.c:3564`.
</issue_to_address>

### Comment 3
<location path="block/blk-iocost.c" line_range="3590" />
<code_context>
 		.write = ioc_cost_model_write,
 	},
+	{
+		.name = "cost.boost",
+		.flags = CFTYPE_NOT_ON_ROOT,
+		.seq_show = ioc_boost_show,
</code_context>
<issue_to_address>
**Boost interface is undocumented**

When operators consult the cgroup-v2 reference for the new file’s behavior, the cgroup-v2 reference documents `io.cost.qos` and `io.cost.model` at lines 1990–2085 but has no `io.cost.boost` entry, so operators cannot find the file’s microsecond input, one-minute limit, or remaining-time output in the kernel interface documentation.

Add an `io.cost.boost` entry to the cgroup-v2 reference describing its duration input, limit, and readback semantics.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread block/blk-iocost.c
Comment on lines +2321 to +2324
struct blkcg_gq *blkg = iocg_to_blkg(iocg);
struct ioc_cgrp *iocc = blkcg_to_iocc(blkg->blkcg);

if (READ_ONCE(iocc->boost_deadline) > now.now_ns) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 High · Parent boosts miss descendant IO

When a non-root cgroup with active descendants is boosted, ioc_timer_fn checks only each active leaf’s own cgroup deadline, so it never applies the parent’s boost to its descendants and their IO shares remain unboosted.

Have timer evaluation apply ancestor boost deadlines to active descendants.

Prompt for AI agents
In `block/blk-iocost.c` at lines 2321-2324:

**Parent boosts miss descendant IO**

When a non-root cgroup with active descendants is boosted, `ioc_timer_fn` checks only each active leaf’s own cgroup deadline, so it never applies the parent’s boost to its descendants and their IO shares remain unboosted.

Have timer evaluation apply ancestor boost deadlines to active descendants.

Comment thread block/blk-iocost.c
if (duration_us == 0) {
WRITE_ONCE(iocc->boost_deadline, 0);
} else {
u64 deadline = ktime_get_ns() + duration_us * NSEC_PER_USEC;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Short boosts have no effect

When the requested duration expires before the next periodic timer evaluation, the write stores only a deadline, and the timer applies the boost only when it observes that deadline; if it misses the interval, the cgroup’s weight is not restored during the boost and the requested share change has no effect.

Apply the boost when it is written or guarantee a timer evaluation before it expires.

Also at block/blk-iocost.c:2324-2333, block/blk-iocost.c:3564.

Prompt for AI agents
In `block/blk-iocost.c` at line 3562:

**Short boosts have no effect**

When the requested duration expires before the next periodic timer evaluation, the write stores only a deadline, and the timer applies the boost only when it observes that deadline; if it misses the interval, the cgroup’s weight is not restored during the boost and the requested share change has no effect.

Apply the boost when it is written or guarantee a timer evaluation before it expires.

Also at `block/blk-iocost.c:2324-2333`, `block/blk-iocost.c:3564`.

Comment thread block/blk-iocost.c
.write = ioc_cost_model_write,
},
{
.name = "cost.boost",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚪ Low · Boost interface is undocumented

When operators consult the cgroup-v2 reference for the new file’s behavior, the cgroup-v2 reference documents io.cost.qos and io.cost.model at lines 1990–2085 but has no io.cost.boost entry, so operators cannot find the file’s microsecond input, one-minute limit, or remaining-time output in the kernel interface documentation.

Add an io.cost.boost entry to the cgroup-v2 reference describing its duration input, limit, and readback semantics.

Prompt for AI agents
In `block/blk-iocost.c` at line 3590:

**Boost interface is undocumented**

When operators consult the cgroup-v2 reference for the new file’s behavior, the cgroup-v2 reference documents `io.cost.qos` and `io.cost.model` at lines 1990–2085 but has no `io.cost.boost` entry, so operators cannot find the file’s microsecond input, one-minute limit, or remaining-time output in the kernel interface documentation.

Add an `io.cost.boost` entry to the cgroup-v2 reference describing its duration input, limit, and readback semantics.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Concurrency, hierarchy, timer-granularity, and missing ABI documentation issues must be addressed.

4 open findings
What changed in this PR

Adds temporary per-cgroup I/O-cost boosting to preserve full I/O share.

Changes:

  • Adds bounded boost duration and remaining-time reporting.
  • Skips surplus donation and restores active weight while boosted.
File Description
block/​blk-iocost.c Implements the io.cost.boost cgroup interface and boost behavior.

🧠 Review effort: Balanced


Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.

Comment thread block/blk-iocost.c
struct ioc_cgrp {
struct blkcg_policy_data cpd;
unsigned int dfl_weight;
u64 boost_deadline;
Comment thread block/blk-iocost.c
Comment on lines +2321 to +2324
struct blkcg_gq *blkg = iocg_to_blkg(iocg);
struct ioc_cgrp *iocc = blkcg_to_iocc(blkg->blkcg);

if (READ_ONCE(iocc->boost_deadline) > now.now_ns) {
Comment thread block/blk-iocost.c
Comment on lines +3562 to +3564
u64 deadline = ktime_get_ns() + duration_us * NSEC_PER_USEC;

WRITE_ONCE(iocc->boost_deadline, deadline);
Comment thread block/blk-iocost.c
Comment on lines +3590 to +3593
.name = "cost.boost",
.flags = CFTYPE_NOT_ON_ROOT,
.seq_show = ioc_boost_show,
.write = ioc_boost_write,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants