Skip to content

[Deepin-Kernel-SIG] [linux 6.6.y] [Upstream] zswap/list_lru: restore list_lru_add/list_lru_del for KAPI - #2030

Merged
opsiff merged 2 commits into
deepin-community:linux-6.6.yfrom
opsiff:linux-6.6.y-2026-07-30-mm-3
Jul 30, 2026
Merged

[Deepin-Kernel-SIG] [linux 6.6.y] [Upstream] zswap/list_lru: restore list_lru_add/list_lru_del for KAPI#2030
opsiff merged 2 commits into
deepin-community:linux-6.6.yfrom
opsiff:linux-6.6.y-2026-07-30-mm-3

Conversation

@opsiff

@opsiff opsiff commented Jul 30, 2026

Copy link
Copy Markdown
Member

Summary by Sourcery

Restore legacy list_lru_add/list_lru_del kernel API while introducing internal memcg-aware helpers and updating zswap to use the new interfaces.

New Features:

  • Reintroduce two-argument list_lru_add and list_lru_del symbols for out-of-tree modules relying on the legacy KAPI.

Enhancements:

  • Introduce internal __list_lru_add/__list_lru_del helpers that take nid and memcg parameters for in-tree callers like zswap.
  • Simplify list_lru_putback to use list_lru_from_memcg instead of memcg_kmem_id-based lookup.

@sourcery-ai

sourcery-ai Bot commented Jul 30, 2026

Copy link
Copy Markdown

Reviewer's Guide

Restores the legacy two-argument list_lru_add/list_lru_del kernel API for out-of-tree modules while keeping the newer memcg-aware internals, and updates zswap and list_lru internals to use new internal helpers and a simplified memcg accessor.

Sequence diagram for updated list_lru_add/list_lru_del call paths

sequenceDiagram
    actor OutOfTreeModule
    participant zswap
    participant list_lru_API
    participant list_lru_add_obj
    participant __list_lru_add
    participant list_lru_del_obj
    participant __list_lru_del

    OutOfTreeModule->>list_lru_API: list_lru_add(lru, item)
    list_lru_API->>list_lru_add_obj: list_lru_add_obj(lru, item)
    alt list_lru_memcg_aware(lru)
        list_lru_add_obj->>__list_lru_add: __list_lru_add(lru, item, nid, memcg_from_slab_obj)
    else
        list_lru_add_obj->>__list_lru_add: __list_lru_add(lru, item, nid, NULL)
    end

    OutOfTreeModule->>list_lru_API: list_lru_del(lru, item)
    list_lru_API->>list_lru_del_obj: list_lru_del_obj(lru, item)
    alt list_lru_memcg_aware(lru)
        list_lru_del_obj->>__list_lru_del: __list_lru_del(lru, item, nid, memcg_from_slab_obj)
    else
        list_lru_del_obj->>__list_lru_del: __list_lru_del(lru, item, nid, NULL)
    end

    zswap->>__list_lru_add: __list_lru_add(list_lru, entry_lru, nid, mem_cgroup_from_entry)
    zswap->>__list_lru_del: __list_lru_del(list_lru, entry_lru, nid, mem_cgroup_from_entry)
Loading

File-Level Changes

Change Details Files
Split list_lru_add/list_lru_del into internal memcg-aware helpers and public legacy KAPI wrappers.
  • Rename the existing four-argument list_lru_add implementation to __list_lru_add and update its declaration in the header.
  • Rename the existing four-argument list_lru_del implementation to __list_lru_del and update its declaration in the header.
  • Introduce new two-argument list_lru_add and list_lru_del functions that delegate to list_lru_add_obj/list_lru_del_obj to restore the old KAPI.
  • Export the new two-argument list_lru_add and list_lru_del symbols for use by out-of-tree modules.
  • Update list_lru_add_obj and list_lru_del_obj to call the new internal __list_lru_add/__list_lru_del helpers instead of the public API.
mm/list_lru.c
include/linux/list_lru.h
Adjust zswap to use the new internal memcg-aware list_lru helpers.
  • Change zswap_lru_add to call __list_lru_add with nid and memcg rather than list_lru_add.
  • Change zswap_lru_del to call __list_lru_del with nid and memcg rather than list_lru_del.
mm/zswap.c
Simplify memcg lookup in list_lru_putback by using list_lru_from_memcg.
  • Replace the use of list_lru_from_memcg_idx with memcg_kmem_id in list_lru_putback with a direct call to list_lru_from_memcg using memcg.
  • Keep putback semantics the same while aligning with the memcg-aware list_lru helpers.
mm/list_lru.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

@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 __list_lru_add/__list_lru_del are intended only for in-tree callers, consider moving their declarations out of the public list_lru.h header (or clearly marking them as internal) to avoid encouraging use by out-of-tree modules despite the leading underscores.
  • The new legacy list_lru_add/list_lru_del wrappers rely on mem_cgroup_from_slab_obj via list_lru_add_obj/list_lru_del_obj; if there are known legacy callers that expect non-slab items or different nid selection, it may be worth double-checking and documenting any behavioral differences from the old KAPI.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- If __list_lru_add/__list_lru_del are intended only for in-tree callers, consider moving their declarations out of the public list_lru.h header (or clearly marking them as internal) to avoid encouraging use by out-of-tree modules despite the leading underscores.
