memcg dirty_ratio and additional page statistics
Subsystems (6)
RFC PATCH 1/2 memcg dirty_ratio and additional page statistics
Collect dirty file and writeback pages to be used by memory cgroup dirty_ratio to evaluate dirty limits.
Moreover, the following entries are added to the file memory.stat of each cgroup to export these statistics to userspace:
- filedirty (number of dirty file pages)
- writeback (number of pages under writeback)
[ Note: currently only non-anonymous pages are accounted in writeback pages; for swapped-out pages with swap_writepage() it's not possible to retrieve the memory cgroup they belong to, so there would be a leak in writeback statistics if we also try to account these pages without changing too much stuff. ]
--- fs/buffer.c | 2 + fs/nfs/write.c | 4 + fs/nilfs2/page.h | 9 ++- fs/reiser4/as_ops.c | 5 +- fs/reiser4/page_cache.c | 5 +- include/linux/memcontrol.h | 76 ++++++++++++++++++ mm/filemap.c | 2 + mm/memcontrol.c | 187 ++++++++++++++++++++++++++++++++++++++++---- mm/page-writeback.c | 13 +++- mm/truncate.c | 2 + 10 files changed, 284 insertions(+), 21 deletions(-)
fs/buffer.c +2 -0
@@ -31,6 +31,7 @@#include <linux/highmem.h> #include <linux/module.h> #include <linux/writeback.h> +#include <linux/memcontrol.h> #include <linux/hash.h> #include <linux/suspend.h> #include <linux/buffer_head.h>
@@ -718,6 +719,7 @@ static int __set_page_dirty(struct page *page,WARN_ON_ONCE (warn && !PageUptodate (page));if (mapping_cap_account_dirty (mapping)) { +mem_cgroup_charge_file_dirty (page,1 );__inc_zone_page_state (page,NR_FILE_DIRTY );__inc_bdi_stat (mapping->backing_dev_info,BDI_RECLAIMABLE );
fs/nfs/write.c +4 -0
@@ -12,6 +12,7 @@#include <linux/pagemap.h> #include <linux/file.h> #include <linux/writeback.h> +#include <linux/memcontrol.h> #include <linux/swap.h> #include <linux/sunrpc/clnt.h>
@@ -410,6 +411,7 @@ nfs_mark_request_commit(struct nfs_page *req) req->wb_index, NFS_PAGE_TAG_COMMIT);spin_unlock (&inode->i_lock); +mem_cgroup_charge_file_dirty (req->wb_page,1 );inc_zone_page_state (req->wb_page,NR_UNSTABLE_NFS );inc_bdi_stat (req->wb_page->mapping->backing_dev_info,BDI_RECLAIMABLE );__mark_inode_dirty (inode,I_DIRTY_DATASYNC );
@@ -421,6 +423,7 @@ nfs_clear_request_commit(struct nfs_page *req)struct page *page = req->wb_page;if (test_and_clear_bit (PG_CLEAN , &(req)->wb_flags)) { +mem_cgroup_charge_file_dirty (page,-1 );dec_zone_page_state (page,NR_UNSTABLE_NFS );dec_bdi_stat (page->mapping->backing_dev_info,BDI_RECLAIMABLE );return 1 ;
@@ -1263,6 +1266,7 @@ nfs_commit_list(struct inode *inode, struct list_head *head, int how) req =nfs_list_entry (head->next);nfs_list_remove_request (req);nfs_mark_request_commit (req); +mem_cgroup_charge_file_dirty (page,-1 );dec_zone_page_state (req->wb_page,NR_UNSTABLE_NFS );dec_bdi_stat (req->wb_page->mapping->backing_dev_info,BDI_RECLAIMABLE );
fs/nilfs2/page.h +7 -2
@@ -24,6 +24,7 @@#ifndef _NILFS_PAGE_H#define _NILFS_PAGE_H +#include <linux/memcontrol.h> #include "nilfs.h" extern struct buffer_head *nilfs_get_page_block(struct page *, unsigned long,
@@ -68,8 +69,10 @@ nilfs_page_get_nth_block(struct page *page, unsigned int count)static inline void nilfs_set_page_writeback (struct page *page) {if (buffer_nilfs_allocated (page_buffers (page))) { -if (!TestSetPageWriteback (page)) +if (!TestSetPageWriteback (page)) { +mem_cgroup_charge_writeback (page,1 );inc_zone_page_state (page,NR_WRITEBACK ); + } }else set_page_writeback (page); }
@@ -77,8 +80,10 @@ static inline void nilfs_set_page_writeback(struct page *page)static inline void nilfs_end_page_writeback (struct page *page) {if (buffer_nilfs_allocated (page_buffers (page))) { -if (TestClearPageWriteback (page)) +if (TestClearPageWriteback (page)) { +mem_cgroup_charge_writeback (page,-1 );dec_zone_page_state (page,NR_WRITEBACK ); + } }else end_page_writeback (page); }
fs/reiser4/as_ops.c +4 -1
@@ -40,6 +40,7 @@#include <linux/init.h> #include <linux/module.h> #include <linux/writeback.h> +#include <linux/memcontrol.h> #include <linux/backing-dev.h> #include <linux/quotaops.h> #include <linux/security.h>
@@ -82,9 +83,11 @@ int reiser4_set_page_dirty(struct page *page)/* check for race with truncate */ if (page->mapping) {assert ("vs-1652" , page->mapping == mapping); -if (mapping_cap_account_dirty (mapping)) +if (mapping_cap_account_dirty (mapping)) { +mem_cgroup_charge_file_dirty (page,1 );inc_zone_page_state (page,NR_FILE_DIRTY ); + }radix_tree_tag_set (&mapping->page_tree, page->index,PAGECACHE_TAG_REISER4_MOVED );
fs/reiser4/page_cache.c +4 -1
@@ -202,6 +202,7 @@#include <linux/pagemap.h> #include <linux/bio.h> #include <linux/writeback.h> +#include <linux/memcontrol.h> #include <linux/blkdev.h> static struct bio *page_bio (struct page *,jnode * ,int rw,gfp_t gfp);
@@ -467,8 +468,10 @@ int reiser4_set_page_dirty_internal(struct page *page)BUG_ON (mapping ==NULL );if (!TestSetPageDirty (page)) { -if (mapping_cap_account_dirty (mapping)) +if (mapping_cap_account_dirty (mapping)) { +mem_cgroup_charge_file_dirty (page,1 );inc_zone_page_state (page,NR_FILE_DIRTY ); + }__mark_inode_dirty (mapping->host,I_DIRTY_PAGES ); }
include/linux/memcontrol.h +76 -0
97 lines not on this page · raw message
mm/filemap.c +2 -0
@@ -25,6 +25,7 @@#include <linux/uio.h> #include <linux/hash.h> #include <linux/writeback.h> +#include <linux/memcontrol.h> #include <linux/backing-dev.h> #include <linux/pagevec.h> #include <linux/blkdev.h>
@@ -131,6 +132,7 @@ void __remove_from_page_cache(struct page *page)* having removed the page entirely. */ if (PageDirty (page) &&mapping_cap_account_dirty (mapping)) { +mem_cgroup_charge_file_dirty (page,-1 );dec_zone_page_state (page,NR_FILE_DIRTY );dec_bdi_stat (mapping->backing_dev_info,BDI_RECLAIMABLE ); }
mm/memcontrol.c +172 -15
235 lines not on this page · raw message
mm/page-writeback.c +11 -2
@@ -25,6 +25,7 @@#include <linux/task_io_accounting_ops.h> #include <linux/blkdev.h> #include <linux/mpage.h> +#include <linux/memcontrol.h> #include <linux/rmap.h> #include <linux/percpu.h> #include <linux/notifier.h>
@@ -1090,6 +1091,7 @@ int __set_page_dirty_nobuffers(struct page *page)BUG_ON (mapping2 != mapping);WARN_ON_ONCE (!PagePrivate (page) && !PageUptodate (page));if (mapping_cap_account_dirty (mapping)) { +mem_cgroup_charge_file_dirty (page,1 );__inc_zone_page_state (page,NR_FILE_DIRTY );__inc_bdi_stat (mapping->backing_dev_info,BDI_RECLAIMABLE );
@@ -1234,6 +1236,7 @@ int clear_page_dirty_for_io(struct page *page)* for more comments. */ if (TestClearPageDirty (page)) { +mem_cgroup_charge_file_dirty (page,-1 );dec_zone_page_state (page,NR_FILE_DIRTY );dec_bdi_stat (mapping->backing_dev_info,BDI_RECLAIMABLE );
@@ -1269,8 +1272,11 @@ int test_clear_page_writeback(struct page *page) }else { ret =TestClearPageWriteback (page); } -if (ret) +if (ret) { +if (!PageAnon (page)) +mem_cgroup_charge_writeback (page,-1 );dec_zone_page_state (page,NR_WRITEBACK ); + }return ret; }
@@ -1300,8 +1306,11 @@ int test_set_page_writeback(struct page *page) }else { ret =TestSetPageWriteback (page); } -if (!ret) +if (!ret) { +if (!PageAnon (page)) +mem_cgroup_charge_writeback (page,1 );inc_zone_page_state (page,NR_WRITEBACK ); + }return ret; }
mm/truncate.c +2 -0
@@ -10,6 +10,7 @@#include <linux/kernel.h> #include <linux/backing-dev.h> #include <linux/mm.h> +#include <linux/memcontrol.h> #include <linux/swap.h> #include <linux/module.h> #include <linux/pagemap.h>
@@ -73,6 +74,7 @@ void cancel_dirty_page(struct page *page, unsigned int account_size)if (TestClearPageDirty (page)) {struct address_space *mapping = page->mapping;if (mapping &&mapping_cap_account_dirty (mapping)) { +mem_cgroup_charge_file_dirty (page,-1 );dec_zone_page_state (page,NR_FILE_DIRTY );dec_bdi_stat (mapping->backing_dev_info,BDI_RECLAIMABLE );
Signature · 1 line
1.5.4.3