From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pdx-out-001.esa.us-west-2.outbound.mail-perimeter.amazon.com (pdx-out-001.esa.us-west-2.outbound.mail-perimeter.amazon.com [44.245.243.92]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 051A52D7DC2; Fri, 17 Oct 2025 09:09:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=44.245.243.92 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760692194; cv=none; b=VNfzfEroC7UWZlQ8TSN7UtI7iaPuzfqXtvtybrvcqQOhDFfvR7Vu2Vswbiubnyr9cXf7rcqbweFQdP3w6RXiU9Hkodqem3K9b9sz7xKmvuW1y5NVFTSWPuY+bGYVpnvwRefnUgPfQ7+FGt0oBkxh42dGyrZrPCpuvrvSpPGTbb8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760692194; c=relaxed/simple; bh=c8CkUW1Wymk66rGG5tsvWtIDgSEWGpXx8+69cD8zAvI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ZFLpuc9Y2eSyQ2c9YnSNlswPp1k3N5dWEy1GwXoSQ1EjyqRfa7PVAucujjZojYQaVlxQGuZS0OK6GKjtJAaRBStSSucQPt63MOV3Qo/Ev43PtaAsmsfvTLQOV35PtYpCjT0FRFUQkcKhqfeqdZl9dPTsB3jRzYXSWtWPMnRwxEM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com; spf=pass smtp.mailfrom=amazon.com; dkim=pass (2048-bit key) header.d=amazon.com header.i=@amazon.com header.b=tUeuE655; arc=none smtp.client-ip=44.245.243.92 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=amazon.com header.i=@amazon.com header.b="tUeuE655" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazoncorp2; t=1760692193; x=1792228193; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=jvk2RBzXwrA99Hwxay/jSQlk3gLjsVti9lJHvH/pTPQ=; b=tUeuE655DnO2BvvljolDMutzwHyXrzK56nmeqoSHn6nMgYSCTgl+M3Ms eD9w3RY61Cdu7KBgrGlr1MAsR7Hm7sb0mRxhJpp5HF25RTA6pit18ng7p Xm+I5+ymBA5T/KZeA7KoapmQppflfoitvIp03pZKIA8NYNFkg3ylv/fKJ vAVi3OxBGin6Avl55RtfS4UaBxhff/NTUHroIPoW2VMnf8cSGzQYke9k5 P8W4CWagO7w7/jkMjynMaxA7FR5g0XUWTWkel4nFWWw29YF9Rk+9C9dlQ A81k2B6ONLPFo9KIvOBiK/1DCbPgHx94SaqSUnsiqWRNfQSZ16kD+KvvX Q==; X-CSE-ConnectionGUID: a+NhYey6RlObFrKw5WjAwg== X-CSE-MsgGUID: oQoxSvvuRJaorqC4IO71Bg== X-IronPort-AV: E=Sophos;i="6.18,281,1751241600"; d="scan'208";a="5073542" Received: from ip-10-5-12-219.us-west-2.compute.internal (HELO smtpout.naws.us-west-2.prod.farcaster.email.amazon.dev) ([10.5.12.219]) by internal-pdx-out-001.esa.us-west-2.outbound.mail-perimeter.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Oct 2025 09:09:50 +0000 Received: from EX19MTAUWC002.ant.amazon.com [205.251.233.51:6698] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.38.191:2525] with esmtp (Farcaster) id 86cb7d91-ec0e-46ce-a7ab-81f9e379a950; Fri, 17 Oct 2025 09:09:50 +0000 (UTC) X-Farcaster-Flow-ID: 86cb7d91-ec0e-46ce-a7ab-81f9e379a950 Received: from EX19D001UWA001.ant.amazon.com (10.13.138.214) by EX19MTAUWC002.ant.amazon.com (10.250.64.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.20; Fri, 17 Oct 2025 09:09:50 +0000 Received: from dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (172.19.116.181) by EX19D001UWA001.ant.amazon.com (10.13.138.214) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.20; Fri, 17 Oct 2025 09:09:35 +0000 From: Eliav Farber To: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , CC: Linus Torvalds , Lorenzo Stoakes , David Laight Subject: [PATCH v2 13/27 5.10.y] minmax: avoid overly complicated constant expressions in VM code Date: Fri, 17 Oct 2025 09:05:05 +0000 Message-ID: <20251017090519.46992-14-farbere@amazon.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251017090519.46992-1-farbere@amazon.com> References: <20251017090519.46992-1-farbere@amazon.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: EX19D037UWB003.ant.amazon.com (10.13.138.115) To EX19D001UWA001.ant.amazon.com (10.13.138.214) From: Linus Torvalds [ Upstream commit 3a7e02c040b130b5545e4b115aada7bacd80a2b6 ] The minmax infrastructure is overkill for simple constants, and can cause huge expansions because those simple constants are then used by other things. For example, 'pageblock_order' is a core VM constant, but because it was implemented using 'min_t()' and all the type-checking that involves, it actually expanded to something like 2.5kB of preprocessor noise. And when that simple constant was then used inside other expansions: #define pageblock_nr_pages (1UL << pageblock_order) #define pageblock_start_pfn(pfn) ALIGN_DOWN((pfn), pageblock_nr_pages) and we then use that inside a 'max()' macro: case ISOLATE_SUCCESS: update_cached = false; last_migrated_pfn = max(cc->zone->zone_start_pfn, pageblock_start_pfn(cc->migrate_pfn - 1)); the end result was that one statement expanding to 253kB in size. There are probably other cases of this, but this one case certainly stood out. I've added 'MIN_T()' and 'MAX_T()' macros for this kind of "core simple constant with specific type" use. These macros skip the type checking, and as such need to be very sparingly used only for obvious cases that have active issues like this. Reported-by: Lorenzo Stoakes Link: https://lore.kernel.org/all/36aa2cad-1db1-4abf-8dd2-fb20484aabc3@lucifer.local/ Cc: David Laight Signed-off-by: Linus Torvalds Signed-off-by: Eliav Farber --- include/linux/minmax.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/linux/minmax.h b/include/linux/minmax.h index 2ec559284a9f..a7ef65f78933 100644 --- a/include/linux/minmax.h +++ b/include/linux/minmax.h @@ -270,4 +270,11 @@ static inline bool in_range32(u32 val, u32 start, u32 len) #define swap(a, b) \ do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while (0) +/* + * Use these carefully: no type checking, and uses the arguments + * multiple times. Use for obvious constants only. + */ +#define MIN_T(type,a,b) __cmp(min,(type)(a),(type)(b)) +#define MAX_T(type,a,b) __cmp(max,(type)(a),(type)(b)) + #endif /* _LINUX_MINMAX_H */ -- 2.47.3