Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to convert Linux virtual memory address to physical memory address

Shulou Source: shulou.com Published: 2022-06-01 14:12:14 11月13日 Update

This article mainly explains "how to convert Linux virtual memory addresses into physical memory addresses". The explanation in this article is simple and clear, easy to learn and understand. Please follow the ideas of Xiaobian and study and learn "how to convert Linux virtual memory addresses into physical memory addresses" together.

background

Modern mobile phones this SOC(system on chip), because power consumption, Modem and other functions SOC integrated a lot of core, they can also be independent systems in operation.

For example, ADSP(Application Digital Signal Processing) is a Hexagon DSP , which is a core+system that operates independently. This can not only use the dedicated core on the SOC to handle professional things, such as the ADSP mentioned above can handle audio decoding, of course, its DSP features can also handle sensor fusion algorithms, compared to general purpose processors (cortex a72 a53 a17 a9 a8 these cores) processing efficiency is higher, more power saving.

Of course, we won't solder a memory grain for it alone because of cost, it shares a portion of main memory, such as 1MB from address 0xc00000 - 0xc0100000, and the kernel (Linux running on general purpose processors) will no longer touch this memory.

However, there is also a disadvantage in sharing the same address space with multiple cores, that is, if the program has problems (wild pointers, array boundaries), it may write other core management memory space, which brings us the problem that the value of the program is inexplicably changed. In order to troubleshoot this problem, we considered converting the virtual address of the application to a physical address and performing print debug for unified analysis.

achieve

kernel added such a function/proc/self/pagemap in 2.6.25, that is, there is a pagemap in/proc of each process. By reading the contents inside, you can calculate the physical page corresponding to the current virtual address, and then add page_offset to know the physical address corresponding to the current virtual address.

Pagemap requires your app to have root privileges to use.

#include #include #include #include #include #include #include #include #include #include #include #include //Reference//https://www.kernel.org/doc/Documentation/vm/pagemap.txt #define page_map_file "/proc/self/pagemap" #define PFN_MASK ((((uint64_t)1)

Tags: Address memory physics processing that is commands programs problems content space faceted learning application verification examples functions processors modules source code independent Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Shulou Technology Shulou Information Shulou Tech Info Docker