linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATH] Trigger OOM handler through sysrq
@ 2001-08-17  3:36 Justin A
  2001-08-17 15:51 ` Szabolcs Szakacsits
  0 siblings, 1 reply; 3+ messages in thread
From: Justin A @ 2001-08-17  3:36 UTC (permalink / raw)
  To: linux-kernel

The below patch allows you to trigger the OOM handler rather then the
generic SAK.  This may very well be the wrong way to do things, but
I'm sure someone else will know the right way to do this.  Apply this
if you want to try another way of bringing back a thrashing system.

Thanks,
-Justin

diff -urP sysrq.c.orig sysrq.c -u
--- sysrq.c.orig        Thu Aug 16 23:22:18 2001
+++ sysrq.c     Thu Aug 16 23:24:01 2001
@@ -23,6 +23,7 @@
 #include <linux/quotaops.h>
 #include <linux/smp_lock.h>
 #include <linux/module.h>
+#include <linux/swap.h>
 
 #include <asm/ptrace.h>
 
@@ -137,6 +138,11 @@
                send_sig_all(SIGKILL, 1);
                orig_log_level = 8;
                break;
+       case 'f':                                                /* F -- Free memory by invoking the oom handler */
+               printk("Free memory -- oom_kill()\n");
+               oom_kill();
+               break;
+
        default:                                            /* Unknown: help */
                if (kbd)
                        printk("unRaw ");
@@ -147,7 +153,7 @@
                printk("Boot ");
                if (sysrq_power_off)
                        printk("Off ");
-               printk("Sync Unmount showPc showTasks showMem loglevel0-8 tErm kIll killalL\n");
+               printk("Sync Unmount showPc showTasks showMem loglevel0-8 tErm kIll killalL Freemem\n");
                /* Don't use 'A' as it's handled specially on the Sparc */
        }
 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATH] Trigger OOM handler through sysrq
  2001-08-17  3:36 [PATH] Trigger OOM handler through sysrq Justin A
@ 2001-08-17 15:51 ` Szabolcs Szakacsits
  2001-08-26 16:37   ` Pavel Machek
  0 siblings, 1 reply; 3+ messages in thread
From: Szabolcs Szakacsits @ 2001-08-17 15:51 UTC (permalink / raw)
  To: Justin A; +Cc: linux-kernel


Hi Justin,

On Thu, 16 Aug 2001, Justin A wrote:
> The below patch allows you to trigger the OOM handler rather then the
> generic SAK.

Hmm, does your patch work? You can't call oom_kill() from a non-task
context because it uses schedule(). I had a similar patch for
experiments long ago but can't find it. Anyway I think this solution
fixes the symptom, not the root of the problem, especially SysRq
is disabled in many places because of security reasons ....

.... but it's true it can be lifesaver in cases ;) The patch below works
for me. For people who are interested, see
/usr/src/linux/Documentation/sysrq.txt how to enable 'Magic SysRq keys'
and after you can use ALT-SysRQ-f whenever you want to free some
memory killing a process chosen by the kernel.

	Szaka


diff -ur linux.orig/drivers/char/sysrq.c linux/drivers/char/sysrq.c
--- linux.orig/drivers/char/sysrq.c	Fri Aug 17 00:58:32 2001
+++ linux/drivers/char/sysrq.c	Fri Aug 17 22:09:31 2001
@@ -28,6 +28,7 @@

 extern void reset_vc(unsigned int);
 extern struct list_head super_blocks;
+extern int sysrq_oom;

 /* Whether we react on sysrq keys or just ignore them */
 int sysrq_enabled = 1;
@@ -137,6 +138,11 @@
 		send_sig_all(SIGKILL, 1);
 		orig_log_level = 8;
 		break;
+	case 'f':					    /* F -- call out of memory killer */
+		printk("Trying to free some memory killing a \"bad\" process\n");
+	 	sysrq_oom = 1;
+		wakeup_kswapd();
+		break;
 	default:					    /* Unknown: help */
 		if (kbd)
 			printk("unRaw ");
@@ -147,7 +153,7 @@
 		printk("Boot ");
 		if (sysrq_power_off)
 			printk("Off ");
-		printk("Sync Unmount showPc showTasks showMem loglevel0-8 tErm kIll killalL\n");
+		printk("Sync Unmount showPc showTasks showMem loglevel0-8 tErm kIll killalL Freemem\n");
 		/* Don't use 'A' as it's handled specially on the Sparc */
 	}

diff -ur linux.orig/mm/vmscan.c linux/mm/vmscan.c
--- linux.orig/mm/vmscan.c	Fri Aug 17 03:01:33 2001
+++ linux/mm/vmscan.c	Fri Aug 17 22:03:51 2001
@@ -24,6 +24,8 @@

 #include <asm/pgalloc.h>

+int sysrq_oom = 0;
+
 /*
  * The "priority" of VM scanning is how much of the queues we
  * will scan in one go. A value of 6 for DEF_PRIORITY implies
@@ -925,6 +927,12 @@

 			/* Recalculate VM statistics. */
 			recalculate_vm_stats();
+		}
+
+		if (sysrq_oom) {
+			sysrq_oom = 0;
+			oom_kill();
+			continue;
 		}

 		if (!do_try_to_free_pages(GFP_KSWAPD, 1)) {




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATH] Trigger OOM handler through sysrq
  2001-08-17 15:51 ` Szabolcs Szakacsits
