From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) (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 EA7032C2365 for ; Mon, 8 Dec 2025 18:57:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765220251; cv=none; b=nIpFsMpymex2fxroIxEYU9/LqqpQG+SySCZ1R8uIWZEwMU6BrvQ7DI6QggsKNAlrs0N/b/DIiEkMjuPqs7WkQmsKbY/JpMkyA0KT4uHxw9Hcx/HQaHn/YLwtuE91lWaAusZH/MNlFU8L3f5GEpXJUvQMxRVvTZZtFaOWLOVa/jo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765220251; c=relaxed/simple; bh=CH7BXHn8i0ZN2N70A/Jw8RyYAkuFgREGbPFxlwrzNFI=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=fw+mq29jXUXbF+TdaSvx0d1nnfzeDvIIOjHEoIn8CvLmpU5u7Bfd82d2uR8rOS7th0w1wHzyXP/iMP4KqiXfgBchisLl2HC2X6FG6lwIeS+9QpyJtgsb3vfZ0/xdkyoSiTUdmZWXt+TOT8FffPE5QYyh/UYVNU/1OBzJrfrr01I= 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=KXfFaPrv; arc=none smtp.client-ip=209.85.221.53 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KXfFaPrv" Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-42e2e47be25so2428908f8f.2 for ; Mon, 08 Dec 2025 10:57:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1765220248; x=1765825048; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=KWyaFrEhG3z3cIAYB95757Y84D0cm8l/dldSl2D79pM=; b=KXfFaPrvssUxT+eOz51XCa/zCC7BBiSkGj2n/WqrtNs5140Ax+ALUGCYHk8IaoCj/8 0QNvEA5pN3IEU5194vfvzdBljoJldwdAL/2Stshzj9/eSS9PqEJ/6iGKn9y3j83qld+Z I1OvF0CePYc1XIo5APaBUGFuc0BoafhLottak0vG4JVz+7GolL8TkwPps77BaUw1DvHg 0LR2cCjSBmHPF0rHC7Mmk8NO3Isi2iXnseTRXlSdxGBsXZJ82gGfVlZ2IO+KyKrTDJpO U/6SQwbtug/m0Gr2DgPciR/an2+FrWohCyg618PgCek1heAf5V41q/uzL6AX599VBZ6r CDUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765220248; x=1765825048; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=KWyaFrEhG3z3cIAYB95757Y84D0cm8l/dldSl2D79pM=; b=t+WiniqoOltnUJYUczTj/JtLS2aWxTSXK+ERDHJFjHAx+EnHTc3ZZnBvvFkTsIKqlp NuXw8YpXYhqK1A8pYWSXR38tOqxcV5/71T5EII0Y3F1+D11gErSaWRKw0h99c+EJ6bU1 LEOUglFP7MsjBHqANNcz/d8PZSGLu70yIP0/x6Df5Ax5374CSpI37UyidHJ1AMmMGFIr 5uShkLhPmb5j6VMJUGlhoum3Z3fVuFCaaG4iFDvDKQzxwxKCmHIfGcviD2kEnBKQXtW6 U6mhuiEBHEbUTs4g2+AMEEBYHKNjaBJwK4PjzGQbCPv09lFoPk9XRpVXcd8VL0ZK1/ei AdXg== X-Forwarded-Encrypted: i=1; AJvYcCUw/sPE2ABXMgII+RftGe+t6vA2UVNAEbvATYPfCcyko9lE1DfyxNzgJsaNdPWzU9qcTW5Rv6k4wZvwcQY=@vger.kernel.org X-Gm-Message-State: AOJu0YzqkdUhBh9Ec3HJnTqPeiBSzthjvmofshu9ZltDxrMvoajeaIno pA3k2h+QiSF4FEV2WGfp3coaEn+aaWLpfUmDEEFgDhaPAKpSaynFuO/9 X-Gm-Gg: ASbGncsKxyeuw1jeSvrXZ7lEBKKdAGRAXBlxYjPiHZdewxzeoSxVJ03r7WTKYeWek+Z B0eytUoHByiJsRC+7hJbj+M7qrpSHdSs64OgC8pYvLbm9shW9GWVx7tLves4aoEyG6PxqqLiHDk +DfDV57I1VTMXKpkDVG5xXN+pB1VxvhIHASfS4aAN+eBQpTULwlCuaiD/Ng/xz/08SakXQJ9DZ6 2UOLlOcC7yP0+tBNaydNVF4g4cqWN1vvH89nsV+mFl2yxoxgSj/mA8+TFMgXHYdv2kdSwj4m+a7 GDtBdbDVu91WzKRMtUV+OdkCIb0TTKFEYfLg39+iJE4UO+bsWkyAuL6GEC3hAULu8Vx09oHYMWP 8TsFN6pXdf6vAP4jHH/4qu84HghyvPTMYR8s5KS6/XwI55LrmJvFov3+hdSlRZZmHY8yAh5/L7h G8ORHgJctAlKq2m0UhuE8d5po2O+RGUyWfEjUHtimsAqBLmNWHBBek X-Google-Smtp-Source: AGHT+IG0dUoaqrtgWtzPv53mIAeFPpwBu8JvslqiBa2uwkU22Y0TLTRiSrVJGb1khvuOup2fFSbmVg== X-Received: by 2002:a05:6000:2891:b0:42f:8816:9505 with SMTP id ffacd0b85a97d-42f89f58e5dmr9440683f8f.61.1765220247936; Mon, 08 Dec 2025 10:57:27 -0800 (PST) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-42f7d331df0sm28107904f8f.36.2025.12.08.10.57.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Dec 2025 10:57:27 -0800 (PST) Date: Mon, 8 Dec 2025 18:57:25 +0000 From: David Laight To: Lorenzo Stoakes Cc: Andrew Morton , David Hildenbrand , "Liam R . Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , oliver.sang@intel.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] mm: avoid use of BIT() macro for initialising VMA flags Message-ID: <20251208185725.6ab9bf7e@pumpkin> In-Reply-To: References: <20251205175037.1287366-1-lorenzo.stoakes@oracle.com> <20251205184342.2cfcc73e@pumpkin> <4eea9138-3853-457d-9113-e3caa7f00437@lucifer.local> <20251205213449.12bf4819@pumpkin> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) 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-Transfer-Encoding: 7bit On Mon, 8 Dec 2025 16:42:43 +0000 Lorenzo Stoakes wrote: > On Sat, Dec 06, 2025 at 04:43:57PM +0000, Lorenzo Stoakes wrote: > > On Fri, Dec 05, 2025 at 09:34:49PM +0000, David Laight wrote: > > > On Fri, 5 Dec 2025 19:18:56 +0000 > > > Lorenzo Stoakes wrote: > > > > > > > On Fri, Dec 05, 2025 at 06:43:42PM +0000, David Laight wrote: > > > > > On Fri, 5 Dec 2025 17:50:37 +0000 > > > > > Lorenzo Stoakes wrote: > > > > > > > > > > > Commit 2b6a3f061f11 ("mm: declare VMA flags by bit") significantly changed > > > > > > how VMA flags are declared, utilising an enum of VMA bit values and > > > > > > ifdef-fery VM_xxx flag declarations via macro. > > > > > > > > > > > > As part of this change, it uses INIT_VM_FLAG() to define VM_xxx flags from > > > > > > the newly introduced VMA bit numbers. > > > > > > > > > > > > However, use of this macro results in apparently unfortunate macro > > > > > > expansion and resulted in a performance degradation.This appears to be due > > > > > > to the (__force int), which is required for the sparse typechecking to > > > > > > work. > > > > > > > > > > Does sparse complain if you just add 0? As in: > > > > > #define INIT_VM_FLAG(name) BIT(VMA_ ## name ## _BIT + 0u) > > > > > > > > > > That should change the type without affecting what BIT() expands to. > > > > > > > > Thanks, checked that and unfortunately that doesn't satisfy sparse :) > > > > > > > > I don't think it's too crazy to use 1UL << here, just very frustrating (TM) > > > > that this is an issue. > > > > > > I might use some of my copious spare time (ha) to see why BIT() fails. > > > I bet it is just too complex for its own good. > > > Personally I'm fine with both explicit (1ul << n) and hex constants. > > > The latter are definitely most useful if you ever look at hexdumps. > > > > Thanks :) yeah I just didn't want to go down that rabbit hole myself as I seemed > > to have the answer and wanted to get it fixed, but obviously am quite curious as > > to what on earth is causing that. > > I did wonder about _calc_vm_trans(), given the 'interesting' stuff it does. > > Maybe I should fiddle with that and see... Hmmm... /* * Optimisation macro. It is equivalent to: * (x & bit1) ? bit2 : 0 * but this version is faster. * ("bit1" and "bit2" must be single bits) */ #define _calc_vm_trans(x, bit1, bit2) \ ((!(bit1) || !(bit2)) ? 0 : \ ((bit1) <= (bit2) ? ((x) & (bit1)) * ((bit2) / (bit1)) \ : ((x) & (bit1)) / ((bit1) / (bit2)))) The comment fails to mention it is only sane for constants. If nothing else 9 expansions of BIT() are going to generate a very long line. For starters make it a statement expression and use __auto_type _bit1 = bit1. Then add a check for both _bit1 and _bit2 being constants. It is also worth checking the compiler doesn't do it for you. Looks like gcc 7.1 onwards generate the 'optimised' code. https://godbolt.org/z/EGGE56E3r David