免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2269 | 回复: 6
打印 上一主题 下一主题

[内存管理] 对shrink_page_list的疑问。。。。 [复制链接]

论坛徽章:
4
酉鸡
日期:2014-03-21 23:19:50狮子座
日期:2014-08-01 22:11:40酉鸡
日期:2015-01-10 21:31:442015年辞旧岁徽章
日期:2015-03-03 16:54:15
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2013-05-06 11:23 |只看该作者 |倒序浏览
本帖最后由 chishanmingshen 于 2013-05-07 08:41 编辑

shrink_page_list()->page_has_private(page)

page_has_private(page)表示跟buffer是有关系,怎么个有关系啊?求详解。。。谢谢!

此类page包括哪些?






论坛徽章:
6
金牛座
日期:2013-10-08 10:19:10技术图书徽章
日期:2013-10-14 16:24:09CU十二周年纪念徽章
日期:2013-10-24 15:41:34狮子座
日期:2013-11-24 19:26:19未羊
日期:2014-01-23 15:50:002015年亚洲杯之阿联酋
日期:2015-05-09 14:36:15
2 [报告]
发表于 2013-05-07 09:05 |只看该作者
回复 1# chishanmingshen
shrink_page_list()->page_has_private(page)

page_has_private(page)表示跟buffer是有关系,怎么个有关系啊?求详解。。。谢谢!

此类page包括哪些?


page_has_private表示PG_private 或者PG_private_2被置位。
其中PG_private置位的情形:
        page对应的pagecache,并且pagecache对应的磁盘物理块不连续。block_read_full_page->create_empty_buffers-->attach_page_buffers

   

论坛徽章:
4
酉鸡
日期:2014-03-21 23:19:50狮子座
日期:2014-08-01 22:11:40酉鸡
日期:2015-01-10 21:31:442015年辞旧岁徽章
日期:2015-03-03 16:54:15
3 [报告]
发表于 2013-05-07 09:44 |只看该作者
本帖最后由 chishanmingshen 于 2013-05-07 11:22 编辑

回复 2# 瀚海书香

from 3.9
static inline int page_has_private(struct page *page)
{
        return !!(page->flags & PAGE_FLAGS_PRIVATE);
}

shrink_page_list():
                /*
                 * If the page has buffers, try to free the buffer mappings
                 * associated with this page. If we succeed we try to free
                 * the page as well.
                 *
                 * We do this even if the page is PageDirty().
                 * try_to_release_page() does not perform I/O, but it is
                 * possible for a page to have PageDirty set, but it is actually
                 * clean (all its buffers are clean).  This happens if the
                 * buffers were written out directly, with submit_bh(). ext3
                 * will do this, as well as the blockdev mapping.
                 * try_to_release_page() will discover that cleanness and will
                 * drop the buffers and mark the page clean - it can be freed.
                 *
                 * Rarely, pages can have buffers and no ->mapping.  These are
                 * the pages which were not successfully invalidated in
                 * truncate_complete_page().  We try to drop those buffers here
                 * and if that worked, and the page is no longer mapped into
                 * process address space (page_count == 1) it can be freed.
                 * Otherwise, leave the page on the LRU so it is swappable.
                 */
                if (page_has_private(page)) {这里应该是跟文件相关的。。。
                        if (!try_to_release_page(page, sc->gfp_mask))
                                goto activate_locked;
                        if (!mapping && page_count(page) == 1) {这里mapping为空,注释里的error case?
                                unlock_page(page);
                                if (put_page_testzero(page))
                                        goto free_it;
                                else {
                                        /*
                                         * rare race with speculative reference.
                                         * the speculative reference will free
                                         * this page shortly, so we may
                                         * increment nr_reclaimed here (and
                                         * leave it off the LRU).
                                         */
                                        nr_reclaimed++;
                                        continue;
                                }
                        }
                }


怎么理解这段对于此类page的处理?一直没想明白。。。。
   

论坛徽章:
6
金牛座
日期:2013-10-08 10:19:10技术图书徽章
日期:2013-10-14 16:24:09CU十二周年纪念徽章
日期:2013-10-24 15:41:34狮子座
日期:2013-11-24 19:26:19未羊
日期:2014-01-23 15:50:002015年亚洲杯之阿联酋
日期:2015-05-09 14:36:15
4 [报告]
发表于 2013-05-08 09:05 |只看该作者
回复 3# chishanmingshen
如果page有相关的buffer链表,那么需要释放掉buffer链表。如果释放成功,判断该页面有没有引用,如果没有引用将该页放到空闲列表中。

   

论坛徽章:
4
酉鸡
日期:2014-03-21 23:19:50狮子座
日期:2014-08-01 22:11:40酉鸡
日期:2015-01-10 21:31:442015年辞旧岁徽章
日期:2015-03-03 16:54:15
5 [报告]
发表于 2013-05-08 10:11 来自手机 |只看该作者
why need "!mapping" ? thanks

论坛徽章:
6
金牛座
日期:2013-10-08 10:19:10技术图书徽章
日期:2013-10-14 16:24:09CU十二周年纪念徽章
日期:2013-10-24 15:41:34狮子座
日期:2013-11-24 19:26:19未羊
日期:2014-01-23 15:50:002015年亚洲杯之阿联酋
日期:2015-05-09 14:36:15
6 [报告]
发表于 2013-05-08 12:03 |只看该作者
回复 5# chishanmingshen
why need "!mapping" ?

首先需要明白这个mapping变量的函数,在shrink_page_list中
mapping == NULL, 表示该页面是匿名映射页,不映射到任何物理存储。
mapping != NULL,表示该页要么在swap cache中,要么在page cache中。

那么在回收页面的时候,如果mapping == NULL,就可以直接将页面释放到空闲链表中。(从作者的注释也可以看到,对于有buffers的页面来说,mapping == NULL的情况是非常少的,这些页面的产生"These are pages which were not successfully invalidated in truncate_complete_page()”)。
如果mapping != NULL,那么在回收页面之前就需要将页面从swap cache或page cache中移除(对应的函数就是__remove_mapping),才能释放到空闲链表中。
   

论坛徽章:
4
酉鸡
日期:2014-03-21 23:19:50狮子座
日期:2014-08-01 22:11:40酉鸡
日期:2015-01-10 21:31:442015年辞旧岁徽章
日期:2015-03-03 16:54:15
7 [报告]
发表于 2013-05-08 12:51 来自手机 |只看该作者
en,此种rare case可以直接将页面释放到空闲链表中.
此种case的理解可能需要对文件系统的了解吧,呵呵。

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

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP