linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] mm/memcg: revise the using condition of lock_page_lruvec function series
@ 2020-12-17  6:28 Alex Shi
  2020-12-17  6:28 ` [PATCH 2/3] mm/memcg: remove rcu locking for " Alex Shi
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Alex Shi @ 2020-12-17  6:28 UTC (permalink / raw)
  To: akpm
  Cc: Hugh Dickins, Johannes Weiner, Michal Hocko, Vladimir Davydov,
	cgroups, linux-mm, linux-kernel

The series function could be used under lock_page_memcg(), add this and
a bit style changes following commit_charge().

Signed-off-by: Alex Shi <alex.shi@linux.alibaba.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Vladimir Davydov <vdavydov.dev@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: cgroups@vger.kernel.org
Cc: linux-mm@kvack.org
Cc: linux-kernel@vger.kernel.org
---
 mm/memcontrol.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index b80328f52fb4..e6b50d068b2f 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -1345,10 +1345,11 @@ void lruvec_memcg_debug(struct lruvec *lruvec, struct page *page)
  * lock_page_lruvec - lock and return lruvec for a given page.
  * @page: the page
  *
- * This series functions should be used in either conditions:
- * PageLRU is cleared or unset
- * or page->_refcount is zero
- * or page is locked.
+ * This series functions should be used in any one of following conditions:
+ * - PageLRU is cleared or unset
+ * - page->_refcount is zero
+ * - page is locked.
+ * - lock_page_memcg()
  */
 struct lruvec *lock_page_lruvec(struct page *page)
 {
-- 
2.29.GIT



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

* [PATCH 2/3] mm/memcg: remove rcu locking for lock_page_lruvec function series
  2020-12-17  6:28 [PATCH 1/3] mm/memcg: revise the using condition of lock_page_lruvec function series Alex Shi
@ 2020-12-17  6:28 ` Alex Shi
  2020-12-22  3:38   ` Hugh Dickins
  2020-12-17  6:28 ` [PATCH 3/3] mm/compaction: remove rcu_read_lock during page compaction Alex Shi
  2020-12-22  3:01 ` [PATCH 1/3] mm/memcg: revise the using condition of lock_page_lruvec function series Hugh Dickins
  2 siblings, 1 reply; 7+ messages in thread
From: Alex Shi @ 2020-12-17  6:28 UTC (permalink / raw)
  To: akpm
  Cc: Hugh Dickins, Johannes Weiner, Michal Hocko, Vladimir Davydov,
	cgroups, linux-mm, linux-kernel

The rcu_read_lock was used to block memcg destory, but with the detailed
calling conditions, the memcg won't gone since the page is hold. So we
don't need it now, let's remove them to save locking load in debugging.

Signed-off-by: Alex Shi <alex.shi@linux.alibaba.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Vladimir Davydov <vdavydov.dev@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: cgroups@vger.kernel.org
Cc: linux-mm@kvack.org
Cc: linux-kernel@vger.kernel.org
---
 mm/memcontrol.c | 6 ------
 1 file changed, 6 deletions(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index e6b50d068b2f..98bbee1d2faf 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -1356,10 +1356,8 @@ struct lruvec *lock_page_lruvec(struct page *page)
 	struct lruvec *lruvec;
 	struct pglist_data *pgdat = page_pgdat(page);
 
-	rcu_read_lock();
 	lruvec = mem_cgroup_page_lruvec(page, pgdat);
 	spin_lock(&lruvec->lru_lock);
-	rcu_read_unlock();
 
 	lruvec_memcg_debug(lruvec, page);
 
@@ -1371,10 +1369,8 @@ struct lruvec *lock_page_lruvec_irq(struct page *page)
 	struct lruvec *lruvec;
 	struct pglist_data *pgdat = page_pgdat(page);
 
-	rcu_read_lock();
 	lruvec = mem_cgroup_page_lruvec(page, pgdat);
 	spin_lock_irq(&lruvec->lru_lock);
-	rcu_read_unlock();
 
 	lruvec_memcg_debug(lruvec, page);
 
@@ -1386,10 +1382,8 @@ struct lruvec *lock_page_lruvec_irqsave(struct page *page, unsigned long *flags)
 	struct lruvec *lruvec;
 	struct pglist_data *pgdat = page_pgdat(page);
 
-	rcu_read_lock();
 	lruvec = mem_cgroup_page_lruvec(page, pgdat);
 	spin_lock_irqsave(&lruvec->lru_lock, *flags);
-	rcu_read_unlock();
 
 	lruvec_memcg_debug(lruvec, page);
 
-- 
2.29.GIT



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

* [PATCH 3/3] mm/compaction: remove rcu_read_lock during page compaction
  2020-12-17  6:28 [PATCH 1/3] mm/memcg: revise the using condition of lock_page_lruvec function series Alex Shi
  2020-12-17  6:28 ` [PATCH 2/3] mm/memcg: remove rcu locking for " Alex Shi
