From patchwork Wed Jun 19 09:48:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ge Yang X-Patchwork-Id: 13703580 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 31565C27C53 for ; Wed, 19 Jun 2024 09:48:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A66AA8D007C; Wed, 19 Jun 2024 05:48:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A16228D007A; Wed, 19 Jun 2024 05:48:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8DE158D007C; Wed, 19 Jun 2024 05:48:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 6E3508D007A for ; Wed, 19 Jun 2024 05:48:41 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 15195C0FDE for ; Wed, 19 Jun 2024 09:48:41 +0000 (UTC) X-FDA: 82247163642.21.F074CA7 Received: from m16.mail.126.com (m16.mail.126.com [220.197.31.8]) by imf19.hostedemail.com (Postfix) with ESMTP id AFD651A001A for ; Wed, 19 Jun 2024 09:48:37 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=126.com header.s=s110527 header.b=bHCk9FS6; spf=pass (imf19.hostedemail.com: domain of yangge1116@126.com designates 220.197.31.8 as permitted sender) smtp.mailfrom=yangge1116@126.com; dmarc=pass (policy=none) header.from=126.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1718790511; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references:dkim-signature; bh=Y8DxonlczYBTK4ErHDjFK14pvQyoYGA2Il/eyFLdS/o=; b=15LiSFFAufd1ZqXqzfRc9/TuxunpXnv7hwu5jV0xUwvXcGNah8iNB5pezRShrT0ybv8Nib Ee1Srphg+iANkdHM9ugDTuuGWHpOCgmy6Qf91N2lZc4sAEJE1hLKeurKiEQaqy+mS5skJm fE/anzodvinWR2mXYR0o++9X89Tgxik= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718790511; a=rsa-sha256; cv=none; b=WAfhwwxC8F6A2giGWxeEdj9ThPy1vLnvJPXgKNXlfpp10hW4ebrcvnXJrBO3hLAMxn5ADH ml00Bed/QlF2oeePHnR8SBdQCk2Y6uKsW488wACywfXiRsr7lI8tkaQdPWQbdkv8O+vlAm onLC4Eq3LbEWbU71nayZf1VrPfePEVI= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=126.com header.s=s110527 header.b=bHCk9FS6; spf=pass (imf19.hostedemail.com: domain of yangge1116@126.com designates 220.197.31.8 as permitted sender) smtp.mailfrom=yangge1116@126.com; dmarc=pass (policy=none) header.from=126.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=126.com; s=s110527; h=From:Subject:Date:Message-Id; bh=Y8DxonlczYBTK4ErHD jFK14pvQyoYGA2Il/eyFLdS/o=; b=bHCk9FS6AagSsJ1J9zFrFce2YCBdDySru2 jpmLN+3K6Y9eI5/w822qFJWBg1wNIhSaU6b5tSuoH29OZHuuQmuFWME0Gsz30Utk zu7HuLuZ/0PZN4mksUqMwt5PY1wk8j4IDWQAQIBV94PDFpNurxNgmUXzQo1PEuVr aw7eawR+s= Received: from hg-OptiPlex-7040.hygon.cn (unknown [118.242.3.34]) by gzga-smtp-mta-g0-3 (Coremail) with SMTP id _____wD3H3NlqXJmPcTQBw--.9650S2; Wed, 19 Jun 2024 17:48:23 +0800 (CST) From: yangge1116@126.com To: akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, 21cnbao@gmail.com, baolin.wang@linux.alibaba.com, liuzixing@hygon.cn, yangge Subject: [PATCH] mm/page_alloc: add one PCP list for THP Date: Wed, 19 Jun 2024 17:48:19 +0800 Message-Id: <1718790499-28151-1-git-send-email-yangge1116@126.com> X-Mailer: git-send-email 2.7.4 X-CM-TRANSID: _____wD3H3NlqXJmPcTQBw--.9650S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxAFWUtF17Xw18JF1UuFWDXFb_yoWrGrW8pF WxJr4av3yjq34Yyr1xA3Wqkrn5C3ZxGFsrur1I9ry8ZwsxJFyS9a4xKF1qvF95ArW7AFWx Xr9rK343CF4DZ3DanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07Umg4DUUUUU= X-Originating-IP: [118.242.3.34] X-CM-SenderInfo: 51dqwwjhrrila6rslhhfrp/1tbiOgsDG2VEw4oP+AAAs2 X-Rspamd-Queue-Id: AFD651A001A X-Stat-Signature: 7o616opi79iygqz74z5wgpf871icqy5a X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1718790517-510419 X-HE-Meta: U2FsdGVkX19DcJ+kmFNARxBcJ5fQZSychvdEwvmU0HXCGkB5/7r9ARQqVCKzd84A8Nez6lRrzYd5zEsL2uycDyKydhFfv1OKmmaLJ2ss4eaauYe1CMngmZRJkEfujJrQ1/jLGjy5pJFpcKsLVTZofBa5QU/TYCiPfEgN/ai+qSI6T5LM5o6t5wCZWPxcZ5JkorhokGODxeRWYOFgT/GbfzwkdRdljpycokj44Nb/8AyEgm36UqdhaUe4VwLgS+ReNaKJmhu0g090b/9/bdu6sJk5KYBSq6KyPTRSVBwWvWmnniy9MOEdTXwX5Mwhcnb9CDYlfY6JnXJ4GagW4rDNY6J3qwIC0NlGYmtSi/7ERvA3K7X7Wgl5LyFcnmlj0cN/ElorqsZX7lxOwTks6CJat27Sj9ENzLVCo71l93M/4WS79+UojroeqDcywZjzj23eqfpO2b88fdIVqwKgJ/FvkLB6xMGXINh24N9LxeoZrM1b51QkGly/yve5pyzYnZRFrOtwelKQJwkl+ask7TUMNU54OTZJjPWV+7cOXuh5HGKrjpptjrkHR92QJ80hG4eZqN5cprzuuf9KqkjsHNJuH1OAmRCnqlIrhd9mWguCxlFuwQByBqA1GOs31j9eb0vav+EFN89AWwooPi1gqKXs4Jdx5+nBhcL6lybmkrZec8yUeja6cLCjIgX2k9C+x8TJc2lAiBNqHuHhKmp4zUs7+9djNR0k7VayVlAUwz43S90rUAw2lpZyJfchohjOzhxDTeX57w1Rjp+Vj0EDKsSbg9ehOrUNcXZxJuzH2SI9y0W7i0K3dlKZszDQ+uA9akqhxuILagy0EQHf8qFVHz8tEBeHGPea1ogJctvNrn+r5iIhFRIJIbwK2uYAUpzm36A9NlRulKTp/w7asCEiEn9NgAk18bchgX/w0YDMs79KWWLZ/qNeOtr7y3gQEpv1gu3/kcb8BOtJJDjpCDWTpe7 o3PFm8Gl jDHuxS9l4ruixr6HqB94QjqIBhg++bcqixS6qGv+RrzRt5TUCOLy6VCxw+PnxrUkLlW9OPJ0IeFkFdthSLjyF3zbLHptvrUhW9hfJskiiidAk8OrxA20XLPsSmeRqwECeYx41l3oNXYA+SwOeT+/aY8gk/kLEifarHyMzPbglvBu0qhKEzb+sH40EOO8fH0M9m5zft2McAB/hrHE6fcF91Khnpzlu46RkkZF009r+EvRwoKoJjzIZhXdbw5jL3FbK0Gg4C3pRmN0lFCag2vr88BMWPwvTWBJIfTgHTRNbONpYoe7wN8H5dSNdEODW3OH49DxJzpGPPdux8gwVTZlodzo9AKP2Ot8Bj2wLP483Eyke1+U= 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: 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 To fix the problem above, we add one PCP list for THP, which will not introduce a new cacheline. 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. Link: https://lore.kernel.org/all/1717492460-19457-1-git-send-email-yangge1116@126.com/ Fixes: 5d0a661d808f ("mm/page_alloc: use only one PCP list for THP-sized allocations") Signed-off-by: yangge --- include/linux/mmzone.h | 9 ++++----- mm/page_alloc.c | 9 +++++++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index b7546dd..cb7f265 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -656,13 +656,12 @@ enum zone_watermarks { }; /* - * 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. + * One per migratetype for each PAGE_ALLOC_COSTLY_ORDER. Two additional lists + * are added for THP. One PCP list is used by GPF_MOVABLE, and the other PCP list + * is used by GFP_UNMOVABLE and GFP_RECLAIMABLE. */ #ifdef CONFIG_TRANSPARENT_HUGEPAGE -#define NR_PCP_THP 1 +#define NR_PCP_THP 2 #else #define NR_PCP_THP 0 #endif diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 8f416a0..0ecbde3 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -504,10 +504,15 @@ static void bad_page(struct page *page, const char *reason) static inline unsigned int order_to_pindex(int migratetype, int order) { + bool __maybe_unused movable; + #ifdef CONFIG_TRANSPARENT_HUGEPAGE if (order > PAGE_ALLOC_COSTLY_ORDER) { VM_BUG_ON(order != HPAGE_PMD_ORDER); - return NR_LOWORDER_PCP_LISTS; + + movable = migratetype == MIGRATE_MOVABLE; + + return NR_LOWORDER_PCP_LISTS + movable; } #else VM_BUG_ON(order > PAGE_ALLOC_COSTLY_ORDER); @@ -521,7 +526,7 @@ static inline int pindex_to_order(unsigned int pindex) int order = pindex / MIGRATE_PCPTYPES; #ifdef CONFIG_TRANSPARENT_HUGEPAGE - if (pindex == NR_LOWORDER_PCP_LISTS) + if (order > PAGE_ALLOC_COSTLY_ORDER) order = HPAGE_PMD_ORDER; #else VM_BUG_ON(order > PAGE_ALLOC_COSTLY_ORDER);