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 2F5FAC433DF for ; Thu, 20 Aug 2020 10:56:19 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E164E20724 for ; Thu, 20 Aug 2020 10:56:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Tl+eqpzM" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E164E20724 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 635DC8D0007; Thu, 20 Aug 2020 06:56:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5BE548D0001; Thu, 20 Aug 2020 06:56:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4ACD88D0007; Thu, 20 Aug 2020 06:56:18 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0065.hostedemail.com [216.40.44.65]) by kanga.kvack.org (Postfix) with ESMTP id 31BA58D0001 for ; Thu, 20 Aug 2020 06:56:18 -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 ECE53362D for ; Thu, 20 Aug 2020 10:56:17 +0000 (UTC) X-FDA: 77170642794.30.vest47_2603f2827030 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin30.hostedemail.com (Postfix) with ESMTP id BE807180B3C83 for ; Thu, 20 Aug 2020 10:56:17 +0000 (UTC) X-HE-Tag: vest47_2603f2827030 X-Filterd-Recvd-Size: 4235 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by imf06.hostedemail.com (Postfix) with ESMTP for ; Thu, 20 Aug 2020 10:56:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1597920976; 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=zXZn0ptz4OdIcD8qJiz0sPtwyG4FrJg7hkfvx+FDmUI=; b=Tl+eqpzMq8xCFHLkgOHKU/ajmyruQ71vpw/yhFc0gFDjvWAzjTtIsabEyLml1rdkGe9HZt a3p1r63051d3A05sZR2vKNBOGOppwiux6+LcS3S7VK8Y99kCnDS/6x6LU5kP6OIKVValVQ +ekdk7LvGzqM3TAX/y1pP/Cml1i/hzg= 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-558-P_V1LyLiOz2MfwMupSW5mw-1; Thu, 20 Aug 2020 06:56:12 -0400 X-MC-Unique: P_V1LyLiOz2MfwMupSW5mw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 29506871803; Thu, 20 Aug 2020 10:56:07 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.40.192.73]) by smtp.corp.redhat.com (Postfix) with SMTP id 5E00C5D9F1; Thu, 20 Aug 2020 10:55:57 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Thu, 20 Aug 2020 12:56:06 +0200 (CEST) Date: Thu, 20 Aug 2020 12:55:56 +0200 From: Oleg Nesterov To: Suren Baghdasaryan Cc: mhocko@suse.com, christian.brauner@ubuntu.com, mingo@kernel.org, peterz@infradead.org, tglx@linutronix.de, esyr@redhat.com, christian@kellner.me, areber@redhat.com, shakeelb@google.com, cyphar@cyphar.com, adobriyan@gmail.com, akpm@linux-foundation.org, ebiederm@xmission.com, gladkov.alexey@gmail.com, walken@google.com, daniel.m.jordan@oracle.com, avagin@gmail.com, bernd.edlinger@hotmail.de, john.johansen@canonical.com, laoar.shao@gmail.com, timmurray@google.com, minchan@kernel.org, kernel-team@android.com, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, Michal Hocko Subject: Re: [PATCH 1/1] mm, oom_adj: don't loop through tasks in __set_oom_adj when not necessary Message-ID: <20200820105555.GA4546@redhat.com> References: <20200820002053.1424000-1-surenb@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200820002053.1424000-1-surenb@google.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Rspamd-Queue-Id: BE807180B3C83 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam02 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/19, Suren Baghdasaryan wrote: > > Since the combination of CLONE_VM and !CLONE_SIGHAND is rarely > used the additional mutex lock in that path of the clone() syscall should > not affect its overall performance. Clearing the MMF_PROC_SHARED flag > (when the last process sharing the mm exits) is left out of this patch to > keep it simple and because it is believed that this threading model is > rare. vfork() ? > --- a/kernel/fork.c > +++ b/kernel/fork.c > @@ -1403,6 +1403,15 @@ static int copy_mm(unsigned long clone_flags, struct task_struct *tsk) > if (clone_flags & CLONE_VM) { > mmget(oldmm); > mm = oldmm; > + if (!(clone_flags & CLONE_SIGHAND)) { I agree with Christian, you need CLONE_THREAD > + /* We need to synchronize with __set_oom_adj */ > + mutex_lock(&oom_adj_lock); > + set_bit(MMF_PROC_SHARED, &mm->flags); > + /* Update the values in case they were changed after copy_signal */ > + tsk->signal->oom_score_adj = current->signal->oom_score_adj; > + tsk->signal->oom_score_adj_min = current->signal->oom_score_adj_min; > + mutex_unlock(&oom_adj_lock); I don't understand how this can close the race with __set_oom_adj... What if __set_oom_adj() is called right after mutex_unlock() ? It will see MMF_PROC_SHARED, but for_each_process() won't find the new child until copy_process() does list_add_tail_rcu(&p->tasks, &init_task.tasks) ? Oleg.