Re: physical pages of a process

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Vinceno Mallozzi wrote:
Hi all,
I am developing my thesys' project and I need to know the physical pages a process occupies. I have just tried to read these informations from the proc directory; in particular, I've read some memory ranges from the file /proc/$pid/maps, but I have later understood that these ranges indicate intervals of linear addresses (or better, indicate the memory region occupied by the process). In other word, I've not found the physical addresses I need.
Later, I've also read, from the book "Understanding Linux Kernel", how to obtain memory regions informations from the process descriptor; but I haven't understood where I can find physical addresses or how can I translate linear addresses representing memory region into physical ones or finally if exists a C function that return these values.
Can Someone help me, please?


To get the corresponding pysical adress (of a virtual adress), you can use the function follow_page(). This function takes a virtual adress and walk trhough the GPD,PMD and PT. So you can get the physical page. Here is the nearly code of follow_page() (but have a look at the source code ):


pgd_t *pgd; pmd_t *pmd; pte_t *ptep, pte;

pgd = pgd_offset(mm, address);
if (pgd_none(*pgd) || pgd_bad(*pgd))
	goto out;

pmd = pmd_offset(pgd, address);
if (pmd_none(*pmd) || pmd_bad(*pmd))
	goto out;

ptep = pte_offset(pmd, address);
if (!ptep)
	goto out;

pte = *ptep;


You have to use this code with the good PGD,PMD and PTE, corresponding to the process you deal with.


I hope i've grought you some help


-- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux