Linux.ChinaUnix.net
ChinaUnix | Linux首页 | 新闻 | 博客 | 文章 | 专栏 | 新手 | 方案 | 图书 | 下载 | 人才 | 手册 | wiki | 搜索     
Linux论坛
  会员: 密码: 免费注册 | 忘记密码 | 会员登录 | 搜索 | 帮助 


x86下dma映射以及页面锁页换页的问题
首页 » CU论坛 » Linux » 汇总贴列表 » 内核源码 »  
[打印] [订阅] [收藏] [推荐给朋友] [本帖文本页]
duanius
风云使者



UID:471810
注册:2006-10-1
最后登录: 2008-07-05
帖子:407
精华:1

可用积分:363
信誉积分:100
专家积分:0 (本版)

状态:...保密...

[资料] [站内短信] [Blog]


顶部
11楼 发表于 2008-4-29 15:00 


QUOTE:
原帖由 albcamus 于 2008-4-29 14:52 发表
分配大内存可以用bootmem吧? google一下应该有,我没用过^_^

曾经动过这个念头  但按照ldd3的说法 “这种技术比较粗暴也很不灵活”  所以感觉有点“很黄很暴力”
应该是可以的 ldd上也说这种方法是最不容易失败的  但ldd对它的描述实在有些惊心动魄 所以不是很敢用  因为实在是“不走寻常路”



您对本贴的看法:鲜花[0] 臭蛋[0]
CU可用积分兑换Linux/Unix精品图书 |《Ubuntu标准教程》书评获奖名单公布
duanius
风云使者



UID:471810
注册:2006-10-1
最后登录: 2008-07-05
帖子:407
精华:1

可用积分:363
信誉积分:100
专家积分:0 (本版)

状态:...保密...

[资料] [站内短信] [Blog]


顶部
12楼 发表于 2008-4-29 16:02 
其实还是对锁页有疑惑  不是很清楚应该手动锁页的PG_locked 还是调用SetPageReserved来设置PG_reserved  感觉locked就够了 但老外文献用的是设为保留   
在这一点上实在很迷茫  不清楚在我的应用中应该用哪个  网上搜了搜也没感觉完全明白
有关这点哪位老大可以展开讲讲它们的具体区别和应用场景么



您对本贴的看法:鲜花[0] 臭蛋[0]
CU可用积分兑换Linux/Unix精品图书 |《Ubuntu标准教程》书评获奖名单公布
版主 albcamus (百無一用書生)
版主-大法师
[ 願天速殞可憐生 ]



UID:140189
注册:2004-3-7
最后登录: 2008-07-04
帖子:10935
精华:20

可用积分:4345
信誉积分:105
专家积分:15 (本版)

来自:嫏嬛閣
状态:...保密...

[资料] [站内短信] [Blog]


顶部
13楼 发表于 2008-4-29 16:40 


QUOTE:
原帖由 duanius 于 2008-4-29 16:02 发表
其实还是对锁页有疑惑  不是很清楚应该手动锁页的PG_locked 还是调用SetPageReserved来设置PG_reserved  感觉locked就够了 但老外文献用的是设为保留   
在这一点上实在很迷茫  不清楚在我的应用中应该用哪个  ...

我是VM文盲, 不过翻了一下ULK3, 发现PG_locked的意思是不允许别的地方访问该页;


PG_reserved的意思是The page frame is reserved for kernel code or is unusable.



您对本贴的看法:鲜花[0] 臭蛋[0]

__________________________________

欢迎投票:
http://bbs.chinaunix.net/thread-1043990-1-1.html
   平生自有千秋在,不向群兒問毀譽!


   
   爱国主义是群氓的道德安全套……



CU可用积分兑换Linux/Unix精品图书 |《Ubuntu标准教程》书评获奖名单公布
duanius
风云使者



UID:471810
注册:2006-10-1
最后登录: 2008-07-05
帖子:407
精华:1

可用积分:363
信誉积分:100
专家积分:0 (本版)

状态:...保密...

[资料] [站内短信] [Blog]


顶部
14楼 发表于 2008-4-29 17:02 
听你这么一说我感觉好像它们更像了阿。。。
我以前的理解是pg_lock就是锁住页面不准换出   pg_reserved就是做为保留 不让mm来管理(也是道听途说 不是很理解其中的意思  可能就是这个页框以后不准再用于分配等mm操作之类的意思吧)
糊涂的很  感觉有区别  但限于水平  讲不出来