@ 2020-12-17  6:28 ` Alex Shi
  2020-12-22  3:49   ` Hugh Dickins
  2020-12-22  3:01 ` [PATCH 1/3] mm/memcg: revise the using condition of lock_page_lruvec function series Hugh Dickins
  2 siblings, 1 reply; 7+ messages in thread
From: Alex Shi @ 2020-12-17  6:28 UTC (permalink / raw)
  To: akpm; +Cc: Hugh Dickins, Johannes Weiner, linux-mm, linux-kernel

rcu_read_lock was used to guard memcg destory, now TestClearPageLRU
could block this happen, so we don't need it. Remove it to reduce
locking load in debugging mode.

Signed-off-by: Alex Shi <alex.shi@linux.alibaba.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-mm@kvack.org
Cc: linux-kernel@vger.kernel.org
---
 mm/compaction.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/mm/compaction.c b/mm/compaction.c
index 8049d3530812..02af220fb992 100644
--- a/mm/compaction.c
+++ b/mm/compaction.c
@@ -995,7 +995,6 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn,
 		if (!TestClearPageLRU(page))
 			goto isolate_fail_put;
 
-		rcu_read_lock();
 		lruvec = mem_cgroup_page_lruvec(page, pgdat);
 
 		/* If we already hold the lock, we can skip some rechecking */
@@ -1005,7 +1004,6 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn,
 
 			compact_lock_irqsave(&lruvec->lru_lock, &flags, cc);
 			locked = lruvec;
-			rcu_read_unlock();
 
 			lruvec_memcg_debug(lruvec, page);
 
@@ -1026,8 +1024,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn,
 				SetPageLRU(page);
 				goto isolate_fail_put;
 			}
-		} else
-			rcu_read_unlock();
+		}
 
 		/* The whole page is taken off the LRU; skip the tail pages. */
 		if (PageCompound(page))
-- 
2.29.GIT



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

* Re: [PATCH 1/3] mm/memcg: revise the using condition of lock_page_lruvec function series
  2020-12-17  6:28 [PATCH 1/3] mm/memcg: revise the using condition of lock_page_lruvec function series Alex Shi
  2020-12-17  6:28 ` [PATCH 2/3] mm/memcg: remove rcu locking for " Alex Shi
  2020-12-17  6:28 ` [PATCH 3/3] mm/compaction: remove rcu_read_lock during page compaction Alex Shi
@ 2020-12-22  3:01 ` Hugh Dickins
  2020-12-22  5:23   ` Alex Shi
  2 siblings, 1 reply; 7+ messages in thread
From: Hugh Dickins @ 2020-12-22  3:01 UTC (permalink / raw)
  To: Alex Shi
  Cc: Andrew Morton, Hugh Dickins, Johannes Weiner, Michal Hocko,
	Vladimir Davydov, cgroups, linux-mm, linux-kernel

On Thu, 17 Dec 2020, Alex Shi wrote:

> The series function could be used under lock_page_memcg(), add this and
> a bit style changes following commit_charge().
> 
> Signed-off-by: Alex Shi <alex.shi@linux.alibaba.com>
> Cc: Hugh Dickins <hughd@google.com>

This patch, or its intention,
Acked-by: Hugh Dickins <hughd@google.com>
but rewording suggested below, and requested above -
which left me very puzzled before eventually I understood it.
I don't think we need to talk about "a bit style changes",
but the cross-reference to commit_charge() is helpful.

"
lock_page_lruvec() and its variants are safe to use under the same
conditions as commit_charge(): add lock_page_memcg() to the comment.
"

> Cc: Johannes Weiner <hannes@cmpxchg.org>
> Cc: Michal Hocko <mhocko@kernel.org>
> Cc: Vladimir Davydov <vdavydov.dev@gmail.com>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: cgroups@vger.kernel.org
> Cc: linux-mm@kvack.org
> Cc: linux-kernel@vger.kernel.org
> ---
>  mm/memcontrol.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index b80328f52fb4..e6b50d068b2f 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -1345,10 +1345,11 @@ void lruvec_memcg_debug(struct lruvec *lruvec, struct page *page)
>   * lock_page_lruvec - lock and return lruvec for a given page.
>   * @page: the page
>   *
> - * This series functions should be used in either conditions:
> - * PageLRU is cleared or unset
> - * or page->_refcount is zero
> - * or page is locked.
> + * This series functions should be used in any one of following conditions:

These functions are safe to use under any of the following conditions:

> + * - PageLRU is cleared or unset
> + * - page->_refcount is zero
> + * - page is locked.

Remove that full stop...

> + * - lock_page_memcg()

... and, if you wish (I don't care), add full stop at the end of that line.

Maybe reorder those to the same order as listed in commit_charge().
Copy its text exactly? I don't think so, actually, I find your wording
(e.g. _refcount is zero) more explicit: good to have both descriptions.

>   */
>  struct lruvec *lock_page_lruvec(struct page *page)
>  {
> -- 
> 2.29.GIT


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

* Re: [PATCH 2/3] mm/memcg: remove rcu locking for lock_page_lruvec function series
  2020-12-17  6:28 ` [PATCH 2/3] mm/memcg: remove rcu locking for " Alex Shi
