If we have two images
imageA: libc.so, programA
imageB: libc.so, programB
When we start A , the libc.so is loaded into memory for the first time. Then we start B, will be using the same RAM area of the libc.so? Not logically, I mean physical memory. If we dong’t run container, A and B can share libc.so. I’ m wandering what’s going on for a container-involved condition.
1 Like
If imageA and imageB are in different directories, libc.so will be loaded twice. Dynamic libraries are loaded into memory with mmap. Without container, libc.so has only one copy in the file system. So it is loaded into physical memory for just once, but mapped to different processes in different logical memory address.
If we use chroot to start two processes in in two base directory, their dynamic libraries are not shared, since they are in the different file system location.
When we use union fs, two containers share the same base readonly images including dynamic libraries, then sharing dynamic libraries depends on the implementation of union fs. Still digging.