[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <cfd5ad12-e589-dcca-52da-6b9db3e26b12@suse.cz>
Date: Tue, 11 May 2021 10:33:04 +0200
From: Vlastimil Babka <vbabka@...e.cz>
To: Hyeonggon Yoo <42.hyeyoo@...il.com>,
Matthew Wilcox <willy@...radead.org>
Cc: cl@...ux.com, penberg@...nel.org, rientjes@...gle.com,
iamjoonsoo.kim@....com, linux-mm@...ck.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2] mm: kmalloc_index: make compiler break when size is
not supported
On 5/11/21 5:03 AM, Hyeonggon Yoo wrote:
> On Mon, May 10, 2021 at 04:44:09PM +0100, Matthew Wilcox wrote:
>> On Tue, May 11, 2021 at 12:02:30AM +0900, Hyeonggon Yoo wrote:
>> > @@ -382,8 +385,8 @@ static __always_inline unsigned int kmalloc_index(size_t size)
>> > if (size <= 8 * 1024 * 1024) return 23;
>> > if (size <= 16 * 1024 * 1024) return 24;
>> > if (size <= 32 * 1024 * 1024) return 25;
>> > - if (size <= 64 * 1024 * 1024) return 26;
>> > - BUG();
>> > +
>> > + BUILD_BUG_ON_MSG(1, "unexpected size in kmalloc_index()");
>>
>> we're being encouraged to use static_assert() these days.
>> https://en.cppreference.com/w/c/language/_Static_assert
>>
>
> can you tell me difference between static_assert and BUILD_BUG_ON?
> it seems that mm subsystem does not make use of it now.
Some difference is explained in include/linux/build_bug.h near static_assert
definition.
But importantly it seems it's not possible to place static_assert(false) in
place of the BUG() because it will trigger despite not being reachable.
BUILD_BUG_ON_MSG(1 "..."); worked as expected for me.
Powered by blists - more mailing lists