@ 2020-12-22  3:38   ` Hugh Dickins
  0 siblings, 0 replies; 7+ messages in thread
From: Hugh Dickins @ 2020-12-22  3:38 UTC (permalink / raw)
  To: Alex Shi
  Cc: Andrew Morton, Hugh Dickins, Johannes Weiner, Michal Hocko,
	Vladimir Davydov, Alexander Duyck, Hui Su, cgroups, linux-mm,
	linux-kernel

On Thu, 17 Dec 2020, Alex Shi wrote:

> The rcu_read_lock was used to block memcg destory, but with the detailed
> calling conditions, the memcg won't gone since the page is hold. So we
> don't need it now, let's remove them to save locking load in debugging.

"
lock_page_lruvec() and its variants used rcu_read_lock() with the
intention of safeguarding against the mem_cgroup being destroyed
concurrently; but so long as they are called under the specified
conditions (as they are), there is no way for the page's mem_cgroup
to be destroyed.  Delete the unnecessary rcu_read_lock() and _unlock().
"

This has little to do with a "locking load in debugging" - so what?
But everything to do with deleting bogosity, the sooner the better.

> 
> Signed-off-by: Alex Shi <alex.shi@linux.alibaba.com>
> Cc: Hugh Dickins <hughd@google.com>

Acked-by: Hugh Dickins <hughd@google.com>

This really surprised me!  Nice change, but how on earth did we not
notice until now?  The rcu_read_lock() seems to have come in, without
explanation, somewhere between lru_lock v9 and v11 (I never saw v10); and
I guess I was so used to needing rcu_read_lock() in my own implementation,
that I was blind to its irrelevance in yours.  Cc'ing Alex Duyck, since
he was generally very alert to this kind of thing - be good to have his
Ack too.  Also Cc'ing Hui Su, who sent a similar but unexplained patch
just before yours.

> Cc: Johannes Weiner <hannes@cmpxchg.org>
> Cc: Michal Hocko <mhocko@kernel.org>
> Cc: Vladimir Davydov <vdavydov.dev@gmail.com>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: cgroups@vger.kernel.org
> Cc: linux-mm@kvack.org
> Cc: linux-kernel@vger.kernel.org
> ---
>  mm/memcontrol.c | 6 ------
>  1 file changed, 6 deletions(-)
> 
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index e6b50d068b2f..98bbee1d2faf 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -1356,10 +1356,8 @@ struct lruvec *lock_page_lruvec(struct page *page)
>  	struct lruvec *lruvec;
>  	struct pglist_data *pgdat = page_pgdat(page);
>  
> -	rcu_read_lock();
>  	lruvec = mem_cgroup_page_lruvec(page, pgdat);
>  	spin_lock(&lruvec->lru_lock);
> -	rcu_read_unlock();
>  
>  	lruvec_memcg_debug(lruvec, page);
>  
> @@ -1371,10 +1369,8 @@ struct lruvec *lock_page_lruvec_irq(struct page *page)
>  	struct lruvec *lruvec;
>  	struct pglist_data *pgdat = page_pgdat(page);
>  
> -	rcu_read_lock();
>  	lruvec = mem_cgroup_page_lruvec(page, pgdat);
>  	spin_lock_irq(&lruvec->lru_lock);
> -	rcu_read_unlock();
>  
>  	lruvec_memcg_debug(lruvec, page);
>  
> @@ -1386,10 +1382,8 @@ struct lruvec *lock_page_lruvec_irqsave(struct page *page, unsigned long *flags)
>  	struct lruvec *lruvec;
>  	struct pglist_data *pgdat = page_pgdat(page);
>  
> -	rcu_read_lock();
>  	lruvec = mem_cgroup_page_lruvec(page, pgdat);
>  	spin_lock_irqsave(&lruvec->lru_lock, *flags);
> -	rcu_read_unlock();
>  
>  	lruvec_memcg_debug(lruvec, page);
>  
> -- 
> 2.29.GIT


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

* Re: [PATCH 3/3] mm/compaction: remove rcu_read_lock during page compaction
  2020-12-17  6:28 ` [PATCH 3/3] mm/compaction: remove rcu_read_lock during page compaction Alex Shi
