亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊(cè) 查看新帖 |

Chinaunix

  平臺(tái) 論壇 博客 文庫
123下一頁
最近訪問板塊 發(fā)新帖
查看: 8308 | 回復(fù): 23
打印 上一主題 下一主題

[內(nèi)存管理] 請(qǐng)教pagecache的writeback問題 [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2013-03-27 10:00 |只看該作者 |倒序?yàn)g覽
本帖最后由 leil 于 2013-03-27 10:16 編輯

如果一個(gè)page,正在被writeback,這時(shí)候上層應(yīng)用正好又要寫這個(gè)page。系統(tǒng)是如何保證互斥的?

上層應(yīng)用寫page的時(shí)候,是在page lock保護(hù)下進(jìn)行。
但submit_bio()將page提交給下面后,已經(jīng)不再會(huì)有page lock加/解鎖操作了。
所以很納悶。

論壇徽章:
0
2 [報(bào)告]
發(fā)表于 2013-03-27 10:50 |只看該作者
generic_perform_write()
->ext2_write_begin()
->grab_cache_page_write_begin()
如果這個(gè)時(shí)候發(fā)現(xiàn)page的PG_Writeback被設(shè)置了就會(huì)等待知道完成。
/*
* Wait for a page to complete writeback
*/
static inline void wait_on_page_writeback(struct page *page)
{
        if (PageWriteback(page))
                wait_on_page_bit(page, PG_writeback);
}



//////////////////////////////////////////////////////////////////
bdi回寫的時(shí)候:
wb_do_writeback()
->__writeback_single_inode()
->do_writepages
->ext2_writepage()  //mapping->a_ops->writepage
->block_write_full_page_endio  //這個(gè)里面會(huì)先設(shè)置page的PG_writeback標(biāo)志。
->submit_bh
->submit_bio


///////////////////////
驅(qū)動(dòng)完成寫請(qǐng)求后,執(zhí)行bh回調(diào)
end_buffer_async_write()
如果page內(nèi)相關(guān)的所有bh都是最新的了,則調(diào)用end_page_writeback清楚標(biāo)志進(jìn)行喚醒。
void end_page_writeback(struct page *page)
{
        if (TestClearPageReclaim(page))
                rotate_reclaimable_page(page);

        if (!test_clear_page_writeback(page))
                BUG();

        smp_mb__after_clear_bit();
        wake_up_page(page, PG_writeback);
}


評(píng)分

參與人數(shù) 1可用積分 +4 收起 理由
瀚海書香 + 4 贊一個(gè)!

查看全部評(píng)分

論壇徽章:
0
3 [報(bào)告]
發(fā)表于 2013-03-27 11:10 |只看該作者
本帖最后由 leil 于 2013-03-27 11:12 編輯

我是以ext3來看的:
generic_perform_write()
  ->ext3_write_begin()
      ->grab_cache_page_write_begin()                                   獲取到page lock,沒看到有wait on page writeback動(dòng)作。
      ->block_write_begin()->__block_prepare_write()             將數(shù)據(jù)寫到page中去。
  ->ext3_writeback_write_end()                                              解鎖page lock

我也仔細(xì)看了如上流程,反正是沒看到有wait on page writeback的地方。
難道還有看漏的地方?
BTW,我看的代碼是2.6.32系列。

論壇徽章:
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
4 [報(bào)告]
發(fā)表于 2013-03-27 11:11 |只看該作者
本帖最后由 chishanmingshen 于 2013-03-27 11:13 編輯

怎么判斷所有的bh的?

buffer_async_write():怎么找不到這個(gè)函數(shù)的定義?

回復(fù) 2# blake326


   

論壇徽章:
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 [報(bào)告]
發(fā)表于 2013-03-27 11:23 |只看該作者

/*
* Find or create a page at the given pagecache position. Return the locked
* page. This function is specifically for buffered writes.
*/
struct page *grab_cache_page_write_begin(struct address_space *mapping,
                                        pgoff_t index, unsigned flags)
{
        int status;
        gfp_t gfp_mask;
        struct page *page;
        gfp_t gfp_notmask = 0;

        gfp_mask = mapping_gfp_mask(mapping);
        if (mapping_cap_account_dirty(mapping))
                gfp_mask |= __GFP_WRITE;
        if (flags & AOP_FLAG_NOFS)
                gfp_notmask = __GFP_FS;
repeat:
        page = find_lock_page(mapping, index);
        if (page)
                goto found;

        page = __page_cache_alloc(gfp_mask & ~gfp_notmask);
        if (!page)
                return NULL;
        status = add_to_page_cache_lru(page, mapping, index,
                                                GFP_KERNEL & ~gfp_notmask);
        if (unlikely(status)) {
                page_cache_release(page);
                if (status == -EEXIST)
                        goto repeat;
                return NULL;
        }
found:
        wait_on_page_writeback(page);<------------------HERE
        return page;
}

