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 1AE52D2AB24 for ; Tue, 29 Oct 2024 11:52:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8B45D6B009D; Tue, 29 Oct 2024 07:52:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 863C66B009E; Tue, 29 Oct 2024 07:52:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 72AF16B009F; Tue, 29 Oct 2024 07:52:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 55D4C6B009D for ; Tue, 29 Oct 2024 07:52:40 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 114A9120E11 for ; Tue, 29 Oct 2024 11:52:40 +0000 (UTC) X-FDA: 82726476756.06.9F7269F Received: from mail-ed1-f51.google.com (mail-ed1-f51.google.com [209.85.208.51]) by imf04.hostedemail.com (Postfix) with ESMTP id 4C4DA40008 for ; Tue, 29 Oct 2024 11:52:06 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf04.hostedemail.com: domain of breno.debian@gmail.com designates 209.85.208.51 as permitted sender) smtp.mailfrom=breno.debian@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1730202583; h=from:from:sender: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: in-reply-to:in-reply-to:references:references; bh=Ai+cIbtgQ7yQvilNgvPeFEHFRDsKY7CEjZmgbBMDi18=; b=pg1nMrX/xdADzXav+7ESPjJNr+bSE5dp0NvZ6OeIRoBLbwg0mcOttZodIRignZClNIzStm nXxWUaWreLdX090WiOA6aeeF2kvRnyPzl64PInxF4P2CShsHw+foBNa0zLbiHTYyEV9FA6 HGSFJT0FO28oblWY4h/Fs9gORJi8Vic= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730202583; a=rsa-sha256; cv=none; b=sptcRtJihZ4g2UwrI2+FZ6NXUHz49SA/OqgBuxJocFZi2M3TsZ7z+mZe4U7j38keC4v7nX rKAmyJFbtX5DHUiWSRTo9tXjLPgkVQRfaES7YZ96r6wuF5C27zeg0g4etuVsivBYq5/qa/ 2diHDPNWvnw7vVTySpj+iQV6laCiWE0= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf04.hostedemail.com: domain of breno.debian@gmail.com designates 209.85.208.51 as permitted sender) smtp.mailfrom=breno.debian@gmail.com Received: by mail-ed1-f51.google.com with SMTP id 4fb4d7f45d1cf-5cb6704ff6bso7022710a12.3 for ; Tue, 29 Oct 2024 04:52:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730202756; x=1730807556; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Ai+cIbtgQ7yQvilNgvPeFEHFRDsKY7CEjZmgbBMDi18=; b=pCLmp6Xt0taJxgf5ySzjXtgce9WmJbRL6Uet7c4FptfpbQzH9WlJKn8xI1hyHGTtFN T5+2k8jC9PIBv6q72hO+vB4Z8sVYMaZlBuTznxu7MpJt18Gl/WMPNE1ZB4QtRXvsdiBo rVA9cK6KIT+Ig2Gm/liPil08OKvygAo0GK0QfXYSu4BYUocqXxo95bqnGKDaIcn3+tJO LfIrX0UeGO1MFr2ejw2dEH+RzRE6gOVxLzwbTGIdR2jzlFrtN2JVWYiWNb6Da2XV9UMd doG1Y/LrazL/SfFvKKe8FH3l0VjoIfYb7ZqqEPDYJtuBPz/WgfJrOnXon0ge1PsoQSg1 mTuQ== X-Forwarded-Encrypted: i=1; AJvYcCUnOdoIqHesX8mesDZBw/jF5+mfj8zE5FIcM7/XvmeKkaIZ0ixpXtbZW8BVPeW72WE+pKqm6gn6qw==@kvack.org X-Gm-Message-State: AOJu0YzNpZAEAujH1Ps1Z2Z/8ea5jx7j2HCwYQ+23+b9MpREjZuyXLig e2KW4mZ800AznfumON+u4/DbZButmGFFR4On2w6rQm68OcYQwKpM X-Google-Smtp-Source: AGHT+IFUCCQnzXhPIYVaEn9VnvmByYgfDRscXsGuypBsXwD6UWBZW4TAVB5CRwK82jxXmRGrIEG2UA== X-Received: by 2002:a17:907:3f23:b0:a8a:8d81:97ac with SMTP id a640c23a62f3a-a9de5c9f5f9mr1070376566b.4.1730202755736; Tue, 29 Oct 2024 04:52:35 -0700 (PDT) Received: from gmail.com (fwdproxy-lla-000.fbsv.net. [2a03:2880:30ff::face:b00c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9b1dec7b90sm466962966b.28.2024.10.29.04.52.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Oct 2024 04:52:35 -0700 (PDT) Date: Tue, 29 Oct 2024 04:52:32 -0700 From: Breno Leitao To: Lorenzo Stoakes , Liam.Howlett@oracle.com Cc: Andrew Morton , "Liam R. Howlett" , Vlastimil Babka , kernel-team@meta.com, "open list:VMA" , open list Subject: Re: [PATCH] mm: Remove misleading 'unlikely' hint in vms_gather_munmap_vmas() Message-ID: <20241029-discerning-outstanding-badger-6376bd@leitao> References: <20241004164832.218681-1-leitao@debian.org> <71b7cbeb-1301-491c-9637-e6d48938ddaf@lucifer.local> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <71b7cbeb-1301-491c-9637-e6d48938ddaf@lucifer.local> X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 4C4DA40008 X-Stat-Signature: c9qbe574ckkb65yxn5m5hrtxndauwnbq X-Rspam-User: X-HE-Tag: 1730202726-922130 X-HE-Meta: U2FsdGVkX180cElZNqz0trcwKN9+LXrBIddpxTqHNuu6mzt9VIzHM2iXTGEH0p7nfba1/apeJ25tN6MMNVshSJMSg6Kkffusw190YHcR18awMPYg3aST9Ct57XOsCAp+Thtd3CqRZTAHjPZ8gr7VowxA33Nug3Nf6RX9czgakm0/lN8vyAz3l6ej/6jIIwhKcY8v0a22TMzR0xbghDywn+umKW9vOdP1R/yLxHg+VWk6dRs8uTuJcLj3mR9d7CSgP/CDv5QBSVq8cuZqgtHzm899zUX+LbIpMrr1QPL5QsWFuZ48X3DO05f13gwgnBbt3FXHmQlTxrgUizJM8mDUg2ZVmDellM94rp2vjbJ8hK/7AUCzur5j2tDFwCW0aAD72MLXB/CABGNmIQKfJFa6UL2lWFFqGMiXvzyeZWfz6KnPJ1gcmsP9gRGLiKhHOMw7iuE46ju4nmGZOIwxbqRHXgJLMGqgHotYyW1UPMGiG2pFaaRMf65/G692LhFuZtONK40xrJLJU45ZMT83FRopYFTINIQ6G834tOUyK4D2b+wX8DkfRXqxkyFxCRYyaINTPBozV2VWWofKxqIwcHwp6PFLTJvbGf1MxcqZXhp+qbB9gKQNHGqjT05Oaixrx+C0KGo1ULKwdorr0U2FObCsqp6zkc5hHRfi2fhHLBSA6ylHIFcotaEx+kdzMxFQ42A5NtyK0DCsJuH1yDm9TdR6jFUa26oGfjsk3KLzyfF0KhRWiqCXQAddc15olMPj/5zvRKaZz7kQOxksxqTHZDIp+l8OtI0UgnAHwkALKpVaNtlzAgz7wzJ2uKWctbHPRV1zx9x8nnSJ8DOmHyqCq31srO51sp6i9Um9BoPGgAd8Xr/k8ika1fU8Vpd6R4ZmvIqKPavYNsHTIwAmD6OrYpDDBJwirNWhhc/f62iuVMG+wGR+kz/Yg76dK3u1Q92TwOER+c3eDZ6vf23btmJW9I3 cOPDTW01 p3bSIyqYTEBX0aMTk8g97hht/XpBeNm1fPe4DL2sKtXI1VQMJptTxND6k9DlNpPqiA15aelRlbs9FH9BoqRnyO8nefhUlLjPZFRSfArpuSsAftGZebQw8rnXPRNEfYHt+9OueUy3DSuw5gFgluL71NYDtHU7T6MU7zNI7L7cd3XlxJNviJ+MsGDKMzVfh2IfYAI0xu19cpHT/Xf0uLlG+9QwETJauc7N52reDsbuf0zjr/ioIKwUzhtUpPMEg+PZ5ZvxH2XtDdhcwmc4mUyuBNnJq4lDkjoNiBVA+BXF2873cp2R4Xrm93YUILRJqMMcRKsb8GcTNbJOyzNfsl0Bk9hVbitY0Rst/KsYs/x3Vm1r8NU8zwF+8jGR2YD4mIC5tSh2kosZidsrlXjZrKITt83v1VsruadRrKNbSa0oEqUCeEtnhr6qYgG5o3cUh/ilroZiwIbi5gLvhdJq7phDU4p8th1uVSJ4iv2UHf8519A6sz2s= 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: List-Subscribe: List-Unsubscribe: On Fri, Oct 04, 2024 at 06:01:07PM +0100, Lorenzo Stoakes wrote: > On Fri, Oct 04, 2024 at 09:48:31AM -0700, Breno Leitao wrote: > > Performance analysis using branch annotation on a fleet of 200 hosts > > running web servers revealed that the 'likely' hint in > > To be pedantic: *unlikely > > > vms_gather_munmap_vmas() was 100% consistently incorrect. In all > > observed cases, the branch behavior contradicted the hint. > > OK so this is probably because vm_mmap_pgoff() declares the userfaultfd > list head on the stack then passes it into do_mmap() and threads all the > way to this code... and yeah, so that would be 100%. > > There are other code paths that aren't 100%, but the system call one is. > > Nice spot! > > > > > Remove the 'unlikely' qualifier from the condition checking 'vms->uf'. > > By doing so, we allow the compiler to make optimization decisions based > > on its own heuristics and profiling data, rather than relying on a > > static hint that has proven to be inaccurate in real-world scenarios. > > Yeah I'm generally not in favour of 'vibes' based likely()/unlikely(), I > think it should always be based on profiling. > > It's understandable that there would be this expectation, and it may have > migrated from other code that already had this check in where perhaps it > wasn't always referencing a stack object, but yeah this is just wrong. > > > > > Signed-off-by: Breno Leitao > > Liam will want a look too when he's back next week. Liam, are you OK with this one? I suspect that Andrew is waiting for your review before merging it. > > Looks good to me though! > > Reviewed-by: Lorenzo Stoakes > > > --- > > mm/vma.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/mm/vma.c b/mm/vma.c > > index 4737afcb064c..9d4fe794dd07 100644 > > --- a/mm/vma.c > > +++ b/mm/vma.c > > @@ -1250,7 +1250,7 @@ int vms_gather_munmap_vmas(struct vma_munmap_struct *vms, > > else if (is_data_mapping(next->vm_flags)) > > vms->data_vm += nrpages; > > > > - if (unlikely(vms->uf)) { > > + if (vms->uf) { > > /* > > * If userfaultfd_unmap_prep returns an error the vmas > > * will remain split, but userland will get a > > -- > > 2.43.5 > >