- The new legacy list_lru_add/list_lru_del wrappers rely on mem_cgroup_from_slab_obj via list_lru_add_obj/list_lru_del_obj; if there are known legacy callers that expect non-slab items or different nid selection, it may be worth double-checking and documenting any behavioral differences from the old KAPI.

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.

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 restores the legacy two-argument list_lru_add() / list_lru_del() KAPI for out-of-tree users while keeping in-tree callers (notably zswap) on new internal memcg-aware helpers.

Changes:

  • Introduces internal __list_lru_add() / __list_lru_del() APIs that take (nid, memcg) for in-tree callers.
  • Reintroduces legacy two-argument list_lru_add() / list_lru_del() wrappers (exported) for KAPI compatibility.
  • Updates zswap to call __list_lru_add() / __list_lru_del() and simplifies list_lru_putback() to use list_lru_from_memcg().

Reviewed changes

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

File Description
mm/zswap.c Switches zswap’s LRU operations to the new internal __list_lru_* helpers.
mm/list_lru.c Renames the internal implementations to __list_lru_* and adds legacy 2-arg exported wrappers; adjusts list_lru_putback() lookup path.
include/linux/list_lru.h Updates API declarations for __list_lru_* and re-adds 2-arg list_lru_* declarations.
Comments suppressed due to low confidence (1)

include/linux/list_lru.h:135

  • The kerneldoc comment header still says list_lru_del, but the documented prototype here is now __list_lru_del(lru, item, nid, memcg). With the new legacy 2-arg list_lru_del() declaration, this will cause kerneldoc/parameter mismatch and mis-document the API. Rename the comment header to __list_lru_del to match the documented function signature.
bool __list_lru_del(struct list_lru *lru, struct list_head *item, int nid,
		    struct mem_cgroup *memcg);
bool list_lru_del(struct list_lru *lru, struct list_head *item);


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

Comment thread include/linux/list_lru.h
Comment on lines +102 to 105
bool __list_lru_add(struct list_lru *lru, struct list_head *item, int nid,
struct mem_cgroup *memcg);
bool list_lru_add(struct list_lru *lru, struct list_head *item);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

true

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

true

done

Comment thread include/linux/list_lru.h
Comment on lines +102 to 105
bool __list_lru_add(struct list_lru *lru, struct list_head *item, int nid,
struct mem_cgroup *memcg);
bool list_lru_add(struct list_lru *lru, struct list_head *item);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

true

Comment thread include/linux/list_lru.h
* Return: true if the list was updated, false otherwise
*/
bool list_lru_del(struct list_lru *lru, struct list_head *item, int nid,
bool __list_lru_del(struct list_lru *lru, struct list_head *item, int nid,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

same as above

opsiff added 2 commits July 30, 2026 22:19
deepin inclusion
category: kapi

Commit 7a40655 ("list_lru: allow explicit memcg and NUMA node
selection") replaced the exported two-argument list_lru_add(lru, item)
/ list_lru_del(lru, item) with four-argument variants (adding @NiD and
@memcg), and renamed the old behavior to list_lru_add_obj() /
list_lru_del_obj().  All in-tree callers were updated to the _obj forms.

This silently broke the EXPORT_SYMBOL_GPL KAPI list_lru_add(lru, item)
/ list_lru_del(lru, item): out-of-tree modules built against the
pre-7a40655c4d3ae interface no longer compile (argument count mismatch).

Restore KAPI compatibility with minimal changes:

  * rename the four-argument implementations to __list_lru_add() /
    __list_lru_del() (internal, not exported);

  * reintroduce the legacy two-argument list_lru_add(lru, item) /
    list_lru_del(lru, item) as EXPORT_SYMBOL_GPL wrappers forwarding to
    list_lru_add_obj() / list_lru_del_obj(), preserving the original
    semantics.

The zswap shrinker introduced by 1d2290edafb38 ("zswap: make shrinking
memcg-aware") calls the explicit four-argument form in
zswap_lru_add()/zswap_lru_del() to pass @NiD and @memcg directly.
Update those two call sites in mm/zswap.c to use __list_lru_add()/
__list_lru_del() so they keep targeting the explicit-selection
implementation instead of the legacy two-argument wrapper.
list_lru_putback() is unaffected.

Assisted-by: atomcode:glm-5.2
Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
deepin inclusion
category: bugfix

After commit 2e60fe3 ("mm/list_lru: simplify reparenting and
initial allocation"), memcg_reparent_list_lrus() erases the dying
memcg's list_lru_memcg slot from the xarray, so list_lru_from_memcg_idx()
can return NULL for a dying memcg.  list_lru_add()/list_lru_del()
handle this via list_lru_from_memcg(), which walks up to the parent.

list_lru_putback() still used list_lru_from_memcg_idx() directly and
dereferenced the result without a NULL check.  Its only caller is the
zswap shrinker: shrink_memcg_cb() -> zswap_lru_putback() on writeback
failure, where the entry's memcg (obtained under rcu_read_lock()) may
be concurrently offlined/reparented, leading to a NULL pointer
dereference in list_add_tail().

Upstream never hit this because commit 5878303 removed the only
caller and 3f798aa removed list_lru_putback() altogether; this
branch keeps both, so switch list_lru_putback() to the same
parent-fallback lookup used by list_lru_add()/list_lru_del().

Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
@opsiff
opsiff force-pushed the linux-6.6.y-2026-07-30-mm-3 branch from 5bd67a0 to 13b0875 Compare July 30, 2026 14:19
@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

@opsiff
opsiff merged commit 0b23df8 into deepin-community:linux-6.6.y Jul 30, 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.

4 participants