1

I have a parent process that forks a child which is profiled using perf in sampling mode (sample every N events). Approximately 10000 samples are being generated. I know by using mmap() we can access the shared memory where samples are stored. But is it possible for another child to access the samples while they are being generated or written to the mmaped section? If so, how? This way i reduce the need for a huge memory to be allocated.

PHP
  • 61
  • 4
  • In theory yes; mmap shared memory is coherent. What exactly is your real goal? Having another process log to disk so you can unmap already logged samples? Simply reading isn't enough for that; you'd need some synchronization to be sure all threads were done with a page before writing + unmapping it. – Peter Cordes Nov 27 '19 at 10:23
  • Yes. Have another process log to disk whenever `mmap` ed section is full. Reuse the `mmap`ed section for storing new samples of the child. The goal is to do a timed profiling of a task. – PHP Nov 27 '19 at 11:18
  • If you wait until it's full, you'd have to pause the task you're profiling. You'd want to partition your buffer into two halves or something and use one while another thread empties the other one. – Peter Cordes Nov 27 '19 at 11:19

0 Answers0