From patchwork Wed Mar 4 16:21:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mateusz Nosek X-Patchwork-Id: 11420379 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 63FF217E0 for ; Wed, 4 Mar 2020 16:22:00 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2FFC221775 for ; Wed, 4 Mar 2020 16:22:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="EO+9SIDW" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2FFC221775 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 56BFC6B0003; Wed, 4 Mar 2020 11:21:59 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 51C0C6B0005; Wed, 4 Mar 2020 11:21:59 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 458E36B0006; Wed, 4 Mar 2020 11:21:59 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0134.hostedemail.com [216.40.44.134]) by kanga.kvack.org (Postfix) with ESMTP id 2F26F6B0003 for ; Wed, 4 Mar 2020 11:21:59 -0500 (EST) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id C486A180AD802 for ; Wed, 4 Mar 2020 16:21:58 +0000 (UTC) X-FDA: 76558196316.13.heat96_85aa63ddd524a X-Spam-Summary: 2,0,0,8a544bf18ea494db,d41d8cd98f00b204,mateusznosek0@gmail.com,,RULES_HIT:41:355:379:541:800:960:973:981:988:989:1260:1345:1437:1535:1543:1711:1730:1747:1777:1792:2198:2199:2393:2553:2559:2562:2693:2910:3138:3139:3140:3141:3142:3355:3865:3866:3867:3868:3870:3871:3874:4117:4321:4362:5007:6261:6653:7514:7576:9413:9592:10004:11026:11473:11658:11914:12043:12296:12297:12438:12517:12519:12555:12679:12895:13255:14096:14181:14394:14721:21080:21444:21451:21627:21666:30012:30054:30090,0,RBL:209.85.167.66:@gmail.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: heat96_85aa63ddd524a X-Filterd-Recvd-Size: 6033 Received: from mail-lf1-f66.google.com (mail-lf1-f66.google.com [209.85.167.66]) by imf01.hostedemail.com (Postfix) with ESMTP for ; Wed, 4 Mar 2020 16:21:58 +0000 (UTC) Received: by mail-lf1-f66.google.com with SMTP id w27so2026560lfc.1 for ; Wed, 04 Mar 2020 08:21:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=O24KKwE3bCNAXE/AxZ3sPbGF9KCAkXxe3BjPmV9rOX0=; b=EO+9SIDWbT6LZnKAEg2mm+Jw4k8sOnlYlZ9tgunN/Co1d9dVdLGkLI6P4phqXvRH8/ 59o564h/u1w1zeeO2HPhyo1ELWswxne/hSkVEKyTpVoLPDAg1aiNQ8setYoGCHqKtEc3 JSpS+/yZMdwQiEMARmvBCkfZ/zqUlz7Tr0gdbMwjBHivE/DEbE6ii8m1FoaonnMobmH4 ncCniwywa69Ox/6RE8S2td0tCDdlRJadj+gfK4N5eJxjCMFayAqYWgnyuC0BMFww2zRW JGGJSh1+MmRA0F7wC7rALOi/wuMvoB47ZTXkGlzXLwBjRNdmMD9OcJhsbMKz5euWE4y8 /iaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=O24KKwE3bCNAXE/AxZ3sPbGF9KCAkXxe3BjPmV9rOX0=; b=K6Ll8HbXnhrNWnwN3oEt4Duzx0o8LhpV8aB0l+fCVGGihIX5WNYHYOC6/hgy5g0g2j snBCCx3ezj7WWS9IDmzgOqyInW9sneFAi0XglsVZG9J4nxh6K3G7TV1Y31cn9DQHHL8r LX2tf8DBxVoQyGUUOG7UYChlRKWpdxMnxWmnp+Un5DjgEmpheJLmirAFqBy3Uh2tAatB +ViGQ4aw9Te1YuqyId4qRN47WN70wfSc4f/m9pX238VkCJUtD9CmqiFkGPVxgubizgUU YxZBrBstiEFesZDl4W+P95dJJiiIUSDsy4hjSZzJkfgW6CD69sgKq8kQivINTEh2IsEO pxLQ== X-Gm-Message-State: ANhLgQ0Pwz9ZhsELCBUuMpQSFqfwgYgQqKFTvVZdlWeg9rnb2ssPxx5S lR2ky57Wc3VOVP2AXWJWjlGjipd6dKw= X-Google-Smtp-Source: ADFU+vu8XOFeWJMwK9k3vQ9qTzW4w5iJib5+Lj2Ig0FCvGWB9de+h99yB+IrqJPyd6/c0UmhasAToA== X-Received: by 2002:ac2:5f62:: with SMTP id c2mr2517936lfc.207.1583338916346; Wed, 04 Mar 2020 08:21:56 -0800 (PST) Received: from localhost.localdomain (188.146.98.66.nat.umts.dynamic.t-mobile.pl. [188.146.98.66]) by smtp.gmail.com with ESMTPSA id w24sm13445961ljh.26.2020.03.04.08.21.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Mar 2020 08:21:55 -0800 (PST) From: mateusznosek0@gmail.com To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Mateusz Nosek , akpm@linux-foundation.org, vbabka@suse.cz, mgorman@techsingularity.net Subject: [PATCH v2] mm: Micro-optimisation: Save two branches on hot - page allocation path Date: Wed, 4 Mar 2020 17:21:18 +0100 Message-Id: <20200304162118.14784-1-mateusznosek0@gmail.com> X-Mailer: git-send-email 2.17.1 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Mateusz Nosek This patch makes ALLOC_KSWAPD equal to __GFP_KSWAPD_RECLAIM (cast to int). Thanks to that code like: if (gfp_mask & __GFP_KSWAPD_RECLAIM) alloc_flags |= ALLOC_KSWAPD; can be changed to: alloc_flags |= (__force int) (gfp_mask &__GFP_KSWAPD_RECLAIM); Thanks to this one branch less is generated in the assembly. In case of ALLOC_KSWAPD flag two branches are saved, first one in code that always executes in the beginning of page allocation and the second one in loop in page allocator slowpath. Signed-off-by: Mateusz Nosek Acked-by: Vlastimil Babka Acked-by: Mel Gorman --- mm/internal.h | 2 +- mm/page_alloc.c | 22 ++++++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/mm/internal.h b/mm/internal.h index 86372d164476..f089fc98fc08 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -535,7 +535,7 @@ unsigned long reclaim_clean_pages_from_list(struct zone *zone, #else #define ALLOC_NOFRAGMENT 0x0 #endif -#define ALLOC_KSWAPD 0x200 /* allow waking of kswapd */ +#define ALLOC_KSWAPD 0x800 /* allow waking of kswapd, __GFP_KSWAPD_RECLAIM set */ enum ttu_flags; struct tlbflush_unmap_batch; diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 79e950d76ffc..eed9f790eef7 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -3609,10 +3609,13 @@ static bool zone_allows_reclaim(struct zone *local_zone, struct zone *zone) static inline unsigned int alloc_flags_nofragment(struct zone *zone, gfp_t gfp_mask) { - unsigned int alloc_flags = 0; + unsigned int alloc_flags; - if (gfp_mask & __GFP_KSWAPD_RECLAIM) - alloc_flags |= ALLOC_KSWAPD; + /* + * __GFP_KSWAPD_RECLAIM is assumed to be the same as ALLOC_KSWAPD + * to save a branch. + */ + alloc_flags = (__force int) (gfp_mask & __GFP_KSWAPD_RECLAIM); #ifdef CONFIG_ZONE_DMA32 if (!zone) @@ -4248,8 +4251,13 @@ gfp_to_alloc_flags(gfp_t gfp_mask) { unsigned int alloc_flags = ALLOC_WMARK_MIN | ALLOC_CPUSET; - /* __GFP_HIGH is assumed to be the same as ALLOC_HIGH to save a branch. */ + /* + * __GFP_HIGH is assumed to be the same as ALLOC_HIGH + * and __GFP_KSWAPD_RECLAIM is assumed to be the same as ALLOC_KSWAPD + * to save two branches. + */ BUILD_BUG_ON(__GFP_HIGH != (__force gfp_t) ALLOC_HIGH); + BUILD_BUG_ON(__GFP_KSWAPD_RECLAIM != (__force gfp_t) ALLOC_KSWAPD); /* * The caller may dip into page reserves a bit more if the caller @@ -4257,7 +4265,8 @@ gfp_to_alloc_flags(gfp_t gfp_mask) * policy or is asking for __GFP_HIGH memory. GFP_ATOMIC requests will * set both ALLOC_HARDER (__GFP_ATOMIC) and ALLOC_HIGH (__GFP_HIGH). */ - alloc_flags |= (__force int) (gfp_mask & __GFP_HIGH); + alloc_flags |= (__force int) + (gfp_mask & (__GFP_HIGH | __GFP_KSWAPD_RECLAIM)); if (gfp_mask & __GFP_ATOMIC) { /* @@ -4274,9 +4283,6 @@ gfp_to_alloc_flags(gfp_t gfp_mask) } else if (unlikely(rt_task(current)) && !in_interrupt()) alloc_flags |= ALLOC_HARDER; - if (gfp_mask & __GFP_KSWAPD_RECLAIM) - alloc_flags |= ALLOC_KSWAPD; - #ifdef CONFIG_CMA if (gfpflags_to_migratetype(gfp_mask) == MIGRATE_MOVABLE) alloc_flags |= ALLOC_CMA;