From patchwork Tue Sep 12 16:28:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13381932 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 CF45DCA0EF5 for ; Tue, 12 Sep 2023 16:28:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 350256B012D; Tue, 12 Sep 2023 12:28:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2D91E6B012E; Tue, 12 Sep 2023 12:28:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 12C4C6B012F; Tue, 12 Sep 2023 12:28:38 -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 EF3B86B012D for ; Tue, 12 Sep 2023 12:28:37 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id C46621A0C5D for ; Tue, 12 Sep 2023 16:28:37 +0000 (UTC) X-FDA: 81228478674.11.1D69547 Received: from out2-smtp.messagingengine.com (out2-smtp.messagingengine.com [66.111.4.26]) by imf25.hostedemail.com (Postfix) with ESMTP id 45487A0027 for ; Tue, 12 Sep 2023 16:28:35 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=sent.com header.s=fm1 header.b="CGv0U/fN"; dkim=pass header.d=messagingengine.com header.s=fm1 header.b=Vo2kSa9N; spf=pass (imf25.hostedemail.com: domain of zi.yan@sent.com designates 66.111.4.26 as permitted sender) smtp.mailfrom=zi.yan@sent.com; dmarc=pass (policy=none) header.from=sent.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694536115; a=rsa-sha256; cv=none; b=WndHT3cSEwnoUt6yad0JNA0MfsQguzOIBYyRcefz2IKDfQhH+ZJH6ti0lhJAiDUHxpeaoX b4XNkK22KsKoHt96sOzL7X3vL5DOwEmIsBnVEtGA/CRGhoQVuek5hX+rZLJrrwaeiPpGcv msdBheAfGnh+k6rLJMGo20iiZ8e09Eo= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=sent.com header.s=fm1 header.b="CGv0U/fN"; dkim=pass header.d=messagingengine.com header.s=fm1 header.b=Vo2kSa9N; spf=pass (imf25.hostedemail.com: domain of zi.yan@sent.com designates 66.111.4.26 as permitted sender) smtp.mailfrom=zi.yan@sent.com; dmarc=pass (policy=none) header.from=sent.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1694536115; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=l1QmaKsAs0paNUi+ts0YZyUc8/34+jxr73p6s3d8XgM=; b=ji5B5Z+LgHnh8dag0w7UeUGjpLERvuL1hyZ7FvEgpB7pPTmWS38e2rtkX4HVOsK+3vycnU w82AsIAeIRjoxCdM6oRq2m/AmNNavssEoC4nHqIoSEDdDCwBjXMnW2bfjRsygGyWvRpbBW 1OjGUNxR3iKQ1WLuWRKgFTMDvQCCGgU= Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 895995C022E; Tue, 12 Sep 2023 12:28:34 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Tue, 12 Sep 2023 12:28:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sent.com; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:reply-to:sender:subject:subject:to:to; s=fm1; t= 1694536114; x=1694622514; bh=l1QmaKsAs0paNUi+ts0YZyUc8/34+jxr73p 6s3d8XgM=; b=CGv0U/fN66Lrt9dDPPSCbQa5AY52dtGJOyDZ0tS7J1mGwebKfps NhByliGCEQkj6G9iRYleWIxPKatnk3rJ+a3YHxdHMGGVH37D5ZtF7No7vvUokyK9 m6rYYOfIbeW5T5WzXU1YQSQh/ujkDjAp/GS6wb3VFCgQtB3NsRu7HsCzxiO6Tay8 h//tS5qjIls/sjbucjzlUWQVvi/pHFFOKF+KaCd1kZ8XHVTxaT1oZ34RcKwXkOIP x7TR4ziqR4Q4enld9IeNFdHldT655BJNYA6nqAxlGEyVFDRzybk+DDVlSOlXPWS3 KDrLFpYI4P1+1qsZwB1jmNLdY9FPBG7A4Rw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :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:sender:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t= 1694536114; x=1694622514; bh=l1QmaKsAs0paNUi+ts0YZyUc8/34+jxr73p 6s3d8XgM=; b=Vo2kSa9Nzs4JRJzpGNI+smMKi1kWj7MvyRZkuvWyDbwklDKbNhR VtKNQ5K4LAtVehWPTp3K0wnH3Z7lwEM2QbBQ0lmVuTrZ5eJ/iF9xFeCDE3GBLowJ dswvJsUbW3/QBcQjmazYMI/Db03ANvlW6HavV4F6KDvvaDu7IUCgtWTqpqoOn2hj f5x6uu8UTIuEgfADSSmO37zlt8Gk4Jwii64Y4doC0dCIJ07ZtWm0Sw1J9A0ZdAi3 9awfWb0w/+pt1bzsGqK8LIC+Qz5nXcei30LmyucoiQS5yL4irtCavl0HrIoVZTR+ supWj9q8RT+NIUfYfm4Uwl/Wuw1hB81+R6g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrudeiiedguddtudcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefhvfevufffkffojghfrhgggfestdhqredtredttdenucfhrhhomhepkghi ucgjrghnuceoiihirdihrghnsehsvghnthdrtghomheqnecuggftrfgrthhtvghrnhepge eghedugfduuddvleehheetgeeltdetieevuefhffevkefhveeufeeiieejgedvnecuvehl uhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepiihirdihrghnse hsvghnthdrtghomh X-ME-Proxy: Feedback-ID: iccd040f4:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 12 Sep 2023 12:28:33 -0400 (EDT) From: Zi Yan To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Zi Yan , Ryan Roberts , Andrew Morton , "Matthew Wilcox (Oracle)" , David Hildenbrand , "Yin, Fengwei" , Yu Zhao , Vlastimil Babka , Johannes Weiner , Baolin Wang , Kemeng Shi , Mel Gorman , Rohan Puri , Mcgrof Chamberlain , Adam Manzanares , John Hubbard Subject: [RFC PATCH 2/4] mm/compaction: optimize >0 order folio compaction with free page split. Date: Tue, 12 Sep 2023 12:28:13 -0400 Message-Id: <20230912162815.440749-3-zi.yan@sent.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230912162815.440749-1-zi.yan@sent.com> References: <20230912162815.440749-1-zi.yan@sent.com> Reply-To: Zi Yan MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 45487A0027 X-Stat-Signature: 3p3kwigsnywf1z4ukn5swsxrh6rr7ub8 X-Rspam-User: X-HE-Tag: 1694536115-1038 X-HE-Meta: U2FsdGVkX1+5CKOG13gAOfXAPJGoRGo5DyxSZdA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/2K3Ikjbl5Bq93Cwuk+bKQ97FH0Jf+5tYM9bZPrIu+dTbUR0KIrF2qzu5WFZwruG/UUC4Wb6rfarHvL4fxyYLmlvITrb0lHUjYJCUw50IE8f6NWF08PedAKV/M15+P6wPcgdT4/5bTK4bQfpLoUcy8TlmOOgk71Lr3/8I2qFXY9sPxKvM4yIt7LaL3x/eOcMX0PcroAM+K2wvedSp+tBl0NdEtcJ1MZU+PnTq5xl5FRKMtnDvZniPH5EWqKspzv+lJB+VkcNtcKkNYkHctR1vI/9j8swEZf8GSBZI1aT2UZ1cegVQSXzcLTvteHRArST0RnTX5pNJwcqDng== 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: 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. 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 | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/mm/compaction.c b/mm/compaction.c index 868e92e55d27..45747ab5f380 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -1801,9 +1801,46 @@ 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_free) { - isolate_freepages(cc); + int i; + + for (i = order + 1; i <= MAX_ORDER; i++) { + if (cc->freepages[i].nr_free) { + 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_free--; + + while (start_order > order) { + start_order--; + size >>= 1; + + list_add(&freepage[size].lru, + &cc->freepages[start_order].pages); + cc->freepages[start_order].nr_free++; + set_page_private(&freepage[size], start_order); + } + post_alloc_hook(freepage, order, __GFP_MOVABLE); + if (order) + prep_compound_page(freepage, order); + dst = page_folio(freepage); + goto done; + } + } + if (!has_isolated_pages) { + isolate_freepages(cc); + has_isolated_pages = true; + goto again; + } + if (!cc->freepages[order].nr_free) return NULL; } @@ -1814,6 +1851,7 @@ static struct folio *compaction_alloc(struct folio *src, unsigned long data) post_alloc_hook(&dst->page, order, __GFP_MOVABLE); if (order) prep_compound_page(&dst->page, order); +done: cc->nr_freepages -= 1 << order; return dst; }