Received: by 2002:a05:7412:1e0b:b0:fc:a2b0:25d7 with SMTP id kr11csp1234229rdb; Fri, 16 Feb 2024 09:06:29 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUPXpNtTkp31F4ExmECw8Ht0UYCpHk3RLEJCTgJvb5YYDmt7n8mjEjGI3BelhWUT2S18fHUi4FCWPCdH7irQT8tFl4uo64xJlDJ+ta34g== X-Google-Smtp-Source: AGHT+IGniUKYYTc3o7kKXd1neUsHhRC8aPABS2vfsRXylykmXOUSc54iRM/AI2utWxDnx10C9Fz1 X-Received: by 2002:a05:620a:31e:b0:787:2b5c:e9f with SMTP id s30-20020a05620a031e00b007872b5c0e9fmr5686928qkm.14.1708103189564; Fri, 16 Feb 2024 09:06:29 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708103189; cv=pass; d=google.com; s=arc-20160816; b=tLCh+q9fN0G0x2qm+NW22bydoSF6vdrKFI+pA8UVHHCSiT9UmNzgHaON9LejXYLEpd CnjcpdTGFLuDCB1PQMQu36gUKXnV4XlEQulTHyT8/JSTSP90pYh1xGh8+oXiHHnrCosY 4X2Nd5B0O0R5VRf/RakP0jUcr+iP751eyC6KcYeq3P8VwmhZZZ34JXTg/b1r5UAjRTbe GENmM3llTuY39wB07nEG1rh4ZHuAphyLCZVggfcHSCJwkWYy4RQFkS4Au3h14Q2ea2YK Pju9SXO9EoQdX/PjHD/rlR0Ney2NT147lbepjd/GUk1Anks/Ql8Bs9ZO2QiPgHka71Lk es/g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:reply-to:references:in-reply-to :message-id:date:subject:cc:to:from:feedback-id:dkim-signature :dkim-signature; bh=bTCMfMRgj0TAxiQeyNSNVpFoxlWh0Oj72NH6xXdaFx0=; fh=vJ0CYzlC3FzFcxY+JvdHzizIe8XjzG5USPt1Sa6qsGI=; b=MMjABiGdaw6VV1ELgwst2HZYehDUPRLCdqPd2DceRqYkKsKqWHCqy5TZm7GA/PKb7b coIJsqUAbN4ZELFkQb9//EB0QSzS125GUtzn4EQaL8VYY1oedErDfrezoG2/wcJdySGg qYd+fa0ZFNZixY3X1eFNW6eWS5GnZ4DDWa0uytYEwxztmxn7WTJg2I6Fjey73SKo6+Pm rEpgAWdxNkhNs3ry3Vd6lXjxF29siMXv/YyxqgnSYuS59FrZKGN+sM5fWnVSjH3dKaPJ pmJvF3u9PZA0UEAof37osQyY5aLYiyHGdbTyOBkWGwRbRMZKeKeniaN/N9uyWQA1w7si riTA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@sent.com header.s=fm1 header.b=Qh+SFOC2; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=hrjQmkGw; arc=pass (i=1 spf=pass spfdomain=sent.com dkim=pass dkdomain=sent.com dkim=pass dkdomain=messagingengine.com dmarc=pass fromdomain=sent.com); spf=pass (google.com: domain of linux-kernel+bounces-69016-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69016-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sent.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id v8-20020a05620a440800b007858c916862si319428qkp.612.2024.02.16.09.06.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 09:06:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-69016-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@sent.com header.s=fm1 header.b=Qh+SFOC2; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=hrjQmkGw; arc=pass (i=1 spf=pass spfdomain=sent.com dkim=pass dkdomain=sent.com dkim=pass dkdomain=messagingengine.com dmarc=pass fromdomain=sent.com); spf=pass (google.com: domain of linux-kernel+bounces-69016-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69016-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sent.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 64FAA1C2324F for ; Fri, 16 Feb 2024 17:05:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 183331332AD; Fri, 16 Feb 2024 17:04:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sent.com header.i=@sent.com header.b="Qh+SFOC2"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="hrjQmkGw" Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0253B13249C for ; Fri, 16 Feb 2024 17:04:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=66.111.4.25 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708103096; cv=none; b=A2Gkp262CKdU4rZIIKPb8RTuSUKSfF6Hp54Wd3ysxXIgrVt7VuOyoI3DbaiA5MuVNxsFHDFHYOsRNJ+7oxCmGBD19ImYBsuYvXyG1NPyL0Rr2Atu4cubKHeF0f2VSuXJG4YKCxDLPRA60O0slc/UuOggT7vfrBLStDzzdi/tClg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708103096; c=relaxed/simple; bh=82Y1OAgcDxB2eyqtTi+XVPaxghLqy53X5y/mvWFu9A8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=nAEuXN0pT0Pp4jRUlMu/1RzTMVYe11gPuvojR+lrSsS0EXvDyXkCk4DY+WEawymr4eKj4b8hTNFP3cPCtbD2/NG22qZmkzuATld35uZz5lSCKDwpX11JZrTr8HJ6hBwcbGpOho6p21YIMn3NqWokLccnBLy5CDF0VQWmo9B7YqI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sent.com; spf=pass smtp.mailfrom=sent.com; dkim=pass (2048-bit key) header.d=sent.com header.i=@sent.com header.b=Qh+SFOC2; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=hrjQmkGw; arc=none smtp.client-ip=66.111.4.25 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sent.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sent.com Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 4C4285C00A3; Fri, 16 Feb 2024 12:04:54 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Fri, 16 Feb 2024 12:04:54 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sent.com; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:reply-to:subject:subject:to:to; s=fm1; t= 1708103094; x=1708189494; bh=bTCMfMRgj0TAxiQeyNSNVpFoxlWh0Oj72NH 6xXdaFx0=; b=Qh+SFOC2uzfXFBf2MQSyLCdE/iSEti9OEl50htzixNEhyH3p6uD ttorsdTatpDLJct9xYK/4M3p/v7LE26pEawkhX7e/2gw/IgIzs+ZnS0OlP6lk+GM ky8YC+gWiiRpMIiUyVUI440RtoKFFQL6F3XF/7jnQTCtljg5jUe8YyQDVCwSs2X0 EiaOz0v44hVK/fl2b4G4CGshkV4t5MDCSjUGswZ2+MZXyZCka1nlMw/+KtnzqqMb bRnU1jjZCdIibwvZ3ewjRHaciWMNXBOY5T5oWefeQM53QEmyjbNvjT09kiFL+KHE MK3s+71oUT9iXOSHIQqrV9Pigpngwe7lufQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:reply-to:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t= 1708103094; x=1708189494; bh=bTCMfMRgj0TAxiQeyNSNVpFoxlWh0Oj72NH 6xXdaFx0=; b=hrjQmkGwrw/QsZ5Oscv5eFQex/wKIva4wZWzZZTaY8WxwPrCbpL /ZEs1k6WWt/DCUHTPsxn+xV/sxbFuyc/GeRxj0F+KqJKqsHAdfouZeJPYmbY3Llc qFDPmgp0dlEjvCp0JEAVVMc7CTuB4tudRrtgDKZQNbEDGajyQl7TZbpmBYzOK2AN +R8PjACg5jv+jcaXiSiRoegIQsH6NxUP8XFWTtzFS6HWHrSqvz589A1OuKpQ5i50 n3BqTWs+bOWlfzAO30MSVhbfDDlzGhM5UXXuob7GZAgXH9cPTf8pucGiIF2vUIRf sMR7aFPAF37x1XJ6C+uErmm2LAwmQQ172bg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvddvgdelhecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvfevufffkffojghfrhggtgfgsehtkeertdertdejnecuhfhrohhmpegkihcu jggrnhcuoeiiihdrhigrnhesshgvnhhtrdgtohhmqeenucggtffrrghtthgvrhhnpeejke etkeffleelkeduffdtfedvtdejjeeutdeutdetgeejgfevtdefudejkeeiveenucevlhhu shhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpeiiihdrhigrnhessh gvnhhtrdgtohhm X-ME-Proxy: Feedback-ID: iccd040f4:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 16 Feb 2024 12:04:52 -0500 (EST) From: Zi Yan To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Zi Yan , "Huang, Ying" , Ryan Roberts , Andrew Morton , "Matthew Wilcox (Oracle)" , David Hildenbrand , "Yin, Fengwei" , Yu Zhao , Vlastimil Babka , "Kirill A . Shutemov" , Johannes Weiner , Baolin Wang , Kemeng Shi , Mel Gorman , Rohan Puri , Mcgrof Chamberlain , Adam Manzanares , "Vishal Moola (Oracle)" Subject: [PATCH v6 4/4] mm/compaction: optimize >0 order folio compaction with free page split. Date: Fri, 16 Feb 2024 12:04:32 -0500 Message-ID: <20240216170432.1268753-5-zi.yan@sent.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240216170432.1268753-1-zi.yan@sent.com> References: <20240216170432.1268753-1-zi.yan@sent.com> Reply-To: Zi Yan Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit From: Zi Yan During migration in a memory compaction, free pages are placed in an array of page lists based on their order. But the desired free page order (i.e., the order of a source page) might not be always present, thus leading to migration failures and premature compaction termination. Split a high order free pages when source migration page has a lower order to increase migration successful rate. Note: merging free pages when a migration fails and a lower order free page is returned via compaction_free() is possible, but there is too much work. Since the free pages are not buddy pages, it is hard to identify these free pages using existing PFN-based page merging algorithm. Signed-off-by: Zi Yan Reviewed-by: Baolin Wang Reviewed-by: Vlastimil Babka Tested-by: Baolin Wang Tested-by: Yu Zhao Cc: Adam Manzanares Cc: David Hildenbrand Cc: Huang Ying Cc: Johannes Weiner Cc: Kemeng Shi Cc: Kirill A. Shutemov Cc: Luis Chamberlain Cc: Matthew Wilcox (Oracle) Cc: Mel Gorman Cc: Ryan Roberts Cc: Vishal Moola (Oracle) Cc: Vlastimil Babka Cc: Yin Fengwei --- mm/compaction.c | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/mm/compaction.c b/mm/compaction.c index f21836ca243a..b2a570e00a8e 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -1832,15 +1832,40 @@ static struct folio *compaction_alloc(struct folio *src, unsigned long data) struct compact_control *cc = (struct compact_control *)data; struct folio *dst; int order = folio_order(src); + bool has_isolated_pages = false; + int start_order; + struct page *freepage; + unsigned long size; + +again: + for (start_order = order; start_order < NR_PAGE_ORDERS; start_order++) + if (!list_empty(&cc->freepages[start_order])) + break; - if (list_empty(&cc->freepages[order])) { - isolate_freepages(cc); - if (list_empty(&cc->freepages[order])) + /* no free pages in the list */ + if (start_order == NR_PAGE_ORDERS) { + if (has_isolated_pages) return NULL; + isolate_freepages(cc); + has_isolated_pages = true; + goto again; + } + + freepage = list_first_entry(&cc->freepages[start_order], struct page, + lru); + size = 1 << start_order; + + list_del(&freepage->lru); + + while (start_order > order) { + start_order--; + size >>= 1; + + list_add(&freepage[size].lru, &cc->freepages[start_order]); + set_page_private(&freepage[size], start_order); } + dst = (struct folio *)freepage; - dst = list_first_entry(&cc->freepages[order], struct folio, lru); - list_del(&dst->lru); post_alloc_hook(&dst->page, order, __GFP_MOVABLE); if (order) prep_compound_page(&dst->page, order); -- 2.43.0