Skip to content

Add a file-backed DiskBuffer - #1195

Draft
nirandaperera wants to merge 2 commits into
rapidsai:mainfrom
nirandaperera:disk-buffer-impl
Draft

Add a file-backed DiskBuffer#1195
nirandaperera wants to merge 2 commits into
rapidsai:mainfrom
nirandaperera:disk-buffer-impl

Conversation

@nirandaperera

@nirandaperera nirandaperera commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

DiskResource could read and write files, but nothing owned a backing file or moved a Buffer to and from disk. This adds DiskBuffer as a move-only, file-backed handle outside the MemoryType taxonomy, owned through unique_ptr.

  • Spill with from_buffer and restore with restore; both block until the transfer finishes and delete the file when the handle is released.
  • Have BufferResource own a shared_ptr<DiskResource> so disk handles can outlive the buffer resource, and allocate unique spill paths under its directory.
  • Cover round-trip, ownership, cleanup, reservation errors, and directory wiring in disk tests.

Closes #1184
Depends on #1193 #1186
Related #1170

Signed-off-by: niranda perera <niranda.perera@gmail.com>
@nirandaperera nirandaperera self-assigned this Sep 3, 2026
@nirandaperera nirandaperera added improvement Improves an existing functionality non-breaking Introduces a non-breaking change labels Sep 3, 2026
@copy-pr-bot

copy-pr-bot Bot commented Sep 3, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@nirandaperera nirandaperera changed the title Add a file-backed DiskBuffer handle Add a file-backed DiskBuffer Sep 3, 2026
Comment on lines +38 to +39
* Transfers ownership of the backing file. The moved-from object is empty
* (`path()` is empty and `size()` is zero).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
* Transfers ownership of the backing file. The moved-from object is empty
* (`path()` is empty and `size()` is zero).
* Transfers ownership of the backing file.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Seems unnecessarily verbose docstring for a mover.

Comment on lines +103 to +104
* @param reservation Memory reservation covering at least `source->size()`
* bytes.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why at least, and not exactly?

Comment on lines +61 to +65
RAPIDSMPF_EXPECTS(
source->is_latest_write_done(),
"cannot write buffer to disk with pending stream-ordered writes",
std::logic_error
);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could we validate source->is_latest_write_done() before calling create_unique_path()? As written, a buffer with pending stream-ordered writes throws here after path has already been created, and thus not cleaned.

Comment on lines +55 to +58
* @note This is a point-in-time check and is subject to TOCTOU races:
* another thread may call `get()` after this returns `true`. Like
* `std::future`, concurrent `is_ready()`/`get()` from multiple
* threads is undefined behavior.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
* @note This is a point-in-time check and is subject to TOCTOU races:
* another thread may call `get()` after this returns `true`. Like
* `std::future`, concurrent `is_ready()`/`get()` from multiple
* threads is undefined behavior.
* @note This is a point-in-time check and is subject to TOCTOU races:
* another thread may call `get()` after this returns `true`. Like
* `std::future`, concurrent `is_ready()`/`get()` from multiple
* threads is undefined behavior.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Style.

Comment on lines +66 to +70
* @return Number of bytes transferred. The caller must check this against
* the requested size.
*
* @note Like `std::future::get()`, this is not thread-safe. Calling get()
* concurrently from multiple threads is undefined behavior.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
* @return Number of bytes transferred. The caller must check this against
* the requested size.
*
* @note Like `std::future::get()`, this is not thread-safe. Calling get()
* concurrently from multiple threads is undefined behavior.
* @return Number of bytes transferred. The caller must check this against
* the requested size.
*
* @note Like `std::future::get()`, this is not thread-safe. Calling get()
* concurrently from multiple threads is undefined behavior.

* `std::future`, concurrent `is_ready()`/`get()` from multiple
* threads is undefined behavior.
*/
[[nodiscard]] virtual bool is_ready() const = 0;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This seems to have been added by this PR (not included in #1186 that introduced this class) and is only used by DiskFutureIsReadyBeforeGet, do we really need it just to satisfy testing?

Comment on lines +56 to +58
RAPIDSMPF_EXPECTS(
disk_resource_ != nullptr, "the disk resource pointer cannot be NULL"
);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why not? Isn't that effectively forcing us to enable disk spilling, even when that's not wanted?

Comment on lines +84 to +87
// create a dir for each pid under the spill directory
std::shared_ptr<disk::DiskResource> disk_res{
new disk::DiskResource{std::move(spill_directory) / std::to_string(::getpid())}
};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

And also forcing creating a spilling directory?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

improvement Improves an existing functionality non-breaking Introduces a non-breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a disk buffer

2 participants