2023-05-15 11:54:46

by Mel Gorman

[permalink] [raw]
Subject: [PATCH 0/4] Follow-up "Fix excessive CPU usage during compaction"

The series "Fix excessive CPU usage during compaction" [1] attempted to
fix a bug [2] but Vlastimil noted that the fix was incomplete [3]. While
the series was merged, fast_find_migrateblock was still disabled. This
series should fix the corner cases and allow 95e7a450b819 ("Revert
"mm/compaction: fix set skip in fast_find_migrateblock"") to be safely
reverted. Details on how many pageblocks are rescanned are in the
changelog of the last patch.

[1] https://lore.kernel.org/r/[email protected]
[2] https://bugzilla.suse.com/show_bug.cgi?id=1206848
[3] https://lore.kernel.org/r/[email protected]

mm/compaction.c | 24 ++++++++++--------------
1 file changed, 10 insertions(+), 14 deletions(-)

--
2.35.3



2023-05-15 11:55:21

by Mel Gorman

[permalink] [raw]
Subject: [PATCH 2/4] mm: compaction: Only force pageblock scan completion when skip hints are obeyed

fast_find_migrateblock relies on skip hints to avoid rescanning a recently
selected pageblock but compact_zone() only forces the pageblock scan
completion to set the skip hint if in direct compaction. While this
prevents direct compaction repeatedly scanning a subset of blocks due
to fast_find_migrateblock(), it does not prevent proactive compaction,
node compaction and kcompactd encountering the same problem described
in commit cfccd2e63e7e ("mm, compaction: finish pageblocks on complete
migration failure").

Force the scan completion of a pageblock to set the skip hint if skip
hints are obeyed to prevent fast_find_migrateblock() repeatedly selecting
a subset of pageblocks.

Suggested-by: Vlastimil Babka <[email protected]>
Signed-off-by: Mel Gorman <[email protected]>
---
mm/compaction.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/mm/compaction.c b/mm/compaction.c
index 81791c124bb8..accc6568091a 100644
--- a/mm/compaction.c
+++ b/mm/compaction.c
@@ -2456,7 +2456,8 @@ compact_zone(struct compact_control *cc, struct capture_control *capc)
}
/*
* If an ASYNC or SYNC_LIGHT fails to migrate a page
- * within the current order-aligned block, scan the
+ * within the current order-aligned block and
+ * fast_find_migrateblock may be used then scan the
* remainder of the pageblock. This will mark the
* pageblock "skip" to avoid rescanning in the near
* future. This will isolate more pages than necessary
@@ -2465,7 +2466,7 @@ compact_zone(struct compact_control *cc, struct capture_control *capc)
* recently partially scanned.
*/
if (!pageblock_aligned(cc->migrate_pfn) &&
- cc->direct_compaction && !cc->finish_pageblock &&
+ !cc->ignore_skip_hint && !cc->finish_pageblock &&
(cc->mode < MIGRATE_SYNC)) {
cc->finish_pageblock = true;

--
2.35.3


2023-05-19 07:00:30

by Raghavendra K T

[permalink] [raw]
Subject: Re: [PATCH 0/4] Follow-up "Fix excessive CPU usage during compaction"

On 5/15/2023 5:03 PM, Mel Gorman wrote:
> The series "Fix excessive CPU usage during compaction" [1] attempted to
> fix a bug [2] but Vlastimil noted that the fix was incomplete [3]. While
> the series was merged, fast_find_migrateblock was still disabled. This
> series should fix the corner cases and allow 95e7a450b819 ("Revert
> "mm/compaction: fix set skip in fast_find_migrateblock"") to be safely
> reverted. Details on how many pageblocks are rescanned are in the
> changelog of the last patch.
>
> [1] https://lore.kernel.org/r/[email protected]
> [2] https://bugzilla.suse.com/show_bug.cgi?id=1206848
> [3] https://lore.kernel.org/r/[email protected]
>
> mm/compaction.c | 24 ++++++++++--------------
> 1 file changed, 10 insertions(+), 14 deletions(-)
>

Hello Mel,

Not sure how much this info would help, (also I saw it is in Andrew's
tree already) But was curious to evaluate the patchset from perf
perspective, and I have run mmtest usemem so here is the result (Only
for compact cases).

kernel configuration:
1) base 6.4.0-rc2
2) patchseries
3) base - revert of 7efc3b726103

