免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: embeddedlwp

[内存管理] page cache问题 [复制链接]

论坛徽章:
1
双鱼座
日期:2013-08-28 13:47:26
发表于 2012-05-29 16:50 |显示全部楼层
回复 50# embeddedlwp
我觉得这个值就是vm_start/PAGE_SIZE,得0是就是在线性地址小于4k时。

论坛徽章:
16
2015亚冠之吉达阿赫利
日期:2015-08-17 11:21:462015年迎新春徽章
日期:2015-03-04 09:58:11酉鸡
日期:2014-12-07 09:06:19水瓶座
日期:2014-11-04 14:23:29天秤座
日期:2014-03-02 08:57:52双鱼座
日期:2014-02-22 13:07:56午马
日期:2014-02-14 11:08:18双鱼座
日期:2014-02-13 11:09:37卯兔
日期:2014-02-06 15:10:34子鼠
日期:2014-01-20 14:48:19戌狗
日期:2013-12-19 09:37:46射手座
日期:2013-12-19 09:33:47
发表于 2012-05-29 17:14 |显示全部楼层
回复 51# firkraag


也就是说vma->pgoff在filemap与anon的时候是不一样的含义是吧
在anon的时候是vm_start/PAGE_SIZE

不知理解对不对


   

论坛徽章:
1
双鱼座
日期:2013-08-28 13:47:26
发表于 2012-05-29 17:17 |显示全部楼层
回复 52# embeddedlwp
是的。


   

论坛徽章:
16
2015亚冠之吉达阿赫利
日期:2015-08-17 11:21:462015年迎新春徽章
日期:2015-03-04 09:58:11酉鸡
日期:2014-12-07 09:06:19水瓶座
日期:2014-11-04 14:23:29天秤座
日期:2014-03-02 08:57:52双鱼座
日期:2014-02-22 13:07:56午马
日期:2014-02-14 11:08:18双鱼座
日期:2014-02-13 11:09:37卯兔
日期:2014-02-06 15:10:34子鼠
日期:2014-01-20 14:48:19戌狗
日期:2013-12-19 09:37:46射手座
日期:2013-12-19 09:33:47
发表于 2012-05-29 17:37 |显示全部楼层
回复 43# firkraag

忘记了是哪个帖子啦,能不能给个链接  


   

论坛徽章:
1
双鱼座
日期:2013-08-28 13:47:26
发表于 2012-05-29 17:44 |显示全部楼层

论坛徽章:
16
2015亚冠之吉达阿赫利
日期:2015-08-17 11:21:462015年迎新春徽章
日期:2015-03-04 09:58:11酉鸡
日期:2014-12-07 09:06:19水瓶座
日期:2014-11-04 14:23:29天秤座
日期:2014-03-02 08:57:52双鱼座
日期:2014-02-22 13:07:56午马
日期:2014-02-14 11:08:18双鱼座
日期:2014-02-13 11:09:37卯兔
日期:2014-02-06 15:10:34子鼠
日期:2014-01-20 14:48:19戌狗
日期:2013-12-19 09:37:46射手座
日期:2013-12-19 09:33:47
发表于 2012-05-29 21:31 |显示全部楼层
回复 55# firkraag

COW的page fault函数是do_wp_page函数,do_wp_page函数首先获取与缺页异常相关的页框描述符。在2.6.11代码中也就是一句:
pfn_to_page(pfn);
但是在2.6.24中确实下边庞大的函数,不知红色部分的注释怎么理解,比如什么叫raw PFN

