Skip to content

Commit 9cbfd1c

Browse files
yuzhaogoogleakpm00
authored andcommitted
mm/mglru: clean up workingset
Patch series "mm/mglru: performance optimizations", v4. This series improves performance for some previously reported test cases. Most of the code changes gathered here has been floating on the mailing list [1][2]. They are now properly organized and have gone through various benchmarks on client and server devices, including Android, FIO, memcached, multiple VMs and MongoDB. In addition to the syzbot regressions fixed in v2 [3] and v3 [4], this version fixes two more regressions: one reported by Oliver Sang [5] and the other by Barry Song. [1] https://lore.kernel.org/CAOUHufahuWcKf5f1Sg3emnqX+cODuR=2TQo7T4Gr-QYLujn4RA@mail.gmail.com/ [2] https://lore.kernel.org/CAOUHufawNerxqLm7L9Yywp3HJFiYVrYO26ePUb1jH-qxNGWzyA@mail.gmail.com/ [3] https://lore.kernel.org/[email protected]/ [4] https://lore.kernel.org/[email protected]/ [5] https://lore.kernel.org/[email protected]/ This patch (of 7): Move VM_BUG_ON_FOLIO() to cover both the default and MGLRU paths. Also use a pair of rcu_read_lock() and rcu_read_unlock() within each path, to improve readability. This change should not have any side effects. Link: https://lkml.kernel.org/r/[email protected] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Yu Zhao <[email protected]> Tested-by: Kalesh Singh <[email protected]> Cc: Barry Song <[email protected]> Cc: Bharata B Rao <[email protected]> Cc: David Stevens <[email protected]> Cc: Kairui Song <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent c6f2397 commit 9cbfd1c

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

mm/workingset.c

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -428,17 +428,17 @@ bool workingset_test_recent(void *shadow, bool file, bool *workingset,
428428
struct pglist_data *pgdat;
429429
unsigned long eviction;
430430

431-
rcu_read_lock();
432-
433431
if (lru_gen_enabled()) {
434-
bool recent = lru_gen_test_recent(shadow, file,
435-
&eviction_lruvec, &eviction, workingset);
432+
bool recent;
436433

434+
rcu_read_lock();
435+
recent = lru_gen_test_recent(shadow, file, &eviction_lruvec,
436+
&eviction, workingset);
437437
rcu_read_unlock();
438438
return recent;
439439
}
440440

441-
441+
rcu_read_lock();
442442
unpack_shadow(shadow, &memcgid, &pgdat, &eviction, workingset);
443443
eviction <<= bucket_order;
444444

@@ -459,14 +459,12 @@ bool workingset_test_recent(void *shadow, bool file, bool *workingset,
459459
* configurations instead.
460460
*/
461461
eviction_memcg = mem_cgroup_from_id(memcgid);
462-
if (!mem_cgroup_disabled() &&
463-
(!eviction_memcg || !mem_cgroup_tryget(eviction_memcg))) {
464-
rcu_read_unlock();
465-
return false;
466-
}
467-
462+
if (!mem_cgroup_tryget(eviction_memcg))
463+
eviction_memcg = NULL;
468464
rcu_read_unlock();
469465

466+
if (!mem_cgroup_disabled() && !eviction_memcg)
467+
return false;
470468
/*
471469
* Flush stats (and potentially sleep) outside the RCU read section.
472470
*
@@ -544,6 +542,8 @@ void workingset_refault(struct folio *folio, void *shadow)
544542
bool workingset;
545543
long nr;
546544

545+
VM_BUG_ON_FOLIO(!folio_test_locked(folio), folio);
546+
547547
if (lru_gen_enabled()) {
548548
lru_gen_refault(folio, shadow);
549549
return;
@@ -558,7 +558,6 @@ void workingset_refault(struct folio *folio, void *shadow)
558558
* is actually experiencing the refault event. Make sure the folio is
559559
* locked to guarantee folio_memcg() stability throughout.
560560
*/
561-
VM_BUG_ON_FOLIO(!folio_test_locked(folio), folio);
562561
nr = folio_nr_pages(folio);
563562
memcg = folio_memcg(folio);
564563
pgdat = folio_pgdat(folio);

0 commit comments

Comments
 (0)