@ 2001-08-26 16:37   ` Pavel Machek
  0 siblings, 0 replies; 3+ messages in thread
From: Pavel Machek @ 2001-08-26 16:37 UTC (permalink / raw)
  To: Szabolcs Szakacsits; +Cc: Justin A, linux-kernel

Hi!

> > The below patch allows you to trigger the OOM handler rather then the
> > generic SAK.
> 
> Hmm, does your patch work? You can't call oom_kill() from a non-task
> context because it uses schedule(). I had a similar patch for
> experiments long ago but can't find it. Anyway I think this solution
> fixes the symptom, not the root of the problem, especially SysRq
> is disabled in many places because of security reasons ....
> 
> .... but it's true it can be lifesaver in cases ;) The patch below works
> for me. For people who are interested, see
> /usr/src/linux/Documentation/sysrq.txt how to enable 'Magic SysRq keys'
> and after you can use ALT-SysRQ-f whenever you want to free some
> memory killing a process chosen by the kernel.

This is usefull and can be lifesaver. Can you push it to linus?

> 
> diff -ur linux.orig/drivers/char/sysrq.c linux/drivers/char/sysrq.c
> --- linux.orig/drivers/char/sysrq.c	Fri Aug 17 00:58:32 2001
> +++ linux/drivers/char/sysrq.c	Fri Aug 17 22:09:31 2001
> @@ -28,6 +28,7 @@
> 
>  extern void reset_vc(unsigned int);
>  extern struct list_head super_blocks;
> +extern int sysrq_oom;
> 
>  /* Whether we react on sysrq keys or just ignore them */
>  int sysrq_enabled = 1;
> @@ -137,6 +138,11 @@
>  		send_sig_all(SIGKILL, 1);
>  		orig_log_level = 8;
>  		break;
> +	case 'f':					    /* F -- call out of memory killer */
> +		printk("Trying to free some memory killing a \"bad\" process\n");
> +	 	sysrq_oom = 1;
> +		wakeup_kswapd();
> +		break;
>  	default:					    /* Unknown: help */
>  		if (kbd)
>  			printk("unRaw ");
> @@ -147,7 +153,7 @@
>  		printk("Boot ");
>  		if (sysrq_power_off)
>  			printk("Off ");
> -		printk("Sync Unmount showPc showTasks showMem loglevel0-8 tErm kIll killalL\n");
> +		printk("Sync Unmount showPc showTasks showMem loglevel0-8 tErm kIll killalL Freemem\n");
>  		/* Don't use 'A' as it's handled specially on the Sparc */
>  	}
> 
> diff -ur linux.orig/mm/vmscan.c linux/mm/vmscan.c
> --- linux.orig/mm/vmscan.c	Fri Aug 17 03:01:33 2001
> +++ linux/mm/vmscan.c	Fri Aug 17 22:03:51 2001
> @@ -24,6 +24,8 @@
> 
>  #include <asm/pgalloc.h>
> 
> +int sysrq_oom = 0;
> +
>  /*
>   * The "priority" of VM scanning is how much of the queues we
>   * will scan in one go. A value of 6 for DEF_PRIORITY implies
> @@ -925,6 +927,12 @@
> 
>  			/* Recalculate VM statistics. */
>  			recalculate_vm_stats();
> +		}
> +
> +		if (sysrq_oom) {
> +			sysrq_oom = 0;
> +			oom_kill();
> +			continue;
>  		}
> 
>  		if (!do_try_to_free_pages(GFP_KSWAPD, 1)) {
> 
> 
> 
> -
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/

-- 
Philips Velo 1: 1"x4"x8", 300gram, 60, 12MB, 40bogomips, linux, mutt,
details at http://atrey.karlin.mff.cuni.cz/~pavel/velo/index.html.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2001-08-30 21:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-08-17  3:36 [PATH] Trigger OOM handler through sysrq Justin A
2001-08-17 15:51 ` Szabolcs Szakacsits
2001-08-26 16:37   ` Pavel Machek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).