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=-13.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 BCF60C433EF for ; Sat, 18 Sep 2021 10:31:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 92EE06112E for ; Sat, 18 Sep 2021 10:31:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236221AbhIRKcv (ORCPT ); Sat, 18 Sep 2021 06:32:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235388AbhIRKct (ORCPT ); Sat, 18 Sep 2021 06:32:49 -0400 Received: from mail-pg1-x536.google.com (mail-pg1-x536.google.com [IPv6:2607:f8b0:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70ECBC061757 for ; Sat, 18 Sep 2021 03:31:25 -0700 (PDT) Received: by mail-pg1-x536.google.com with SMTP id h3so12210644pgb.7 for ; Sat, 18 Sep 2021 03:31:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=sqcmPvsXMriA6MZ/1xe+ZZKmWFZFt3hQB0j09TtDJdc=; b=FgcErukEVEa15/A2CYRRQCkwAVaBw080oU1C53GRRDOjSajj4JGHY/qMQf5QUHDrHp 7/p4dzu++xya5ko0h5l7RnTk+oP0w9KVPzS12z27k749zOCFAHiKby5GRG0kXC8NNuhF RE6lYdMSj2/TnwUwYM3IigU3rlGhpoO9+nrfIzlpo/nGqi6zfHhsiS9EkQjmPXy7Rdqv eiG2vyotuIrvjz73vVOHc6PO1VsFSVwc77mU+XCPXn8ASD0Abd+cjqwx3O096ACv3aKA r47pn0AMdRC6GdK1Od9VTXvHQYma34HJuFz9kqFl9h+A4aztodofsu1VQtEb//5DPHxp dQsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=sqcmPvsXMriA6MZ/1xe+ZZKmWFZFt3hQB0j09TtDJdc=; b=beqIaXUYID0eQo3bFlgknmoCaMS+lJOz+rXgAf0YbAcCu6G4HP7/vho4UViGCNs+CN O9MgiFVie8ekkPMvAd1CQ4sxgZpKftIiRA1mbukM7M8Upmi3Y2eGRChxBk1U9BeUiURQ czR4u301VKJEVU6HDC/xHxODobFMSoX3Urnfoi+A8twp3ihNRA4QexblF6F/M/9vuckM gpXPtKWgTgA4qXLmg90eYWCw9u2LJWT2/lZuZxuk4cCDuD8GyZHBQJhw7W9SQ9+iXurs ryChCwJyzWtqoC49ZVcF/tlDBKADgP4K399leRJzm9CtH2oG/WYM8O1H8xjKAo7j++wk cLFA== X-Gm-Message-State: AOAM532dz1GBxugNNy6ZCUEWus+tEew16FYM+N4xpPsd630ev1GMOQKE p/AcOCLKPd+buSUN0haR9043w+Wg4scuMvas6WJsEg== X-Google-Smtp-Source: ABdhPJxsMhmppLIPhrb1MKC0j7eF7QvQ/6Qw0M9XceOp5ZDgbWPzUZwGjcW6ItDdNounSGnzkJEhgvIu+UCRWQn1ipc= X-Received: by 2002:a63:3753:: with SMTP id g19mr14236561pgn.328.1631961084827; Sat, 18 Sep 2021 03:31:24 -0700 (PDT) MIME-Version: 1.0 References: <20210917034815.80264-1-songmuchun@bytedance.com> <20210917034815.80264-3-songmuchun@bytedance.com> In-Reply-To: From: Muchun Song Date: Sat, 18 Sep 2021 18:30:47 +0800 Message-ID: Subject: Re: [PATCH RESEND v2 2/4] mm: hugetlb: replace hugetlb_free_vmemmap_enabled with a static_key To: Barry Song <21cnbao@gmail.com> Cc: Mike Kravetz , Andrew Morton , Oscar Salvador , Michal Hocko , Barry Song , David Hildenbrand , Chen Huang , "Bodeddula, Balasubramaniam" , Jonathan Corbet , Matthew Wilcox , Xiongchun duan , fam.zheng@bytedance.com, Muchun Song , Qi Zheng , linux-doc@vger.kernel.org, LKML , Linux-MM Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Sep 18, 2021 at 12:55 PM Barry Song <21cnbao@gmail.com> wrote: > > On Sat, Sep 18, 2021 at 12:08 AM Muchun Song wrote: > > > > The page_head_if_fake() is used throughout memory management and the > > conditional check requires checking a global variable, although the > > overhead of this check may be small, it increases when the memory > > cache comes under pressure. Also, the global variable will not be > > modified after system boot, so it is very appropriate to use static > > key machanism. > > > > Signed-off-by: Muchun Song > > --- > > include/linux/hugetlb.h | 6 +++++- > > include/linux/page-flags.h | 6 ++++-- > > mm/hugetlb_vmemmap.c | 10 +++++----- > > 3 files changed, 14 insertions(+), 8 deletions(-) > > > > diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h > > index f7ca1a3870ea..ee3ddf3d12cf 100644 > > --- a/include/linux/hugetlb.h > > +++ b/include/linux/hugetlb.h > > @@ -1057,7 +1057,11 @@ static inline void set_huge_swap_pte_at(struct mm_struct *mm, unsigned long addr > > #endif /* CONFIG_HUGETLB_PAGE */ > > > > #ifdef CONFIG_HUGETLB_PAGE_FREE_VMEMMAP > > -extern bool hugetlb_free_vmemmap_enabled; > > +DECLARE_STATIC_KEY_MAYBE(CONFIG_HUGETLB_PAGE_FREE_VMEMMAP_DEFAULT_ON, > > + hugetlb_free_vmemmap_enabled_key); > > +#define hugetlb_free_vmemmap_enabled \ > > + static_key_enabled(&hugetlb_free_vmemmap_enabled_key) > > + > > #else > > #define hugetlb_free_vmemmap_enabled false > > #endif > > diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h > > index 7b1a918ebd43..d68d2cf30d76 100644 > > --- a/include/linux/page-flags.h > > +++ b/include/linux/page-flags.h > > @@ -185,7 +185,8 @@ enum pageflags { > > #ifndef __GENERATING_BOUNDS_H > > > > #ifdef CONFIG_HUGETLB_PAGE_FREE_VMEMMAP > > -extern bool hugetlb_free_vmemmap_enabled; > > +DECLARE_STATIC_KEY_MAYBE(CONFIG_HUGETLB_PAGE_FREE_VMEMMAP_DEFAULT_ON, > > + hugetlb_free_vmemmap_enabled_key); > > > > /* > > * If the feature of freeing some vmemmap pages associated with each HugeTLB > > @@ -204,7 +205,8 @@ extern bool hugetlb_free_vmemmap_enabled; > > */ > > static __always_inline const struct page *page_head_if_fake(const struct page *page) > > { > > - if (!hugetlb_free_vmemmap_enabled) > > + if (!static_branch_maybe(CONFIG_HUGETLB_PAGE_FREE_VMEMMAP_DEFAULT_ON, > > + &hugetlb_free_vmemmap_enabled_key)) > > A question bothering me is that we still have hugetlb_free_vmemmap_enabled > defined as static_key_enabled(&hugetlb_free_vmemmap_enabled_key). > but here you are using static_branch_maybe() with the CONFIG and refer the key > directly. > Do we only need one of them? Or something is wrong? > Yeah, we only need one. But my consideration is that we use static_branch_maybe() for performance sensitive places. So I do not change hugetlb_free_vmemmap_enabled to static_branch_maybe(), this can reduce some codes that need to be updated when the static key is enabled. Actually, the user of hugetlb_free_vmemmap_enabled is not performance sensitive. Thanks. 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=-13.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 9358AC433FE for ; Sat, 18 Sep 2021 10:31:28 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 057EE6112E for ; Sat, 18 Sep 2021 10:31:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 057EE6112E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bytedance.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 9011C6B0071; Sat, 18 Sep 2021 06:31:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8AFFA6B0072; Sat, 18 Sep 2021 06:31:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 776E86B0073; Sat, 18 Sep 2021 06:31:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0144.hostedemail.com [216.40.44.144]) by kanga.kvack.org (Postfix) with ESMTP id 64EBF6B0071 for ; Sat, 18 Sep 2021 06:31:27 -0400 (EDT) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 2602D28DD7 for ; Sat, 18 Sep 2021 10:31:27 +0000 (UTC) X-FDA: 78600327414.24.76D3C04 Received: from mail-pg1-f173.google.com (mail-pg1-f173.google.com [209.85.215.173]) by imf27.hostedemail.com (Postfix) with ESMTP id 1670B70000B5 for ; Sat, 18 Sep 2021 10:31:25 +0000 (UTC) Received: by mail-pg1-f173.google.com with SMTP id 17so12219707pgp.4 for ; Sat, 18 Sep 2021 03:31:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=sqcmPvsXMriA6MZ/1xe+ZZKmWFZFt3hQB0j09TtDJdc=; b=FgcErukEVEa15/A2CYRRQCkwAVaBw080oU1C53GRRDOjSajj4JGHY/qMQf5QUHDrHp 7/p4dzu++xya5ko0h5l7RnTk+oP0w9KVPzS12z27k749zOCFAHiKby5GRG0kXC8NNuhF RE6lYdMSj2/TnwUwYM3IigU3rlGhpoO9+nrfIzlpo/nGqi6zfHhsiS9EkQjmPXy7Rdqv eiG2vyotuIrvjz73vVOHc6PO1VsFSVwc77mU+XCPXn8ASD0Abd+cjqwx3O096ACv3aKA r47pn0AMdRC6GdK1Od9VTXvHQYma34HJuFz9kqFl9h+A4aztodofsu1VQtEb//5DPHxp dQsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=sqcmPvsXMriA6MZ/1xe+ZZKmWFZFt3hQB0j09TtDJdc=; b=BtdrnKRHYPMIjDNaYn0TBrOgFfISP6/kVoMWxTQI4C31sEKZLQi8syarkJ38XqqUMV Ieg43G1kZn1y3gsqIrkJ4rC1CHHheXpMu13q6QPcXFhUlrUHQWi9YbDcE67p+eTHy1BW NrZ+EwsVj7Q0DHwP3O5G7D24kaJYSt6HDC6jQf7dyEPbnMLx7fMm7g6GD77uSRqQqh2S ia05D3vB2VBjnE+iM8ZdLpJHAC+oZeZY5OGAT0vw9Apx0RnsENZ9q37SAt4h5XoytwJT iqY2ZHE4T8yC+s5YcWd1SZhMAh32ucXs2RtEvyCWIGqnVMB3h+4KGzeLBVCn+DGHjyA5 KMYg== X-Gm-Message-State: AOAM533AzeGVbtstjqLJwPSqjP0cZGprCcuo6ToH386M92zex6uywCGH IDTTmimWqIL7XehK+T4nXrH3eHbj4Z3dYIaFxug9cg== X-Google-Smtp-Source: ABdhPJxsMhmppLIPhrb1MKC0j7eF7QvQ/6Qw0M9XceOp5ZDgbWPzUZwGjcW6ItDdNounSGnzkJEhgvIu+UCRWQn1ipc= X-Received: by 2002:a63:3753:: with SMTP id g19mr14236561pgn.328.1631961084827; Sat, 18 Sep 2021 03:31:24 -0700 (PDT) MIME-Version: 1.0 References: <20210917034815.80264-1-songmuchun@bytedance.com> <20210917034815.80264-3-songmuchun@bytedance.com> In-Reply-To: From: Muchun Song Date: Sat, 18 Sep 2021 18:30:47 +0800 Message-ID: Subject: Re: [PATCH RESEND v2 2/4] mm: hugetlb: replace hugetlb_free_vmemmap_enabled with a static_key To: Barry Song <21cnbao@gmail.com> Cc: Mike Kravetz , Andrew Morton , Oscar Salvador , Michal Hocko , Barry Song , David Hildenbrand , Chen Huang , "Bodeddula, Balasubramaniam" , Jonathan Corbet , Matthew Wilcox , Xiongchun duan , fam.zheng@bytedance.com, Muchun Song , Qi Zheng , linux-doc@vger.kernel.org, LKML , Linux-MM Content-Type: text/plain; charset="UTF-8" Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=FgcErukE; spf=pass (imf27.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.215.173 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com; dmarc=pass (policy=none) header.from=bytedance.com X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 1670B70000B5 X-Stat-Signature: astom9pzt6tte6dbqs6x3qup34gshfep X-HE-Tag: 1631961085-72277 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 Sat, Sep 18, 2021 at 12:55 PM Barry Song <21cnbao@gmail.com> wrote: > > On Sat, Sep 18, 2021 at 12:08 AM Muchun Song wrote: > > > > The page_head_if_fake() is used throughout memory management and the > > conditional check requires checking a global variable, although the > > overhead of this check may be small, it increases when the memory > > cache comes under pressure. Also, the global variable will not be > > modified after system boot, so it is very appropriate to use static > > key machanism. > > > > Signed-off-by: Muchun Song > > --- > > include/linux/hugetlb.h | 6 +++++- > > include/linux/page-flags.h | 6 ++++-- > > mm/hugetlb_vmemmap.c | 10 +++++----- > > 3 files changed, 14 insertions(+), 8 deletions(-) > > > > diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h > > index f7ca1a3870ea..ee3ddf3d12cf 100644 > > --- a/include/linux/hugetlb.h > > +++ b/include/linux/hugetlb.h > > @@ -1057,7 +1057,11 @@ static inline void set_huge_swap_pte_at(struct mm_struct *mm, unsigned long addr > > #endif /* CONFIG_HUGETLB_PAGE */ > > > > #ifdef CONFIG_HUGETLB_PAGE_FREE_VMEMMAP > > -extern bool hugetlb_free_vmemmap_enabled; > > +DECLARE_STATIC_KEY_MAYBE(CONFIG_HUGETLB_PAGE_FREE_VMEMMAP_DEFAULT_ON, > > + hugetlb_free_vmemmap_enabled_key); > > +#define hugetlb_free_vmemmap_enabled \ > > + static_key_enabled(&hugetlb_free_vmemmap_enabled_key) > > + > > #else > > #define hugetlb_free_vmemmap_enabled false > > #endif > > diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h > > index 7b1a918ebd43..d68d2cf30d76 100644 > > --- a/include/linux/page-flags.h > > +++ b/include/linux/page-flags.h > > @@ -185,7 +185,8 @@ enum pageflags { > > #ifndef __GENERATING_BOUNDS_H > > > > #ifdef CONFIG_HUGETLB_PAGE_FREE_VMEMMAP > > -extern bool hugetlb_free_vmemmap_enabled; > > +DECLARE_STATIC_KEY_MAYBE(CONFIG_HUGETLB_PAGE_FREE_VMEMMAP_DEFAULT_ON, > > + hugetlb_free_vmemmap_enabled_key); > > > > /* > > * If the feature of freeing some vmemmap pages associated with each HugeTLB > > @@ -204,7 +205,8 @@ extern bool hugetlb_free_vmemmap_enabled; > > */ > > static __always_inline const struct page *page_head_if_fake(const struct page *page) > > { > > - if (!hugetlb_free_vmemmap_enabled) > > + if (!static_branch_maybe(CONFIG_HUGETLB_PAGE_FREE_VMEMMAP_DEFAULT_ON, > > + &hugetlb_free_vmemmap_enabled_key)) > > A question bothering me is that we still have hugetlb_free_vmemmap_enabled > defined as static_key_enabled(&hugetlb_free_vmemmap_enabled_key). > but here you are using static_branch_maybe() with the CONFIG and refer the key > directly. > Do we only need one of them? Or something is wrong? > Yeah, we only need one. But my consideration is that we use static_branch_maybe() for performance sensitive places. So I do not change hugetlb_free_vmemmap_enabled to static_branch_maybe(), this can reduce some codes that need to be updated when the static key is enabled. Actually, the user of hugetlb_free_vmemmap_enabled is not performance sensitive. Thanks.