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=-10.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 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 88EDCC43463 for ; Fri, 18 Sep 2020 15:18:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 038882389F for ; Fri, 18 Sep 2020 15:18:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="eFpw96Zb" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726239AbgIRPSi (ORCPT ); Fri, 18 Sep 2020 11:18:38 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:25058 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726044AbgIRPSi (ORCPT ); Fri, 18 Sep 2020 11:18:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600442316; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8ETZHh7FXeQbyxpDjZYV13SKWV6kJy3ncbq86WYzI9Q=; b=eFpw96ZbjXDuJsMPL1zbb02WbvhCVdZ4wv+/FLDIEJj8fjnf2daUto2k6SiFQ1ZzWbWWuN h6msWZwjdfGALjDb2j0vIBOt0AxOJTQwe1+AUgB1dHeHaIoJx7abCjRDTXeapZOvdhH+pJ Nna7HAEggSawbacvqmcgEm8pXRC+mn8= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-590-VgCgk5PWNmKv1s7PrTgqKA-1; Fri, 18 Sep 2020 11:18:34 -0400 X-MC-Unique: VgCgk5PWNmKv1s7PrTgqKA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1E5ED64098; Fri, 18 Sep 2020 15:18:33 +0000 (UTC) Received: from llong.remote.csb (ovpn-112-232.rdu2.redhat.com [10.10.112.232]) by smtp.corp.redhat.com (Postfix) with ESMTP id 428925C225; Fri, 18 Sep 2020 15:18:32 +0000 (UTC) Subject: Re: [PATCH v2] sched, mm: Optimize current_gfp_context() To: "Xu, Yanfei" Cc: Andrew Morton , Peter Zijlstra , Ingo Molnar , Mathieu Desnoyers , Michel Lespinasse , linux-kernel@vger.kernel.org References: <20200618212936.9776-1-longman@redhat.com> <20200811152921.1d43e34ad7aff928c6c1267f@linux-foundation.org> From: Waiman Long Organization: Red Hat Message-ID: Date: Fri, 18 Sep 2020 11:18:31 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 9/18/20 2:44 AM, Xu, Yanfei wrote: > Hi Waiman, > > On 8/12/20 6:29 AM, Andrew Morton wrote: >> On Thu, 18 Jun 2020 17:29:36 -0400 Waiman Long >> 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 :) That condition usually won't happen on a non-debug kernel. However, if certain debugging capability is turned on, access to current will be compiled into a bunch of checks and memory accesses. So if current is used multiple times, the same set of codes will be duplicated the same number of times slowing down the operation and increasing code size. By accessing current once, we avoid this overhead in a debug kernel. Cheers, Longman