Skip to content

[暂不合并]chore(xsettings): add ExecStartPre to disable THP before service startup#69

Open
mhduiy wants to merge 1 commit into
linuxdeepin:masterfrom
mhduiy:thp
Open

[暂不合并]chore(xsettings): add ExecStartPre to disable THP before service startup#69
mhduiy wants to merge 1 commit into
linuxdeepin:masterfrom
mhduiy:thp

Conversation

@mhduiy
Copy link
Copy Markdown
Contributor

@mhduiy mhduiy commented May 25, 2026

  1. Added ExecStartPre=-/usr/libexec/dde-thp-disable to XSettings1 D-Bus service
  2. Ensures touchpad palm rejection (THP) is disabled before the XSettings service starts

Log: Run dde-thp-disable as ExecStartPre in XSettings1 D-Bus service

chore(xsettings): 在 XSettings 服务启动前添加 ExecStartPre 禁用 THP

  1. 在 XSettings1 D-Bus service 中添加了 ExecStartPre=-/usr/libexec/dde-thp-disable
  2. 确保在 XSettings 服务启动前禁用触摸板手掌防误触(THP)

Log: 在 XSettings1 D-Bus 服务中添加 dde-thp-disable 作为 ExecStartPre
PMS: TASK-390043

Summary by Sourcery

Enhancements:

  • Add a pre-start command to the XSettings1 D-Bus service to run dde-thp-disable before service startup.

@deepin-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: mhduiy

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

@mhduiy
Copy link
Copy Markdown
Contributor Author

mhduiy commented May 25, 2026

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented May 25, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds a pre-start step to the XSettings1 D-Bus service to run a helper that disables touchpad palm rejection (THP) before the service starts.

File-Level Changes

Change Details Files
Run dde-thp-disable as an ExecStartPre command for the XSettings1 D-Bus service so THP is disabled before XSettings starts.
  • Add ExecStartPre=-/usr/libexec/dde-thp-disable to the XSettings1 D-Bus service unit configuration
  • Ensure the pre-start helper is optional (failure-tolerant) by using the '-' prefix in ExecStartPre
src/plugin-qt/xsettings/misc/org.deepin.dde.XSettings1.service

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
Copy Markdown

@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 - 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.

@mhduiy mhduiy changed the title chore(xsettings): add ExecStartPre to disable THP before service startup [暂不合并]chore(xsettings): add ExecStartPre to disable THP before service startup May 25, 2026
1. Added ExecStartPre=-/usr/libexec/dde-thp-disable to XSettings1 D-Bus service
2. Ensures touchpad palm rejection (THP) is disabled before the XSettings service starts

Log: Run dde-thp-disable as ExecStartPre in XSettings1 D-Bus service

chore(xsettings): 在 XSettings 服务启动前添加 ExecStartPre 禁用 THP

1. 在 XSettings1 D-Bus service 中添加了 ExecStartPre=-/usr/libexec/dde-thp-disable
2. 确保在 XSettings 服务启动前禁用触摸板手掌防误触(THP)

Log: 在 XSettings1 D-Bus 服务中添加 dde-thp-disable 作为 ExecStartPre
PMS: TASK-390043
@deepin-ci-robot
Copy link
Copy Markdown

deepin pr auto review

你好!我是CodeGeeX。我已仔细审查了你提供的 Git diff 内容。

本次修改在 systemd 的 service 单元文件中添加了一行 ExecStartPre=-/usr/libexec/dde-thp-disable,意图在 XSettings1 服务启动前执行一个名为 dde-thp-disable 的脚本或程序(推测是用于禁用透明大页 THP,以避免某些特定的内存性能问题)。

以下是我从语法逻辑、代码质量、代码性能和代码安全四个维度提出的详细审查意见和改进建议:

1. 语法逻辑

  • 前缀 - 的使用(正确):在 ExecStartPre 中使用 - 前缀表示“如果该命令执行失败(返回非零退出码),则忽略错误并继续执行后续的 ExecStart”。这在某些非关键的前置准备任务中是合理的,逻辑上是正确的。
  • 潜在逻辑风险:虽然语法允许忽略错误,但你需要评估:禁用 THP 是否是强依赖? 如果 dde-thp-disable 执行失败,但主服务依然启动,是否会导致严重的性能回退或内存泄漏(这正是通常需要禁用 THP 的原因)?如果是强依赖,应该去掉 - 前缀,让服务在前置任务失败时直接启动失败。

