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 C58A8C433F5 for ; Fri, 14 Jan 2022 14:55:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 25F1D6B0072; Fri, 14 Jan 2022 09:55:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 20DF46B0073; Fri, 14 Jan 2022 09:55:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0D6F86B0074; Fri, 14 Jan 2022 09:55:22 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0060.hostedemail.com [216.40.44.60]) by kanga.kvack.org (Postfix) with ESMTP id F3B406B0072 for ; Fri, 14 Jan 2022 09:55:21 -0500 (EST) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id B2ADA181E8E6B for ; Fri, 14 Jan 2022 14:55:21 +0000 (UTC) X-FDA: 79029190842.18.EF15214 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf27.hostedemail.com (Postfix) with ESMTP id 11C9840002 for ; Fri, 14 Jan 2022 14:55:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642172120; 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=ULSBCTiB85+pd++faKqH2i+l6ecH+2tEYKM+evo+AMI=; b=HdaRW0zULlQ7y01eR2ylY4eWSk0n0P7YHp/2lNZAU/FbNc1j3LHcPiBUMmnxe/bxP3EYLb hjtTxOmcHRxBdMNmfTcQW9XiPSrPUT0x4ov8PrQF26o0oo+vZnotrFbJfRI4OTG9de0cSI yPlWqQTvtQ8i4D1lZRyJPk5iOvOtEKg= 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-32-uJVMGmcoOgW_PRLrS0aanQ-1; Fri, 14 Jan 2022 09:55:19 -0500 X-MC-Unique: uJVMGmcoOgW_PRLrS0aanQ-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 80A2E801B04; Fri, 14 Jan 2022 14:55:17 +0000 (UTC) Received: from [10.22.33.90] (unknown [10.22.33.90]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6B35A753F6; Fri, 14 Jan 2022 14:55:10 +0000 (UTC) Message-ID: Date: Fri, 14 Jan 2022 09:55:10 -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 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> From: Waiman Long In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Rspamd-Queue-Id: 11C9840002 X-Stat-Signature: fzupd7tw5dz8jsgn1kwqppchoqhemmgi Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=HdaRW0zU; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf27.hostedemail.com: domain of longman@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=longman@redhat.com X-Rspamd-Server: rspam06 X-HE-Tag: 1642172120-561601 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: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 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 *tsk) > if (test_and_set_bit(MMF_OOM_REAP_QUEUED, &tsk->signal->oom_mm->flags)) > return; > > +#ifdef CONFIG_FUTEX > + /* > + * don't wake the oom_reaper thread if we still have a robust > list to handle > + * This will then rely on the sigkill to handle the cleanup of memory > + */ > + if(tsk->robust_list) > + return; > +#ifdef CONFIG_COMPAT > + if(tsk->compat_robust_list) > + return; > +#endif > +#endif > + > get_task_struct(tsk); > > spin_lock(&oom_reaper_lock); OK, that can explain why the robust futex is not properly cleaned up. Could you post a more formal v2 patch with description about the possible race condition? Cheers, Longman