/*
* This function gets the "struct page" associated with a pte.
*
* NOTE! Some mappings do not have "struct pages". A raw PFN mapping
* will have each page table entry just pointing to a raw page frame
* number, and as far as the VM layer is concerned, those do not have
* pages associated with them - even if the PFN might point to memory
* that otherwise is perfectly fine and has a "struct page".
*

* The way we recognize those mappings is through the rules set up
* by "remap_pfn_range()": the vma will have the VM_PFNMAP bit set,
* and the vm_pgoff will point to the first PFN mapped: thus every
* page that is a raw mapping will always honor the rule
*
*        pfn_of_page == vma->vm_pgoff + ((addr - vma->vm_start) >> PAGE_SHIFT)
*
* and if that isn't true, the page has been COW'ed (in which case it
* _does_ have a "struct page" associated with it even if it is in a
* VM_PFNMAP range).
*/
struct page *vm_normal_page(struct vm_area_struct *vma, unsigned long addr, pte_t pte)
{
        unsigned long pfn = pte_pfn(pte);

        if (unlikely(vma->vm_flags & VM_PFNMAP)) {
                unsigned long off = (addr - vma->vm_start) >> PAGE_SHIFT;
                if (pfn == vma->vm_pgoff + off)
                        return NULL;
                if (!is_cow_mapping(vma->vm_flags))
                        return NULL;
        }

#ifdef CONFIG_DEBUG_VM
        /*
         * Add some anal sanity checks for now. Eventually,
         * we should just do "return pfn_to_page(pfn)", but
         * in the meantime we check that we get a valid pfn,
         * and that the resulting page looks ok.
         */
        if (unlikely(!pfn_valid(pfn))) {
                print_bad_pte(vma, pte, addr);
                return NULL;
        }
#endif

        /*
         * NOTE! We still have PageReserved() pages in the page
         * tables.
         *
         * The PAGE_ZERO() pages and various VDSO mappings can
         * cause them to exist.
         */
        return pfn_to_page(pfn);
}

   

论坛徽章:
16
2015亚冠之吉达阿赫利
日期:2015-08-17 11:21:462015年迎新春徽章
日期:2015-03-04 09:58:11酉鸡
日期:2014-12-07 09:06:19水瓶座
日期:2014-11-04 14:23:29天秤座
日期:2014-03-02 08:57:52双鱼座
日期:2014-02-22 13:07:56午马
日期:2014-02-14 11:08:18双鱼座
日期:2014-02-13 11:09:37卯兔
日期:2014-02-06 15:10:34子鼠
日期:2014-01-20 14:48:19戌狗
日期:2013-12-19 09:37:46射手座
日期:2013-12-19 09:33:47
发表于 2012-05-29 21:38 |显示全部楼层
本帖最后由 embeddedlwp 于 2012-05-29 21:45 编辑

回复 55# firkraag

非线性内存映射主要用于什么场合?

在handle_pte_fault函数中,为什么根据pte设置_PAGE_FILE就可以确定是非线性内存映射:

if (pte_file(entry))
                        return do_nonlinear_fault(mm, vma, address,
                                        pte, pmd, write_access, entry);


   

论坛徽章:
1
双鱼座
日期:2013-08-28 13:47:26
发表于 2012-05-30 08:25 |显示全部楼层
本帖最后由 firkraag 于 2012-05-30 08:26 编辑

回复 57# embeddedlwp
这个_PAGE_FILE就是_PAGE_DIRTY,对于不存在于内存中的脏页(这种情况应该不存在吧),就认为是Non-Linear Memory Mapping页。
   
systemcall:
http://lwn.net/Articles/24468/

论坛徽章:
1
双鱼座
日期:2013-08-28 13:47:26
发表于 2012-05-30 08:53 |显示全部楼层
回复 56# embeddedlwp

见remap_pfn_range系统调用:
http://gnugeneration.com/books/linux/2.6.20/kernel-api/re286.html

就是直接修改页表项,让它指向一个页帧,不管该页帧是否与一个page结构相关。
   

论坛徽章:
1
双鱼座
日期:2013-08-28 13:47:26
发表于 2012-05-30 09:06 |显示全部楼层
回复 59# firkraag
感觉就是要满足这样一种需求:“不管这个物理页是否被使用,用户都要能看到它的内容,如果权限允许,还可以修改它。”
这样极端的需求给我的感觉就好像是在操作未经加工(raw)的物理页。

   
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP