From patchwork Thu Nov 23 14:50:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhiguo Jiang X-Patchwork-Id: 168971 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce62:0:b0:403:3b70:6f57 with SMTP id o2csp499833vqx; Thu, 23 Nov 2023 06:51:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IFZgjanQka3cY/oM3LYc8RXq9KzrsPE4ILBf1vJzQ5EdszmLKcs4NeFyLXxeGxVK/A4awTn X-Received: by 2002:aca:f07:0:b0:3b6:3d44:4d75 with SMTP id 7-20020aca0f07000000b003b63d444d75mr5994958oip.22.1700751093491; Thu, 23 Nov 2023 06:51:33 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1700751093; cv=pass; d=google.com; s=arc-20160816; b=l7RW6/4eaneyvb6veWquuZVTwMwHn4NGjtt9lS2yNIZ1DgheqJpqncim19cfvCTIcv hb5v/9jO1MRq90vWJwR6pYDti60J0tkdul229lFmJgTS02YI5i9OYvIyvGiDiTVZPJa7 gPo6FHXX+c5/XQLlhoG8s7K25THg+FBE0W310ilChXqYuMpASdX/bXf3i2vkhgOr/kqB vWGDaUIueo7K5ioHYl9RB+OYn/W0xiXZV+FAto8kxCNBGqdzIb9GVwitAgBY39rj3H+N stZw6TS/6B8FXYGCeIbERSz1tHiCzEYxzEQh1QmKMHrDSq8z1bPFUhgI7uDFqZW60Vv9 85wg== 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=OTIqclJ02i6ZeRgQeohCcDYE1go2oPIXQLh0H/48ifA=; fh=eiGAgBO6+q8PrwPCw965L9mIh4ObJTDqurq7CZUD4jA=; b=UETWvWn0UDkkE5TZBZPyz3vIv+Z8pOm1ItFvOW4n7bfu9uSfoosI+C8diV0nOyNLU4 Wj8XW8NZzR8ZxRlUW9fnP+uDszSdgZyZHH2R+nyNhrEybTR1Owl87UBjVAa/VaI7FZ9y MHymYzaNCCXI3EzDVyjsHhErKnC6t70ntHUE8yJ6wjyLUU+4Q7WurEVi4W4LqYss+o4H ouGJYkt6N/tWIGsLuPCTvOoz9Uo6ROgAjmyn9KDrmJka4v18gECkLHXqeKyCyktE8QIU vS3OJ8aG7edb5mF37KTM7KHaXWh7AIHF30TXb32m74un8Ev1ol+rUw6m9bYH+rZLAa3G 1H3A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@vivo.com header.s=selector2 header.b=QuE0QEHf; 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.35 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 groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id z20-20020a63d014000000b005b3b86ab19csi1422211pgf.107.2023.11.23.06.51.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Nov 2023 06:51:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@vivo.com header.s=selector2 header.b=QuE0QEHf; 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.35 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 groat.vger.email (Postfix) with ESMTP id 5178B83249A8; Thu, 23 Nov 2023 06:51:28 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345912AbjKWOvI (ORCPT + 99 others); Thu, 23 Nov 2023 09:51:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345882AbjKWOvH (ORCPT ); Thu, 23 Nov 2023 09:51:07 -0500 Received: from APC01-SG2-obe.outbound.protection.outlook.com (mail-sgaapc01on2128.outbound.protection.outlook.com [40.107.215.128]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5892D44 for ; Thu, 23 Nov 2023 06:51:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MqU6CjSBqSXbXWVMLwq+4Pcs0k7UreyKZ8A5fstHtKM+ZWSIMAQnqCpnJwAPe3GBSTItvqjuHTKZSlkVgjJS9d5YpFrNK6hcVnTqXR0Ads7QIy179ADPixUHpzTLNe0eUvrj2Q3Vx5aq1ipAX2cBc9UWr+kgI5ZBT7RyRd1WlX2yoIboafb23FswYXLnnYuVe+/k6Dc3N128ZwcsWkzm1VVIeuEntqBBJT52F2O4AAmHXVtZ+VAawaqK5/XS5JtIsPSQS27+jvKrWzjEuLffFwZApn/JIXCO7ZdOHJeA1f2yGGNPG+AbGl+Bd+pKXLXG9qYSQGDkwv+5K9VCSkRZpg== 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=OTIqclJ02i6ZeRgQeohCcDYE1go2oPIXQLh0H/48ifA=; b=IZ7SQLd8DgjpjuVcSPYOYqPcxGBKVoCcMQeQAP9G5EXVAuGgRYS0tmMsGf6WcmV8R4hCOGstBgXV2+YixUCZAuitsxZKSw+3dMq1HONekJtjlcwUHu10IAb2O+0MICxE1tkvpCjZH5W0TkU8Hk9LvNjGc9d1M36yJZi29gO2RR5/qD1x1gpchea30Q5hb4L7PvRDld6DKkklKAmDb1mArPXkEqpqIF2fNvyGA/zPWGMP6D3OVMMhuMDKYyNiD2rIAHd7u27CtIiXJwxlqLmFxBBoQQlBCUJjFnHkOTjeJIQmAfxQ8D/M5jWixhDm5/p2MpT/gvXT6rkJapztmAoREw== 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=OTIqclJ02i6ZeRgQeohCcDYE1go2oPIXQLh0H/48ifA=; b=QuE0QEHf9we8vOWJPWshwkMsXaKN3qFzG9nGdwoBW+RaiZ5mzqAJRjAOlq1ZuzqfTAAfjUFHf09xVgSAe4jN8GCD+yf0KSHxggoDPvaQgWrlntL/vaEVVhqyyPiowTqYFxFFacYZh+Kiw4ghbLikhu+Dd+cdjBQXpjTFCqvCiq0J4sq2Viv6hKuLD2g7M6cWXFMxCZK6wKwCPS2mgNQeBa1gHRK5Ny2/r+oaD8D/1DENKi4SZnCJouU5RlTHsxlG+okF/+uMNu6iY4xGlZrK5AD22oW9rCEwRqzQUtfowEpPn+zkqhqvwiJ8OQxvAzvsKkBtRiQsEjpqzURVBjtuLw== 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 SEZPR06MB5762.apcprd06.prod.outlook.com (2603:1096:101:ac::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7025.18; Thu, 23 Nov 2023 14:51:02 +0000 Received: from JH0PR06MB6849.apcprd06.prod.outlook.com ([fe80::bdde:31ee:f13c:79fb]) by JH0PR06MB6849.apcprd06.prod.outlook.com ([fe80::bdde:31ee:f13c:79fb%4]) with mapi id 15.20.7025.017; Thu, 23 Nov 2023 14:51:01 +0000 From: Zhiguo Jiang To: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Matthew Wilcox , Johannes Weiner , opensource.kernel@vivo.com, Zhiguo Jiang Subject: [PATCH] mm: ALLOC_HIGHATOMIC flag allocation issue Date: Thu, 23 Nov 2023 22:50:52 +0800 Message-ID: <20231123145052.613-1-justinjiang@vivo.com> X-Mailer: git-send-email 2.41.0.windows.3 X-ClientProxiedBy: SI2PR02CA0051.apcprd02.prod.outlook.com (2603:1096:4:196::10) To JH0PR06MB6849.apcprd06.prod.outlook.com (2603:1096:990:47::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: JH0PR06MB6849:EE_|SEZPR06MB5762:EE_ X-MS-Office365-Filtering-Correlation-Id: 26e58b87-1099-4013-31a3-08dbec339bf4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: TtAiuyJo86hWd1L9U8T1vxrR8dDGY9pCyd2OiFbr2S98pV9XuVkDy1ZIxpBGYCmc8f26t5r0dtU1Rl/KAdOrd1eNFp4hHC3+0zPpiGPKX+QXZLN93096WHuSv3pTsu9kr6WECHo/H1YY2houB0fAYGKnnFXRcbhcytGsYY4d6++qRNgOCsTEF1IiPd6/GRhs2BGjbGe8+UN6nbvHrtjyRa4fWF3vfbbhHrjY/dJ8+k0eQrkVTXzApIzs8cF0iBIOB82H8UyO5bLYPeBsCLcH+dtk9zhgkGc9M4oKAoltlPvCB+ETU6jmaun8QpRxkLNP4jufFqy/YR/Nbl/CyH0Un/r0t0JNiez7F6Kfq3vrj9SiMwYUwx0zZdDLRwYOTbdkQacQbkqTrmSVSzKS5VnGF9YTzRWgPWiBGSpd6BQJjG8mrEIZ4DzRLPQVEQ+RhXbpfxSXs3qWAlDql6wsS67vSxEP4cNq9mLWb4tBu92zpSepAhrNGrqdEyYYPlEFoJOVUk8cs3Wbu0dhrCWqNobNEy3aEqQ3Hi7mMvZfugwTUV4trnfk+rTdgwz66khVLVW9TKKu6jYV/P5ToFoW0WhalrWxgFodyiAQSeALGnGMgEFi+0DR6+eVnSRZmoMhTNPn 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)(396003)(376002)(346002)(136003)(39860400002)(230922051799003)(186009)(451199024)(1800799012)(64100799003)(83380400001)(107886003)(6512007)(6666004)(52116002)(1076003)(2616005)(26005)(38100700002)(6506007)(4326008)(8676002)(8936002)(316002)(2906002)(41300700001)(478600001)(6486002)(5660300002)(54906003)(66946007)(66556008)(66476007)(86362001)(36756003)(38350700005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: CmphaCVlr+iX+McgNOk+6qsvCUUINPKbfaRQQh23dHldjFD3Ooc6qxOF4i4qpgKiewOqvVfeP5r2OKzBhZR0GQc3ugZenvCuYZc7gcifvTvTGF9vZv1FtTF7gmbnYlvCpWhf1JMmcS0KSOhd4pwPSrQjl0uDpa7Pl61hMv2onXZXfKHEMPh+HIBFvX1PaO/LOuuwr6PFLb9WxWNjweOTVioMOW2A200avWoFVe3ytkOHcws8d3IrizE1d6QhwXgDVBOYWSOzcK4x/WNHgUtSJ0uVJSlN8/CP7Ymi8Z9p8VT+kEJ6VzVnixhM/B5sK7Owg1pKQRpk/P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7ttzEz4mhQgMWEG4lPDFm3TXn14S3M5Q4knvAusdnPIrygU9wQ93pG1Rb/oeXh+WHKFslmm38jCyr6ZCNCqSzkw442Fviuo7w6OmtSSkIcP0kE2GZbqg5KiB15rutfoFwj8VqA1biOc9Lv+W8V7dKveQykhgCfueKPL4UvRARAdyYJbdxpkvDTW8KLUWWdgoJlI1 X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 26e58b87-1099-4013-31a3-08dbec339bf4 X-MS-Exchange-CrossTenant-AuthSource: JH0PR06MB6849.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Nov 2023 14:51:01.1204 (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: L/q89At5e2XAjSYoGvpije7S57L1nOdO2lPNF14Egy7phrn1VoSJihbhvUo94P0yCwe9BuVYPXRYftDA+2kVWQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SEZPR06MB5762 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email 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 (groat.vger.email [0.0.0.0]); Thu, 23 Nov 2023 06:51:28 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783366778407746559 X-GMAIL-MSGID: 1783366778407746559 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 7a8dac0c1c74..693e86fc9850 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -2850,11 +2850,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; } @@ -2918,7 +2927,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; @@ -2938,6 +2947,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) && @@ -3208,6 +3235,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: /* @@ -3339,7 +3367,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); @@ -3347,7 +3375,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;