lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <a5b29e4d-cc9e-a422-e7b4-e68e0dee37c7@windriver.com>
Date:   Fri, 18 Sep 2020 14:44:15 +0800
From:   "Xu, Yanfei" <yanfei.xu@...driver.com>
To:     Waiman Long <longman@...hat.com>
Cc:     Andrew Morton <akpm@...ux-foundation.org>,
        Peter Zijlstra <peterz@...radead.org>,
        Ingo Molnar <mingo@...hat.com>,
        Mathieu Desnoyers <mathieu.desnoyers@...icios.com>,
        Michel Lespinasse <walken@...gle.com>,
        linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2] sched, mm: Optimize current_gfp_context()

Hi Waiman,

On 8/12/20 6:29 AM, Andrew Morton wrote:
> On Thu, 18 Jun 2020 17:29:36 -0400 Waiman Long <longman@...hat.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.
>>
I have a puzzle about this comment, what's the meaning about "That may
lead to duplicated access of the same memory location". After using
variable 'pflags', will it not duplicated access the same memory
location?
Looking forward to your reply :)

Thanks,
Yanfei

>> 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
>>   	}
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