查看Linux中DMA的大小

本文详细解读了Linux操作系统中内存的分区结构,特别是DMA、DMA32和Normal区域的划分、大小计算,以及如何通过`/proc/buddyinfo`和`free`命令观察内存使用情况。同时,通过dmesg日志对比了不同分区的信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

操作系统会将内存分段,分页,分区,本文讲linux下的内存分区。

在64位的操作系统中,内存划分为DMA、MDA32、Normal区。

DMA

Direct memory access, or DMA, is the advanced topic that completes our overview of memory issues. DMA is the hardware mechanism that allows peripheral components to transfer their I/O data directly to and from main memory without the need to involve the system processor. Use of this mechanism can greatly increase throughput to and from a device, because a great deal of computational overhead is eliminated.

查看各分区大小:

[zyq@zyq ~]$ cat /proc/buddyinfo 
Node 0, zone      DMA      0      2      3      2      3      1      0      0      1      1      3 
Node 0, zone    DMA32    218     77     38     26     13      5      2      2      2      2    539 
Node 0, zone   Normal    164     80     71    148     89     49     19     11      6      9   7043

每一行代表当前的内存区中连续1、2、4、8、16、32、64、128、256、512、1024个可使用空闲页的数量,当前系统默认的页大小为4K,所以分别对应的大小为1x4k、2x4k、4x4k、8x4k、16x4k、32x4k、64x4k、128x4k、256x4k=1M、512x4k=2M、1024x4k=4M,由此可以计算出:

DMA大小为:

3x4M+1x2M+1x1M+...=16M

DMA32大小为:

539x4M+2*2M+2*1M+...=2G

Normal大小为:

7043x4M+9x2M+6x1M+...=27G

查看当前系统可用内存

[zyq@zyq ~]$ free -h
              total        used        free      shared  buff/cache   available
Mem:            31G        697M         29G        108M        664M         29G
Swap:          7.7G          0B        7.7G
[zyq@zyq ~]$ cat /proc/meminfo 
MemTotal:       32520788 kB
MemFree:        31126504 kB
MemAvailable:   31270580 kB
Buffers:            5400 kB
Cached:           513132 kB
SwapCached:            0 kB
Active:           378812 kB
...

[zyq@zyq ~]$ python
Python 2.7.5 (default, May  3 2017, 07:55:04) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-14)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 31126504/1024
30396
>>>    

由上图可发现系统当前可使用内存为30G与上述基本吻合。

通过dmesg日志查看DMA区域

[zyq@zyq ~]$ grep -i dma /var/log/dmesg -5
...
[    0.000000]   DMA      [mem 0x00001000-0x00ffffff]
[    0.000000]   DMA32    [mem 0x01000000-0xffffffff]
[    0.000000]   Normal   [mem 0x100000000-0x8527fffff]
...
[    0.000000]   DMA zone: 64 pages used for memmap
[    0.000000]   DMA zone: 71 pages reserved
[    0.000000]   DMA zone: 3978 pages, LIFO batch:0
[    0.000000]   DMA32 zone: 10014 pages used for memmap
[    0.000000]   DMA32 zone: 640850 pages, LIFO batch:31
[    0.000000]   Normal zone: 119968 pages used for memmap
[    0.000000]   Normal zone: 7677952 pages, LIFO batch:31
...

从本日志也可以查询到相关信息,但是与/proc/buddyinfo的信息有出入,待进一步分析

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值