@ 2020-12-22  3:49   ` Hugh Dickins
  0 siblings, 0 replies; 7+ messages in thread
From: Hugh Dickins @ 2020-12-22  3:49 UTC (permalink / raw)
  To: Alex Shi
  Cc: Andrew Morton, Hugh Dickins, Johannes Weiner, Alexander Duyck,
	Hui Su, linux-mm, linux-kernel

On Thu, 17 Dec 2020, Alex Shi wrote:

> rcu_read_lock was used to guard memcg destory, now TestClearPageLRU
> could block this happen, so we don't need it. Remove it to reduce
> locking load in debugging mode.

"
isolate_migratepages_block() used rcu_read_lock() with the intention
of safeguarding against the mem_cgroup being destroyed concurrently;
but its TestClearPageLRU already protects against that.  Delete the
unnecessary rcu_read_lock() and _unlock().
"

> 
> Signed-off-by: Alex Shi <alex.shi@linux.alibaba.com>
> Cc: Hugh Dickins <hughd@google.com>

Acked-by: Hugh Dickins <hughd@google.com>

> Cc: Johannes Weiner <hannes@cmpxchg.org>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: linux-mm@kvack.org
> Cc: linux-kernel@vger.kernel.org
> ---
>  mm/compaction.c | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/mm/compaction.c b/mm/compaction.c
> index 8049d3530812..02af220fb992 100644
> --- a/mm/compaction.c
> +++ b/mm/compaction.c
> @@ -995,7 +995,6 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn,
>  		if (!TestClearPageLRU(page))
>  			goto isolate_fail_put;
>  
> -		rcu_read_lock();
>  		lruvec = mem_cgroup_page_lruvec(page, pgdat);
>  
>  		/* If we already hold the lock, we can skip some rechecking */
> @@ -1005,7 +1004,6 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn,
>  
>  			compact_lock_irqsave(&lruvec->lru_lock, &flags, cc);
>  			locked = lruvec;
> -			rcu_read_unlock();
>  
>  			lruvec_memcg_debug(lruvec, page);
>  
> @@ -1026,8 +1024,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn,
>  				SetPageLRU(page);
>  				goto isolate_fail_put;
>  			}
> -		} else
> -			rcu_read_unlock();
> +		}
>  
>  		/* The whole page is taken off the LRU; skip the tail pages. */
>  		if (PageCompound(page))
> -- 
> 2.29.GIT


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

* Re: [PATCH 1/3] mm/memcg: revise the using condition of lock_page_lruvec function series
  2020-12-22  3:01 ` [PATCH 1/3] mm/memcg: revise the using condition of lock_page_lruvec function series Hugh Dickins
