From patchwork Mon Apr 15 08:12:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13629606 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 042EBC4345F for ; Mon, 15 Apr 2024 08:12:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 846CC6B0096; Mon, 15 Apr 2024 04:12:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7CCF46B0093; Mon, 15 Apr 2024 04:12:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6C53E6B0095; Mon, 15 Apr 2024 04:12:49 -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 4EBAB6B0089 for ; Mon, 15 Apr 2024 04:12:49 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 203E91A04C0 for ; Mon, 15 Apr 2024 08:12:49 +0000 (UTC) X-FDA: 82011050058.18.B7F1DA6 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf21.hostedemail.com (Postfix) with ESMTP id 9C4641C0005 for ; Mon, 15 Apr 2024 08:12:46 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=none; spf=pass (imf21.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1713168767; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9vCchmtiklmD2PaZzSvllHrKk3Uhitz218v08T0VuNo=; b=U5eMzSPwtNCqcMI4uOjF0XA54ghnfyhqK1DJiOcEyXmr7qD+BFSGpmkTOkj3YRrYIhlrgM WSB/XDM0Lxsm8bS5SKKpmT/XQPrNT7RM7SOEEew6J3oU0xupQPuuAH+ABWvv1EGapsay3r 9pwrc7/kLElEqNwFVHhAwuiutD3gdiE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1713168767; a=rsa-sha256; cv=none; b=n2uFEbtrN/Bj6cmpPPadS77uAgACkm5gpd3p4nj0WxBiWLrp4AXWzuusgQKWeqQNCebLM8 wTkytAlKNH5U+vv3jTCs+KIQLbJ/uDeMGdo6OJfOClT2O8jV8r2yNF7wTmydHj2Ddvk8EZ YCwvKqjECmfqO5tLYuebHUQN+I4qPAw= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=none; spf=pass (imf21.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.252]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4VJ0Fr6nJ7z1R5pf; Mon, 15 Apr 2024 16:09:52 +0800 (CST) Received: from dggpemm100001.china.huawei.com (unknown [7.185.36.93]) by mail.maildlp.com (Postfix) with ESMTPS id 915FE18007D; Mon, 15 Apr 2024 16:12:42 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) by dggpemm100001.china.huawei.com (7.185.36.93) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Mon, 15 Apr 2024 16:12:41 +0800 From: Kefeng Wang To: Andrew Morton CC: Huang Ying , Mel Gorman , Ryan Roberts , David Hildenbrand , Barry Song , Vlastimil Babka , Zi Yan , "Matthew Wilcox (Oracle)" , Jonathan Corbet , Yang Shi , Yu Zhao , , Kefeng Wang Subject: [PATCH rfc 1/3] mm: prepare more high-order pages to be stored on the per-cpu lists Date: Mon, 15 Apr 2024 16:12:18 +0800 Message-ID: <20240415081220.3246839-2-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240415081220.3246839-1-wangkefeng.wang@huawei.com> References: <20240415081220.3246839-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm100001.china.huawei.com (7.185.36.93) X-Rspamd-Queue-Id: 9C4641C0005 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: insn36gofeqxre84b76ei6ktiqpum3ar X-HE-Tag: 1713168766-382826 X-HE-Meta: U2FsdGVkX1+ftLXlz6dtQNQIjSO8NqktfGTyZLSYzX5d56BXhQMTc5H/98SipFu3T5haB/6RSGAzWuHxjJdnRz1wY1ILs0nYrXF7nQAG6g6AalsnkxAk/Ri6c6B6Xouf/igXWZPdBB4WqJnCh8edZOE102xsXhQjLbtOWGfApgi+FqW5MqwTBVhD6gTBsE8WVPxhxy9+vjnLb9DvF5oUJAKEXmmsBvcgDOMAusAw08nWIN6bev4YYn5xoih7T3IPzXA/8n6YDH6plLlAnKQXoWvdxIjRMYpvPFsbqa1VVdudh4vI6sTt1sr+IZp2Q/IqeuTi3O3bswJ3HZREi0604A2MGYhDgvSIgBVlDGv04+5yqe58J3mOMyuPCrFbbtCdwGk3EB0kLteJ3XVQb3z8nuuelVD5XWXnprF2xs1l/Io2xHj8rYw9lr5w8bqiABtb5E/dX3mqLThS4u5FOEmRg0RZkYK9sd1tL/kJc5gdmyDeESt0atr28PYSM76tPfeuiNYXFrWJ1XmN6sJmLn1pYpD8mIsD4YDR2CvUtKTTccl4jWjlfdG77PvK9uxXunM63kZhTi8Fov+/JUaQZx8LTUsQjMHFqusEVtGdhOvPHtr5bx6b/XUwlTMxx1dKOBtn64A1ynVzqm/z7D1wzpx31G8rHS6M1g+8TpySC/J5pe898CThnmnP6jgCveXZhGaSgyeWA/JCS4k0YK1dHUkPHtLUgGfecCf5idYp71qPl2O6Ssp71LzXvTNKEhFpFwDhu7DW8v/1hUMeL9IpFzv8ijCDtrM06qbBKRtavkOcwxxvY9iUBHqonTPS2HgP0uLhRxosgo7qBeKiUGT2SpjnogFFRZ9zsBsCRKn4TUdrnC0pk0vY3bBMRi42MYv04MSAQRfaIi9TT9i3rvg9KBfXjgNoUL1MfyfcBKJi5c/9xcFofQluSSADYT7sT9NJhEWn8AJCSEwaAHrlv8W7Cgx 6THIXo+T gajgj92C1hg8P3nVtCCUm5RxuiHgIy+m2NBiQ9LvCGEdmJfyoOexcGvNHzAtN+5Vu047DykK54MmzBa5dTo2UIwz4llPGKTWKLK7x67ZrXqwxIuPcTsBg+k31cD4Ssrhp7JKgqIBw0CII1H5gp3b5CPvc/g== 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: Both the file pages and anonymous pages support large folio, high-order pages except HPAGE_PMD_ORDER(PMD_SHIFT - PAGE_SHIFT) will be allocated frequently which will increase the zone lock contention, allow high-order pages on pcp lists could alleviate the big zone lock contention, in order to allows high-orders(PAGE_ALLOC_COSTLY_ORDER, HPAGE_PMD_ORDER) to be stored on the per-cpu lists, similar with PMD_ORDER pages, more lists is added in struct per_cpu_pages (one list each high-order pages), also a new PCP_MAX_ORDER instead of HPAGE_PMD_ORDER is added in mmzone.h. But as commit 44042b449872 ("mm/page_alloc: allow high-order pages to be stored on the per-cpu lists") pointed, it may not win in all the scenes, so this don't allow higher-order pages to be added to PCP list, the next will add a control to enable or disable it. The struct per_cpu_pages increases in size from 256(4 cache lines) to 320 bytes (5 cache lines) on arm64 with defconfig. Signed-off-by: Kefeng Wang --- include/linux/mmzone.h | 4 +++- mm/page_alloc.c | 10 +++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index c11b7cde81ef..c745e2f1a0f2 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -657,11 +657,13 @@ enum zone_watermarks { * failures. */ #ifdef CONFIG_TRANSPARENT_HUGEPAGE -#define NR_PCP_THP 1 +#define PCP_MAX_ORDER (PMD_SHIFT - PAGE_SHIFT) +#define NR_PCP_THP (PCP_MAX_ORDER - PAGE_ALLOC_COSTLY_ORDER) #else #define NR_PCP_THP 0 #endif #define NR_LOWORDER_PCP_LISTS (MIGRATE_PCPTYPES * (PAGE_ALLOC_COSTLY_ORDER + 1)) +#define HIGHORDER_PCP_LIST_INDEX (NR_LOWORDER_PCP_LISTS - (PAGE_ALLOC_COSTLY_ORDER + 1)) #define NR_PCP_LISTS (NR_LOWORDER_PCP_LISTS + NR_PCP_THP) #define min_wmark_pages(z) (z->_watermark[WMARK_MIN] + z->watermark_boost) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index b51becf03d1e..2248afc7b73a 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -506,8 +506,8 @@ 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 != HPAGE_PMD_ORDER); - return NR_LOWORDER_PCP_LISTS; + VM_BUG_ON(order > PCP_MAX_ORDER); + return order + HIGHORDER_PCP_LIST_INDEX; } #else VM_BUG_ON(order > PAGE_ALLOC_COSTLY_ORDER); @@ -521,8 +521,8 @@ static inline int pindex_to_order(unsigned int pindex) int order = pindex / MIGRATE_PCPTYPES; #ifdef CONFIG_TRANSPARENT_HUGEPAGE - if (pindex == NR_LOWORDER_PCP_LISTS) - order = HPAGE_PMD_ORDER; + if (pindex >= NR_LOWORDER_PCP_LISTS) + order = pindex - HIGHORDER_PCP_LIST_INDEX; #else VM_BUG_ON(order > PAGE_ALLOC_COSTLY_ORDER); #endif @@ -535,7 +535,7 @@ static inline bool pcp_allowed_order(unsigned int order) if (order <= PAGE_ALLOC_COSTLY_ORDER) return true; #ifdef CONFIG_TRANSPARENT_HUGEPAGE - if (order == HPAGE_PMD_ORDER) + if (order == PCP_MAX_ORDER) return true; #endif return false;