Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp159927lqb; Tue, 28 May 2024 11:36:13 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXW3PJDLzLm2T09/XRBE9RH7K6ZxDW9hErMrSNwEa1MitS6451XDKIej2WJSluhHNluQSzZt/FpDh96BQ6CTGTjxFGMShX6tU/xJ75q2Q== X-Google-Smtp-Source: AGHT+IHgKl642Ht9c99CkV0C5Sr2I6NTQ3XD1OX4wc/OJsGN2hRXWWGUxKI39TLLgeFSI5MxXC/0 X-Received: by 2002:a50:f68e:0:b0:578:635d:67ba with SMTP id 4fb4d7f45d1cf-578635d6941mr10269068a12.18.1716921373781; Tue, 28 May 2024 11:36:13 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716921373; cv=pass; d=google.com; s=arc-20160816; b=X85EbK8XnbxqHML3JpMfp+B2Bnq+/6+BxJvf+E5DNsL1z/ZAGeHVd8H7XddilVTluY fQP3iX1ZDvf2xY6qKX/fMMbg862tybceM9fQCNMHiipxVYwFnLNDEnnpqSt7K7yAxU/W aWNsZ8E8RUw1BSd7ug5mKbyCi4tLtUGB1IgZvIEyYQFsszvcvhU06S9IJRAl9U2hOGcR sTalJtzKiKUZg58EfNC5vAxVmfynUj0ZEK4uOiEdQSkUnTpxT6nxcMUkZEN0daxVT4G1 e2QDfQDgfHdpv0x/+0HvTwQfQYEyYf5y+0qwxaFkH99PQE0V1txTv5A4JA67GJVGmnms nz7g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:date:from:dkim-signature; bh=2Meei9ZVa20+5yNphV/wKrB9x+kwpXFk7nEopIQ+RSs=; fh=AX68Zjzd2yi8Vri6ZqeGajfmiNuR3SRuPk249Fg8Dmo=; b=w6UHLJ1AuZbXp3L8dox2DKhGMIMCpQ5N4N4VpBXKC+STOPfHncL2WLsniBkjl+A05P MEWJGPJbNL2GlDwZuAZFwHhz5u1KeiRBsMRDkEBDrLOsoOmJ915x8qoFf6OPi2CmcsNL 5hHLLUNUdtNRu53MqXf+SuFpY7HauDHEU426Zyf+vCUNlSyNfoNpMLq4sMjvMs25k+J3 pDruKQfD60+KZ+N7/KLYZYcoqa5Wot7VbbZ14QMWFHq/tSnrT+l3CrAdfp4wGNVceck9 7AvjLoqQhfBZYAyQZ1XYrqBByhAeXd1fn66JunNURy+IxPmaaegJ+It2GbkvkrdsxdG9 M4EQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="P/vNHNOb"; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-192870-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-192870-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-579fdb52f59si387708a12.377.2024.05.28.11.36.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 11:36:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-192870-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="P/vNHNOb"; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-192870-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-192870-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 79F9D1F23CCC for ; Tue, 28 May 2024 18:36:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 85071502B2; Tue, 28 May 2024 18:36:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="P/vNHNOb" Received: from mail-lf1-f47.google.com (mail-lf1-f47.google.com [209.85.167.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0C0411C6A5 for ; Tue, 28 May 2024 18:36:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716921366; cv=none; b=l/DyU3I/VLZYIB1fifijwjdjotsg9G/yCLSbqWAG8f6loRCGsmlPbY9e+KOeqgnGj06qy4QizKI7bJXda77mmn3VeptFsojVNegSuzUSz+D44WGjOi2/0RcwpPeh2RbsEiddmJuxJ5Qs1dh2uOtucpQlZjf91ML1gVDTCvsabtQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716921366; c=relaxed/simple; bh=rXtUrXLXV0OhPXCJZls3z+Z2nTXyO3iCbX5GfLKNHyc=; h=From:Date:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ht2wYt5jW1WGt2kRcbVsY+cCuQsWrbsd6oDGNLYY1U7BxgqEoq9J6iSjGn0b79FFXEwZt33usSSsIsM2O9XRP/OdlivSM30YDdBZgKrDnQeOnOpq6ZGAJY1tj+I4mi+KZYBWPJDDB4vGV4DIWHkhS9DtAT2tEquygF1I/zTASN0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=P/vNHNOb; arc=none smtp.client-ip=209.85.167.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lf1-f47.google.com with SMTP id 2adb3069b0e04-51fcb7dc722so92081e87.1 for ; Tue, 28 May 2024 11:36:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716921363; x=1717526163; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:date:from:from:to:cc:subject:date:message-id:reply-to; bh=2Meei9ZVa20+5yNphV/wKrB9x+kwpXFk7nEopIQ+RSs=; b=P/vNHNObUlMC+ifIv/dYOowOFR5MBaVdF9QHXFilETYrZOwv0zH7dbu/NOU417Bt2q bVxFM61/V4RPgu2O1Eci1h0aHVKho0bAWVMqYiNOVlfZH1GonJ2jyb/OtoFQyGNaf5Ep 0HYtiudMzaXTXFWFQHxUBgixP/lTDyWlYfiVspxaDUhnYCnxYel1gnuxTRlSwBVapozp 9laYZFUaDqvc+oQOazkUNVL54sHDOXFCKRYVSbRPFnXwZX2H9m2dn3kQJ6zciIEOfHDQ fWYK9zSuME0aUMNCZpI06ygeDFrxUO89iPFU1OrU8yuqlI13lssoFFwHrlPJUpTootDM +SrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716921363; x=1717526163; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:date:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=2Meei9ZVa20+5yNphV/wKrB9x+kwpXFk7nEopIQ+RSs=; b=iNVbqYbVWnbvfcM7hVfn2jyO3M08l/N/Ii/wUhuyBVzUJhOA/FtmTX4yXIT3y4mOSq wDd560HsU6QzNOrepf8e/cKIqwask0q4OxKg/nqyFRa3VP5+O8Pf/Q1NiOZzRXynR5iR ffOCmb9+lvbEHN1+u+xAxRomEzawO6/wFPh2OiQo72C5AYxgiYEeXA+zBC7sIR3SG6U7 FlG+Ibie5Gxd5unkYe16Hm2sNOchQt8QsOx4hSg6A4Olap71OXx3xywusFbulO7KFq7J RXO1iU3HLxKgl8WEyhZOesclWNyuMz/+JSq19hRlatSq8nQ6kCTCbUJ2RCrffDLzw3+g m+rw== X-Forwarded-Encrypted: i=1; AJvYcCVtmJDG2IYnU691I4LLCZBgJvHr1CgILRWuq+4MoxeNPCbSy+6lVQmaEZCjd+n2FO344AVVFdksLhSxYy2EotUzJPOtKmFR3NLV2xbj X-Gm-Message-State: AOJu0Yy4e7TOe9nQrV4EX0mOOUWXwLLnPcRHd3RjkEUSWUoYMUgG3wLO rBhiufqELHPOhMYLhwGndw7bxerjf/b/vCSU8BXoYmOAjQce6rDx X-Received: by 2002:ac2:4c2d:0:b0:51f:c153:c3e7 with SMTP id 2adb3069b0e04-527ef4f5c29mr5136415e87.12.1716921362881; Tue, 28 May 2024 11:36:02 -0700 (PDT) Received: from pc636 (host-95-193-70-101.mobileonline.telia.com. [95.193.70.101]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-529be969ab2sm160302e87.150.2024.05.28.11.36.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 11:36:02 -0700 (PDT) From: Uladzislau Rezki X-Google-Original-From: Uladzislau Rezki Date: Tue, 28 May 2024 20:36:00 +0200 To: Uros Bizjak Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton , Uladzislau Rezki , Christoph Hellwig , Lorenzo Stoakes , Dennis Zhou , Tejun Heo , Christoph Lameter Subject: Re: [PATCH v2 2/2] mm/vmalloc: Use __this_cpu_try_cmpxchg() in preload_this_cpu_lock() Message-ID: References: <20240528144345.5980-1-ubizjak@gmail.com> <20240528144345.5980-2-ubizjak@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240528144345.5980-2-ubizjak@gmail.com> On Tue, May 28, 2024 at 04:43:14PM +0200, Uros Bizjak wrote: > Use __this_cpu_try_cmpxchg() instead of > __this_cpu_cmpxchg (*ptr, old, new) == old in > preload_this_cpu_lock(). x86 CMPXCHG instruction returns > success in ZF flag, so this change saves a compare after cmpxchg. > > The generated code improves from: > > 4bb6: 48 85 f6 test %rsi,%rsi > 4bb9: 0f 84 10 fa ff ff je 45cf <...> > 4bbf: 4c 89 e8 mov %r13,%rax > 4bc2: 65 48 0f b1 35 00 00 cmpxchg %rsi,%gs:0x0(%rip) > 4bc9: 00 00 > 4bcb: 48 85 c0 test %rax,%rax > 4bce: 0f 84 fb f9 ff ff je 45cf <...> > > to: > > 4bb6: 48 85 f6 test %rsi,%rsi > 4bb9: 0f 84 10 fa ff ff je 45cf <...> > 4bbf: 4c 89 e8 mov %r13,%rax > 4bc2: 65 48 0f b1 35 00 00 cmpxchg %rsi,%gs:0x0(%rip) > 4bc9: 00 00 > 4bcb: 0f 84 fe f9 ff ff je 45cf <...> > > No functional change intended. > > Signed-off-by: Uros Bizjak > Cc: Andrew Morton > Cc: Uladzislau Rezki > Cc: Christoph Hellwig > Cc: Lorenzo Stoakes > Cc: Dennis Zhou > Cc: Tejun Heo > Cc: Christoph Lameter > --- > v2: Show generated code improvement in the commit message. > --- > mm/vmalloc.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/mm/vmalloc.c b/mm/vmalloc.c > index 5d3aa2dc88a8..4f34d935d648 100644 > --- a/mm/vmalloc.c > +++ b/mm/vmalloc.c > @@ -1816,7 +1816,7 @@ static void free_vmap_area(struct vmap_area *va) > static inline void > preload_this_cpu_lock(spinlock_t *lock, gfp_t gfp_mask, int node) > { > - struct vmap_area *va = NULL; > + struct vmap_area *va = NULL, *tmp; > > /* > * Preload this CPU with one extra vmap_area object. It is used > @@ -1832,7 +1832,8 @@ preload_this_cpu_lock(spinlock_t *lock, gfp_t gfp_mask, int node) > > spin_lock(lock); > > - if (va && __this_cpu_cmpxchg(ne_fit_preload_node, NULL, va)) > + tmp = NULL; > + if (va && !__this_cpu_try_cmpxchg(ne_fit_preload_node, &tmp, va)) > kmem_cache_free(vmap_area_cachep, va); > } > > -- > 2.42.0 > Reviewed-by: Uladzislau Rezki (Sony) Thanks! -- Uladzislau Rezki