Merge lp:~unity-team/qtmir/dash-killed-less-likely into lp:qtmir

Proposed by Michał Sawicz
Status: Merged
Approved by: Gerry Boland
Approved revision: 267
Merged at revision: 272
Proposed branch: lp:~unity-team/qtmir/dash-killed-less-likely
Merge into: lp:qtmir
Diff against target: 145 lines (+83/-1)
5 files modified
src/modules/Unity/Application/processcontroller.cpp (+37/-0)
src/modules/Unity/Application/processcontroller.h (+1/-0)
src/modules/Unity/Application/taskcontroller.cpp (+8/-1)
tests/modules/ApplicationManager/application_manager_test.cpp (+36/-0)
tests/modules/common/mock_oom_controller.h (+1/-0)
To merge this branch: bzr merge lp:~unity-team/qtmir/dash-killed-less-likely
Reviewer Review Type Date Requested Status
Gerry Boland (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+237915@code.launchpad.net

Commit message

Ensure unity8-dash is less likely to be killed than other background apps.

Description of the change

 * Are there any related MPs required for this MP to build/function as expected? Please list.
N
 * Did you perform an exploratory manual test run of your code change and any related functionality?
Not yet, need to build.
 * If you changed the packaging (debian), did you subscribe the ubuntu-unity team to this MP?
N/A

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Oliver Grawert (ogra) wrote :

tested and seems to work fine, the dash is not restarted anymore no matter how many apps i open

Revision history for this message
Gerry Boland (gerboland) wrote :

LGTM

review: Approve
Revision history for this message
Gerry Boland (gerboland) wrote :

 * Did you perform an exploratory manual test run of the code change and any related functionality?
Y
 * Did CI run pass? If not, please explain why.
Fine

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/modules/Unity/Application/processcontroller.cpp'
2--- src/modules/Unity/Application/processcontroller.cpp 2014-07-18 12:14:30 +0000
3+++ src/modules/Unity/Application/processcontroller.cpp 2014-10-10 08:40:09 +0000
4@@ -115,6 +115,43 @@
5 }
6
7 /*!
8+ * \brief ProcessController::OomController::ensureProcessLessLikelyToBeKilled
9+ * \param pid
10+ * Set the process OOM-killer score so that, in a low memory situation, the process
11+ * is _more_ likely to be killed than the foreground application, but less likely
12+ * than the background applications
13+ */
14+void ProcessController::OomController::ensureProcessLessLikelyToBeKilled(pid_t pid)
15+{
16+ // Set it to 50% of the total available range.
17+ static const float defaultPercentage = 0.5;
18+
19+ core::posix::Process process(pid);
20+
21+ try {
22+ plpp::OomScoreAdj shellScore;
23+ core::posix::this_process::instance() >> shellScore;
24+
25+ plpp::OomScoreAdj processScore
26+ {
27+ static_cast<int>((plpp::OomScoreAdj::max_value() - shellScore.value) * defaultPercentage) + shellScore.value
28+ };
29+
30+ process << processScore;
31+ } catch(...) {
32+ // Accessing OomScoreAdj resulted in an exception being thrown.
33+ // Trying with the deprecated OomAdj now as a last resort.
34+ try
35+ {
36+ process << plpp::OomAdj{plpp::OomAdj::max_value()};
37+ } catch(...)
38+ {
39+ qDebug() << "ensureProcessIsLessLikelyToBeKilled failed for pid=" << pid;
40+ }
41+ }
42+}
43+
44+/*!
45 * \brief ProcessController::OomController::ensureProcessUnlikelyToBeKilled
46 * \param pid
47 * Set the process OOM-killer weighting so that the process is _less_ likely to be killed
48
49=== modified file 'src/modules/Unity/Application/processcontroller.h'
50--- src/modules/Unity/Application/processcontroller.h 2014-07-01 13:38:06 +0000
51+++ src/modules/Unity/Application/processcontroller.h 2014-10-10 08:40:09 +0000
52@@ -38,6 +38,7 @@
53 OomController& operator=(const OomController&) = delete;
54
55 virtual void ensureProcessLikelyToBeKilled(pid_t);
56+ virtual void ensureProcessLessLikelyToBeKilled(pid_t);
57 virtual void ensureProcessUnlikelyToBeKilled(pid_t);
58 };
59
60
61=== modified file 'src/modules/Unity/Application/taskcontroller.cpp'
62--- src/modules/Unity/Application/taskcontroller.cpp 2014-09-18 09:39:48 +0000
63+++ src/modules/Unity/Application/taskcontroller.cpp 2014-10-10 08:40:09 +0000
64@@ -116,7 +116,14 @@
65 if (pid == 0) {
66 pid = app->pid();
67 }
68- m_processController->oomController()->ensureProcessLikelyToBeKilled(pid);
69+
70+ // FIXME This harcodes the unity8-dash name, we should consider a different approach,
71+ // some privileged way to define which apps should be less likely to be killed.
72+ if (app->appId() == "unity8-dash") {
73+ m_processController->oomController()->ensureProcessLessLikelyToBeKilled(pid);
74+ } else {
75+ m_processController->oomController()->ensureProcessLikelyToBeKilled(pid);
76+ }
77
78 if (pid) {
79 // We do assume that the app was launched by ubuntu-app-launch and with that,
80
81=== modified file 'tests/modules/ApplicationManager/application_manager_test.cpp'
82--- tests/modules/ApplicationManager/application_manager_test.cpp 2014-10-06 11:59:39 +0000
83+++ tests/modules/ApplicationManager/application_manager_test.cpp 2014-10-10 08:40:09 +0000
84@@ -60,6 +60,7 @@
85 EXPECT_CALL(processController, sigContinueProcessGroupForPid(_)).Times(1);
86 EXPECT_CALL(oomController, ensureProcessUnlikelyToBeKilled(_)).Times(1);
87 EXPECT_CALL(oomController, ensureProcessLikelyToBeKilled(_)).Times(1);
88+ EXPECT_CALL(oomController, ensureProcessLessLikelyToBeKilled(_)).Times(0);
89
90 auto application = applicationManager.startApplication(
91 appId,
92@@ -72,6 +73,41 @@
93 QMetaObject::invokeMethod(application, "onSessionResumed");
94 }
95
96+TEST_F(ApplicationManagerTests, SuspendingAndResumingDashResultsInOomScoreAdjustment)
97+{
98+ using namespace ::testing;
99+
100+ quint64 procId = 5921;
101+ std::shared_ptr<mir::scene::Surface> aSurface(nullptr);
102+ QByteArray cmdLine( "/usr/bin/app1 --desktop_file_hint=unity8-dash");
103+
104+ EXPECT_CALL(procInfo,command_line(procId))
105+ .Times(1)
106+ .WillOnce(Return(cmdLine));
107+
108+ ON_CALL(appController,appIdHasProcessId(_,_)).WillByDefault(Return(false));
109+
110+ EXPECT_CALL(processController, sigStopProcessGroupForPid(_)).Times(1);
111+ EXPECT_CALL(processController, sigContinueProcessGroupForPid(_)).Times(1);
112+ EXPECT_CALL(oomController, ensureProcessUnlikelyToBeKilled(_)).Times(1);
113+ EXPECT_CALL(oomController, ensureProcessLikelyToBeKilled(_)).Times(0);
114+ EXPECT_CALL(oomController, ensureProcessLessLikelyToBeKilled(_)).Times(1);
115+
116+ bool authed = true;
117+
118+ std::shared_ptr<mir::scene::Session> session = std::make_shared<MockSession>("Oo", procId);
119+ applicationManager.authorizeSession(procId, authed);
120+ onSessionStarting(session);
121+
122+ auto application = applicationManager.findApplication("unity8-dash");
123+ applicationManager.onSessionCreatedSurface(session.get(), aSurface);
124+
125+ // FIXME - this is doesn't really excerise the actualt behaviour since suspend/resume should be
126+ // controlled by state changes. Requires using suspend timer.
127+ QMetaObject::invokeMethod(application, "onSessionSuspended");
128+ QMetaObject::invokeMethod(application, "onSessionResumed");
129+}
130+
131 // Currently disabled as we need to make sure that we have a corresponding mir session, too.
132 TEST_F(ApplicationManagerTests, DISABLED_FocusingRunningApplicationResultsInOomScoreAdjustment)
133 {
134
135=== modified file 'tests/modules/common/mock_oom_controller.h'
136--- tests/modules/common/mock_oom_controller.h 2014-07-01 13:38:06 +0000
137+++ tests/modules/common/mock_oom_controller.h 2014-10-10 08:40:09 +0000
138@@ -26,6 +26,7 @@
139 struct MockOomController : public qtmir::ProcessController::OomController
140 {
141 MOCK_METHOD1(ensureProcessLikelyToBeKilled, void(pid_t));
142+ MOCK_METHOD1(ensureProcessLessLikelyToBeKilled, void(pid_t));
143 MOCK_METHOD1(ensureProcessUnlikelyToBeKilled, void(pid_t));
144 };
145 }

Subscribers

People subscribed via source and target branches