Thread (29 messages) 29 messages, 6 authors, 2020-01-14

Re: [PATCH v7 02/10] mm/memcg: fold lru_lock in lock_page_lru

From: Konstantin Khlebnikov <hidden>
Date: 2020-01-10 08:49:14
Also in: linux-mm, lkml

On 25/12/2019 12.04, Alex Shi wrote:
quoted hunk ↗ jump to hunk
 From the commit_charge's explanations and mem_cgroup_commit_charge
comments, as well as call path when lrucare is ture, The lru_lock is
just to guard the task migration(which would be lead to move_account)
So it isn't needed when !PageLRU, and better be fold into PageLRU to
reduce lock contentions.

Signed-off-by: Alex Shi <alex.shi-KPsoFbNs7GizrGE5bRqYAgC/G2K4zDHf@public.gmane.org>
Cc: Johannes Weiner <redacted>
Cc: Michal Hocko <redacted>
Cc: Matthew Wilcox <redacted>
Cc: Vladimir Davydov <redacted>
Cc: Andrew Morton <akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>
Cc: cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Cc: linux-mm-Bw31MaZKKs3YtjvyW6yDsg@public.gmane.org
Cc: linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
---
  mm/memcontrol.c | 9 ++++-----
  1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index c5b5f74cfd4d..0ad10caabc3d 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -2572,12 +2572,11 @@ static void cancel_charge(struct mem_cgroup *memcg, unsigned int nr_pages)
  
  static void lock_page_lru(struct page *page, int *isolated)
  {
-	pg_data_t *pgdat = page_pgdat(page);
-
-	spin_lock_irq(&pgdat->lru_lock);
  	if (PageLRU(page)) {
+		pg_data_t *pgdat = page_pgdat(page);
  		struct lruvec *lruvec;
  
+		spin_lock_irq(&pgdat->lru_lock);
That's wrong. Here PageLRU must be checked again under lru_lock.


Also I don't like these functions:
- called lock/unlock but actually also isolates
- used just once
- pgdat evaluated twice
quoted hunk ↗ jump to hunk
  		lruvec = mem_cgroup_page_lruvec(page, pgdat);
  		ClearPageLRU(page);
  		del_page_from_lru_list(page, lruvec, page_lru(page));
@@ -2588,17 +2587,17 @@ static void lock_page_lru(struct page *page, int *isolated)
  
  static void unlock_page_lru(struct page *page, int isolated)
  {
-	pg_data_t *pgdat = page_pgdat(page);
  
  	if (isolated) {
+		pg_data_t *pgdat = page_pgdat(page);
  		struct lruvec *lruvec;
  
  		lruvec = mem_cgroup_page_lruvec(page, pgdat);
  		VM_BUG_ON_PAGE(PageLRU(page), page);
  		SetPageLRU(page);
  		add_page_to_lru_list(page, lruvec, page_lru(page));
+		spin_unlock_irq(&pgdat->lru_lock);
  	}
-	spin_unlock_irq(&pgdat->lru_lock);
  }
  
  static void commit_charge(struct page *page, struct mem_cgroup *memcg,
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help