LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-04-2017, 04:57 PM   #1
Mohammed BEY
Member
 
Registered: Feb 2017
Location: Lorient
Distribution: Ubuntu
Posts: 34

Rep: Reputation: Disabled
mmap() monitoring


Hello everybody,
I need to count reads and writes to the memory allocated by mmap().
I tried Valgrind, but it counts only the heap accesses and mmap() doesn't allocate in the heap !!
Please, could someone help me to achieve my purpose (counting reads and writes in mmap()'d area)?
Thank you
 
Old 04-06-2017, 01:51 AM   #2
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,263
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
I searched online for variations of the term mmap monitoring and did not find anything that appeared to directly answer your question. I see no obvious facility for monitoring accesses to mmaped memory as you describe.

You might find the IEEE mmap specification helpful to understanding mmap better.
 
Old 04-06-2017, 02:08 AM   #3
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,830

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
probably impossible, because you can pass mmapped address to external functions (libc ...) and also mmapped memory can be accessed from several processes.
I would try to create some wrapper functions to be able to log access.
 
1 members found this post helpful.
Old 04-06-2017, 02:29 AM   #4
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
I don't think it would be possible without a specific CPU instruction, say START/STOP_VIRTUAL_MEMORY_USAGE_STATISTICS MINADDR=addr MAXADDR=addr INTO=addr
 
Old 04-06-2017, 02:36 AM   #5
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,125

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
Sounds like yet another xyproblem.

What's the real problem ?. Simple things can be strace'd - libc:read and write can be dynamically probed. The kernel functions likewise. Not many would describe that as "simple", although it is getting easier.
 
Old 04-06-2017, 04:54 PM   #6
Mohammed BEY
Member
 
Registered: Feb 2017
Location: Lorient
Distribution: Ubuntu
Posts: 34

Original Poster
Rep: Reputation: Disabled
Smile

Quote:
Originally Posted by Mohammed BEY View Post
Hello everybody,
I need to count reads and writes to the memory allocated by mmap().
I tried Valgrind, but it counts only the heap accesses and mmap() doesn't allocate in the heap !!
Please, could someone help me to achieve my purpose (counting reads and writes in mmap()'d area)?
Thank you

Resolved.
I have used this command line:
valgrind --tool=lackey --trace-mem=yes --log-file=outputlackey.txt <command>
This will trace all the memory space of the process <command> that has been monitored and logs a file.
First of all, I got the address returned by mmap() function. Then, I read the log file, and I counted the number of the Loads and Stores. You can look at the details of the output. https://github.com/mozilla-b2g/valgr...ckey/lk_main.c

Best regards.
 
2 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
mmap 1mela Programming 2 02-05-2010 05:50 AM
about mmap chetan.c.thorat Linux - Newbie 0 09-29-2008 06:20 AM
Monitoring free memory with enterprise monitoring application Steelb Linux - Enterprise 2 02-13-2008 10:10 AM
Need help with 'dd'and 'mmap()' Agresvig Linux - Newbie 7 05-14-2007 08:19 PM
using mmap AngryLlama Programming 1 02-09-2005 08:53 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:20 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration