From: Claude Code Review Bot <claude-review@example.com>
To: dri-devel-reviews@example.com
Subject: Claude review: cgroup/dmem: allow max to be set below current usage
Date: Sun, 22 Mar 2026 04:08:56 +1000 [thread overview]
Message-ID: <review-patch3-20260319-dmem_max_ebusy-v2-3-b5ce97205269@igalia.com> (raw)
In-Reply-To: <20260319-dmem_max_ebusy-v2-3-b5ce97205269@igalia.com>
Patch Review
**Verdict: Good**
The core fix. Replaces:
```c
page_counter_set_max(&pool->cnt, val);
```
with:
```c
xchg(&pool->cnt.max, val);
```
This is correct. Looking at `page_counter_set_max()` in `mm/page_counter.c:197`, it uses an `xchg` internally but wraps it in a loop that returns `-EBUSY` when usage exceeds the new max. The return value was being silently discarded by `set_resource_max()` (which returns `void`), causing the write to appear successful while the limit remained unchanged.
The direct `xchg` unconditionally sets the max, which:
1. Has the correct memory ordering semantics (full barrier, matching what `page_counter_try_charge` expects)
2. Prevents new allocations from exceeding the new limit
3. Matches the intended memcg-like behavior where setting max below usage is allowed
One consideration: `page_counter_set_max` was designed with the read-swap-read pattern to ensure coherency with `page_counter_try_charge`. By doing a bare `xchg` without the subsequent usage check, there's a theoretical window where a concurrent charge could slip through if it read the old (higher) max just before the `xchg`. However, this is the same race that exists in memcg's `memory.max` write path (which also just does `WRITE_ONCE` on the max), and is acceptable — the charge will be caught on the next attempt. This is fine.
---
Generated by Claude Code Patch Reviewer
next prev parent reply other threads:[~2026-03-21 18:08 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-19 21:22 [PATCH v2 0/3] cgroup/dmem: allow atomic irrestrictive writes to dmem.max Thadeu Lima de Souza Cascardo
2026-03-19 21:22 ` [PATCH v2 1/3] cgroup/dmem: remove region parameter from dmemcg_parse_limit Thadeu Lima de Souza Cascardo
2026-03-21 18:08 ` Claude review: " Claude Code Review Bot
2026-03-19 21:22 ` [PATCH v2 2/3] cgroup/dmem: accept a single region when writing to attributes Thadeu Lima de Souza Cascardo
2026-03-21 18:08 ` Claude review: " Claude Code Review Bot
2026-03-19 21:22 ` [PATCH v2 3/3] cgroup/dmem: allow max to be set below current usage Thadeu Lima de Souza Cascardo
2026-03-21 18:08 ` Claude Code Review Bot [this message]
2026-03-21 18:08 ` Claude review: cgroup/dmem: allow atomic irrestrictive writes to dmem.max Claude Code Review Bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=review-patch3-20260319-dmem_max_ebusy-v2-3-b5ce97205269@igalia.com \
--to=claude-review@example.com \
--cc=dri-devel-reviews@example.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox