From nobody Thu Oct 2 09:18:56 2025 Received: from fra-out-015.esa.eu-central-1.outbound.mail-perimeter.amazon.com (fra-out-015.esa.eu-central-1.outbound.mail-perimeter.amazon.com [18.158.153.154]) (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 DA0772E7BC0; Fri, 19 Sep 2025 10:25:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=18.158.153.154 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758277507; cv=none; b=UXXHctcpqy1vYaQr7O4vI5wtpO5dhrnn+lAb0XVyDyMNlYdgkf+G86oRgIjc+R4e8Q1jGsbtFcsBHZOY+6tyk3U65UYhWI93ztasS5WDi7ZpTMMeJAVmRJtQai1Pw5u7g8Oqcl65j6x59RwFt595aWE93lpdsu5bmWbBS0AQ1I8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758277507; c=relaxed/simple; bh=c8CkUW1Wymk66rGG5tsvWtIDgSEWGpXx8+69cD8zAvI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=pG5A/IAHB1flgfhWK5gHpvzOwZ15GYBndrywP5GwcESJo39uO0FNEzBsvCP8ra0Y6TuNQh69mDyqU4KZUL4CYzBbM44RC3plgMk48a0lbhJOpVZIV7xLa0WS6eYrpg3USOj2ZFzk0XxXFY479sVee5zMODCoxq8HXCvyrineVzI= 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=XFhs2WpC; arc=none smtp.client-ip=18.158.153.154 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="XFhs2WpC" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazoncorp2; t=1758277506; x=1789813506; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=jvk2RBzXwrA99Hwxay/jSQlk3gLjsVti9lJHvH/pTPQ=; b=XFhs2WpC5PAU7w72aczKfGWzk3yF5qqIR6Cw+RYd/eomvHpsYsTRpIEJ jdt63a2LEJJOQJuJ0yAt1TTkup42HgRnG+rUx77txyyDE0JHL6YVxKJzk suZwWIiaPqOw4EiM+nwpVBxwh1Q01aqUQQfaJeOl3kXQ0NsxWWWdlW1Bh FcNQYxNfU+6WWN8XSiy0pjMqKRrNbXHDk8A5yGDeHMKK45mbB9Zy4SuFs 6nBfkYpGFPBaEieQuKe5piOTFJs+eJxrL67ALcn9tdSwlphGkLGihs02T 9jUDbgcl+PSIFzvvhgKw5lbNk4yaUt4ayaNdwffEP3D2QPskgZRLwNmE3 g==; X-CSE-ConnectionGUID: LpY6wDAyQJSA4twPebH9HA== X-CSE-MsgGUID: yMhJGOvHSMKs3wOwCmRBRQ== X-IronPort-AV: E=Sophos;i="6.18,277,1751241600"; d="scan'208";a="2256255" Received: from ip-10-6-3-216.eu-central-1.compute.internal (HELO smtpout.naws.eu-central-1.prod.farcaster.email.amazon.dev) ([10.6.3.216]) by internal-fra-out-015.esa.eu-central-1.outbound.mail-perimeter.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Sep 2025 10:25:02 +0000 Received: from EX19MTAEUA001.ant.amazon.com [54.240.197.233:30717] by smtpin.naws.eu-central-1.prod.farcaster.email.amazon.dev [10.0.30.197:2525] with esmtp (Farcaster) id 9341bcf3-0572-48aa-a1aa-a34eedd38ac8; Fri, 19 Sep 2025 10:25:02 +0000 (UTC) X-Farcaster-Flow-ID: 9341bcf3-0572-48aa-a1aa-a34eedd38ac8 Received: from EX19D018EUA004.ant.amazon.com (10.252.50.85) by EX19MTAEUA001.ant.amazon.com (10.252.50.192) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.20; Fri, 19 Sep 2025 10:25:02 +0000 Received: from dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (172.19.116.181) by EX19D018EUA004.ant.amazon.com (10.252.50.85) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.20; Fri, 19 Sep 2025 10:24:33 +0000 From: Eliav Farber To: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , CC: , Linus Torvalds , Lorenzo Stoakes , David Laight Subject: [PATCH 12/27 5.10.y] minmax: avoid overly complicated constant expressions in VM code Date: Fri, 19 Sep 2025 10:17:12 +0000 Message-ID: <20250919101727.16152-13-farbere@amazon.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250919101727.16152-1-farbere@amazon.com> References: <20250919101727.16152-1-farbere@amazon.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: EX19D035UWB004.ant.amazon.com (10.13.138.104) To EX19D018EUA004.ant.amazon.com (10.252.50.85) Content-Type: text/plain; charset="utf-8" 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 =3D false; last_migrated_pfn =3D 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@luci= fer.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 =3D (a); (a) =3D (b); (b) =3D __tmp; } while (0) =20 +/* + * 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 */ --=20 2.47.3