linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH stable 4.6+] radix-tree: account nodes to memcg only if explicitly requested
@ 2016-08-02 12:45 Vladimir Davydov
  2016-08-03  3:51 ` Greg KH
  0 siblings, 1 reply; 4+ messages in thread
From: Vladimir Davydov @ 2016-08-02 12:45 UTC (permalink / raw)
  To: stable; +Cc: Johannes Weiner, Michal Hocko, linux-mm, linux-kernel

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.

Signed-off-by: Vladimir Davydov <vdavydov@virtuozzo.com>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Acked-by: Michal Hocko <mhocko@suse.com>
Cc: <stable@vger.kernel.org>  [4.6+]
---
 fs/inode.c       |  2 +-
 lib/radix-tree.c | 14 ++++++++++----
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/fs/inode.c b/fs/inode.c
index 69b8b526c194..b4ff82f3a57d 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -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);
diff --git a/lib/radix-tree.c b/lib/radix-tree.c
index 1624c4117961..9b9be3ffa1f6 100644
--- a/lib/radix-tree.c
+++ b/lib/radix-tree.c
@@ -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) {
-- 
2.1.4

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH stable 4.6+] radix-tree: account nodes to memcg only if explicitly requested
  2016-08-02 12:45 [PATCH stable 4.6+] radix-tree: account nodes to memcg only if explicitly requested Vladimir Davydov
@ 2016-08-03  3:51 ` Greg KH
  2016-08-03  8:15   ` Vladimir Davydov
  0 siblings, 1 reply; 4+ messages in thread
From: Greg KH @ 2016-08-03  3:51 UTC (permalink / raw)
  To: Vladimir Davydov
  Cc: stable, Johannes Weiner, Michal Hocko, linux-mm, linux-kernel

On Tue, Aug 02, 2016 at 03:45:34PM +0300, Vladimir Davydov wrote:
> 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.
> 
> Signed-off-by: Vladimir Davydov <vdavydov@virtuozzo.com>
> Acked-by: Johannes Weiner <hannes@cmpxchg.org>
> Acked-by: Michal Hocko <mhocko@suse.com>
> Cc: <stable@vger.kernel.org>  [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 majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH stable 4.6+] radix-tree: account nodes to memcg only if explicitly requested
  2016-08-03  3:51 ` Greg KH
@ 2016-08-03  8:15   ` Vladimir Davydov
  2016-08-03  8:29     ` Greg KH
  0 siblings, 1 reply; 4+ messages in thread
From: Vladimir Davydov @ 2016-08-03  8:15 UTC (permalink / raw)
  To: Greg KH; +Cc: stable, Johannes Weiner, Michal Hocko, linux-mm, linux-kernel

On Wed, Aug 03, 2016 at 05:51:39AM +0200, Greg KH wrote:
> On Tue, Aug 02, 2016 at 03:45:34PM +0300, Vladimir Davydov wrote:
> > 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.
> > 
> > Signed-off-by: Vladimir Davydov <vdavydov@virtuozzo.com>
> > Acked-by: Johannes Weiner <hannes@cmpxchg.org>
> > Acked-by: Michal Hocko <mhocko@suse.com>
> > Cc: <stable@vger.kernel.org>  [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?

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.

> 
> confused,

Sorry for the noise.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH stable 4.6+] radix-tree: account nodes to memcg only if explicitly requested
  2016-08-03  8:15   ` Vladimir Davydov
@ 2016-08-03  8:29     ` Greg KH
  0 siblings, 0 replies; 4+ messages in thread
From: Greg KH @ 2016-08-03  8:29 UTC (permalink / raw)
  To: Vladimir Davydov
  Cc: stable, Johannes Weiner, Michal Hocko, linux-mm, linux-kernel

On Wed, Aug 03, 2016 at 11:15:25AM +0300, Vladimir Davydov wrote:
> On Wed, Aug 03, 2016 at 05:51:39AM +0200, Greg KH wrote:
> > On Tue, Aug 02, 2016 at 03:45:34PM +0300, Vladimir Davydov wrote:
> > > 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.
> > > 
> > > Signed-off-by: Vladimir Davydov <vdavydov@virtuozzo.com>
> > > Acked-by: Johannes Weiner <hannes@cmpxchg.org>
> > > Acked-by: Michal Hocko <mhocko@suse.com>
> > > Cc: <stable@vger.kernel.org>  [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?
> 
> 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 majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-08-03  8:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-08-02 12:45 [PATCH stable 4.6+] radix-tree: account nodes to memcg only if explicitly requested Vladimir Davydov
2016-08-03  3:51 ` Greg KH
2016-08-03  8:15   ` Vladimir Davydov
2016-08-03  8:29     ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).