[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v1 7/7] tools/ocaml/libs/eventchn: do not leak event channels and OCaml 5.0 compat


  • To: Edwin Torok <edvin.torok@xxxxxxxxxx>
  • From: Andrew Cooper <Andrew.Cooper3@xxxxxxxxxx>
  • Date: Mon, 8 Aug 2022 09:59:14 +0000
  • Accept-language: en-GB, en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=4KdswnCGNoBj46tV+m2UQug6LHCAU7u2DJfoAWjJgcs=; b=PcnCDz2+m94he09xCcvGCtC0mAUN5aUJlCirE9KKqYVcL93zP8KnOD1zPQMFDhJyySas41fQBOXhsjnYg3zJLW8jI5wpJHgSY1l3LQ1uJ8NY+yVFVMLc0Eztrvx1dSS2twKAvEYW8LwNUn8l0db40jHgKfjYu8Eext9F1KWtRJN9ZdGxaCiR3gQlkaNftfAzNXSdT6R4L8ONv2SWh6FWrcfpSlgWUESXS3eNZ33OsoLk1JdfUs98NggCGDAnGHs9TUNrH+CFHH6zdhqLj65k7+205qHab5BmusrMmuYBO3scXEXSCjYuKnW0IG9LpkGhTD3ZzS8yGkkjDSjvsasASA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MJVWnVt96AYlPRV1GZ96M5fcEUkvl4JCD3jkZffuWXvoUZwsQo4sAdVzF3aY2E/AeyNMFOxLoQ7MXVm2ZW9gsZIZEeyxkSB53JYPcE3wTfK3KQUB1ofPDwL4oYytugd6osjP+3tMEsrpDMJC8gyVKB4vhVoll3Jxr9NLuKJ5gN0gFHg9vQWSNgfFb6A8g4S8BWwSPdyRsdMwq+LfuWFo1xHEgV6syoCa/sV5rOoc+DmXGKskJupQjzdu0+el3AwzYd1uPD20nqBwJnbnlgFgwiNepdfqzboYCgvggJ9EdUctRVRAX1+7PXVkJDmHPQTAp8PtWncSA3KPDUSzorre3Q==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Christian Lindig <christian.lindig@xxxxxxxxxx>, David Scott <dave@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Anthony Perard <anthony.perard@xxxxxxxxxx>
  • Delivery-date: Mon, 08 Aug 2022 09:59:32 +0000
  • Ironport-data: A9a23:YDNWy65s5iyyPnrcWe4TLAxRtCfGchMFZxGqfqrLsTDasY5as4F+v mYfDG+EaPreN2XzeNkia4qx9ExX6p7RztRrTwc9+ywyHi5G8cbLO4+Ufxz6V8+wwmwvb67FA +E2MISowBUcFyeEzvuVGuG96yM6jclkf5KkYMbcICd9WAR4fykojBNnioYRj5VhxNO0GGthg /uryyHkEALjimUc3l48sfrZ8ks/5KSq4Vv0g3RlDRx1lA6G/5UqJMp3yZGZdxPQXoRSF+imc OfPpJnRErTxpkpF5nuNy94XQ2VSKlLgFVHmZkl+AsBOtiNqtC0qupvXAdJHAathZ5dlqPgqo DlFncTYpQ7EpcQgksxFO/VTO3kW0aGrZNYriJVw2CCe5xSuTpfi/xlhJF4oG7Ea5blIPTpp6 /UxJzkvSD/bvf3jldpXSsE07igiBO/CGdtD/1Rfl3TeB/tgRo3fSaLX49MexC03ms1FAffZY YwedCZraxPDJRZIPz/7CrpnxLvu2ia5LGYe8Q3IzUY0yzG7IAhZ+b7hKtfKPPeNQt1YhB2wr WPa5WXpRBodMbRzzBLarS/82bSTzEsXXqojDZeJ/fxroWaR5TE4GQArawuwnsmQ3xvWt9V3b hZ8FjAVhbg/8gmnQ8fwWzW8oWWYpVgMVtxICeo45QqRjK3O7G6xCmEaQxZbZdchtctwQiYlv neWm/v5CDopt6eaIU9x7Z+RpDK2fC0Kd2kLYHdYSRNfuoa+5oYukhjIU9BvVravicH4Ei3xx DbMqzUig7IUjogA0KDTEU37vg9Ab6PhFmYdjjg7lEr/hu+lTOZJv7CV1GU=
  • Ironport-hdrordr: A9a23:1DJELq+unAi9xAoUGfRuk+F7db1zdoMgy1knxilNoENuH/Bwxv rFoB1E73TJYW4qKQodcdDpAtjifZtFnaQFrLX5To3SJjUO31HYYL2KjLGSiQEIfheTygcz79 YGT0ETMrzN5B1B/L7HCWqDYpkdKbu8gcaVbI7lph8DIz2CKZsQljuRYTzrcHGeMTM2YabRY6 Dsg/avyQDBRV0nKuCAQlUVVenKoNPG0Lj8ZwQdOhIh4A6SyRu19b/TCXGjr1YjegIK5Y1n3X nOkgT/6Knmmeq80AXg22ja6IkTsMf9y+FEGNeHhqEuW3XRY0eTFcdcso+5zXUISdKUmRIXeR 730lAd1vFImjHsl6eO0F3QMkfboW8TAjTZuCKlaDPY0LDErXQBeoR8bMtiA2XkAwBLhqAC7I tbm22erJZZFhXGgWD04MXJTQhjkg6urWMlivN7tQ0XbWIyUs4nkWUkxjIiLL4QWCbhrIw3Gu hnC8/RoP5QbFOBdnjc+m1i2salUHg/FgqPBhFqgL3f7xFG2HRii0cIzs0WmXkNsJo7Vplf/u zBdqBljqtHQMMaZb90QO0BXcy0AGrQRg+kChPbHX33UKUcf37doZ/+57s4oOmsZZwT1ZM33I /MVVtJ3FRCD34Gyff+qaGj3iq9MFlVBw6du/22z6IJyYHUVf7sLTCJTkwono+pv+gfa/erKc qOBA==
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHYo3Q7g2T4T7O1X0OIdhve1Wb7Ta2gpUyAgAQVkQCAABlAgA==
  • Thread-topic: [PATCH v1 7/7] tools/ocaml/libs/eventchn: do not leak event channels and OCaml 5.0 compat

