LinuxQuestions.org
Visit Jeremy's Blog.
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 02-03-2012, 10:06 AM   #1
demon007
LQ Newbie
 
Registered: Sep 2011
Posts: 13

Rep: Reputation: Disabled
Memory map or physical address of some memory allocated by malloc


How can I get the memory map or physical address of some memory allocated by malloc?

Please help me. I cannot get it anywhere.

Thanks in advance.
 
Old 02-04-2012, 06:17 AM   #2
Nominal Animal
Senior Member
 
Registered: Dec 2010
Location: Finland
Distribution: Xubuntu, CentOS, LFS
Posts: 1,723
Blog Entries: 3

Rep: Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948
Find out the virtual page number of the virtual address (by dividing by sysconf(_SC_PAGE_SIZE)), and use it as an index to the correct 64-bit descriptor in /proc/self/pagemap (or /proc/pid/pagemap for process pid). Read the 64-bit descriptor. If the page is present (highest bit, bit 63, is 1) and not swapped (bit 62 is 0), then the lowest 55 bits shifted left by (bits 56..61 = 0..63) tells the start address of the physical page. Add the offset of the virtual address from the start of the virtual page (i.e. virtual address modulus sysconf(_SC_PAGE_SIZE)), and you get the physical address of the virtual address the pointer points to.

Last edited by Nominal Animal; 02-04-2012 at 06:18 AM.
 
  


Reply

Tags
address, malloc, memory, physical



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
[SOLVED] Using malloc and getting memory address southpau1 Programming 2 11-10-2011 10:14 AM
Clearing of memory allocated by using malloc/kmalloc/vmalloc manikumar086 Linux - Newbie 2 08-08-2011 11:46 PM
How to configure Linux physical memory map andreiatlinux Linux - Newbie 3 05-18-2010 05:04 PM
Can't malloc all free physical memory, CommitLimit too low FEWP Programming 2 07-23-2009 12:56 PM

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

All times are GMT -5. The time now is 10:19 PM.

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