Linux MM tree latest commits
 help / color / mirror / Atom feed
* + mm-oom_kill-wake-futex-waiters-before-annihilating-victim-shared-mutex.patch added to -mm tree
@ 2021-12-07 23:49 akpm
  2021-12-10  9:26 ` Michal Hocko
  0 siblings, 1 reply; 3+ messages in thread
From: akpm @ 2021-12-07 23:49 UTC (permalink / raw)
  To: jsavitz, longman, mhocko, mm-commits, npache, peterz


The patch titled
     Subject: mm/oom_kill: wake futex waiters before annihilating victim shared mutex
has been added to the -mm tree.  Its filename is
     mm-oom_kill-wake-futex-waiters-before-annihilating-victim-shared-mutex.patch

This patch should soon appear at
    https://ozlabs.org/~akpm/mmots/broken-out/mm-oom_kill-wake-futex-waiters-before-annihilating-victim-shared-mutex.patch
and later at
    https://ozlabs.org/~akpm/mmotm/broken-out/mm-oom_kill-wake-futex-waiters-before-annihilating-victim-shared-mutex.patch

Before you just go and hit "reply", please:
   a) Consider who else should be cc'ed
   b) Prefer to cc a suitable mailing list as well
   c) Ideally: find the original patch on the mailing list and do a
      reply-to-all to that, adding suitable additional cc's

*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***

The -mm tree is included into linux-next and is updated
there every 3-4 working days

------------------------------------------------------
From: Joel Savitz <jsavitz@redhat.com>
Subject: mm/oom_kill: wake futex waiters before annihilating victim shared mutex

In the case that two or more processes share a futex located within a
shared mmaped region, such as a process that shares a lock between itself
and a number of child processes, we have observed that when a process
holding the lock is oom killed, at least one waiter is never alerted to
this new development and simply continues to wait.

This is visible via pthreads by checking the __owner field of the
pthread_mutex_t structure within a waiting process, perhaps with gdb.

We identify reproduction of this issue by checking a waiting process of a
test program and viewing the contents of the pthread_mutex_t, taking note
of the value in the owner field, and then checking dmesg to see if the
owner has already been killed.

This issue can be tricky to reproduce, but with the modifications of this
small patch, I have found it to be impossible to reproduce.  There may be
additional considerations that I have not taken into account in this patch
and I welcome any comments and criticism.

Link: https://lkml.kernel.org/r/20211207214902.772614-1-jsavitz@redhat.com
Signed-off-by: Nico Pache <npache@redhat.com>
Co-developed-by: Nico Pache <npache@redhat.com>
Signed-off-by: Joel Savitz <jsavitz@redhat.com>
Cc: Waiman Long <longman@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Michal Hocko <mhocko@suse.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 mm/oom_kill.c |    3 +++
 1 file changed, 3 insertions(+)

--- a/mm/oom_kill.c~mm-oom_kill-wake-futex-waiters-before-annihilating-victim-shared-mutex
+++ a/mm/oom_kill.c
@@ -44,6 +44,7 @@
 #include <linux/kthread.h>
 #include <linux/init.h>
 #include <linux/mmu_notifier.h>
+#include <linux/futex.h>
 
 #include <asm/tlb.h>
 #include "internal.h"
@@ -890,6 +891,7 @@ static void __oom_kill_process(struct ta
 	 * in order to prevent the OOM victim from depleting the memory
 	 * reserves from the user space under its control.
 	 */
+	futex_exit_release(victim);
 	do_send_sig_info(SIGKILL, SEND_SIG_PRIV, victim, PIDTYPE_TGID);
 	mark_oom_victim(victim);
 	pr_err("%s: Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB, shmem-rss:%lukB, UID:%u pgtables:%lukB oom_score_adj:%hd\n",
@@ -930,6 +932,7 @@ static void __oom_kill_process(struct ta
 		 */
 		if (unlikely(p->flags & PF_KTHREAD))
 			continue;
+		futex_exit_release(p);
 		do_send_sig_info(SIGKILL, SEND_SIG_PRIV, p, PIDTYPE_TGID);
 	}
 	rcu_read_unlock();
_

Patches currently in -mm which might be from jsavitz@redhat.com are

mm-oom_kill-wake-futex-waiters-before-annihilating-victim-shared-mutex.patch


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

* + mm-oom_kill-wake-futex-waiters-before-annihilating-victim-shared-mutex.patch added to -mm tree
@ 2021-12-08 23:28 akpm
  0 siblings, 0 replies; 3+ messages in thread
From: akpm @ 2021-12-08 23:28 UTC (permalink / raw)
  To: andrealmeid, dave, dvhart, jsavitz, longman, mhocko, mingo,
	mm-commits, npache, peterz, tglx


The patch titled
     Subject: mm/oom_kill: wake futex waiters before annihilating victim shared mutex
has been added to the -mm tree.  Its filename is
     mm-oom_kill-wake-futex-waiters-before-annihilating-victim-shared-mutex.patch

This patch should soon appear at
    https://ozlabs.org/~akpm/mmots/broken-out/mm-oom_kill-wake-futex-waiters-before-annihilating-victim-shared-mutex.patch
and later at
    https://ozlabs.org/~akpm/mmotm/broken-out/mm-oom_kill-wake-futex-waiters-before-annihilating-victim-shared-mutex.patch

Before you just go and hit "reply", please:
   a) Consider who else should be cc'ed
   b) Prefer to cc a suitable mailing list as well
   c) Ideally: find the original patch on the mailing list and do a
      reply-to-all to that, adding suitable additional cc's

*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***

The -mm tree is included into linux-next and is updated
there every 3-4 working days

------------------------------------------------------
From: Joel Savitz <jsavitz@redhat.com>
Subject: mm/oom_kill: wake futex waiters before annihilating victim shared mutex

In the case that two or more processes share a futex located within a
shared mmaped region, such as a process that shares a lock between itself
and a number of child processes, we have observed that when a process
holding the lock is oom killed, at least one waiter is never alerted to
this new development and simply continues to wait.

This is visible via pthreads by checking the __owner field of the
pthread_mutex_t structure within a waiting process, perhaps with gdb.

We identify reproduction of this issue by checking a waiting process of a
test program and viewing the contents of the pthread_mutex_t, taking note
of the value in the owner field, and then checking dmesg to see if the
owner has already been killed.

This issue can be tricky to reproduce, but with the modifications of this
small patch, I have found it to be impossible to reproduce.  There may be
additional considerations that I have not taken into account in this patch
and I welcome any comments and criticism.

Link: https://lkml.kernel.org/r/20211208181714.880312-1-jsavitz@redhat.com
Co-developed-by: Nico Pache <npache@redhat.com>
Signed-off-by: Nico Pache <npache@redhat.com>
Signed-off-by: Joel Savitz <jsavitz@redhat.com>
Cc: Waiman Long <longman@redhat.com>
Cc: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Darren Hart <dvhart@infradead.org>
Cc: Davidlohr Bueso <dave@stgolabs.net>
Cc: Andr Almeida <andrealmeid@collabora.com>
Cc: Michal Hocko <mhocko@suse.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 mm/oom_kill.c |   12 ++++++++++++
 1 file changed, 12 insertions(+)

--- a/mm/oom_kill.c~mm-oom_kill-wake-futex-waiters-before-annihilating-victim-shared-mutex
+++ a/mm/oom_kill.c
@@ -44,6 +44,7 @@
 #include <linux/kthread.h>
 #include <linux/init.h>
 #include <linux/mmu_notifier.h>
+#include <linux/futex.h>
 
 #include <asm/tlb.h>
 #include "internal.h"
@@ -886,6 +887,11 @@ static void __oom_kill_process(struct ta
 	memcg_memory_event_mm(mm, MEMCG_OOM_KILL);
 
 	/*
+	 * We call futex_exit_release() on the victim task to ensure any waiters on any
+	 * process-shared futexes held by the victim task are woken up.
+	 */
+	futex_exit_release(victim);
+	/*
 	 * We should send SIGKILL before granting access to memory reserves
 	 * in order to prevent the OOM victim from depleting the memory
 	 * reserves from the user space under its control.
@@ -930,6 +936,12 @@ static void __oom_kill_process(struct ta
 		 */
 		if (unlikely(p->flags & PF_KTHREAD))
 			continue;
+		/*
+		 * We call futex_exit_release() on any task p sharing the
+		 * victim->mm to ensure any waiters on any
+		 * process-shared futexes held by task p are woken up.
+		 */
+		futex_exit_release(p);
 		do_send_sig_info(SIGKILL, SEND_SIG_PRIV, p, PIDTYPE_TGID);
 	}
 	rcu_read_unlock();
_

Patches currently in -mm which might be from jsavitz@redhat.com are

mm-oom_kill-wake-futex-waiters-before-annihilating-victim-shared-mutex.patch


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

* Re: + mm-oom_kill-wake-futex-waiters-before-annihilating-victim-shared-mutex.patch added to -mm tree
  2021-12-07 23:49 + mm-oom_kill-wake-futex-waiters-before-annihilating-victim-shared-mutex.patch added to -mm tree akpm
@ 2021-12-10  9:26 ` Michal Hocko
  0 siblings, 0 replies; 3+ messages in thread