@ 2020-12-22  5:23   ` Alex Shi
  0 siblings, 0 replies; 7+ messages in thread
From: Alex Shi @ 2020-12-22  5:23 UTC (permalink / raw)
  To: Hugh Dickins
  Cc: Andrew Morton, Johannes Weiner, Michal Hocko, Vladimir Davydov,
	cgroups, linux-mm, linux-kernel



在 2020/12/22 上午11:01, Hugh Dickins 写道:
> On Thu, 17 Dec 2020, Alex Shi wrote:
> 
>> The series function could be used under lock_page_memcg(), add this and
>> a bit style changes following commit_charge().
>>
>> Signed-off-by: Alex Shi <alex.shi@linux.alibaba.com>
>> Cc: Hugh Dickins <hughd@google.com>
> 
> This patch, or its intention,
> Acked-by: Hugh Dickins <hughd@google.com>
> but rewording suggested below, and requested above -
> which left me very puzzled before eventually I understood it.
> I don't think we need to talk about "a bit style changes",
> but the cross-reference to commit_charge() is helpful.
> 
> "
> lock_page_lruvec() and its variants are safe to use under the same
> conditions as commit_charge(): add lock_page_memcg() to the comment.
> "

Thanks a lot, Hugh. Yes, your commit log are far more better than mine. :)

I will resent with your changes and Ack.

Thanks!
Alex

> 
>> Cc: Johannes Weiner <hannes@cmpxchg.org>
>> Cc: Michal Hocko <mhocko@kernel.org>
>> Cc: Vladimir Davydov <vdavydov.dev@gmail.com>
>> Cc: Andrew Morton <akpm@linux-foundation.org>
>> Cc: cgroups@vger.kernel.org
>> Cc: linux-mm@kvack.org
>> Cc: linux-kernel@vger.kernel.org
>> ---
>>  mm/memcontrol.c | 9 +++++----
>>  1 file changed, 5 insertions(+), 4 deletions(-)
>>
>> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
>> index b80328f52fb4..e6b50d068b2f 100644
>> --- a/mm/memcontrol.c
>> +++ b/mm/memcontrol.c
>> @@ -1345,10 +1345,11 @@ void lruvec_memcg_debug(struct lruvec *lruvec, struct page *page)
>>   * lock_page_lruvec - lock and return lruvec for a given page.
>>   * @page: the page
>>   *
>> - * This series functions should be used in either conditions:
>> - * PageLRU is cleared or unset
>> - * or page->_refcount is zero
>> - * or page is locked.
>> + * This series functions should be used in any one of following conditions:
> 
> These functions are safe to use under any of the following conditions:
> 
>> + * - PageLRU is cleared or unset
>> + * - page->_refcount is zero
>> + * - page is locked.
> 
> Remove that full stop...
> 
>> + * - lock_page_memcg()
> 
> ... and, if you wish (I don't care), add full stop at the end of that line.
> 
> Maybe reorder those to the same order as listed in commit_charge().
> Copy its text exactly? I don't think so, actually, I find your wording
> (e.g. _refcount is zero) more explicit: good to have both descriptions.
> 
>>   */
>>  struct lruvec *lock_page_lruvec(struct page *page)
>>  {
>> -- 
>> 2.29.GIT


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

end of thread, other threads:[~2020-12-22  5:23 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-17  6:28 [PATCH 1/3] mm/memcg: revise the using condition of lock_page_lruvec function series Alex Shi
2020-12-17  6:28 ` [PATCH 2/3] mm/memcg: remove rcu locking for " Alex Shi
2020-12-22  3:38   ` Hugh Dickins
2020-12-17  6:28 ` [PATCH 3/3] mm/compaction: remove rcu_read_lock during page compaction Alex Shi
2020-12-22  3:49   ` Hugh Dickins
2020-12-22  3:01 ` [PATCH 1/3] mm/memcg: revise the using condition of lock_page_lruvec function series Hugh Dickins
2020-12-22  5:23   ` Alex Shi

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).