* [PATCH] mm/hugetlb: Use max() to simplify hugetlb_vmemmap_optimizable_size()
@ 2025-08-10 21:47 Thorsten Blum
2025-08-11 0:15 ` Matthew Wilcox
0 siblings, 1 reply; 5+ messages in thread
From: Thorsten Blum @ 2025-08-10 21:47 UTC (permalink / raw)
To: Muchun Song, Oscar Salvador, David Hildenbrand, Andrew Morton
Cc: Thorsten Blum, linux-mm, linux-kernel
Use max() to simplify hugetlb_vmemmap_optimizable_size() and improve its
readability.
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
mm/hugetlb_vmemmap.h | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/mm/hugetlb_vmemmap.h b/mm/hugetlb_vmemmap.h
index 18b490825215..4da44b1e8e1a 100644
--- a/mm/hugetlb_vmemmap.h
+++ b/mm/hugetlb_vmemmap.h
@@ -11,6 +11,7 @@
#include <linux/hugetlb.h>
#include <linux/io.h>
#include <linux/memblock.h>
+#include <linux/minmax.h>
/*
* Reserve one vmemmap page, all vmemmap addresses are mapped to it. See
@@ -44,11 +45,10 @@ static inline unsigned int hugetlb_vmemmap_size(const struct hstate *h)
*/
static inline unsigned int hugetlb_vmemmap_optimizable_size(const struct hstate *h)
{
- int size = hugetlb_vmemmap_size(h) - HUGETLB_VMEMMAP_RESERVE_SIZE;
-
if (!is_power_of_2(sizeof(struct page)))
return 0;
- return size > 0 ? size : 0;
+
+ return max(0, hugetlb_vmemmap_size(h) - HUGETLB_VMEMMAP_RESERVE_SIZE);
}
#else
static inline int hugetlb_vmemmap_restore_folio(const struct hstate *h, struct folio *folio)
--
2.50.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] mm/hugetlb: Use max() to simplify hugetlb_vmemmap_optimizable_size()
2025-08-10 21:47 [PATCH] mm/hugetlb: Use max() to simplify hugetlb_vmemmap_optimizable_size() Thorsten Blum
@ 2025-08-11 0:15 ` Matthew Wilcox
2025-08-11 8:26 ` David Hildenbrand
0 siblings, 1 reply; 5+ messages in thread
From: Matthew Wilcox @ 2025-08-11 0:15 UTC (permalink / raw)
To: Thorsten Blum
Cc: Muchun Song, Oscar Salvador, David Hildenbrand, Andrew Morton,
linux-mm, linux-kernel
On Sun, Aug 10, 2025 at 11:47:45PM +0200, Thorsten Blum wrote:
> Use max() to simplify hugetlb_vmemmap_optimizable_size() and improve its
> readability.
That ... isn't clearer.
> {
> - int size = hugetlb_vmemmap_size(h) - HUGETLB_VMEMMAP_RESERVE_SIZE;
> -
> if (!is_power_of_2(sizeof(struct page)))
> return 0;
> - return size > 0 ? size : 0;
> +
> + return max(0, hugetlb_vmemmap_size(h) - HUGETLB_VMEMMAP_RESERVE_SIZE);
> }
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] mm/hugetlb: Use max() to simplify hugetlb_vmemmap_optimizable_size()
2025-08-11 0:15 ` Matthew Wilcox
@ 2025-08-11 8:26 ` David Hildenbrand
2025-08-11 9:08 ` Thorsten Blum
0 siblings, 1 reply; 5+ messages in thread
From: David Hildenbrand @ 2025-08-11 8:26 UTC (permalink / raw)
To: Matthew Wilcox, Thorsten Blum
Cc: Muchun Song, Oscar Salvador, Andrew Morton, linux-mm,
linux-kernel
On 11.08.25 02:15, Matthew Wilcox wrote:
> On Sun, Aug 10, 2025 at 11:47:45PM +0200, Thorsten Blum wrote:
>> Use max() to simplify hugetlb_vmemmap_optimizable_size() and improve its
>> readability.
>
> That ... isn't clearer.
No, it isn't.
--
Cheers,
David / dhildenb
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] mm/hugetlb: Use max() to simplify hugetlb_vmemmap_optimizable_size()
2025-08-11 8:26 ` David Hildenbrand
@ 2025-08-11 9:08 ` Thorsten Blum
2025-08-11 9:14 ` David Hildenbrand
0 siblings, 1 reply; 5+ messages in thread
From: Thorsten Blum @ 2025-08-11 9:08 UTC (permalink / raw)
To: David Hildenbrand
Cc: Matthew Wilcox, Muchun Song, Oscar Salvador, Andrew Morton,
linux-mm, linux-kernel
On 11. Aug 2025, at 10:26, David Hildenbrand wrote:
> On 11.08.25 02:15, Matthew Wilcox wrote:
>> On Sun, Aug 10, 2025 at 11:47:45PM +0200, Thorsten Blum wrote:
>>> Use max() to simplify hugetlb_vmemmap_optimizable_size() and improve its
>>> readability.
>> That ... isn't clearer.
>
> No, it isn't.
I guess it's personal preference. I'd prefer max(0, x) over a ternary
operator any time.
Thorsten
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] mm/hugetlb: Use max() to simplify hugetlb_vmemmap_optimizable_size()
2025-08-11 9:08 ` Thorsten Blum
@ 2025-08-11 9:14 ` David Hildenbrand
0 siblings, 0 replies; 5+ messages in thread
From: David Hildenbrand @ 2025-08-11 9:14 UTC (permalink / raw)
To: Thorsten Blum
Cc: Matthew Wilcox, Muchun Song, Oscar Salvador, Andrew Morton,
linux-mm, linux-kernel
On 11.08.25 11:08, Thorsten Blum wrote:
> On 11. Aug 2025, at 10:26, David Hildenbrand wrote:
>> On 11.08.25 02:15, Matthew Wilcox wrote:
>>> On Sun, Aug 10, 2025 at 11:47:45PM +0200, Thorsten Blum wrote:
>>>> Use max() to simplify hugetlb_vmemmap_optimizable_size() and improve its
>>>> readability.
>>> That ... isn't clearer.
>>
>> No, it isn't.
>
> I guess it's personal preference. I'd prefer max(0, x) over a ternary
> operator any time.
if (size > 0)
return size;
/* Nothing can be optimized out. */
return 0;
--
Cheers,
David / dhildenb
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-08-11 9:14 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-10 21:47 [PATCH] mm/hugetlb: Use max() to simplify hugetlb_vmemmap_optimizable_size() Thorsten Blum
2025-08-11 0:15 ` Matthew Wilcox
2025-08-11 8:26 ` David Hildenbrand
2025-08-11 9:08 ` Thorsten Blum
2025-08-11 9:14 ` David Hildenbrand
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).