mirror of
git://sourceware.org/git/lvm2.git
synced 2025-01-18 10:04:20 +03:00
Add support for new oom killer adjustment interface (oom_score_adj).
The filename to adjust the oom score was changed in 2.6.36. We should use oom_score_adj instead of oom_adj (which is still there under /proc, but it's scheduled for removal in August 2012). New oom_score_adj uses a range from -1000 (OOM_SCORE_ADJ_MIN, disable oom killing) to 1000 (OOM_SCORE_ADJ_MAX).
This commit is contained in:
parent
6e5c1f7579
commit
7d47d109b9
@ -1,5 +1,6 @@
|
||||
Version 1.02.66 -
|
||||
===============================
|
||||
Add support for new oom killer adjustment interface (oom_score_adj).
|
||||
Add systemd unit files for dmeventd.
|
||||
Fix read-only identical table reload supression.
|
||||
|
||||
|
@ -41,11 +41,19 @@
|
||||
#ifdef linux
|
||||
# include <malloc.h>
|
||||
|
||||
# define OOM_ADJ_FILE "/proc/self/oom_adj"
|
||||
/*
|
||||
* Kernel version 2.6.36 and higher has
|
||||
* new OOM killer adjustment interface.
|
||||
*/
|
||||
# define OOM_ADJ_FILE_OLD "/proc/self/oom_adj"
|
||||
# define OOM_ADJ_FILE "/proc/self/oom_score_adj"
|
||||
|
||||
/* From linux/oom.h */
|
||||
/* Old interface */
|
||||
# define OOM_DISABLE (-17)
|
||||
# define OOM_ADJUST_MIN (-16)
|
||||
/* New interface */
|
||||
# define OOM_SCORE_ADJ_MIN (-1000)
|
||||
|
||||
#endif
|
||||
|
||||
@ -1594,34 +1602,49 @@ static void _exit_handler(int sig __attribute__((unused)))
|
||||
}
|
||||
|
||||
#ifdef linux
|
||||
/*
|
||||
* Protection against OOM killer if kernel supports it
|
||||
*/
|
||||
static int _set_oom_adj(int val)
|
||||
static int _set_oom_adj(const char *oom_adj_path, int val)
|
||||
{
|
||||
FILE *fp;
|
||||
|
||||
struct stat st;
|
||||
|
||||
if (stat(OOM_ADJ_FILE, &st) == -1) {
|
||||
if (errno == ENOENT)
|
||||
perror(OOM_ADJ_FILE " not found");
|
||||
else
|
||||
perror(OOM_ADJ_FILE ": stat failed");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!(fp = fopen(OOM_ADJ_FILE, "w"))) {
|
||||
perror(OOM_ADJ_FILE ": fopen failed");
|
||||
if (!(fp = fopen(oom_adj_path, "w"))) {
|
||||
perror("oom_adj: fopen failed");
|
||||
return 0;
|
||||
}
|
||||
|
||||
fprintf(fp, "%i", val);
|
||||
|
||||
if (dm_fclose(fp))
|
||||
perror(OOM_ADJ_FILE ": fclose failed");
|
||||
perror("oom_adj: fclose failed");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Protection against OOM killer if kernel supports it
|
||||
*/
|
||||
static int _protect_against_oom_killer()
|
||||
{
|
||||
struct stat st;
|
||||
|
||||
if (stat(OOM_ADJ_FILE, &st) == -1) {
|
||||
if (errno != ENOENT)
|
||||
perror(OOM_ADJ_FILE ": stat failed");
|
||||
|
||||
/* Try old oom_adj interface as a fallback */
|
||||
if (stat(OOM_ADJ_FILE_OLD, &st) == -1) {
|
||||
if (errno == ENOENT)
|
||||
perror(OOM_ADJ_FILE_OLD " not found");
|
||||
else
|
||||
perror(OOM_ADJ_FILE_OLD ": stat failed");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return _set_oom_adj(OOM_ADJ_FILE_OLD, OOM_DISABLE) ||
|
||||
_set_oom_adj(OOM_ADJ_FILE_OLD, OOM_ADJUST_MIN);
|
||||
}
|
||||
|
||||
return _set_oom_adj(OOM_ADJ_FILE, OOM_SCORE_ADJ_MIN);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void remove_lockfile(void)
|
||||
@ -1829,8 +1852,8 @@ int main(int argc, char *argv[])
|
||||
signal(SIGQUIT, &_exit_handler);
|
||||
|
||||
#ifdef linux
|
||||
if (!_set_oom_adj(OOM_DISABLE) && !_set_oom_adj(OOM_ADJUST_MIN))
|
||||
syslog(LOG_ERR, "Failed to set oom_adj to protect against OOM killer");
|
||||
if (!_protect_against_oom_killer())
|
||||
syslog(LOG_ERR, "Failed to protect against OOM killer");
|
||||
#endif
|
||||
|
||||
_init_thread_signals();
|
||||
|
Loading…
x
Reference in New Issue
Block a user