linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: Vlastimil Babka <vbabka@suse.cz>,
	Andrew Morton <akpm@linux-foundation.org>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	Alexander Potapenko <glider@google.com>,
	Kees Cook <keescook@chromium.org>,
	Michal Hocko <mhocko@kernel.org>,
	Mateusz Nosek <mateusznosek0@gmail.com>
Subject: Re: [PATCH 2/3] mm, page_poison: use static key more efficiently
Date: Tue, 27 Oct 2020 10:07:28 +0100	[thread overview]
Message-ID: <4e35c52a-800a-4a60-2ef5-dd70a4f774c6@redhat.com> (raw)
In-Reply-To: <20201026173358.14704-3-vbabka@suse.cz>

On 26.10.20 18:33, Vlastimil Babka wrote:
> Commit 11c9c7edae06 ("mm/page_poison.c: replace bool variable with static key")
> changed page_poisoning_enabled() to a static key check. However, the function
> is not inlined, so each check still involves a function call with overhead not
> eliminated when page poisoning is disabled.
> 
> Analogically to how debug_pagealloc is handled, this patch converts
> page_poisoning_enabled() back to boolean check, and introduces
> page_poisoning_enabled_static() for fast paths. Both functions are inlined.
> 
> Also optimize the check that enables page poisoning instead of debug_pagealloc
> for architectures without proper debug_pagealloc support. Move the check to
> init_mem_debugging() to enable a single static key instead of having two
> static branches in page_poisoning_enabled_static().
> 
> Signed-off-by: Vlastimil Babka <vbabka@suse.cz>

[...]

> +/*
> + * For use in fast paths after init_mem_debugging() has run, or when a
> + * false negative result is not harmful when called too early.
> + */
> +static inline bool page_poisoning_enabled_static(void)
> +{
> +	return (static_branch_unlikely(&_page_poisoning_enabled));


return static_branch_unlikely(&_page_poisoning_enabled);

> +}
>   #else
>   static inline bool page_poisoning_enabled(void) { return false; }
> +static inline bool page_poisoning_enabled_static(void) { return false; }
>   static inline void kernel_poison_pages(struct page *page, int numpages,
>   					int enable) { }
>   #endif
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index b168c58ef337..2a1be197649d 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -777,6 +777,17 @@ void init_mem_debugging()
>   		}
>   	}
>   
> +#ifdef CONFIG_PAGE_POISONING
> +	/*
> +	 * Page poisoning is debug page alloc for some arches. If
> +	 * either of those options are enabled, enable poisoning.
> +	 */
> +	if (page_poisoning_enabled() ||
> +			(!IS_ENABLED(CONFIG_ARCH_SUPPORTS_DEBUG_PAGEALLOC) &&
> +			debug_pagealloc_enabled()))

Weird indentation

if (page_poisoning_enabled() ||
     (!IS_ENABLED(CONFIG_ARCH_SUPPORTS_DEBUG_PAGEALLOC) &&
      debug_pagealloc_enabled()))


> +		static_branch_enable(&_page_poisoning_enabled);
> +#endif
> +
>   #ifdef CONFIG_DEBUG_PAGEALLOC
>   	if (!debug_pagealloc_enabled())
>   		return;
> @@ -2208,7 +2219,7 @@ static inline int check_new_page(struct page *page)
>   static inline bool free_pages_prezeroed(void)
>   {
>   	return (IS_ENABLED(CONFIG_PAGE_POISONING_ZERO) &&
> -		page_poisoning_enabled()) || want_init_on_free();
> +		page_poisoning_enabled_static()) || want_init_on_free();
>   }

Apart from that LGTM.

-- 
Thanks,

David / dhildenb


  reply	other threads:[~2020-10-27  9:07 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-26 17:33 [PATCH 0/3] optimize handling of memory debugging parameters Vlastimil Babka
2020-10-26 17:33 ` [PATCH 1/3] mm, page_alloc: do not rely on the order of page_poison and init_on_alloc/free parameters Vlastimil Babka
2020-10-27  9:03   ` David Hildenbrand
2020-10-27  9:58     ` Vlastimil Babka
2020-10-27  9:58       ` David Hildenbrand
2020-10-28  8:31   ` Mike Rapoport
2020-10-26 17:33 ` [PATCH 2/3] mm, page_poison: use static key more efficiently Vlastimil Babka
2020-10-27  9:07   ` David Hildenbrand [this message]
2020-10-30 16:27   ` Luis Chamberlain
2020-10-30 22:56     ` Vlastimil Babka
2020-11-11 13:29       ` Luis Chamberlain
2020-10-26 17:33 ` [PATCH 3/3] mm, page_alloc: reduce static keys in prep_new_page() Vlastimil Babka
2020-10-27  9:10   ` David Hildenbrand
2020-10-27 11:05     ` Vlastimil Babka
2020-10-27 13:32       ` Vlastimil Babka
2020-10-27 17:41         ` Vlastimil Babka
2020-10-28  8:38           ` David Hildenbrand
2020-10-29 17:37         ` Alexander Potapenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4e35c52a-800a-4a60-2ef5-dd70a4f774c6@redhat.com \
    --to=david@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=glider@google.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mateusznosek0@gmail.com \
    --cc=mhocko@kernel.org \
    --cc=vbabka@suse.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).