设为首页 加入收藏

TOP

Linux内核最新的连续内存分配器(CMA)——避免预留大块内存【转】(三)
2019-09-01 23:09:14 】 浏览:156
Tags:Linux 内核 最新 连续 内存 分配器 CMA 避免 预留 大块
id *p; /* touch every page in the allocated memory */ for (p = dma_virt[i]; p < dma_virt[i] + (i + 1) * SZ_1M; p += PAGE_SIZE) *(u32 *)p = 0; _dev_info(cma_dev, "alloc virt: %p phys: %p\n", dma_virt[i], (void *)dma_phys[i]); } else { dev_err(cma_dev, "no mem in CMA area\n"); ret = -ENOMEM; } break; } } return count; } static const struct file_operations cma_test_fops = { .owner = THIS_MODULE, .read = cma_test_read, .write = cma_test_write, }; static struct miscdevice cma_test_misc = { .name = "cma_test", .fops = &cma_test_fops, }; static int __init cma_test_init(void) { int ret = 0; ret = misc_register(&cma_test_misc); if (unlikely(ret)) { pr_err("failed to register cma test misc device!\n"); return ret; } cma_dev = cma_test_misc.this_device; cma_dev->coherent_dma_mask = ~0; _dev_info(cma_dev, "registered.\n"); return ret; } module_init(cma_test_init); static void __exit cma_test_exit(void) { misc_deregister(&cma_test_misc); } module_exit(cma_test_exit); MODULE_LICENSE("GPL"); MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>"); MODULE_DESCRIPTION("kernel module to help the test of CMA"); MODULE_ALIAS("CMA test");

申请内存:

# echo 0 > /dev/cma_test

释放内存:

# cat /dev/cma_test
首页 上一页 1 2 3 4 5 6 下一页 尾页 3/6/6
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇微处理器功耗来源 下一篇a simple game based on RT-Thread

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目