public inbox for libc-help@sourceware.org
 help / color / mirror / Atom feed
From: Adhemerval Zanella <adhemerval.zanella@linaro.org>
To: "Soni L." <fakedme+libc@gmail.com>, Libc-help <libc-help@sourceware.org>
Subject: Re: inode-based dlopen caching
Date: Tue, 8 Jun 2021 13:51:10 -0300	[thread overview]
Message-ID: <d81ad6d4-9f97-d95d-dd31-9b468ffdf3a9@linaro.org> (raw)
In-Reply-To: <cc290ea8-7ee2-04ec-e67e-cdcda6baf80b@gmail.com>



On 08/06/2021 13:26, Soni L. wrote:
> 
> 
> On 2021-06-08 10:14 a.m., Adhemerval Zanella wrote:
>>
>>
>> On 07/06/2021 19:50, Soni L. wrote:
>>>
>>>
>>> On 2021-06-07 6:53 p.m., Adhemerval Zanella wrote:
>>>>
>>>>
>>>> On 05/06/2021 10:59, Soni L. via Libc-help wrote:
>>>>> Currently dlopen caching is based on filenames, it'd be nice if it was
>>>>> based on inodes to support better "re"loading (aka loading a new module
>>>>> with the same name because unloading modules with threads is never a
>>>>> good idea). This is good for stuff that deals with plugins.
>>>>>
>>>>
>>>> What do you mean by 'caching' in this scenario? glibc does not maintain
>>>> a cache of loaded libraries, different than other implementation it
>>>> does try to unload the library on dlclose (there are cases where it
>>>> is not readily possible due dependency chains). 
>>>>
>>>> And I am not seeing how inote-bases dlopen really helps here, if inode 
>>>> changes means that file was potentially changed (so you will need to 
>>>> proper dclose it).  I think using filenames is in fact the proper way
>>>> here, since Linux does the hard lifting of the inode cache and provide
>>>> fast file access and mmap support for shared libraries.
>>>>
>>> You can't unload a dlopen that uses threads, at least not safely. So for
>>> all intents and purposes you can't unload it. Instead you need to tell
>>> it you're done with it, but not unload it, and load the new one. But
>>> that's the problem - the filename-based stuff means you can't load the
>>> new one.
>>>
>>
>> Sure you can unload a dlopen library, the API makes the program responsible
>> to synchronize the access (since dlsym/dlvsym returns an function pointer).
>> [snip]
> If the shared library creates its own threads, those won't be killed
> when the shared library is closed. If the shared library is then
> unloaded, those threads will be running code from the void. That's a
> problem.
> 
> Being able to update the library, without getting rid of the original
> (i.e. by unlinking the original file first), allows the program to
> gracefully update loaded plugins without a full restart.
> 

Again, this is a library issue that should be dealt by the provided
API by the library (such as providing a cleanup handler to synchronize
or cancel the threads execution).

In this scenario you are describing you will end up with the library
loaded in two different mapping with potentially two different code
(since you are updating the library and dlclose might be a noop).
I really don't see this as an improvement, it is rather a potential
trigger to subtle issues, specially if the threads trying to sync
with process shared resources.

  reply	other threads:[~2021-06-08 16:51 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-05 13:59 Soni L.
2021-06-07 21:53 ` Adhemerval Zanella
2021-06-07 22:50   ` Soni L.
2021-06-08 13:14     ` Adhemerval Zanella
2021-06-08 16:26       ` Soni L.
2021-06-08 16:51         ` Adhemerval Zanella [this message]
2021-06-08 16:56 ` Florian Weimer
2021-06-08 17:19   ` Adhemerval Zanella
2021-06-08 17:20     ` Florian Weimer
2021-06-08 18:10       ` Soni L.
2021-06-08 18:17         ` Florian Weimer
2021-06-08 19:25           ` Adhemerval Zanella

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d81ad6d4-9f97-d95d-dd31-9b468ffdf3a9@linaro.org \
    --to=adhemerval.zanella@linaro.org \
    --cc=fakedme+libc@gmail.com \
    --cc=libc-help@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).