Summary,
The result shows decent improvement from perf perspective as well as
compaction related data.

$ cat kcompact_fix_result_thp_madv

SUT : 256 cpu two node milan

usemem
6.4.0-rc2 6.4.0-rc2-compactfix
6.4.0-rc2-revert
Amean syst-1 102.18 ( 0.00%) 98.98 * 3.13%*
96.96 * 5.10%*
Amean elsp-1 220.57 ( 0.00%) 215.96 * 2.09%*
212.49 * 3.67%*
Amean syst-3 126.34 ( 0.00%) 122.39 * 3.13%*
124.09 * 1.78%*
Amean elsp-3 84.72 ( 0.00%) 81.91 * 3.31%*
82.46 * 2.66%*
Amean syst-4 142.64 ( 0.00%) 130.69 * 8.38%*
131.19 * 8.03%*
Amean elsp-4 79.48 ( 0.00%) 66.60 * 16.21%*
66.37 * 16.49%*

6.4.0-rc2 6.4.0-rc2-compactfix 6.4.0-rc2-revert
Duration User 2106.24 2065.61 2047.87
Duration System 2598.68 2464.98 2466.33
Duration Elapsed 2693.98 2551.89 2529.83

6.4.0-rc2
6.4.0-rc2-compactfix 6.4.0-rc2-revert
Ops Minor Faults 2440289187.00 2356626072.00
2354663705.00
Ops Sector Reads 556.00 1028.00
2400.00
Ops Sector Writes 20388.00 15556.00
16744.00
Ops Page migrate success 94642602.00 40234601.00
38486059.00
Ops Page migrate failure 2161.00 467.00
725.00
Ops Compaction pages isolated 116977416.00 80467188.00
76966075.00
Ops Compaction migrate scanned 136909038.00 60060978.00
60479389.00
Ops Compaction free scanned 165907615.00 95661742.00
89794809.00
Ops Compact scan efficiency 82.52 62.78
67.35
Ops Compaction cost 101419.99 43712.83
41834.25
Ops Kcompactd wake 0.00 0.00
0.00
Ops Kcompactd migrate scanned 136909038.00 60060978.00
60479389.00
Ops Kcompactd free scanned 165907615.00 95661742.00
89794809.00
Ops NUMA alloc hit 1834950351.00 1853285684.00
1867258209.00
Ops NUMA alloc miss 413982625.00 359494012.00
345537623.00
Ops NUMA alloc local 1834950349.00 1853285649.00
1867258632.00
Ops NUMA base-page range updates 202326681.00 149242271.00
147460952.00
Ops NUMA PTE updates 202326681.00 149242271.00
147460952.00
Ops NUMA hint faults 195595665.00 148152760.00
146173618.00
Ops NUMA hint local faults % 159439097.00 148150869.00
146169658.00
Ops NUMA hint local percent 81.51 100.00
100.00
Ops NUMA pages migrated 36155998.00 1454.00
3596.00
Ops AutoNUMA cost 980081.58 741808.52
731900.38

Thanks

2023-05-21 19:22:49

by Mel Gorman

[permalink] [raw]
Subject: Re: [PATCH 0/4] Follow-up "Fix excessive CPU usage during compaction"

