This is the mail archive of the libc-help@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: writing to global variable in shared object file will increase memory usage


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]