memcg: per cgroup dirty page limiting
Subsystems (12)
v9 cover memcg: per cgroup dirty page limiting
This patch series provides the ability for each cgroup to have independent dirty page usage limits. Limiting dirty memory fixes the max amount of dirty (hard to reclaim) page cache used by a cgroup. This allows for better per cgroup memory isolation and fewer memcg OOMs.
Three features are included in this patch series:
1. memcg dirty page accounting
2. memcg writeback
3. memcg dirty page limiting
1. memcg dirty page accounting
Each memcg maintains a dirty page count and dirty page limit. Previous iterations of this patch series have refined this logic. The interface is similar to the procfs interface: /proc/sys/vm/dirty_*. It is possible to configure a limit to trigger throttling of a dirtier or queue background writeback. The root cgroup memory.dirty_* control files are read-only and match the contents of the /proc/sys/vm/dirty_* files.
2. memcg writeback
Having per cgroup dirty memory limits is not very interesting unless writeback is also cgroup aware. There is not much isolation if cgroups have to writeback data from outside the affected cgroup to get below the cgroup dirty memory threshold.
Per-memcg dirty limits are provided to support isolation and thus cross cgroup inode sharing is not a priority. This allows the code be simpler.
To add cgroup awareness to writeback, this series adds an i_memcg field to struct address_space to allow writeback to isolate inodes for a particular cgroup. When an inode is marked dirty, i_memcg is set to the current cgroup. When inode pages are marked dirty the i_memcg field is compared against the page's cgroup. If they differ, then the inode is marked as shared by setting i_memcg to a special shared value (zero).
When performing per-memcg writeback, move_expired_inodes() scans the per bdi b_dirty list using each inode's i_memcg and the global over-limit memcg bitmap to determine if the inode should be written. This inode scan may involve skipping many unrelated inodes from other cgroup. To test the scanning overhead, I created two cgroups (cgroup_A with 100,000 dirty inodes under A's dirty limit, cgroup_B with 1 inode over B's dirty limit). The writeback code then had to skip 100,000 inodes when balancing cgroup_B to find the one inode that needed writing. This scanning took 58 msec to skip 100,000 foreign inodes.
3. memcg dirty page limiting
balance_dirty_pages() calls mem_cgroup_balance_dirty_pages(), which checks the dirty usage vs dirty thresholds for the current cgroup and its parents. As cgroups exceed their background limit, they are marked in a global over-limit bitmap (indexed by cgroup id) and the bdi flusher is awoke. As a cgroup hits is foreground limit, the task is throttled while performing foreground writeback on inodes owned by the over-limit cgroup. If mem_cgroup_balance_dirty_pages() is unable to get below the dirty page threshold writing per-memcg inodes, then downshifts to also writing shared inodes (i_memcg=0).
I know that there is some significant IO-less balance_dirty_pages() changes. I am not trying to derail that effort. I have done moderate functional testing of the newly proposed features.
The memcg aspects of this patch are pretty mature. The writeback aspects are still fairly new and need feedback from the writeback community. These features are linked, so it's not clear which branch to send the changes to (the writeback development branch or mmotm).
Here is an example of the memcg OOM that is avoided with this patch series:
# mkdir /dev/cgroup/memory/x
# echo 100M > /dev/cgroup/memory/x/memory.limit_in_bytes
# echo $$ > /dev/cgroup/memory/x/tasks
# dd if=/dev/zero of=/data/f1 bs=1k count=1M &
# dd if=/dev/zero of=/data/f2 bs=1k count=1M &
# wait
[1]- Killed dd if=/dev/zero of=/data/f1 bs=1M count=1k
[2]+ Killed dd if=/dev/zero of=/data/f1 bs=1M count=1kChanges since -v8:
- Reordered patches for better more readability.
- No longer passing struct writeback_control into memcontrol functions. Instead the needed attributes (memcg_id, etc.) are explicitly passed in. Therefore no more field additions to struct writeback_control.
- Replaced 'Andrea Righi <[email protected]>' with 'Andrea Righi <[email protected]>' in commit descriptions.
- Rebased to mmotm-2011-08-02-16-19
Greg Thelen (13):
memcg: document cgroup dirty memory interfaces
memcg: add page_cgroup flags for dirty page tracking
memcg: add dirty page accounting infrastructure
memcg: add kernel calls for memcg dirty page stats
memcg: add mem_cgroup_mark_inode_dirty()
memcg: add dirty limits to mem_cgroup
memcg: add cgroupfs interface to memcg dirty limits
memcg: dirty page accounting support routines
memcg: create support routines for writeback
writeback: pass wb_writeback_work into move_expired_inodes()
writeback: make background writeback cgroup aware
memcg: create support routines for page writeback
memcg: check memcg dirty limits in page writeback
Documentation/cgroups/memory.txt | 70 ++++ fs/buffer.c | 2 +- fs/fs-writeback.c | 113 ++++-- fs/inode.c | 3 + fs/nfs/write.c | 4 + fs/sync.c | 2 +- include/linux/cgroup.h | 1 + include/linux/fs.h | 9 + include/linux/memcontrol.h | 64 +++- include/linux/page_cgroup.h | 23 ++ include/linux/writeback.h | 9 +- include/trace/events/memcontrol.h | 207 ++++++++++ kernel/cgroup.c | 1 - mm/backing-dev.c | 3 +- mm/filemap.c | 1 + mm/memcontrol.c | 760 ++++++++++++++++++++++++++++++++++++- mm/page-writeback.c | 44 ++- mm/truncate.c | 1 + mm/vmscan.c | 5 +- 19 files changed, 1265 insertions(+), 57 deletions(-) create mode 100644 include/trace/events/memcontrol.h
Signature · 8 lines
1.7.3.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v9 1/13 memcg: document cgroup dirty memory interfaces
Document cgroup dirty memory interfaces and statistics.
The implementation for these new interfaces routines comes in a series of following patches.
--- Documentation/cgroups/memory.txt | 70 ++++++++++++++++++++++++++++++++++++++ 1 files changed, 70 insertions(+), 0 deletions(-)
Documentation/cgroups/memory.txt +70 -0
@@ -389,6 +389,10 @@ mapped_file - # of bytes of mapped file (includes tmpfs/shmem) pgpgin - # of pages paged in (equivalent to # of charging events). pgpgout - # of pages paged out (equivalent to # of uncharging events). swap - # of bytes of swap usage +dirty - # of bytes that are waiting to get written back to the disk. +writeback - # of bytes that are actively being written back to the disk. +nfs_unstable - # of bytes sent to the NFS server, but not yet committed to + the actual storage. inactive_anon - # of bytes of anonymous memory and swap cache memory on LRU list. active_anon - # of bytes of anonymous and swap cache memory on active
@@ -410,6 +414,9 @@ total_mapped_file - sum of all children's "cache" total_pgpgin - sum of all children's "pgpgin" total_pgpgout - sum of all children's "pgpgout" total_swap - sum of all children's "swap" +total_dirty - sum of all children's "dirty" +total_writeback - sum of all children's "writeback" +total_nfs_unstable - sum of all children's "nfs_unstable" total_inactive_anon - sum of all children's "inactive_anon" total_active_anon - sum of all children's "active_anon" total_inactive_file - sum of all children's "inactive_file"
@@ -567,6 +574,69 @@ unevictable=<total anon pages> N0=<node 0 pages> N1=<node 1 pages> ... And we have total = file + anon + unevictable. +5.7 dirty memory + +Control the maximum amount of dirty pages a cgroup can have at any given time. + +Limiting dirty memory is like fixing the max amount of dirty (hard to reclaim) +page cache used by a cgroup. So, in case of multiple cgroup writers, they will +not be able to consume more than their designated share of dirty pages and will +be throttled if they cross that limit. System-wide dirty limits are also +consulted. Dirty memory consumption is checked against both system-wide and +per-cgroup dirty limits. + +The interface is similar to the procfs interface: /proc/sys/vm/dirty_*. It is +possible to configure a limit to trigger throttling of a dirtier or queue +background writeback. The root cgroup memory.dirty_* control files are +read-only and match the contents of the /proc/sys/vm/dirty_* files. + +Per-cgroup dirty limits can be set using the following files in the cgroupfs: + +- memory.dirty_ratio: the amount of dirty memory (expressed as a percentage of + cgroup memory) at which a process generating dirty pages will be throttled. + The default value is the system-wide dirty ratio, /proc/sys/vm/dirty_ratio. + +- memory.dirty_limit_in_bytes: the amount of dirty memory (expressed in bytes) + in the cgroup at which a process generating dirty pages will be throttled. + Suffix (k, K, m, M, g, or G) can be used to indicate that value is kilo, mega + or gigabytes. The default value is the system-wide dirty limit, + /proc/sys/vm/dirty_bytes. + + Note: memory.dirty_limit_in_bytes is the counterpart of memory.dirty_ratio. + Only one may be specified at a time. When one is written it is immediately + taken into account to evaluate the dirty memory limits and the other appears + as 0 when read. + +- memory.dirty_background_ratio: the amount of dirty memory of the cgroup + (expressed as a percentage of cgroup memory) at which background writeback + kernel threads will start writing out dirty data. The default value is the + system-wide background dirty ratio, /proc/sys/vm/dirty_background_ratio. + +- memory.dirty_background_limit_in_bytes: the amount of dirty memory (expressed + in bytes) in the cgroup at which background writeback kernel threads will + start writing out dirty data. Suffix (k, K, m, M, g, or G) can be used to + indicate that value is kilo, mega or gigabytes. The default value is the + system-wide dirty background limit, /proc/sys/vm/dirty_background_bytes. + + Note: memory.dirty_background_limit_in_bytes is the counterpart of + memory.dirty_background_ratio. Only one may be specified at a time. When one + is written it is immediately taken into account to evaluate the dirty memory + limits and the other appears as 0 when read. + +A cgroup may contain more dirty memory than its dirty limit. This is possible +because of the principle that the first cgroup to touch a page is charged for +it. Subsequent page counting events (dirty, writeback, nfs_unstable) are also +counted to the originally charged cgroup. Example: If page is allocated by a +cgroup A task, then the page is charged to cgroup A. If the page is later +dirtied by a task in cgroup B, then the cgroup A dirty count will be +incremented. If cgroup A is over its dirty limit but cgroup B is not, then +dirtying a cgroup A page from a cgroup B task may push cgroup A over its dirty +limit without throttling the dirtying cgroup B task. + +When use_hierarchy=0, each cgroup has independent dirty memory usage and limits. +When use_hierarchy=1 the dirty limits of parent cgroups are also checked to +ensure that no dirty limit is exceeded. + 6. Hierarchy support The memory controller supports a deep hierarchy and hierarchical accounting.
Signature · 8 lines
1.7.3.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v9 2/13 memcg: add page_cgroup flags for dirty page tracking
In reply to Greg ThelenAdd additional flags to page_cgroup to track dirty pages within a mem_cgroup.
--- include/linux/page_cgroup.h | 23 +++++++++++++++++++++++ 1 files changed, 23 insertions(+), 0 deletions(-)
include/linux/page_cgroup.h +23 -0
@@ -10,6 +10,9 @@ enum {/* flags for mem_cgroup and file and I/O status */ PCG_MOVE_LOCK ,/* For race between move_account v.s. following bits */ PCG_FILE_MAPPED ,/* page is accounted as "mapped" */ +PCG_FILE_DIRTY ,/* page is dirty */ +PCG_FILE_WRITEBACK ,/* page is under writeback */ +PCG_FILE_UNSTABLE_NFS ,/* page is NFS unstable */ /* No lock in page_cgroup */ PCG_ACCT_LRU ,/* page has been accounted for (under lru_lock) */ __NR_PCG_FLAGS,
@@ -67,6 +70,10 @@ static inline void ClearPageCgroup##uname(struct page_cgroup *pc) \ static inline int TestClearPageCgroup##uname(struct page_cgroup *pc) \ { return test_and_clear_bit(PCG_##lname, &pc->flags); } +#define TESTSETPCGFLAG (uname, lname) \ +static inline int TestSetPageCgroup##uname(struct page_cgroup *pc) \ + { return test_and_set_bit(PCG_##lname, &pc->flags); } +/* Cache flag is set only once (at allocation) */ TESTPCGFLAG(Cache, CACHE)CLEARPCGFLAG (Cache,CACHE )
@@ -86,6 +93,22 @@ SETPCGFLAG(FileMapped, FILE_MAPPED) CLEARPCGFLAG(FileMapped, FILE_MAPPED) TESTPCGFLAG(FileMapped, FILE_MAPPED) +SETPCGFLAG(FileDirty, FILE_DIRTY) +CLEARPCGFLAG(FileDirty, FILE_DIRTY) +TESTPCGFLAG(FileDirty, FILE_DIRTY) +TESTCLEARPCGFLAG(FileDirty, FILE_DIRTY) +TESTSETPCGFLAG(FileDirty, FILE_DIRTY) + +SETPCGFLAG(FileWriteback, FILE_WRITEBACK) +CLEARPCGFLAG(FileWriteback, FILE_WRITEBACK) +TESTPCGFLAG(FileWriteback, FILE_WRITEBACK) + +SETPCGFLAG(FileUnstableNFS, FILE_UNSTABLE_NFS) +CLEARPCGFLAG(FileUnstableNFS, FILE_UNSTABLE_NFS) +TESTPCGFLAG(FileUnstableNFS, FILE_UNSTABLE_NFS) +TESTCLEARPCGFLAG(FileUnstableNFS, FILE_UNSTABLE_NFS) +TESTSETPCGFLAG(FileUnstableNFS, FILE_UNSTABLE_NFS) + SETPCGFLAG(Migration, MIGRATION) CLEARPCGFLAG(Migration, MIGRATION)TESTPCGFLAG (Migration,MIGRATION )
Signature · 8 lines
1.7.3.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v9 3/13 memcg: add dirty page accounting infrastructure
In reply to Greg ThelenAdd memcg routines to count dirty, writeback, and unstable_NFS pages. These routines are not yet used by the kernel to count such pages. A later change adds kernel calls to these new routines.
As inode pages are marked dirty, if the dirtied page's cgroup differs from the inode's cgroup, then mark the inode shared across several cgroup.
---
Changelog since v8:
- In v8 this patch was applied after 'memcg: add mem_cgroup_mark_inode_dirty()'. In this version (v9), this patch comes first. The result is that this patch does not contain code to mark inode with I_MEMCG_SHARED. That logic is deferred until the later 'memcg: add mem_cgroup_mark_inode_dirty()' patch.
include/linux/memcontrol.h | 8 ++++- mm/memcontrol.c | 87 ++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 86 insertions(+), 9 deletions(-)
include/linux/memcontrol.h +7 -1
@@ -27,9 +27,15 @@ struct page_cgroup;struct page ;struct mm_struct ; -/* Stats that can be updated by kernel. */ +/* +* Per mem_cgroup page counts tracked by kernel. As pages enter and leave these +* states, the kernel notifies memcg using mem_cgroup_{inc,dec}_page_stat(). +*/ enum mem_cgroup_page_stat_item {MEMCG_NR_FILE_MAPPED ,/* # of pages charged as file rss */ +MEMCG_NR_FILE_DIRTY ,/* # of dirty pages in page cache */ +MEMCG_NR_FILE_WRITEBACK ,/* # of pages under writeback */ +MEMCG_NR_FILE_UNSTABLE_NFS ,/* # of NFS unstable pages */ }; extern unsigned long mem_cgroup_isolate_pages(unsigned long nr_to_scan,
mm/memcontrol.c +79 -8
130 lines not on this page · raw message
Signature · 8 lines
1.7.3.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v9 03/13] memcg: add dirty page accounting infrastructure
Quoted 10 lines · On Wed, 17 Aug 2011 09:14:55 -0700 Greg Thelen <[email protected]> wrote:
Add memcg routines to count dirty, writeback, and
unstable_NFSpages. These routines are not yet used by the kernel to count such pages. A later change adds kernel calls to these new routines.As inode pages are marked dirty, if the dirtied page's cgroup differs from the inode's cgroup, then mark the inode shared across several cgroup.
Signed-off-by Greg Thelen <[email protected]>Signed-off-by Andrea Righi <[email protected]>
A nitpick..
mm/memcontrol.c void mem_cgroup_split_huge_fixup(struct page *head, struct page *tail) · line 2717
Quoted 11 lines
mm/memcontrol.c +11
-0+static inline +void mem_cgroup_move_account_page_stat (struct mem_cgroup *from, +struct mem_cgroup *to, +enum mem_cgroup_stat_index idx) +{ +preempt_disable (); +__this_cpu_dec (from->stat->count[idx]); +__this_cpu_inc (to->stat->count[idx]); +preempt_enable (); +} +
this_cpu_dec()this_cpu_inc()
without preempt_disable/enable will work. CPU change between dec/inc will not be problem.
Thanks,
-Kame
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v9 03/13] memcg: add dirty page accounting infrastructure
Quoted 35 lines · KAMEZAWA Hiroyuki
Quoted 10 lines · On Wed, 17 Aug 2011 09:14:55 -0700 Greg Thelen <[email protected]> wrote:
Add memcg routines to count dirty, writeback, and
unstable_NFSpages. These routines are not yet used by the kernel to count such pages. A later change adds kernel calls to these new routines.As inode pages are marked dirty, if the dirtied page's cgroup differs from the inode's cgroup, then mark the inode shared across several cgroup.
Signed-off-by Greg Thelen <[email protected]>Signed-off-by Andrea Righi <[email protected]>A nitpick..
mm/memcontrol.c void mem_cgroup_split_huge_fixup(struct page *head, struct page *tail) · line 2717
Quoted 11 lines
mm/memcontrol.c +11
-0+static inline +void mem_cgroup_move_account_page_stat (struct mem_cgroup *from, +struct mem_cgroup *to, +enum mem_cgroup_stat_index idx) +{ +preempt_disable (); +__this_cpu_dec (from->stat->count[idx]); +__this_cpu_inc (to->stat->count[idx]); +preempt_enable (); +} +
this_cpu_dec()this_cpu_inc()
Quoted 5 lines
without preempt_disable/enable will work. CPU change between dec/inc will not be problem.
Thanks,
-Kame
I agree, but this fix is general cleanup, which seems independent of memcg dirty accounting. This preemption disable/enable pattern exists before this patch series in both mem_cgroup_charge_statistics() and mem_cgroup_move_account(). For consistency we should change both. To keep the dirty page accounting series simple, I would like to make these changes outside of this series. On x86 usage of this_cpu_dec/inc looks equivalent to __this_cpu_inc(), so I assume the only trade off is that preemptible non-x86 using generic this_this_cpu() will internally disable/enable preemption in this_cpu_*() operations.
I'll submit a cleanup patch outside of the dirty limit patches for this.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v9 4/13 memcg: add kernel calls for memcg dirty page stats
In reply to Greg ThelenAdd calls into memcg dirty page accounting. Notify memcg when pages transition between clean, file dirty, writeback, and unstable nfs. This allows the memory controller to maintain an accurate view of the amount of its memory that is dirty.
--- fs/nfs/write.c | 4 ++++ mm/filemap.c | 1 + mm/page-writeback.c | 4 ++++ mm/truncate.c | 1 + 4 files changed, 10 insertions(+), 0 deletions(-)
fs/nfs/write.c +4 -0
@@ -449,6 +449,7 @@ nfs_mark_request_commit(struct nfs_page *req, struct pnfs_layout_segment *lseg) nfsi->ncommit++;spin_unlock (&inode->i_lock);pnfs_mark_request_commit (req, lseg); +mem_cgroup_inc_page_stat (req->wb_page,MEMCG_NR_FILE_UNSTABLE_NFS );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 );
@@ -460,6 +461,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_dec_page_stat (page,MEMCG_NR_FILE_UNSTABLE_NFS );dec_zone_page_state (page,NR_UNSTABLE_NFS );dec_bdi_stat (page->mapping->backing_dev_info,BDI_RECLAIMABLE );return 1 ;
@@ -1408,6 +1410,8 @@ void nfs_retry_commit(struct list_head *page_list, req =nfs_list_entry (page_list->next);nfs_list_remove_request (req);nfs_mark_request_commit (req, lseg); +mem_cgroup_dec_page_stat (req->wb_page, +MEMCG_NR_FILE_UNSTABLE_NFS );dec_zone_page_state (req->wb_page,NR_UNSTABLE_NFS );dec_bdi_stat (req->wb_page->mapping->backing_dev_info,BDI_RECLAIMABLE );
mm/filemap.c +1 -0
@@ -142,6 +142,7 @@ void __delete_from_page_cache(struct page *page)* having removed the page entirely. */ if (PageDirty (page) &&mapping_cap_account_dirty (mapping)) { +mem_cgroup_dec_page_stat (page,MEMCG_NR_FILE_DIRTY );dec_zone_page_state (page,NR_FILE_DIRTY );dec_bdi_stat (mapping->backing_dev_info,BDI_RECLAIMABLE ); }
mm/page-writeback.c +4 -0
@@ -1328,6 +1328,7 @@ int __set_page_dirty_no_writeback(struct page *page)void account_page_dirtied (struct page *page,struct address_space *mapping) {if (mapping_cap_account_dirty (mapping)) { +mem_cgroup_inc_page_stat (page,MEMCG_NR_FILE_DIRTY );__inc_zone_page_state (page,NR_FILE_DIRTY );__inc_zone_page_state (page,NR_DIRTIED );__inc_bdi_stat (mapping->backing_dev_info,BDI_RECLAIMABLE );
@@ -1344,6 +1345,7 @@ EXPORT_SYMBOL(account_page_dirtied);*/ void account_page_writeback (struct page *page) { +mem_cgroup_inc_page_stat (page,MEMCG_NR_FILE_WRITEBACK );inc_zone_page_state (page,NR_WRITEBACK ); }EXPORT_SYMBOL (account_page_writeback);
@@ -1526,6 +1528,7 @@ int clear_page_dirty_for_io(struct page *page)* for more comments. */ if (TestClearPageDirty (page)) { +mem_cgroup_dec_page_stat (page,MEMCG_NR_FILE_DIRTY );dec_zone_page_state (page,NR_FILE_DIRTY );dec_bdi_stat (mapping->backing_dev_info,BDI_RECLAIMABLE );
@@ -1562,6 +1565,7 @@ int test_clear_page_writeback(struct page *page) ret =TestClearPageWriteback (page); }if (ret) { +mem_cgroup_dec_page_stat (page,MEMCG_NR_FILE_WRITEBACK );dec_zone_page_state (page,NR_WRITEBACK );inc_zone_page_state (page,NR_WRITTEN ); }
mm/truncate.c +1 -0
@@ -76,6 +76,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_dec_page_stat (page,MEMCG_NR_FILE_DIRTY );dec_zone_page_state (page,NR_FILE_DIRTY );dec_bdi_stat (mapping->backing_dev_info,BDI_RECLAIMABLE );
Signature · 8 lines
1.7.3.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v9 5/13 memcg: add mem_cgroup_mark_inode_dirty()
In reply to Greg ThelenCreate the mem_cgroup_mark_inode_dirty() routine, which is called when an inode is marked dirty. In kernels without memcg, this is an inline no-op.
Add i_memcg field to struct address_space. When an inode is marked dirty with mem_cgroup_mark_inode_dirty(), the css_id of current memcg is recorded in i_memcg. Per-memcg writeback (introduced in a latter change) uses this field to isolate inodes associated with a particular memcg.
The type of i_memcg is an 'unsigned short' because it stores the css_id of the memcg. Using a struct mem_cgroup pointer would be larger and also create a reference on the memcg which would hang memcg rmdir deletion. Usage of a css_id is not a reference so cgroup deletion is not affected. The memcg can be deleted without cleaning up the i_memcg field. When a memcg is deleted its pages are recharged to the cgroup parent, and the related inode(s) are marked as shared thus disassociating the inodes from the deleted cgroup.
A mem_cgroup_mark_inode_dirty() tracepoint is also included to allow for easier understanding of memcg writeback operation.
---
Changelog since v8:
- Use I_MEMCG_SHARED when initializing i_memcg.
- Use 'memcg' rather than 'mem' for local variables. This is consistent with other memory controller code.
- The logic in mem_cgroup_update_page_stat() and mem_cgroup_move_account() which marks inodes I_MEMCG_SHARED is now part of this patch. This makes more sense because this is that patch that introduces that shared-inode concept.
fs/fs-writeback.c | 2 + fs/inode.c | 3 ++ include/linux/fs.h | 9 +++++++ include/linux/memcontrol.h | 6 ++++ include/trace/events/memcontrol.h | 32 +++++++++++++++++++++++++ mm/memcontrol.c | 47 ++++++++++++++++++++++++++++++++++++- 6 files changed, 98 insertions(+), 1 deletions(-) create mode 100644 include/trace/events/memcontrol.h
fs/fs-writeback.c +2 -0
@@ -19,6 +19,7 @@#include <linux/slab.h> #include <linux/sched.h> #include <linux/fs.h> +#include <linux/memcontrol.h> #include <linux/mm.h> #include <linux/kthread.h> #include <linux/freezer.h>
@@ -1111,6 +1112,7 @@ void __mark_inode_dirty(struct inode *inode, int flags)spin_lock (&bdi->wb.list_lock); inode->dirtied_when = jiffies;list_move (&inode->i_wb_list, &bdi->wb.b_dirty); +mem_cgroup_mark_inode_dirty (inode);spin_unlock (&bdi->wb.list_lock);if (wakeup_bdi)
fs/inode.c +3 -0
@@ -176,6 +176,9 @@ int inode_init_always(struct super_block *sb, struct inode *inode) mapping->assoc_mapping =NULL ; mapping->backing_dev_info = &default_backing_dev_info; mapping->writeback_index =0 ; +#ifdef CONFIG_CGROUP_MEM_RES_CTLR + mapping->i_memcg =I_MEMCG_SHARED ; +#endif /* * If the block_device provides a backing_dev_info for client
include/linux/fs.h +9 -0
@@ -651,6 +651,9 @@ struct address_space {spinlock_t private_lock;/* for use by the address_space */ struct list_head private_list;/* ditto */ struct address_space *assoc_mapping;/* ditto */ +#ifdef CONFIG_CGROUP_MEM_RES_CTLR +unsigned short i_memcg;/* css_id of memcg dirtier */ +#endif } __attribute__((aligned(sizeof(long))));/* * On most architectures that alignment is already the case; but
@@ -658,6 +661,12 @@ struct address_space {* of struct page's "mapping" pointer be used for PAGE_MAPPING_ANON. */ +/* +* When an address_space is shared by multiple memcg dirtieres, then i_memcg is +* set to this special, wildcard, css_id value (zero). +*/ +#define I_MEMCG_SHARED 0 +struct block_device {dev_t bd_dev;/* not a kdev_t - it's a search key */ int bd_openers;
include/linux/memcontrol.h +6 -0
@@ -119,6 +119,8 @@ mem_cgroup_prepare_migration(struct page *page,extern void mem_cgroup_end_migration (struct mem_cgroup *mem,struct page *oldpage,struct page *newpage,bool migration_ok); +void mem_cgroup_mark_inode_dirty (struct inode *inode); +/* * For memory reclaim. */
@@ -297,6 +299,10 @@ static inline void mem_cgroup_end_migration(struct mem_cgroup *mem, { } +static inline void mem_cgroup_mark_inode_dirty (struct inode *inode) +{ +} +static inline int mem_cgroup_get_reclaim_priority (struct mem_cgroup *mem) {return 0 ;
include/trace/events/memcontrol.h new file +32 -0
@@ -0,0 +1,32 @@ +#undef TRACE_SYSTEM +#define TRACE_SYSTEM memcontrol + +#if !defined(_TRACE_MEMCONTROL_H) || defined(TRACE_HEADER_MULTI_READ ) +#define _TRACE_MEMCONTROL_H + +#include <linux/types.h> +#include <linux/tracepoint.h> + +TRACE_EVENT (mem_cgroup_mark_inode_dirty, + TP_PROTO(struct inode *inode), + +TP_ARGS (inode), + +TP_STRUCT__entry ( + __field(unsigned long, ino) + __field(unsigned short, css_id) + ), + +TP_fast_assign ( + __entry->ino = inode->i_ino; + __entry->css_id = + inode->i_mapping ? inode->i_mapping->i_memcg : 0; + ), + +TP_printk ("ino=%ld css_id=%d" , __entry->ino, __entry->css_id) +) + +#endif /* _TRACE_MEMCONTROL_H */ + +/* This part must be outside protection */ +#include <trace/define_trace.h>
mm/memcontrol.c +46 -1
81 lines not on this page · raw message
Signature · 8 lines
1.7.3.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v9 05/13] memcg: add mem_cgroup_mark_inode_dirty()
Quoted 19 lines · On Wed, 17 Aug 2011 09:14:57 -0700 Greg Thelen <[email protected]> wrote:
Create the
mem_cgroup_mark_inode_dirty()routine, which is called when an inode is marked dirty. In kernels without memcg, this is an inline no-op.Add
i_memcgfield to structaddress_space. When an inode is marked dirty withmem_cgroup_mark_inode_dirty(), thecss_idof current memcg is recorded ini_memcg. Per-memcg writeback (introduced in a latter change) uses this field to isolate inodes associated with a particular memcg.The type of
i_memcgis an 'unsigned short' because it stores thecss_idof the memcg. Using a structmem_cgrouppointer would be larger and also create a reference on the memcg which would hang memcg rmdir deletion. Usage of acss_idis not a reference so cgroup deletion is not affected. The memcg can be deleted without cleaning up thei_memcgfield. When a memcg is deleted its pages are recharged to the cgroup parent, and the related inode(s) are marked as shared thus disassociating the inodes from the deleted cgroup.
Quoted 4 lines
A
mem_cgroup_mark_inode_dirty()tracepoint is also included to allow for easier understanding of memcg writeback operation.Signed-off-by Greg Thelen <[email protected]>
Quoted 11 lines
---
Changelog since v8:
- UseI_MEMCG_SHAREDwhen initializingi_memcg.- Use 'memcg' rather than 'mem' for local variables. This is consistent with other memory controller code.
- The logic in
mem_cgroup_update_page_stat()andmem_cgroup_move_account()which marks inodesI_MEMCG_SHAREDis now part of this patch. This makes more sense because this is that patch that introduces that shared-inode concept.
yes, this makes the patch clearer.
Thanks,
-Kame
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v9 6/13 memcg: add dirty limits to mem_cgroup
In reply to Greg ThelenExtend mem_cgroup to contain dirty page limits.
---
Changelog since v8:
- Use 'memcg' rather than 'mem' for local variables and parameters. This is consistent with other memory controller code.
mm/memcontrol.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 49 insertions(+), 1 deletions(-)
mm/memcontrol.c +49 -1
@@ -254,6 +254,13 @@ const char *scanstat_string[NR_SCANSTATS] = {#define SCANSTAT_WORD_SYSTEM "_by_system"#define SCANSTAT_WORD_HIERARCHY "_under_hierarchy" +/* Dirty memory parameters */ +struct vm_dirty_param { +int dirty_ratio; +int dirty_background_ratio; +unsigned long dirty_bytes; +unsigned long dirty_background_bytes; +};/* * The memory controller data structure. The memory controller controls both
@@ -303,6 +310,10 @@ struct mem_cgroup {atomic_t refcnt;int swappiness; + +/* control memory cgroup dirty pages */ +struct vm_dirty_param dirty_param; +/* OOM-Killer disable */ int oom_kill_disable;
@@ -1348,6 +1359,36 @@ int mem_cgroup_swappiness(struct mem_cgroup *memcg)return memcg->swappiness; } +/* +* Return true if the current memory cgroup has local dirty memory settings. +* There is an allowed race between the current task migrating in-to/out-of the +* root cgroup while this routine runs. So the return value may be incorrect if +* the current task is being simultaneously migrated. +*/ +static bool mem_cgroup_has_dirty_limit (struct mem_cgroup *memcg) +{ +return memcg && !mem_cgroup_is_root (memcg); +} + +/* +* Returns a snapshot of the current dirty limits which is not synchronized with +* the routines that change the dirty limits. If this routine races with an +* update to the dirty bytes/ratio value, then the caller must handle the case +* where neither dirty_[background_]_ratio nor _bytes are set. +*/ +static void mem_cgroup_dirty_param (struct vm_dirty_param *param, +struct mem_cgroup *memcg) +{ +if (mem_cgroup_has_dirty_limit (memcg)) { + *param = memcg->dirty_param; + }else { + param->dirty_ratio = vm_dirty_ratio; + param->dirty_bytes = vm_dirty_bytes; + param->dirty_background_ratio = dirty_background_ratio; + param->dirty_background_bytes = dirty_background_bytes; + } +} +static void mem_cgroup_start_move (struct mem_cgroup *mem) {int cpu;
@@ -5220,8 +5261,15 @@ mem_cgroup_create(struct cgroup_subsys *ss, struct cgroup *cont) mem->last_scanned_node =MAX_NUMNODES ;INIT_LIST_HEAD (&mem->oom_notify); -if (parent) +if (parent) { mem->swappiness =mem_cgroup_swappiness (parent); +mem_cgroup_dirty_param (&mem->dirty_param, parent); + }else { +/* +* The root cgroup dirty_param field is not used, instead, +* system-wide dirty limits are used. +*/ + }atomic_set (&mem->refcnt,1 ); mem->move_charge_at_immigrate =0 ;mutex_init (&mem->thresholds_lock);
Signature · 8 lines
1.7.3.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v9 06/13] memcg: add dirty limits to mem_cgroup
Quoted 5 lines · On Wed, 17 Aug 2011 09:14:58 -0700 Greg Thelen <[email protected]> wrote:
Extend
mem_cgroupto contain dirty page limits.Signed-off-by Greg Thelen <[email protected]>Signed-off-by Andrea Righi <[email protected]>Signed-off-by Johannes Weiner <[email protected]>
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v9 7/13 memcg: add cgroupfs interface to memcg dirty limits
In reply to Greg ThelenAdd cgroupfs interface to memcg dirty page limits:
Direct write-out is controlled with:
- memory.dirty_ratio
- memory.dirty_limit_in_bytes
Background write-out is controlled with:
- memory.dirty_background_ratio
- memory.dirty_background_limit_bytes
Other memcg cgroupfs files support 'M', 'm', 'k', 'K', 'g' and 'G' suffixes for byte counts. This patch provides the same functionality for memory.dirty_limit_in_bytes and memory.dirty_background_limit_bytes.
---
Changelog since v8:
- Use 'memcg' rather than 'mem' for local variables and parameters. This is consistent with other memory controller code.
mm/memcontrol.c | 115 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 115 insertions(+), 0 deletions(-)
mm/memcontrol.c +115 -0
@@ -121,6 +121,13 @@ enum mem_cgroup_events_target {#define SOFTLIMIT_EVENTS_TARGET (1024)#define NUMAINFO_EVENTS_TARGET (1024) +enum { +MEM_CGROUP_DIRTY_RATIO , +MEM_CGROUP_DIRTY_LIMIT_IN_BYTES , +MEM_CGROUP_DIRTY_BACKGROUND_RATIO , +MEM_CGROUP_DIRTY_BACKGROUND_LIMIT_IN_BYTES , +}; +struct mem_cgroup_stat_cpu {long count[MEM_CGROUP_STAT_NSTATS ];unsigned long events[MEM_CGROUP_EVENTS_NSTATS ];
@@ -4927,6 +4934,90 @@ static int mem_cgroup_reset_vmscan_stat(struct cgroup *cgrp,return 0 ; } +static u64 mem_cgroup_dirty_read (struct cgroup *cgrp,struct cftype *cft) +{ +struct mem_cgroup *memcg =mem_cgroup_from_cont (cgrp); +bool use_sys = !mem_cgroup_has_dirty_limit (memcg); + +switch (cft->private) { +case MEM_CGROUP_DIRTY_RATIO : +return use_sys ? vm_dirty_ratio : + memcg->dirty_param.dirty_ratio; +case MEM_CGROUP_DIRTY_LIMIT_IN_BYTES : +return use_sys ? vm_dirty_bytes : + memcg->dirty_param.dirty_bytes; +case MEM_CGROUP_DIRTY_BACKGROUND_RATIO : +return use_sys ? dirty_background_ratio : + memcg->dirty_param.dirty_background_ratio; +case MEM_CGROUP_DIRTY_BACKGROUND_LIMIT_IN_BYTES : +return use_sys ? dirty_background_bytes : + memcg->dirty_param.dirty_background_bytes; +default : +BUG (); + } +} + +static int +mem_cgroup_dirty_write_string (struct cgroup *cgrp,struct cftype *cft, +const char *buffer) +{ +struct mem_cgroup *memcg =mem_cgroup_from_cont (cgrp); +int type = cft->private; +int ret = -EINVAL ; +unsigned long long val; + +if (!mem_cgroup_has_dirty_limit (memcg)) +return ret; + +switch (type) { +case MEM_CGROUP_DIRTY_LIMIT_IN_BYTES : +/* This function does all necessary parse...reuse it */ + ret =res_counter_memparse_write_strategy (buffer, &val); +if (ret) +break ; + memcg->dirty_param.dirty_bytes = val; + memcg->dirty_param.dirty_ratio =0 ; +break ; +case MEM_CGROUP_DIRTY_BACKGROUND_LIMIT_IN_BYTES : + ret =res_counter_memparse_write_strategy (buffer, &val); +if (ret) +break ; + memcg->dirty_param.dirty_background_bytes = val; + memcg->dirty_param.dirty_background_ratio =0 ; +break ; +default : +BUG (); +break ; + } +return ret; +} + +static int +mem_cgroup_dirty_write (struct cgroup *cgrp,struct cftype *cft,u64 val) +{ +struct mem_cgroup *memcg =mem_cgroup_from_cont (cgrp); +int type = cft->private; + +if (!mem_cgroup_has_dirty_limit (memcg)) +return -EINVAL ; +if ((type ==MEM_CGROUP_DIRTY_RATIO || + type ==MEM_CGROUP_DIRTY_BACKGROUND_RATIO ) && val >100 ) +return -EINVAL ; +switch (type) { +case MEM_CGROUP_DIRTY_RATIO : + memcg->dirty_param.dirty_ratio = val; + memcg->dirty_param.dirty_bytes =0 ; +break ; +case MEM_CGROUP_DIRTY_BACKGROUND_RATIO : + memcg->dirty_param.dirty_background_ratio = val; + memcg->dirty_param.dirty_background_bytes =0 ; +break ; +default : +BUG (); +break ; + } +return 0 ; +}static struct cftype mem_cgroup_files[] = { {
@@ -5003,6 +5094,30 @@ static struct cftype mem_cgroup_files[] = { .read_map = mem_cgroup_vmscan_stat_read, .trigger = mem_cgroup_reset_vmscan_stat, }, + { + .name = "dirty_ratio", + .read_u64 = mem_cgroup_dirty_read, + .write_u64 = mem_cgroup_dirty_write, + .private = MEM_CGROUP_DIRTY_RATIO, + }, + { + .name = "dirty_limit_in_bytes", + .read_u64 = mem_cgroup_dirty_read, + .write_string = mem_cgroup_dirty_write_string, + .private = MEM_CGROUP_DIRTY_LIMIT_IN_BYTES, + }, + { + .name = "dirty_background_ratio", + .read_u64 = mem_cgroup_dirty_read, + .write_u64 = mem_cgroup_dirty_write, + .private = MEM_CGROUP_DIRTY_BACKGROUND_RATIO, + }, + { + .name = "dirty_background_limit_in_bytes", + .read_u64 = mem_cgroup_dirty_read, + .write_string = mem_cgroup_dirty_write_string, + .private = MEM_CGROUP_DIRTY_BACKGROUND_LIMIT_IN_BYTES, + }, }; #ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
Signature · 8 lines
1.7.3.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v9 07/13] memcg: add cgroupfs interface to memcg dirty limits
Quoted 9 lines · On Wed, 17 Aug 2011 09:14:59 -0700 Greg Thelen <[email protected]> wrote:
Add cgroupfs interface to memcg dirty page limits:
Direct write-out is controlled with:
- memory.dirty_ratio
- memory.dirty_limit_in_bytesBackground write-out is controlled with:
- memory.dirty_background_ratio
- memory.dirty_background_limit_bytes
Quoted 8 lines
Other memcg cgroupfs files support 'M', 'm', 'k', 'K', 'g' and 'G' suffixes for byte counts. This patch provides the same functionality for memory.dirty_limit_in_bytes and memory.dirty_background_limit_bytes.
Signed-off-by Andrea Righi <[email protected]>Signed-off-by Balbir Singh <[email protected]>Signed-off-by Greg Thelen <[email protected]>
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v9 8/13 memcg: dirty page accounting support routines
In reply to Greg ThelenAdded memcg dirty page accounting support routines. These routines are used by later changes to provide memcg aware writeback and dirty page limiting. A mem_cgroup_dirty_info() tracepoint is is also included to allow for easier understanding of memcg writeback operation.
---
Changelog since v8:
- Use 'memcg' rather than 'mem' for local variables and parameters. This is consistent with other memory controller code.
include/linux/memcontrol.h | 9 ++ include/trace/events/memcontrol.h | 34 +++++++++ mm/memcontrol.c | 147 +++++++++++++++++++++++++++++++++++++ 3 files changed, 190 insertions(+), 0 deletions(-)
include/linux/memcontrol.h +9 -0
@@ -36,6 +36,15 @@ enum mem_cgroup_page_stat_item {MEMCG_NR_FILE_DIRTY ,/* # of dirty pages in page cache */ MEMCG_NR_FILE_WRITEBACK ,/* # of pages under writeback */ MEMCG_NR_FILE_UNSTABLE_NFS ,/* # of NFS unstable pages */ + MEMCG_NR_DIRTYABLE_PAGES, /* # of pages that could be dirty */ +}; + +struct dirty_info { +unsigned long dirty_thresh; +unsigned long background_thresh; +unsigned long nr_file_dirty; +unsigned long nr_writeback; +unsigned long nr_unstable_nfs; }; extern unsigned long mem_cgroup_isolate_pages(unsigned long nr_to_scan,
include/trace/events/memcontrol.h +34 -0
@@ -26,6 +26,40 @@ TRACE_EVENT(mem_cgroup_mark_inode_dirty, TP_printk("ino=%ld css_id=%d", __entry->ino, __entry->css_id) ) +TRACE_EVENT (mem_cgroup_dirty_info, + TP_PROTO(unsigned short css_id, + struct dirty_info *dirty_info), + +TP_ARGS (css_id, dirty_info), + +TP_STRUCT__entry ( + __field(unsigned short, css_id) + __field(unsigned long, dirty_thresh) + __field(unsigned long, background_thresh) + __field(unsigned long, nr_file_dirty) + __field(unsigned long, nr_writeback) + __field(unsigned long, nr_unstable_nfs) + ), + +TP_fast_assign ( + __entry->css_id = css_id; + __entry->dirty_thresh = dirty_info->dirty_thresh; + __entry->background_thresh = dirty_info->background_thresh; + __entry->nr_file_dirty = dirty_info->nr_file_dirty; + __entry->nr_writeback = dirty_info->nr_writeback; + __entry->nr_unstable_nfs = dirty_info->nr_unstable_nfs; + ), + +TP_printk ("css_id=%d thresh=%ld bg_thresh=%ld dirty=%ld wb=%ld " +"unstable_nfs=%ld" , + __entry->css_id, + __entry->dirty_thresh, + __entry->background_thresh, + __entry->nr_file_dirty, + __entry->nr_writeback, + __entry->nr_unstable_nfs) +) +#endif /* _TRACE_MEMCONTROL_H */ /* This part must be outside protection */
mm/memcontrol.c +147 -0
159 lines not on this page · raw message
Signature · 8 lines
1.7.3.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v9 08/13] memcg: dirty page accounting support routines
Quoted 6 lines · On Wed, 17 Aug 2011 09:15:00 -0700 Greg Thelen <[email protected]> wrote:
Added memcg dirty page accounting support routines. These routines are used by later changes to provide memcg aware writeback and dirty page limiting. A
mem_cgroup_dirty_info()tracepoint is is also included to allow for easier understanding of memcg writeback operation.Signed-off-by Greg Thelen <[email protected]>
I have small comments.
Quoted 92 lines
---
Changelog since v8:
- Use 'memcg' rather than 'mem' for local variables and parameters. This is consistent with other memory controller code.include/linux/memcontrol.h | 9 ++ include/trace/events/memcontrol.h | 34 +++++++++ mm/memcontrol.c | 147 +++++++++++++++++++++++++++++++++++++ 3 files changed, 190 insertions(+), 0 deletions(-)include/linux/memcontrol.h +9
-0@@ -36,6 +36,15 @@ enum mem_cgroup_page_stat_item {MEMCG_NR_FILE_DIRTY ,/* # of dirty pages in page cache */ MEMCG_NR_FILE_WRITEBACK ,/* # of pages under writeback */ MEMCG_NR_FILE_UNSTABLE_NFS ,/* # of NFS unstable pages */ + MEMCG_NR_DIRTYABLE_PAGES, /* # of pages that could be dirty */ +}; + +struct dirty_info { +unsigned long dirty_thresh; +unsigned long background_thresh; +unsigned long nr_file_dirty; +unsigned long nr_writeback; +unsigned long nr_unstable_nfs; }; extern unsigned long mem_cgroup_isolate_pages(unsigned long nr_to_scan,include/trace/events/memcontrol.h +34
-0@@ -26,6 +26,40 @@ TRACE_EVENT(mem_cgroup_mark_inode_dirty, TP_printk("ino=%ld css_id=%d", __entry->ino, __entry->css_id) ) +TRACE_EVENT (mem_cgroup_dirty_info, + TP_PROTO(unsigned short css_id, + struct dirty_info *dirty_info), + +TP_ARGS (css_id, dirty_info), + +TP_STRUCT__entry ( + __field(unsigned short, css_id) + __field(unsigned long, dirty_thresh) + __field(unsigned long, background_thresh) + __field(unsigned long, nr_file_dirty) + __field(unsigned long, nr_writeback) + __field(unsigned long, nr_unstable_nfs) + ), + +TP_fast_assign ( + __entry->css_id = css_id; + __entry->dirty_thresh = dirty_info->dirty_thresh; + __entry->background_thresh = dirty_info->background_thresh; + __entry->nr_file_dirty = dirty_info->nr_file_dirty; + __entry->nr_writeback = dirty_info->nr_writeback; + __entry->nr_unstable_nfs = dirty_info->nr_unstable_nfs; + ), + +TP_printk ("css_id=%d thresh=%ld bg_thresh=%ld dirty=%ld wb=%ld " +"unstable_nfs=%ld" , + __entry->css_id, + __entry->dirty_thresh, + __entry->background_thresh, + __entry->nr_file_dirty, + __entry->nr_writeback, + __entry->nr_unstable_nfs) +) +#endif /* _TRACE_MEMCONTROL_H */ /* This part must be outside protection */ mm/memcontrol.c +5
-0@@ -1366,6 +1366,11 @@ int mem_cgroup_swappiness(struct mem_cgroup *memcg)return memcg->swappiness; } +static unsigned long dirty_info_reclaimable (struct dirty_info *info) +{ +return info->nr_file_dirty + info->nr_unstable_nfs; +} +/* * Return true if the current memory cgroup has local dirty memory settings. * There is an allowed race between the current task migrating in-to/out-of the
mm/memcontrol.c static void mem_cgroup_dirty_param(struct vm_dirty_param *param, · line 1410
Quoted 10 lines
mm/memcontrol.c +7
-0@@ -1396,6 +1401,148 @@ static void mem_cgroup_dirty_param(struct vm_dirty_param *param, } } +static inline bool mem_cgroup_can_swap (struct mem_cgroup *memcg) +{ +if (!do_swap_account) +return nr_swap_pages >0 ; +return !memcg->memsw_is_minimum && + (res_counter_read_u64 (&memcg->memsw,RES_LIMIT ) >0 ); +}
I think
if (nr_swap_pages == 0)
return false;
if (!do_swap_account)
return true;
if (memcg->memsw_is_mininum)
return false;
if (res_counter_margin(&memcg->memsw) == 0)
return false;is a correct check.
Quoted 39 lines
mm/memcontrol.c +39
-0+ +static s64 mem_cgroup_local_page_stat (struct mem_cgroup *memcg, +enum mem_cgroup_page_stat_item item) +{ +s64 ret; + +switch (item) { +case MEMCG_NR_FILE_DIRTY : + ret =mem_cgroup_read_stat (memcg,MEM_CGROUP_STAT_FILE_DIRTY ); +break ; +case MEMCG_NR_FILE_WRITEBACK : + ret =mem_cgroup_read_stat (memcg, +MEM_CGROUP_STAT_FILE_WRITEBACK ); +break ; +case MEMCG_NR_FILE_UNSTABLE_NFS : + ret =mem_cgroup_read_stat (memcg, +MEM_CGROUP_STAT_FILE_UNSTABLE_NFS ); +break ; +case MEMCG_NR_DIRTYABLE_PAGES : + ret =mem_cgroup_read_stat (memcg,LRU_ACTIVE_FILE ) + +mem_cgroup_read_stat (memcg,LRU_INACTIVE_FILE ); +if (mem_cgroup_can_swap (memcg)) + ret +=mem_cgroup_read_stat (memcg,LRU_ACTIVE_ANON ) + +mem_cgroup_read_stat (memcg,LRU_INACTIVE_ANON ); +break ; +default : +BUG (); +break ; + } +return ret; +} + +/* +* Return the number of additional pages that the @memcg cgroup could allocate. +* If use_hierarchy is set, then this involves checking parent mem cgroups to +* find the cgroup with the smallest free space. +*/ +static unsigned long +mem_cgroup_hierarchical_free_pages (struct mem_cgroup *memcg)
mm/memcontrol.c static void mem_cgroup_dirty_param(struct vm_dirty_param *param, · line 1459
Quoted 10 lines
mm/memcontrol.c +10
-0+{ +u64 free; +unsigned long min_free; + + min_free =global_page_state (NR_FREE_PAGES ); + +while (memcg) { + free = (res_counter_read_u64 (&memcg->res,RES_LIMIT ) - +res_counter_read_u64 (&memcg->res,RES_USAGE )) >> +PAGE_SHIFT ;
How about
free = mem_cgroup_margin(&mem->res);
?
Thanks,
-Kame
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v9 08/13] memcg: dirty page accounting support routines
Quoted 126 lines · KAMEZAWA Hiroyuki
Quoted 6 lines · On Wed, 17 Aug 2011 09:15:00 -0700 Greg Thelen <[email protected]> wrote:
Added memcg dirty page accounting support routines. These routines are used by later changes to provide memcg aware writeback and dirty page limiting. A
mem_cgroup_dirty_info()tracepoint is is also included to allow for easier understanding of memcg writeback operation.Signed-off-by Greg Thelen <[email protected]>I have small comments.
Quoted 92 lines
---
Changelog since v8:
- Use 'memcg' rather than 'mem' for local variables and parameters. This is consistent with other memory controller code.include/linux/memcontrol.h | 9 ++ include/trace/events/memcontrol.h | 34 +++++++++ mm/memcontrol.c | 147 +++++++++++++++++++++++++++++++++++++ 3 files changed, 190 insertions(+), 0 deletions(-)include/linux/memcontrol.h +9
-0@@ -36,6 +36,15 @@ enum mem_cgroup_page_stat_item {MEMCG_NR_FILE_DIRTY ,/* # of dirty pages in page cache */ MEMCG_NR_FILE_WRITEBACK ,/* # of pages under writeback */ MEMCG_NR_FILE_UNSTABLE_NFS ,/* # of NFS unstable pages */ + MEMCG_NR_DIRTYABLE_PAGES, /* # of pages that could be dirty */ +}; + +struct dirty_info { +unsigned long dirty_thresh; +unsigned long background_thresh; +unsigned long nr_file_dirty; +unsigned long nr_writeback; +unsigned long nr_unstable_nfs; }; extern unsigned long mem_cgroup_isolate_pages(unsigned long nr_to_scan,include/trace/events/memcontrol.h +34
-0@@ -26,6 +26,40 @@ TRACE_EVENT(mem_cgroup_mark_inode_dirty, TP_printk("ino=%ld css_id=%d", __entry->ino, __entry->css_id) ) +TRACE_EVENT (mem_cgroup_dirty_info, + TP_PROTO(unsigned short css_id, + struct dirty_info *dirty_info), + +TP_ARGS (css_id, dirty_info), + +TP_STRUCT__entry ( + __field(unsigned short, css_id) + __field(unsigned long, dirty_thresh) + __field(unsigned long, background_thresh) + __field(unsigned long, nr_file_dirty) + __field(unsigned long, nr_writeback) + __field(unsigned long, nr_unstable_nfs) + ), + +TP_fast_assign ( + __entry->css_id = css_id; + __entry->dirty_thresh = dirty_info->dirty_thresh; + __entry->background_thresh = dirty_info->background_thresh; + __entry->nr_file_dirty = dirty_info->nr_file_dirty; + __entry->nr_writeback = dirty_info->nr_writeback; + __entry->nr_unstable_nfs = dirty_info->nr_unstable_nfs; + ), + +TP_printk ("css_id=%d thresh=%ld bg_thresh=%ld dirty=%ld wb=%ld " +"unstable_nfs=%ld" , + __entry->css_id, + __entry->dirty_thresh, + __entry->background_thresh, + __entry->nr_file_dirty, + __entry->nr_writeback, + __entry->nr_unstable_nfs) +) +#endif /* _TRACE_MEMCONTROL_H */ /* This part must be outside protection */ mm/memcontrol.c +5
-0@@ -1366,6 +1366,11 @@ int mem_cgroup_swappiness(struct mem_cgroup *memcg)return memcg->swappiness; } +static unsigned long dirty_info_reclaimable (struct dirty_info *info) +{ +return info->nr_file_dirty + info->nr_unstable_nfs; +} +/* * Return true if the current memory cgroup has local dirty memory settings. * There is an allowed race between the current task migrating in-to/out-of the mm/memcontrol.c static void mem_cgroup_dirty_param(struct vm_dirty_param *param, · line 1410
Quoted 10 lines
mm/memcontrol.c +7
-0@@ -1396,6 +1401,148 @@ static void mem_cgroup_dirty_param(struct vm_dirty_param *param, } } +static inline bool mem_cgroup_can_swap (struct mem_cgroup *memcg) +{ +if (!do_swap_account) +return nr_swap_pages >0 ; +return !memcg->memsw_is_minimum && + (res_counter_read_u64 (&memcg->memsw,RES_LIMIT ) >0 ); +}I think
if (nr_swap_pages == 0) return false; if (!do_swap_account) return true; if (memcg->memsw_is_mininum) return false; if (res_counter_margin(&memcg->memsw) == 0) return false;
Quoted 1 line
is a correct check.
Ok. I'll update to use your logic.
Quoted 51 lines
Quoted 39 lines
mm/memcontrol.c +39
-0+ +static s64 mem_cgroup_local_page_stat (struct mem_cgroup *memcg, +enum mem_cgroup_page_stat_item item) +{ +s64 ret; + +switch (item) { +case MEMCG_NR_FILE_DIRTY : + ret =mem_cgroup_read_stat (memcg,MEM_CGROUP_STAT_FILE_DIRTY ); +break ; +case MEMCG_NR_FILE_WRITEBACK : + ret =mem_cgroup_read_stat (memcg, +MEM_CGROUP_STAT_FILE_WRITEBACK ); +break ; +case MEMCG_NR_FILE_UNSTABLE_NFS : + ret =mem_cgroup_read_stat (memcg, +MEM_CGROUP_STAT_FILE_UNSTABLE_NFS ); +break ; +case MEMCG_NR_DIRTYABLE_PAGES : + ret =mem_cgroup_read_stat (memcg,LRU_ACTIVE_FILE ) + +mem_cgroup_read_stat (memcg,LRU_INACTIVE_FILE ); +if (mem_cgroup_can_swap (memcg)) + ret +=mem_cgroup_read_stat (memcg,LRU_ACTIVE_ANON ) + +mem_cgroup_read_stat (memcg,LRU_INACTIVE_ANON ); +break ; +default : +BUG (); +break ; + } +return ret; +} + +/* +* Return the number of additional pages that the @memcg cgroup could allocate. +* If use_hierarchy is set, then this involves checking parent mem cgroups to +* find the cgroup with the smallest free space. +*/ +static unsigned long +mem_cgroup_hierarchical_free_pages (struct mem_cgroup *memcg)mm/memcontrol.c static void mem_cgroup_dirty_param(struct vm_dirty_param *param, · line 1459
Quoted 10 lines
mm/memcontrol.c +10
-0+{ +u64 free; +unsigned long min_free; + + min_free =global_page_state (NR_FREE_PAGES ); + +while (memcg) { + free = (res_counter_read_u64 (&memcg->res,RES_LIMIT ) - +res_counter_read_u64 (&memcg->res,RES_USAGE )) >> +PAGE_SHIFT ;How about
Quoted 5 lines
free = mem_cgroup_margin(&mem->res);?
Thanks,
-Kame
Sounds good. I'll update to:
while (memcg) {
free = res_counter_margin(&memcg->res) >> PAGE_SHIFT;
min_free = min_t(u64, min_free, free);
memcg = parent_mem_cgroup(memcg);
}--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v9 9/13 memcg: create support routines for writeback
In reply to Greg ThelenIntroduce memcg routines to assist in per-memcg writeback:
- mem_cgroups_over_bground_dirty_thresh() determines if any cgroups need writeback because they are over their dirty memory threshold.
- should_writeback_mem_cgroup_inode() will be called by writeback to determine if a particular inode should be written back. The answer depends on the writeback context (foreground, background, try_to_free_pages, etc.).
- mem_cgroup_writeback_done() is used periodically during writeback to update memcg writeback data.
These routines make use of a new over_bground_dirty_thresh bitmap that indicates which mem_cgroup are over their respective dirty background threshold. As this bitmap is indexed by css_id, the largest possible css_id value is needed to create the bitmap. So move the definition of CSS_ID_MAX from cgroup.c to cgroup.h. This allows users of css_id() to know the largest possible css_id value. This knowledge can be used to build such per-cgroup bitmaps.
Make determine_dirtyable_memory() non-static because it is needed by mem_cgroup_writeback_done().
---
Changelog since v8:
- No longer passing struct writeback_control into memcontrol functions. Instead the needed attributes (memcg_id, etc.) are explicitly passed in.
- No more field additions to struct writeback_control.
- make determine_dirtyable_memory() non-static.
- rename 'over_limit' in should_writeback_mem_cgroup_inode() to 'wb' because should_writeback_mem_cgroup_inode() does not necessarily return just inodes that are in over-limit memcg. It returns inodes that need writeback based on input criteria.
- Added more comments to clarify should_writeback_mem_cgroup_inode().
- To handle foreground writeback and try_to_free_pages(), should_writeback_mem_cgroup_inode() can check for the inodes in a specific memory cgroup.
- Use 'memcg' rather than 'mem' for local variables and parameters. This is consistent with other memory controller code.
include/linux/cgroup.h | 1 + include/linux/memcontrol.h | 23 ++++++ include/linux/writeback.h | 1 + include/trace/events/memcontrol.h | 53 +++++++++++++ kernel/cgroup.c | 1 - mm/memcontrol.c | 153 +++++++++++++++++++++++++++++++++++++ mm/page-writeback.c | 2 +- 7 files changed, 232 insertions(+), 2 deletions(-)
include/linux/cgroup.h +1 -0
@@ -623,6 +623,7 @@ bool css_is_ancestor(struct cgroup_subsys_state *cg, const struct cgroup_subsys_state *root);/* Get id and depth of css */ +#define CSS_ID_MAX (65535)unsigned short css_id (struct cgroup_subsys_state *css);unsigned short css_depth (struct cgroup_subsys_state *css);struct cgroup_subsys_state *cgroup_css_from_dir (struct file *f,int id);
include/linux/memcontrol.h +23 -0
@@ -181,6 +181,12 @@ static inline void mem_cgroup_dec_page_stat(struct page *page,mem_cgroup_update_page_stat (page, idx,-1 ); } +bool should_writeback_mem_cgroup_inode (struct inode *inode, +unsigned short memcg_id, +bool shared_inodes); +bool mem_cgroups_over_bground_dirty_thresh (void ); +void mem_cgroup_writeback_done (void ); +unsigned long mem_cgroup_soft_limit_reclaim (struct zone *zone,int order,gfp_t gfp_mask,unsigned long *total_scanned);
@@ -379,6 +385,23 @@ static inline void mem_cgroup_dec_page_stat(struct page *page, { } +static inline bool +should_writeback_mem_cgroup_inode (struct inode *inode, +unsigned short memcg_id, +bool shared_inodes) +{ +return true; +} + +static inline bool mem_cgroups_over_bground_dirty_thresh (void ) +{ +return true; +} + +static inline void mem_cgroup_writeback_done (void ) +{ +} + static inline unsigned long mem_cgroup_soft_limit_reclaim(struct zone *zone, int order, gfp_t gfp_mask,
include/linux/writeback.h +1 -0
@@ -128,6 +128,7 @@ extern unsigned int dirty_expire_interval;extern int vm_highmem_is_dirtyable;extern int block_dump;extern int laptop_mode; +extern unsigned long determine_dirtyable_memory (void ); extern int dirty_background_ratio_handler(struct ctl_table *table, int write, void __user *buffer, size_t *lenp,
include/trace/events/memcontrol.h +53 -0
59 lines not on this page · raw message
kernel/cgroup.c +0 -1
@@ -131,7 +131,6 @@ static struct cgroupfs_root rootnode;* CSS ID -- ID per subsys's Cgroup Subsys State(CSS). used only when * cgroup_subsys->use_id != 0. */ -#define CSS_ID_MAX (65535)struct css_id {/* * The css to which this ID points. This pointer is set to valid value
mm/memcontrol.c +153 -0
169 lines not on this page · raw message
mm/page-writeback.c +1 -1
@@ -190,7 +190,7 @@ static unsigned long highmem_dirtyable_memory(unsigned long total)* Returns the numebr of pages that can currently be freed and used * by the kernel for direct mappings. */ -static unsigned long determine_dirtyable_memory (void ) +unsigned long determine_dirtyable_memory (void ) {unsigned long x;
Signature · 8 lines
1.7.3.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v9 09/13] memcg: create support routines for writeback
Quoted 21 lines · On Wed, 17 Aug 2011 09:15:01 -0700 Greg Thelen <[email protected]> wrote:
Introduce memcg routines to assist in per-memcg writeback:
-
mem_cgroups_over_bground_dirty_thresh()determines if any cgroups need writeback because they are over their dirty memory threshold.-
should_writeback_mem_cgroup_inode()will be called by writeback to determine if a particular inode should be written back. The answer depends on the writeback context (foreground, background,try_to_free_pages, etc.).-
mem_cgroup_writeback_done()is used periodically during writeback to update memcg writeback data.These routines make use of a new
over_bground_dirty_threshbitmap that indicates whichmem_cgroupare over their respective dirty background threshold. As this bitmap is indexed bycss_id, the largest possiblecss_idvalue is needed to create the bitmap. So move the definition ofCSS_ID_MAXfromcgroup.ctocgroup.h. This allows users ofcss_id()to know the largest possiblecss_idvalue. This knowledge can be used to build such per-cgroup bitmaps.
Quoted 4 lines
Make
determine_dirtyable_memory()non-static because it is needed bymem_cgroup_writeback_done().Signed-off-by Greg Thelen <[email protected]>
PATCH v9 10/13 writeback: pass wb_writeback_work into move_expired_inodes()
In reply to Greg ThelenA later change to move_expired_inodes() requires passing fields from writeback work descriptor into memcontrol code when determining if an inode should be written back considered.
--- fs/fs-writeback.c | 15 ++++++++------- 1 files changed, 8 insertions(+), 7 deletions(-)
fs/fs-writeback.c +8 -7
@@ -252,7 +252,7 @@ static bool inode_dirtied_after(struct inode *inode, unsigned long t)*/ static int move_expired_inodes (struct list_head *delaying_queue,struct list_head *dispatch_queue, -unsigned long *older_than_this) +struct wb_writeback_work *work) {LIST_HEAD (tmp);struct list_head *pos, *node;
@@ -263,8 +263,8 @@ static int move_expired_inodes(struct list_head *delaying_queue,while (!list_empty (delaying_queue)) { inode =wb_inode (delaying_queue->prev); -if (older_than_this && -inode_dirtied_after (inode, *older_than_this)) +if (work->older_than_this && +inode_dirtied_after (inode, *work->older_than_this))break ;if (sb && sb != inode->i_sb) do_sb_sort =1 ;
@@ -303,13 +303,14 @@ out:* | * +--> dequeue for IO */ -static void queue_io (struct bdi_writeback *wb,unsigned long *older_than_this) +static void queue_io (struct bdi_writeback *wb,struct wb_writeback_work *work) {int moved;assert_spin_locked (&wb->list_lock);list_splice_init (&wb->b_more_io, &wb->b_io); - moved =move_expired_inodes (&wb->b_dirty, &wb->b_io, older_than_this); -trace_writeback_queue_io (wb, older_than_this, moved); + moved =move_expired_inodes (&wb->b_dirty, &wb->b_io, work); +trace_writeback_queue_io (wb, work ? work->older_than_this :NULL , + moved); }static int write_inode (struct inode *inode,struct writeback_control *wbc)
@@ -739,7 +740,7 @@ static long wb_writeback(struct bdi_writeback *wb,trace_writeback_start (wb->bdi, work);if (list_empty (&wb->b_io)) -queue_io (wb, work->older_than_this); +queue_io (wb, work);if (work->sb) progress =writeback_sb_inodes (work->sb, wb, work);else
Signature · 8 lines
1.7.3.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v9 10/13] writeback: pass wb_writeback_work into move_expired_inodes()
Quoted 5 lines · On Wed, 17 Aug 2011 09:15:02 -0700 Greg Thelen <[email protected]> wrote:
A later change to
move_expired_inodes()requires passing fields from writeback work descriptor into memcontrol code when determining if an inode should be written back considered.Signed-off-by Greg Thelen <[email protected]>
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v9 11/13 writeback: make background writeback cgroup aware
In reply to Greg ThelenWhen the system is under background dirty memory threshold but some cgroups are over their background dirty memory thresholds, then only writeback inodes associated with the over-limit cgroups.
In addition to checking if the system dirty memory usage is over the system background threshold, over_bground_thresh() now checks if any cgroups are over their respective background dirty memory thresholds.
If over-limit cgroups are found, then the new wb_writeback_work.for_cgroup field is set to distinguish between system and memcg overages. The new wb_writeback_work.shared_inodes field is also set. Inodes written by multiple cgroup are marked owned by I_MEMCG_SHARED rather than a particular cgroup. Such shared inodes cannot easily be attributed to a cgroup, so per-cgroup writeback (futures version of wakeup_flusher_threads and balance_dirty_pages) performs suboptimally in the presence of shared inodes. Therefore, write shared inodes when performing cgroup background writeback.
If performing cgroup writeback, move_expired_inodes() skips inodes that do not contribute dirty pages to the cgroup being written back.
After writing some pages, wb_writeback() will call mem_cgroup_writeback_done() to update the set of over-bg-limits memcg.
This change also makes wakeup_flusher_threads() memcg aware so that per-cgroup try_to_free_pages() is able to operate more efficiently without having to write pages of foreign containers. This change adds a mem_cgroup parameter to wakeup_flusher_threads() to allow callers, especially try_to_free_pages() and foreground writeback from balance_dirty_pages(), to specify a particular cgroup to write inodes from.
---
Changelog since v8:
- Added optional memcg parameter to __bdi_start_writeback(), bdi_start_writeback(), wakeup_flusher_threads(), writeback_inodes_wb().
- move_expired_inodes() now uses pass in struct wb_writeback_work instead of struct writeback_control.
- Added comments to over_bground_thresh().
fs/buffer.c | 2 +- fs/fs-writeback.c | 96 +++++++++++++++++++++++++++++++++----------- fs/sync.c | 2 +- include/linux/writeback.h | 6 ++- mm/backing-dev.c | 3 +- mm/page-writeback.c | 3 +- mm/vmscan.c | 3 +- 7 files changed, 84 insertions(+), 31 deletions(-)
fs/buffer.c +1 -1
@@ -293,7 +293,7 @@ static void free_more_memory(void)struct zone *zone;int nid; -wakeup_flusher_threads (1024 ); +wakeup_flusher_threads (1024 ,NULL );yield ();for_each_online_node (nid) {
fs/fs-writeback.c +72 -24
197 lines not on this page · raw message
fs/sync.c +1 -1
@@ -98,7 +98,7 @@ static void sync_filesystems(int wait)*/ SYSCALL_DEFINE0 (sync) { -wakeup_flusher_threads (0 ); +wakeup_flusher_threads (0 ,NULL );sync_filesystems (0 );sync_filesystems (1 );if (unlikely (laptop_mode))
include/linux/writeback.h +4 -2
@@ -40,6 +40,7 @@#define MIN_WRITEBACK_PAGES (4096UL >> (PAGE_CACHE_SHIFT - 10))struct backing_dev_info ; +struct mem_cgroup ;/* * fs/fs-writeback.c
@@ -85,9 +86,10 @@ void writeback_inodes_sb_nr(struct super_block *, unsigned long nr);int writeback_inodes_sb_if_idle (struct super_block *);int writeback_inodes_sb_nr_if_idle (struct super_block *,unsigned long nr);void sync_inodes_sb (struct super_block *); -long writeback_inodes_wb (struct bdi_writeback *wb,long nr_pages); +long writeback_inodes_wb (struct bdi_writeback *wb,long nr_pages, +struct mem_cgroup *memcg,bool shared_inodes);long wb_do_writeback (struct bdi_writeback *wb,int force_wait); -void wakeup_flusher_threads (long nr_pages); +void wakeup_flusher_threads (long nr_pages,struct mem_cgroup *memcg);/* writeback.h requires fs.h; it, too, is not included from here. */ static inline void wait_on_inode (struct inode *inode)
mm/backing-dev.c +2 -1
@@ -456,7 +456,8 @@ static int bdi_forker_thread(void *ptr)* the bdi from the thread. Hopefully 1024 is * large enough for efficient IO. */ -writeback_inodes_wb (&bdi->wb,1024 ); +writeback_inodes_wb (&bdi->wb,1024 ,NULL , + false); }else {/* * The spinlock makes sure we do not lose
mm/page-writeback.c +2 -1
@@ -736,7 +736,8 @@ static void balance_dirty_pages(struct address_space *mapping,trace_balance_dirty_start (bdi);if (bdi_nr_reclaimable > task_bdi_thresh) { pages_written +=writeback_inodes_wb (&bdi->wb, - write_chunk); + write_chunk, +NULL , false);trace_balance_dirty_written (bdi, pages_written);if (pages_written >= write_chunk)break ;/* We've done our duty */
mm/vmscan.c +2 -1
@@ -2223,7 +2223,8 @@ static unsigned long do_try_to_free_pages(struct zonelist *zonelist,*/ writeback_threshold = sc->nr_to_reclaim + sc->nr_to_reclaim /2 ;if (total_scanned > writeback_threshold) { -wakeup_flusher_threads (laptop_mode ?0 : total_scanned); +wakeup_flusher_threads (laptop_mode ?0 : total_scanned, + sc->mem_cgroup); sc->may_writepage =1 ; }
Signature · 8 lines
1.7.3.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v9 11/13] writeback: make background writeback cgroup aware
Quoted 100 lines · On Wed, 17 Aug 2011 09:15:03 -0700 Greg Thelen <[email protected]> wrote:
When the system is under background dirty memory threshold but some cgroups are over their background dirty memory thresholds, then only writeback inodes associated with the over-limit cgroups.
In addition to checking if the system dirty memory usage is over the system background threshold,
over_bground_thresh()now checks if any cgroups are over their respective background dirty memory thresholds.If over-limit cgroups are found, then the new wb_writeback_work.for_cgroup field is set to distinguish between system and memcg overages. The new wb_writeback_work.shared_inodes field is also set. Inodes written by multiple cgroup are marked owned by
I_MEMCG_SHAREDrather than a particular cgroup. Such shared inodes cannot easily be attributed to a cgroup, so per-cgroup writeback (futures version ofwakeup_flusher_threadsandbalance_dirty_pages) performs suboptimally in the presence of shared inodes. Therefore, write shared inodes when performing cgroup background writeback.If performing cgroup writeback,
move_expired_inodes()skips inodes that do not contribute dirty pages to the cgroup being written back.After writing some pages,
wb_writeback()will callmem_cgroup_writeback_done()to update the set of over-bg-limits memcg.This change also makes
wakeup_flusher_threads()memcg aware so that per-cgrouptry_to_free_pages()is able to operate more efficiently without having to write pages of foreign containers. This change adds amem_cgroupparameter towakeup_flusher_threads()to allow callers, especiallytry_to_free_pages()and foreground writeback frombalance_dirty_pages(), to specify a particular cgroup to write inodes from.Signed-off-by Greg Thelen <[email protected]>---
Changelog since v8:- Added optional memcg parameter to
__bdi_start_writeback(),bdi_start_writeback(),wakeup_flusher_threads(),writeback_inodes_wb().-
move_expired_inodes()now uses pass in structwb_writeback_workinstead of structwriteback_control.- Added comments to
over_bground_thresh().fs/buffer.c | 2 +- fs/fs-writeback.c | 96 +++++++++++++++++++++++++++++++++----------- fs/sync.c | 2 +- include/linux/writeback.h | 6 ++- mm/backing-dev.c | 3 +- mm/page-writeback.c | 3 +- mm/vmscan.c | 3 +- 7 files changed, 84 insertions(+), 31 deletions(-)fs/buffer.c +1
-1@@ -293,7 +293,7 @@ static void free_more_memory(void)struct zone *zone;int nid; -wakeup_flusher_threads (1024 ); +wakeup_flusher_threads (1024 ,NULL );yield ();for_each_online_node (nid) {fs/fs-writeback.c +8
-1@@ -38,10 +38,14 @@ struct wb_writeback_work {struct super_block *sb;unsigned long *older_than_this;enum writeback_sync_modes sync_mode; +unsigned short memcg_id;/* If non-zero, then writeback specified +* cgroup. */ unsigned int tagged_writepages:1; unsigned int for_kupdate:1; unsigned int range_cyclic:1; unsigned int for_background:1; + unsigned int for_cgroup:1; /* cgroup writeback */ + unsigned int shared_inodes:1; /* write inodes spanning cgroups */struct list_head list;/* pending work list */ struct completion *done;/* set if the caller waits */ @@ -114,9 +118,12 @@ static void bdi_queue_work(struct backing_dev_info *bdi,spin_unlock_bh (&bdi->wb_lock); } +/* +* @memcg is optional. If set, then limit writeback to the specified cgroup. +*/ static void __bdi_start_writeback (struct backing_dev_info *bdi,long nr_pages, -bool range_cyclic) +bool range_cyclic,struct mem_cgroup *memcg) {struct wb_writeback_work *work;
fs/fs-writeback.c __bdi_start_writeback(struct backing_dev_info *bdi, long nr_pages, · line 148
Quoted 6 lines
fs/fs-writeback.c +2
-0@@ -136,6 +143,8 @@ __bdi_start_writeback(struct backing_dev_info *bdi, long nr_pages, work->sync_mode =WB_SYNC_NONE ; work->nr_pages = nr_pages; work->range_cyclic = range_cyclic; + work->memcg_id = memcg ?css_id (mem_cgroup_css (memcg)) :0 ; + work->for_cgroup = memcg !=NULL ;
I couldn't find a patch for mem_cgroup_css(NULL). Is it in patch 1-10 ? Other parts seems ok to me.
Thanks,
-Kame
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v9 11/13] writeback: make background writeback cgroup aware
Quoted 115 lines · KAMEZAWA Hiroyuki
Quoted 100 lines · On Wed, 17 Aug 2011 09:15:03 -0700 Greg Thelen <[email protected]> wrote:
When the system is under background dirty memory threshold but some cgroups are over their background dirty memory thresholds, then only writeback inodes associated with the over-limit cgroups.
In addition to checking if the system dirty memory usage is over the system background threshold,
over_bground_thresh()now checks if any cgroups are over their respective background dirty memory thresholds.If over-limit cgroups are found, then the new wb_writeback_work.for_cgroup field is set to distinguish between system and memcg overages. The new wb_writeback_work.shared_inodes field is also set. Inodes written by multiple cgroup are marked owned by
I_MEMCG_SHAREDrather than a particular cgroup. Such shared inodes cannot easily be attributed to a cgroup, so per-cgroup writeback (futures version ofwakeup_flusher_threadsandbalance_dirty_pages) performs suboptimally in the presence of shared inodes. Therefore, write shared inodes when performing cgroup background writeback.If performing cgroup writeback,
move_expired_inodes()skips inodes that do not contribute dirty pages to the cgroup being written back.After writing some pages,
wb_writeback()will callmem_cgroup_writeback_done()to update the set of over-bg-limits memcg.This change also makes
wakeup_flusher_threads()memcg aware so that per-cgrouptry_to_free_pages()is able to operate more efficiently without having to write pages of foreign containers. This change adds amem_cgroupparameter towakeup_flusher_threads()to allow callers, especiallytry_to_free_pages()and foreground writeback frombalance_dirty_pages(), to specify a particular cgroup to write inodes from.Signed-off-by Greg Thelen <[email protected]>---
Changelog since v8:- Added optional memcg parameter to
__bdi_start_writeback(),bdi_start_writeback(),wakeup_flusher_threads(),writeback_inodes_wb().-
move_expired_inodes()now uses pass in structwb_writeback_workinstead of structwriteback_control.- Added comments to
over_bground_thresh().fs/buffer.c | 2 +- fs/fs-writeback.c | 96 +++++++++++++++++++++++++++++++++----------- fs/sync.c | 2 +- include/linux/writeback.h | 6 ++- mm/backing-dev.c | 3 +- mm/page-writeback.c | 3 +- mm/vmscan.c | 3 +- 7 files changed, 84 insertions(+), 31 deletions(-)fs/buffer.c +1
-1@@ -293,7 +293,7 @@ static void free_more_memory(void)struct zone *zone;int nid; -wakeup_flusher_threads (1024 ); +wakeup_flusher_threads (1024 ,NULL );yield ();for_each_online_node (nid) {fs/fs-writeback.c +8
-1@@ -38,10 +38,14 @@ struct wb_writeback_work {struct super_block *sb;unsigned long *older_than_this;enum writeback_sync_modes sync_mode; +unsigned short memcg_id;/* If non-zero, then writeback specified +* cgroup. */ unsigned int tagged_writepages:1; unsigned int for_kupdate:1; unsigned int range_cyclic:1; unsigned int for_background:1; + unsigned int for_cgroup:1; /* cgroup writeback */ + unsigned int shared_inodes:1; /* write inodes spanning cgroups */struct list_head list;/* pending work list */ struct completion *done;/* set if the caller waits */ @@ -114,9 +118,12 @@ static void bdi_queue_work(struct backing_dev_info *bdi,spin_unlock_bh (&bdi->wb_lock); } +/* +* @memcg is optional. If set, then limit writeback to the specified cgroup. +*/ static void __bdi_start_writeback (struct backing_dev_info *bdi,long nr_pages, -bool range_cyclic) +bool range_cyclic,struct mem_cgroup *memcg) {struct wb_writeback_work *work;fs/fs-writeback.c __bdi_start_writeback(struct backing_dev_info *bdi, long nr_pages, · line 148
Quoted 6 lines
fs/fs-writeback.c +2
-0@@ -136,6 +143,8 @@ __bdi_start_writeback(struct backing_dev_info *bdi, long nr_pages, work->sync_mode =WB_SYNC_NONE ; work->nr_pages = nr_pages; work->range_cyclic = range_cyclic; + work->memcg_id = memcg ?css_id (mem_cgroup_css (memcg)) :0 ; + work->for_cgroup = memcg !=NULL ;I couldn't find a patch for
mem_cgroup_css(NULL). Is it in patch 1-10 ? Other parts seems ok to me.
Quoted 2 lines
Thanks,
-Kame
Mainline commit d324236b3333e87c8825b35f2104184734020d35 adds mem_cgroup_css() to memcontrol.c. The above code does not call mem_cgroup_css() with a NULL parameter due to the 'memcg ? ...' check. So I do not think any additional changes to mem_cgroup_css() are needed. Am I missing your point?
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v9 11/13] writeback: make background writeback cgroup aware
Quoted 117 lines · On Thu, 18 Aug 2011 00:10:56 -0700 Greg Thelen <[email protected]> wrote:
Quoted 115 lines · KAMEZAWA Hiroyuki
Quoted 100 lines · On Wed, 17 Aug 2011 09:15:03 -0700 Greg Thelen <[email protected]> wrote:
When the system is under background dirty memory threshold but some cgroups are over their background dirty memory thresholds, then only writeback inodes associated with the over-limit cgroups.
In addition to checking if the system dirty memory usage is over the system background threshold,
over_bground_thresh()now checks if any cgroups are over their respective background dirty memory thresholds.If over-limit cgroups are found, then the new wb_writeback_work.for_cgroup field is set to distinguish between system and memcg overages. The new wb_writeback_work.shared_inodes field is also set. Inodes written by multiple cgroup are marked owned by
I_MEMCG_SHAREDrather than a particular cgroup. Such shared inodes cannot easily be attributed to a cgroup, so per-cgroup writeback (futures version ofwakeup_flusher_threadsandbalance_dirty_pages) performs suboptimally in the presence of shared inodes. Therefore, write shared inodes when performing cgroup background writeback.If performing cgroup writeback,
move_expired_inodes()skips inodes that do not contribute dirty pages to the cgroup being written back.After writing some pages,
wb_writeback()will callmem_cgroup_writeback_done()to update the set of over-bg-limits memcg.This change also makes
wakeup_flusher_threads()memcg aware so that per-cgrouptry_to_free_pages()is able to operate more efficiently without having to write pages of foreign containers. This change adds amem_cgroupparameter towakeup_flusher_threads()to allow callers, especiallytry_to_free_pages()and foreground writeback frombalance_dirty_pages(), to specify a particular cgroup to write inodes from.Signed-off-by Greg Thelen <[email protected]>---
Changelog since v8:- Added optional memcg parameter to
__bdi_start_writeback(),bdi_start_writeback(),wakeup_flusher_threads(),writeback_inodes_wb().-
move_expired_inodes()now uses pass in structwb_writeback_workinstead of structwriteback_control.- Added comments to
over_bground_thresh().fs/buffer.c | 2 +- fs/fs-writeback.c | 96 +++++++++++++++++++++++++++++++++----------- fs/sync.c | 2 +- include/linux/writeback.h | 6 ++- mm/backing-dev.c | 3 +- mm/page-writeback.c | 3 +- mm/vmscan.c | 3 +- 7 files changed, 84 insertions(+), 31 deletions(-)fs/buffer.c +1
-1@@ -293,7 +293,7 @@ static void free_more_memory(void)struct zone *zone;int nid; -wakeup_flusher_threads (1024 ); +wakeup_flusher_threads (1024 ,NULL );yield ();for_each_online_node (nid) {fs/fs-writeback.c +8
-1@@ -38,10 +38,14 @@ struct wb_writeback_work {struct super_block *sb;unsigned long *older_than_this;enum writeback_sync_modes sync_mode; +unsigned short memcg_id;/* If non-zero, then writeback specified +* cgroup. */ unsigned int tagged_writepages:1; unsigned int for_kupdate:1; unsigned int range_cyclic:1; unsigned int for_background:1; + unsigned int for_cgroup:1; /* cgroup writeback */ + unsigned int shared_inodes:1; /* write inodes spanning cgroups */struct list_head list;/* pending work list */ struct completion *done;/* set if the caller waits */ @@ -114,9 +118,12 @@ static void bdi_queue_work(struct backing_dev_info *bdi,spin_unlock_bh (&bdi->wb_lock); } +/* +* @memcg is optional. If set, then limit writeback to the specified cgroup. +*/ static void __bdi_start_writeback (struct backing_dev_info *bdi,long nr_pages, -bool range_cyclic) +bool range_cyclic,struct mem_cgroup *memcg) {struct wb_writeback_work *work;fs/fs-writeback.c __bdi_start_writeback(struct backing_dev_info *bdi, long nr_pages, · line 148
Quoted 6 lines
fs/fs-writeback.c +2
-0@@ -136,6 +143,8 @@ __bdi_start_writeback(struct backing_dev_info *bdi, long nr_pages, work->sync_mode =WB_SYNC_NONE ; work->nr_pages = nr_pages; work->range_cyclic = range_cyclic; + work->memcg_id = memcg ?css_id (mem_cgroup_css (memcg)) :0 ; + work->for_cgroup = memcg !=NULL ;I couldn't find a patch for
mem_cgroup_css(NULL). Is it in patch 1-10 ? Other parts seems ok to me.
Quoted 9 lines
Quoted 2 lines
Thanks,
-KameMainline commit
d324236b3333e87c8825b35f2104184734020d35addsmem_cgroup_css()tomemcontrol.c. The above code does not callmem_cgroup_css()with a NULL parameter due to the 'memcg ? ...' check. So I do not think any additional changes tomem_cgroup_css()are needed. Am I missing your point?
I thought you need
==
struct cgroup_subsys_state *mem_cgroup_css(struct mem_cgroup *mem) {
+ if (!mem)
+ return NULL;
return &mem->css;
}==
And
==
unsigned short css_id(struct cgroup_subsys_state *css)
{
struct css_id *cssid;+ if (!css)
return 0; }
==
Thanks,
-Kame
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v9 11/13] writeback: make background writeback cgroup aware
Quoted 148 lines · KAMEZAWA Hiroyuki
Quoted 117 lines · On Thu, 18 Aug 2011 00:10:56 -0700 Greg Thelen <[email protected]> wrote:
Quoted 115 lines · KAMEZAWA Hiroyuki
Quoted 100 lines · On Wed, 17 Aug 2011 09:15:03 -0700 Greg Thelen <[email protected]> wrote:
When the system is under background dirty memory threshold but some cgroups are over their background dirty memory thresholds, then only writeback inodes associated with the over-limit cgroups.
In addition to checking if the system dirty memory usage is over the system background threshold,
over_bground_thresh()now checks if any cgroups are over their respective background dirty memory thresholds.If over-limit cgroups are found, then the new wb_writeback_work.for_cgroup field is set to distinguish between system and memcg overages. The new wb_writeback_work.shared_inodes field is also set. Inodes written by multiple cgroup are marked owned by
I_MEMCG_SHAREDrather than a particular cgroup. Such shared inodes cannot easily be attributed to a cgroup, so per-cgroup writeback (futures version ofwakeup_flusher_threadsandbalance_dirty_pages) performs suboptimally in the presence of shared inodes. Therefore, write shared inodes when performing cgroup background writeback.If performing cgroup writeback,
move_expired_inodes()skips inodes that do not contribute dirty pages to the cgroup being written back.After writing some pages,
wb_writeback()will callmem_cgroup_writeback_done()to update the set of over-bg-limits memcg.This change also makes
wakeup_flusher_threads()memcg aware so that per-cgrouptry_to_free_pages()is able to operate more efficiently without having to write pages of foreign containers. This change adds amem_cgroupparameter towakeup_flusher_threads()to allow callers, especiallytry_to_free_pages()and foreground writeback frombalance_dirty_pages(), to specify a particular cgroup to write inodes from.Signed-off-by Greg Thelen <[email protected]>---
Changelog since v8:- Added optional memcg parameter to
__bdi_start_writeback(),bdi_start_writeback(),wakeup_flusher_threads(),writeback_inodes_wb().-
move_expired_inodes()now uses pass in structwb_writeback_workinstead of structwriteback_control.- Added comments to
over_bground_thresh().fs/buffer.c | 2 +- fs/fs-writeback.c | 96 +++++++++++++++++++++++++++++++++----------- fs/sync.c | 2 +- include/linux/writeback.h | 6 ++- mm/backing-dev.c | 3 +- mm/page-writeback.c | 3 +- mm/vmscan.c | 3 +- 7 files changed, 84 insertions(+), 31 deletions(-)fs/buffer.c +1
-1@@ -293,7 +293,7 @@ static void free_more_memory(void)struct zone *zone;int nid; -wakeup_flusher_threads (1024 ); +wakeup_flusher_threads (1024 ,NULL );yield ();for_each_online_node (nid) {fs/fs-writeback.c +8
-1@@ -38,10 +38,14 @@ struct wb_writeback_work {struct super_block *sb;unsigned long *older_than_this;enum writeback_sync_modes sync_mode; +unsigned short memcg_id;/* If non-zero, then writeback specified +* cgroup. */ unsigned int tagged_writepages:1; unsigned int for_kupdate:1; unsigned int range_cyclic:1; unsigned int for_background:1; + unsigned int for_cgroup:1; /* cgroup writeback */ + unsigned int shared_inodes:1; /* write inodes spanning cgroups */struct list_head list;/* pending work list */ struct completion *done;/* set if the caller waits */ @@ -114,9 +118,12 @@ static void bdi_queue_work(struct backing_dev_info *bdi,spin_unlock_bh (&bdi->wb_lock); } +/* +* @memcg is optional. If set, then limit writeback to the specified cgroup. +*/ static void __bdi_start_writeback (struct backing_dev_info *bdi,long nr_pages, -bool range_cyclic) +bool range_cyclic,struct mem_cgroup *memcg) {struct wb_writeback_work *work;fs/fs-writeback.c __bdi_start_writeback(struct backing_dev_info *bdi, long nr_pages, · line 148
Quoted 6 lines
fs/fs-writeback.c +2
-0@@ -136,6 +143,8 @@ __bdi_start_writeback(struct backing_dev_info *bdi, long nr_pages, work->sync_mode =WB_SYNC_NONE ; work->nr_pages = nr_pages; work->range_cyclic = range_cyclic; + work->memcg_id = memcg ?css_id (mem_cgroup_css (memcg)) :0 ; + work->for_cgroup = memcg !=NULL ;I couldn't find a patch for
mem_cgroup_css(NULL). Is it in patch 1-10 ? Other parts seems ok to me.Quoted 9 lines
Quoted 2 lines
Thanks,
-KameMainline commit
d324236b3333e87c8825b35f2104184734020d35addsmem_cgroup_css()tomemcontrol.c. The above code does not callmem_cgroup_css()with a NULL parameter due to the 'memcg ? ...' check. So I do not think any additional changes tomem_cgroup_css()are needed. Am I missing your point?I thought you need
==
structcgroup_subsys_state*mem_cgroup_css(structmem_cgroup*mem) {(quoted diff) +2
-0+ if (!mem) + return NULL; return &mem->css;}
==
And
==
unsigned shortcss_id(struct cgroup_subsys_state *css){ struct css_id *cssid;(quoted diff) +1
-0+ if (!css)return 0; }
Quoted 4 lines
==
Thanks,
-Kame
I think that your changes to mem_cgroup_css() and css_id() are unnecessary for my patches because my patches do not call mem_cgroup_css(NULL). The "?" check below prevents NULL from being passed into mem_cgroup_css():
+ work->memcg_id = memcg ? css_id(mem_cgroup_css(memcg)) : 0;
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v9 11/13] writeback: make background writeback cgroup aware
Quoted 161 lines · On Thu, 18 Aug 2011 00:38:49 -0700 Greg Thelen <[email protected]> wrote:
Quoted 148 lines · KAMEZAWA Hiroyuki
Quoted 117 lines · On Thu, 18 Aug 2011 00:10:56 -0700 Greg Thelen <[email protected]> wrote:
Quoted 115 lines · KAMEZAWA Hiroyuki
Quoted 100 lines · On Wed, 17 Aug 2011 09:15:03 -0700 Greg Thelen <[email protected]> wrote:
When the system is under background dirty memory threshold but some cgroups are over their background dirty memory thresholds, then only writeback inodes associated with the over-limit cgroups.
In addition to checking if the system dirty memory usage is over the system background threshold,
over_bground_thresh()now checks if any cgroups are over their respective background dirty memory thresholds.If over-limit cgroups are found, then the new wb_writeback_work.for_cgroup field is set to distinguish between system and memcg overages. The new wb_writeback_work.shared_inodes field is also set. Inodes written by multiple cgroup are marked owned by
I_MEMCG_SHAREDrather than a particular cgroup. Such shared inodes cannot easily be attributed to a cgroup, so per-cgroup writeback (futures version ofwakeup_flusher_threadsandbalance_dirty_pages) performs suboptimally in the presence of shared inodes. Therefore, write shared inodes when performing cgroup background writeback.If performing cgroup writeback,
move_expired_inodes()skips inodes that do not contribute dirty pages to the cgroup being written back.After writing some pages,
wb_writeback()will callmem_cgroup_writeback_done()to update the set of over-bg-limits memcg.This change also makes
wakeup_flusher_threads()memcg aware so that per-cgrouptry_to_free_pages()is able to operate more efficiently without having to write pages of foreign containers. This change adds amem_cgroupparameter towakeup_flusher_threads()to allow callers, especiallytry_to_free_pages()and foreground writeback frombalance_dirty_pages(), to specify a particular cgroup to write inodes from.Signed-off-by Greg Thelen <[email protected]>---
Changelog since v8:- Added optional memcg parameter to
__bdi_start_writeback(),bdi_start_writeback(),wakeup_flusher_threads(),writeback_inodes_wb().-
move_expired_inodes()now uses pass in structwb_writeback_workinstead of structwriteback_control.- Added comments to
over_bground_thresh().fs/buffer.c | 2 +- fs/fs-writeback.c | 96 +++++++++++++++++++++++++++++++++----------- fs/sync.c | 2 +- include/linux/writeback.h | 6 ++- mm/backing-dev.c | 3 +- mm/page-writeback.c | 3 +- mm/vmscan.c | 3 +- 7 files changed, 84 insertions(+), 31 deletions(-)fs/buffer.c +1
-1@@ -293,7 +293,7 @@ static void free_more_memory(void)struct zone *zone;int nid; -wakeup_flusher_threads (1024 ); +wakeup_flusher_threads (1024 ,NULL );yield ();for_each_online_node (nid) {fs/fs-writeback.c +8
-1@@ -38,10 +38,14 @@ struct wb_writeback_work {struct super_block *sb;unsigned long *older_than_this;enum writeback_sync_modes sync_mode; +unsigned short memcg_id;/* If non-zero, then writeback specified +* cgroup. */ unsigned int tagged_writepages:1; unsigned int for_kupdate:1; unsigned int range_cyclic:1; unsigned int for_background:1; + unsigned int for_cgroup:1; /* cgroup writeback */ + unsigned int shared_inodes:1; /* write inodes spanning cgroups */struct list_head list;/* pending work list */ struct completion *done;/* set if the caller waits */ @@ -114,9 +118,12 @@ static void bdi_queue_work(struct backing_dev_info *bdi,spin_unlock_bh (&bdi->wb_lock); } +/* +* @memcg is optional. If set, then limit writeback to the specified cgroup. +*/ static void __bdi_start_writeback (struct backing_dev_info *bdi,long nr_pages, -bool range_cyclic) +bool range_cyclic,struct mem_cgroup *memcg) {struct wb_writeback_work *work;fs/fs-writeback.c __bdi_start_writeback(struct backing_dev_info *bdi, long nr_pages, · line 148
Quoted 6 lines
fs/fs-writeback.c +2
-0@@ -136,6 +143,8 @@ __bdi_start_writeback(struct backing_dev_info *bdi, long nr_pages, work->sync_mode =WB_SYNC_NONE ; work->nr_pages = nr_pages; work->range_cyclic = range_cyclic; + work->memcg_id = memcg ?css_id (mem_cgroup_css (memcg)) :0 ; + work->for_cgroup = memcg !=NULL ;I couldn't find a patch for
mem_cgroup_css(NULL). Is it in patch 1-10 ? Other parts seems ok to me.Quoted 9 lines
Quoted 2 lines
Thanks,
-KameMainline commit
d324236b3333e87c8825b35f2104184734020d35addsmem_cgroup_css()tomemcontrol.c. The above code does not callmem_cgroup_css()with a NULL parameter due to the 'memcg ? ...' check. So I do not think any additional changes tomem_cgroup_css()are needed. Am I missing your point?I thought you need
==
structcgroup_subsys_state*mem_cgroup_css(structmem_cgroup*mem) {(quoted diff) +2
-0+ if (!mem) + return NULL; return &mem->css;}
==
And
==
unsigned shortcss_id(struct cgroup_subsys_state *css){ struct css_id *cssid;(quoted diff) +1
-0+ if (!css)return 0; }Quoted 4 lines
==
Thanks,
-KameI think that your changes to
mem_cgroup_css()andcss_id()are unnecessary for my patches because my patches do not callmem_cgroup_css(NULL). The "?" check below prevents NULL from being passed intomem_cgroup_css():
fs/fs-writeback.c __bdi_start_writeback(struct backing_dev_info *bdi, long nr_pages, · line 146
Quoted 1 line
fs/fs-writeback.c +1
-0+ work->memcg_id = memcg ?css_id (mem_cgroup_css (memcg)) :0 ;
Ah, I see. Thank you for clarification.
Thanks,
-Kame
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v9 12/13 memcg: create support routines for page writeback
In reply to Greg ThelenIntroduce memcg routines to assist in per-memcg dirty page management:
- mem_cgroup_balance_dirty_pages() walks a memcg hierarchy comparing dirty memory usage against memcg foreground and background thresholds. If an over-background-threshold memcg is found, then per-memcg background writeback is queued. Per-memcg writeback differs from classic, non-memcg, per bdi writeback by setting the new writeback_control.for_cgroup bit.
If an over-foreground-threshold memcg is found, then foreground writeout occurs. When performing foreground writeout, first consider inodes exclusive to the memcg. If unable to make enough progress, then consider inodes shared between memcg. Such cross-memcg inode sharing likely to be rare in situations that use per-cgroup memory isolation. So the approach tries to handle the common case well without falling over in cases where such sharing exists. This routine is used by balance_dirty_pages() in a later change.
- mem_cgroup_hierarchical_dirty_info() returns the dirty memory usage and limits of the memcg closest to (or over) its dirty limit. This will be used by throttle_vm_writeout() in a latter change.
---
Changelog since v8:
- Use 'memcg' rather than 'mem' for local variables and parameters. This is consistent with other memory controller code.
- No more field additions to struct writeback_control.
- Added more comments to mem_cgroup_balance_dirty_pages().
- Adapted to changes in writeback_inodes_wb().
- Improved mem_cgroup_hierarchical_dirty_info() comment.
include/linux/memcontrol.h | 18 ++++ include/trace/events/memcontrol.h | 88 ++++++++++++++++++++ mm/memcontrol.c | 165 +++++++++++++++++++++++++++++++++++++ 3 files changed, 271 insertions(+), 0 deletions(-)
include/linux/memcontrol.h +18 -0
@@ -186,6 +186,11 @@ bool should_writeback_mem_cgroup_inode(struct inode *inode, bool shared_inodes);bool mem_cgroups_over_bground_dirty_thresh (void );void mem_cgroup_writeback_done (void ); +bool mem_cgroup_hierarchical_dirty_info (unsigned long sys_available_mem, +struct mem_cgroup *memcg, +struct dirty_info *info); +void mem_cgroup_balance_dirty_pages (struct address_space *mapping, +unsigned long write_chunk); unsigned long mem_cgroup_soft_limit_reclaim(struct zone *zone, int order, gfp_t gfp_mask,
@@ -402,6 +407,19 @@ static inline void mem_cgroup_writeback_done(void) { } +static inline void mem_cgroup_balance_dirty_pages (struct address_space *mapping, +unsigned long write_chunk) +{ +} + +static inline bool +mem_cgroup_hierarchical_dirty_info (unsigned long sys_available_mem, +struct mem_cgroup *memcg, +struct dirty_info *info) +{ +return false; +} + static inline unsigned long mem_cgroup_soft_limit_reclaim(struct zone *zone, int order, gfp_t gfp_mask,
include/trace/events/memcontrol.h +88 -0
94 lines not on this page · raw message
mm/memcontrol.c +165 -0
171 lines not on this page · raw message
Signature · 8 lines
1.7.3.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v9 12/13] memcg: create support routines for page writeback
Quoted 18 lines · On Wed, 17 Aug 2011 09:15:04 -0700 Greg Thelen <[email protected]> wrote:
Introduce memcg routines to assist in per-memcg dirty page management:
-
mem_cgroup_balance_dirty_pages()walks a memcg hierarchy comparing dirty memory usage against memcg foreground and background thresholds. If an over-background-threshold memcg is found, then per-memcg background writeback is queued. Per-memcg writeback differs from classic, non-memcg, per bdi writeback by setting the new writeback_control.for_cgroup bit.If an over-foreground-threshold memcg is found, then foreground writeout occurs. When performing foreground writeout, first consider inodes exclusive to the memcg. If unable to make enough progress, then consider inodes shared between memcg. Such cross-memcg inode sharing likely to be rare in situations that use per-cgroup memory isolation. So the approach tries to handle the common case well without falling over in cases where such sharing exists. This routine is used by
balance_dirty_pages()in a later change.
Quoted 5 lines
-
mem_cgroup_hierarchical_dirty_info()returns the dirty memory usage and limits of the memcg closest to (or over) its dirty limit. This will be used bythrottle_vm_writeout()in a latter change.Signed-off-by Greg Thelen <[email protected]>
Comparing page-writebakc.c, I have some questions.
Quoted 78 lines
mm/memcontrol.c +78
-0+/* +* This routine must be called periodically by processes which generate dirty +* pages. It considers the dirty pages usage and thresholds of the current +* cgroup and (depending if hierarchical accounting is enabled) ancestral memcg. +* If any of the considered memcg are over their background dirty limit, then +* background writeback is queued. If any are over the foreground dirty limit +* then the dirtying task is throttled while writing dirty data. The per-memcg +* dirty limits checked by this routine are distinct from either the per-system, +* per-bdi, or per-task limits considered by balance_dirty_pages(). +* +* Example hierarchy: +* root +* A B +* A1 A2 B1 +* A11 A12 A21 A22 +* +* Assume that mem_cgroup_balance_dirty_pages() is called on A11. This routine +* starts at A11 walking upwards towards the root. If A11 is over dirty limit, +* then writeback A11 inodes until under limit. Next check A1, if over limit +* then write A1,A11,A12. Then check A. If A is over A limit, then invoke +* writeback on A* until A is under A limit. +*/ +void mem_cgroup_balance_dirty_pages (struct address_space *mapping, +unsigned long write_chunk) +{ +struct backing_dev_info *bdi = mapping->backing_dev_info; +struct mem_cgroup *memcg; +struct mem_cgroup *ref_memcg; +struct dirty_info info; +unsigned long nr_reclaimable; +unsigned long nr_written; +unsigned long sys_available_mem; +unsigned long pause =1 ; +unsigned short id; +bool over; +bool shared_inodes; + +if (mem_cgroup_disabled ()) +return ; + + sys_available_mem =determine_dirtyable_memory (); + +/* reference the memcg so it is not deleted during this routine */ +rcu_read_lock (); + memcg =mem_cgroup_from_task (current); +if (memcg &&mem_cgroup_is_root (memcg)) + memcg =NULL ; +if (memcg) +css_get (&memcg->css); +rcu_read_unlock (); + ref_memcg = memcg; + +/* balance entire ancestry of current's memcg. */ +for (;mem_cgroup_has_dirty_limit (memcg); + memcg =parent_mem_cgroup (memcg)) { + id =css_id (&memcg->css); + +/* +* Keep throttling and writing inode data so long as memcg is +* over its dirty limit. Inode being written by multiple memcg +* (aka shared_inodes) cannot easily be attributed a particular +* memcg. Shared inodes are thought to be much rarer than +* shared inodes. First try to satisfy this memcg's dirty +* limits using non-shared inodes. +*/ +for (shared_inodes = false; ; ) { +/* +* if memcg is under dirty limit, then break from +* throttling loop. +*/ +mem_cgroup_dirty_info (sys_available_mem, memcg, &info); + nr_reclaimable =dirty_info_reclaimable (&info); + over = nr_reclaimable > info.dirty_thresh; +trace_mem_cgroup_consider_fg_writeback ( + id, bdi, nr_reclaimable, info.dirty_thresh, + over); +if (!over) +break ;
mm/memcontrol.c void mem_cgroup_writeback_done(void) · line 1786
Quoted 10 lines
mm/memcontrol.c +10
-0+ + nr_written =writeback_inodes_wb (&bdi->wb, write_chunk, + memcg, shared_inodes); +trace_mem_cgroup_fg_writeback (write_chunk, nr_written, + id, shared_inodes); +/* if no progress, then consider shared inodes */ +if ((nr_written ==0 ) && !shared_inodes) { +trace_mem_cgroup_enable_shared_writeback (id); + shared_inodes = true; + }
in page-writeback.c
if (pages_written >= write_chunk)
break; /* We've done our duty */
write_chunk(ratelimit) is used. Can't we make use of this threshold ?
mm/memcontrol.c void mem_cgroup_writeback_done(void) · line 1790
Quoted 4 lines
mm/memcontrol.c +4
-0+ +__set_current_state (TASK_UNINTERRUPTIBLE ); +io_schedule_timeout (pause); +
How do you think about MAX_PAUSE/PASS_GOOD ?
==
/*
* max-pause area. If dirty exceeded but still within this
* area, no need to sleep for more than 200ms: (a) 8 pages per
* 200ms is typically more than enough to curb heavy dirtiers;
* (b) the pause time limit makes the dirtiers more responsive. */
if (nr_dirty < dirty_thresh +
dirty_thresh / DIRTY_MAXPAUSE_AREA &&
time_after(jiffies, start_time + MAX_PAUSE))
break;
/*
* pass-good area. When some bdi gets blocked (eg. NFS server
* not responding), or write bandwidth dropped dramatically due
* to concurrent reads, or dirty threshold suddenly dropped and
* the dirty pages cannot be brought down anytime soon (eg. on
* slow USB stick), at least let go of the good bdi's. */
if (nr_dirty < dirty_thresh +
dirty_thresh / DIRTY_PASSGOOD_AREA &&
bdi_dirty < bdi_thresh)
break;
==
Thanks,
-Kame
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Wu Fengguang
Tested-by Li ShaohuaRe: [PATCH v9 12/13] memcg: create support routines for page writeback
Quoted 21 lines
Review
Quoted 4 lines
(quoted diff) +4
-0+ + __set_current_state(TASK_UNINTERRUPTIBLE); + io_schedule_timeout(pause); +How do you think about MAX_PAUSE/PASS_GOOD ?
==
/*
* max-pause area. If dirty exceeded but still within this
* area, no need to sleep for more than 200ms: (a) 8 pages per
* 200ms is typically more than enough to curb heavy dirtiers;
* (b) the pause time limit makes the dirtiers more responsive. */
if (nr_dirty<dirty_thresh+
dirty_thresh/DIRTY_MAXPAUSE_AREA&&
time_after(jiffies, start_time + MAX_PAUSE))
break;
/*
* pass-good area. When some bdi gets blocked (eg. NFS server
* not responding), or write bandwidth dropped dramatically due
* to concurrent reads, or dirty threshold suddenly dropped and
Quoted 8 lines
* the dirty pages cannot be brought down anytime soon (eg. on
* slow USB stick), at least let go of the good bdi's. */
if (nr_dirty<dirty_thresh+
dirty_thresh/DIRTY_PASSGOOD_AREA&&
bdi_dirty<bdi_thresh)
break;
==
Sorry that piece of code actually has some problems in JBOD setup. I'm going to submit a patch for fixing it:
Subject: squeeze max-pause area and drop pass-good area
Date: Tue Aug 16 13:37:14 CST 2011
Remove the pass-good area introduced in ffd1f609ab10 ("writeback:
introduce max-pause and pass-good dirty limits") and make the max-pause area smaller and safe.
This fixes ~30% performance regression in the ext3 data=writeback fio_mmap_randwrite_64k/fio_mmap_randrw_64k test cases, where there are 12 JBOD disks, on each disk runs 8 concurrent tasks doing reads+writes.
Using deadline scheduler also has a regression, but not that big as CFQ, so this suggests we have some write starvation.
The test logs show that
- the disks are sometimes under utilized
- global dirty pages sometimes rush high to the pass-good area for several hundred seconds, while in the mean time some bdi dirty pages drop to very low value (bdi_dirty << bdi_thresh).
Then suddenly the global dirty pages dropped under global dirty threshold and bdi_dirty rush very high (for example, 2 times higher than bdi_thresh). During which time balance_dirty_pages() is not called at all.
So the problems are
1) The random writes progress so slow that they break the assumption of the max-pause logic that "8 pages per 200ms is typically more than enough to curb heavy dirtiers".
2) The max-pause logic ignored task_bdi_thresh and thus opens the possibility for some bdi's to over dirty pages, leading to (bdi_dirty >> bdi_thresh) and then (bdi_thresh >> bdi_dirty) for others.
3) The higher max-pause/pass-good thresholds somehow leads to some bad swing of dirty pages.
The fix is to allow the task to slightly dirty over task_bdi_thresh, but no way to exceed bdi_dirty and/or global dirty_thresh.
Tests show that it fixed the JBOD regression completely (both behavior and performance), while still being able to cut down large pause times in balance_dirty_pages() for single-disk cases.
--- include/linux/writeback.h | 11 ----------- mm/page-writeback.c | 15 ++------------- 2 files changed, 2 insertions(+), 24 deletions(-)
mm/page-writeback.c +2 -13
@@ -786,21 +786,10 @@ static void balance_dirty_pages(struct a* 200ms is typically more than enough to curb heavy dirtiers; * (b) the pause time limit makes the dirtiers more responsive. */ -if (nr_dirty < dirty_thresh + - dirty_thresh /DIRTY_MAXPAUSE_AREA && +if (nr_dirty < dirty_thresh && + bdi_dirty < (task_bdi_thresh + bdi_thresh) /2 &&time_after (jiffies, start_time +MAX_PAUSE ))break ; -/* -* pass-good area. When some bdi gets blocked (eg. NFS server -* not responding), or write bandwidth dropped dramatically due -* to concurrent reads, or dirty threshold suddenly dropped and -* the dirty pages cannot be brought down anytime soon (eg. on -* slow USB stick), at least let go of the good bdi's. -*/ -if (nr_dirty < dirty_thresh + - dirty_thresh /DIRTY_PASSGOOD_AREA && - bdi_dirty < bdi_thresh) -break ;/* * Increase the delay for each loop, up to our previous
include/linux/writeback.h +0 -11
@@ -12,15 +12,6 @@* * (thresh - thresh/DIRTY_FULL_SCOPE, thresh) * -* The 1/16 region above the global dirty limit will be put to maximum pauses: -* -* (limit, limit + limit/DIRTY_MAXPAUSE_AREA) -* -* The 1/16 region above the max-pause region, dirty exceeded bdi's will be put -* to loops: -* -* (limit + limit/DIRTY_MAXPAUSE_AREA, limit + limit/DIRTY_PASSGOOD_AREA) -* * Further beyond, all dirtier tasks will enter a loop waiting (possibly long * time) for the dirty pages to drop, unless written enough pages. *
@@ -31,8 +22,6 @@*/ #define DIRTY_SCOPE 8#define DIRTY_FULL_SCOPE (DIRTY_SCOPE / 2) -#define DIRTY_MAXPAUSE_AREA 16 -#define DIRTY_PASSGOOD_AREA 8/* * 4MB minimal write chunk size
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Jan Kara
maintainerRe: [PATCH v9 12/13] memcg: create support routines for page writeback
Quoted 57 lines · Wu Fengguang
Subject: squeeze max-pause area and drop pass-good area
Date: Tue Aug 16 13:37:14 CST 2011Remove the pass-good area introduced in
ffd1f609ab10("writeback:
introduce max-pause and pass-good dirty limits") and make the max-pause area smaller and safe.This fixes ~30% performance regression in the ext3 data=writeback fio_mmap_randwrite_64k/fio_mmap_randrw_64k test cases, where there are 12 JBOD disks, on each disk runs 8 concurrent tasks doing reads+writes.
Using deadline scheduler also has a regression, but not that big as CFQ, so this suggests we have some write starvation.
The test logs show that
- the disks are sometimes under utilized
- global dirty pages sometimes rush high to the pass-good area for several hundred seconds, while in the mean time some bdi dirty pages drop to very low value (
bdi_dirty<<bdi_thresh).
Then suddenly the global dirty pages dropped under global dirty threshold andbdi_dirtyrush very high (for example, 2 times higher thanbdi_thresh). During which timebalance_dirty_pages()is not called at all.So the problems are
1) The random writes progress so slow that they break the assumption of the max-pause logic that "8 pages per 200ms is typically more than enough to curb heavy dirtiers".
2) The max-pause logic ignored
task_bdi_threshand thus opens the possibility for some bdi's to over dirty pages, leading to (bdi_dirty>>bdi_thresh) and then (bdi_thresh>>bdi_dirty) for others.3) The higher max-pause/pass-good thresholds somehow leads to some bad swing of dirty pages.
The fix is to allow the task to slightly dirty over
task_bdi_thresh, but no way to exceedbdi_dirtyand/or globaldirty_thresh.Tests show that it fixed the JBOD regression completely (both behavior and performance), while still being able to cut down large pause times in
balance_dirty_pages()for single-disk cases.Reported-by Li Shaohua <[email protected]>Tested-by Li Shaohua <[email protected]>Signed-off-by Wu Fengguang <[email protected]>--- include/linux/writeback.h | 11 ----------- mm/page-writeback.c | 15 ++------------- 2 files changed, 2 insertions(+), 24 deletions(-)
mm/page-writeback.c static void balance_dirty_pages(struct a · line 792
Quoted 9 lines
mm/page-writeback.c +2
-2@@ -786,21 +786,10 @@ static void balance_dirty_pages(struct a* 200ms is typically more than enough to curb heavy dirtiers; * (b) the pause time limit makes the dirtiers more responsive. */ -if (nr_dirty < dirty_thresh + - dirty_thresh /DIRTY_MAXPAUSE_AREA && +if (nr_dirty < dirty_thresh && + bdi_dirty < (task_bdi_thresh + bdi_thresh) /2 &&time_after (jiffies, start_time +MAX_PAUSE ))break ;
This looks definitely much safer than the original patch since we now
always observe global dirty limit. I just wonder: We have throttled the task because bdi_nr_reclaimable > task_bdi_thresh. Now in practice there should be some pages under writeback and this task should have submitted even more just a while ago. So the condition
bdi_dirty < (task_bdi_thresh + bdi_thresh) / 2
looks still relatively weak. Shouldn't there be
bdi_nr_reclaimable < (task_bdi_thresh + bdi_thresh) / 2?
Since bdi_nr_reclaimable is really the number we want to limit... Alternatively, I could see also a reason for
bdi_dirty < task_bdi_thresh
which leaves the task pages under writeback as the pausing area. But since these are not really well limited, I'd prefer my first suggestion.
Honza
Quoted 41 lines
mm/page-writeback.c +0
-11-/* -* pass-good area. When some bdi gets blocked (eg. NFS server -* not responding), or write bandwidth dropped dramatically due -* to concurrent reads, or dirty threshold suddenly dropped and -* the dirty pages cannot be brought down anytime soon (eg. on -* slow USB stick), at least let go of the good bdi's. -*/ -if (nr_dirty < dirty_thresh + - dirty_thresh /DIRTY_PASSGOOD_AREA && - bdi_dirty < bdi_thresh) -break ;/* * Increase the delay for each loop, up to our previous include/linux/writeback.h +0
-11@@ -12,15 +12,6 @@* * (thresh - thresh/DIRTY_FULL_SCOPE, thresh) * -* The 1/16 region above the global dirty limit will be put to maximum pauses: -* -* (limit, limit + limit/DIRTY_MAXPAUSE_AREA) -* -* The 1/16 region above the max-pause region, dirty exceeded bdi's will be put -* to loops: -* -* (limit + limit/DIRTY_MAXPAUSE_AREA, limit + limit/DIRTY_PASSGOOD_AREA) -* * Further beyond, all dirtier tasks will enter a loop waiting (possibly long * time) for the dirty pages to drop, unless written enough pages. * @@ -31,8 +22,6 @@*/ #define DIRTY_SCOPE 8#define DIRTY_FULL_SCOPE (DIRTY_SCOPE / 2) -#define DIRTY_MAXPAUSE_AREA 16 -#define DIRTY_PASSGOOD_AREA 8/* * 4MB minimal write chunk size
Signature · 9 lines
Jan Kara <[email protected]> SUSE Labs, CR -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v9 12/13] memcg: create support routines for page writeback
Quoted 55 lines · Jan Kara
Quoted 54 lines · Wu Fengguang
Subject: squeeze max-pause area and drop pass-good area
Date: Tue Aug 16 13:37:14 CST 2011Remove the pass-good area introduced in
ffd1f609ab10("writeback:
introduce max-pause and pass-good dirty limits") and make the max-pause area smaller and safe.This fixes ~30% performance regression in the ext3 data=writeback fio_mmap_randwrite_64k/fio_mmap_randrw_64k test cases, where there are 12 JBOD disks, on each disk runs 8 concurrent tasks doing reads+writes.
Using deadline scheduler also has a regression, but not that big as CFQ, so this suggests we have some write starvation.
The test logs show that
- the disks are sometimes under utilized
- global dirty pages sometimes rush high to the pass-good area for several hundred seconds, while in the mean time some bdi dirty pages drop to very low value (
bdi_dirty<<bdi_thresh).
Then suddenly the global dirty pages dropped under global dirty threshold andbdi_dirtyrush very high (for example, 2 times higher thanbdi_thresh). During which timebalance_dirty_pages()is not called at all.So the problems are
1) The random writes progress so slow that they break the assumption of the max-pause logic that "8 pages per 200ms is typically more than enough to curb heavy dirtiers".
2) The max-pause logic ignored
task_bdi_threshand thus opens the possibility for some bdi's to over dirty pages, leading to (bdi_dirty>>bdi_thresh) and then (bdi_thresh>>bdi_dirty) for others.3) The higher max-pause/pass-good thresholds somehow leads to some bad swing of dirty pages.
The fix is to allow the task to slightly dirty over
task_bdi_thresh, but no way to exceedbdi_dirtyand/or globaldirty_thresh.Tests show that it fixed the JBOD regression completely (both behavior and performance), while still being able to cut down large pause times in
balance_dirty_pages()for single-disk cases.Reported-by Li Shaohua <[email protected]>Tested-by Li Shaohua <[email protected]>Signed-off-by Wu Fengguang <[email protected]>--- include/linux/writeback.h | 11 ----------- mm/page-writeback.c | 15 ++------------- 2 files changed, 2 insertions(+), 24 deletions(-)
Quoted 14 lines
mm/page-writeback.c static void balance_dirty_pages(struct a · line 792
Quoted 12 lines
mm/page-writeback.c +2
-2@@ -786,21 +786,10 @@ static void balance_dirty_pages(struct a* 200ms is typically more than enough to curb heavy dirtiers; * (b) the pause time limit makes the dirtiers more responsive. */ -if (nr_dirty < dirty_thresh + - dirty_thresh /DIRTY_MAXPAUSE_AREA && +if (nr_dirty < dirty_thresh && + bdi_dirty < (task_bdi_thresh + bdi_thresh) /2 &&time_after (jiffies, start_time +MAX_PAUSE ))break ;This looks definitely much safer than the original patch since we now
always observe global dirty limit.
Yeah.
Quoted 2 lines
I just wonder: We have throttled the
task becausebdi_nr_reclaimable>task_bdi_thresh.
Not necessarily. It's possible (bdi_nr_reclaimable < task_bdi_thresh) for the whole loop. And the 200ms pause that trigger the above test may totally come from the io_schedule_timeout() calls.
Quoted 4 lines
Now in practice there
should be some pages under writeback and this task should have submitted even more just a while ago. So the condition
bdi_dirty< (task_bdi_thresh+bdi_thresh) / 2
I guess the writeback_inodes_wb() call is irrelevant for the above test, because writeback_inodes_wb() transfers reclaimable pages to writeback pages, with the total bdi_dirty value staying the same. Not to mention the fact that both the bdi_dirty and bdi_nr_reclaimable variables have not been updated between writeback_inodes_wb() and the max-pause test.
Quoted 2 lines
looks still relatively weak. Shouldn't there be
bdi_nr_reclaimable< (task_bdi_thresh+bdi_thresh) / 2?
That's much easier condition to satisfy..
Quoted 5 lines
Since
bdi_nr_reclaimableis really the number we want to limit... Alternatively, I could see also a reason for
bdi_dirty<task_bdi_thresh
which leaves the task pages under writeback as the pausing area. But since these are not really well limited, I'd prefer my first suggestion.
Thanks,
Fengguang
Quoted 39 lines
Quoted 39 lines
mm/page-writeback.c +0
-11-/* -* pass-good area. When some bdi gets blocked (eg. NFS server -* not responding), or write bandwidth dropped dramatically due -* to concurrent reads, or dirty threshold suddenly dropped and -* the dirty pages cannot be brought down anytime soon (eg. on -* slow USB stick), at least let go of the good bdi's. -*/ -if (nr_dirty < dirty_thresh + - dirty_thresh /DIRTY_PASSGOOD_AREA && - bdi_dirty < bdi_thresh) -break ;/* * Increase the delay for each loop, up to our previous include/linux/writeback.h +0
-11@@ -12,15 +12,6 @@* * (thresh - thresh/DIRTY_FULL_SCOPE, thresh) * -* The 1/16 region above the global dirty limit will be put to maximum pauses: -* -* (limit, limit + limit/DIRTY_MAXPAUSE_AREA) -* -* The 1/16 region above the max-pause region, dirty exceeded bdi's will be put -* to loops: -* -* (limit + limit/DIRTY_MAXPAUSE_AREA, limit + limit/DIRTY_PASSGOOD_AREA) -* * Further beyond, all dirtier tasks will enter a loop waiting (possibly long * time) for the dirty pages to drop, unless written enough pages. * @@ -31,8 +22,6 @@*/ #define DIRTY_SCOPE 8#define DIRTY_FULL_SCOPE (DIRTY_SCOPE / 2) -#define DIRTY_MAXPAUSE_AREA 16 -#define DIRTY_PASSGOOD_AREA 8
Quoted 5 lines
Quoted 2 lines
include/linux/writeback.h +0
-0/* * 4MB minimal write chunk size Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v9 12/13] memcg: create support routines for page writeback
Quoted 85 lines · Wu Fengguang
Quoted 55 lines · Jan Kara
Quoted 54 lines · Wu Fengguang
Subject: squeeze max-pause area and drop pass-good area
Date: Tue Aug 16 13:37:14 CST 2011Remove the pass-good area introduced in
ffd1f609ab10("writeback:
introduce max-pause and pass-good dirty limits") and make the max-pause area smaller and safe.This fixes ~30% performance regression in the ext3 data=writeback fio_mmap_randwrite_64k/fio_mmap_randrw_64k test cases, where there are 12 JBOD disks, on each disk runs 8 concurrent tasks doing reads+writes.
Using deadline scheduler also has a regression, but not that big as CFQ, so this suggests we have some write starvation.
The test logs show that
- the disks are sometimes under utilized
- global dirty pages sometimes rush high to the pass-good area for several hundred seconds, while in the mean time some bdi dirty pages drop to very low value (
bdi_dirty<<bdi_thresh).
Then suddenly the global dirty pages dropped under global dirty threshold andbdi_dirtyrush very high (for example, 2 times higher thanbdi_thresh). During which timebalance_dirty_pages()is not called at all.So the problems are
1) The random writes progress so slow that they break the assumption of the max-pause logic that "8 pages per 200ms is typically more than enough to curb heavy dirtiers".
2) The max-pause logic ignored
task_bdi_threshand thus opens the possibility for some bdi's to over dirty pages, leading to (bdi_dirty>>bdi_thresh) and then (bdi_thresh>>bdi_dirty) for others.3) The higher max-pause/pass-good thresholds somehow leads to some bad swing of dirty pages.
The fix is to allow the task to slightly dirty over
task_bdi_thresh, but no way to exceedbdi_dirtyand/or globaldirty_thresh.Tests show that it fixed the JBOD regression completely (both behavior and performance), while still being able to cut down large pause times in
balance_dirty_pages()for single-disk cases.Reported-by Li Shaohua <[email protected]>Tested-by Li Shaohua <[email protected]>Signed-off-by Wu Fengguang <[email protected]>--- include/linux/writeback.h | 11 ----------- mm/page-writeback.c | 15 ++------------- 2 files changed, 2 insertions(+), 24 deletions(-)Quoted 14 lines
mm/page-writeback.c static void balance_dirty_pages(struct a · line 792
Quoted 12 lines
mm/page-writeback.c +2
-2@@ -786,21 +786,10 @@ static void balance_dirty_pages(struct a* 200ms is typically more than enough to curb heavy dirtiers; * (b) the pause time limit makes the dirtiers more responsive. */ -if (nr_dirty < dirty_thresh + - dirty_thresh /DIRTY_MAXPAUSE_AREA && +if (nr_dirty < dirty_thresh && + bdi_dirty < (task_bdi_thresh + bdi_thresh) /2 &&time_after (jiffies, start_time +MAX_PAUSE ))break ;This looks definitely much safer than the original patch since we now
always observe global dirty limit.Yeah.
Quoted 2 lines
I just wonder: We have throttled the
task becausebdi_nr_reclaimable>task_bdi_thresh.Not necessarily. It's possible (
bdi_nr_reclaimable<task_bdi_thresh) for the whole loop. And the 200ms pause that trigger the above test may totally come from theio_schedule_timeout()calls.Quoted 4 lines
Now in practice there
should be some pages under writeback and this task should have submitted even more just a while ago. So the condition
bdi_dirty< (task_bdi_thresh+bdi_thresh) / 2
Quoted 6 lines
I guess the
writeback_inodes_wb()call is irrelevant for the above test, becausewriteback_inodes_wb()transfers reclaimable pages to writeback pages, with the totalbdi_dirtyvalue staying the same. Not to mention the fact that both thebdi_dirtyandbdi_nr_reclaimablevariables have not been updated betweenwriteback_inodes_wb()and the max-pause test.
Right, that comment was a bit off.
Quoted 4 lines
Quoted 2 lines
looks still relatively weak. Shouldn't there be
bdi_nr_reclaimable< (task_bdi_thresh+bdi_thresh) / 2?That's much easier condition to satisfy..
Argh, sorry. I was mistaken by the name of the variable - I though it
contains only dirty pages on the bdi but it also contains pages under writeback and bdi_nr_reclaimable is the one that contains only dirty pages. So your patch does exactly what I had in mind. You can add:
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH v9 12/13] memcg: create support routines for page writeback
Quoted 94 lines · Jan Kara
Quoted 85 lines · Wu Fengguang
Quoted 55 lines · Jan Kara
Quoted 54 lines · Wu Fengguang
Subject: squeeze max-pause area and drop pass-good area
Date: Tue Aug 16 13:37:14 CST 2011Remove the pass-good area introduced in
ffd1f609ab10("writeback:
introduce max-pause and pass-good dirty limits") and make the max-pause area smaller and safe.This fixes ~30% performance regression in the ext3 data=writeback fio_mmap_randwrite_64k/fio_mmap_randrw_64k test cases, where there are 12 JBOD disks, on each disk runs 8 concurrent tasks doing reads+writes.
Using deadline scheduler also has a regression, but not that big as CFQ, so this suggests we have some write starvation.
The test logs show that
- the disks are sometimes under utilized
- global dirty pages sometimes rush high to the pass-good area for several hundred seconds, while in the mean time some bdi dirty pages drop to very low value (
bdi_dirty<<bdi_thresh).
Then suddenly the global dirty pages dropped under global dirty threshold andbdi_dirtyrush very high (for example, 2 times higher thanbdi_thresh). During which timebalance_dirty_pages()is not called at all.So the problems are
1) The random writes progress so slow that they break the assumption of the max-pause logic that "8 pages per 200ms is typically more than enough to curb heavy dirtiers".
2) The max-pause logic ignored
task_bdi_threshand thus opens the possibility for some bdi's to over dirty pages, leading to (bdi_dirty>>bdi_thresh) and then (bdi_thresh>>bdi_dirty) for others.3) The higher max-pause/pass-good thresholds somehow leads to some bad swing of dirty pages.
The fix is to allow the task to slightly dirty over
task_bdi_thresh, but no way to exceedbdi_dirtyand/or globaldirty_thresh.Tests show that it fixed the JBOD regression completely (both behavior and performance), while still being able to cut down large pause times in
balance_dirty_pages()for single-disk cases.Reported-by Li Shaohua <[email protected]>Tested-by Li Shaohua <[email protected]>Signed-off-by Wu Fengguang <[email protected]>--- include/linux/writeback.h | 11 ----------- mm/page-writeback.c | 15 ++------------- 2 files changed, 2 insertions(+), 24 deletions(-)Quoted 14 lines
mm/page-writeback.c static void balance_dirty_pages(struct a · line 792
Quoted 12 lines
mm/page-writeback.c +2
-2@@ -786,21 +786,10 @@ static void balance_dirty_pages(struct a* 200ms is typically more than enough to curb heavy dirtiers; * (b) the pause time limit makes the dirtiers more responsive. */ -if (nr_dirty < dirty_thresh + - dirty_thresh /DIRTY_MAXPAUSE_AREA && +if (nr_dirty < dirty_thresh && + bdi_dirty < (task_bdi_thresh + bdi_thresh) /2 &&time_after (jiffies, start_time +MAX_PAUSE ))break ;This looks definitely much safer than the original patch since we now
always observe global dirty limit.Yeah.
Quoted 2 lines
I just wonder: We have throttled the
task becausebdi_nr_reclaimable>task_bdi_thresh.Not necessarily. It's possible (
bdi_nr_reclaimable<task_bdi_thresh) for the whole loop. And the 200ms pause that trigger the above test may totally come from theio_schedule_timeout()calls.Quoted 4 lines
Now in practice there
should be some pages under writeback and this task should have submitted even more just a while ago. So the condition
bdi_dirty< (task_bdi_thresh+bdi_thresh) / 2Quoted 6 lines
I guess the
writeback_inodes_wb()call is irrelevant for the above test, becausewriteback_inodes_wb()transfers reclaimable pages to writeback pages, with the totalbdi_dirtyvalue staying the same. Not to mention the fact that both thebdi_dirtyandbdi_nr_reclaimablevariables have not been updated betweenwriteback_inodes_wb()and the max-pause test.Right, that comment was a bit off.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
looks still relatively weak. Shouldn't there be
bdi_nr_reclaimable< (task_bdi_thresh+bdi_thresh) / 2?That's much easier condition to satisfy..
Argh, sorry. I was mistaken by the name of the variable - I though it
contains only dirty pages on the bdi but it also contains pages under writeback andbdi_nr_reclaimableis the one that contains only dirty pages.
Yeah the name may be a bit confusing.. but we'll soon get rid of bdi_nr_reclaimable :)
Quoted 2 lines
So your patch does exactly what I had in mind. You can add:
Acked-by Jan Kara <[email protected]>
Thanks! I'll test it in linux-next for a week and then send to Linus.
Thanks,
Fengguang
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v9 13/13 memcg: check memcg dirty limits in page writeback
In reply to Greg ThelenIf the current process is in a non-root memcg, then balance_dirty_pages() will consider the memcg dirty limits as well as the system-wide limits. This allows different cgroups to have distinct dirty limits which trigger direct and background writeback at different levels.
If called with a mem_cgroup, then throttle_vm_writeout() queries the given cgroup for its dirty memory usage limits.
---
Changelog since v8:
- Use 'memcg' rather than 'mem' for local variables and parameters. This is consistent with other memory controller code.
include/linux/writeback.h | 2 +- mm/page-writeback.c | 35 +++++++++++++++++++++++++++++------ mm/vmscan.c | 2 +- 3 files changed, 31 insertions(+), 8 deletions(-)
include/linux/writeback.h +1 -1
@@ -116,7 +116,7 @@ void laptop_mode_timer_fn(unsigned long data);#else static inline void laptop_sync_completion (void ) { }#endif -void throttle_vm_writeout (gfp_t gfp_mask); +void throttle_vm_writeout (gfp_t gfp_mask,struct mem_cgroup *memcg);extern unsigned long global_dirty_limit;
mm/page-writeback.c +29 -6
@@ -645,7 +645,8 @@ static void bdi_update_bandwidth(struct backing_dev_info *bdi,* data. It looks at the number of dirty pages in the machine and will force * the caller to perform writeback if the system is over `vm_dirty_ratio'. * If we're over `background_thresh' then the writeback threads are woken to -* perform some writeout. +* perform some writeout. The current task may belong to a cgroup with +* dirty limits, which are also checked. */ static void balance_dirty_pages (struct address_space *mapping,unsigned long write_chunk)
@@ -665,6 +666,8 @@ static void balance_dirty_pages(struct address_space *mapping,struct backing_dev_info *bdi = mapping->backing_dev_info;unsigned long start_time = jiffies; +mem_cgroup_balance_dirty_pages (mapping, write_chunk); +for (;;) { nr_reclaimable =global_page_state (NR_FILE_DIRTY ) +global_page_state (NR_UNSTABLE_NFS );
@@ -856,23 +859,43 @@ void balance_dirty_pages_ratelimited_nr(struct address_space *mapping, }EXPORT_SYMBOL (balance_dirty_pages_ratelimited_nr); -void throttle_vm_writeout (gfp_t gfp_mask) +/* +* Throttle the current task if it is near dirty memory usage limits. Both +* global dirty memory limits and (if @memcg is given) per-cgroup dirty memory +* limits are checked. +* +* If near limits, then wait for usage to drop. Dirty usage should drop because +* dirty producers should have used balance_dirty_pages(), which would have +* scheduled writeback. +*/ +void throttle_vm_writeout (gfp_t gfp_mask,struct mem_cgroup *memcg) {unsigned long background_thresh;unsigned long dirty_thresh; +struct dirty_info memcg_info; +bool do_memcg;for ( ; ; ) {global_dirty_limits (&background_thresh, &dirty_thresh); + do_memcg = memcg && +mem_cgroup_hierarchical_dirty_info ( +determine_dirtyable_memory (), memcg, + &memcg_info);/* * Boost the allowable dirty threshold a bit for page * allocators so they don't get DoS'ed by heavy writers */ dirty_thresh += dirty_thresh /10 ;/* wheeee... */ - -if (global_page_state (NR_UNSTABLE_NFS ) + -global_page_state (NR_WRITEBACK ) <= dirty_thresh) -break ; +if (do_memcg) + memcg_info.dirty_thresh += memcg_info.dirty_thresh /10 ; + +if ((global_page_state (NR_UNSTABLE_NFS ) + +global_page_state (NR_WRITEBACK ) <= dirty_thresh) && + (!do_memcg || + (memcg_info.nr_unstable_nfs + + memcg_info.nr_writeback <= memcg_info.dirty_thresh))) +break ;congestion_wait (BLK_RW_ASYNC ,HZ /10 );/*
mm/vmscan.c +1 -1
@@ -2068,7 +2068,7 @@ restart: sc->nr_scanned - nr_scanned, sc)) goto restart; -throttle_vm_writeout (sc->gfp_mask); +throttle_vm_writeout (sc->gfp_mask, sc->mem_cgroup); }/*
Signature · 8 lines
1.7.3.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v9 13/13] memcg: check memcg dirty limits in page writeback
Quoted 11 lines · On Wed, 17 Aug 2011 09:15:05 -0700 Greg Thelen <[email protected]> wrote:
If the current process is in a non-root memcg, then
balance_dirty_pages()will consider the memcg dirty limits as well as the system-wide limits. This allows different cgroups to have distinct dirty limits which trigger direct and background writeback at different levels.If called with a
mem_cgroup, thenthrottle_vm_writeout()queries the given cgroup for its dirty memory usage limits.Signed-off-by Andrea Righi <[email protected]>Signed-off-by Greg Thelen <[email protected]>
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 5 lines · On Wed, 17 Aug 2011 09:14:52 -0700 Greg Thelen <[email protected]> wrote:
This patch series provides the ability for each cgroup to have independent dirty page usage limits. Limiting dirty memory fixes the max amount of dirty (hard to reclaim) page cache used by a cgroup. This allows for better per cgroup memory isolation and fewer memcg OOMs.
Thank you for your patient work!. I really want this feature. (Hopefully before we tune vmscan)
I hope this patch will not have heavy HUNKs..
Thanks,
-Kame
Quoted 112 lines
Three features are included in this patch series:
1. memcg dirty page accounting
2. memcg writeback
3. memcg dirty page limiting1. memcg dirty page accounting
Each memcg maintains a dirty page count and dirty page limit. Previous iterations of this patch series have refined this logic. The interface is similar to the procfs interface:
/proc/sys/vm/dirty_*. It is possible to configure a limit to trigger throttling of a dirtier or queue background writeback. The root cgroup memory.dirty_* control files are read-only and match the contents of the/proc/sys/vm/dirty_*files.2. memcg writeback
Having per cgroup dirty memory limits is not very interesting unless writeback is also cgroup aware. There is not much isolation if cgroups have to writeback data from outside the affected cgroup to get below the cgroup dirty memory threshold.
Per-memcg dirty limits are provided to support isolation and thus cross cgroup inode sharing is not a priority. This allows the code be simpler.
To add cgroup awareness to writeback, this series adds an
i_memcgfield to structaddress_spaceto allow writeback to isolate inodes for a particular cgroup. When an inode is marked dirty,i_memcgis set to the current cgroup. When inode pages are marked dirty thei_memcgfield is compared against the page's cgroup. If they differ, then the inode is marked as shared by settingi_memcgto a special shared value (zero).When performing per-memcg writeback,
move_expired_inodes()scans the per bdib_dirtylist using each inode'si_memcgand the global over-limit memcg bitmap to determine if the inode should be written. This inode scan may involve skipping many unrelated inodes from other cgroup. To test the scanning overhead, I created two cgroups (cgroup_Awith 100,000 dirty inodes under A's dirty limit,cgroup_Bwith 1 inode over B's dirty limit). The writeback code then had to skip 100,000 inodes when balancingcgroup_Bto find the one inode that needed writing. This scanning took 58 msec to skip 100,000 foreign inodes.3. memcg dirty page limiting
balance_dirty_pages()callsmem_cgroup_balance_dirty_pages(), which checks the dirty usage vs dirty thresholds for the current cgroup and its parents. As cgroups exceed their background limit, they are marked in a global over-limit bitmap (indexed by cgroup id) and the bdi flusher is awoke. As a cgroup hits is foreground limit, the task is throttled while performing foreground writeback on inodes owned by the over-limit cgroup. Ifmem_cgroup_balance_dirty_pages()is unable to get below the dirty page threshold writing per-memcg inodes, then downshifts to also writing shared inodes (i_memcg=0).I know that there is some significant IO-less
balance_dirty_pages()changes. I am not trying to derail that effort. I have done moderate functional testing of the newly proposed features.The memcg aspects of this patch are pretty mature. The writeback aspects are still fairly new and need feedback from the writeback community. These features are linked, so it's not clear which branch to send the changes to (the writeback development branch or mmotm).
Here is an example of the memcg OOM that is avoided with this patch series:
# mkdir /dev/cgroup/memory/x # echo 100M > /dev/cgroup/memory/x/memory.limit_in_bytes # echo $$ > /dev/cgroup/memory/x/tasks # dd if=/dev/zero of=/data/f1 bs=1k count=1M & # dd if=/dev/zero of=/data/f2 bs=1k count=1M & # wait [1]- Killed dd if=/dev/zero of=/data/f1 bs=1M count=1k [2]+ Killed dd if=/dev/zero of=/data/f1 bs=1M count=1kChanges since -v8:
- Reordered patches for better more readability.- No longer passing struct
writeback_controlinto memcontrol functions. Instead the needed attributes (memcg_id, etc.) are explicitly passed in. Therefore no more field additions to structwriteback_control.- Replaced 'Andrea Righi <[email protected]>' with 'Andrea Righi <[email protected]>' in commit descriptions.
- Rebased to mmotm-2011-08-02-16-19
Greg Thelen (13):
memcg: document cgroup dirty memory interfaces
memcg: addpage_cgroupflags for dirty page tracking
memcg: add dirty page accounting infrastructure
memcg: add kernel calls for memcg dirty page stats
memcg: addmem_cgroup_mark_inode_dirty()
memcg: add dirty limits tomem_cgroup
memcg: add cgroupfs interface to memcg dirty limits
memcg: dirty page accounting support routines
memcg: create support routines for writeback
writeback: passwb_writeback_workintomove_expired_inodes()
writeback: make background writeback cgroup aware
memcg: create support routines for page writeback
memcg: check memcg dirty limits in page writebackDocumentation/cgroups/memory.txt | 70 ++++ fs/buffer.c | 2 +- fs/fs-writeback.c | 113 ++++-- fs/inode.c | 3 + fs/nfs/write.c | 4 + fs/sync.c | 2 +- include/linux/cgroup.h | 1 + include/linux/fs.h | 9 + include/linux/memcontrol.h | 64 +++- include/linux/page_cgroup.h | 23 ++ include/linux/writeback.h | 9 +- include/trace/events/memcontrol.h | 207 ++++++++++ kernel/cgroup.c | 1 -
Quoted 13 lines
mm/backing-dev.c | 3 +- mm/filemap.c | 1 + mm/memcontrol.c | 760 ++++++++++++++++++++++++++++++++++++- mm/page-writeback.c | 44 ++- mm/truncate.c | 1 + mm/vmscan.c | 5 +- 19 files changed, 1265 insertions(+), 57 deletions(-) create mode 100644 include/trace/events/memcontrol.hSignature · 1 line
1.7.3.1
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>