On Fri, May 19, 2023 at 12:13:11PM +0530, Raghavendra K T wrote:
> On 5/15/2023 5:03 PM, Mel Gorman wrote:
> > The series "Fix excessive CPU usage during compaction" [1] attempted to
> > fix a bug [2] but Vlastimil noted that the fix was incomplete [3]. While
> > the series was merged, fast_find_migrateblock was still disabled. This
> > series should fix the corner cases and allow 95e7a450b819 ("Revert
> > "mm/compaction: fix set skip in fast_find_migrateblock"") to be safely
> > reverted. Details on how many pageblocks are rescanned are in the
> > changelog of the last patch.
> >
> > [1] https://lore.kernel.org/r/[email protected]
> > [2] https://bugzilla.suse.com/show_bug.cgi?id=1206848
> > [3] https://lore.kernel.org/r/[email protected]
> >
> > mm/compaction.c | 24 ++++++++++--------------
> > 1 file changed, 10 insertions(+), 14 deletions(-)
> >
>
> Hello Mel,
>
> Not sure how much this info would help, (also I saw it is in Andrew's
> tree already) But was curious to evaluate the patchset from perf
> perspective, and I have run mmtest usemem so here is the result (Only
> for compact cases).
>
> <SNIP>
>

Thanks Raghavendra!

--
Mel Gorman
SUSE Labs

2023-05-23 13:58:54

by Baolin Wang

[permalink] [raw]
Subject: Re: [PATCH 0/4] Follow-up "Fix excessive CPU usage during compaction"

Hi Mel,

On 5/15/2023 7:33 PM, Mel Gorman wrote:
> The series "Fix excessive CPU usage during compaction" [1] attempted to
> fix a bug [2] but Vlastimil noted that the fix was incomplete [3]. While
> the series was merged, fast_find_migrateblock was still disabled. This
> series should fix the corner cases and allow 95e7a450b819 ("Revert
> "mm/compaction: fix set skip in fast_find_migrateblock"") to be safely
> reverted. Details on how many pageblocks are rescanned are in the
> changelog of the last patch.
>
> [1] https://lore.kernel.org/r/[email protected]
> [2] https://bugzilla.suse.com/show_bug.cgi?id=1206848
> [3] https://lore.kernel.org/r/[email protected]

I've run this series on my machine, which can solve the regression I met
before [1], and no other issues found. So please feel free to add:
Tested-by: Baolin Wang <[email protected]>

[1]
https://lore.kernel.org/all/3576e3520c044beb2a81860aecb2d4f597089300.1682521303.git.baolin.wang@linux.alibaba.com/

>
> mm/compaction.c | 24 ++++++++++--------------
> 1 file changed, 10 insertions(+), 14 deletions(-)
>

2023-05-25 10:22:03

by Vlastimil Babka

[permalink] [raw]
Subject: Re: [PATCH 2/4] mm: compaction: Only force pageblock scan completion when skip hints are obeyed

On 5/15/23 13:33, Mel Gorman wrote:
> fast_find_migrateblock relies on skip hints to avoid rescanning a recently
> selected pageblock but compact_zone() only forces the pageblock scan
> completion to set the skip hint if in direct compaction. While this
> prevents direct compaction repeatedly scanning a subset of blocks due
> to fast_find_migrateblock(), it does not prevent proactive compaction,
> node compaction and kcompactd encountering the same problem described
> in commit cfccd2e63e7e ("mm, compaction: finish pageblocks on complete
> migration failure").
>
> Force the scan completion of a pageblock to set the skip hint if skip
> hints are obeyed to prevent fast_find_migrateblock() repeatedly selecting
> a subset of pageblocks.
>
> Suggested-by: Vlastimil Babka <[email protected]>
> Signed-off-by: Mel Gorman <[email protected]>

Acked-by: Vlastimil Babka <[email protected]>

> ---
> mm/compaction.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/mm/compaction.c b/mm/compaction.c
> index 81791c124bb8..accc6568091a 100644
> --- a/mm/compaction.c
> +++ b/mm/compaction.c
> @@ -2456,7 +2456,8 @@ compact_zone(struct compact_control *cc, struct capture_control *capc)
> }
> /*
> * If an ASYNC or SYNC_LIGHT fails to migrate a page
> - * within the current order-aligned block, scan the
> + * within the current order-aligned block and
> + * fast_find_migrateblock may be used then scan the
> * remainder of the pageblock. This will mark the
> * pageblock "skip" to avoid rescanning in the near
> * future. This will isolate more pages than necessary
> @@ -2465,7 +2466,7 @@ compact_zone(struct compact_control *cc, struct capture_control *capc)
> * recently partially scanned.
> */
> if (!pageblock_aligned(cc->migrate_pfn) &&
> - cc->direct_compaction && !cc->finish_pageblock &&
> + !cc->ignore_skip_hint && !cc->finish_pageblock &&
> (cc->mode < MIGRATE_SYNC)) {
> cc->finish_pageblock = true;
>