-
Notifications
You must be signed in to change notification settings - Fork 30
feat: add OOM score adjustment tool for critical DDE services #180
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,13 @@ | ||||||||
| #!/bin/sh | ||||||||
|
|
||||||||
| case "$1" in | ||||||||
| configure) | ||||||||
| # Set CAP_SYS_RESOURCE capability on dde-oom-score-adj | ||||||||
| # This allows it to adjust oom_score_adj for monitored services | ||||||||
| if [ -x /usr/bin/dde-oom-score-adj ]; then | ||||||||
| setcap cap_sys_resource=ep /usr/bin/dde-oom-score-adj || true | ||||||||
| fi | ||||||||
|
||||||||
| fi | |
| fi | |
| #DEBHELPER# |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,16 @@ | ||||||
| { | ||||||
| "magic": "dsg.config.meta", | ||||||
| "version": "1.0", | ||||||
| "contents": { | ||||||
| "monitorServices": { | ||||||
| "value": ["dde-session-manager.service","dde-session@x11.service"], | ||||||
| "serial": 0, | ||||||
| "flags": ["global"], | ||||||
| "name": "monitorServices", | ||||||
| "name[zh_CN]": "OOM 分数调整监控服务列表", | ||||||
|
||||||
| "name[zh_CN]": "OOM 分数调整监控服务列表", | |
| "name[zh_CN]": "内存溢出(OOM)分数调整监控服务列表", |
Copilot
AI
Dec 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The permissions field is set to "readonly" which means users cannot modify the monitored services list through DConfig. However, the PR description mentions "customizable service monitoring list", which implies this should be configurable. If the intent is to make this configurable by administrators or users, change permissions to "readwrite". If it should only be modifiable by the system, consider using "readwrite" with appropriate visibility settings or clarify in the description that it's readonly by design.
| "permissions": "readonly", | |
| "permissions": "readwrite", |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| # SPDX-FileCopyrightText: 2025 UnionTech Software Technology Co., Ltd. | ||
| # | ||
| # SPDX-License-Identifier: CC0-1.0 | ||
|
|
||
| set(BIN_NAME dde-oom-score-adj) | ||
|
|
||
| set(CMAKE_AUTOUIC ON) | ||
| set(CMAKE_AUTOMOC ON) | ||
| set(CMAKE_AUTORCC ON) | ||
|
|
||
| find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core DBus REQUIRED) | ||
| find_package(Dtk${DTK_VERSION_MAJOR} REQUIRED COMPONENTS Core) | ||
| find_package(PkgConfig REQUIRED) | ||
| pkg_check_modules(CAPNG REQUIRED IMPORTED_TARGET libcap-ng) | ||
|
|
||
| add_executable(${BIN_NAME} | ||
| main.cpp | ||
| oomscoreadjuster.h | ||
| oomscoreadjuster.cpp | ||
| ) | ||
|
|
||
| target_link_libraries(${BIN_NAME} | ||
| Qt${QT_VERSION_MAJOR}::Core | ||
| Qt${QT_VERSION_MAJOR}::DBus | ||
| Dtk${DTK_VERSION_MAJOR}::Core | ||
| PkgConfig::CAPNG | ||
| ) | ||
|
|
||
| install(TARGETS ${BIN_NAME} DESTINATION bin) | ||
| install(FILES dde-oom-score-adj.desktop DESTINATION /etc/xdg/autostart/) |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,7 @@ | ||||||||||
| [Desktop Entry] | ||||||||||
| Type=Application | ||||||||||
| Name=DDE OOM Score Adjuster | ||||||||||
| Comment=Adjust OOM score for critical DDE services | ||||||||||
| Exec=/usr/bin/dde-oom-score-adj | ||||||||||
| Terminal=false | ||||||||||
| NoDisplay=true | ||||||||||
|
||||||||||
| NoDisplay=true | |
| NoDisplay=true | |
| OnlyShowIn=Deepin; | |
| X-GNOME-Autostart-enabled=true |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| // SPDX-FileCopyrightText: 2025 UnionTech Software Technology Co., Ltd. | ||
| // | ||
| // SPDX-License-Identifier: GPL-3.0-or-later | ||
|
|
||
| #include "oomscoreadjuster.h" | ||
| #include <QCoreApplication> | ||
| #include <QDebug> | ||
| #include <cap-ng.h> | ||
| #include <unistd.h> | ||
|
|
||
| int main(int argc, char *argv[]) | ||
| { | ||
| QCoreApplication app(argc, argv); | ||
|
|
||
| // 初始化 libcap-ng | ||
| capng_get_caps_process(); | ||
|
|
||
| // 检查是否有 CAP_SYS_RESOURCE capability(仅用于调试信息) | ||
| if (!capng_have_capability(CAPNG_EFFECTIVE, CAP_SYS_RESOURCE)) { | ||
| qWarning() << "Warning: Missing CAP_SYS_RESOURCE capability!"; | ||
| qWarning() << "The program may not be able to modify oom_score_adj."; | ||
| qWarning() << "When running as systemd service, capabilities are granted automatically."; | ||
| } | ||
|
Comment on lines
+18
to
+23
|
||
|
|
||
| OomScoreAdjuster adjuster; | ||
|
|
||
| // 连接退出信号 | ||
| QObject::connect(&adjuster, &OomScoreAdjuster::handleExit, &app, &QCoreApplication::quit); | ||
| QMetaObject::invokeMethod(&adjuster, "start", Qt::QueuedConnection); | ||
|
|
||
| return app.exec(); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The postinst script uses "|| true" which silently suppresses all errors from setcap, including permission errors, missing binary, or invalid capability names. This makes debugging difficult if the capability setting fails. Consider logging the failure or at minimum documenting why failures are acceptable. A better approach would be to check the return value and log a warning to help system administrators identify configuration issues.