Skip to content

Commit 722bad7

Browse files
committed
feat: add OOM score adjustment tool for critical DDE services
1. Implement dde-oom-score-adj tool to monitor and adjust OOM scores for critical DDE services 2. Add DConfig configuration for customizable service monitoring list and target score 3. Set up systemd signal monitoring to detect service startup and adjust OOM scores in real-time 4. Include automatic capability management via postinst script for CAP_SYS_RESOURCE 5. Add autostart desktop file for automatic execution during system startup 6. The tool automatically exits after 3 minutes to avoid long-running processes Log: Added OOM score adjustment feature to protect critical DDE services from being killed by the system OOM killer Influence: 1. Test that dde-oom-score-adj starts automatically during system boot 2. Verify critical DDE services (dde-session-manager, dde-session@x11) have adjusted OOM scores 3. Check that the tool exits after 3 minutes as expected 4. Test configuration changes through DConfig interface 5. Verify capability assignment works correctly during package installation 6. Monitor system logs for any OOM adjustment related errors feat: 为关键 DDE 服务添加 OOM 分数调整工具 1. 实现 dde-oom-score-adj 工具来监控和调整关键 DDE 服务的 OOM 分数 2. 添加 DConfig 配置用于可自定义的服务监控列表和目标分数 3. 设置 systemd 信号监控以实时检测服务启动并调整 OOM 分数 4. 包含通过 postinst 脚本自动管理 CAP_SYS_RESOURCE 能力 5. 添加自动启动桌面文件用于系统启动时自动执行 6. 工具在 3 分钟后自动退出,避免长时间运行的进程 Log: 新增 OOM 分数调整功能,保护关键 DDE 服务不被系统 OOM killer 终止 Influence: 1. 测试 dde-oom-score-adj 在系统启动时是否自动启动 2. 验证关键 DDE 服务(dde-session-manager, dde-session@x11)是否具有调整 后的 OOM 分数 3. 检查工具是否在 3 分钟后按预期退出 4. 通过 DConfig 接口测试配置更改 5. 验证包安装期间的能力分配是否正确工作 6. 监控系统日志中是否有 OOM 调整相关的错误
1 parent c2d4798 commit 722bad7

File tree

12 files changed

+521
-2
lines changed

12 files changed

+521
-2
lines changed

REUSE.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ SPDX-FileCopyrightText = "UnionTech Software Technology Co., Ltd."
2222
SPDX-License-Identifier = "LGPL-3.0-or-later"
2323

2424
[[annotations]]
25-
path = ["dbus/**.service", "systemd/**", "tools/**.service"]
25+
path = ["dbus/**.service", "systemd/**", "tools/**.service", "tools/**.desktop"]
2626
precedence = "aggregate"
2727
SPDX-FileCopyrightText = "UnionTech Software Technology Co., Ltd."
2828
SPDX-License-Identifier = "LGPL-3.0-or-later"

debian/control

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Maintainer: Deepin Packages Builder <[email protected]>
55
Build-Depends:
66
cmake,
77
debhelper-compat (= 11),
8+
libcap-ng-dev,
89
libdtk6core-dev,
910
libdtk6core-bin,
1011
libglib2.0-dev,

debian/postinst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/sh
2+
3+
case "$1" in
4+
configure)
5+
# Set CAP_SYS_RESOURCE capability on dde-oom-score-adj
6+
# This allows it to adjust oom_score_adj for monitored services
7+
if [ -x /usr/bin/dde-oom-score-adj ]; then
8+
setcap cap_sys_resource=ep /usr/bin/dde-oom-score-adj || true
9+
fi
10+
;;
11+
esac
12+
13+
#DEBHELPER#

