Implementing the threads library with Domains #342
Implementing the threads library with Domains #342abbysmal wants to merge 3 commits intoocaml-multicore:parallel_minor_gcfrom
Conversation
|
Would you be so kind as to add me as a reviewer or an assignee (whatever is the best policy)? |
|
Done @jhwoodyatt. |
|
Some updates regarding the work on this PR: Following #241, and the subsequent work to implement I didn't investigate in detail so far the test results. The CI will likely catch up, but for now my observations are the following for the
The next step for me is to investigate each aforementioned issues. |
|
Thanks for the update @Engil. Do you want one of us to start looking at these issues right now? (asking since the PR is still marked as a draft). |
aade55d to
e315ffb
Compare
|
#346 is now merged. @jhwoodyatt Please let us know if you have specific need (I think you are now correctly set as a reviewer as well), or specific notes about your contribution. :) Have a great day, Edit: |
|
I spent the last few days investigating the failing test cases I mentioned earlier.
This is for the test I could investigate properly under this PR. For updates regarding the current state of this work in the ecosystem, I think one major point still missing is proper signal handling. I will try to reproduce the |
|
One thing that was brought to our attention recently is that there are reasonable industrial use cases where a systhread is spawned per file descriptor. Hence, it is not unreasonable to see 10k threads alive at the same time. This would no longer be possible with this PR since the maximum number of domains alive at the same time is 128. @avsm @jonludlam |
|
One of those use cases might be the XAPI project. Looking at an otherwise fairly idle system with 1 VM running XAPI has 59 threads, and xenopsd has 48, a more busy system will have more. OTOH Dom0 only has 16 vCPUs currently, so if the limit is 128 "concurrently executing OCaml threads" then it wouldn't affect us for a long time (as long as we can actually create >128 threads, without multicore the limit is 1, so 128 would be an improvement) Also there are systems with a large number of cores, e.g. 448 logical CPUs, so it is not unreasonable to expect for someone wanting to use all of that in an application (and future systems may have more). Where does the 128 limit for Domains come from, is there an O(domains)/O(log(domains)) algorithm somewhere? |
|
@edwintorok we're going to implement systhreads as multiple pthreads that service a single domain. The downside of having domains stand-in for systhreads is that a domain is more than just a c stack; it has an associated minor heap. All the domains need to participate in the minor GC as well as the major GC cycling. Hence, after some internal discussion we're going to do #357. This does not have any restriction on the number of systhreads that can be spawned.
128 comes from our minor heap layout for concurrent minor collector [1]. The current parallel minor collector does not have this restriction, but still carries the vestiges of the concurrent collector (which will be removed later). Still the fact that each of the domains will have to synchronize for minor GC and major GC cycling still stands. Hence, #357 is definitely a better idea. |
Thanks so much for looking into this for me! I think I agree. #334 is an important feature that will make a difference in how this change can progress. |
Okay. I have no objection to that. |
|
Closed in favour of #407. |
As previously mentioned on #240, here is a rebase of @jhwoodyatt's implementation of the Thread library in terms of Domains.
Some bits in the rebase are still not perfect, but it is in good enough conditions that the build performs correctly and the testsuite now runs.
@jhwoodyatt
Thank you again for your contribution to Multicore OCaml. We will try our best to review and integrate your contribution as soon as possible to OCaml Multicore main development branch.
As the rebasing work is now in mostly good condition, I will work next on assessing the testsuite results.
I will as well work conjointly on #241, in order to simplify testing this contribution against the wider OCaml ecosystem.
Original message from #240:
This is a request for review and comment on a candidate for implementing the
Threadslibrary in terms of the newDomainand andAtomicmodules in the Multicore OCaml standard library. This change, when combined with my other patch forUnix.systemto not useUnix.forkmakes the stock Dune 1.9.2 package compile and run properly on Multicore OCaml. (Or at least, it did until something in themasterbranch related to Lazy values introduced a regression.)Some caveats are worth noting up front:
Firstly, I've made a half-hearted attempt at introducing this as a third library without overwriting the existing vmthread and systhread implementations. I noticed this decision is visible when trying to compile the ounit external package, so I'm anticipating the need to revisit some of these interoperability concerns.
Secondly, I've tried to improve the assurance of correctness by using the unit tests, but unfortunately, this pull request does not currently pass all of them reliably, and moreover, the only reason it can pass most of them at all is that I inserted a call to
Gc.minorin the blocking section entrance hook. Obviously, that's a suboptimal workaround. Also, theswapchanunit test looks to my eye like it has a concurrency error of its own, and can only pass reliably if the Thread library is expected to have some guarantee about context switches that I don't think it actually promises. In short, I think it only accidentally passes reliably in the mainline monocore distribution.(This introductory message is updated from its previous content.)