{"action":"created","issue":{"url":"https://api.github.com/repos/ocaml/ocaml/issues/1738","repository_url":"https://api.github.com/repos/ocaml/ocaml","labels_url":"https://api.github.com/repos/ocaml/ocaml/issues/1738/labels{/name}","comments_url":"https://api.github.com/repos/ocaml/ocaml/issues/1738/comments","events_url":"https://api.github.com/repos/ocaml/ocaml/issues/1738/events","html_url":"https://github.com/ocaml/ocaml/pull/1738","id":317670439,"number":1738,"title":"Add caml_alloc_custom_mem","user":{"login":"damiendoligez","id":19104,"avatar_url":"https://avatars2.githubusercontent.com/u/19104?v=4","gravatar_id":"","url":"https://api.github.com/users/damiendoligez","html_url":"https://github.com/damiendoligez","followers_url":"https://api.github.com/users/damiendoligez/followers","following_url":"https://api.github.com/users/damiendoligez/following{/other_user}","gists_url":"https://api.github.com/users/damiendoligez/gists{/gist_id}","starred_url":"https://api.github.com/users/damiendoligez/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/damiendoligez/subscriptions","organizations_url":"https://api.github.com/users/damiendoligez/orgs","repos_url":"https://api.github.com/users/damiendoligez/repos","events_url":"https://api.github.com/users/damiendoligez/events{/privacy}","received_events_url":"https://api.github.com/users/damiendoligez/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":8,"created_at":"2018-04-25T15:06:34Z","updated_at":"2018-05-11T11:02:38Z","closed_at":null,"author_association":"OWNER","pull_request":{"url":"https://api.github.com/repos/ocaml/ocaml/pulls/1738","html_url":"https://github.com/ocaml/ocaml/pull/1738","diff_url":"https://github.com/ocaml/ocaml/pull/1738.diff","patch_url":"https://github.com/ocaml/ocaml/pull/1738.patch"},"body":"This PR is related to #1476 and [MPR#7750](https://caml.inria.fr/mantis/view.php?id=7750).\r\n\r\nIt adds one function to the runtime and three new GC parameters.\r\n\r\nThe function (`caml_alloc_custom_mem`) is to be used by C code to allocate custom objects that consist of a small block in the heap pointing to a large amount of memory outside the heap (typically allocated with `malloc`). This function takes only one size parameter, the number of bytes of memory outside the heap used by this custom block.\r\n\r\nThe user can then control how much of this memory is retained by dead blocks because the GC does not immediately collect dead blocks (\"floating garbage\"). This is done with three new GC parameters:\r\n\r\n* `M` `custom_major_ratio` This is a percentage relative to the major heap size. A complete GC cycle will be done every time 2/3 of that much memory is allocated for blocks in the major heap. Assuming constant allocation and deallocation rates, this means there are at most (M/100 * major-heap-size) bytes of floating garbage at any time. The factor of 2/3 (or 1.5) is (roughly speaking) because the major GC takes 1.5 cycles (previous cycle + marking phase) before it starts to deallocate dead blocks allocated during the previous cycle.\r\n\r\n* `m` `custom_minor_ratio` This is a percentage relative to the minor heap size. A minor GC will be forced when the memory allocated for blocks in the minor heap reaches this value.\r\n\r\n* `n` `custom_minor_max_size` This is a number of bytes. Blocks allocated in the minor heap that are over this size are assumed to be long-lived and counted immediately against the major heap rather than the minor heap. This is to avoid large allocations forcing a minor GC every time.\r\n\r\nThe function is then used to allocate bigarrays, allowing us to get rid of the infamous `CAML_BA_MAX_MEMORY` constant.\r\n\r\nWhen applied to the test program of [MPR#7750](https://caml.inria.fr/mantis/view.php?id=7750), the results are pretty good: we can make the process size vary from about 6GB (with M=10) to 15 GB (with M=100) to 25 GB (with M=200).\r\n\r\n**needs to be done**: documentation"},"comment":{"url":"https://api.github.com/repos/ocaml/ocaml/issues/comments/388332798","html_url":"https://github.com/ocaml/ocaml/pull/1738#issuecomment-388332798","issue_url":"https://api.github.com/repos/ocaml/ocaml/issues/1738","id":388332798,"user":{"login":"alainfrisch","id":3305274,"avatar_url":"https://avatars0.githubusercontent.com/u/3305274?v=4","gravatar_id":"","url":"https://api.github.com/users/alainfrisch","html_url":"https://github.com/alainfrisch","followers_url":"https://api.github.com/users/alainfrisch/followers","following_url":"https://api.github.com/users/alainfrisch/following{/other_user}","gists_url":"https://api.github.com/users/alainfrisch/gists{/gist_id}","starred_url":"https://api.github.com/users/alainfrisch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alainfrisch/subscriptions","organizations_url":"https://api.github.com/users/alainfrisch/orgs","repos_url":"https://api.github.com/users/alainfrisch/repos","events_url":"https://api.github.com/users/alainfrisch/events{/privacy}","received_events_url":"https://api.github.com/users/alainfrisch/received_events","type":"User","site_admin":false},"created_at":"2018-05-11T11:02:38Z","updated_at":"2018-05-11T11:02:38Z","author_association":"CONTRIBUTOR","body":"@damiendoligez Should this new API also be used for i/o channels?"}}
{"actor":{"display_login":"alainfrisch"}}