Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 392B1C30658 for ; Fri, 5 Jul 2024 09:28:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BBF1C6B00A1; Fri, 5 Jul 2024 05:28:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B6E616B00A3; Fri, 5 Jul 2024 05:28:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A36946B00A5; Fri, 5 Jul 2024 05:28:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 7E9A96B00A1 for ; Fri, 5 Jul 2024 05:28:02 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 076A8A171A for ; Fri, 5 Jul 2024 09:28:02 +0000 (UTC) X-FDA: 82305172404.14.1B1ACDE Received: from mail17.out.titan.email (mail17.out.titan.email [3.64.226.211]) by imf29.hostedemail.com (Postfix) with ESMTP id 561E9120010 for ; Fri, 5 Jul 2024 09:27:59 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=techsingularity.net header.s=titan1 header.b=C8PQzFbr; dmarc=none; spf=pass (imf29.hostedemail.com: domain of mgorman@techsingularity.net designates 3.64.226.211 as permitted sender) smtp.mailfrom=mgorman@techsingularity.net ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1720171658; a=rsa-sha256; cv=none; b=6HCayqB3P+0sf2EKqr86+NPsi4gh9mke0E+kMy+QXcHjTtgiwNM+7RdPDmOZvOMOC70nUK nh5R8b4tplimLFXisTZ2IKHtuAdxJ7oDSS3wLRV8W5cZHxFULlm5AOypFwcWR2IY4JZbJR GLpcmTEQKYYuBsUTKG+TuDNSAB+ckI0= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=techsingularity.net header.s=titan1 header.b=C8PQzFbr; dmarc=none; spf=pass (imf29.hostedemail.com: domain of mgorman@techsingularity.net designates 3.64.226.211 as permitted sender) smtp.mailfrom=mgorman@techsingularity.net ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1720171658; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=gfDNsbbr44wtsa/28j7FedUDrpzQMLgTmEhYi5JNIWE=; b=0B93wlg/DOln+BxnqEvO1XIickIXcIIDudlnl4YUGtgxpFP9OvEpEIDNevuLDzNchpfbEW RIQq9JQXUuXKp0n44kU3Po+lgH3jouHDbUltQ2TPIAoEynowZ7Ti/1cbkmrSZ6JV356CRg OJ5rlDOZZPLG6sIy0f5OeNXmMKv1ryU= Received: from smtp-out0101.titan.email (localhost [127.0.0.1]) by smtp-out0101.titan.email (Postfix) with ESMTP id 9E13FA0031; Fri, 5 Jul 2024 09:27:57 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=gfDNsbbr44wtsa/28j7FedUDrpzQMLgTmEhYi5JNIWE=; c=relaxed/relaxed; d=techsingularity.net; h=date:cc:references:message-id:from:to:mime-version:in-reply-to:subject:from:to:cc:subject:date:message-id:in-reply-to:references:reply-to; q=dns/txt; s=titan1; t=1720171677; v=1; b=C8PQzFbr5RtS+PXu5Q3771cr6OtzTM4mxoAhv7jnP0TiSiuM1MlxAjp+TENn2TJhuxcuCfGW oiCdF8HE40AYFXd8gvjG5yjd07H4zgNkMqbP927fxvyp0cJU6cedxRoMzBLwOdyGFeV+3pkREhb GPljQmvIMUWTsvPgZY/yiXus= Received: from mail.blacknight.com (ip-84-203-196-95.broadband.digiweb.ie [84.203.196.95]) by smtp-out0101.titan.email (Postfix) with ESMTPA id D649CA0051; Fri, 5 Jul 2024 09:27:56 +0000 (UTC) Date: Fri, 5 Jul 2024 10:27:54 +0100 Feedback-ID: :mgorman@techsingularity.net:techsingularity.net:flockmailId From: Mel Gorman To: yangge1116@126.com Cc: akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, 21cnbao@gmail.com, baolin.wang@linux.alibaba.com, liuzixing@hygon.cn Subject: Re: [PATCH] mm/page_alloc: add one PCP list for THP Message-ID: <20240705092754.cv4dowdunoxfn6l5@techsingularity.net> References: <1718801672-30152-1-git-send-email-yangge1116@126.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Disposition: inline In-Reply-To: <1718801672-30152-1-git-send-email-yangge1116@126.com> X-F-Verdict: SPFVALID X-Titan-Src-Out: 1720171677523044635.8944.4972576934373349811@prod-euc1-smtp-out1002. X-Virus-Scanned: ClamAV using ClamSMTP X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 561E9120010 X-Stat-Signature: 8eef81pndzmwkknkc8cke919taf7r8kd X-Rspam-User: X-CMAE-Score: 0 X-CMAE-Analysis: v=2.4 cv=I8M3R8gg c=1 sm=1 tr=0 ts=6687bca0 a=3gGNrESU9SrMLaOf6x+A+w==:117 a=yLX2s/SMutoCvBNwHxSr4A==:17 a=Q9fys5e9bTEA:10 a=4kmOji7k6h8A:10 a=CEWIc4RMnpUA:10 a=gnbuhwpKAAAA:8 a=R_Myd5XaAAAA:8 a=rSyjtz3AbgEkiwi8wb8A:9 a=PUjeQqilurYA:10 a=L2g4Dz8VuBQ37YGmWQah:22 X-HE-Tag: 1720171679-333005 X-HE-Meta: U2FsdGVkX18OUhqyCFDpCe8dTUUAHzLpmO2NGupvhp4iKeFAV5rqCusNFkJHLeLE/thqG9YGa7UODt+3tHNy998lEl1gd9F8vWJwiOibcVN/7Yv9vLO4ojy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NdGdgOmVLsyWys8L1tKH5V6cZ+bU5/oKidMelXCHVkmmMdw+4p3QsKm1VHMUOpF3kPrcwL+ZlqSpbek5a6zXahKzfFjrmVlayNPD+A7CEivbxfIH6rTQhZiGa56YzE8PuPqO/96oFQgq1kz/Tz/9URoHjMqJF5E40gfBBUgZoeGfQPrs34g7AWp3XI/f0VLJ5Rt+DwPYLgCS9SdENJXvspPH7OdLCZ/zpxibqQInZBN5kMLV0w7p+53REI/PheysI0CsVwv/fqIxtTtFq+bQSJmyBPBKVyDzZYvbRMdF/HgCCMuEB3yI30Xxdrcha4DBCnZhuFV2yspjFc5SXuc5nM4zgUFydqoJujKmDiUxNJ2i0VeYUFBxJrmJeQQ+RdhV9aQJRlZDbuQzCVNlofxUYJYK3xYu5FSxhXIQ7I5/n0h8nQbz2Q5/g8oG7IBNv93JmnfwCH/bSQfEvoGyLg0gyTsufPiC0SgqJqBb574mnuf961bYyE2VQnQZA9cFJD3p8tB8te0t3E7PAgEwfeTdj/YLTxRi5gAML2libjeYzcJIG67Us9LY1Ks6HGdP1zFir/5dfGGUyKn6kewZKVueyCFWCk4+1Kys3Sh5KzxZjRYWejy2IKkpsS7K79qxUwZZg4= 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: List-Subscribe: List-Unsubscribe: On Wed, Jun 19, 2024 at 08:54:32PM +0800, yangge1116@126.com wrote: > From: yangge > > Since commit 5d0a661d808f ("mm/page_alloc: use only one PCP list for > THP-sized allocations") no longer differentiates the migration type > of pages in THP-sized PCP list, it's possible that non-movable > allocation requests may get a CMA page from the list, in some cases, > it's not acceptable. > > If a large number of CMA memory are configured in system (for > example, the CMA memory accounts for 50% of the system memory), > starting a virtual machine with device passthrough will get stuck. > During starting the virtual machine, it will call > pin_user_pages_remote(..., FOLL_LONGTERM, ...) to pin memory. Normally > if a page is present and in CMA area, pin_user_pages_remote() will > migrate the page from CMA area to non-CMA area because of > FOLL_LONGTERM flag. But if non-movable allocation requests return > CMA memory, migrate_longterm_unpinnable_pages() will migrate a CMA > page to another CMA page, which will fail to pass the check in > check_and_migrate_movable_pages() and cause migration endless. > Call trace: > pin_user_pages_remote > --__gup_longterm_locked // endless loops in this function > ----_get_user_pages_locked > ----check_and_migrate_movable_pages > ------migrate_longterm_unpinnable_pages > --------alloc_migration_target > > This problem will also have a negative impact on CMA itself. For > example, when CMA is borrowed by THP, and we need to reclaim it > through cma_alloc() or dma_alloc_coherent(), we must move those > pages out to ensure CMA's users can retrieve that contigous memory. > Currently, CMA's memory is occupied by non-movable pages, meaning > we can't relocate them. As a result, cma_alloc() is more likely to > fail. > > To fix the problem above, we add one PCP list for THP, which will > not introduce a new cacheline for struct per_cpu_pages. THP will > have 2 PCP lists, one PCP list is used by MOVABLE allocation, and > the other PCP list is used by UNMOVABLE allocation. MOVABLE > allocation contains GPF_MOVABLE, and UNMOVABLE allocation contains > GFP_UNMOVABLE and GFP_RECLAIMABLE. > > Fixes: 5d0a661d808f ("mm/page_alloc: use only one PCP list for THP-sized allocations") > Signed-off-by: yangge Too late to be relevant but Acked-by: Mel Gorman It would have been preferred if the comment stated why GFP_UNMOVABLE is needed because the original assumption that THP would mostly be MOVABLE allocations did not age well but git blame is enough. Maybe one day GFP_RECLAIMABLE will also be added to the list. However, I suspect the bigger problem later will be multiple THP sizes becoming more common that are not necessarily fitting within PAGE_ALLOC_COSTLY_ORDER and per-cpu not being enough to mitigate zone->lock contention in general. That's beyond the scope of this patch. Thanks. -- Mel Gorman SUSE Labs