per lruvec lru_lock for memcg
Subsystems (14)
v2 cover per lruvec lru_lock for memcg
Hi all,
This patchset move lru_lock into lruvec, give a lru_lock for each of lruvec, thus bring a lru_lock for each of memcg per node.
According to Daniel Jordan's suggestion, I run 64 'dd' with on 32 containers on my 2s* 8 core * HT box with the modefied case:
https://git.kernel.org/pub/scm/linux/kernel/git/wfg/vm-scalability.git/tree/case-lru-file-readtwice
With this change above lru_lock censitive testing improved 17% with multiple containers scenario. And no performance lose w/o mem_cgroup.
Thanks Hugh Dickins and Konstantin Khlebnikov, they both bring the same idea 7 years ago. I don't know why they didn't go further, but according to my testing, and google internal usage. This feathre is clearly benefit multi-container user.
So I like to introduce it here.
v2: bypass a performance regression bug and fix some function issues
--- Documentation/admin-guide/cgroup-v1/memcg_test.rst | 15 +++------------ Documentation/admin-guide/cgroup-v1/memory.rst | 6 +++--- Documentation/trace/events-kmem.rst | 2 +- Documentation/vm/unevictable-lru.rst | 22 ++++++++-------------- include/linux/memcontrol.h | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/mm_types.h | 2 +- include/linux/mmzone.h | 7 +++++-- mm/compaction.c | 62 ++++++++++++++++++++++++++++++++++++++++++-------------------- mm/filemap.c | 4 ++-- mm/huge_memory.c | 16 ++++++---------- mm/memcontrol.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++------------- mm/mlock.c | 27 ++++++++++++++------------- mm/mmzone.c | 1 + mm/page_alloc.c | 1 - mm/page_idle.c | 5 +++-- mm/rmap.c | 2 +- mm/swap.c | 77 +++++++++++++++++++++++++++++++---------------------------------------------- mm/vmscan.c | 74 ++++++++++++++++++++++++++++++++++++++------------------------------------ 18 files changed, 277 insertions(+), 177 deletions(-)
[PATCH v2 1/8] mm/lru: add per lruvec lock for memcg [PATCH v2 2/8] mm/lruvec: add irqsave flags into lruvec struct [PATCH v2 3/8] mm/lru: replace pgdat lru_lock with lruvec lock [PATCH v2 4/8] mm/lru: only change the lru_lock iff page's lruvec is [PATCH v2 5/8] mm/pgdat: remove pgdat lru_lock
[PATCH v2 6/8] mm/lru: remove rcu_read_lock to fix performance [PATCH v2 7/8] mm/lru: likely enhancement
[PATCH v2 8/8] mm/lru: revise the comments of lru_lock
PATCH v2 1/8 mm/lru: add per lruvec lock for memcg
Currently memcg still use per node pgdat->lru_lock to guard its lruvec. That causes some lru_lock contention in a high container density system.
If we can use per lruvec lock, that could relief much of the lru_lock contention.
The later patches will replace the pgdat->lru_lock with lruvec->lru_lock and show the performance benefit by benchmarks.
--- include/linux/mmzone.h | 2 ++ mm/mmzone.c | 1 + 2 files changed, 3 insertions(+)
include/linux/mmzone.h +2 -0
@@ -303,6 +303,8 @@ struct lruvec {atomic_long_t inactive_age;/* Refaults at the time of last reclaim cycle */ unsigned long refaults; +/* per lruvec lru_lock for memcg */ +spinlock_t lru_lock;#ifdef CONFIG_MEMCG struct pglist_data *pgdat;#endif
mm/mmzone.c +1 -0
@@ -91,6 +91,7 @@ void lruvec_init(struct lruvec *lruvec)enum lru_list lru;memset (lruvec,0 ,sizeof (struct lruvec )); +spin_lock_init (&lruvec->lru_lock);for_each_lru (lru)INIT_LIST_HEAD (&lruvec->lists[lru]);
Signature · 1 line
1.8.3.1
PATCH v2 2/8 mm/lruvec: add irqsave flags into lruvec struct
In reply to Alex ShiWe need a flags vaiable to save state when do irqsave action, declare it here would make code more clear/clean.
Rong Chen <[email protected]> report the flag variable needs to move the tail of lruvec struct otherwise it causes 18% regressions of vm-scalability testing on his machine. Add the flags and lru_lock to both near struct tail.
Originally-from: Hugh Dickins <[email protected]>
--- include/linux/mmzone.h | 2 ++ 1 file changed, 2 insertions(+)
include/linux/mmzone.h +2 -0
@@ -305,6 +305,8 @@ struct lruvec {unsigned long refaults;/* per lruvec lru_lock for memcg */ spinlock_t lru_lock; +/* flags for irqsave */ +unsigned long flags;#ifdef CONFIG_MEMCG struct pglist_data *pgdat;#endif
Signature · 1 line
1.8.3.1
PATCH v2 3/8 mm/lru: replace pgdat lru_lock with lruvec lock
In reply to Alex ShiThis patchset move lru_lock into lruvec, give a lru_lock for each of lruvec, thus bring a lru_lock for each of memcg per node.
This is the main patch to replace per node lru_lock with per memcg lruvec lock. It also fold the irqsave flags into lruvec.
We introduce function lock_page_lruvec, it's same as vanilla pgdat lock when memory cgroup unset, w/o memcg, the function will keep repin the lruvec's lock to guard from page->mem_cgroup changes in page migrations between memcgs. (Thanks Hugh Dickins and Konstantin Khlebnikov reminder on this. Than the core logical is same as their previous patchs)
According to Daniel Jordan's suggestion, I run 64 'dd' with on 32 containers on my 2s* 8 core * HT box with the modefied case:
https://git.kernel.org/pub/scm/linux/kernel/git/wfg/vm-scalability.git/tree/case-lru-file-readtwice
With this and later patches, the dd performance is 144MB/s, the vanilla kernel performance is 123MB/s. 17% performance increased.
--- include/linux/memcontrol.h | 23 ++++++++++++++ mm/compaction.c | 62 ++++++++++++++++++++++++------------ mm/huge_memory.c | 16 ++++------ mm/memcontrol.c | 64 +++++++++++++++++++++++++++++-------- mm/mlock.c | 31 +++++++++--------- mm/page_idle.c | 5 +-- mm/swap.c | 79 +++++++++++++++++++--------------------------- mm/vmscan.c | 58 ++++++++++++++++------------------ 8 files changed, 201 insertions(+), 137 deletions(-)
include/linux/memcontrol.h +23 -0
@@ -428,6 +428,9 @@ static inline struct lruvec *mem_cgroup_lruvec(struct pglist_data *pgdat,struct lruvec *mem_cgroup_page_lruvec (struct page *,struct pglist_data *); +struct lruvec *lock_page_lruvec_irq (struct page *,struct pglist_data *); +struct lruvec *lock_page_lruvec_irqsave (struct page *,struct pglist_data *); +struct mem_cgroup *mem_cgroup_from_task (struct task_struct *p);struct mem_cgroup *get_mem_cgroup_from_mm (struct mm_struct *mm);
@@ -911,6 +914,26 @@ static inline struct lruvec *mem_cgroup_page_lruvec(struct page *page,return &pgdat->lruvec; } +static inline struct lruvec *lock_page_lruvec_irq (struct page *page, +struct pglist_data *pgdat) +{ +struct lruvec *lruvec =mem_cgroup_page_lruvec (page, pgdat); + +spin_lock_irq (&lruvec->lru_lock); + +return lruvec; +} + +static inline struct lruvec *lock_page_lruvec_irqsave (struct page *page, +struct pglist_data *pgdat) +{ +struct lruvec *lruvec =mem_cgroup_page_lruvec (page, pgdat); + +spin_lock_irqsave (&lruvec->lru_lock, lruvec->flags); + +return lruvec; +} +static inline bool mm_match_cgroup (struct mm_struct *mm,struct mem_cgroup *memcg) {
mm/compaction.c +42 -20
105 lines not on this page · raw message
mm/huge_memory.c +6 -10
@@ -2495,17 +2495,13 @@ static void __split_huge_page_tail(struct page *head, int tail, }static void __split_huge_page (struct page *page,struct list_head *list, -pgoff_t end,unsigned long flags) +struct lruvec *lruvec,pgoff_t end) {struct page *head =compound_head (page); -pg_data_t *pgdat =page_pgdat (head); -struct lruvec *lruvec;struct address_space *swap_cache =NULL ;unsigned long offset =0 ;int i; - lruvec =mem_cgroup_page_lruvec (head, pgdat); -/* complete memcg works before add pages to LRU */ mem_cgroup_split_huge_fixup (head);
@@ -2554,7 +2550,7 @@ static void __split_huge_page(struct page *page, struct list_head *list,xa_unlock (&head->mapping->i_pages); } -spin_unlock_irqrestore (&pgdat->lru_lock, flags); +spin_unlock_irqrestore (&lruvec->lru_lock, lruvec->flags);remap_page (head);
@@ -2697,9 +2693,9 @@ int split_huge_page_to_list(struct page *page, struct list_head *list)struct deferred_split *ds_queue =get_deferred_split_queue (page);struct anon_vma *anon_vma =NULL ;struct address_space *mapping =NULL ; +struct lruvec *lruvec;int count, mapcount, extra_pins, ret;bool mlocked; -unsigned long flags;pgoff_t end;VM_BUG_ON_PAGE (is_huge_zero_page (page), page);
@@ -2766,7 +2762,7 @@ int split_huge_page_to_list(struct page *page, struct list_head *list)lru_add_drain ();/* prevent PageLRU to go away from under us, and freeze lru stats */ -spin_lock_irqsave (&pgdata->lru_lock, flags); + lruvec =lock_page_lruvec_irqsave (head, pgdata);if (mapping) {XA_STATE (xas, &mapping->i_pages,page_index (head));
@@ -2797,7 +2793,7 @@ int split_huge_page_to_list(struct page *page, struct list_head *list) }spin_unlock (&ds_queue->split_queue_lock); -__split_huge_page (page, list, end, flags); +__split_huge_page (page, list, lruvec, end);if (PageSwapCache (head)) {swp_entry_t entry = { .val =page_private (head) };
@@ -2816,7 +2812,7 @@ int split_huge_page_to_list(struct page *page, struct list_head *list)spin_unlock (&ds_queue->split_queue_lock); fail:if (mapping)xa_unlock (&mapping->i_pages); -spin_unlock_irqrestore (&pgdata->lru_lock, flags); +spin_unlock_irqrestore (&lruvec->lru_lock, lruvec->flags);remap_page (head); ret = -EBUSY ; }
mm/memcontrol.c +51 -13
119 lines not on this page · raw message
mm/mlock.c +15 -16
@@ -106,12 +106,10 @@ void mlock_vma_page(struct page *page)* Isolate a page from LRU with optional get_page() pin. * Assumes lru_lock already held and page already pinned. */ -static bool __munlock_isolate_lru_page (struct page *page,bool getpage) +static bool __munlock_isolate_lru_page (struct page *page, +struct lruvec *lruvec,bool getpage) {if (PageLRU (page)) { -struct lruvec *lruvec; - - lruvec =mem_cgroup_page_lruvec (page,page_pgdat (page));if (getpage)get_page (page);ClearPageLRU (page);
@@ -183,6 +181,7 @@ unsigned int munlock_vma_page(struct page *page) {int nr_pages;pg_data_t *pgdat =page_pgdat (page); +struct lruvec *lruvec;/* For try_to_munlock() and to serialize with page migration */ BUG_ON (!PageLocked (page));
@@ -194,7 +193,7 @@ unsigned int munlock_vma_page(struct page *page)* might otherwise copy PageMlocked to part of the tail pages before * we clear it in the head page. It also stabilizes hpage_nr_pages(). */ -spin_lock_irq (&pgdat->lru_lock); + lruvec =lock_page_lruvec_irq (page, pgdat);if (!TestClearPageMlocked (page)) {/* Potentially, PTE-mapped THP: do not skip the rest PTEs */
@@ -205,15 +204,15 @@ unsigned int munlock_vma_page(struct page *page) nr_pages =hpage_nr_pages (page);__mod_zone_page_state (page_zone (page),NR_MLOCK , -nr_pages); -if (__munlock_isolate_lru_page (page, true)) { -spin_unlock_irq (&pgdat->lru_lock); +if (__munlock_isolate_lru_page (page, lruvec, true)) { +spin_unlock_irq (&lruvec->lru_lock);__munlock_isolated_page (page); goto out; }__munlock_isolation_failed (page); unlock_out: -spin_unlock_irq (&pgdat->lru_lock); +spin_unlock_irq (&lruvec->lru_lock); out:return nr_pages -1 ;
@@ -291,28 +290,29 @@ static void __munlock_pagevec(struct pagevec *pvec, struct zone *zone) {int i;int nr =pagevec_count (pvec); -int delta_munlocked = -nr;struct pagevec pvec_putback; +struct lruvec *lruvec =NULL ;int pgrescued =0 ;pagevec_init (&pvec_putback);/* Phase 1: page isolation */ -spin_lock_irq (&zone->zone_pgdat->lru_lock);for (i =0 ; i < nr; i++) {struct page *page = pvec->pages[i]; + lruvec =lock_page_lruvec_irq (page,page_pgdat (page)); +if (TestClearPageMlocked (page)) {/* * We already have pin from follow_page_mask() * so we can spare the get_page() here. */ -if (__munlock_isolate_lru_page (page, false)) +if (__munlock_isolate_lru_page (page, lruvec, false)) { +__mod_zone_page_state (zone,NR_MLOCK ,-1 ); +spin_unlock_irq (&lruvec->lru_lock);continue ; -else + }else __munlock_isolation_failed (page); - }else { - delta_munlocked++; }/*
@@ -323,9 +323,8 @@ static void __munlock_pagevec(struct pagevec *pvec, struct zone *zone)*/ pagevec_add (&pvec_putback, pvec->pages[i]); pvec->pages[i] =NULL ; +spin_unlock_irq (&lruvec->lru_lock); } -__mod_zone_page_state (zone,NR_MLOCK , delta_munlocked); -spin_unlock_irq (&zone->zone_pgdat->lru_lock);/* Now we can release pins of pages that we are not munlocking */ pagevec_release (&pvec_putback);
mm/page_idle.c +3 -2
@@ -32,6 +32,7 @@ static struct page *page_idle_get_page(unsigned long pfn) {struct page *page;pg_data_t *pgdat; +struct lruvec *lruvec;if (!pfn_valid (pfn))return NULL ;
@@ -42,12 +43,12 @@ static struct page *page_idle_get_page(unsigned long pfn)return NULL ; pgdat =page_pgdat (page); -spin_lock_irq (&pgdat->lru_lock); + lruvec =lock_page_lruvec_irq (page, pgdat);if (unlikely (!PageLRU (page))) {put_page (page); page =NULL ; } -spin_unlock_irq (&pgdat->lru_lock); +spin_unlock_irq (&lruvec->lru_lock);return page; }
mm/swap.c +33 -46
156 lines not on this page · raw message
mm/vmscan.c +28 -30
175 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v2 4/8 mm/lru: only change the lru_lock iff page's lruvec is different
In reply to Alex ShiDuring the pagevec locking, a new page's lruvec is may same as previous one. So we may save a lruvec locking if the lruvec is same as previous one, and only change the lock iff lruvec is new.
Function named relock_page_lruvec following Hugh Dickins patch.
--- include/linux/memcontrol.h | 49 ++++++++++++++++++++++++++++++++++++++++++++++ mm/mlock.c | 16 ++++++++------- mm/swap.c | 14 ++++++------- mm/vmscan.c | 24 +++++++++++------------ 4 files changed, 76 insertions(+), 27 deletions(-)
include/linux/memcontrol.h +49 -0
@@ -1300,6 +1300,55 @@ static inline void dec_lruvec_page_state(struct page *page,mod_lruvec_page_state (page, idx,-1 ); } +/* Don't lock again iff page's lruvec locked */ +static inline struct lruvec *relock_page_lruvec_irq (struct page *page, +struct lruvec *locked_lruvec) +{ +struct pglist_data *pgdat =page_pgdat (page); +struct lruvec *lruvec; + +rcu_read_lock (); + lruvec =mem_cgroup_page_lruvec (page, pgdat); + +if (locked_lruvec == lruvec) { +rcu_read_unlock (); +return lruvec; + } +rcu_read_unlock (); + +if (locked_lruvec) +spin_unlock_irq (&locked_lruvec->lru_lock); + + lruvec =lock_page_lruvec_irq (page, pgdat); + +return lruvec; +} + +/* Don't lock again iff page's lruvec locked */ +static inline struct lruvec *relock_page_lruvec_irqsave (struct page *page, +struct lruvec *locked_lruvec) +{ +struct pglist_data *pgdat =page_pgdat (page); +struct lruvec *lruvec; + +rcu_read_lock (); + lruvec =mem_cgroup_page_lruvec (page, pgdat); + +if (locked_lruvec == lruvec) { +rcu_read_unlock (); +return lruvec; + } +rcu_read_unlock (); + +if (locked_lruvec) +spin_unlock_irqrestore (&locked_lruvec->lru_lock, + locked_lruvec->flags); + + lruvec =lock_page_lruvec_irqsave (page, pgdat); + +return lruvec; +} +#ifdef CONFIG_CGROUP_WRITEBACK struct wb_domain *mem_cgroup_wb_domain (struct bdi_writeback *wb);
mm/mlock.c +9 -7
@@ -290,6 +290,7 @@ static void __munlock_pagevec(struct pagevec *pvec, struct zone *zone) {int i;int nr =pagevec_count (pvec); +int delta_munlocked = -nr;struct pagevec pvec_putback;struct lruvec *lruvec =NULL ;int pgrescued =0 ;
@@ -300,20 +301,19 @@ static void __munlock_pagevec(struct pagevec *pvec, struct zone *zone)for (i =0 ; i < nr; i++) {struct page *page = pvec->pages[i]; - lruvec =lock_page_lruvec_irq (page,page_pgdat (page)); + lruvec =relock_page_lruvec_irq (page, lruvec);if (TestClearPageMlocked (page)) {/* * We already have pin from follow_page_mask() * so we can spare the get_page() here. */ -if (__munlock_isolate_lru_page (page, lruvec, false)) { -__mod_zone_page_state (zone,NR_MLOCK ,-1 ); -spin_unlock_irq (&lruvec->lru_lock); +if (__munlock_isolate_lru_page (page, lruvec, false))continue ; - }else +else __munlock_isolation_failed (page); - } + }else + delta_munlocked++;/* * We won't be munlocking this page in the next phase
@@ -323,8 +323,10 @@ static void __munlock_pagevec(struct pagevec *pvec, struct zone *zone)*/ pagevec_add (&pvec_putback, pvec->pages[i]); pvec->pages[i] =NULL ; -spin_unlock_irq (&lruvec->lru_lock); } +__mod_zone_page_state (zone,NR_MLOCK , delta_munlocked); +if (lruvec) +spin_unlock_irq (&lruvec->lru_lock);/* Now we can release pins of pages that we are not munlocking */ pagevec_release (&pvec_putback);
mm/swap.c +6 -8
@@ -195,11 +195,12 @@ static void pagevec_lru_move_fn(struct pagevec *pvec,for (i =0 ; i <pagevec_count (pvec); i++) {struct page *page = pvec->pages[i]; - lruvec =lock_page_lruvec_irqsave (page,page_pgdat (page)); + lruvec =relock_page_lruvec_irqsave (page, lruvec); (*move_fn)(page, lruvec, arg); -spin_unlock_irqrestore (&lruvec->lru_lock, lruvec->flags); } +if (lruvec) +spin_unlock_irqrestore (&lruvec->lru_lock, lruvec->flags);release_pages (pvec->pages, pvec->nr);pagevec_reinit (pvec);
@@ -802,15 +803,12 @@ void release_pages(struct page **pages, int nr) }if (PageLRU (page)) { -struct lruvec *new_lruvec =mem_cgroup_page_lruvec (page,page_pgdat (page)); +struct lruvec *pre_lruvec = lruvec; -if (new_lruvec != lruvec) { -if (lruvec) -spin_unlock_irqrestore (&lruvec->lru_lock, lruvec->flags); + lruvec =relock_page_lruvec_irqsave (page, lruvec); +if (pre_lruvec != lruvec) lock_batch =0 ; - lruvec =lock_page_lruvec_irqsave (page,page_pgdat (page)); - }VM_BUG_ON_PAGE (!PageLRU (page), page);__ClearPageLRU (page);del_page_from_lru_list (page, lruvec,page_off_lru (page));
mm/vmscan.c +12 -12
@@ -1874,22 +1874,25 @@ static int too_many_isolated(struct pglist_data *pgdat, int file,* Returns the number of pages moved to the given lruvec. */ -static unsigned noinline_for_stack move_pages_to_lru (struct lruvec *lruvec, +static unsigned noinline_for_stack move_pages_to_lru (struct lruvec *llvec,struct list_head *list) {int nr_pages, nr_moved =0 ;LIST_HEAD (pages_to_free);struct page *page;enum lru_list lru; +struct lruvec *lruvec = llvec;while (!list_empty (list)) { page =lru_to_page (list); + lruvec =relock_page_lruvec_irq (page, lruvec); +VM_BUG_ON_PAGE (PageLRU (page), page);if (unlikely (!page_evictable (page))) {list_del (&page->lru);spin_unlock_irq (&lruvec->lru_lock); + lruvec =NULL ;putback_lru_page (page); -spin_lock_irq (&lruvec->lru_lock);continue ; }
@@ -1907,8 +1910,8 @@ static unsigned noinline_for_stack move_pages_to_lru(struct lruvec *lruvec,if (unlikely (PageCompound (page))) {spin_unlock_irq (&lruvec->lru_lock); + lruvec =NULL ; (*get_compound_page_dtor (page))(page); -spin_lock_irq (&lruvec->lru_lock); }else list_add (&page->lru, &pages_to_free); }else {
@@ -1916,6 +1919,11 @@ static unsigned noinline_for_stack move_pages_to_lru(struct lruvec *lruvec, } } +if (lruvec != llvec) { +if (lruvec) +spin_unlock_irq (&lruvec->lru_lock); +spin_lock_irq (&llvec->lru_lock); + }/* * To save our caller's stack, now use input list for pages to free. */
@@ -4338,18 +4346,10 @@ void check_move_unevictable_pages(struct pagevec *pvec)for (i =0 ; i < pvec->nr; i++) {struct page *page = pvec->pages[i]; -struct pglist_data *pgdat =page_pgdat (page); -struct lruvec *new_lruvec =mem_cgroup_page_lruvec (page, pgdat); - pgscanned++; -if (lruvec != new_lruvec) { -if (lruvec) -spin_unlock_irq (&lruvec->lru_lock); - lruvec = new_lruvec; -spin_lock_irq (&lruvec->lru_lock); - } + lruvec =relock_page_lruvec_irq (page, lruvec);if (!PageLRU (page) || !PageUnevictable (page))continue ;
Signature · 1 line
1.8.3.1
PATCH v2 5/8 mm/pgdat: remove pgdat lru_lock
In reply to Alex ShiNow pgdat was replaced by lruvec lock. It's not used anymore.
--- include/linux/mmzone.h | 1 - mm/page_alloc.c | 1 - 2 files changed, 2 deletions(-)
include/linux/mmzone.h +0 -1
@@ -759,7 +759,6 @@ struct deferred_split {/* Write-intensive fields used by page reclaim */ ZONE_PADDING (_pad1_) - spinlock_t lru_lock; #ifdef CONFIG_DEFERRED_STRUCT_PAGE_INIT/*
mm/page_alloc.c +0 -1
@@ -6710,7 +6710,6 @@ static void __meminit pgdat_init_internals(struct pglist_data *pgdat)init_waitqueue_head (&pgdat->pfmemalloc_wait);pgdat_page_ext_init (pgdat); -spin_lock_init (&pgdat->lru_lock);lruvec_init (node_lruvec (pgdat)); }
Signature · 1 line
1.8.3.1
PATCH v2 6/8 mm/lru: remove rcu_read_lock to fix performance regression
In reply to Alex ShiIntel 0day report there are performance regression on this patchset. The detailed info points to rcu_read_lock + PROVE_LOCKING which causes queued_spin_lock_slowpath waiting too long time to get lock. Remove rcu_read_lock is safe here since we had a spinlock hold.
--- include/linux/memcontrol.h | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-)
include/linux/memcontrol.h +12 -17
@@ -1307,20 +1307,18 @@ static inline struct lruvec *relock_page_lruvec_irq(struct page *page,struct pglist_data *pgdat =page_pgdat (page);struct lruvec *lruvec; -rcu_read_lock (); +if (!locked_lruvec) + goto lock; + lruvec =mem_cgroup_page_lruvec (page, pgdat); -if (locked_lruvec == lruvec) { -rcu_read_unlock (); +if (locked_lruvec == lruvec)return lruvec; - } -rcu_read_unlock (); -if (locked_lruvec) -spin_unlock_irq (&locked_lruvec->lru_lock); +spin_unlock_irq (&locked_lruvec->lru_lock); +lock: lruvec =lock_page_lruvec_irq (page, pgdat); -return lruvec; }
@@ -1331,21 +1329,18 @@ static inline struct lruvec *relock_page_lruvec_irqsave(struct page *page,struct pglist_data *pgdat =page_pgdat (page);struct lruvec *lruvec; -rcu_read_lock (); +if (!locked_lruvec) + goto lock; + lruvec =mem_cgroup_page_lruvec (page, pgdat); -if (locked_lruvec == lruvec) { -rcu_read_unlock (); +if (locked_lruvec == lruvec)return lruvec; - } -rcu_read_unlock (); -if (locked_lruvec) -spin_unlock_irqrestore (&locked_lruvec->lru_lock, - locked_lruvec->flags); +spin_unlock_irqrestore (&locked_lruvec->lru_lock, locked_lruvec->flags); +lock: lruvec =lock_page_lruvec_irqsave (page, pgdat); -return lruvec; }
Signature · 1 line
1.8.3.1
PATCH v2 7/8 mm/lru: likely enhancement
In reply to Alex ShiUse likely() to remove speculations according to pagevec usage mode.
--- include/linux/memcontrol.h | 8 ++++---- mm/memcontrol.c | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-)
include/linux/memcontrol.h +4 -4
@@ -1307,12 +1307,12 @@ static inline struct lruvec *relock_page_lruvec_irq(struct page *page,struct pglist_data *pgdat =page_pgdat (page);struct lruvec *lruvec; -if (!locked_lruvec) +if (unlikely (!locked_lruvec)) goto lock; lruvec =mem_cgroup_page_lruvec (page, pgdat); -if (locked_lruvec == lruvec) +if (likely (locked_lruvec == lruvec))return lruvec;spin_unlock_irq (&locked_lruvec->lru_lock);
@@ -1329,12 +1329,12 @@ static inline struct lruvec *relock_page_lruvec_irqsave(struct page *page,struct pglist_data *pgdat =page_pgdat (page);struct lruvec *lruvec; -if (!locked_lruvec) +if (unlikely (!locked_lruvec)) goto lock; lruvec =mem_cgroup_page_lruvec (page, pgdat); -if (locked_lruvec == lruvec) +if (likely (locked_lruvec == lruvec))return lruvec;spin_unlock_irqrestore (&locked_lruvec->lru_lock, locked_lruvec->flags);
mm/memcontrol.c +2 -2
@@ -1273,7 +1273,7 @@ struct lruvec *lock_page_lruvec_irq(struct page *page,spin_lock_irq (&lruvec->lru_lock);/* lruvec may changed in commit_charge() */ -if (lruvec !=mem_cgroup_page_lruvec (page, pgdat)) { +if (unlikely (lruvec !=mem_cgroup_page_lruvec (page, pgdat))) {spin_unlock_irq (&lruvec->lru_lock); goto again; }
@@ -1291,7 +1291,7 @@ struct lruvec *lock_page_lruvec_irqsave(struct page *page,spin_lock_irqsave (&lruvec->lru_lock, lruvec->flags);/* lruvec may changed in commit_charge() */ -if (lruvec !=mem_cgroup_page_lruvec (page, pgdat)) { +if (unlikely (lruvec !=mem_cgroup_page_lruvec (page, pgdat))) {spin_unlock_irqrestore (&lruvec->lru_lock, lruvec->flags); goto again; }
Signature · 1 line
1.8.3.1
PATCH v2 8/8 mm/lru: revise the comments of lru_lock
In reply to Alex ShiSince we changed the pgdat->lru_lock to lruvec->lru_lock, it's time to fix the incorrect comments in code. Also fixed some zone->lru_lock comment error from ancient time. etc.
Originally-from: Hugh Dickins <[email protected]>
--- Documentation/admin-guide/cgroup-v1/memcg_test.rst | 15 +++------------ Documentation/admin-guide/cgroup-v1/memory.rst | 6 +++--- Documentation/trace/events-kmem.rst | 2 +- Documentation/vm/unevictable-lru.rst | 22 ++++++++-------------- include/linux/mm_types.h | 2 +- include/linux/mmzone.h | 2 +- mm/filemap.c | 4 ++-- mm/rmap.c | 2 +- mm/vmscan.c | 12 ++++++++---- 9 files changed, 28 insertions(+), 39 deletions(-)
Documentation/admin-guide/cgroup-v1/memcg_test.rst +3 -12
@@ -133,18 +133,9 @@ Under below explanation, we assume CONFIG_MEM_RES_CTRL_SWAP=y. 8. LRU ====== - Each memcg has its own private LRU. Now, its handling is under global - VM's control (means that it's handled under global pgdat->lru_lock). - Almost all routines around memcg's LRU is called by global LRU's - list management functions under pgdat->lru_lock. - - A special function is mem_cgroup_isolate_pages(). This scans - memcg's private LRU and call __isolate_lru_page() to extract a page - from LRU. - - (By __isolate_lru_page(), the page is removed from both of global and - private LRU.) - + Each memcg has its own vector of LRUs (inactive anon, active anon, + inactive file, active file, unevictable) of pages from each node, + each LRU handled under a single lru_lock for that memcg and node. 9. Typical Tests. =================
Documentation/admin-guide/cgroup-v1/memory.rst +3 -3
@@ -297,13 +297,13 @@ When oom event notifier is registered, event will be delivered. PG_locked. mm->page_table_lock - pgdat->lru_lock + lruvec->lru_lock lock_page_cgroup. In many cases, just lock_page_cgroup() is called. - per-zone-per-cgroup LRU (cgroup's private LRU) is just guarded by - pgdat->lru_lock, it has no lock of its own. + per-node-per-cgroup LRU (cgroup's private LRU) is just guarded by + lruvec->lru_lock, it has no lock of its own. 2.7 Kernel Memory Extension (CONFIG_MEMCG_KMEM) -----------------------------------------------
Documentation/trace/events-kmem.rst +1 -1
@@ -69,7 +69,7 @@ When pages are freed in batch, the also mm_page_free_batched is triggered. Broadly speaking, pages are taken off the LRU lock in bulk and freed in batch with a page list. Significant amounts of activity here could indicate that the system is under memory pressure and can also indicate -contention on the zone->lru_lock. +contention on the lruvec->lru_lock. 4. Per-CPU Allocator Activity =============================
Documentation/vm/unevictable-lru.rst +8 -14
@@ -33,7 +33,7 @@ reclaim in Linux. The problems have been observed at customer sites on large memory x86_64 systems. To illustrate this with an example, a non-NUMA x86_64 platform with 128GB of -main memory will have over 32 million 4k pages in a single zone. When a large +main memory will have over 32 million 4k pages in a single node. When a large fraction of these pages are not evictable for any reason [see below], vmscan will spend a lot of time scanning the LRU lists looking for the small fraction of pages that are evictable. This can result in a situation where all CPUs are
@@ -55,7 +55,7 @@ unevictable, either by definition or by circumstance, in the future. The Unevictable Page List ------------------------- -The Unevictable LRU infrastructure consists of an additional, per-zone, LRU list +The Unevictable LRU infrastructure consists of an additional, per-node, LRU list called the "unevictable" list and an associated page flag, PG_unevictable, to indicate that the page is being managed on the unevictable list.
@@ -84,15 +84,9 @@ The unevictable list does not differentiate between file-backed and anonymous, swap-backed pages. This differentiation is only important while the pages are, in fact, evictable. -The unevictable list benefits from the "arrayification" of the per-zone LRU +The unevictable list benefits from the "arrayification" of the per-node LRU lists and statistics originally proposed and posted by Christoph Lameter. -The unevictable list does not use the LRU pagevec mechanism. Rather, -unevictable pages are placed directly on the page's zone's unevictable list -under the zone lru_lock. This allows us to prevent the stranding of pages on -the unevictable list when one task has the page isolated from the LRU and other -tasks are changing the "evictability" state of the page. - Memory Control Group Interaction --------------------------------
@@ -101,8 +95,8 @@ The unevictable LRU facility interacts with the memory control group [aka memory controller; see Documentation/admin-guide/cgroup-v1/memory.rst] by extending the lru_list enum. -The memory controller data structure automatically gets a per-zone unevictable -list as a result of the "arrayification" of the per-zone LRU lists (one per +The memory controller data structure automatically gets a per-node unevictable +list as a result of the "arrayification" of the per-node LRU lists (one per lru_list enum element). The memory controller tracks the movement of pages to and from the unevictable list.
@@ -196,7 +190,7 @@ for the sake of expediency, to leave a unevictable page on one of the regular active/inactive LRU lists for vmscan to deal with. vmscan checks for such pages in all of the shrink_{active|inactive|page}_list() functions and will "cull" such pages that it encounters: that is, it diverts those pages to the -unevictable list for the zone being scanned. +unevictable list for the node being scanned. There may be situations where a page is mapped into a VM_LOCKED VMA, but the page is not marked as PG_mlocked. Such pages will make it all the way to
@@ -328,7 +322,7 @@ If the page was NOT already mlocked, mlock_vma_page() attempts to isolate the page from the LRU, as it is likely on the appropriate active or inactive list at that time. If the isolate_lru_page() succeeds, mlock_vma_page() will put back the page - by calling putback_lru_page() - which will notice that the page -is now mlocked and divert the page to the zone's unevictable list. If +is now mlocked and divert the page to the node's unevictable list. If mlock_vma_page() is unable to isolate the page from the LRU, vmscan will handle it later if and when it attempts to reclaim the page.
@@ -603,7 +597,7 @@ Some examples of these unevictable pages on the LRU lists are: unevictable list in mlock_vma_page(). shrink_inactive_list() also diverts any unevictable pages that it finds on the -inactive lists to the appropriate zone's unevictable list. +inactive lists to the appropriate node's unevictable list. shrink_inactive_list() should only see SHM_LOCK'd pages that became SHM_LOCK'd after shrink_active_list() had moved them to the inactive list, or pages mapped
include/linux/mm_types.h +1 -1
@@ -78,7 +78,7 @@ struct page {struct {/* Page cache and anonymous pages */ /** * @lru: Pageout list, eg. active_list protected by -* pgdat->lru_lock. Sometimes used as a generic list +* lruvec->lru_lock. Sometimes used as a generic list * by the page owner. */ struct list_head lru;
include/linux/mmzone.h +1 -1
@@ -159,7 +159,7 @@ static inline bool free_area_empty(struct free_area *area, int migratetype)struct pglist_data ;/* -* zone->lock and the zone lru_lock are two of the hottest locks in the kernel. +* zone->lock and the lru_lock are two of the hottest locks in the kernel. * So add a wild amount of padding here to ensure that they fall into separate * cachelines. There are very few zone structures in the machine, so space * consumption is not a concern here.
mm/filemap.c +2 -2
@@ -101,8 +101,8 @@* ->swap_lock (try_to_unmap_one) * ->private_lock (try_to_unmap_one) * ->i_pages lock (try_to_unmap_one) -* ->pgdat->lru_lock (follow_page->mark_page_accessed) -* ->pgdat->lru_lock (check_pte_range->isolate_lru_page) +* ->lruvec->lru_lock (follow_page->mark_page_accessed) +* ->lruvec->lru_lock (check_pte_range->isolate_lru_page) * ->private_lock (page_remove_rmap->set_page_dirty) * ->i_pages lock (page_remove_rmap->set_page_dirty) * bdi.wb->list_lock (page_remove_rmap->set_page_dirty)
mm/rmap.c +1 -1
@@ -27,7 +27,7 @@* mapping->i_mmap_rwsem * anon_vma->rwsem * mm->page_table_lock or pte_lock -* pgdat->lru_lock (in mark_page_accessed, isolate_lru_page) +* lruvec->lru_lock (in mark_page_accessed, isolate_lru_page) * swap_lock (in swap_duplicate, swap_info_get) * mmlist_lock (in mmput, drain_mmlist and others) * mapping->private_lock (in __set_page_dirty_buffers)
mm/vmscan.c +8 -4
@@ -1661,14 +1661,16 @@ static __always_inline void update_lru_sizes(struct lruvec *lruvec, }/** -* pgdat->lru_lock is heavily contended. Some of the functions that +* Isolating page from the lruvec to fill in @dst list by nr_to_scan times. +* +* lruvec->lru_lock is heavily contended. Some of the functions that * shrink the lists perform better by taking out a batch of pages * and working on them outside the LRU lock. * * For pagecache intensive workloads, this function is the hottest * spot in the kernel (apart from copy_*_user functions). * -* Appropriate locks must be held before calling this function. +* Lru_lock must be held before calling this function. * * @nr_to_scan: The number of eligible pages to look through on the list. * @lruvec: The LRU vector to pull pages from.
@@ -1856,14 +1858,16 @@ static int too_many_isolated(struct pglist_data *pgdat, int file,/* * This moves pages from @list to corresponding LRU list. +* The pages from @list is out of any lruvec, and in the end list reuses as +* pages_to_free list. * * We move them the other way if the page is referenced by one or more * processes, from rmap. * * If the pages are mostly unmapped, the processing is fast and it is -* appropriate to hold zone_lru_lock across the whole operation. But if +* appropriate to hold lru_lock across the whole operation. But if * the pages are mapped, the processing is slow (page_referenced()) so we -* should drop zone_lru_lock around each page. It's impossible to balance +* should drop lru_lock around each page. It's impossible to balance * this, so instead we remove the pages from the LRU while processing them. * It is safe to rely on PG_active against the non-LRU pages in here because * nobody will play with that bit on a non-LRU page.
Signature · 1 line
1.8.3.1
Matthew Wilcox
maintainerRe: [PATCH v2 4/8] mm/lru: only change the lru_lock iff page's lruvec is different
In reply to Alex ShiQuoted 5 lines · Alex Shi
include/linux/memcontrol.h +5
-0+/* Don't lock again iff page's lruvec locked */ +static inline struct lruvec *relock_page_lruvec_irq (struct page *page, +struct lruvec *locked_lruvec) +{ +struct pglist_data *pgdat =page_pgdat (page);
include/linux/memcontrol.h static inline void dec_lruvec_page_state(struct page *page, · line 1317
Quoted 10 lines
include/linux/memcontrol.h +10
-0+struct lruvec *lruvec; + +rcu_read_lock (); + lruvec =mem_cgroup_page_lruvec (page, pgdat); + +if (locked_lruvec == lruvec) { +rcu_read_unlock (); +return lruvec; + } +rcu_read_unlock ();
Why not simply:
rcu_read_lock(); lruvec = mem_cgroup_page_lruvec(page, pgdat); rcu_read_unlock(); if (locked_lruvec == lruvec) return lruvec;
Also, why are you bothering to re-enable interrupts here? Surely if you're holding lock A with interrupts disabled , you can just drop lock A, acquire lock B and leave the interrupts alone. That way you only need one of this variety of function, and not the separate irq/irqsave variants.
Matthew Wilcox
maintainerRe: [PATCH v2 6/8] mm/lru: remove rcu_read_lock to fix performance regression
In reply to Alex ShiQuoted 4 lines · Alex Shi
Intel 0day report there are performance regression on this patchset. The detailed info points to
rcu_read_lock+PROVE_LOCKINGwhich causesqueued_spin_lock_slowpathwaiting too long time to get lock. Removercu_read_lockis safe here since we had a spinlock hold.
Argh. You have not sent these patches in a properly reviewable form! I wasted all that time reviewing the earlier patch in this series only to find out that you changed it here. FIX THE PATCH, don't send a fix-patch on top of it!
Quoted 78 lines
Reported-by kbuild test robot <[email protected]>Signed-off-by Alex Shi <[email protected]>Cc Andrew Morton <[email protected]>Cc Johannes Weiner <[email protected]>Cc Roman Gushchin <[email protected]>Cc Shakeel Butt <[email protected]>Cc Chris Down <[email protected]>Cc Tejun Heo <[email protected]>Cc Thomas Gleixner <[email protected]>--- include/linux/memcontrol.h | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-)include/linux/memcontrol.h +12
-17@@ -1307,20 +1307,18 @@ static inline struct lruvec *relock_page_lruvec_irq(struct page *page,struct pglist_data *pgdat =page_pgdat (page);struct lruvec *lruvec; -rcu_read_lock (); +if (!locked_lruvec) + goto lock; + lruvec =mem_cgroup_page_lruvec (page, pgdat); -if (locked_lruvec == lruvec) { -rcu_read_unlock (); +if (locked_lruvec == lruvec)return lruvec; - } -rcu_read_unlock (); -if (locked_lruvec) -spin_unlock_irq (&locked_lruvec->lru_lock); +spin_unlock_irq (&locked_lruvec->lru_lock); +lock: lruvec =lock_page_lruvec_irq (page, pgdat); -return lruvec; }@@ -1331,21 +1329,18 @@ static inline struct lruvec *relock_page_lruvec_irqsave(struct page *page,struct pglist_data *pgdat =page_pgdat (page);struct lruvec *lruvec; -rcu_read_lock (); +if (!locked_lruvec) + goto lock; + lruvec =mem_cgroup_page_lruvec (page, pgdat); -if (locked_lruvec == lruvec) { -rcu_read_unlock (); +if (locked_lruvec == lruvec)return lruvec; - } -rcu_read_unlock (); -if (locked_lruvec) -spin_unlock_irqrestore (&locked_lruvec->lru_lock, - locked_lruvec->flags); +spin_unlock_irqrestore (&locked_lruvec->lru_lock, locked_lruvec->flags); +lock: lruvec =lock_page_lruvec_irqsave (page, pgdat); -return lruvec; }Signature · 1 line
1.8.3.1
Re: [PATCH v2 4/8] mm/lru: only change the lru_lock iff page's lruvec is different
In reply to Matthew Wilcoxhi Matthew,
Thanks a lot for comments!
ÔÚ 2019/11/12 ÏÂÎç10:36, Matthew Wilcox дµÀ:
Quoted 19 lines · Alex Shi
Quoted 5 lines
include/linux/memcontrol.h +5
-0+/* Don't lock again iff page's lruvec locked */ +static inline struct lruvec *relock_page_lruvec_irq (struct page *page, +struct lruvec *locked_lruvec) +{ +struct pglist_data *pgdat =page_pgdat (page);include/linux/memcontrol.h static inline void dec_lruvec_page_state(struct page *page, · line 1317
Quoted 10 lines
include/linux/memcontrol.h +10
-0+struct lruvec *lruvec; + +rcu_read_lock (); + lruvec =mem_cgroup_page_lruvec (page, pgdat); + +if (locked_lruvec == lruvec) { +rcu_read_unlock (); +return lruvec; + } +rcu_read_unlock ();Why not simply:
Quoted 5 lines
rcu_read_lock(); lruvec = mem_cgroup_page_lruvec(page, pgdat); rcu_read_unlock(); if (locked_lruvec == lruvec)
The rcu_read_unlock here is for guarding the locked_lruvec/lruvec comparsion. Otherwise memcg/lruvec maybe changed, like, from memcg migration etc. I guess.
Quoted 7 lines
return lruvec;Also, why are you bothering to re-enable interrupts here? Surely if you're holding lock A with interrupts disabled , you can just drop lock A, acquire lock B and leave the interrupts alone. That way you only need one of this variety of function, and not the separate irq/irqsave variants.
Thanks for the suggestion! Yes, if only do re-lock, it's better to leave the irq unchanging. but, when the locked_lruvec is NULL, it become a first time lock which irq or irqsave are different. Thus, in combined function we need a nother parameter to indicate if it do irqsaving. So comparing to a extra/indistinct parameter, I guess 2 inline functions would be a bit more simple/cleary?
Thanks a lot!
Alex
Re: [PATCH v2 6/8] mm/lru: remove rcu_read_lock to fix performance regression
In reply to Matthew WilcoxÔÚ 2019/11/12 ÏÂÎç10:38, Matthew Wilcox дµÀ:
Quoted 10 lines · Alex Shi
Quoted 4 lines
Intel 0day report there are performance regression on this patchset. The detailed info points to
rcu_read_lock+PROVE_LOCKINGwhich causesqueued_spin_lock_slowpathwaiting too long time to get lock. Removercu_read_lockis safe here since we had a spinlock hold.Argh. You have not sent these patches in a properly reviewable form! I wasted all that time reviewing the earlier patch in this series only to find out that you changed it here. FIX THE PATCH, don't send a fix-patch on top of it!
Hi Matthew,
Very sorry for your time! The main reasons I use a separate patch since a, Intel 0day asking me to credit their are founding, and I don't know how to give a clearly/elegant explanation for a non-exist regression in a fixed patch. b, this regression is kindly pretty tricky. Maybe it's better saying thanks in version change log of cover-letter?
Anyway, Thanks a lot for your review!
Alex
Re: [PATCH v2 6/8] mm/lru: remove rcu_read_lock to fix performance regression
Quoted 14 lines · Alex Shi
?? 2019/11/12 ????10:38, Matthew Wilcox ????:
Quoted 10 lines · Alex Shi
Quoted 4 lines
Intel 0day report there are performance regression on this patchset. The detailed info points to
rcu_read_lock+PROVE_LOCKINGwhich causesqueued_spin_lock_slowpathwaiting too long time to get lock. Removercu_read_lockis safe here since we had a spinlock hold.Argh. You have not sent these patches in a properly reviewable form! I wasted all that time reviewing the earlier patch in this series only to find out that you changed it here. FIX THE PATCH, don't send a fix-patch on top of it!
Quoted 4 lines
Hi Matthew,
Very sorry for your time! The main reasons I use a separate patch since a, Intel 0day asking me to credit their are founding, and I don't know how to give a clearly/elegant explanation for a non-exist regression in a fixed patch. b, this regression is kindly pretty tricky. Maybe it's better saying thanks in version change log of cover-letter?
Add something like this to the patch
...
Signature · 2 lines
Mel Gorman SUSE Labs
Matthew Wilcox
maintainerRe: [PATCH v2 4/8] mm/lru: only change the lru_lock iff page's lruvec is different
In reply to Alex ShiQuoted 20 lines · Alex Shi
Quoted 19 lines · Matthew Wilcox
Quoted 5 lines · Alex Shi
include/linux/memcontrol.h +5
-0+/* Don't lock again iff page's lruvec locked */ +static inline struct lruvec *relock_page_lruvec_irq (struct page *page, +struct lruvec *locked_lruvec) +{ +struct pglist_data *pgdat =page_pgdat (page);include/linux/memcontrol.h static inline void dec_lruvec_page_state(struct page *page, · line 1317
Quoted 10 lines
include/linux/memcontrol.h +10
-0+struct lruvec *lruvec; + +rcu_read_lock (); + lruvec =mem_cgroup_page_lruvec (page, pgdat); + +if (locked_lruvec == lruvec) { +rcu_read_unlock (); +return lruvec; + } +rcu_read_unlock ();Why not simply:
Quoted 8 lines
Quoted 5 lines
rcu_read_lock(); lruvec = mem_cgroup_page_lruvec(page, pgdat); rcu_read_unlock(); if (locked_lruvec == lruvec)The
rcu_read_unlockhere is for guarding the locked_lruvec/lruvec comparsion. Otherwise memcg/lruvec maybe changed, like, from memcg migration etc. I guess.
How does holding the RCU lock guard the comparison? You're comparing two pointers for equality. Nothing any other CPU can do at this point will change the results of that comparison.
Quoted 7 lines
Quoted 5 lines
Also, why are you bothering to re-enable interrupts here? Surely if you're holding lock A with interrupts disabled , you can just drop lock A, acquire lock B and leave the interrupts alone. That way you only need one of this variety of function, and not the separate irq/irqsave variants.
Thanks for the suggestion! Yes, if only do re-lock, it's better to leave the irq unchanging. but, when the
locked_lruvecis NULL, it become a first time lock which irq or irqsave are different. Thus, in combined function we need a nother parameter to indicate if it do irqsaving. So comparing to a extra/indistinct parameter, I guess 2 inline functions would be a bit more simple/cleary?
Ah, right, I missed the "if it's not held" case.
Re: [PATCH v2 4/8] mm/lru: only change the lru_lock iff page's lruvec is different
Quoted 6 lines · Matthew Wilcox
Quoted 6 lines
Quoted 6 lines
Why not simply:
rcu_read_lock(); lruvec = mem_cgroup_page_lruvec(page, pgdat); rcu_read_unlock();
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
if (locked_lruvec == lruvec)The
rcu_read_unlockhere is for guarding the locked_lruvec/lruvec comparsion. Otherwise memcg/lruvec maybe changed, like, from memcg migration etc. I guess.How does holding the RCU lock guard the comparison? You're comparing two pointers for equality. Nothing any other CPU can do at this point will change the results of that comparison.
Hi Matthew, Thanks for reply!
The reason of guarding lruvec compasion here is a bit undistinct, in fact, it guards the page's memcg from free/migrate etc, since the lruvec is kind of binding to each of memcg. The detailed explanation could be found in lock_page_memcg().
Thanks
Alex
Re: [PATCH v2 6/8] mm/lru: remove rcu_read_lock to fix performance regression
In reply to Mel GormanQuoted 8 lines · Mel Gorman
Quoted 4 lines
Hi Matthew,
Very sorry for your time! The main reasons I use a separate patch since a, Intel 0day asking me to credit their are founding, and I don't know how to give a clearly/elegant explanation for a non-exist regression in a fixed patch. b, this regression is kindly pretty tricky. Maybe it's better saying thanks in version change log of cover-letter?
Add something like this to the patch
[[email protected]: Fix RCU-related regression reported by LKP robot]Signed-off-by Alex Shi <[email protected]>
It's a good idea! Thanks a lot, Mel!