Skip to content

Conversation

@opsiff
Copy link
Member

@opsiff opsiff commented Sep 4, 2025

We had merged
e19a3f5 mm/compaction: factor out code to test if we should run compaction for target order
in #775
So merge the whole series.

Summary by Sourcery

Merge upstream compaction fixes and cleanups from v6.7 into Deepin-Kernel-SIG/linux 6.6-y.

Enhancements:

  • Refactor reset_isolation_suitable to always invoke __reset and move the compact_blockskip_flush check into the helper
  • Enforce pageblock boundary constraints for compound pages in isolate_freepages_block to prevent overshoot
  • Switch move_freelist_head and move_freelist_tail to use buddy_list instead of the lru list
  • Expand is_via_compact_memory documentation to list all proactive compaction triggers

Kemeng Shi added 5 commits September 4, 2025 16:21
mainline inclusion
from mainline-v6.7-rc1
category: bugfix

Patch series "Fixes and cleanups to compaction", v3.

This is a series to do fix and clean up to compaction.
Patch 1-2 fix and clean up freepage list operation.
Patch 3-4 fix and clean up isolation of freepages
Patch 7 factor code to check if compaction is needed for allocation order.

More details can be found in respective patches.

This patch (of 6):

The freepage is chained with buddy_list in freelist head. Use buddy_list
instead of lru to correct the list operation.

Link: https://lkml.kernel.org/r/20230901155141.249860-1-shikemeng@huaweicloud.com
Link: https://lkml.kernel.org/r/20230901155141.249860-2-shikemeng@huaweicloud.com
Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>
Acked-by: Mel Gorman <mgorman@techsingularity.net>
Cc: David Hildenbrand <david@redhat.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
(cherry picked from commit bbefa0f)
Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
…reelist_{head}/{tail}

mainline inclusion
from mainline-v6.7-rc1
category: bugfix

We use move_freelist_head after list_for_each_entry_reverse to skip recent
pages.  And there is no need to do actual move if all freepages are
searched in list_for_each_entry_reverse, e.g.  freepage point to first
page in freelist.  It's more intuitively to call list_is_first with list
entry as the first argument and list head as the second argument to check
if list entry is the first list entry instead of call list_is_last with
list entry and list head passed in reverse.

Similarly, call list_is_last in move_freelist_tail is more intuitively.

Link: https://lkml.kernel.org/r/20230901155141.249860-3-shikemeng@huaweicloud.com
Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>
Acked-by: Mel Gorman <mgorman@techsingularity.net>
Cc: David Hildenbrand <david@redhat.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
(cherry picked from commit 4c17989)
Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
…strict mode

mainline inclusion
from mainline-v6.7-rc1
category: bugfix

In strict mode, we should return 0 if there is any hole in pageblock.  If
we successfully isolated pages at beginning at pageblock and then have a
bogus compound_order outside pageblock in next page.  We will abort search
loop with blockpfn > end_pfn.  Although we will limit blockpfn to end_pfn,
we will treat it as a successful isolation in strict mode as blockpfn is
not < end_pfn and return partial isolated pages.  Then
isolate_freepages_range may success unexpectly with hole in isolated
range.

Link: https://lkml.kernel.org/r/20230901155141.249860-4-shikemeng@huaweicloud.com
Fixes: 9fcd6d2 ("mm, compaction: skip compound pages by order in free scanner")
Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>
Acked-by: Mel Gorman <mgorman@techsingularity.net>
Cc: David Hildenbrand <david@redhat.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
(cherry picked from commit 3da0272)
Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
…solation_suitable

mainline inclusion
from mainline-v6.7-rc1
category: bugfix

We have compact_blockskip_flush check in __reset_isolation_suitable, just
remove repeat check before __reset_isolation_suitable in
compact_blockskip_flush.

Link: https://lkml.kernel.org/r/20230901155141.249860-5-shikemeng@huaweicloud.com
Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>
Acked-by: Mel Gorman <mgorman@techsingularity.net>
Cc: David Hildenbrand <david@redhat.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
(cherry picked from commit 8df4e28)
Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
mainline inclusion
from mainline-v6.7-rc1
category: bugfix

We do proactive compaction with order == -1 via
1. /proc/sys/vm/compact_memory
2. /sys/devices/system/node/nodex/compact
3. /proc/sys/vm/compaction_proactiveness
Add missed situation in which order == -1.

Link: https://lkml.kernel.org/r/20230901155141.249860-6-shikemeng@huaweicloud.com
Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>
Acked-by: Mel Gorman <mgorman@techsingularity.net>
Cc: David Hildenbrand <david@redhat.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
(cherry picked from commit 9cc17ed)
Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
@sourcery-ai
Copy link

sourcery-ai bot commented Sep 4, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Merge upstream compaction fixes and cleanups from v6.7 into the v6.6-y branch, improving isolation flush logic, enforcing pageblock boundary checks, correcting freelist operations, and expanding compaction trigger documentation.

File-Level Changes

