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 X-Spam-Level: X-Spam-Status: No, score=-5.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8DE57C433DF for ; Fri, 21 Aug 2020 11:16:21 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 52D8B207BB for ; Fri, 21 Aug 2020 11:16:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Gu+esTfB" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 52D8B207BB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 804418D0041; Fri, 21 Aug 2020 07:16:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7B2DC8D0008; Fri, 21 Aug 2020 07:16:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 67C058D0041; Fri, 21 Aug 2020 07:16:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0071.hostedemail.com [216.40.44.71]) by kanga.kvack.org (Postfix) with ESMTP id 4EDBA8D0008 for ; Fri, 21 Aug 2020 07:16:20 -0400 (EDT) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 084E83626 for ; Fri, 21 Aug 2020 11:16:20 +0000 (UTC) X-FDA: 77174322120.30.bone90_4600e0927038 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin30.hostedemail.com (Postfix) with ESMTP id CB27A180B3C85 for ; Fri, 21 Aug 2020 11:16:19 +0000 (UTC) X-HE-Tag: bone90_4600e0927038 X-Filterd-Recvd-Size: 4618 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by imf47.hostedemail.com (Postfix) with ESMTP for ; Fri, 21 Aug 2020 11:16:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1598008578; 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: in-reply-to:in-reply-to:references:references; bh=ABDyB8/1YGeMfmJ/yBam8ctdBXagiKU/H6XOWCtsLPc=; b=Gu+esTfBWJPvyMXu3X4Glei4T8yRK6HV1+KU/dqU1ljPUbM0pdkeWGCz1+wNImwdVIHHhJ 5ebVyPvSFn4LtG+xh6T/HCLPW9seHLglppnOcOZKtpRT7Y5RGFefH1yMlnvhEdkOxvyNGX 0afCuRM1gbb+wtf3G+JoYvGvK6XTBNQ= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-386-zWW6EVJFMqGwA_lUPfjDnQ-1; Fri, 21 Aug 2020 07:16:14 -0400 X-MC-Unique: zWW6EVJFMqGwA_lUPfjDnQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 852DA18B9F01; Fri, 21 Aug 2020 11:16:10 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.40.192.73]) by smtp.corp.redhat.com (Postfix) with SMTP id B090650AC5; Fri, 21 Aug 2020 11:16:00 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Fri, 21 Aug 2020 13:16:10 +0200 (CEST) Date: Fri, 21 Aug 2020 13:15:59 +0200 From: Oleg Nesterov To: "Eric W. Biederman" Cc: Michal Hocko , Suren Baghdasaryan , Tetsuo Handa , Christian Brauner , Tim Murray , mingo@kernel.org, Peter Zijlstra , Thomas Gleixner , esyr@redhat.com, christian@kellner.me, areber@redhat.com, Shakeel Butt , cyphar@cyphar.com, adobriyan@gmail.com, Andrew Morton , gladkov.alexey@gmail.com, Michel Lespinasse , daniel.m.jordan@oracle.com, avagin@gmail.com, bernd.edlinger@hotmail.de, John Johansen , laoar.shao@gmail.com, Minchan Kim , kernel-team , LKML , linux-fsdevel@vger.kernel.org, linux-mm Subject: Re: [PATCH 1/1] mm, oom_adj: don't loop through tasks in __set_oom_adj when not necessary Message-ID: <20200821111558.GG4546@redhat.com> References: <87d03lxysr.fsf@x220.int.ebiederm.org> <20200820132631.GK5033@dhcp22.suse.cz> <20200820133454.ch24kewh42ax4ebl@wittgenstein> <20200820140054.fdkbotd4tgfrqpe6@wittgenstein> <637ab0e7-e686-0c94-753b-b97d24bb8232@i-love.sakura.ne.jp> <87k0xtv0d4.fsf@x220.int.ebiederm.org> <20200820162645.GP5033@dhcp22.suse.cz> <87r1s0txxe.fsf@x220.int.ebiederm.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87r1s0txxe.fsf@x220.int.ebiederm.org> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Rspamd-Queue-Id: CB27A180B3C85 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam01 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 08/20, Eric W. Biederman wrote: > > That said if we are going for a small change why not: > > /* > * Make sure we will check other processes sharing the mm if this is > * not vfrok which wants its own oom_score_adj. > * pin the mm so it doesn't go away and get reused after task_unlock > */ > if (!task->vfork_done) { > struct task_struct *p = find_lock_task_mm(task); > > if (p) { > - if (atomic_read(&p->mm->mm_users) > 1) { > + if (atomic_read(&p->mm->mm_users) > p->signal->nr_threads) { In theory this needs a barrier to avoid the race with do_exit(). And I'd suggest to use signal->live, I think signal->nr_threads should die... Something like bool probably_has_other_mm_users(tsk) { return atomic_read_acquire(&tsk->mm->mm_users) > atomic_read(&tsk->signal->live); } The barrier implied by _acquire ensures that if we race with the exiting task and see the result of exit_mm()->mmput(mm), then we must also see the result of atomic_dec_and_test(signal->live). Either way, if we want to fix the race with clone(CLONE_VM) we need other changes. Oleg.