From: Michal Hocko @ 2021-12-10  9:26 UTC (permalink / raw)
  To: linux-kernel; +Cc: jsavitz, longman, mm-commits, npache, peterz

Btw. I do not think this patch should be in MM until we hear from Futex
maintainers and also learn more about the underlying issue.

Thanks.

On Tue 07-12-21 15:49:24, Andrew Morton wrote:
> From: Joel Savitz <jsavitz@redhat.com>
> Subject: mm/oom_kill: wake futex waiters before annihilating victim shared mutex
> 
> In the case that two or more processes share a futex located within a
> shared mmaped region, such as a process that shares a lock between itself
> and a number of child processes, we have observed that when a process
> holding the lock is oom killed, at least one waiter is never alerted to
> this new development and simply continues to wait.
> 
> This is visible via pthreads by checking the __owner field of the
> pthread_mutex_t structure within a waiting process, perhaps with gdb.
> 
> We identify reproduction of this issue by checking a waiting process of a
> test program and viewing the contents of the pthread_mutex_t, taking note
> of the value in the owner field, and then checking dmesg to see if the
> owner has already been killed.
> 
> This issue can be tricky to reproduce, but with the modifications of this
> small patch, I have found it to be impossible to reproduce.  There may be
> additional considerations that I have not taken into account in this patch
> and I welcome any comments and criticism.
> 
> Link: https://lkml.kernel.org/r/20211207214902.772614-1-jsavitz@redhat.com
> Signed-off-by: Nico Pache <npache@redhat.com>
> Co-developed-by: Nico Pache <npache@redhat.com>
> Signed-off-by: Joel Savitz <jsavitz@redhat.com>
> Cc: Waiman Long <longman@redhat.com>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Michal Hocko <mhocko@suse.com>
> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
> ---
> 
>  mm/oom_kill.c |    3 +++
>  1 file changed, 3 insertions(+)
> 
> --- a/mm/oom_kill.c~mm-oom_kill-wake-futex-waiters-before-annihilating-victim-shared-mutex
> +++ a/mm/oom_kill.c
> @@ -44,6 +44,7 @@
>  #include <linux/kthread.h>
>  #include <linux/init.h>
>  #include <linux/mmu_notifier.h>
> +#include <linux/futex.h>
>  
>  #include <asm/tlb.h>
>  #include "internal.h"
> @@ -890,6 +891,7 @@ static void __oom_kill_process(struct ta
>  	 * in order to prevent the OOM victim from depleting the memory
>  	 * reserves from the user space under its control.
>  	 */
> +	futex_exit_release(victim);
>  	do_send_sig_info(SIGKILL, SEND_SIG_PRIV, victim, PIDTYPE_TGID);
>  	mark_oom_victim(victim);
>  	pr_err("%s: Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB, shmem-rss:%lukB, UID:%u pgtables:%lukB oom_score_adj:%hd\n",
> @@ -930,6 +932,7 @@ static void __oom_kill_process(struct ta
>  		 */
>  		if (unlikely(p->flags & PF_KTHREAD))
>  			continue;
> +		futex_exit_release(p);
>  		do_send_sig_info(SIGKILL, SEND_SIG_PRIV, p, PIDTYPE_TGID);
>  	}
>  	rcu_read_unlock();
> _
> 
> Patches currently in -mm which might be from jsavitz@redhat.com are
> 
> mm-oom_kill-wake-futex-waiters-before-annihilating-victim-shared-mutex.patch

-- 
Michal Hocko
SUSE Labs

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

end of thread, other threads:[~2021-12-10  9:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-12-07 23:49 + mm-oom_kill-wake-futex-waiters-before-annihilating-victim-shared-mutex.patch added to -mm tree akpm
2021-12-10  9:26 ` Michal Hocko
  -- strict thread matches above, loose matches on Subject: below --
2021-12-08 23:28 akpm

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox