Skip to content

Comments

Support writing to block devices on MacOS#827

Closed
aaronjeline wants to merge 1 commit intoocaml-multicore:mainfrom
aaronjeline:main
Closed

Support writing to block devices on MacOS#827
aaronjeline wants to merge 1 commit intoocaml-multicore:mainfrom
aaronjeline:main

Conversation

@aaronjeline
Copy link

If we get POLLNVAL, wake all of our readers/writers. MacOS will report POLLNVAL for any block device. Solves #757

Copy link
Collaborator

@talex5 talex5 left a comment

Choose a reason for hiding this comment

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

I assume this means that, if the resource isn't ready, then it will spin? That's not a problem for /dev/null but it might be for other things.

Possibly that's still better than the current behaviour, but needs a comment in the code that it should be improved if it turns out to be a problem.

@aaronjeline
Copy link
Author

aaronjeline commented Jan 9, 2026

but needs a comment in the code that it should be improved if it turns out to be a problem.

Added a note about this.

@talex5
Copy link
Collaborator

talex5 commented Jan 11, 2026

This results in us blocking on block devices

Does it block? I'd expect it to keep trying at 100% CPU instead (since we normally open things as non-blocking, it should get EAGAIN and try to wait again).

I wonder if we should just use select on macOS, since apparently you can avoid the 1024 FD limit there (with _DARWIN_UNLIMITED_SELECT), and I doubt people are using macOS to run e.g. high-performance servers with huge numbers of connections anyway.

Any other mac users have thoughts about this?

@aaronjeline
Copy link
Author

aaronjeline commented Jan 12, 2026

I wonder if we should just use select on macOS

Do you mean just switch from poll() to select() for all files, or keep a separate thread up for monitoring non-pollable files with select.

I believe (2) is what libuv does

@talex5
Copy link
Collaborator

talex5 commented Jan 12, 2026

Either would be fine I think.

Block devices currently did not work on macOS,
due to a bug that prevents poll(2) from working with
block devices. This fixes that by creating a new thread
that monitors block devices using select(2). The thread is
created the first time a user computation attempts to read
or write to a block devices. The implementation of the new
select manager is in select.ml

Additionally, the select manager also needed an eventfd system.
The eventfd system from sched.ml was refactoring into a
re-usable model that encapsulates some of the internal state
in posix_eventfd.ml.
@aaronjeline
Copy link
Author

Latest commits spawns a new thread to handle block devices on macOS. Let me know if you want anything organized differently. Happy to adjust as you'd like.

@talex5 talex5 added the aislop Suspected AI-generated. label Jan 29, 2026
@aaronjeline aaronjeline closed this Feb 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

aislop Suspected AI-generated.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants