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=-3.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,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 97D29C433E0 for ; Thu, 11 Mar 2021 10:00:52 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D63A064E28 for ; Thu, 11 Mar 2021 10:00:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D63A064E28 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bytedance.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 4B3BE8D02A9; Thu, 11 Mar 2021 05:00:51 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 463E58D028E; Thu, 11 Mar 2021 05:00:51 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2B5D98D02A9; Thu, 11 Mar 2021 05:00:51 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0225.hostedemail.com [216.40.44.225]) by kanga.kvack.org (Postfix) with ESMTP id 0E3788D028E for ; Thu, 11 Mar 2021 05:00:51 -0500 (EST) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id C0712180ACC31 for ; Thu, 11 Mar 2021 10:00:50 +0000 (UTC) X-FDA: 77907149460.08.E7181AF Received: from mail-pg1-f175.google.com (mail-pg1-f175.google.com [209.85.215.175]) by imf19.hostedemail.com (Postfix) with ESMTP id 2EBF490009FA for ; Thu, 11 Mar 2021 10:00:46 +0000 (UTC) Received: by mail-pg1-f175.google.com with SMTP id n9so12403578pgi.7 for ; Thu, 11 Mar 2021 02:00:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=UQYHWAxJkDDd3f+gQZzvbrjXR8K2vgw8ut0GHNgkmoM=; b=TGZB56pq53iJrbDY/snWAhnMelGY6QSE+Yv/4rXOZF8ClO6D17/XVaPjgLf/6KmFGv UIkQ/2qRLk3cCji7+/COxGOJFB14ZYLUhacmrEXPkr5eL/l43Czfhqly17NuHNj0e+UY zuFiR7pojUusz5EVmDAIDRxBRa2JsxlgSqXnwehIg5gen6srHlXbS82ai+U6lhRhjWph PpsZQrZfgnFvfxrZsJvi1gFcFi/nEpv7r7rZ/GopaDNqOFb9YbRlV8FyTgFx+YSnJbr/ ioPbB3tV3Um5t0pJY5uKOyKLo8ACUmzSZrB9NqPQXaY5yKUUM/Ctm8B5HNpv4UmFCvPG ycXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=UQYHWAxJkDDd3f+gQZzvbrjXR8K2vgw8ut0GHNgkmoM=; b=Cjv8FSto0ghGkG5sowsAoH/40VNrbQrda8wzjthtcZtPkdnAqq6bqoO/jpUaq9NZEb eGNFqLswsCyUVpAmHRb8iJ2R3GkM2ukKuVUIzKKDrHUMcjVSKUbN/tXCeOe6ARaiyR2Z tGwu3F2CPd9Ls1YQdFlG9dFmMMJ6fZOrFq25iO/mmxHU9OvZ5gKYl75QWPDijVR0G+av Nw27G0WzuXLHq3ZyA0DK+p819UQrTOGFxy+resUfLOWYfxm/NRpDegu2pcXpuYhVI9hL tza4p7kVJPyFWvJa9qdTYz0KnLlV1By+yAtdrNxctfUBfXuBLMQpgxGai1CHfJ97W1Bf OVkQ== X-Gm-Message-State: AOAM532q75scnehBNfHbYDbrPAmTtR57grYS34Qd6PMpqkJuv7OKBzVP Upk9P6q4pRIHckkTu2wRIdFPZd7Hrl81hzRdy83jTQ== X-Google-Smtp-Source: ABdhPJwqzuj630hhgNm5RpgiIIsq6u5FJpc47tt2JPxPfMHD0qYBylhZFf5FrpayQuz02H1TABPQKpF4NTKHNt6mO7g= X-Received: by 2002:a63:141e:: with SMTP id u30mr6765052pgl.31.1615456846679; Thu, 11 Mar 2021 02:00:46 -0800 (PST) MIME-Version: 1.0 References: <20210308102807.59745-1-songmuchun@bytedance.com> <20210308102807.59745-10-songmuchun@bytedance.com> In-Reply-To: From: Muchun Song Date: Thu, 11 Mar 2021 18:00:09 +0800 Message-ID: Subject: Re: [External] Re: [PATCH v18 9/9] mm: hugetlb: optimize the code with the help of the compiler To: Michal Hocko Cc: Jonathan Corbet , Mike Kravetz , Thomas Gleixner , Ingo Molnar , bp@alien8.de, x86@kernel.org, hpa@zytor.com, dave.hansen@linux.intel.com, luto@kernel.org, Peter Zijlstra , Alexander Viro , Andrew Morton , paulmck@kernel.org, mchehab+huawei@kernel.org, pawan.kumar.gupta@linux.intel.com, Randy Dunlap , oneukum@suse.com, anshuman.khandual@arm.com, jroedel@suse.de, Mina Almasry , David Rientjes , Matthew Wilcox , Oscar Salvador , "Song Bao Hua (Barry Song)" , David Hildenbrand , =?UTF-8?B?SE9SSUdVQ0hJIE5BT1lBKOWggOWPoyDnm7TkuZ8p?= , Joao Martins , Xiongchun duan , linux-doc@vger.kernel.org, LKML , Linux Memory Management List , linux-fsdevel , Miaohe Lin , Chen Huang , Bodeddula Balasubramaniam Content-Type: text/plain; charset="UTF-8" X-Stat-Signature: ggzskw4cngkx7axty8tzdk598bah7zwk X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 2EBF490009FA Received-SPF: none (bytedance.com>: No applicable sender policy available) receiver=imf19; identity=mailfrom; envelope-from=""; helo=mail-pg1-f175.google.com; client-ip=209.85.215.175 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1615456846-818924 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 Thu, Mar 11, 2021 at 5:39 PM Michal Hocko wrote: > > On Thu 11-03-21 17:08:34, Muchun Song wrote: > > On Thu, Mar 11, 2021 at 4:55 PM Michal Hocko wrote: > > > > > > On Thu 11-03-21 15:33:20, Muchun Song wrote: > > > > On Wed, Mar 10, 2021 at 11:41 PM Michal Hocko wrote: > > > > > > > > > > On Mon 08-03-21 18:28:07, Muchun Song wrote: > > > > > > When the "struct page size" crosses page boundaries we cannot > > > > > > make use of this feature. Let free_vmemmap_pages_per_hpage() > > > > > > return zero if that is the case, most of the functions can be > > > > > > optimized away. > > > > > > > > > > I am confused. Don't you check for this in early_hugetlb_free_vmemmap_param already? > > > > > > > > Right. > > > > > > > > > Why do we need any runtime checks? > > > > > > > > If the size of the struct page is not power of 2, compiler can think > > > > is_hugetlb_free_vmemmap_enabled() always return false. So > > > > the code snippet of this user can be optimized away. > > > > > > > > E.g. > > > > > > > > if (is_hugetlb_free_vmemmap_enabled()) > > > > /* do something */ > > > > > > > > The compiler can drop "/* do something */" directly, because > > > > it knows is_hugetlb_free_vmemmap_enabled() always returns > > > > false. > > > > > > OK, so this is a micro-optimization to generate a better code? > > > > Right. > > > > > Is this measurable to warrant more code? > > > > I have disassembled the code to confirm this behavior. > > I know this is not the hot path. But it actually can decrease > > the code size. > > struct page which is not power of 2 is not a common case. I know this is not a common case. But the check of is_power_of_2(sizeof(struct page)) does not bring extra runtime overhead. It just tells the compiler to optimize code as much as possible. > Are you sure > it makes sense to micro optimize for an outliar. If you really want to > microptimize then do that for a common case - the feature being > disabled - via static key. We cannot optimize the code size (vmlinux) even if we use a static key when the size is not power of 2. Sorry. I am confused why you disagree with this change. It does not bring any disadvantages. > -- > Michal Hocko > SUSE Labs