Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp41867ybt; Thu, 18 Jun 2020 17:40:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxiw8LnESwQvEpxkY3ZAgcd7s0qFYaP2VLInEX2QLO1tltMnj590iRlyT2iCDS1x4DH+jgJ X-Received: by 2002:a17:906:689:: with SMTP id u9mr1217574ejb.13.1592527239350; Thu, 18 Jun 2020 17:40:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592527239; cv=none; d=google.com; s=arc-20160816; b=FZdsMmFL1xM5QZJtjklPY2JmeXh/TQhBHxaXFcDdutL/szv3ii8i2DMZVJrLAxKxMv Ihk/6M3dhNv7L8or05PyxUb/aRiycePH3Ip5jPmGVpH/BXYiEt5vsCs+rj3XMaKj9DhU 6E9qdeRDGWpes/9j9oD+UJEhH0lttC6RhG0AEn8l9WGVxWtoQo5E4MIVf34Bo0WidZxF wtSJWL+JP6FdPmzRx2eK7zwKyd1HcT9lqgClFTCbUL7wH6RuQ1HxcbAqi6kDlBl+n8oe x0dVUs/lsstDwLBqQO1j4NXU4b2Gm+v+jfhFJJ0xwPQZZVtreQfDcGcM2K3BDbWntl4V Xuxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=pSeBMkGoiWF7Uqz9mv4RyLPu5DAlwZeP6Lwc6V30QlY=; b=CrcD5ROj6HteV1ib+VgOjYb1v26Wf9zjKeqaT7CnqNzL6TAy+l//4V7a4zczzamvaR DWszyHsK10fUr451izno2V801dLv5fWH4pUV4LneR39QK0+1ufMla6jJYHN6eo7qbEvW e3WnS1J0aoWuDp3R1MqoqaCxYeEbgtngdpsfL9DGkp5HzVD04jx1LnMFZdN9wlM0WDYH q6IYL/OeoCwD1T4U7LG+LeA8o7uxOxyeofz9QNB0K/xJ2OfhCIN7P+HRxTQ2NRAtVRm9 dJQfu7R63IKqdlJSB2fC3Ug95RJIZ24WETxhFlMW61VYERmnybwLI4F2WfHYzBQPnybu mrvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="T6/H5JPI"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e18si2763159ejd.466.2020.06.18.17.40.17; Thu, 18 Jun 2020 17:40:39 -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=@redhat.com header.s=mimecast20190719 header.b="T6/H5JPI"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730703AbgFRV3y (ORCPT + 99 others); Thu, 18 Jun 2020 17:29:54 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:44380 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730486AbgFRV3x (ORCPT ); Thu, 18 Jun 2020 17:29:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1592515791; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc; bh=pSeBMkGoiWF7Uqz9mv4RyLPu5DAlwZeP6Lwc6V30QlY=; b=T6/H5JPI+RFtoTvNxwr0BDLvUXRnxlwfkjEK5QHFjYTJY6B7xxHiZ5UMP29L0zYumeLSMA j0Xf1bfgQpZNBCPdil1IksZfGR0PZS8hCZQ3BKYvY4gRXl7U3ZDkSFcNqUJhBbr2NFylDk z5c3Avcx0R/cfYnvogsO+5nU3C508vI= 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-489-_HwV8PBmPmiEXunbTnrkpA-1; Thu, 18 Jun 2020 17:29:49 -0400 X-MC-Unique: _HwV8PBmPmiEXunbTnrkpA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 971F78035DF; Thu, 18 Jun 2020 21:29:48 +0000 (UTC) Received: from llong.com (ovpn-118-66.rdu2.redhat.com [10.10.118.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id EE709100238D; Thu, 18 Jun 2020 21:29:44 +0000 (UTC) From: Waiman Long To: Peter Zijlstra , Ingo Molnar , Andrew Morton , Mathieu Desnoyers , Michel Lespinasse Cc: linux-kernel@vger.kernel.org, Waiman Long Subject: [PATCH v2] sched, mm: Optimize current_gfp_context() Date: Thu, 18 Jun 2020 17:29:36 -0400 Message-Id: <20200618212936.9776-1-longman@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Signed-off-by: Waiman Long --- include/linux/sched/mm.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/include/linux/sched/mm.h b/include/linux/sched/mm.h index 480a4d1b7dd8..ff37cd8bbd82 100644 --- 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); + + 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 } -- 2.18.1