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 38F1BC433EF for ; Wed, 8 Dec 2021 00:47:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 988DB6B0072; Tue, 7 Dec 2021 19:47:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9390A6B0073; Tue, 7 Dec 2021 19:47:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7B2B56B0074; Tue, 7 Dec 2021 19:47:12 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0176.hostedemail.com [216.40.44.176]) by kanga.kvack.org (Postfix) with ESMTP id 66AF46B0072 for ; Tue, 7 Dec 2021 19:47:12 -0500 (EST) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 25FF3886D5 for ; Wed, 8 Dec 2021 00:47:02 +0000 (UTC) X-FDA: 78892787484.05.383720D Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf05.hostedemail.com (Postfix) with ESMTP id 7DAEC100008 for ; Wed, 8 Dec 2021 00:47:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1638924421; 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=/bkte5kbEv7yRhaepNDkMXzUr2MX0jMtq9+W5g/aFV4=; b=STF3eHb/1SjPA1Z4ZGn4cTb6c43L85A5a6HFDs+u5DKi47ECcTP+JyFEE69o0epvBF7B7c XYOjK55/jDuaoQ9M1bdzS3UXGGlF8rECR9zRTC5e1F1LjBIC0yjdK7DNpUZl/dyHG25hKt AGRm7ZMu579JgSKgAFItwlktRjsn7Zg= Received: from mail-io1-f72.google.com (mail-io1-f72.google.com [209.85.166.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-243-9zhIHXFSNP6-NSz0qQVOvQ-1; Tue, 07 Dec 2021 19:46:59 -0500 X-MC-Unique: 9zhIHXFSNP6-NSz0qQVOvQ-1 Received: by mail-io1-f72.google.com with SMTP id d12-20020a0566022d4c00b005ebda1035b1so1192614iow.7 for ; Tue, 07 Dec 2021 16:46:59 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=/bkte5kbEv7yRhaepNDkMXzUr2MX0jMtq9+W5g/aFV4=; b=f+hw8voX592F844EPr2gTYELRbQ9tHSkvftTUt9t/bxaqz96+u76a0iWb9RF+6BcLl u3Fa7d/aKnIYLcO3vxIycgLgn2rQYFAYAQNPdBnFwNkGl1w2a7QA4+uIE962wSXL5wRe njuM3LdJqFfgHqdj9R/4Xo+alOmYl/L/pqkU6X6C58QeltdpXXVpXn/G18HHyHreMsOB xX4mMUxQb/CwlKYafM/PoLRRcs1S5eoVBOz7jrGCz/ajORtQaQ5CO8Hy+AeXpN1qTppe CgRN7nEGS3LZwguKN993LFT0oWwNazm8zCJnNwLPsDx3BdzSHjE10cs1wP7WK4QJTXcE Nmpg== X-Gm-Message-State: AOAM533EMrUfazCOoZC0hlrtAVaqzIkqvPPFa11cAcjRWXb2kJI9J0li m4Xy0W1WTAiyPQggTAUPG8x+q7+243yJpBKj0/ufRmC9Mqfi1Fop1Bd2EsUWuAqjhI/SQKpkOqI IZI7fhJRZUp4= X-Received: by 2002:a05:6638:2727:: with SMTP id m39mr54630578jav.75.1638924419029; Tue, 07 Dec 2021 16:46:59 -0800 (PST) X-Google-Smtp-Source: ABdhPJwRE5ima0X05DHObOH9ga3HGoSmZ+ZDUI+nVxZ+m9e+zZhJByt0pZmjxkyOa6fkhzywL7PG8w== X-Received: by 2002:a05:6638:2727:: with SMTP id m39mr54630561jav.75.1638924418847; Tue, 07 Dec 2021 16:46:58 -0800 (PST) Received: from ?IPV6:2601:280:4400:a2e0:7336:512c:930d:4f0e? ([2601:280:4400:a2e0:7336:512c:930d:4f0e]) by smtp.gmail.com with ESMTPSA id r12sm823873iln.72.2021.12.07.16.46.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 07 Dec 2021 16:46:58 -0800 (PST) Message-ID: Date: Tue, 7 Dec 2021 19:46:57 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.2.0 Subject: Re: [PATCH] mm/oom_kill: wake futex waiters before annihilating victim shared mutex To: Andrew Morton , Joel Savitz Cc: linux-kernel@vger.kernel.org, Waiman Long , linux-mm@kvack.org, Peter Zijlstra , Michal Hocko References: <20211207214902.772614-1-jsavitz@redhat.com> <20211207154759.3f3fe272349c77e0c4aca36f@linux-foundation.org> From: Nico Pache In-Reply-To: <20211207154759.3f3fe272349c77e0c4aca36f@linux-foundation.org> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 7DAEC100008 X-Stat-Signature: xz7powf3gkbsm7ocirinysaa4d9tedgg Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="STF3eHb/"; spf=none (imf05.hostedemail.com: domain of npache@redhat.com has no SPF policy when checking 170.10.129.124) smtp.mailfrom=npache@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-HE-Tag: 1638924421-690796 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 12/7/21 18:47, Andrew Morton wrote: > (cc's added) > > On Tue, 7 Dec 2021 16:49:02 -0500 Joel Savitz wrote: > >> 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. > > Well dang. Is there any way of killing off that waiting process, or do > we have a resource leak here? If I understood your question correctly, there is a way to recover the system by killing the process that is utilizing the futex; however, the purpose of robust futexes is to avoid having to do this. >From my work with Joel on this it seems like a race is occurring between the oom_reaper and the exit signal sent to the OMM'd process. By setting the futex_exit_release before these signals are sent we avoid this. > >> 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. > >> Co-developed-by: Nico Pache >> Signed-off-by: Nico Pache >> Signed-off-by: Joel Savitz >> --- >> mm/oom_kill.c | 3 +++ >> 1 file changed, 3 insertions(+) >> >> diff --git a/mm/oom_kill.c b/mm/oom_kill.c >> index 1ddabefcfb5a..fa58bd10a0df 100644 >> --- a/mm/oom_kill.c >> +++ b/mm/oom_kill.c >> @@ -44,6 +44,7 @@ >> #include >> #include >> #include >> +#include >> >> #include >> #include "internal.h" >> @@ -890,6 +891,7 @@ static void __oom_kill_process(struct task_struct *victim, const char *message) >> * 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 task_struct *victim, const char *message) >> */ >> 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(); >> -- >> 2.33.1 >