From: Suren Baghdasaryan <surenb@google.com>
To: akpm@linux-foundation.org
Cc: oleg@redhat.com, mhocko@suse.com, brauner@kernel.org,
tandersen@netflix.com, bigeasy@linutronix.de,
vincent.whitchurch@axis.com, ardb@kernel.org,
linux-kernel@vger.kernel.org,
Suren Baghdasaryan <surenb@google.com>,
Martin Liu <liumartin@google.com>,
Minchan Kim <minchan@google.com>
Subject: [PATCH 1/1] signal: on exit skip waiting for an ack from the tracer if it is frozen
Date: Fri, 28 Jun 2024 10:32:47 -0700 [thread overview]
Message-ID: <20240628173247.3507846-1-surenb@google.com> (raw)
When a process is being killed or exiting and it has a tracer, it will
notify the tracer and wait for an ack from the tracer to proceed. However
if the tracer is frozen, this ack will not arrive until the tracer gets
thawed. This poses a problem especially during memory pressure because
resources of the process are not released.
Things become even more interesting if OOM killer picks such tracee
and adds it into oom_victims. oom_victims counter will get incremented
and stay that way until tracee exits. In the meantime, if the system
tries to go into suspend, it will call oom_killer_disable() after
freezing all processes. That call will fail due to positive oom_victims,
but not until freeze_timeout_msecs passes. For the whole duration of the
freeze_timeout_msecs (20sec by default) the system will appear
unresponsive.
To fix this problem, skip the ack waiting step in the tracee when it's
exiting and the tracer is frozen. Per ptrace(2) manual, the tracer
cannot assume that the ptrace-stopped tracee exists. Therefore this
change does not break any valid assumptions.
Debugged-by: Martin Liu <liumartin@google.com>
Debugged-by: Minchan Kim <minchan@google.com>
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
---
kernel/signal.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/kernel/signal.c b/kernel/signal.c
index 1f9dd41c04be..dd9c18fdaaa5 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -2320,6 +2320,19 @@ static int ptrace_stop(int exit_code, int why, unsigned long message,
if (gstop_done && (!current->ptrace || ptrace_reparented(current)))
do_notify_parent_cldstop(current, false, why);
+ /*
+ * If tracer is frozen, it won't ack until it gets unfrozen and if the
+ * tracee is exiting this means its resources do not get freed until
+ * the tracer is thawed. Skip waiting for the tracer. Per ptrace(2)
+ * manual, the tracer cannot assume that the ptrace-stopped tracee
+ * exists, so exiting now should not be an issue.
+ */
+ if (current->ptrace && (exit_code >> 8) == PTRACE_EVENT_EXIT &&
+ cgroup_task_frozen(current->parent)) {
+ read_unlock(&tasklist_lock);
+ goto skip_wait;
+ }
+
/*
* The previous do_notify_parent_cldstop() invocation woke ptracer.
* One a PREEMPTION kernel this can result in preemption requirement
@@ -2356,6 +2369,7 @@ static int ptrace_stop(int exit_code, int why, unsigned long message,
schedule();
cgroup_leave_frozen(true);
+skip_wait:
/*
* We are back. Now reacquire the siglock before touching
* last_siginfo, so that we are sure to have synchronized with
base-commit: 6c0483dbfe7223f2b8390e3d5fe942629d3317b7
--
2.45.2.803.g4e1b14247a-goog
next reply other threads:[~2024-06-28 17:32 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-28 17:32 Suren Baghdasaryan [this message]
2024-06-29 13:12 ` [PATCH 1/1] signal: on exit skip waiting for an ack from the tracer if it is frozen Oleg Nesterov
2024-06-30 19:12 ` Suren Baghdasaryan
2024-07-03 16:48 ` Oleg Nesterov
2024-07-03 18:23 ` Suren Baghdasaryan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240628173247.3507846-1-surenb@google.com \
--to=surenb@google.com \
--cc=akpm@linux-foundation.org \
--cc=ardb@kernel.org \
--cc=bigeasy@linutronix.de \
--cc=brauner@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=liumartin@google.com \
--cc=mhocko@suse.com \
--cc=minchan@google.com \
--cc=oleg@redhat.com \
--cc=tandersen@netflix.com \
--cc=vincent.whitchurch@axis.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox