From: Andrew Morton <akpm@linux-foundation.org>
To: Waiman Long <longman@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
Michel Lespinasse <walken@google.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] sched, mm: Optimize current_gfp_context()
Date: Tue, 11 Aug 2020 15:29:21 -0700 [thread overview]
Message-ID: <20200811152921.1d43e34ad7aff928c6c1267f@linux-foundation.org> (raw)
In-Reply-To: <20200618212936.9776-1-longman@redhat.com>
On Thu, 18 Jun 2020 17:29:36 -0400 Waiman Long <longman@redhat.com> wrote:
> The current_gfp_context() converts a number of PF_MEMALLOC_* per-process
> flags into the corresponding GFP_* flags for memory allocation. In
> that function, current->flags is accessed 3 times. That may lead to
> duplicated access of the same memory location.
>
> This is not usually a problem with minimal debug config options on as the
> compiler can optimize away the duplicated memory accesses. With most
> of the debug config options on, however, that may not be the case.
> For example, the x86-64 object size of the __need_fs_reclaim() in a
> debug kernel that calls current_gfp_context() was 309 bytes. With this
> patch applied, the object size is reduced to 202 bytes. This is a saving
> of 107 bytes and will probably be slightly faster too.
>
> ...
>
> --- a/include/linux/sched/mm.h
> +++ b/include/linux/sched/mm.h
> @@ -181,18 +181,20 @@ static inline bool in_vfork(struct task_struct *tsk)
> */
> static inline gfp_t current_gfp_context(gfp_t flags)
> {
> - if (unlikely(current->flags &
> + unsigned int pflags = READ_ONCE(current->flags);
Why use READ_ONCE() here?
> + if (unlikely(pflags &
> (PF_MEMALLOC_NOIO | PF_MEMALLOC_NOFS | PF_MEMALLOC_NOCMA))) {
> /*
> * NOIO implies both NOIO and NOFS and it is a weaker context
> * so always make sure it makes precedence
> */
> - if (current->flags & PF_MEMALLOC_NOIO)
> + if (pflags & PF_MEMALLOC_NOIO)
> flags &= ~(__GFP_IO | __GFP_FS);
> - else if (current->flags & PF_MEMALLOC_NOFS)
> + else if (pflags & PF_MEMALLOC_NOFS)
> flags &= ~__GFP_FS;
> #ifdef CONFIG_CMA
> - if (current->flags & PF_MEMALLOC_NOCMA)
> + if (pflags & PF_MEMALLOC_NOCMA)
> flags &= ~__GFP_MOVABLE;
> #endif
> }
next prev parent reply other threads:[~2020-08-11 22:29 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-18 21:29 Waiman Long
2020-08-11 22:29 ` Andrew Morton [this message]
2020-08-11 23:32 ` Waiman Long
2020-09-18 6:44 ` Xu, Yanfei
2020-09-18 15:18 ` Waiman Long
2020-09-19 14:55 ` Xu, Yanfei
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=20200811152921.1d43e34ad7aff928c6c1267f@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=longman@redhat.com \
--cc=mathieu.desnoyers@efficios.com \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=walken@google.com \
/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
all inboxes | Powered by JetHome®