From patchwork Wed Feb 14 22:04:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 201143 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:b825:b0:106:860b:bbdd with SMTP id da37csp11652dyb; Wed, 14 Feb 2024 14:05:21 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW274mradEOJZ17aD4WWG0uqyHf1AqJOebwlsD/Put6wx78u/ZNKu7BUg0VRY4YwQd+jDCBQz//13QrJVUJxWrZJCSS3A== X-Google-Smtp-Source: AGHT+IGNy647j8vvvdiCBXnPvUtUX91Vh0BnROpLZJjgszuOZOcGN47AnNLixEo4b6I+6i9aFs0e X-Received: by 2002:a05:6512:3e18:b0:511:5237:a357 with SMTP id i24-20020a0565123e1800b005115237a357mr60432lfv.48.1707948321332; Wed, 14 Feb 2024 14:05:21 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707948321; cv=pass; d=google.com; s=arc-20160816; b=VItue5zQRxhPkfFv0MIas0GpBnSli7Rv3XW4syxcZm0DAqe+lQfAgK7dA4zKg8lywK Ba65t2fLPYbVe02Xk4DmjiRP4kssDTyGuFDVs17R3rY6ApsCwqaiCJUG5zc2+U2fNeN0 NNWwNJI4F4z2GjpEL2KkIdCjk6lUqs0jXM4pesZ24cdPtiGVZ4zOh0BwyE2a9bZWwHcf h6xUKuZN44DXthiy1F1ROGQJv8Mov/7ppAOC4d9SDEMAut4mBcDdW4Tc0KQ94/EOFFpj ChWLN4NC01cBxTfOD30VzEcNl44Wy/4K7eHeKV1acKtf8mXDMlACxsXgqSyGa1b0L+RS 67kw== 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=wQXk9BjzfNbSk+TtQUdIPTBzuKrc4Uz9jkx3jsjH0ns=; fh=+0lFy7AqKkDJkpmC61B1ja+jyfIGdQrF6Q//nE+epyA=; b=Mg1NMRurr8J3flH2xgoP83ARO3RoRR/3QNqrwAOKStekhB8cFySV85bTFhyVfIE2/O W28PbVvC+8ENBZe/4/8QF9g2Xobv4xtvcaoBGEG8fYgwx6a4wi5U7WLC9M/D+K4qwSBJ Saa9zeyiOHsI1e+IhCk3bHlVwmW9fn7Y8untmotk614cjh4cysLrMvqWS1Y96k0+CmY6 MRmWjdTnlUySD2eedjmul72AhdaAN0DqlRNXNVbtWvNsJlkwJOeCjLzb9rwPZRhP6xt3 izWdirgkux3LqK4egB/c2X2rsipdfgsDtRNsRAetkM5b7WDzo14jymcKHikdI5qT2JdN NhJA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@sent.com header.s=fm3 header.b=TYVPJiuB; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=HqHud2bg; 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-66023-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-66023-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sent.com X-Forwarded-Encrypted: i=2; AJvYcCVDBMsycZX6YDIFQnOHDb4qqbuVBWNDXpoyjbVW+OXs0gr2n3+daIXmZBkPQQh6P3dM33sY5TyFLr2aQHSTrcKBZZ3CjA== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id r15-20020a05640251cf00b00561eff0b0cesi2308180edd.397.2024.02.14.14.05.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 14:05:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-66023-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@sent.com header.s=fm3 header.b=TYVPJiuB; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=HqHud2bg; 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-66023-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-66023-ouuuleilei=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 am.mirrors.kernel.org (Postfix) with ESMTPS id BE47D1F2674B for ; Wed, 14 Feb 2024 22:05:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4B20B1420D0; Wed, 14 Feb 2024 22:04:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sent.com header.i=@sent.com header.b="TYVPJiuB"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="HqHud2bg" Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) (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 9C7A2141988 for ; Wed, 14 Feb 2024 22:04:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=66.111.4.28 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707948281; cv=none; b=qK9H2H7YiRBEzRe1lTpMfGDZgbTQ+ae1njgv3icR5zVEzETHpMv1mbFN3Gg1LzlianIRm6trABmkRa1WIeI844ydsg320tXHgOaiDRrZaHh+5EQnxJ6OIBDjIPhW6Dt97HTXhFEDkWwtoRvH/Oyyy0M1bQOfzmca4PLwvUHN/II= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707948281; c=relaxed/simple; bh=g9C2eZyu0HruNfOf1LAuN/17P6rNfDs6CE3m85il8Yc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=YP6xn+dB2+69EtovrUzPiU3K6+grDT/typ9A0keu3n96ps1RFd+ji/TO78C45dZWAgO3yIbpx/iXFo46lZIBT8+jUyCvxv00PepUD69NjlYXJKf3bkSRqYe9b9saYsjgGDLSxV3qivsVZY+2hEexOHCzS4issrGmM0f6qHgnxXo= 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=TYVPJiuB; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=HqHud2bg; arc=none smtp.client-ip=66.111.4.28 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 A39FC5C0086; Wed, 14 Feb 2024 17:04:38 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Wed, 14 Feb 2024 17:04:38 -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=fm3; t= 1707948278; x=1708034678; bh=wQXk9BjzfNbSk+TtQUdIPTBzuKrc4Uz9jkx 3jsjH0ns=; b=TYVPJiuB1JXeQIw8A86L+E6UEI1u4J6XAa1bTxbdRDxlLKK6T9f 1SKgzazMOLcJAFUvzSSe18CwB8JAk2lGIinVMXUswOyaPYyU9MKcZ/0gUG64DlE+ iotkdloZi8W6SU2CDx3DdY7EyzM4xvyJVxZZXLb5ff1heJw+9iG2AHeNEz3Vm3lj KYJcFrSuBUbv53jyQs8E7fCmqs9LxBVjqDdldFm5CkZF1muz32jl8CoUn1UbTF70 Hpfr5MD9QtU/YpuKYeeNKkTfxw9sVc1pVyr+UFOYioNEyEBUrSfbC7kgo2FHy2eA O++9ITQ1VvlZC0PuQw3c7pKO3pQV4eCgbeg== 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=fm3; t= 1707948278; x=1708034678; bh=wQXk9BjzfNbSk+TtQUdIPTBzuKrc4Uz9jkx 3jsjH0ns=; b=HqHud2bgtxbuleg7JIQcX/6DijCsT84RWDVT6WNJueqIH8OoZz5 QHc0wZ5e0+c0P8e1gDZj/PLns77lLJU3OurXalw7lsCU4Ozff3kzIBlFICbROKz5 Wr63YF3Tp0rb5FvwOHBYA3QDMQpVhypJkSEx/uO5DTSDYRpsgdmNIP3pslQiQaDX R7ja2MceSRwLgMR0gMRqB/E973AYvLWD9U7gB4OECl3nI5kGjlQtFHMREofZCpAt fMzWhn4bnRDdT0k6lOwItkdiP264YIQXALVJgNDiwRHlAiyu1Ka+tknWutKzxjcG aEzhxaMbrq/v1MZr5B2/dFn5qCJbKuW35jg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrudejgdduheejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhhrgggtgfesthekredtredtjeenucfhrhhomhepkghi ucgjrghnuceoiihirdihrghnsehsvghnthdrtghomheqnecuggftrfgrthhtvghrnhepje ekteekffelleekudfftdefvddtjeejuedtuedtteegjefgvedtfedujeekieevnecuvehl uhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepiihirdihrghnse hsvghnthdrtghomh X-ME-Proxy: Feedback-ID: iccd040f4:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 14 Feb 2024 17:04:37 -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 v5 3/3] mm/compaction: optimize >0 order folio compaction with free page split. Date: Wed, 14 Feb 2024 17:04:20 -0500 Message-ID: <20240214220420.1229173-4-zi.yan@sent.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240214220420.1229173-1-zi.yan@sent.com> References: <20240214220420.1229173-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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790913619038015105 X-GMAIL-MSGID: 1790913619038015105 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 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 Reviewed-by: Vlastimil Babka --- mm/compaction.c | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/mm/compaction.c b/mm/compaction.c index d0a05a621b67..b261c5f13bef 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);