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=-7.0 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED 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 005F3C433E2 for ; Wed, 2 Sep 2020 08:52:55 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 99DA42078B for ; Wed, 2 Sep 2020 08:52:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 99DA42078B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ubuntu.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id EE0576B0002; Wed, 2 Sep 2020 04:52:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E68196B0003; Wed, 2 Sep 2020 04:52:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D098C6B0037; Wed, 2 Sep 2020 04:52:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0043.hostedemail.com [216.40.44.43]) by kanga.kvack.org (Postfix) with ESMTP id B36FB6B0002 for ; Wed, 2 Sep 2020 04:52:53 -0400 (EDT) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 72AAE180AD807 for ; Wed, 2 Sep 2020 08:52:53 +0000 (UTC) X-FDA: 77217506226.12.dock82_2b099d62709f Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin12.hostedemail.com (Postfix) with ESMTP id CAAF91801A4F9 for ; Wed, 2 Sep 2020 08:52:48 +0000 (UTC) X-HE-Tag: dock82_2b099d62709f X-Filterd-Recvd-Size: 4537 Received: from youngberry.canonical.com (youngberry.canonical.com [91.189.89.112]) by imf25.hostedemail.com (Postfix) with ESMTP for ; Wed, 2 Sep 2020 08:52:48 +0000 (UTC) Received: from ip5f5af70b.dynamic.kabel-deutschland.de ([95.90.247.11] helo=wittgenstein) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1kDOVB-0007sW-3b; Wed, 02 Sep 2020 08:52:21 +0000 Date: Wed, 2 Sep 2020 10:52:19 +0200 From: Christian Brauner To: Michal Hocko Cc: Suren Baghdasaryan , mingo@kernel.org, peterz@infradead.org, tglx@linutronix.de, esyr@redhat.com, christian@kellner.me, areber@redhat.com, shakeelb@google.com, cyphar@cyphar.com, oleg@redhat.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, stable@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH v3 1/1] mm, oom_adj: don't loop through tasks in __set_oom_adj when not necessary Message-ID: <20200902085219.7nvp2wml4wh2dojv@wittgenstein> References: <20200902012558.2335613-1-surenb@google.com> <20200902055302.GA6363@dhcp22.suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20200902055302.GA6363@dhcp22.suse.cz> X-Rspamd-Queue-Id: CAAF91801A4F9 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 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 Wed, Sep 02, 2020 at 07:53:02AM +0200, Michal Hocko wrote: > On Tue 01-09-20 18:25:58, Suren Baghdasaryan wrote: > > Currently __set_oom_adj loops through all processes in the system to > > keep oom_score_adj and oom_score_adj_min in sync between processes > > sharing their mm. This is done for any task with more that one mm_users, > > which includes processes with multiple threads (sharing mm and signals). > > However for such processes the loop is unnecessary because their signal > > structure is shared as well. > > Android updates oom_score_adj whenever a tasks changes its role > > (background/foreground/...) or binds to/unbinds from a service, making > > it more/less important. Such operation can happen frequently. > > We noticed that updates to oom_score_adj became more expensive and after > > further investigation found out that the patch mentioned in "Fixes" > > introduced a regression. Using Pixel 4 with a typical Android workload, > > write time to oom_score_adj increased from ~3.57us to ~362us. Moreover > > this regression linearly depends on the number of multi-threaded > > processes running on the system. > > Mark the mm with a new MMF_MULTIPROCESS flag bit when task is created with > > (CLONE_VM && !CLONE_THREAD && !CLONE_VFORK). Change __set_oom_adj to use > > MMF_MULTIPROCESS instead of mm_users to decide whether oom_score_adj > > update should be synchronized between multiple processes. To prevent > > races between clone() and __set_oom_adj(), when oom_score_adj of the > > process being cloned might be modified from userspace, we use > > oom_adj_mutex. Its scope is changed to global. The combination of > > (CLONE_VM && !CLONE_THREAD) is rarely used except for the case of vfork(). > > To prevent performance regressions of vfork(), we skip taking oom_adj_mutex > > and setting MMF_MULTIPROCESS when CLONE_VFORK is specified. Clearing the > > MMF_MULTIPROCESS 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. Should there ever be a need for optimizing that > > case as well, it can be done by hooking into the exit path, likely > > following the mm_update_next_owner pattern. > > With the combination of (CLONE_VM && !CLONE_THREAD && !CLONE_VFORK) being > > quite rare, the regression is gone after the change is applied. > > > > Fixes: 44a70adec910 ("mm, oom_adj: make sure processes sharing mm have same view of oom_score_adj") > > Reported-by: Tim Murray > > Debugged-by: Minchan Kim > > Suggested-by: Michal Hocko > > Signed-off-by: Suren Baghdasaryan > > Acked-by: Michal Hocko Acked-by: Christian Brauner