You need to iterate through each process /proc/[pid]/smaps
It will contain an entry for each virtual machine mapping:
7ffffffe7000-7ffffffff000 rw-p 00000000 00:00 0 [stack] Size: 100 kB Rss: 20 kB Pss: 20 kB Shared_Clean: 0 kB Shared_Dirty: 0 kB Private_Clean: 0 kB Private_Dirty: 20 kB Referenced: 20 kB Anonymous: 20 kB AnonHugePages: 0 kB Swap: 0 kB KernelPageSize: 4 kB MMUPageSize: 4 kB
Private_Dirty memory is what interests you.
If there is a Pss field in your smaps file, then this is the amount of resident memory divided by the number of processes sharing physical memory.
Private_Clean can be copy to write mappings. They are usually used for shared libraries and are usually read / not written / executed.
source share