Skip to content

Commit aab6416

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 aab6416

File tree

10 files changed

+525
-0
lines changed

10 files changed

+525
-0
lines changed

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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/sh
2+
# postinst script for dde-session
3+
#
4+
# see: dh_installdeb(1)
5+
6+
set -e
7+
8+
case "$1" in
9+
configure)
10+
# Set CAP_SYS_RESOURCE capability on dde-oom-score-adj
11+
# This allows it to adjust oom_score_adj for monitored services
12+
if [ -x /usr/bin/dde-oom-score-adj ]; then
13+
setcap cap_sys_resource=ep /usr/bin/dde-oom-score-adj || true
14+
fi
15+
;;
16+
esac
17+
18+
exit 0

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+
}

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: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
set(BIN_NAME dde-oom-score-adj)
2+
3+
set(CMAKE_AUTOUIC ON)
4+
set(CMAKE_AUTOMOC ON)
5+
set(CMAKE_AUTORCC ON)
6+
7+
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core DBus REQUIRED)
8+
find_package(Dtk${DTK_VERSION_MAJOR} REQUIRED COMPONENTS Core)
9+
find_package(PkgConfig REQUIRED)
10+
pkg_check_modules(CAPNG REQUIRED IMPORTED_TARGET libcap-ng)
11+
12+
add_executable(${BIN_NAME}
13+
main.cpp
14+
oomscoreadjuster.h
15+
oomscoreadjuster.cpp
16+
)
17+
18+
target_link_libraries(${BIN_NAME}
19+
Qt${QT_VERSION_MAJOR}::Core
20+
Qt${QT_VERSION_MAJOR}::DBus
21+
Dtk${DTK_VERSION_MAJOR}::Core
22+
PkgConfig::CAPNG
23+
)
24+
25+
install(TARGETS ${BIN_NAME} DESTINATION bin)
26+
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: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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 <QThread>
8+
#include <QDebug>
9+
#include <cap-ng.h>
10+
#include <unistd.h>
11+
12+
int main(int argc, char *argv[])
13+
{
14+
QCoreApplication app(argc, argv);
15+
16+
// 初始化 libcap-ng
17+
capng_get_caps_process();
18+
19+
// 检查是否有 CAP_SYS_RESOURCE capability(仅用于调试信息)
20+
if (!capng_have_capability(CAPNG_EFFECTIVE, CAP_SYS_RESOURCE)) {
21+
qWarning() << "Warning: Missing CAP_SYS_RESOURCE capability!";
22+
qWarning() << "The program may not be able to modify oom_score_adj.";
23+
qWarning() << "When running as systemd service, capabilities are granted automatically.";
24+
}
25+
26+
OomScoreAdjuster adjuster;
27+
28+
// 连接退出信号
29+
QObject::connect(&adjuster, &OomScoreAdjuster::timeoutExit, &app, &QCoreApplication::quit);
30+
31+
// 在新线程中启动
32+
QThread::create([&adjuster]() {
33+
QMetaObject::invokeMethod(&adjuster, "start", Qt::QueuedConnection);
34+
})->start();
35+
36+
return app.exec();
37+
}

0 commit comments

Comments
 (0)