免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
123下一页
最近访问板块 发新帖
查看: 8082 | 回复: 21

[内存管理] linux pte 的L_PTE_YOUNG作用 [复制链接]

论坛徽章:
0
发表于 2013-06-05 09:54 |显示全部楼层
linux pte 的L_PTE_YOUNG作用
看了下代码,发现只有在确页异常anon ,file map, 分配page的时候才会至位。

然后,在pfra中,page _check_reference回收anon page,file page的时候会看page相应的young pte数目。并且清除相应的pte的young标志。
假设没有swap的话,那么只要page没有young的pte,而不管page的PAGE_REFERENCED标志,page就肯定会被释放(或者active 到 inactive lru)
那么,young标志是否是一次性标志呢?真没有其他地方设置了?


假设 young标志不会再设置了。对于anon,filemap的page,如果在用户态多次访问,kernel如何知道他是被多次访问的,而不应该释放掉?


static enum page_references page_check_references(struct page *page,
                                                  struct scan_control *sc)
{
        int referenced_ptes, referenced_page;
        unsigned long vm_flags;

        referenced_ptes = page_referenced(page, 1, sc->mem_cgroup, &vm_flags);
        referenced_page = TestClearPageReferenced(page);

        /* Lumpy reclaim - ignore references */
        if (sc->reclaim_mode & RECLAIM_MODE_LUMPYRECLAIM)
                return PAGEREF_RECLAIM;

        /*
         * Mlock lost the isolation race with us.  Let try_to_unmap()
         * move the page to the unevictable list.
         */
        if (vm_flags & VM_LOCKED)
                return PAGEREF_RECLAIM;

        if (referenced_ptes) {
                if (PageAnon(page))
                        return PAGEREF_ACTIVATE;
                /*
                 * All mapped pages start out with page table
                 * references from the instantiating fault, so we need
                 * to look twice if a mapped file page is used more
                 * than once.
                 *
                 * Mark it and spare it for another trip around the
                 * inactive list.  Another page table reference will
                 * lead to its activation.
                 *
                 * Note: the mark is set for activated pages as well
                 * so that recently deactivated but used pages are
                 * quickly recovered.
                 */
                SetPageReferenced(page);

                if (referenced_page)
                        return PAGEREF_ACTIVATE;

                return PAGEREF_KEEP;
        }

        /* Reclaim if clean, defer dirty pages to writeback */
        if (referenced_page && !PageSwapBacked(page))
                return PAGEREF_RECLAIM_CLEAN;

        return PAGEREF_RECLAIM;
}

论坛徽章:
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
发表于 2013-06-05 15:56 |显示全部楼层
本帖最后由 embeddedlwp 于 2013-06-05 15:57 编辑

回复 1# blake326


如果没有swap,anon不会被扫描。

看get_scan_count中的: if (!sc->may_swap || (get_nr_swap_pages() <= 0))
3.10-rc4

论坛徽章:
0
发表于 2013-06-05 16:46 |显示全部楼层
回复 2# embeddedlwp


    这个我知道。但是和我关心的问题关系不大。

   我的问题是:
1。linux pte L_PTE_YOUNG 有哪些情况设置?
2。linux 如何区分经常访问的anon和file map page。让pfra不要像随便一个不经常访问的anon file map page一样对待。

论坛徽章:
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
发表于 2013-06-05 17:39 |显示全部楼层
本帖最后由 embeddedlwp 于 2013-06-06 14:27 编辑

回复 3# blake326


这个我知道。但是和我关心的问题关系不大。

===========================
你提到swap,貌似跟你的问题关系也不大。

1。linux pte L_PTE_YOUNG 有哪些情况设置?

========================================
貌似只有arm会用啊,你自己grep一下啊

2。linux 如何区分经常访问的anon和file map page。让pfra不要像随便一个不经常访问的anon file map page一样对待。

=======================================
map的page在回收的时候也就是page_check_references中才会检查。

针对于architectures没有hardware track的情况.
第一次访问的时候,产生major fault, page fault设置young bit,shrink_active_list调用page_referenced,page_referenced_one会清掉young bit,相当于unmap
第二次访问的时候,产生minor fault, page fault设置young bit,之后如果page到inacitve list的末尾,page_check_references会active page。
针对有architectures hardware track的情况.
第一次访问的时候cpu设置access bit,产生major fault,shrink_active_list调用page_referenced,page_referenced_one会清掉access bit
第二次访问cpu会设置access bit, 之后如果page到inacitve list的末尾,page_check_references会active page。

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

回复 3# blake326
I don't konw whether these comments can help you:

The "accessed" or "young" bit is emulated by a similar method; we only
allow accesses to the page if the "young" bit is set.  Accesses to the
page will cause a fault, and handle_pte_fault() will set the young bit
for us as long as the page is marked present in the corresponding Linux
PTE entry.  Again, ptep_set_access_flags() will ensure that the TLB is
up to date.

However, when the "young" bit is cleared, we deny access to the page
by clearing the hardware PTE.  Currently Linux does not flush the TLB
for us in this case, which means the TLB will retain the transation
until either the TLB entry is evicted under pressure, or a context
switch which changes the user space mapping occurs.


Or you can google this: "ARM Linux 如何模拟X86 PTE中的Present Young和Dirty标志位"

   

论坛徽章:
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
发表于 2013-06-05 18:10 |显示全部楼层
本帖最后由 embeddedlwp 于 2013-06-05 18:11 编辑

回复 5# firkraag


x86**young bit? 应该是access bit

   

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

回复 6# embeddedlwp

The comments are for arm architecture.

论坛徽章:
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
发表于 2013-06-05 18:22 |显示全部楼层
回复 5# firkraag


打不开你那个链接,能帮我把内容粘过来吗,谢谢啦

   

论坛徽章:
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
发表于 2013-06-05 18:23 |显示全部楼层
回复 7# firkraag


我是说“ARM Linux 如何模拟X86 PTE中的Present Young和Dirty标志位”


   

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

回复 8# embeddedlwp

use this: "http://proxyie.cn/" to climb over the damned gfw.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP