Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp3563pxa; Tue, 11 Aug 2020 15:33:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxtNFDFy36z6S3wKnWXBuIJjhLkmHbomY10eItFGGGZJzZdL9mXo9wY7BaACfVY68NnCgyD X-Received: by 2002:a17:906:4d89:: with SMTP id s9mr27323684eju.365.1597185183409; Tue, 11 Aug 2020 15:33:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597185183; cv=none; d=google.com; s=arc-20160816; b=Yy1OftMIMNYntJLurB9HCc0xoB8u0iu3naOi//Alm3GC4RMISLL58pwP5MbXZTkWo0 OhmL3bQHX0N6sdoP9J/RoKZ+ZZuPU7T5BeRdQHtET5gS3QSg+UcSZU8/pXl+2YPMqvm+ 46oxuC73FPg/nbbs+p127BJSw4SinCT8/BDnby/Q7NqDdwKdcy37y4S5IEDZ5v/8kXNd CK89ftmm0BmcQUJD6exXDlbR+tDeAfLMKLZFlsO97Nh4w99IpdobWujmLoCsmzBH/nPx dH5DpUDOYW5kohySh8OxJbn56VsWNAK88/5QHkxU7OY5SuTAW0CgDD/ATpQlNimMe4lo CqNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=mjOduT8AuZ6R6LEOxZBqG7mH0Iplqz2qB1EYYrUV9EM=; b=rO0tipQf2s352J1q1KxUZNFTdzq+8jNif3PrLOVXdP4PXgiTnVrMM8mHQsqD6aMpTh wJfr7naZUYlaoGUajX991NAfvVmlzuW9VkZ6Xvm2QoqAYhH8KETSd4r7dsZ1RYPmB0XG OYY6DXoVv2gd+LWdWvk9bmFRg0L0nOSiItsTxhkXhU3SUl3dQ5ASTnrUKqQEjn+pGyw9 DtTlquGJvgY2oPmhkV1OP3RN2vrdDumG6LVIOV5UijRcTy3zKkO8NLjWWTrFyfxlh/3o u3nlPTWjFsnZKLHo40JocGk8Y/SLi20/hTU+Dr7DHAbwJWpFm0dgnwtqsmnsJB3VVC7W gmOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=FdFOy72d; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x16si8100346ejy.527.2020.08.11.15.32.40; Tue, 11 Aug 2020 15:33:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=FdFOy72d; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726271AbgHKW3X (ORCPT + 99 others); Tue, 11 Aug 2020 18:29:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:54724 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725901AbgHKW3W (ORCPT ); Tue, 11 Aug 2020 18:29:22 -0400 Received: from localhost.localdomain (c-73-231-172-41.hsd1.ca.comcast.net [73.231.172.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 257DD206DC; Tue, 11 Aug 2020 22:29:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597184962; bh=822tlIKm9vbmsGGZ1MjxjvGdfOn3MLvDmYXzWXq9CHU=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=FdFOy72dW4BsJMnw79c6FRAVIrHW8aqRZWWTM3HHRUjshu3pEP2iBnWDp8gk+xYaV fNOwVYS/hTwH2rtHO5g8vggkb+3F5yMmBZzJPTjIaUv9lmD547F7/psi8CBVBp7iT0 KtD/o1eYo8kJoeBPfrzg/iwb9/dlRprIK3CeDopA= Date: Tue, 11 Aug 2020 15:29:21 -0700 From: Andrew Morton To: Waiman Long Cc: Peter Zijlstra , Ingo Molnar , Mathieu Desnoyers , Michel Lespinasse , linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] sched, mm: Optimize current_gfp_context() Message-Id: <20200811152921.1d43e34ad7aff928c6c1267f@linux-foundation.org> In-Reply-To: <20200618212936.9776-1-longman@redhat.com> References: <20200618212936.9776-1-longman@redhat.com> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. > > 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 > }