From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 73EAFC433ED for ; Tue, 11 May 2021 08:33:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 49F0D611C2 for ; Tue, 11 May 2021 08:33:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231127AbhEKIeQ (ORCPT ); Tue, 11 May 2021 04:34:16 -0400 Received: from mx2.suse.de ([195.135.220.15]:52168 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231202AbhEKIeM (ORCPT ); Tue, 11 May 2021 04:34:12 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 575C4AF88; Tue, 11 May 2021 08:33:05 +0000 (UTC) Subject: Re: [PATCH v2] mm: kmalloc_index: make compiler break when size is not supported To: Hyeonggon Yoo <42.hyeyoo@gmail.com>, Matthew Wilcox Cc: cl@linux.com, penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20210508221328.7338-1-42.hyeyoo@gmail.com> <20210510135857.GA3594@hyeyoo> <9d0ffe49-a2e2-6c81-377b-4c8d2147dff8@suse.cz> <20210510150230.GA74915@hyeyoo> <20210511030343.GB98904@hyeyoo> From: Vlastimil Babka Message-ID: Date: Tue, 11 May 2021 10:33:04 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.0 MIME-Version: 1.0 In-Reply-To: <20210511030343.GB98904@hyeyoo> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.