From patchwork Tue Jan 23 03:46:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 190701 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2553:b0:103:945f:af90 with SMTP id p19csp104386dyi; Mon, 22 Jan 2024 19:48:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IEa3JJJnNPm53xS1t06BywsSuLW+inzbBUpi8yV2rAexXSuetDiKeyMjiPb2iY0Gk/23p0W X-Received: by 2002:a05:6870:b4a7:b0:214:816f:8b5a with SMTP id y39-20020a056870b4a700b00214816f8b5amr744165oap.12.1705981682890; Mon, 22 Jan 2024 19:48:02 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705981682; cv=pass; d=google.com; s=arc-20160816; b=zSS8agig53lBcqxTHlTjkUKrJWrk/bkyekQo+tffJCbJd0jRMNO3BP1UmvWkLNLD0R JI2Xz+ZOlWr8QtXaGWcG57YnAk+LQgod0xfaI4ExPazt2bEVcn/C85Ds+KuD1u1eU+68 gWLNEx3IPgZTA4y8FGCf8DNO2cQsV6qUnxccmNw5hv9aipXn5fg9DPP2TUc1Y0MCg1FL bCe1SxR7Wb4PbP9Hd7xIg7OMDI8owvidHjt+0a1jJawQN9ja2/qDgqkz5j2PE/9Smw/F nQq973kIGZIB3D03gGvNd8V89UiZj/kolYXs/UCWAyUu9rn+64DUDnor7aQ+C0X2pRdJ 9Mkw== 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=nFXKGo9rKF119RBUFLJm4CCIEN+EywVvwTP6Mlui2MY=; fh=vJ0CYzlC3FzFcxY+JvdHzizIe8XjzG5USPt1Sa6qsGI=; b=uZxAgM0ZEyB44iK/9G+rjdH4QvEhuT5OXpYb4xrg173myy/udwFnK8l2ooXwbYgq30 rV1uitpNXam/IZWkY+sA+WR4Rn9XeMJY/mf3Q1Sbupku2WOuU7Ndor6+DZM8/UlVrxoz EwZMea3LFwJ+YNdvL3R5aG20cpq39A8qc17+V6ppFNazqws3gv4ZVtZNLTQHQM6forQG tzNArAuL3kyqwnnkBzZHdTEocHAw7spNAVQW8YpFjXJzwNucaA2oc9q0YT1UkoenDp+9 ksJeitrMhvVmERg4+UcDOsbKM5WuvnUlmy+69bc8z1QQh+MGlHc7PcCYIyLJEOLxHEMQ ikWw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@sent.com header.s=fm3 header.b=Qb1tyZd8; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=y6CtXNfh; 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-34690-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34690-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sent.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id o14-20020a63f14e000000b005ce172ef504si8950278pgk.36.2024.01.22.19.48.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 19:48:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-34690-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@sent.com header.s=fm3 header.b=Qb1tyZd8; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=y6CtXNfh; 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-34690-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34690-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 97E2028C70E for ; Tue, 23 Jan 2024 03:48:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 798054C75; Tue, 23 Jan 2024 03:47:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sent.com header.i=@sent.com header.b="Qb1tyZd8"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="y6CtXNfh" Received: from out2-smtp.messagingengine.com (out2-smtp.messagingengine.com [66.111.4.26]) (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 2E0D31846 for ; Tue, 23 Jan 2024 03:47:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=66.111.4.26 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705981632; cv=none; b=WwYCfZC7LVuNp15Nx1llWc0JUrrp4gv0f1AgAQ5YGPGrcp/4qOfLxgjbIiHif/XbEeEUOgBjl7ERWc+a1tFyb5nY+TO90u3bhGCmVIAE2zuLDCxo9lLz5zcEB7AbhKJaLejmLYdHgdoRvbI2zuU0AXwJ6VKaTdnIIpuxiLZHOPo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705981632; c=relaxed/simple; bh=ChbwKacJ/HMj8dgI/u5v/MtBZcKgELpNCavNVXl7nio=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=fqqrO93pbUU0e8XeGekVb3Z8UvCXjmQ73Lnn6xKstrrlbeiG5o102vKJ2g6/O0CcxSE9ltd74Gfn9fMpI2BRUBamNTrHHPzegUnOuly5HSgrcWpY37S7Q0pgpOezxVDazl9aToPj3sgrpjSgLRtWKDUrZxD02Y8JP6VDjKyAoGo= 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=Qb1tyZd8; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=y6CtXNfh; arc=none smtp.client-ip=66.111.4.26 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 6F0165C0335; Mon, 22 Jan 2024 22:47:10 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Mon, 22 Jan 2024 22:47:10 -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= 1705981630; x=1706068030; bh=nFXKGo9rKF119RBUFLJm4CCIEN+EywVvwTP 6Mlui2MY=; b=Qb1tyZd8hBxmQdzvOqm/NUrXgHvdk6O59nKJ/UAjsWmR+NJt8o0 sQMQ3BHdYvYBMUEaTgEVGQ1Yg0p04a5toQcQHryZNBnFE/N5HHcXAjP1RpfJGbBg zPxkJCCea7vc0sx3iBeqQy2Kxpj5MYwfVZHYJh8Yqrw/4c2PUnINhNsXKCl+3Wwn Z78At21kPb3Rb1YBAt0Fjjn0QCaYhlfnl/tbX02RhfSUi3eBNufKh+/pEgpOOvE7 DQW1765+/v+nbu7Tf8agm8NoaVUoa4ohTLXtbJk7cY2KtIYz35JKRDhqDy5SnuqG 5/D/WpH1IkLPUgbJm1HcW4IcFI0J+VhgOxQ== 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= 1705981630; x=1706068030; bh=nFXKGo9rKF119RBUFLJm4CCIEN+EywVvwTP 6Mlui2MY=; b=y6CtXNfhQE6UEMdpchPy2BMY5+J1ZsljEUixwVzuhCDkmIckFIu MXK96g2nWTilV5FRWN9CrDxiyGd9DbYosxAXS9pSZYbZqN17/nULWf+mylk3uEm8 CCC6nENgxubwk4/OmfXmDfGlB2tHQI5SQV8A4vVyHUsqRKvAvRr6s03hxvmCeViT jJerNmHRpIN0E0Fo0RChyTjp5BNs4uZjvZk4SnQFETm0b+iJL0bK5GBtbM5PFhzq z574F6aBUj9JBJjAZdDvWvX+Jpk47SjgmRkm6lTvWSFKzUeYVen1otfGPdf9/UGI k75oGdJXDYQGfdq8CvnGI/Tp74NEEKpvGWw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrvdekjedgieduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhhrgggtgfesthekredtredtjeenucfhrhhomhepkghi ucgjrghnuceoiihirdihrghnsehsvghnthdrtghomheqnecuggftrfgrthhtvghrnhepje ekteekffelleekudfftdefvddtjeejuedtuedtteegjefgvedtfedujeekieevnecuvehl uhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepiihirdihrghnse hsvghnthdrtghomh X-ME-Proxy: Feedback-ID: iccd040f4:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 22 Jan 2024 22:47:09 -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 v2 3/3] mm/compaction: optimize >0 order folio compaction with free page split. Date: Mon, 22 Jan 2024 22:46:35 -0500 Message-ID: <20240123034636.1095672-4-zi.yan@sent.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240123034636.1095672-1-zi.yan@sent.com> References: <20240123034636.1095672-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: 1788851448932213721 X-GMAIL-MSGID: 1788851448932213721 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 --- mm/compaction.c | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/mm/compaction.c b/mm/compaction.c index 11f9898e39da..052c82481d64 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -1812,9 +1812,43 @@ 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; +again: if (!cc->freepages[order].nr_pages) { - isolate_freepages(cc); + int i; + + for (i = order + 1; i < NR_PAGE_ORDERS; i++) { + if (cc->freepages[i].nr_pages) { + struct page *freepage = + list_first_entry(&cc->freepages[i].pages, + struct page, lru); + + int start_order = i; + unsigned long size = 1 << start_order; + + list_del(&freepage->lru); + cc->freepages[i].nr_pages--; + + while (start_order > order) { + start_order--; + size >>= 1; + + list_add(&freepage[size].lru, + &cc->freepages[start_order].pages); + cc->freepages[start_order].nr_pages++; + set_page_private(&freepage[size], start_order); + } + dst = (struct folio *)freepage; + goto done; + } + } + if (!has_isolated_pages) { + isolate_freepages(cc); + has_isolated_pages = true; + goto again; + } + if (!cc->freepages[order].nr_pages) return NULL; } @@ -1822,6 +1856,7 @@ static struct folio *compaction_alloc(struct folio *src, unsigned long data) dst = list_first_entry(&cc->freepages[order].pages, struct folio, lru); cc->freepages[order].nr_pages--; list_del(&dst->lru); +done: post_alloc_hook(&dst->page, order, __GFP_MOVABLE); if (order) prep_compound_page(&dst->page, order);