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=ham 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 A0C19C433B4 for ; Tue, 11 May 2021 08:33:08 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 549E16134F for ; Tue, 11 May 2021 08:33:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 549E16134F Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id A246A6B006E; Tue, 11 May 2021 04:33:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9AD976B0071; Tue, 11 May 2021 04:33:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7D8226B0072; Tue, 11 May 2021 04:33:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0248.hostedemail.com [216.40.44.248]) by kanga.kvack.org (Postfix) with ESMTP id 5ED2F6B006E for ; Tue, 11 May 2021 04:33:07 -0400 (EDT) Received: from smtpin38.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 1942681D7 for ; Tue, 11 May 2021 08:33:07 +0000 (UTC) X-FDA: 78128285214.38.9F05E18 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf20.hostedemail.com (Postfix) with ESMTP id 666083EF for ; Tue, 11 May 2021 08:33:06 +0000 (UTC) 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 X-Rspamd-Queue-Id: 666083EF Authentication-Results: imf20.hostedemail.com; dkim=none; spf=pass (imf20.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.15 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none X-Rspamd-Server: rspam03 X-Stat-Signature: m8p8rjbmqr8dep1bn6jqqgoynhkxw7js Received-SPF: none (suse.cz>: No applicable sender policy available) receiver=imf20; identity=mailfrom; envelope-from=""; helo=mx2.suse.de; client-ip=195.135.220.15 X-HE-DKIM-Result: none/none X-HE-Tag: 1620721986-462940 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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.