This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
Re: writing to global variable in shared object file will increase memory usage
- From: Carlos O'Donell <carlos at redhat dot com>
- To: Yubin Ruan <ablacktshirt at gmail dot com>, libc-help at sourceware dot org
- Date: Thu, 31 Aug 2017 09:36:49 -0500
- Subject: Re: writing to global variable in shared object file will increase memory usage
- Authentication-results: sourceware.org; auth=none
- References: <CAJYFCiO9gJQDVuoVVnqOS6frKOZtDtqic=vgq6Y5pHO2YOjOVg@mail.gmail.com>
On 08/31/2017 08:54 AM, Yubin Ruan wrote:
> I know that on many operation systems (almost all) many user programs
> which use the same shared object file will effectively use the same
> piece of memory for that object file, as long as user programs does
> not write to that piece of memory, in which case a Copy-On-Write will
> be triggered.
>
> So, I wonder, if many user programs use the same shared object file
> and all those programs try to write a global variable, will the
> operating system duplicate that shared object for all those programs?
No.
COW is page-based. The *page* that is changed will be COWd and become
unshared.
> Or just the part that got written? How to verify that?
The smallest granularity is pages.
To verify it you could boot your system into single-user mode, to reduce
the changes going on in the system, then run two processes using the
same DSO, and see how much the system memory usage increases by.
--
Cheers,
Carlos.