Thanks for valuable inputs. I'll try to remove this global variable and use Memcached in its place (as we are already using in our system).
Harkins, I am checking /proc/pid/smaps and found shared memory of parent is getting increased.. Following are the details of parent and childs smaps in backup site (very less traffic) and current active site(almost all traffic redirect to this). *smaps of active site:* parent-- 112a3000-216ef000 rw-p 112a3000 00:00 0 Size: 266544 kB Rss: 266308 kB Shared_Clean: 0 kB Shared_Dirty: 235432 kB Private_Clean: 0 kB Private_Dirty: 30876 kB Swap: 0 kB Pss: 65201 kB child-- 112a3000-264c6000 rw-p 112a3000 00:00 0 Size: 346252 kB Rss: 345792 kB Shared_Clean: 0 kB Shared_Dirty: 231344 kB Private_Clean: 0 kB Private_Dirty: 114448 kB Swap: 0 kB Pss: 147608 kB *smaps of backup site:* parent-- 08f29000-0f395000 rw-p 08f29000 00:00 0 Size: 102832 kB Rss: 102440 kB Shared_Clean: 0 kB Shared_Dirty: 97688 kB Private_Clean: 0 kB Private_Dirty: 4752 kB Swap: 0 kB Pss: 21270 kB child-- 08f29000-124df000 rw-p 08f29000 00:00 0 Size: 153304 kB Rss: 152572 kB Shared_Clean: 0 kB Shared_Dirty: 73724 kB Private_Clean: 0 kB Private_Dirty: 78848 kB Swap: 0 kB Pss: 89390 kB As the traffic is increasing shared memory in parent is increasing , thats what puzzling me ! If childs write into shared of parent, then it should come into private of child(copy on write) but why shared of parent is increasing? (correct me if i am wrong) OR is it work like, OS always shows copied pages of parent's shared in its shared dirty memory(in smaps) even if it internally maintains private of each child in that ? On Wed, Sep 17, 2014 at 11:56 PM, Perrin Harkins <phark...@gmail.com> wrote: > > On Wed, Sep 17, 2014 at 1:18 PM, Mark Hedges <mark.hed...@ticketmaster.com > > wrote: > >> For example, you could use a tied DBM/MLDBM hash, DBD::SQLite >> or another file-based database with access locking for your >> cache, and save it in a shared memory filesystem like /dev/shm. >> > > I would suggest that too, if it fits the use case. BerkeleyDB, > Cache::FastMmap, Reddis, or Memcached are all common solutions. They don't > work for everything though. Declaring a global variable in the parent > process and loading it with data in the child processes won't share > anything. It means you're loading the entire data into unshared memory in > each child. If you want to share that data you have to load it before > forking. After a child process modifies it, changes are not shared back to > the parent or to other children. > > As a side note, it's quite difficult to know how much memory is really > shared. If you want to know, look at Linux::Smaps, not top or ps. > > I don't see any way that loading data in the child process could increase > the size of the parent process, but memory sharing behavior is complicated > and I could be missing something. > > - Perrin >