您对本贴的看法:鲜花[0] 臭蛋[0]
CU可用积分兑换Linux/Unix精品图书 |《Ubuntu标准教程》书评获奖名单公布
版主 albcamus (百無一用書生)
版主-大法师
[ 願天速殞可憐生 ]



UID:140189
注册:2004-3-7
最后登录: 2008-07-04
帖子:10935
精华:20

可用积分:4345
信誉积分:105
专家积分:15 (本版)

来自:嫏嬛閣
状态:...保密...

[资料] [站内短信] [Blog]


顶部
15楼 发表于 2008-4-30 11:17 
I know nothing about the Linux VM subsystem, but, since nobody answers...

PG_locked的意思应该不止是锁住页面不让换出,应该是不允许其他代码访问page,当然也是不允许swap out的。

你的case里,我觉得设置Reserve就足够了。 反正这些页面只有你用,怎么互斥由你来决定。



您对本贴的看法:鲜花[0] 臭蛋[0]

__________________________________

欢迎投票:
http://bbs.chinaunix.net/thread-1043990-1-1.html
   平生自有千秋在,不向群兒問毀譽!


   
   爱国主义是群氓的道德安全套……



CU可用积分兑换Linux/Unix精品图书 |《Ubuntu标准教程》书评获奖名单公布
zx_wing   帅哥 (骑着猪的青蛙)
大天使
学徒



UID:499746
注册:2006-12-4
最后登录: 2008-07-04
帖子:1687
精华:3

可用积分:2338
信誉积分:100
专家积分:1 (本版)

来自:成都
状态:...保密...

[资料] [站内短信] [Blog]


顶部
16楼 发表于 2008-4-30 11:49 
心有余而力不足,也是个VM盲



您对本贴的看法:鲜花[0] 臭蛋[0]

__________________________________


C调 ---- C语言
都是最喜欢的
CU可用积分兑换Linux/Unix精品图书 |《Ubuntu标准教程》书评获奖名单公布
duanius
风云使者



UID:471810
注册:2006-10-1
最后登录: 2008-07-05
帖子:407
精华:1

可用积分:363
信誉积分:100
专家积分:0 (本版)

状态:...保密...

[资料] [站内短信] [Blog]


顶部
17楼 发表于 2008-4-30 12:29 
晕。。你们太谦虚了。。 这方面你们肯定懂的比我多  
应该是像a版所说优先考虑Reserve  不过还是再查查想了解更多一点的东西   。。。 我就奇怪为啥没哪本书详细说一下。。还是这个问题太幼齿了。。



您对本贴的看法:鲜花[0] 臭蛋[0]
CU可用积分兑换Linux/Unix精品图书 |《Ubuntu标准教程》书评获奖名单公布
zx_wing   帅哥 (骑着猪的青蛙)
大天使
学徒



UID:499746
注册:2006-12-4
最后登录: 2008-07-04
帖子:1687
精华:3

可用积分:2338
信誉积分:100
专家积分:1 (本版)

来自:成都
状态:...保密...

[资料] [站内短信] [Blog]


顶部
18楼 发表于 2008-4-30 13:18 
虽然不太懂,还是说点自己的看法。
个人也认为用PG_reserved好一点,首先

QUOTE:
* PG_reserved is set for special pages, which can never be swapped out. Some
* of them might not even exist (eg empty_bad_page)...

符合你的要求

其次,对于PG_locked

QUOTE:
* During disk I/O, PG_locked is used. This bit is set before I/O and
* reset when I/O completes. page_waitqueue(page) is a wait queue of all tasks
* waiting for the I/O on this page to complete.

PG_locked是在做disk I/O时让别人不要touch,谁会去touch呢?我认为是page cache的回收程序。因为disk I/O主要是和page cache打交道,而page cache又是动态回收的。所以在做DMA的时候不允许该页面被回收。

最后,有一个PG_reserved的例子,sound/oss/ymfpci.c中的DMA buffer分配函数

QUOTE:
static int alloc_dmabuf(ymfpci_t *unit, struct ymf_dmabuf *dmabuf)
{
        void *rawbuf = NULL;
        dma_addr_t dma_addr;
        int order;
        struct page *map, *mapend;

        /* alloc as big a chunk as we can */
        for (order = DMABUF_DEFAULTORDER; order >= DMABUF_MINORDER; order--) {
                rawbuf = pci_alloc_consistent(unit->pci, PAGE_SIZE << order, &dma_addr);
                if (rawbuf)
                        break;
        }
        if (!rawbuf)
                return -ENOMEM;

#if 0
        printk(KERN_DEBUG "ymfpci: allocated %ld (order = %d) bytes at %p\n",
               PAGE_SIZE << order, order, rawbuf);
#endif

        dmabuf->ready  = dmabuf->mapped = 0;
        dmabuf->rawbuf = rawbuf;
        dmabuf->dma_addr = dma_addr;
        dmabuf->buforder = order;

       /* now mark the pages as reserved; otherwise remap_pfn_range doesn't do what we want */
        mapend = virt_to_page(rawbuf + (PAGE_SIZE << order) - 1);
        for (map = virt_to_page(rawbuf); map <= mapend; map++)
                set_bit(PG_reserved, &map->flags);

        return 0;
}

