pSendDmaPool = dma_pool_create("DmaPool",pci_dev->dev), (size_t)(512 * 64*1024+1024), (size_t)(64*1024), (size_t)0);
pDmaBuf = (unsigned char*)dma_pool_alloc(pSendDmaPool, GFP_KERNEL, &dma_handle);
我的平台是64位X86,我执行完dma_pool_create后,再执行dma_pool_alloc,就崩溃了,然后打印信息是:
------------[ cut here ]------------
WARNING: at mm/page_alloc.c:2139 __alloc_pages_nodemask+0x7a8/0x8d0() (Not tainted)
Hardware name: All Series
Modules linked in: fh130drv(U) ebtable_nat ebtables ipt_MASQUERADE iptable_nat nf_nat xt_CHECKSUM iptable_mangle bridge autofs4 8021q garp stp llc cpufreq_ondemand acpi_cpufreq freq_table mperf ipt_REJECT nf_conntrack_ipv4 nf_defrag_ipv4 iptable_filter ip_tables ip6t_REJECT nf_conntrack_ipv6 nf_defrag_ipv6 xt_state nf_conntrack ip6table_filter ip6_tables ipv6 vhost_net macvtap macvlan tun kvm uinput ppdev iTCO_wdt iTCO_vendor_support microcode parport_pc parport r8169 mii sg serio_raw lpc_ich mfd_core i2c_i801 shpchp snd_hda_codec_realtek snd_hda_codec_hdmi snd_hda_intel snd_hda_codec snd_hwdep snd_seq snd_seq_device snd_pcm snd_timer snd soundcore snd_page_alloc ext4 jbd2 mbcache sd_mod crc_t10dif ahci xhci_hcd i915 drm_kms_helper drm i2c_algo_bit i2c_core video output dm_mirror dm_region_hash dm_log dm_mod [last unloaded: scsi_wait_scan]
Pid: 3725, comm: fh130demo Not tainted 2.6.32-504.el6.x86_64 #1
Call Trace:
[] ? warn_slowpath_common+0x87/0xc0
[] ? warn_slowpath_null+0x1a/0x20
[] ? __alloc_pages_nodemask+0x7a8/0x8d0
[] ? atomic_notifier_call_chain+0x1a/0x20
[] ? notify_update+0x2e/0x30
[] ? vt_console_print+0x260/0x330
[] ? up+0x2f/0x50
[] ? _call_console_drivers+0x4a/0x80
[] ? dma_generic_alloc_coherent+0xa6/0x160
[] ? apic_timer_interrupt+0xe/0x20
[] ? x86_swiotlb_alloc_coherent+0x31/0x70
[] ? dma_pool_alloc+0xfc/0x2a0
[] ? printk+0x41/0x44
[] ? hbaDevAllocDmaBuffers+0x2f6/0x8f0 [fh130drv]
[] ? hbaDevInitialize+0x168/0x1b0 [fh130drv]
[] ? Hba_FC_ASM_LoadConfig+0x54/0xa0 [fh130drv]
[] ? hba_dev_ioctl+0x1e2/0xbd0 [fh130drv]
[] ? avc_has_perm+0x71/0x90
[] ? pty_write+0x73/0x80
[] ? inode_has_perm+0x54/0xa0
[] ? remove_wait_queue+0x3c/0x50
[] ? __wake_up+0x53/0x70
[] ? vfs_ioctl+0x22/0xa0
[] ? do_vfs_ioctl+0x84/0x580
[] ? sys_ioctl+0x81/0xa0
[] ? __audit_syscall_exit+0x25e/0x290
[] ? system_call_fastpath+0x16/0x1b
---[ end trace 03df1cd6b697aafa ]---
求高手解答这个是怎么回事?
然后我想问一下,我可以分配
512 * 64*1024+1024这么大的DMA内存吗?并且对齐方式是64*1024?
然后我alloc的时候,每一块是多大呢?
谢谢了,没有金币了,不好意思!
unsigned char*)dma_pool_alloc(pSendDmaPool, GFP_KERNEL, &dma_handle);
我的平台是64位X86,我执行完dma_pool_create后,再执行dma_pool_alloc,就崩溃了,然后打印信息是:
------------[ cut here ]------------
WARNING: at mm/page_alloc.c:2139 __alloc_pages_nodemask+0x7a8/0x8d0() (Not tainted)
Hardware name: All Series
Modules linked in: fh130drv(U) ebtable_nat ebtables ipt_MASQUERADE iptable_nat nf_nat xt_CHECKSUM iptable_mangle bridge autofs4 8021q garp stp llc cpufreq_ondemand acpi_cpufreq freq_table mperf ipt_REJECT nf_conntrack_ipv4 nf_defrag_ipv4 iptable_filter ip_tables ip6t_REJECT nf_conntrack_ipv6 nf_defrag_ipv6 xt_state nf_conntrack ip6table_filter ip6_tables ipv6 vhost_net macvtap macvlan tun kvm uinput ppdev iTCO_wdt iTCO_vendor_support microcode parport_pc parport r8169 mii sg serio_raw lpc_ich mfd_core i2c_i801 shpchp snd_hda_codec_realtek snd_hda_codec_hdmi snd_hda_intel snd_hda_codec snd_hwdep snd_seq snd_seq_device snd_pcm snd_timer snd soundcore snd_page_alloc ext4 jbd2 mbcache sd_mod crc_t10dif ahci xhci_hcd i915 drm_kms_helper drm i2c_algo_bit i2c_core video output dm_mirror dm_region_hash dm_log dm_mod [last unloaded: scsi_wait_scan]
Pid: 3725, comm: fh130demo Not tainted 2.6.32-504.el6.x86_64 #1
Call Trace:
关于你遇到的问题,从调用栈中看到提示了一个内存分配错误警告,可能是在执行 dma_pool_alloc 函数时发生了内存分配失败的情况。这种情况通常是由于系统中可用内存不足导致的。建议检查一下系统中可用内存是否充足。
另外,对于你的问题:
你可以分配512 * 641024+1024这么大的DMA内存,并且按照641024字节对齐。注意,实际能够分配的内存大小取决于系统中可用的物理内存和虚拟地址空间大小等因素,可能会小于你所要求的大小。
每一块的大小可以自行决定,但需要满足对齐要求,即每一块的起始地址都应该是64*1024的倍数。以下是一个示例代码:
#define BUF_SIZE (64 * 1024)
#define BUF_NUM 10
struct my_dev {
struct dma_pool *pool;
unsigned char *buf[BUF_NUM];
dma_addr_t dma_addr[BUF_NUM];
};
struct my_dev *dev;
// 初始化 DMA 池
dev->pool = dma_pool_create("DmaPool", &pci_dev->dev, BUF_SIZE,
64 * 1024, 0);
if (!dev->pool) {
pr_err("Failed to create DMA pool\n");
return -ENOMEM;
}
// 分配 DMA 缓冲区
int i;
for (i = 0; i < BUF_NUM; i++) {
dev->buf[i] = dma_pool_alloc(dev->pool, GFP_KERNEL,
&dev->dma_addr[i]);
if (!dev->buf[i]) {
pr_err("Failed to allocate DMA buffer %d\n", i);
dma_pool_destroy(dev->pool);
return -ENOMEM;
}
}
// 使用 DMA 缓冲区,传输数据等操作
...
在这个例子中,我们使用 dma_pool_create 创建了一个大小为64KB,对齐要求为64KB的DMA池,然后使用 dma_pool_alloc 函数分配了10个大小为64KB的 DMA 缓冲区,每个缓冲区地址都是64KB对齐的。你可以根据自己的需求修改缓冲区大小和数量