查看Linux中DMA的大小

操作系统会将内存分段,分页,分区,本文讲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的信息有出入,待进一步分析

Linux ,设备树是描述硬件信息的一种数据结构。DMA(Direct Memory Access,直接内存访问)是一种硬件机制,它允许外设直接访问系统内存而不需要 CPU 的干预。在设备树DMA 控制器和外设需要进行正确的配置才能实现 DMA 的功能。 下面是一个示例设备树节点的 DMA 配置: ``` dma-channel@0 { compatible = "arm,pl330", "arm,primecell"; reg = <0x7e001000 0x1000>; interrupts = <0 47 4>; #dma-cells = <1>; dma-channels = <8>; }; ``` 其: - `dma-channel@0` 是节点名称,在系统应该是唯一的。 - `compatible` 属性指定了该节点所对应的 DMA 控制器的类型。 - `reg` 属性指定了该节点所对应的 DMA 控制器的物理地址和大小。 - `interrupts` 属性指定了该节点所对应的 DMA 控制器的断信息。 - `#dma-cells` 属性指定了该节点所对应的 DMA 控制器的单个 DMA 通道所需要的参数个数。在本例,只需要一个参数表示 DMA 通道号。 - `dma-channels` 属性指定了该节点所对应的 DMA 控制器的可用 DMA 通道数量。 对于外设的 DMA 配置,可以在该外设的设备树节点添加 `dma` 属性,例如: ``` spi@ff1a0000 { compatible = "rockchip,rk3066-spi"; reg = <0xff1a0000 0x1000>; interrupts = <0 13 4>; clocks = <&cru SCLK_SPI0>; dmas = <&pdma0 4 3>, <&pdma0 5 3>; dma-names = "rx", "tx"; }; ``` 其: - `dmas` 属性指定了该外设使用的 RX 和 TX DMA 通道。 - `dma-names` 属性指定了 `dmas` 属性指定的 DMA 通道的名称。 以上是一些简单的示例,实际的设备树节点配置可能更加复杂,需要根据硬件的具体情况进行配置。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值