From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D0811C433FE for ; Fri, 14 Jan 2022 14:58:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1985B6B0072; Fri, 14 Jan 2022 09:58:44 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 148636B0073; Fri, 14 Jan 2022 09:58:44 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F2B006B0074; Fri, 14 Jan 2022 09:58:43 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0144.hostedemail.com [216.40.44.144]) by kanga.kvack.org (Postfix) with ESMTP id E1AEC6B0072 for ; Fri, 14 Jan 2022 09:58:43 -0500 (EST) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 89712180A1D38 for ; Fri, 14 Jan 2022 14:58:43 +0000 (UTC) X-FDA: 79029199326.30.3F839F5 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf25.hostedemail.com (Postfix) with ESMTP id DFCF3A0002 for ; Fri, 14 Jan 2022 14:58:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642172322; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HOzdRMknZ5PmyxcIgplcnkj1XzKRyAcCC7j04FkTM74=; b=BJN25dskzTPhOgHdI5r+HTLcjOy82DDwNkwfp+jwr4kuXIMIsWbvpbwz8fmxSl7O/mdvU8 wLzbSsqvUci6uNELnrwgfYAeVkrh/QP2FG4tY+bUMRrsenlp3XDOKE10auUnzteTyEu3Dj rDslcMqaljNNoAIQYonZaloS6B40iwo= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-641-lLo09EyNMbe6qgC0dC3laQ-1; Fri, 14 Jan 2022 09:58:39 -0500 X-MC-Unique: lLo09EyNMbe6qgC0dC3laQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E4BD11083F66; Fri, 14 Jan 2022 14:58:36 +0000 (UTC) Received: from [10.22.33.90] (unknown [10.22.33.90]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9029B753E1; Fri, 14 Jan 2022 14:58:35 +0000 (UTC) Message-ID: Date: Fri, 14 Jan 2022 09:58:35 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.4.0 Subject: Re: [PATCH] mm/oom_kill: wake futex waiters before annihilating victim shared mutex Content-Language: en-US From: Waiman Long To: Joel Savitz , Michal Hocko Cc: Andrew Morton , linux-kernel , linux-mm@kvack.org, Nico Pache , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Darren Hart , Davidlohr Bueso , =?UTF-8?Q?Andr=c3=a9_Almeida?= References: <20211207214902.772614-1-jsavitz@redhat.com> <20211207154759.3f3fe272349c77e0c4aca36f@linux-foundation.org> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: DFCF3A0002 X-Stat-Signature: stxfc6ahzg7ak74ujosznswic1uwodcj Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=BJN25dsk; spf=none (imf25.hostedemail.com: domain of longman@redhat.com has no SPF policy when checking 170.10.129.124) smtp.mailfrom=longman@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-HE-Tag: 1642172322-924055 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 1/14/22 09:55, Waiman Long wrote: > On 1/14/22 09:39, Joel Savitz wrote: >>> What has happened to the oom victim and why it has never exited? >> What appears to happen is that the oom victim is sent SIGKILL by the >> process that triggers the oom while also being marked as an oom >> victim. >> >> As you mention in your patchset introducing the oom reaper in commit >> aac4536355496 ("mm, oom: introduce oom reaper"), the purpose the the >> oom reaper is to try and free more memory more quickly than it >> otherwise would have been by assuming anonymous or swapped out pages >> won't be needed in the exit path as the owner is already dying. >> However, this assumption is violated by the futex_cleanup() path, >> which needs access to userspace in fetch_robust_entry() when it is >> called in exit_robust_list(). Trace_printk()s in this failure path >> reveal an apparent race between the oom reaper thread reaping the >> victim's mm and the futex_cleanup() path. There may be other ways that >> this race manifests but we have been most consistently able to trace >> that one. >> >> Since in the case of an oom victim using robust futexes the core >> assumption of the oom reaper is violated, we propose to solve this >> problem by either canceling or delaying the waking of the oom reaper >> thread by wake_oom_reaper in the case that tsk->robust_list is >> non-NULL. >> >> e.g. the bug does not reproduce with this patch (from=20 >> npache@redhat.com): >> >> diff --git a/mm/oom_kill.c b/mm/oom_kill.c >> index 989f35a2bbb1..b8c518fdcf4d 100644 >> --- a/mm/oom_kill.c >> +++ b/mm/oom_kill.c >> @@ -665,6 +665,19 @@ static void wake_oom_reaper(struct task_struct=20 >> *tsk) >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (test_and_set_bit(= MMF_OOM_REAP_QUEUED,=20 >> &tsk->signal->oom_mm->flags)) >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0 return; >> >> +#ifdef CONFIG_FUTEX >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 /* >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 * don't wake the oom_reape= r thread if we still have a robust >> list to handle >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 * This will then rely on t= he sigkill to handle the cleanup=20 >> of memory >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 */ >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if(tsk->robust_list) >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 return; >> +#ifdef CONFIG_COMPAT >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if(tsk->compat_robust_list) >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 return; >> +#endif >> +#endif >> + >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 get_task_struct(tsk); >> >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 spin_lock(&oom_reaper= _lock); > > OK, that can explain why the robust futex is not properly cleaned up.=20 > Could you post a more formal v2 patch with description about the=20 > possible race condition? > It should be v3. Sorry for the mix-up. Cheers, Longman