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=-5.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 2C85CC433E0 for ; Thu, 11 Mar 2021 09:40:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CC81964FB8 for ; Thu, 11 Mar 2021 09:40:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231994AbhCKJja (ORCPT ); Thu, 11 Mar 2021 04:39:30 -0500 Received: from mx2.suse.de ([195.135.220.15]:57588 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231826AbhCKJjW (ORCPT ); Thu, 11 Mar 2021 04:39:22 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1615455560; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Hu/Cdr4n+Fu84h51ILPTJCG7x6gjXFjYTqSY3KHqpS0=; b=ntsEAuleumNwt6HsDqK9dvf9jZZ+AVd9uXArrgRm8MTdJKc/R/St7o6eZN8YcuiuBG0HzV 2HpWBpQPfP0pWP+7rJeQ7Tf5D5aVBfg8pwAKhfQ1x2sV2Y6s4uewB0lApg1FaDahSkwlMt Vmu4AWUKOJdszdWokf4dquhaaT9xjG0= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 550E2AB8C; Thu, 11 Mar 2021 09:39:20 +0000 (UTC) Date: Thu, 11 Mar 2021 10:39:18 +0100 From: Michal Hocko To: Muchun Song 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 , HORIGUCHI =?utf-8?B?TkFPWUEo5aCA5Y+jIOebtOS5nyk=?= , Joao Martins , Xiongchun duan , linux-doc@vger.kernel.org, LKML , Linux Memory Management List , linux-fsdevel , Miaohe Lin , Chen Huang , Bodeddula Balasubramaniam Subject: Re: [External] Re: [PATCH v18 9/9] mm: hugetlb: optimize the code with the help of the compiler Message-ID: References: <20210308102807.59745-1-songmuchun@bytedance.com> <20210308102807.59745-10-songmuchun@bytedance.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org 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. 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. -- Michal Hocko SUSE Labs