Skip to content

Comments

pkg/atomicwriter: use sequential file access on Windows#49608

Merged
thaJeztah merged 1 commit intomoby:masterfrom
thaJeztah:atomicwriter_sequential
Mar 31, 2025
Merged

pkg/atomicwriter: use sequential file access on Windows#49608
thaJeztah merged 1 commit intomoby:masterfrom
thaJeztah:atomicwriter_sequential

Conversation

@thaJeztah
Copy link
Member

pkg/atomicwriter: use sequential file access on Windows

Using sequential file access (FILE_FLAG_SEQUENTIAL_SCAN) prevents
Windows from aggressively keeping files in the cache, freeing up system
memory for other tasks. On Linux, these changes have no effect, as the
sequential package use the standard (os.CreateTemp, os.OpenFile) on
non-Windows platforms. Refer to the Win32 API documentation for details
on sequential file access.

- Human readable description for the release notes

- A picture of a cute animal (not mandatory but encouraged)

@thaJeztah
Copy link
Member Author

thaJeztah commented Mar 9, 2025

Opened this for discussion; not 100% sure if there would be cases where we would not want to use this. If that's the case, we could consider adding a NewSequential and WriteSet.SequentialFileWriter function / method, and keep the old ones as-is. (or a NewSequentialWriteSet)

Using sequential file access ([FILE_FLAG_SEQUENTIAL_SCAN]) prevents
Windows from aggressively keeping files in the cache, freeing up system
memory for other tasks. On Linux, these changes have no effect, as the
sequential package use the standard (os.CreateTemp, os.OpenFile) on
non-Windows platforms. Refer to the [Win32 API documentation] for details
on sequential file access.

[Win32 API documentation]: https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilea#FILE_FLAG_SEQUENTIAL_SCAN
[FILE_FLAG_SEQUENTIAL_SCAN]: https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilea#FILE_FLAG_SEQUENTIAL_SCAN

Signed-off-by: Sebastiaan van Stijn <[email protected]>
@thaJeztah thaJeztah force-pushed the atomicwriter_sequential branch from 305c3b8 to be6e92a Compare March 21, 2025 15:39
@thaJeztah thaJeztah added platform/windows status/2-code-review kind/enhancement Enhancements are not bugs or new features but can improve usability or performance. labels Mar 21, 2025
@thaJeztah thaJeztah marked this pull request as ready for review March 21, 2025 15:44
@vvoland vvoland added this to the 28.0.4 milestone Mar 25, 2025
@thaJeztah
Copy link
Member Author

Could use some input from our Windows-native friends on this one /cc @CharityKathure @profnandaa

Let me do a quick outline of my thoughts;

  • ❓ First of all; question is if the benefits of using sequential files are worth making this change; I implemented this, based on some existing uses elsewhere, but I'm not sure exactly what's best to measure if it's relevant or if it's pre-mature optimization
  • ☝️ I tried to get some input from ChatGPT to see if it could tell if it's mostly relevant for "large files" or "small files", and what kind of patterns most benefit. I think it came down to "it can be relevant for files only used once / temporarily" (which makes sense).

The reason I opened this PR was because I wanted to replace some code in docker/cli with our atomicwriter package; see docker/cli#5914

  • ☝️ that code is used to save/export images, which could be large files (and possibly only written to as a temporary file)
  • 👉 inside moby/moby, the code is used in quite some places, including to write the container's config / state to disk (so different pattern; would that be a "pro" or "con" for this?)
  • ❓ from that perspective, would it make sense to have separate methods? (NewSequential / NewSequentialWriteSet)

In general, I'm playing with the idea to move this package to a separate module in the https://github.com/moby/sys repo (i.e., to become github.com/moby/sys/atomicwriter). The downside of using the sequential package is that this would mean we'd have a cross-module dependency; not disastrous, but sometimes makes it slightly more complicated to work with.

@vvoland vvoland modified the milestones: 28.0.4, 28.0.5 Mar 25, 2025
@thaJeztah
Copy link
Member Author

This PR was discussed in the maintainer call last Thursday;

  • We discussed whether we should use Sequential file by default, and concluded that it won't hurt to do so by default; if it doesn't benefit, it also won't hurt for how we're using these.
  • We discussed potentially moving this package to moby/sys, and maintainers were ok doing so; this will be looked at separately.

Let me bring this one in 👍

@thaJeztah thaJeztah merged commit b528035 into moby:master Mar 31, 2025
158 checks passed
@thaJeztah thaJeztah deleted the atomicwriter_sequential branch March 31, 2025 16:11
@thompson-shaun thompson-shaun modified the milestones: 28.0.5, 28.1.0 Apr 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/enhancement Enhancements are not bugs or new features but can improve usability or performance. platform/windows status/2-code-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants