Skip to content

[Deepin-Kernel-SIG] [linux 6.6.y] [Upstream] mempolicy: remove confusing MPOL_MF_LAZY dead code#1869

Merged
opsiff merged 2 commits into
deepin-community:linux-6.6.yfrom
opsiff:linux-6.6.y-2026-06-12-mempolicy
Jun 16, 2026
Merged

[Deepin-Kernel-SIG] [linux 6.6.y] [Upstream] mempolicy: remove confusing MPOL_MF_LAZY dead code#1869
opsiff merged 2 commits into
deepin-community:linux-6.6.yfrom
opsiff:linux-6.6.y-2026-06-12-mempolicy

Conversation

@opsiff

@opsiff opsiff commented Jun 16, 2026

Copy link
Copy Markdown
Member

Summary by Sourcery

Clean up mempolicy NUMA balancing code by removing dead support for the MPOL_MF_LAZY flag and clarifying that the flag is unsupported in the UAPI header.

Enhancements:

  • Remove unused MPOL_MF_LAZY handling paths in mempolicy NUMA balancing code to simplify mbind behavior and queue page walking logic.
  • Clarify in the UAPI mempolicy header that MPOL_MF_LAZY is an unsupported flag to prevent confusion for userspace.

Hugh Dickins and others added 2 commits June 16, 2026 18:23
mainline inclusion
from mainline-v6.7-rc1
category: performance

v3.8 commit b24f53a ("mm: mempolicy: Add MPOL_MF_LAZY") introduced
MPOL_MF_LAZY, and included it in the MPOL_MF_VALID flags; but a720094
("mm: mempolicy: Hide MPOL_NOOP and MPOL_MF_LAZY from userspace for now")
immediately removed it from MPOL_MF_VALID flags, pending further review.
"This will need to be revisited", but it has not been reinstated.

The present state is confusing: there is dead code in mm/mempolicy.c to
handle MPOL_MF_LAZY cases which can never occur.  Remove that: it can be
resurrected later if necessary.  But keep the definition of MPOL_MF_LAZY,
which must remain in the UAPI, even though it always fails with EINVAL.

https://lore.kernel.org/linux-mm/1553041659-46787-1-git-send-email-yang.shi@linux.alibaba.com/
links to a previous request to remove MPOL_MF_LAZY.

Link: https://lkml.kernel.org/r/80c9665c-1c3f-17ba-21a3-f6115cebf7d@google.com
Signed-off-by: Hugh Dickins <hughd@google.com>
Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: Yang Shi <shy828301@gmail.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Christoph Lameter <cl@linux.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: "Huang, Ying" <ying.huang@intel.com>
Cc: Kefeng Wang <wangkefeng.wang@huawei.com>
Cc: Mel Gorman <mgorman@techsingularity.net>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Nhat Pham <nphamcs@gmail.com>
Cc: Sidhartha Kumar <sidhartha.kumar@oracle.com>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Tejun heo <tj@kernel.org>
Cc: Vishal Moola (Oracle) <vishal.moola@gmail.com>
Cc: Yosry Ahmed <yosryahmed@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
(cherry picked from commit 2cafb58)
Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
mainline inclusion
from mainline-v6.9-rc1
category: bugfix

Commit 2cafb58 ("mempolicy: remove confusing MPOL_MF_LAZY dead code")
removes MPOL_MF_LAZY handling in queue_pages_test_walk(), and with that,
there is no effective use of the local variable endvma in that function
remaining.

Remove the local variable endvma and its dead code. No functional change.

This issue was identified with clang-analyzer's dead stores analysis.

Link: https://lkml.kernel.org/r/20240122092504.18377-1-lukas.bulwahn@gmail.com
Signed-off-by: Lukas Bulwahn <lukas.bulwahn@gmail.com>
Cc: Hugh Dickins <hughd@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
(cherry picked from commit 3efbe13)
Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
@sourcery-ai

sourcery-ai Bot commented Jun 16, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Removes dead MPOL_MF_LAZY handling and an unused NUMA balancing helper stub from the mempolicy implementation, while clarifying that the MPOL_MF_LAZY flag is unsupported in the UAPI header.

File-Level Changes

Change Details Files
Remove unused NUMA balancing helper stub when CONFIG_NUMA_BALANCING is disabled.
  • Delete the CONFIG_NUMA_BALANCING #else stub implementation of change_prot_numa that always returned 0
  • Rely solely on the CONFIG_NUMA_BALANCING-enabled implementation of change_prot_numa guarded by the existing #if
mm/mempolicy.c
Drop all in-kernel uses of the MPOL_MF_LAZY flag from mempolicy code paths.
  • Remove endvma helper variable and MPOL_MF_LAZY conditional branch from queue_pages_test_walk, eliminating the lazy NUMA protection update on VMAs
  • Remove propagation of MPOL_MF_LAZY to internal MPOL_F_MOF flag in do_mbind
  • Remove WARN_ON_ONCE check tied to MPOL_MF_LAZY when migrating pages after mbind
mm/mempolicy.c
Clarify in the UAPI that MPOL_MF_LAZY is an unsupported flag.
  • Update the MPOL_MF_LAZY macro comment to explicitly label it as an unsupported flag while keeping the numeric value unchanged
include/uapi/linux/mempolicy.h

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

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • If MPOL_MF_LAZY is now considered unsupported, consider rejecting it explicitly in do_mbind() (e.g., returning -EINVAL) rather than silently ignoring it, to avoid confusing userspace that may assume the flag has an effect.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- If MPOL_MF_LAZY is now considered unsupported, consider rejecting it explicitly in do_mbind() (e.g., returning -EINVAL) rather than silently ignoring it, to avoid confusing userspace that may assume the flag has an effect.

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.

@Avenger-285714

Copy link
Copy Markdown
Member

/approve

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Avenger-285714

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

The pull request process is described 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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR removes unreachable/dead handling for the MPOL_MF_LAZY mbind flag in mempolicy code, and updates the UAPI header comment to indicate the flag is not supported.

Changes:

  • Drop MPOL_MF_LAZY-related dead code paths in mm/mempolicy.c (queue-page walking and mbind policy flag handling).
  • Update the UAPI comment for MPOL_MF_LAZY to reduce userspace confusion.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
mm/mempolicy.c Removes unreachable MPOL_MF_LAZY logic (including an unnecessary change_prot_numa() stub and lazy handling in do_mbind()/page-walk).
include/uapi/linux/mempolicy.h Clarifies via comment that MPOL_MF_LAZY is not supported for mbind.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

to policy */
#define MPOL_MF_MOVE_ALL (1<<2) /* Move every page to conform to policy */
#define MPOL_MF_LAZY (1<<3) /* Modifies '_MOVE: lazy migrate on fault */
#define MPOL_MF_LAZY (1<<3) /* UNSUPPORTED FLAG: Lazy migrate on fault */
@opsiff opsiff merged commit 074796f into deepin-community:linux-6.6.y Jun 16, 2026
14 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants