Commit 7223eaa5 authored by Harald Sitter's avatar Harald Sitter 💣

fix(kded): move to kdirwatch to reduce inotify footprint

Each QFileSystemWatch claims its own inotify instance. This is
problematic because there is a default limit of 127 instances per user,
fivolously claiming instances is therefore really poor behavior.

KDirWatch meanwhile shares the same underlying instance behind the scene
so each thread would only have a single instance with N different
watches on it.

Moving to KDW effectively reduces the inotify instance footprint of the
kded module from N per Control to 0 since kded always has a kdirwatch
for ksyscoca/kservice monitoring and our KDW is backed by the same
instance.

CCBUG: 423818
parent 2ef5ddc4
......@@ -18,9 +18,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "globals.h"
#include <QFile>
#include <QFileSystemWatcher>
#include <QJsonDocument>
#include <QDir>
#include <KDirWatch>
#include <kscreen/config.h>
#include <kscreen/output.h>
......@@ -37,14 +37,15 @@ void Control::activateWatcher()
if (m_watcher) {
return;
}
m_watcher = new QFileSystemWatcher({filePath()}, this);
connect(m_watcher, &QFileSystemWatcher::fileChanged, this, [this]() {
m_watcher = new KDirWatch(this);
m_watcher->addFile(filePath());
connect(m_watcher, &KDirWatch::dirty, this, [this]() {
readFile();
Q_EMIT changed();
});
}
QFileSystemWatcher* Control::watcher() const
KDirWatch* Control::watcher() const
{
return m_watcher;
}
......
......@@ -23,7 +23,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <QVector>
#include <QVariantMap>
class QFileSystemWatcher;
class KDirWatch;
class Control : public QObject
{
......@@ -54,14 +54,14 @@ protected:
void readFile();
QVariantMap& info();
const QVariantMap& constInfo() const;
QFileSystemWatcher* watcher() const;
KDirWatch* watcher() const;
static OutputRetention convertVariantToOutputRetention(QVariant variant);
private:
static QString s_dirName;
QVariantMap m_info;
QFileSystemWatcher *m_watcher = nullptr;
KDirWatch *m_watcher = nullptr;
};
class ControlOutput;
......
......@@ -23,7 +23,7 @@ macro(ADD_KDED_TEST testname)
add_executable(${testname} ${test_SRCS})
add_dependencies(${testname} kscreen) # make sure the dbus interfaces are generated
target_compile_definitions(${testname} PRIVATE "-DTEST_DATA=\"${CMAKE_CURRENT_SOURCE_DIR}/\"")
target_link_libraries(${testname} Qt5::Test Qt5::DBus Qt5::Gui Qt5::Sensors KF5::Screen)
target_link_libraries(${testname} Qt5::Test Qt5::DBus Qt5::Gui Qt5::Sensors KF5::Screen KF5::CoreAddons)
add_test(NAME kscreen-kded-${testname} COMMAND ${testname})
ecm_mark_as_test(${testname})
endmacro()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment