Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp860302pxb; Fri, 22 Apr 2022 12:51:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwRG2+VH08U4HszjBPz7k/wsDctq1sCWcMze+bNTvxQFYDX3JAhCBqPcIxCRla4gBmmNgEW X-Received: by 2002:a17:902:d3cb:b0:15b:a002:d80c with SMTP id w11-20020a170902d3cb00b0015ba002d80cmr5989415plb.108.1650657060519; Fri, 22 Apr 2022 12:51:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650657060; cv=none; d=google.com; s=arc-20160816; b=B7zn4BBUWXR5XaclDCEyNAzmA1PUkKsdGE9Fjo4qMARFMtNMgdL5bXFmIKHkXCGmMZ UKDbF73ISey/qvFuclmZUwos0tAD4gHniajfM4wsq5+a3r2BjxI5Vh5WjGGqKnyxqALj AgKII2TtWWP0LjNHFiIncG6DHzWBacRjfq6Gz8cJKcSsCl3WXybdz1xo96HQTi/niRM9 e/qiKYZmElENb2rjiwk8vm4FzuDOiZYTFl9+AcrDjJ1uv+/Ju/kYRpnSZmzrkxs85ybP xLUzuepLIBZIS4IbS0pIRlXEYr5+ir+qYMr+4LlSkfZX7Uez9O05edlXtqMP+LpmuKlF gzYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=gWUfslv3yfiAbWgvOAL6zRxNnwAOJbgOtrRLOryq0GE=; b=i3/08EYlxHIZPouaN5tafBvjPeNh8bQ8codHtT9kd8AyCcSNJXDQo1R4xR6pIAE8+o fSEy/WpVXTtnWcQLoIMWBxLXgZE7yAdemD3DeIwmckC06Udco9XK/zW0D8PyzcvgAjRb ApUILhoK0Ti7J+pSu1l/hfVZX/qpjgDrgxBBoN25m2/qB7SFwatvi6JXYtyhHA4+mfH1 bHqxuGk21Uo+Fxjb+ccJX6kYtUe+SolJB4xHtcQUhIcFw0uTtnqJ6gObtVsnUw7A0H6A i4ixIy+jB5+Ysvgcvg9n94PQ08QBLHd9u2LDVqS7DxoG5QPrI3oa/wv0u+mCcmToQi88 z7fw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id v20-20020a631514000000b003a292c2149asi9614949pgl.164.2022.04.22.12.51.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Apr 2022 12:51:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0B71F13662A; Fri, 22 Apr 2022 11:52:35 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377493AbiDTKJv (ORCPT + 99 others); Wed, 20 Apr 2022 06:09:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377492AbiDTKJs (ORCPT ); Wed, 20 Apr 2022 06:09:48 -0400 X-Greylist: delayed 440 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Wed, 20 Apr 2022 03:07:00 PDT Received: from outbound-smtp06.blacknight.com (outbound-smtp06.blacknight.com [81.17.249.39]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B74F61D0F5 for ; Wed, 20 Apr 2022 03:07:00 -0700 (PDT) Received: from mail.blacknight.com (pemlinmail04.blacknight.ie [81.17.254.17]) by outbound-smtp06.blacknight.com (Postfix) with ESMTPS id 35628C2B9E for ; Wed, 20 Apr 2022 10:59:39 +0100 (IST) Received: (qmail 10849 invoked from network); 20 Apr 2022 09:59:39 -0000 Received: from unknown (HELO morpheus.112glenside.lan) (mgorman@techsingularity.net@[84.203.198.246]) by 81.17.254.9 with ESMTPA; 20 Apr 2022 09:59:38 -0000 From: Mel Gorman To: Nicolas Saenz Julienne Cc: Marcelo Tosatti , Vlastimil Babka , Michal Hocko , LKML , Linux-MM , Mel Gorman Subject: [PATCH 2/6] mm/page_alloc: Use only one PCP list for THP-sized allocations Date: Wed, 20 Apr 2022 10:59:02 +0100 Message-Id: <20220420095906.27349-3-mgorman@techsingularity.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220420095906.27349-1-mgorman@techsingularity.net> References: <20220420095906.27349-1-mgorman@techsingularity.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The per_cpu_pages is cache-aligned on a standard x86-64 distribution configuration but a later patch will add a new field which would push the structure into the next cache line. Use only one list to store THP-sized pages on the per-cpu list. This assumes that the vast majority of THP-sized allocations are GFP_MOVABLE but even if it was another type, it would not contribute to serious fragmentation that potentially causes a later THP allocation failure. Align per_cpu_pages on the cacheline boundary to ensure there is no false cache sharing. After this patch, the structure sizing is; struct per_cpu_pages { int count; /* 0 4 */ int high; /* 4 4 */ int batch; /* 8 4 */ short int free_factor; /* 12 2 */ short int expire; /* 14 2 */ struct list_head lists[13]; /* 16 208 */ /* size: 256, cachelines: 4, members: 6 */ /* padding: 32 */ } __attribute__((__aligned__(64))); Signed-off-by: Mel Gorman --- include/linux/mmzone.h | 11 +++++++---- mm/page_alloc.c | 4 ++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index 962b14d403e8..abe530748de6 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -358,15 +358,18 @@ enum zone_watermarks { }; /* - * One per migratetype for each PAGE_ALLOC_COSTLY_ORDER plus one additional - * for pageblock size for THP if configured. + * One per migratetype for each PAGE_ALLOC_COSTLY_ORDER. One additional list + * for THP which will usually be GFP_MOVABLE. Even if it is another type, + * it should not contribute to serious fragmentation causing THP allocation + * failures. */ #ifdef CONFIG_TRANSPARENT_HUGEPAGE #define NR_PCP_THP 1 #else #define NR_PCP_THP 0 #endif -#define NR_PCP_LISTS (MIGRATE_PCPTYPES * (PAGE_ALLOC_COSTLY_ORDER + 1 + NR_PCP_THP)) +#define NR_LOWORDER_PCP_LISTS (MIGRATE_PCPTYPES * (PAGE_ALLOC_COSTLY_ORDER + 1)) +#define NR_PCP_LISTS (NR_LOWORDER_PCP_LISTS + NR_PCP_THP) /* * Shift to encode migratetype and order in the same integer, with order @@ -392,7 +395,7 @@ struct per_cpu_pages { /* Lists of pages, one per migrate type stored on the pcp-lists */ struct list_head lists[NR_PCP_LISTS]; -}; +} ____cacheline_aligned_in_smp; struct per_cpu_zonestat { #ifdef CONFIG_SMP diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 63976ad4b7f1..ed2deb93a758 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -648,7 +648,7 @@ static inline unsigned int order_to_pindex(int migratetype, int order) #ifdef CONFIG_TRANSPARENT_HUGEPAGE if (order > PAGE_ALLOC_COSTLY_ORDER) { VM_BUG_ON(order != pageblock_order); - base = PAGE_ALLOC_COSTLY_ORDER + 1; + return NR_LOWORDER_PCP_LISTS; } #else VM_BUG_ON(order > PAGE_ALLOC_COSTLY_ORDER); @@ -662,7 +662,7 @@ static inline int pindex_to_order(unsigned int pindex) int order = pindex / MIGRATE_PCPTYPES; #ifdef CONFIG_TRANSPARENT_HUGEPAGE - if (order > PAGE_ALLOC_COSTLY_ORDER) + if (pindex == NR_LOWORDER_PCP_LISTS) order = pageblock_order; #else VM_BUG_ON(order > PAGE_ALLOC_COSTLY_ORDER); -- 2.34.1