Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update disk.hpp - Flush disk cache instantly to avoid stuck in Windows #226

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

zhaoyangwx
Copy link

@zhaoyangwx zhaoyangwx commented May 2, 2021

Avoid stuck in windows disk cache when plotting in parallel using a bunch of disks as cache respectively for each task.

@zhaoyangwx zhaoyangwx changed the title Update disk.hpp Update disk.hpp - Flush disk cache instantly to avoid stuck in Windows May 2, 2021
@hoffmang9
Copy link
Member

GitHub has a new process that requires a team member to trigger Actions. They are now running.

src/disk.hpp Outdated
@@ -201,6 +206,9 @@ struct FileDisk {
}
amtwritten =
::fwrite(reinterpret_cast<const char *>(memcache), sizeof(uint8_t), length, f_);
#ifdef _WIN32
_commit(_fileno(f_));
Copy link
Contributor

Choose a reason for hiding this comment

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

it's not obvious that this is an improvement. This will block until the bytes have made it to the disk, right?
Could you provide some explanation of the symptom you're experiencing that this solves?
Ideally it would be explained in a comment here as well, to let future readers of the code understand why this call is here

Copy link
Author

Choose a reason for hiding this comment

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

The symptom is seen in Chia-Network/chia-blockchain#2337

Copy link
Contributor

Choose a reason for hiding this comment

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

could you provide measurements demonstrating the improvement with this patch?

Copy link
Contributor

Choose a reason for hiding this comment

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

the reason I feel cautious about this is that you really want disk writes to happen in parallel with your program executing, which means sticking the data in kernel buffers that are flushed to disk at some later time, while the program keeps running. As far as I can tell, this will effectively stop the program to wait for the data to make it all the way down to the platter (presumably surviving a power outage).

Generally, you save a lot of time to keep running instead.

Copy link
Contributor

Choose a reason for hiding this comment

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

the documentation doesn't actually say whether the call blocks until the data has been flushed or not.

#ifdef _WIN32
// Flush Windows Cache after few cycles
flush_cyclecount += 1;
if (flush_cyclecount >= flush_cyclelimit){
Copy link
Contributor

Choose a reason for hiding this comment

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

This makes more sense. However, if this turns out to give some people worse performance, they really should have a configuration option to disable it or change this limit.

The limit should probably be specified in number-of-bytes written to the file too.

@github-actions
Copy link

'This PR has been flagged as stale due to no activity for over 60
days. It will not be automatically closed, but it has been given
a stale-pr label and should be manually reviewed.'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants