From: Alison Schofield <alison.schofield@intel.com>
To: "Gregory Price (Meta)" <gourry@gourry.net>
Cc: <nvdimm@lists.linux.dev>, <linux-cxl@vger.kernel.org>
Subject: Re: [PATCH 3/6] daxctl: offline whole-device memory via atomic unplug when available
Date: Wed, 21 Oct 2026 19:20:38 -0700 [thread overview]
Message-ID: <atly9gd-Rsf-AoqB@aschofie-mobl2.lan> (raw)
In-Reply-To: <20261016214248.443247-4-gourry@gourry.net>
On Fri, Oct 16, 2026 at 05:42:45PM -0400, Gregory Price (Meta) wrote:
> From: Gregory Price <gourry@gourry.net>
>
> When the kernel provides daxX.Y/state, offline by writing 'unplugged'.
> The kernel offlines and removes the whole device atomically, so no
> agent can online blocks before a later unbind. On failure the device
> is left unchanged.
>
> The memory blocks are removed rather than left offline, including
> when they are all offline already; 'daxctl online-memory' restores
> them. If they are all offline and the unplug fails (e.g. no memory
> hotremove support), this remains a no-op.
>
> Unplugging a node's last memory removes its sysfs directory, so treat
> a missing node directory as zero blocks when the device is unplugged.
> 'daxctl list' likewise omits 'movable' for a device with no blocks.
>
> Signed-off-by: Gregory Price <gourry@gourry.net>
> ---
> daxctl/device.c | 51 +++++++++++++++++++++++++++++++++++++++---
> daxctl/json.c | 6 ++++-
> daxctl/lib/libdaxctl.c | 12 ++++++++--
> 3 files changed, 63 insertions(+), 6 deletions(-)
>
> diff --git a/daxctl/device.c b/daxctl/device.c
> index fd84799..99c0d96 100644
> --- a/daxctl/device.c
> +++ b/daxctl/device.c
> @@ -694,7 +694,8 @@ static int dev_offline_memory(struct daxctl_dev *dev)
> {
> struct daxctl_memory *mem = daxctl_dev_get_memory(dev);
> const char *devname = daxctl_dev_get_devname(dev);
> - int num_sections, num_on, num_off, rc;
> + int num_sections, num_on, num_off, rc, unplug;
> + enum daxctl_kmem_state state;
>
> if (!mem) {
> fprintf(stderr, "%s: failed to get the memory object\n",
> @@ -717,17 +718,61 @@ static int dev_offline_memory(struct daxctl_dev *dev)
> return num_on;
> }
>
> + /*
> + * Unplug atomically where supported, even if already offline, so
> + * no agent can online blocks before a later unbind.
> + */
> + state = daxctl_dev_get_kmem_state(dev);
> + unplug = state != DAXCTL_KMEM_UNKNOWN && state != DAXCTL_KMEM_UNPLUGGED;
> +
Hi Greg,
I see you called this out in the cover letter, and that the kernel is
deliberately combining offlining and removing memory to avoid the race
before unbind.
But, this does change the behavior of the command "daxctl offline-memory".
Previously it left memory blocks present but offline and now it removes
them entirely.
Should offline-memory keep its existing behavior of leaving memory blocks
offline, and use atomic unplug only when reconfiguring the device?
> num_off = num_sections - num_on;
> - if (num_off == num_sections) {
> + if (num_off == num_sections && !unplug) {
> fprintf(stderr, "%s: all memory sections (%d) already offline\n",
> devname, num_off);
> return 1;
> }
> - if (num_off)
> + if (num_off && num_on)
> fprintf(stderr, "%s: %d memory section%s already offline\n",
> devname, num_off,
> num_off == 1 ? "" : "s");
>
> + if (unplug) {
> + rc = daxctl_dev_set_kmem_state(dev, DAXCTL_KMEM_UNPLUGGED);
> + if (rc < 0 && num_on == 0) {
> + /* already offline, unplug is best effort */
When num_on == 0, another agent could online a block between the earlier
check and the unplug and that memory would then be removed.
I see this noted in the commit message. Is that worth documenting for
users?
-- Alison
next prev parent reply other threads:[~2026-10-22 2:21 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-16 21:42 [PATCH 0/6] daxctl: use dax kmem atomic whole-device hotplug Gregory Price (Meta)
2026-10-16 21:42 ` [PATCH 1/6] libdaxctl: add dax kmem atomic hotplug state accessors Gregory Price (Meta)
2026-10-22 2:01 ` Alison Schofield
2026-10-16 21:42 ` [PATCH 2/6] daxctl: online whole-device memory atomically when available Gregory Price (Meta)
2026-10-22 2:12 ` Alison Schofield
2026-10-22 16:40 ` Gregory Price (Meta)
2026-10-16 21:42 ` [PATCH 3/6] daxctl: offline whole-device memory via atomic unplug " Gregory Price (Meta)
2026-10-22 2:20 ` Alison Schofield [this message]
2026-10-22 16:46 ` Gregory Price (Meta)
2026-10-22 22:00 ` Alison Schofield
2026-10-23 1:48 ` Gregory Price (Meta)
2026-10-23 1:56 ` Gregory Price (Meta)
2026-10-16 21:42 ` [PATCH 4/6] daxctl: report whole-device hotplug state in 'daxctl list' Gregory Price (Meta)
2026-10-22 2:21 ` Alison Schofield
2026-10-16 21:42 ` [PATCH 5/6] Documentation: describe atomic whole-device hotplug in daxctl man pages Gregory Price (Meta)
2026-10-22 2:23 ` Alison Schofield
2026-10-22 16:47 ` Gregory Price (Meta)
2026-10-16 21:42 ` [PATCH 6/6] test/daxctl-devices.sh: cycle offline/online to cover unplug and replug Gregory Price (Meta)
2026-10-22 2:34 ` Alison Schofield
2026-10-22 16:49 ` Gregory Price (Meta)
2026-10-22 1:59 ` [PATCH 0/6] daxctl: use dax kmem atomic whole-device hotplug Alison Schofield
2026-10-22 16:30 ` Gregory Price (Meta)
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=atly9gd-Rsf-AoqB@aschofie-mobl2.lan \
--to=alison.schofield@intel.com \
--cc=gourry@gourry.net \
--cc=linux-cxl@vger.kernel.org \
--cc=nvdimm@lists.linux.dev \
/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