From patchwork Fri Dec 1 07:25:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhiguo Jiang X-Patchwork-Id: 172300 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp940137vqy; Thu, 30 Nov 2023 23:27:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IEg2YhYk+cAz23ZEjT8mm0usqXtGRVvgcPRdXJyrS7+YNDsvRBW+n63g4VP80uKAV11fpZW X-Received: by 2002:a17:903:124c:b0:1ca:7f91:aa5d with SMTP id u12-20020a170903124c00b001ca7f91aa5dmr29372116plh.16.1701415625545; Thu, 30 Nov 2023 23:27:05 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1701415625; cv=pass; d=google.com; s=arc-20160816; b=j3XrcATAunkBTr+kqrWVE+aI2IXsSTdqKC888DX3cdyKGXPDQAhGm3R3HORvzmalVO FFL5H6a5qP53sGE3waAcNM2NdcBp6vSXdxI61w6ZMDDe1OOOoaFDk93RNFEavgiuKcwW XzSnq5qIMr0N8P9dM4tM34cJO4R9r4ihmUVYQB5I8C58sB/UQMQdPBrxKzOqQaoFTDtN nXnaIKbRqftNTYbJ6LHueyyKo6FZtUjv1S8VpeVuvcSrIg07o1W7/0eHWI1fLBjZDXE5 p42fT+QTOfUXI07J4ObYeF33owmjRSKg1UQYbjblX2QII5OH49dYL5N1+slBGszhz99E phAQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :message-id:date:subject:cc:to:from:dkim-signature; bh=tI8oEPip3Q7kwfhovo59YbyVALnN/SAlZobRe3NHgcI=; fh=c2eYxmN/YNr2ouhP31X3BrePKjLzNfOQt6lh5667ppQ=; b=g7wzgCHlEobF5WdukM+HBszLX0cw+z+8fVRmJmaO8MI7fw0x0jTBDztqyvwd6AGmG2 pJSoYzAUofB23Ps9ZfjgUJfWppFu0mHqY80wOxGlk1zE7elYWqw5rk5yxd1lNLbDIP1J ozJGTl0eLM9lGRaX7M/GojXRNJWyWWePuWicho0CaGo8QtWaR4cshSv0JYWj5XlNjrio 76YFpjpBgF0oir8czpohC0ESmIaCSr9L6bf9syc/DLPor7/Qv32TjOgWEW6edakiVeni qJc2sQu0HJi68qixeHwjYW5XalLYTdTJmZjVXS+LdkWWKZ3A48JM7kV8pn0OkL7OFK/6 nLww== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@vivo.com header.s=selector2 header.b=ps4fdZTY; arc=pass (i=1 spf=pass spfdomain=vivo.com dkim=pass dkdomain=vivo.com dmarc=pass fromdomain=vivo.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=vivo.com Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id q1-20020a170902dac100b001c07bac13d0si2891575plx.383.2023.11.30.23.27.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 23:27:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@vivo.com header.s=selector2 header.b=ps4fdZTY; arc=pass (i=1 spf=pass spfdomain=vivo.com dkim=pass dkdomain=vivo.com dmarc=pass fromdomain=vivo.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=vivo.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 777CA807798F; Thu, 30 Nov 2023 23:25:37 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377691AbjLAHZ3 (ORCPT + 99 others); Fri, 1 Dec 2023 02:25:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229505AbjLAHZ2 (ORCPT ); Fri, 1 Dec 2023 02:25:28 -0500 Received: from APC01-SG2-obe.outbound.protection.outlook.com (mail-sgaapc01on2102.outbound.protection.outlook.com [40.107.215.102]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 415E91A4 for ; Thu, 30 Nov 2023 23:25:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Gg7BiY+oXS39jK4AuuQBimVu0gYVmKYtAQ6cd/jc+wfPQ78+9oMRXHkq2vT5VV3+b0mGe4naID50uGfCJ8HHbjbg+98q2meyBr4j+zcDtgOfI/J/uhSASObezBjF2i5w0MiZEs75SOmPJy7K42J1jSQQaFlH767v42PyW8j6dqhrYw7hOzFlu9pyaV0O6b5ipqbBHm7ypmD2e8U9AiW+llJRLrQ+vYLHI6p1JCZ7VN5ZU/UTXpsiLb1Oil24Ar6Pflba2gt+jAXE7cH66CZ65yWcCyHENipGfPOG396E/sdQUgXLFadU+T1vzzrukLUuULRyW4uivTMqQ9gIenTRmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=tI8oEPip3Q7kwfhovo59YbyVALnN/SAlZobRe3NHgcI=; b=S0YtpLEoLevdg5AXea2JUgFeRElPdciPSVBDhby9HX3g2VUsydYBFJW5FUX4bDB/G8uxuh//QkZgV0KtWSmrZqfqEyucuRs/YLdwwLVQ8URqLIO+p7rFej7sl5ET77ZDPSG0SXNMMqwv36rQ5uXy5CMEeMuUzq0YiLyTIQqBgthHA9fGI0zDu6669L8GwndirWLPelwjYcpOMSUWHbIkYfm0lwsqB4Y/ieBg0GybvZ2Ui8YTuetciHXiYPIWU1m1+ONuY5YG6OUpRGO+OSuspYxDe6BuFRu2dAHUKge+ajMxnXIMIz8T4eurLPXhjAfAy/QSiDuGh0kQt+ZcYhXPbA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=vivo.com; dmarc=pass action=none header.from=vivo.com; dkim=pass header.d=vivo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vivo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=tI8oEPip3Q7kwfhovo59YbyVALnN/SAlZobRe3NHgcI=; b=ps4fdZTY6t7974ttrIu1t6CVC5jFLKqldhASi2o6uFwIgPeXF0dxWT5AjiB8ZO/o3P548BigjhaziewY4cvTlqaYuoWgmlRsru1krkDZO+y8b0iCSV/ZgxGtdWcHetEYn7J9Te0QNcY/i4jK6KxyXsSRqJZKlZJ2Gs0++qOUx2/hg2/muwh/Lh3P8uvaJ4xRDW5yXdhKk4bGOnmAS7AUmH1KHB/J66igI8WJ+PRMY4r95nX6OKPGGhHfvPCL+e7BS/MhhTmyklrAFyKkdPbmbW/lWd+rVomXu0o0IPJt2P2cJumZ32grLUEJsA6I6x6zbymKzcEIK+v/es7JKqz7SQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=vivo.com; Received: from JH0PR06MB6849.apcprd06.prod.outlook.com (2603:1096:990:47::12) by PSAPR06MB4166.apcprd06.prod.outlook.com (2603:1096:301:32::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7046.26; Fri, 1 Dec 2023 07:25:27 +0000 Received: from JH0PR06MB6849.apcprd06.prod.outlook.com ([fe80::1be0:ebf0:eb04:6bd3]) by JH0PR06MB6849.apcprd06.prod.outlook.com ([fe80::1be0:ebf0:eb04:6bd3%4]) with mapi id 15.20.7046.015; Fri, 1 Dec 2023 07:25:27 +0000 From: Zhiguo Jiang To: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: opensource.kernel@vivo.com, Zhiguo Jiang Subject: [PATCH] mm: ALLOC_HIGHATOMIC flag allocation issue Date: Fri, 1 Dec 2023 15:25:18 +0800 Message-ID: <20231201072518.1974-1-justinjiang@vivo.com> X-Mailer: git-send-email 2.41.0.windows.3 X-ClientProxiedBy: SG2P153CA0013.APCP153.PROD.OUTLOOK.COM (2603:1096::23) To JH0PR06MB6849.apcprd06.prod.outlook.com (2603:1096:990:47::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: JH0PR06MB6849:EE_|PSAPR06MB4166:EE_ X-MS-Office365-Filtering-Correlation-Id: dc9d3d66-8454-438d-89dd-08dbf23eb063 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: yR52UFA/yIuu95uBN8G0C/l8pP3xQ4OGy9LGBVsmZUZ3Qgn0S0I2bjCHfY2eM/PftzprH88P4xr+0qxjZ3RxXyAADQbGvMaNC27L+qEKnEbgA99ioAoYEDJ8tZP4eFGGdNOyrJmQNZrqlc5sy/6kGLLuRS1G/6Jst2bTSBbTX5qTrIayzLYSSCp14P8UOByuglmjFiO4q0s3H15PSFPjdW1+FV4LGgSNBN2WWqSZ2hGnv6I9O6+M7HlnF0lDFgRCDCxAmhh9g+mt6u2njaJ38smP8/ExOSBrgC9CagrG27DOgdsTOEK080YBJCJbZh2MmBN0p4mCIMc/fYM5xtFrn1w3zZ5/SlI74YgJ7W51W3oifeBwroG4alAnUeqM/pj9L/V+CpDw2BwcqJc0HIyhomK2H2QACwrn81sRjpAElLZB+NoYmI21v9NW3xKZ3Fik2iV/qI9MQvI7Ke1gbIdaZcVNQS70vcRh+2WR2HPl1UE1xrPTiKI99xM8d3nOeVGd4cMoqw4nCazL381INZxUflHwZ4qEuyP3wbjnRNNoEOqzQSTHMldV5ORLKyGLN6gs4NXzZlECay7bejZ44IMKu7NzGJPcSfzbZHUgiy8SCGEwThMqiDXYaTAzUTX3L/aE X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:JH0PR06MB6849.apcprd06.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(366004)(39850400004)(136003)(396003)(346002)(376002)(230922051799003)(1800799012)(64100799003)(186009)(451199024)(86362001)(6512007)(36756003)(38100700002)(5660300002)(107886003)(66556008)(66946007)(66476007)(2616005)(1076003)(2906002)(4326008)(8676002)(38350700005)(8936002)(316002)(83380400001)(41300700001)(26005)(6486002)(478600001)(52116002)(6666004)(6506007);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 2Pr8o/qfTPV2RygtU8mrDUrqEih79wLhLS6lH9mXCKxKYtpfwDuKoQookhyTO01Qf8O6cH2v3gKxMlU30AISppHDuJCJ8ZYSm9AusAUiTv03kGypl0wkbFvl8kAuewS4wW7HQSSFNPQkZN9cxhnnmp//DDZ9sokkuP9jl+7Xt1CIFX8n5dDGuXcx2nsHD1kul3JPkWm6AvybPNsArNRllugPaThNAttGCgW1wui2VQVCVn8smrABG1hQ7wmSNC7ggj9mw0nPBHJpPXt7ElUVptwaakn4AF6BQk8LngsxQ4CKXha2cp7ImOfineNQm1CFMEZYwgv4lrFq3P7EaAQcKA3HTGKyzsue5s8CU69+Qh9P8ARDW3zWZxBgvkYsrocNvg66eEWKPBrHl4AUhPPW6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HxyhCuvWwyorxn/VE5n9vFyKuixoO9K4sURucbZEu73KrcMNbRcoY2q6CIqTviJTW91tono6f9YHVKnkVzmHnS7Rj+w+6Xr8JSYuONJ1bW8686+KuCKme+/ApDdlI X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: dc9d3d66-8454-438d-89dd-08dbf23eb063 X-MS-Exchange-CrossTenant-AuthSource: JH0PR06MB6849.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Dec 2023 07:25:27.3603 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 923e42dc-48d5-4cbe-b582-1a797a6412ed X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: lrBPZ/lyVN2Z+LjH/fQdu2EVqfrKRkgef6Ih5rOVL4dSH4XDMaLEHt3nWCjKcDe3ml0xQ/Ul5r0MRJVOxShWYg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PSAPR06MB4166 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 30 Nov 2023 23:25:37 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784063590988912138 X-GMAIL-MSGID: 1784063590988912138 In case that alloc_flags contains ALLOC_HIGHATOMIC and alloc order is order1/2/3/10 in rmqueue(), if pages are allocated from pcplist successfully, a free pageblock will be also moved from the allocated migratetype freelist to MIGRATE_HIGHATOMIC freelist, rather than alloc from MIGRATE_HIGHATOMIC freelist first. So this will result in an increasing number of pages on the buddy highatomic freelist and an increased risk of allocation failure on other migrate freelists in buddy. Currently the sequence of ALLOC_HIGHATOMIC allocation is: pcplist --> rmqueue_bulk() --> rmqueue_buddy() MIGRATE_HIGHATOMIC --> rmqueue_buddy() allocated migratetype. Due to the fact that requesting pages from the pcplist is faster than buddy, the sequence of the ALLOC_HIGHATOMIC allocation is modified: pcplist --> rmqueue_buddy() MIGRATE_HIGHATOMIC --> rmqueue_buddy() allocation migratetype. This patch can solve the failure problem of allocating other migrate type pages due to the excessive MIGRATE_HIGHATOMIC freelist reserved pages. In comparative testing, cat /proc/pagetypeinfo and the HighAtomic freelist size is: Test without this patch: Node 0, zone Normal, type HighAtomic 2369 771 138 15 0 0 0 0 0 0 0 Test with this patch: Node 0, zone Normal, type HighAtomic 206 82 4 2 1 0 0 0 0 0 0 Signed-off-by: Zhiguo Jiang --- mm/page_alloc.c | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) mode change 100644 => 100755 mm/page_alloc.c diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 2f646773a934..95de1204e1e5 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -2861,11 +2861,20 @@ struct page *__rmqueue_pcplist(struct zone *zone, unsigned int order, int batch = nr_pcp_alloc(pcp, zone, order); int alloced; + /* + * If pcplist is empty and alloc_flags + * contains ALLOC_HIGHATOMIC, alloc from + * buddy highatomic freelist first. + */ + if (alloc_flags & ALLOC_HIGHATOMIC) + goto out; + alloced = rmqueue_bulk(zone, order, batch, list, migratetype, alloc_flags); pcp->count += alloced << order; +out: if (unlikely(list_empty(list))) return NULL; } @@ -2929,7 +2938,7 @@ static inline struct page *rmqueue(struct zone *preferred_zone, struct zone *zone, unsigned int order, gfp_t gfp_flags, unsigned int alloc_flags, - int migratetype) + int migratetype, bool *highatomic) { struct page *page; @@ -2949,6 +2958,24 @@ struct page *rmqueue(struct zone *preferred_zone, page = rmqueue_buddy(preferred_zone, zone, order, alloc_flags, migratetype); + /* + * The high-order atomic allocation pageblock reserved: + * + * If the high-order atomic page is allocated from pcplist, + * the highatomic pageblock does not need to be reserved, + * which can avoid migrating an increasing number of pages + * into buddy highatomic freelist and leading to an increased + * risk of allocation failure on other migrate freelists in + * buddy. + * + * If the high-order atomic page is allocated from buddy + * highatomic freelist, regardless of whether the allocation + * is successful or not, the highatomic pageblock can try to + * be reserved. + */ + if (unlikely(alloc_flags & ALLOC_HIGHATOMIC)) + *highatomic = true; + out: /* Separate test+clear to avoid unnecessary atomics */ if ((alloc_flags & ALLOC_KSWAPD) && @@ -3219,6 +3246,7 @@ get_page_from_freelist(gfp_t gfp_mask, unsigned int order, int alloc_flags, struct pglist_data *last_pgdat = NULL; bool last_pgdat_dirty_ok = false; bool no_fallback; + bool highatomic = false; retry: /* @@ -3350,7 +3378,7 @@ get_page_from_freelist(gfp_t gfp_mask, unsigned int order, int alloc_flags, try_this_zone: page = rmqueue(ac->preferred_zoneref->zone, zone, order, - gfp_mask, alloc_flags, ac->migratetype); + gfp_mask, alloc_flags, ac->migratetype, &highatomic); if (page) { prep_new_page(page, order, gfp_mask, alloc_flags); @@ -3358,7 +3386,7 @@ get_page_from_freelist(gfp_t gfp_mask, unsigned int order, int alloc_flags, * If this is a high-order atomic allocation then check * if the pageblock should be reserved for the future */ - if (unlikely(alloc_flags & ALLOC_HIGHATOMIC)) + if (unlikely(highatomic)) reserve_highatomic_pageblock(page, zone); return page;