Skip to contentSkip to conversation

Patch for using /proc/<id>oom_score_adj with newer kernels

PATCH Tony Jones 2 participants 2 messages May 2, 2011 – May 9, 2011

lore
Share & tools
lore

Tony Jones

author
#0 lore raw

I'm not sure what the policy is on moderator approval for posts. AJ sent this a while ago and resent again on 4/27 (he is not subscribed, so both times the post was waiting moderator approval). Anyways, we've had this patch in our OpenSuSE version for a while.

Tony

----- Forwarded message from Andreas Jaeger <[email protected]> -----

Date: Wed, 27 Apr 2011 08:43:00 +0200
From: Andreas Jaeger <[email protected]>
To: [email protected]
Cc: Tony Jones <[email protected]>
Subject: Fwd: Patch for using /proc/<id>oom_score_adj with newer kernels
User-Agent: KMail/1.13.7 (Linux/2.6.37.6-0.0.30.67cfac5-desktop; KDE/4.6.2;

	x86_64; ; )

I send the following message some time ago but do not see it in the archives and it seems this patch is still needed, so let me resend it,

Andreas
---------- Forwarded Message ----------

Subject: Patch for using /proc/<id>oom_score_adj with newer kernels
Date: Tuesday, September 28, 2010, 09:25:02
From: Andreas Jaeger <[email protected]>
To: [email protected]

Hi,

I see in dmesg on my 2.6.36 kernel:

[   19.424535] auditd (2576): /proc/2576/oom_adj is deprecated, please use 

/proc/2576/oom_score_adj instead.

Since oom_adj is deprecated, let's use oom_score_adj.

Patch appended,

Andreas

From: [email protected]
Subject: Use oom_score_adj on newer kernels
Date: 2010-09-27

I see in dmesg on my 2.6.36 kernel:

[   19.424535] auditd (2576): /proc/2576/oom_adj is deprecated, please use 

/proc/2576/oom_score_adj instead.

Since oom_adj is deprecated, let's use oom_score_adj.

auditd.c renamed from auditd.c.orig +9 -1
Index: src/auditd.c
===================================================================
@@ -265,7 +265,15 @@ static int write_pid_file(void)
 static void avoid_oom_killer(void)
 {
 	int oomfd;
-	
+
+	/* Newer kernels (noticed in 2.6.36) */
+	oomfd =	open("/proc/self/oom_score_adj", O_NOFOLLOW | O_WRONLY);
+        if (oomfd >= 0) {
+                (void)write(oomfd, "0", 1);
+                close(oomfd);
+                return;
+        }
+	/* Older kernel */
 	oomfd = open("/proc/self/oom_adj", O_NOFOLLOW | O_WRONLY);
 	if (oomfd >= 0) {
 		(void)write(oomfd, "-17", 3);
Signature · 5 lines
 Andreas Jaeger, Program Manager openSUSE,  aj@{novell.com,opensuse.org}
  Twitter: jaegerandi | Identica: jaegerandi
   SUSE LINUX Products GmbH, GF: Markus Rex, HRB 16746 (AG Nürnberg)
    Maxfeldstr. 5, 90409 Nürnberg, Germany
     GPG fingerprint = 93A3 365E CE47 B889 DF7F  FED1 389A 563C C272 A126
#1 lore raw
Quoted 3 lines · Tony Jones

I'm not sure what the policy is on moderator approval for posts. AJ sent this a while ago and resent again on 4/27 (he is not subscribed, so both times the post was waiting moderator approval).

Anyone can CC me on a patch to make sure its gets through.

Quoted 1 line

Anyways, we've had this patch in our OpenSuSE version for a while.

Applied but with a change.

auditd.c static int write_pid_file(void) · line 272

Quoted 4 lines
auditd.c renamed from auditd.c.orig +4 -0
+	/* Newer kernels (noticed in 2.6.36) */
+	oomfd =	open("/proc/self/oom_score_adj", O_NOFOLLOW | O_WRONLY);
+        if (oomfd >= 0) {
+                (void)write(oomfd, "0", 1);

This needs to be -1000 to have the same behavior as before.

-Steve