On 08/08/2022 09:28, Edwin Torok wrote:
>> On 5 Aug 2022, at 19:06, Andrew Cooper <Andrew.Cooper3@xxxxxxxxxx> wrote:
>>
>> On 29/07/2022 18:53, Edwin Török wrote:
>>> +};
>>>
>>> CAMLprim value stub_eventchn_init(void)
>>> {
>>> @@ -48,7 +71,9 @@ CAMLprim value stub_eventchn_init(void)
>>>     if (xce == NULL)
>>>             caml_failwith("open failed");
>>>
>>> -   result = (value)xce;
>>> +   /* contains file descriptors, trigger full GC at least every 128 
>>> allocations */
>>> +   result = caml_alloc_custom(&xenevtchn_ops, sizeof(xce), 1, 128);
>> The memory allocated for xce is tiny (48 bytes) and invariant for the
>> lifetime of the evtchn object, which we've already established tends to
>> operate as a singleton anyway.
>>
>> Don't we want to use the recommended 0 and 1 here?
> It is not just about the memory itself, but also about the file descriptors: 
> those are a limited resource,
> and if we use the 0 and 1 it means that this will be garbage collected very 
> infrequently since the allocation itself is very small,
> and you could potentially run out of file descriptors if you keep opening new 
> event channels.
> Notice there is no API for the user to close the event channel, so it has to 
> rely on the GC, which is not ideal.
>
> The mirage version of the eventchn lib does provide a close function: 
> https://github.com/mirage/ocaml-evtchn/blob/main/lib/eventchn.mli,
> although its implementation just leaks it (to avoid use-after-free): 
> https://github.com/mirage/ocaml-evtchn/blob/main/lib/eventchn.ml#L42
>
> Are event channel always expected to be singletons, is there a valid use case 
> where you'd want more than 1 event channel/process?

Careful on terminology.  We're discussing an open /dev/xen/evtchn file
handle, upon which an arbitrary number of event channels are muliplexed.

There's no good reason to have more than one file handle open, and
there's no good reason to close it except during shutdown.

So 0 and 1 are probably the right values in this case.

~Andrew

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.