misc/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,7 @@ install(
2121

2222
install(FILES ${XSESSION} DESTINATION /etc/X11/Xsession.d/)
2323
install(FILES ${PROFILE} DESTINATION /etc/profile.d)
24+
25+
# 安装 DConfig 配置文件
26+
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/dconf/org.deepin.dde.session.oom-score-adj.json
27+
DESTINATION ${CMAKE_INSTALL_DATADIR}/dsg/configs/org.deepin.dde.session)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"magic": "dsg.config.meta",
3+
"version": "1.0",
4+
"contents": {
5+
"monitorServices": {
6+
"value": ["dde-session-manager.service","[email protected]"],
7+
"serial": 0,
8+
"flags": ["global"],
9+
"name": "monitorServices",
10+
"name[zh_CN]": "OOM 分数调整监控服务列表",
11+
"description": "List of systemd services to monitor for OOM score adjustment",
12+
"permissions": "readonly",
13+
"visibility": "private"
14+
}
15+
}
16+
}

src/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
1+
# SPDX-FileCopyrightText: 2025 UnionTech Software Technology Co., Ltd.
22
#
33
# SPDX-License-Identifier: CC0-1.0
44

tools/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ add_subdirectory("dde-keyring-checker")
22
add_subdirectory("dde-version-checker")
33
add_subdirectory("dde-xsettings-checker")
44
add_subdirectory("dde-quick-login")
5+
add_subdirectory("dde-oom-score-adj")
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# SPDX-FileCopyrightText: 2025 UnionTech Software Technology Co., Ltd.
2+
#
3+
# SPDX-License-Identifier: CC0-1.0
4+
5+
set(BIN_NAME dde-oom-score-adj)
6+
7+
set(CMAKE_AUTOUIC ON)
8+
set(CMAKE_AUTOMOC ON)
9+
set(CMAKE_AUTORCC ON)
10+
11+
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core DBus REQUIRED)
12+
find_package(Dtk${DTK_VERSION_MAJOR} REQUIRED COMPONENTS Core)
13+
find_package(PkgConfig REQUIRED)
14+
pkg_check_modules(CAPNG REQUIRED IMPORTED_TARGET libcap-ng)
15+
16+
add_executable(${BIN_NAME}
17+
main.cpp
18+
oomscoreadjuster.h
19+
oomscoreadjuster.cpp
20+
)
21+
22+
target_link_libraries(${BIN_NAME}
23+
Qt${QT_VERSION_MAJOR}::Core
24+
Qt${QT_VERSION_MAJOR}::DBus
25+
Dtk${DTK_VERSION_MAJOR}::Core
26+
PkgConfig::CAPNG
27+
)
28+
29+
install(TARGETS ${BIN_NAME} DESTINATION bin)
30+
install(FILES dde-oom-score-adj.desktop DESTINATION /etc/xdg/autostart/)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[Desktop Entry]
2+
Type=Application
3+
Name=DDE OOM Score Adjuster
4+
Comment=Adjust OOM score for critical DDE services
5+
Exec=/usr/bin/dde-oom-score-adj
6+
Terminal=false
7+
NoDisplay=true

tools/dde-oom-score-adj/main.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// SPDX-FileCopyrightText: 2025 UnionTech Software Technology Co., Ltd.
2+
//
3+
// SPDX-License-Identifier: GPL-3.0-or-later
4+
5+
#include "oomscoreadjuster.h"
6+
#include <QCoreApplication>
7+
#include <QDebug>
8+
#include <cap-ng.h>
9+
#include <unistd.h>
10+
11+
int main(int argc, char *argv[])
12+
{
13+
QCoreApplication app(argc, argv);
14+
15+
// 初始化 libcap-ng
16+
capng_get_caps_process();
17+
18+
// 检查是否有 CAP_SYS_RESOURCE capability(仅用于调试信息)
19+
if (!capng_have_capability(CAPNG_EFFECTIVE, CAP_SYS_RESOURCE)) {
20+
qWarning() << "Warning: Missing CAP_SYS_RESOURCE capability!";
21+
qWarning() << "The program may not be able to modify oom_score_adj.";
22+
qWarning() << "When running as systemd service, capabilities are granted automatically.";
23+
}
24+
25+
OomScoreAdjuster adjuster;
26+
27+
// 连接退出信号
28+
QObject::connect(&adjuster, &OomScoreAdjuster::handleExit, &app, &QCoreApplication::quit);
29+
QMetaObject::invokeMethod(&adjuster, "start", Qt::QueuedConnection);
30+
31+
return app.exec();
32+
}

0 commit comments

Comments
 (0)