lkml.org 
[lkml]   [2020]   [Aug]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH v2] sched, mm: Optimize current_gfp_context()
From
Date
On 8/11/20 6:29 PM, Andrew Morton wrote:
> 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?

It was a change suggested by PeterZ. He said without the READ_ONCE(),
the compiler may still choose to access current->flags multiple times
instead of just reading it once. I think he is right and so I made the
change.

Cheers,
Longman

\
 
 \ /
  Last update: 2020-08-12 01:34    [W:1.221 / U:0.548 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site