FROM KERNEL 3.7


回復(fù) 3# leil


   

論壇徽章:
0
6 [報(bào)告]
發(fā)表于 2013-03-27 11:38 |只看該作者
kernel 3.0

int block_write_full_page(struct page *page, get_block_t *get_block,
                        struct writeback_control *wbc)
{
        return block_write_full_page_endio(page, get_block, wbc, end_buffer_async_write);
}
....
mark_buffer_async_write_endio(bh, end_buffer_async_write);

end_buffer_async_write() {
.....
        first = page_buffers(page);
        local_irq_save(flags);
        bit_spin_lock(BH_Uptodate_Lock, &first->b_state);

        clear_buffer_async_write(bh);
        unlock_buffer(bh);
        tmp = bh->b_this_page; //這個(gè)地方在循環(huán)page上所有的bh,有bh還在async write的話,就不會(huì)清除page的writeback。
        while (tmp != bh) {
                if (buffer_async_write(tmp)) {
                        BUG_ON(!buffer_locked(tmp));
                        goto still_busy;
                }
                tmp = tmp->b_this_page;
        }
        bit_spin_unlock(BH_Uptodate_Lock, &first->b_state);
        local_irq_restore(flags);
        end_page_writeback(page);
        return;

論壇徽章:
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 [報(bào)告]
發(fā)表于 2013-03-27 12:27 |只看該作者
有2個(gè)疑問。。。請(qǐng)指點(diǎn)下,謝謝。

1. 這里的tmp只是在入?yún)⒅付ǖ腷h之前的所有bh啊,貌似并不是該page的全部bh。

2. buffer_async_write定義在哪里?找不到定義的地方?

回復(fù) 6# blake326


   

論壇徽章:
0
8 [報(bào)告]
發(fā)表于 2013-03-27 12:37 |只看該作者
struct page *grab_cache_page_write_begin(struct address_space *mapping,
                                        pgoff_t index, unsigned flags)
{
        int status;
        struct page *page;
        gfp_t gfp_notmask = 0;
        if (flags & AOP_FLAG_NOFS)
                gfp_notmask = __GFP_FS;
repeat:
        page = find_lock_page(mapping, index);
        if (likely(page))
                return page;

        page = __page_cache_alloc(mapping_gfp_mask(mapping) & ~gfp_notmask);
        if (!page)
                return NULL;
        status = add_to_page_cache_lru(page, mapping, index,
                                                GFP_KERNEL & ~gfp_notmask);
        if (unlikely(status)) {
                page_cache_release(page);
                if (status == -EEXIST)
                        goto repeat;
                return NULL;
        }
        return page;
}
EXPORT_SYMBOL(grab_cache_page_write_begin);

這是我看的sles11sp1的代碼?礃幼邮前姹局g的差異了。

論壇徽章:
0
9 [報(bào)告]
發(fā)表于 2013-03-27 15:25 |只看該作者
回復(fù) 7# chishanmingshen

1.
tmp = bh->b_this_page;
b_this_page指向當(dāng)前bh的下一個(gè)bh。通過b_this_page可以遍歷page上的所有bh。

2.
這是宏定義的,在buffer_head.h中:
#define BUFFER_FNS(bit, name)                                                \
static inline void set_buffer_##name(struct buffer_head *bh)                \
{                                                                        \
        set_bit(BH_##bit, &(bh)->b_state);                                \
}                                                                        \
static inline void clear_buffer_##name(struct buffer_head *bh)                \
{                                                                        \
        clear_bit(BH_##bit, &(bh)->b_state);                                \
}                                                                        \
static inline int buffer_##name(const struct buffer_head *bh)                \
{                                                                        \
        return test_bit(BH_##bit, &(bh)->b_state);                        \
}

BUFFER_FNS(Async_Write, async_write)



   

論壇徽章:
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
10 [報(bào)告]
發(fā)表于 2013-03-27 16:16 |只看該作者
謝謝指點(diǎn)。。。。

回復(fù) 9# blake326


   
您需要登錄后才可以回帖 登錄 | 注冊(cè)

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號(hào)-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號(hào):11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國互聯(lián)網(wǎng)協(xié)會(huì)會(huì)員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請(qǐng)注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP