2 * Copyright © 2012-2013 Canonical Ltd.
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License version 3,
6 * as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 * Authored by: Thomas Voß <thomas.voss@canonical.com>
18 #ifndef CORE_POSIX_LINUX_PROC_PROCESS_OOM_ADJ_H_
19 #define CORE_POSIX_LINUX_PROC_PROCESS_OOM_ADJ_H_
21 #include <core/posix/visibility.h>
35 * This file can be used to adjust the score used to select which process
36 * should be killed in an out-of-memory (OOM) situation. The kernel uses this
37 * value for a bit-shift operation of the process's oom_score value: valid
38 * values are in the range -16 to +15, plus the special value -17, which disables
39 * OOM-killing altogether for this process. A positive score increases the
40 * likelihood of this process being killed by the OOM-killer; a negative score
41 * decreases the likelihood.
43 * The default value for this file is 0; a new process inherits its parent's
44 * oom_adj setting. A process must be privileged (CAP_SYS_RESOURCE) to update
47 * Since Linux 2.6.36, use of this file is deprecated in favor of
48 * /proc/[pid]/oom_score_adj.
50 struct CORE_POSIX_DLL_PUBLIC OomAdj
53 * @brief Returns the value that makes a process "invisible" to the oom killer.
54 * @return Returns the value that makes a process "invisible" to the oom killer.
56 static int disable_value();
59 * @brief Returns the minimum valid value.
60 * @return The minimum valid value that the OomAdj can be set to.
62 static int min_value();
65 * @brief Returns the maximum valid value.
66 * @return The maximum valid value that the OomAdj can be set to.
68 static int max_value();
71 * @brief is_valid checks whether the contained value is within the predefined bounds.
72 * @return true iff min_value() <= value <= max_value().
74 inline bool is_valid() const
76 return (disable_value() <= value) && (value <= max_value());
80 * @brief Current value.
86 * \brief Read the OomAdj value for a process instance.
87 * \throws std::runtime_error in case of errors.
88 * \param [in] process The process to read the score for.
89 * \param [out] adj The destination to store the value in.
91 CORE_POSIX_DLL_PUBLIC const posix::Process& operator>>(const posix::Process& process, OomAdj& adj);
94 * \brief Write the OomAdj value for a process instance.
95 * \throw std::runtime_error in case of errors and std::logic_error if score_adj.is_valid() returns false.
96 * \param [in] process The process to write the score for.
97 * \param [in] adj The new value to store.
99 CORE_POSIX_DLL_PUBLIC const posix::Process& operator<<(const posix::Process& process,
106 #endif // CORE_POSIX_LINUX_PROC_PROCESS_OOM_ADJ_H_