Re: How to signal kernel that shared library is not in use by any process anymore ?

Shachar Shemesh <[email protected]> Sun, 23 Dec 2018 21:03:56 +0200
Newsgroups gmane.linux.region.israel
Message-ID <[email protected]>
On 23/12/2018 09:49, Lev Olshvang
wrote:

Boker tov,

Thanks for all of your
replies that helped me to understand what question I really
wanted to ask.

So this is a question.

I have C++ program
which calls many services of third party library.

This library is needed
only on initialization phase of my program.

Linker has resolved
symbols of this library and now it is bound to executable and in
a run tine

this lib will be mapped
will have use count > 0 while executable is in
use.

I would like to unmap it
to release memory, but i do not know how to do it in user space.

As an alternative I know
that by using dynamic loader calls dlopen() .. dlclose() I can
achieve the desired effect

The problem that I need
to add a lot of dlfind() calls, and I looked for a way dynamic
loader can do it.

I am not that lazy, but
since the code is C++, function names are mangled and I was
tring to avoid this

by looking as a subject
of this mail said, way to ask kernel to unmap this lib

I wish we have __init
attribute in a user land !

First, yes, it will have a use count of more than zero. So what?
All the pages are clean, and have a file that has a copy. The
kernel will gladly remove them from memory despite being mapped
(unless you mlock them, that is). If, as you say, they are not
used after init, then nothing will fault them and cause them to
come back.

I am not that lazy,

It's not about being lazy. It's about opening yourself up for
introducing bugs. I wouldn't do that.

Assuming you're still not convinced, here's what I would
do: Write your own library (liblevinit.so). Put all the calls that
need to go into that other library into liblevinit.so. dlopen and
dlsym lev init, call the trigger function, and then dlclose it.
You now have to manage only one symbol, and

Like I said above, I don't think that is necessary. If you want
to be paranoid about it, however, that's what I'd do.

Shachar

_______________________________________________
Linux-il mailing list
[email protected]
http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il