From patchwork Mon Feb 12 16:35:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 199918 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp34472dyb; Mon, 12 Feb 2024 08:42:09 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCV07LXfWE3mCt9KHMx/X/HOoiwik6V8/dH5HIzK8058bPjHcJbcGU1K2ZY6F0CPf0P9PDzb65vIYwZfU+FDPF2xIL8TAQ== X-Google-Smtp-Source: AGHT+IER2cmob1Vr9HIG3a54uRv0IVkAxnRypaba1gWmAdhFBdosIHuaqe0UdRt9CpAw3/lA4Yzd X-Received: by 2002:a05:620a:4051:b0:785:c8ba:81e0 with SMTP id i17-20020a05620a405100b00785c8ba81e0mr8135671qko.57.1707756129199; Mon, 12 Feb 2024 08:42:09 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707756129; cv=pass; d=google.com; s=arc-20160816; b=xIreJ/hTsuxL18ofy+xScpOukmRlEFexiYjPDlr1WaLqO/wDsmLxfPVYkakowN9LzX rdUboLlXLrjXDHYmLl2AZ3L1g3o1NiHmU5XsUCbpw4J5w8syQAjaNvVpKFFo5/VcaQPR wfFnu0CSJtz9JVPeZIQ7qaj5QDNz47U6jF/tyv5xEa0IYe2eR6LsLaumuUnEA3qz+i+w Tms9Kct2MKi8BfbiFp9jdsTB30fmDwR3P+xvobYAZ+YjWfK0Gr1YY8vGRx7sXN1ugsVt V0Rydu9s9r8myqzrRUiR++xZq1tn4JIxsP7lCdLFgYqCv4o3NYV2nCo1e5/4nsmwprjm uYfw== 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=/EqPdua3wUu7egs9hj3joQyCeB5KILvG5+17pYfAKJw=; fh=jjsXbedxMiKxzxBkRbLidSxRW5XFRE5oHCTJV/+xFn0=; b=0tCHM6JzwfMP2H0r1Gwj1sZtPHcDOoeCJxYVsg5TcETF5nCdDUcSlL8ThohOlMplfL j4MB77MNlu4wVBiunYq4VWIP7Mo1mfmknbz5iMmxSPa4cD8XyzlB+62Gg8iAJwmERiV3 DMGAipOeRkj5x/x5tdezodwk1FHNSlCpL0XduNxHqaOo6ya/HjmVyFJSfcuBzeNGLnZc WisdIdrvsL3jKtWYc5VA2+wNhL8Qmv1HnVQCEXdMNKDGWgGioMiyscIN4fac8B7/vwnw I7qH8kfjNbLk1VHZC+VhbfLE4uHISCbSBiFNzZGyXZED3s+H8xkVVTZ/PFRcdDrRDZ4x MHMQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@sent.com header.s=fm3 header.b=HlmOQr9q; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=J2YOywBV; 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-61995-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61995-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sent.com X-Forwarded-Encrypted: i=2; AJvYcCVHl1hI5XGJAXn9y4ct/LBQoZILDE3ZCs2LMKi/TxoK2OWbkI74OmMRYOX6KI/4HbcTUyZkMf3jb8cckZrmTzWyR3G1gA== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id m8-20020a05620a290800b0078717e581aasi146675qkp.711.2024.02.12.08.42.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 08:42:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-61995-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@sent.com header.s=fm3 header.b=HlmOQr9q; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=J2YOywBV; 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-61995-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61995-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id E77F51C218D0 for ; Mon, 12 Feb 2024 16:42:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7BCCC481D0; Mon, 12 Feb 2024 16:35:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sent.com header.i=@sent.com header.b="HlmOQr9q"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="J2YOywBV" Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) (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 8901B182C5 for ; Mon, 12 Feb 2024 16:35:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=66.111.4.27 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707755720; cv=none; b=RlfhgeFm4mlLH1otL2UVwD9jEzLWs/G3EB5UHdD8K9LAEvUDDZXgHbG0ADJZMw+2FPxib6+36P4wplzlsN9C5t2AFgcp783Zjx2cSj4zKZhcqkHz/kh7ZCAFCTMP089XFKs1o9NmgtTPSQCKRD6zZyWBcs91/OMEv69xP31xphg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707755720; c=relaxed/simple; bh=IDzhkY1a4910plU/Bf1p6UotGfhcV2qh2ZuJcavuoW4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=kn0EfuQR50fBqOK/VLaq53O6NRfz8Lq1onJ3BId08Vgzbpuawm8XlkfkaDLMi+HDXpeL9+1HplMQqwms5ezg08HSzg24RwakwfPDW898764WbzZahU+SiviAKbeLVtLoFqFLaSTS6TrTNngCHfRdvliz8eh2S60qR/hxrdZQK7E= 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=HlmOQr9q; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=J2YOywBV; arc=none smtp.client-ip=66.111.4.27 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 8F20A5C00CA; Mon, 12 Feb 2024 11:35:17 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Mon, 12 Feb 2024 11:35:17 -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= 1707755717; x=1707842117; bh=/EqPdua3wUu7egs9hj3joQyCeB5KILvG5+1 7pYfAKJw=; b=HlmOQr9qvHE0N6b7r3vJLZNcb3UVrG8RUx4z6QwPWhLBya5sAT9 V/S8Zqpwle9MkAqKRpupK3V2y9nYsva6hSKmft+SWN0zTIoSACDHPIyodradZMjy g+GChb5rZTZ44gfLzd7CUhTC0ssGdm7FJ4mYXHBBtjFA0hDoYMWCuOFobhFSSMaK my8JWVzC16TrYyZO0HNWwVqcee9zpknq/X4JA2fQlF2BU5e2k/PCfbhgTnkzNt2i 2hZBq9/vVwdpRqc9Jw3Ba02aMdxcuP6xjPriauzPyPw+VO5OH8Q9t/KqKNte/okX gxJiwWJoFaUX3BdyN2TVc42jIOZnVCM3oNg== 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= 1707755717; x=1707842117; bh=/EqPdua3wUu7egs9hj3joQyCeB5KILvG5+1 7pYfAKJw=; b=J2YOywBVYcHvZh7SL9Ztx6GaM3mrxWauzT0f5e3Y4/dspDxc67z 0VnElepBVZ/VU9ofd0CW9IdSk+E7tGKMbk72o8MDHt4nIP/V3BV1+7XRh8zkGLZi Qwjkb6t/nNlSuJseIqlikcvWUbzFbWnXQJ+MheLqK7u1DlXuf28jrhHStz07sqFi 0GW/1LGHaNq5478fa5nBMOQpSzr6nmCKNpj7n/tRqAbB07H0Iwze+SKx5tyt2Blm H0L4gRsQaUbjFFUNrwbG1TrzHq5cqxNGBkLFKaCIgBOOftaOWtNkzNsfxoiCkguE JICNz/Blga59c1UaxavgBIMUYrtQMc6AtlA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrudefgdekkecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvfevufffkffojghfrhggtgfgsehtkeertdertdejnecuhfhrohhmpegkihcu jggrnhcuoeiiihdrhigrnhesshgvnhhtrdgtohhmqeenucggtffrrghtthgvrhhnpeejke etkeffleelkeduffdtfedvtdejjeeutdeutdetgeejgfevtdefudejkeeiveenucevlhhu shhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpeiiihdrhigrnhessh gvnhhtrdgtohhm X-ME-Proxy: Feedback-ID: iccd040f4:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 12 Feb 2024 11:35:16 -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 v4 3/3] mm/compaction: optimize >0 order folio compaction with free page split. Date: Mon, 12 Feb 2024 11:35:10 -0500 Message-ID: <20240212163510.859822-4-zi.yan@sent.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240212163510.859822-1-zi.yan@sent.com> References: <20240212163510.859822-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: 1790712090794469085 X-GMAIL-MSGID: 1790712090794469085 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 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 Cc: Yu Zhao --- mm/compaction.c | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/mm/compaction.c b/mm/compaction.c index d0a05a621b67..25908e36b97c 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -1832,15 +1832,41 @@ 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) { + isolate_freepages(cc); + has_isolated_pages = true; + goto again; + } else return NULL; } - dst = list_first_entry(&cc->freepages[order], struct folio, lru); - list_del(&dst->lru); + 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; + post_alloc_hook(&dst->page, order, __GFP_MOVABLE); if (order) prep_compound_page(&dst->page, order);