LZ可以参考。

[ 本帖最后由 zx_wing 于 2008-4-30 13:21 编辑 ]



您对本贴的看法:鲜花[0] 臭蛋[0]

__________________________________


C调 ---- C语言
都是最喜欢的
CU可用积分兑换Linux/Unix精品图书 |《Ubuntu标准教程》书评获奖名单公布
duanius
风云使者



UID:471810
注册:2006-10-1
最后登录: 2008-07-05
帖子:407
精华:1

可用积分:363
信誉积分:100
专家积分:0 (本版)

状态:...保密...

[资料] [站内短信] [Blog]


顶部
19楼 发表于 2008-4-30 14:56 
感谢wing兄  特别是那个不错的例子

本来以为就结束了 但我在网上也搜到了一些不是很爽的结果:

The page structure, used to describe the memory in the system, includes a set of flags; one of those flags is PG_reserved. For a long time, this bit has marked pages which are not part of the regular memory management regime; pages so marked include the kernel text (which really should not be swapped out) and the I/O memory in the legacy ISA hole at 640K. Occasionally, device drivers have explicitly set the reserved bit on ordinary memory so that it could be mapped into user space with remap_pfn_range(). This technique has been discouraged for years, but still persists in spots.

The 2.6.15 kernel removes, for all practical purposes, the reserved bit. Space for page flags is tight, and it was figured that, in 2.6, this bit was no longer needed. The page reclaim code no longer cycles through the system memory map, so it does not need this bit to know which pages to avoid. For the other uses, the VM_RESERVED bit in the vm_area structure could be used instead. So, in 2.6.15-rc2, the PG_reserved bit is (almost) ignored, and the kernel respects VM_RESERVED by not freeing pages found in areas with that bit set.


原帖地址http://lwn.net/Articles/161204/   看上去应该比贴子里看爽


btw  还有结尾的一段话:
Meanwhile, one other interesting result of the PG_reserved removal is that remap_page_range() can now be used to remap any set of addresses, not just those marked reserved.
这是不是就意味着 可以像nopage一样对常规内存进行映射了呢。。。   唉  关于remap_pfn_range   remap_page_range  nopage方法感觉又有些稀里糊涂了  节后还要好好研究下。



您对本贴的看法:鲜花[0] 臭蛋[0]
CU可用积分兑换Linux/Unix精品图书 |《Ubuntu标准教程》书评获奖名单公布
zx_wing   帅哥 (骑着猪的青蛙)
大天使
学徒



UID:499746
注册:2006-12-4
最后登录: 2008-07-04
帖子:1687
精华:3

可用积分:2338
信誉积分:100
专家积分:1 (本版)

来自:成都
状态:...保密...

[资料] [站内短信] [Blog]


顶部
20楼 发表于 2008-4-30 15:07 


QUOTE:
原帖由 duanius 于 2008-4-30 14:56 发表
感谢wing兄  特别是那个不错的例子

本来以为就结束了 但我在网上也搜到了一些不是很爽的结果:

The page structure, used to describe the memory in the system, includes a set of flags; one of thos ...

难怪现在kernel里面用PG_reserved的地方这么少了。
LZ可以研究一下,搞懂和大家分享一下经验。感觉VM_RESERVED这种方法更好,可以把页粒度的控制扩大到以area为单位控制,用起来应该更方便。



您对本贴的看法:鲜花[0] 臭蛋[0]

__________________________________


C调 ---- C语言
都是最喜欢的
CU可用积分兑换Linux/Unix精品图书 |《Ubuntu标准教程》书评获奖名单公布

首页 » CU论坛 » Linux » 汇总贴列表 » 内核源码 »

 


Copyright © 2001-2008 ChinaUnix.net All Rights Reserved     联系我们:

感谢所有关心和支持过ChinaUnix的朋友们    转载本站内容请注明原作者名及出处

京ICP证041476号


清除 Cookies - Linux时代 - Archiver - WAP - TOP

Processed in 0.054176 second(s), 5 queries , Gzip enabled