2. 代码质量

  • 缺乏注释:systemd 配置文件通常面向系统管理员和其他开发者。直接添加一个外部脚本调用缺乏上下文。建议在上方添加注释说明为什么要在启动前禁用 THP,以及该脚本的作用。
  • 硬编码路径/usr/libexec/ 是一个相对规范的路径,但在 systemd 服务中,如果该脚本是随主服务一起安装的,更健壮的做法是使用构建系统(如 CMake/Autotools)在安装时动态替换路径变量,或者确保该路径与 Makefile/install 脚本保持绝对一致。

3. 代码性能

  • 阻塞主服务启动ExecStartPre 是同步执行的,systemd 会等待 dde-thp-disable 执行完毕后才会启动主服务。如果该脚本涉及复杂的逻辑或耗时的 I/O 操作,会直接拖慢 XSettings1 服务的启动速度。
    • 建议:确认该脚本的执行效率。如果它只是简单地向 /sys/kernel/mm/transparent_hugepage/enabled 写入 never,那么性能损耗可以忽略不计;如果它需要遍历进程或做其他耗时操作,则需要优化脚本逻辑。

4. 代码安全

  • 权限与特权:修改内核的 THP 状态(如写入 /sys/kernel/mm/transparent_hugepage/enabled)通常需要 root 权限。如果 dde-thp-disable 内部执行了需要特权的操作,而该 systemd 服务是以非 root 用户(如 User=xxx)运行的,那么该前置命令将会静默失败(虽然有 - 前缀不会阻断启动,但目的未达到)。
    • 建议:如果需要 root 权限执行,考虑在 [Service] 段添加 PermissionsStartOnly=yes(较旧的 systemd),或者使用 systemd 的系统调用规则,或者确保该服务本身以 root 身份运行。
  • 脚本安全性:确保 /usr/libexec/dde-thp-disable 具有严格的文件权限(如 0755,属主为 root:root),防止被恶意篡改。因为以服务身份执行前置命令时,如果脚本被替换,等同于提权攻击。
  • 更安全的替代方案(强烈建议评估):直接在 systemd 中调用外部脚本来修改内核参数并不是最优雅和安全的做法。更符合 Linux 标准的做法是:
    • 方案 A:通过 /tmpfiles.dsysctl.d / modprobe.d 规则来系统级地禁用 THP。
    • 方案 B:如果只是针对此服务,可以使用 systemd 的 SystemCallFilter 或直接在 ExecStartPre 中调用内核参数写入,避免引入外部不受控的脚本,例如:
      # 直接使用内置命令,无需外部脚本,更安全且无依赖
      ExecStartPre=-/bin/sh -c '/bin/echo never > /sys/kernel/mm/transparent_hugepage/enabled'

综合改进建议示例

如果你确认必须使用外部脚本来禁用 THP,且允许它失败,建议改进如下:

[Service]
Type=dbus
BusName=org.deepin.dde.XSettings1

# 禁用透明大页(THP),以避免深色模式/渲染场景下的内存性能问题 (根据实际原因修改注释)
# 忽略执行失败(-),即使禁用未成功也允许服务继续启动
ExecStartPre=-/usr/libexec/dde-thp-disable

ExecStart=/usr/bin/deepin-service-manager -n org.deepin.dde.XSettings1
Restart=on-failure
RestartSec=3

如果你确认可以直接写内核参数,且系统路径规范,建议改进如下(更安全、无外部依赖):

[Service]
Type=dbus
BusName=org.deepin.dde.XSettings1

# 直接禁用透明大页(THP),避免引入外部脚本依赖,提升安全性和可维护性
ExecStartPre=-/bin/sh -c '/usr/bin/test -f /sys/kernel/mm/transparent_hugepage/enabled && /usr/bin/echo never > /sys/kernel/mm/transparent_hugepage/enabled'

ExecStart=/usr/bin/deepin-service-manager -n org.deepin.dde.XSettings1
Restart=on-failure
RestartSec=3

希望这些审查意见对你有所帮助!如果有关于该脚本具体实现细节的代码,也可以发给我进一步审查。

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.

2 participants