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=-1.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,HK_RANDOM_FROM,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no 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 617A6C433B4 for ; Mon, 10 May 2021 13:59:06 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B0943611AB for ; Mon, 10 May 2021 13:59:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B0943611AB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 2FD2C6B006E; Mon, 10 May 2021 09:59:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2AD6A6B0071; Mon, 10 May 2021 09:59:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 14EA36B0072; Mon, 10 May 2021 09:59:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0054.hostedemail.com [216.40.44.54]) by kanga.kvack.org (Postfix) with ESMTP id EF5246B006E for ; Mon, 10 May 2021 09:59:04 -0400 (EDT) Received: from smtpin37.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id A59FB83FD for ; Mon, 10 May 2021 13:59:04 +0000 (UTC) X-FDA: 78125477808.37.EE14AD8 Received: from mail-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.52]) by imf27.hostedemail.com (Postfix) with ESMTP id 4F3C180192F0 for ; Mon, 10 May 2021 13:59:03 +0000 (UTC) Received: by mail-pj1-f52.google.com with SMTP id k3-20020a17090ad083b0290155b934a295so10108069pju.2 for ; Mon, 10 May 2021 06:59:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=eWWny1RMQecsKvOMWuYPoM/t5n+oHPFJqr+Tnw3Kljo=; b=pKoti58TLOtwwm477QlzZuDcSOzsz9RESlJS0Ih1fuCy748GoBB/Yr8h5da5p97ZHk hIgTZ6FuTknIBqQpEqkLwW/rRLeXBllG1UtYN3DaKhLIf82ESKSQAjjSIgvsN5whYo+y zdpRcQ9Dw8atnEkKCrcyNysjyEk8hwjdeoVBjY/B56ZRyCmRalYeM+Zi91egeFRmU0kW 314uJlkPy+GFBFOOYyPY+Ed4suBJcZPFmutwzySXOLiEbclkpAwkkJiPKJCoKSUAkSOP MNz04xbp0T9Y3wJt44IAmmb0qKsnD0MOFvRbLAhqmzPX8QUL9TMOv3E9safQIn9YpBzw rg5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=eWWny1RMQecsKvOMWuYPoM/t5n+oHPFJqr+Tnw3Kljo=; b=bCEMsU5Sh+nvcnnOqrNBfbtVLKKBdSZxY/XGe39Sm+7J0nBWGAYuqrkeIvLrl7/qBp A/qoeEmTiXWohPEeDBh3nsY2CHL5cpAsD2pCkPDsFeM1JNnxLLzCuzFrJtQgkXoUiRSR DX2KeupetJGZY+ydwUCGWONGSWB3jM5lvUdk7heFfBhln3LbjzBaGZh+5/ixLK9uwEqi xwsSvqspA3RfCS0PaXf4Jmw7HknwpJ+yEfUo6uYSoXK1qMo0PLscEerVV+nQCEs7+J0L hLGAH5D2eil12miS6rua0PqSaHoKjdTze81OgAsMF3Ooq4tR+6t9HMZ8endhs8hCQdiS L6vA== X-Gm-Message-State: AOAM533WgJNl51LwVXY0bZGkjsji29M1V9sGygTMUKBxpZXxuTRvDCO8 P/FHKwSCD13aXDnAfmLu5Yg= X-Google-Smtp-Source: ABdhPJxIEN3rnf84NgkWK2mGvNNf/mu1xRPA8bIoz/kUzgR1Mh33iuXQLto4SIzzDtTPi0V3rkdtqQ== X-Received: by 2002:a17:902:c106:b029:ee:9d6f:8861 with SMTP id 6-20020a170902c106b02900ee9d6f8861mr24444856pli.85.1620655143234; Mon, 10 May 2021 06:59:03 -0700 (PDT) Received: from hyeyoo ([183.99.11.150]) by smtp.gmail.com with ESMTPSA id m14sm11795732pff.17.2021.05.10.06.59.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 May 2021 06:59:03 -0700 (PDT) Date: Mon, 10 May 2021 22:58:57 +0900 From: Hyeonggon Yoo <42.hyeyoo@gmail.com> To: Vlastimil Babka Cc: Matthew Wilcox , cl@linux.com, penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] mm: kmalloc_index: remove case when size is more than 32MB Message-ID: <20210510135857.GA3594@hyeyoo> References: <20210508221328.7338-1-42.hyeyoo@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 4F3C180192F0 Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=pKoti58T; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf27.hostedemail.com: domain of 42hyeyoo@gmail.com designates 209.85.216.52 as permitted sender) smtp.mailfrom=42hyeyoo@gmail.com X-Stat-Signature: mpomho7iaxyyn8wz5cpe3iat5yoa53df Received-SPF: none (gmail.com>: No applicable sender policy available) receiver=imf27; identity=mailfrom; envelope-from="<42.hyeyoo@gmail.com>"; helo=mail-pj1-f52.google.com; client-ip=209.85.216.52 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1620655143-727565 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 Mon, May 10, 2021 at 12:09:55PM +0200, Vlastimil Babka wrote: > On 5/9/21 7:33 AM, Hyeonggon Yoo wrote: > > On Sun, May 09, 2021 at 12:19:40AM +0100, Matthew Wilcox wrote: > >> On Sun, May 09, 2021 at 07:13:28AM +0900, Hyeonggon Yoo wrote: > >> > the return value of kmalloc_index is used as index of kmalloc_caches, > >> > >> it doesn't matter. every few weeks somebody posts a patch to "optimise" > >> kmalloc_index, failing to appreciate that it's only ever run at compile > >> time because it's all under __builtin_constant_p(). > > > > Oh thanks, I didn't know about __builtin_constant_p. > > > > But I was not optimizing kmalloc_index. isn't it confusing that > > kmalloc_caches alllows maximum size of 32MB, and kmalloc_index allows > > maximum size of 64MB? > > > > and even if the code I removed is never reached because 64MB is always > > bigger than KMALLOC_MAX_CACHE_SIZE, it will cause an error if reached. > > KMALLOC_MAX_CACHE_SIZE depends on KMALLOC_SHIFT_HIGH > size of kmalloc_caches array depends on KMALLOC_SHIFT_HIGH > > So I don't an easy way how it could become reachable while causing the index to > overflow - if someone increased KMALLOC_SHIFT_HIGH from 25 to 26, all should be > fine, AFAICS. > > The problem would be if someone increased it to 27, then we might suddenly get a > BUG() in kmalloc_index(). We should probably replace that BUG() with > BUILD_BUG_ON(1) to catch that at compile time. Hopefully no supported compiler > will break because it's not able to do the proper compile-time evaluation - but > if it does, at least we would know. > > So I would accept the patch if it also changed BUG() to e.g. BUILD_BUG_ON_MSG(1, > "unexpected size in kmalloc_index()"); > and expanded the function's comment that this is always compile-time evaluated > and thus no attempts at "optimizing" the code should be made. > Thank you so much reviewing and replying to my patch. plecase check if I understood well. Okay, I'll do that work. then the following patch will: - remove case when size is more than 32MB - change "BUG to BUILD_BUG_ON to let compiler know when the size is not supported" - add comment that there's no need to optimize it is it what you mean. right? and I have a question. in the lin 751 of mm/slab_common.c, thre's struct kmalloc_info_struct kmalloc_info. and it initializes kmalloc info up to 64MB, which is currently not supported. should I change it too? in a separate patch?