radix-tree: account nodes to memcg only if explicitly requested
Subsystems (2)
PATCH 1/1 radix-tree: account nodes to memcg only if explicitly requested
Radix trees may be used not only for storing page cache pages, so unconditionally accounting radix tree nodes to the current memory cgroup is bad: if a radix tree node is used for storing data shared among different cgroups we risk pinning dead memory cgroups forever. So let's only account radix tree nodes if it was explicitly requested by passing __GFP_ACCOUNT to INIT_RADIX_TREE. Currently, we only want to account page cache entries, so mark mapping->page_tree so.
--- fs/inode.c | 2 +- lib/radix-tree.c | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-)
fs/inode.c +1 -1
@@ -344,7 +344,7 @@ EXPORT_SYMBOL(inc_nlink);void address_space_init_once (struct address_space *mapping) {memset (mapping,0 ,sizeof (*mapping)); -INIT_RADIX_TREE (&mapping->page_tree,GFP_ATOMIC ); +INIT_RADIX_TREE (&mapping->page_tree,GFP_ATOMIC | __GFP_ACCOUNT);spin_lock_init (&mapping->tree_lock);init_rwsem (&mapping->i_mmap_rwsem);INIT_LIST_HEAD (&mapping->private_list);
lib/radix-tree.c +10 -4
@@ -228,10 +228,11 @@ radix_tree_node_alloc(struct radix_tree_root *root)/* * Even if the caller has preloaded, try to allocate from the -* cache first for the new node to get accounted. +* cache first for the new node to get accounted to the memory +* cgroup. */ ret =kmem_cache_alloc (radix_tree_node_cachep, - gfp_mask | __GFP_ACCOUNT | __GFP_NOWARN); + gfp_mask | __GFP_NOWARN);if (ret) goto out;
@@ -254,8 +255,7 @@ radix_tree_node_alloc(struct radix_tree_root *root)kmemleak_update_trace (ret); goto out; } - ret =kmem_cache_alloc (radix_tree_node_cachep, - gfp_mask | __GFP_ACCOUNT); + ret =kmem_cache_alloc (radix_tree_node_cachep, gfp_mask); out:BUG_ON (radix_tree_is_indirect_ptr (ret));return ret;
@@ -302,6 +302,12 @@ static int __radix_tree_preload(gfp_t gfp_mask)struct radix_tree_node *node;int ret = -ENOMEM ; +/* +* Nodes preloaded by one cgroup can be be used by another cgroup, so +* they should never be accounted to any particular memory cgroup. +*/ + gfp_mask &= ~__GFP_ACCOUNT; +preempt_disable (); rtp =this_cpu_ptr (&radix_tree_preloads);while (rtp->nr <RADIX_TREE_PRELOAD_SIZE ) {
Signature · 7 lines
2.1.4 -- 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/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Greg KH
maintainerQuoted 8 lines · Vladimir Davydov
Radix trees may be used not only for storing page cache pages, so unconditionally accounting radix tree nodes to the current memory cgroup is bad: if a radix tree node is used for storing data shared among different cgroups we risk pinning dead memory cgroups forever. So let's only account radix tree nodes if it was explicitly requested by passing
__GFP_ACCOUNTtoINIT_RADIX_TREE. Currently, we only want to account page cache entries, so markmapping->page_treeso.
Quoted 8 lines
Signed-off-by Vladimir Davydov <[email protected]>Acked-by Johannes Weiner <[email protected]>Acked-by Michal Hocko <[email protected]>Cc <[email protected]> [4.6+]--- fs/inode.c | 2 +- lib/radix-tree.c | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-)
Is this patch in Linus's tree already?
confused,
greg k-h
--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 18 lines · Greg KH
Quoted 8 lines · Vladimir Davydov
Radix trees may be used not only for storing page cache pages, so unconditionally accounting radix tree nodes to the current memory cgroup is bad: if a radix tree node is used for storing data shared among different cgroups we risk pinning dead memory cgroups forever. So let's only account radix tree nodes if it was explicitly requested by passing
__GFP_ACCOUNTtoINIT_RADIX_TREE. Currently, we only want to account page cache entries, so markmapping->page_treeso.Quoted 8 lines
Signed-off-by Vladimir Davydov <[email protected]>Acked-by Johannes Weiner <[email protected]>Acked-by Michal Hocko <[email protected]>Cc <[email protected]> [4.6+]--- fs/inode.c | 2 +- lib/radix-tree.c | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-)
Quoted 1 line
Is this patch in Linus's tree already?
Not yet, it should only be added to 4.8, so I shouldn't have sent this (didn't know how patches are submitted to stable). Please ignore.
Quoted 2 lines
confused,
Sorry for the noise.
--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Greg KH
maintainerQuoted 19 lines · Vladimir Davydov
Quoted 18 lines · Greg KH
Quoted 16 lines · Vladimir Davydov
Radix trees may be used not only for storing page cache pages, so unconditionally accounting radix tree nodes to the current memory cgroup is bad: if a radix tree node is used for storing data shared among different cgroups we risk pinning dead memory cgroups forever. So let's only account radix tree nodes if it was explicitly requested by passing
__GFP_ACCOUNTtoINIT_RADIX_TREE. Currently, we only want to account page cache entries, so markmapping->page_treeso.Signed-off-by Vladimir Davydov <[email protected]>Acked-by Johannes Weiner <[email protected]>Acked-by Michal Hocko <[email protected]>Cc <[email protected]> [4.6+]--- fs/inode.c | 2 +- lib/radix-tree.c | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-)
Quoted 4 lines
Quoted 1 line
Is this patch in Linus's tree already?
Not yet, it should only be added to 4.8, so I shouldn't have sent this (didn't know how patches are submitted to stable). Please ignore.
Please read Documentation/stable_kernel_rules.txt, it should help answer this question (hint, you almost got it right...)
thanks,
greg k-h
--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>