Change Details Files
Factor out compaction flush check into __reset_isolation_suitable and simplify the caller
  • Added compact_blockskip_flush guard at the start of __reset_isolation_suitable
  • Removed redundant flush check in reset_isolation_suitable
mm/compaction.c
Enforce pageblock boundary checks in isolate_freepages_block
  • Added end_pfn boundary condition for compound pages
  • Simplified and clarified the boundary comment
mm/compaction.c
Correct freelist head/tail operations to use buddy_list
  • Replaced lru anchor with buddy_list in move_freelist_head
  • Replaced lru anchor with buddy_list in move_freelist_tail
mm/compaction.c
Expand documentation of proactive compaction triggers
  • Enumerated multiple sysfs and procfs interfaces in the is_via_compact_memory comment
mm/compaction.c

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

mainline inclusion
from mainline-v6.14-rc1
category: bugfix

syzkaller reported a UBSAN shift-out-of-bounds warning of (1UL << order)
in isolate_freepages_block().  The bogus compound_order can be any value
because it is union with flags.  Add back the MAX_PAGE_ORDER check to fix
the warning.

Link: https://lkml.kernel.org/r/20250123021029.2826736-1-liushixin2@huawei.com
Fixes: 3da0272 ("mm/compaction: correctly return failure with bogus compound_order in strict mode")
Signed-off-by: Liu Shixin <liushixin2@huawei.com>
Reviewed-by: Kemeng Shi <shikemeng@huaweicloud.com>
Acked-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Oscar Salvador <osalvador@suse.de>
Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: Kemeng Shi <shikemeng@huaweicloud.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Mel Gorman <mgorman@techsingularity.net>
Cc: Nanyong Sun <sunnanyong@huawei.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
(cherry picked from commit d1366e7)
Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
[Backport to v6.6, because MAX_PAGE_ORDER in v6.6 named MAX_ORDER]
@opsiff opsiff force-pushed the linux-6.6.y-2025-09-04-mm-compaction-fix branch from 69d3132 to 57d9a31 Compare September 4, 2025 09:44
@opsiff opsiff marked this pull request as ready for review September 4, 2025 09:44
@deepin-ci-robot
Copy link

deepin pr auto review

我对这个git diff进行了仔细审查,以下是关于代码质量、逻辑、性能和安全的改进意见:

  1. reset_isolation_suitable 函数的修改:
- if (zone->compact_blockskip_flush)
-     __reset_isolation_suitable(zone);
+ __reset_isolation_suitable(zone);
  • 改进意见:这个修改移除了条件检查,可能会对性能产生影响。建议保留原始的条件检查,因为它可以避免不必要的函数调用。只有当compact_blockskip_flush为真时才执行重置操作是合理的优化。
  1. isolate_freepages_block 函数的修改:
- if (likely(order <= MAX_ORDER)) {
+ if ((order <= MAX_ORDER) &&
+     (blockpfn + (1UL << order) <= end_pfn)) {
  • 改进意见:这个修改增加了边界检查,提高了安全性,防止内存访问越界。这是一个好的改进,但需要注意(1UL << order)可能会产生大数值,建议添加额外的溢出检查。
  1. move_freelist_headmove_freelist_tail 函数的修改:
- if (!list_is_last(freelist, &freepage->lru)) {
-     list_cut_before(&sublist, freelist, &freepage->lru);
+ if (!list_is_first(&freepage->buddy_list, freelist)) {
+     list_cut_before(&sublist, freelist, &freepage->buddy_list);
  • 改进意见:这个修改从使用lru列表改为使用buddy_list列表,这是一个重要的改进。但是,需要确保buddy_list成员在所有相关页面结构中都存在且初始化正确。建议添加适当的注释说明为什么选择buddy_list而不是lru
  1. is_via_compact_memory 函数的注释改进:
- order == -1 is expected when compacting via
- /proc/sys/vm/compact_memory
+ order == -1 is expected when compacting proactively via
+ 1. /proc/sys/vm/compact_memory
+ 2. /sys/devices/system/node/nodex/compact
+ 3. /proc/sys/vm/compaction_proactiveness
  • 改进意见:这个改进很好,增加了更详细的文档说明,使代码更易于理解和维护。建议继续保持这种详细的文档风格。

总体建议:

  1. 对于性能敏感的代码路径(如reset_isolation_suitable),建议保留原始的条件检查,避免不必要的函数调用。
  2. 对于边界检查(如isolate_freepages_block),建议添加额外的溢出检查,确保安全性。
  3. 对于数据结构的选择(如buddy_list),建议添加适当的注释说明原因,提高代码可读性。
  4. 继续保持详细的文档注释,帮助其他开发者理解代码的用途和行为。

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@lanlanxiyiji lanlanxiyiji merged commit 5d79c44 into deepin-community:linux-6.6.y Sep 25, 2025
9 of 11 checks passed
@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: lanlanxiyiji
Once this PR has been reviewed and has the lgtm label, please ask for approval from opsiff. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants