Skip to content

[linux 6.12-y] uosste feature - Add wmark-step #911

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

just-essential
Copy link

@just-essential just-essential commented Jul 1, 2025

Summary by Sourcery

Add a configurable watermark stepping mechanism to memory cgroups and the page allocator to allow fine-tuned reserve adjustments per cgroup and task context.

New Features:

  • Introduce CONFIG_WMARK_STEP option to enable watermark stepping across the kernel.
  • Expose a new memory.wmark_step cgroup file for per-cgroup watermark step configuration.
  • Add a new /sys/kernel/mm/wmark_step sysfs group with attributes for enabling the feature and tuning kthread step size.

Enhancements:

  • Propagate wmark_step values in mem_cgroup allocation and inheritance.
  • Adjust zone watermarks in __zone_watermark_ok based on wmark_step and a new ALLOC_WMARK_STEP flag.
  • Implement get_wmark_step_value helper to select the correct step value for the current task.

Build:

  • Add Kconfig entries for CONFIG_WMARK_STEP and related parameters.

Increase global watermark and watermark stepping based on request:

1. If wmark_step_enable=0, global watermark increased 80M.
2. If wmark_step_enable=1, global watermark increased 80M then
stepping based on allocation request type (1 step for decreasing 16M):
  - Maintain current watermark for ALLOC_RESERVES
  - Apply wmark-step=5 for irq (origin min wmark, highest priority)
  - Apply wmark-step=3 for kthread (can be set by sysfs)
  - Apply wmark-step=0 for process (default, can be set to 0-5)

Signed-off-by: Winston Wen <[email protected]>
Signed-off-by: Fan Jie <[email protected]>
Copy link

sourcery-ai bot commented Jul 1, 2025

Reviewer's Guide

This patch adds a configurable watermark-step mechanism that lets each memcg and the core allocator adjust zone watermark minima by a programmable step size, exposing controls via cgroup files and a sysfs group, and weaving the new ALLOC_WMARK_STEP flag into the watermark and allocation logic.

ER diagram for mem_cgroup and wmark_step sysfs/cgroup files

erDiagram
    MEM_CGROUP ||--o{ MEMORY_FILES : exposes
    MEMORY_FILES {
        string name
        int flags
        function seq_show
        function write
    }
    MEM_CGROUP {
        int swappiness
        int wmark_step
    }
    SYSFS_GROUP ||--o{ WMARK_STEP_ATTRS : contains
    WMARK_STEP_ATTRS {
        string name
        function show
        function store
    }
    SYSFS_GROUP {
        string name
        attribute[] attrs
    }
    MEM_CGROUP ||--o{ SYSFS_GROUP : has
Loading

Class diagram for mem_cgroup and wmark_step integration

classDiagram
    class mem_cgroup {
        int swappiness
        #ifdef CONFIG_WMARK_STEP
        int wmark_step
        #endif
        struct cgroup_file events_file
        struct cgroup_file events_local_file
    }

    class cgroup_subsys_state
    mem_cgroup --|> cgroup_subsys_state

    class kernfs_open_file
    class seq_file

    mem_cgroup : +memory_wmark_step_show(seq_file*, void*)
    mem_cgroup : +memory_wmark_step_write(kernfs_open_file*, char*, size_t, loff_t)
    mem_cgroup : +get_wmark_step_value()

    class kobject
    class kobj_attribute
    kobject : +wmark_step_kthread_show()
    kobject : +wmark_step_kthread_store()
    kobject : +wmark_step_enabled_show()
    kobject : +wmark_step_enabled_store()

    class attribute_group
    attribute_group : +wmark_step_attrs[]
    attribute_group : +wmark_step_attr_group

    class page_alloc
    page_alloc : +__zone_watermark_ok()
    page_alloc : +gfp_to_alloc_flags()
    page_alloc : +__setup_per_zone_wmarks()

    class internal_h
    internal_h : +ALLOC_WMARK_STEP
    internal_h : +wmark_step_enable
    internal_h : +wmark_step_max
    internal_h : +wmark_step_irq
    internal_h : +wmark_step_kthread
    internal_h : +wmark_step_default
    internal_h : +wmark_step_size
    internal_h : +get_wmark_step_value()
Loading

File-Level Changes

Change Details Files
Extend mem_cgroup to carry a wmark_step value
  • Add int wmark_step field to struct mem_cgroup
  • Inherit parent’s wmark_step or initialize default in mem_cgroup_css_alloc
  • Guard additions under CONFIG_WMARK_STEP
mm/memcontrol.c
include/linux/memcontrol.h
Expose per-cgroup wmark_step via cgroupfs
  • Implement memory_wmark_step_show sequence file
  • Implement memory_wmark_step_write with parsing and tree propagation
  • Add wmark_step entry in memory_files cftype array
mm/memcontrol.c
Provide dynamic lookup of wmark_step for current task
  • Add get_wmark_step_value() handling IRQ, kthread, disabled cases
  • Look up mem_cgroup via RCU and return its wmark_step
mm/memcontrol.c
mm/internal.h
Create sysfs group under mm_kobj for global wmark_step settings
  • Define wmark_step_enabled and wmark_step_kthread kobj_attributes
  • Assemble wmark_step_attr_group
  • Invoke sysfs_create_group in mem_cgroup_init
mm/memcontrol.c
Define and expose wmark_step parameters in the allocator
  • Declare globals wmark_step_enable, wmark_step_max, wmark_step_irq, wmark_step_kthread, wmark_step_default, wmark_step_size
  • Add externs to internal.h
mm/page_alloc.c
mm/internal.h
Integrate ALLOC_WMARK_STEP into watermark and allocation logic
  • Modify __zone_watermark_ok to subtract step reserve when ALLOC_WMARK_STEP is set
  • Introduce ALLOC_WMARK_STEP flag and add it in gfp_to_alloc_flags if enabled
  • Include wmark_step reserve in __setup_per_zone_wmarks for ZONE_NORMAL
mm/page_alloc.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

@deepin-ci-robot
Copy link

Hi @just-essential. Thanks for your PR.

I'm waiting for a deepin-community member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@deepin-ci-robot deepin-ci-robot requested a review from BLumia July 1, 2025 02:51
@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

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

Enable WMARK_STEP for arm64, x86 and longarch

Signed-off-by: Fan Jie <[email protected]>
Copy link

@Copilot Copilot AI left a comment

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 adds a configurable watermark stepping mechanism to memory cgroups and the page allocator to enable fine-tuned reserve adjustments per cgroup and task context.

  • Introduces new global watermark step parameters and a CONFIG_WMARK_STEP option.
  • Modifies allocation logic to adjust watermarks based on context (e.g., ALLOC_RESERVES vs. ALLOC_WMARK_STEP).
  • Adds a sysfs group (wmark_step) and new cgroup file to allow runtime configuration of watermark stepping.

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
mm/page_alloc.c Adds watermark step global variables and adjusts __zone_watermark_ok logic.
mm/memcontrol.c Introduces get_wmark_step_value and sysfs support for configuring watermark step.
mm/internal.h Declares watermark step symbols and ALLOC_WMARK_STEP flag.
mm/Kconfig Adds configuration option for watermark stepping.
include/linux/memcontrol.h Exposes wmark_step field within mem_cgroup.
arch//configs/_defconfig Enables CONFIG_WMARK_STEP in various architecture specific default configs.
Comments suppressed due to low confidence (3)

mm/page_alloc.c:3180

  • Consider adding a comment here to explain the fallback behavior when free pages (min) are insufficient to apply the watermark step (min <= pages_wmark_step).
		if (unlikely(min <= pages_wmark_step)) {

mm/memcontrol.c:4292

  • It would be beneficial to add a function comment for get_wmark_step_value to explain its context-specific behavior (IRQ, kthread, and process) and the rationale behind the chosen return values.
int get_wmark_step_value(void)

mm/memcontrol.c:4991

  • [nitpick] Consider adding a logging statement or more detailed documentation in this sysfs store function to clarify the behavior when an invalid wmark_step value is provided, which could aid in debugging configuration issues.
	if (value > wmark_step_max)

@Avenger-285714 Avenger-285714 merged commit 967c085 into deepin-community:linux-6.12.y Jul 2, 2025
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants