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
bigarray lacks a free-like call. #6962
Comments
Comment author: @xavierleroy The solution you propose was implemented in 2012 (see #4108), then rolled back because it prevents valuable optimizations (Common Subexpression Elimination) on bounds checks for bigarray accesses. As a matter of fact, there is a risk that the unsafe_destroy function from Bigstring is potentially unsafe with respect to CSE optimization as performed in the OCaml trunk. |
Comment author: toolslive It might be an idea to be able to give a hint to the GC as Another idea is the ability to turn this CSE off for bigarrays. It's not that we really want/need that call, |
Comment author: domsj Another idea would be not needing bigarrays in the first place ... |
Comment author: @alainfrisch
I guess this is not the case today, but it should also be possible to optimize the indirection on the "data" field of big arrays. |
This issue has been open one year with no activity. Consequently, it is being marked with the "stale" label. What this means is that the issue will be automatically closed in 30 days unless more comments are added or the "stale" label is removed. Comments that provide new information on the issue are especially welcome: is it still reproducible? did it appear in other contexts? how critical is it? etc. |
Deallocatable bigarrays is a request that comes up enough, still now, so I think the issue is not stale. Is there any progress on having separate user-defined libraries for this need that bring advantages and get usage in practice? |
The code was there at some point: 5ca6abd The issue is not to have it in a separate user-defined library. The issue is that since 2012 we've been unable to determine whether it is safe w.r.t. current optimizations (CSE, Flambda) and future optimizations we may want to have one day. This demonstrates rather clearly that nobody cares. Closing this report. |
For the record, I don't agree:
So: I think that some people care, but I don't know how to get them involved in the conversation. They are free to post here if find the issue, whether it's open or closed. |
I did some tricks like this a long time ago when mapping GPU memory to CPU via The code is here, but it's in the In any case it seems that in the current incarnation of the library I rely on programmer discipline (what a good idea :-), but the As this example shows there may be many way to get a pointer to a chunk of memory and relinquish it, so I'm not sure the suggestion was a good idea (unless done via a user defined callback). However I would welcome a clarification whether such tricks as done above are allowed or not and/or what is allowed exactly. Personally I'm fine doing these dirty things in C. |
FWIW I'm still interested in knowing that and I think it would be good to mention it here. It may seem like a niche area, but C libraries that temporarily lease you a pointer to work on is not unheard of (e.g. sound or graphics libraries). |
Original bug ID: 6962
Reporter: toolslive
Status: acknowledged (set by @xavierleroy on 2015-08-18T17:16:08Z)
Resolution: open
Priority: normal
Severity: feature
Target version: undecided
Category: standard library
Related to: #4108 #7676
Monitored by: domsj @braibant @diml @ygrek @jmeber @hcarty
Bug description
When you use bigarrays for IO, you find that after you're done using them, they stay around for quite a while before being garbage collected. The part on the OCaml heap is small, but the part on the C-heap can be quite large causing processes grow without limitations.
The simplest solution is to add a call similar to the one Jane street provides in their Bigstring library:
"""
val unsafe_destroy : t -> unit
unsafe_destroy bstr destroys the bigstring by deallocating its associated data or, if memory-mapped, unmapping the corresponding file, and setting all dimensions to zero. This effectively frees the associated memory or address-space resources instantaneously. This feature helps working around a bug in the current OCaml runtime, which does not correctly estimate how aggressively to reclaim such resources.
This operation is safe unless you have passed the bigstring to another thread that is performing operations on it at the same time. Access to the bigstring after this operation will yield array bounds exceptions.
"""
The text was updated successfully, but these errors were encountered: