From mboxrd@z Thu Jan 1 00:00:00 1970 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 0878DC4828F for ; Fri, 9 Feb 2024 20:43:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 74B4B6B0078; Fri, 9 Feb 2024 15:43:07 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6D3E56B007D; Fri, 9 Feb 2024 15:43:07 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 500636B007E; Fri, 9 Feb 2024 15:43:07 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 399AB6B0078 for ; Fri, 9 Feb 2024 15:43:07 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id F38CB120700 for ; Fri, 9 Feb 2024 20:43:06 +0000 (UTC) X-FDA: 81773439972.23.D1A7D20 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf28.hostedemail.com (Postfix) with ESMTP id 5A260C0012 for ; Fri, 9 Feb 2024 20:43:03 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=IJdjc6ff; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=ZqzsBhrL; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=IJdjc6ff; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=ZqzsBhrL; dmarc=none; spf=pass (imf28.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.130 as permitted sender) smtp.mailfrom=vbabka@suse.cz ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707511383; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=MPJrFIpcUFp3ljkSzw+njm70TJFkUJE5UKVeap+Smwo=; b=6rwu22KyG/P6iHV5SRn5mlvgPJo48OCPAGWw6QIKoMRwUA/jsugrHgMfespAgoymtDoxn8 DWQ4JV/9CuCsVnCiByKzixV9hcoK96NNUXSNGuYie9K7oHM19ldGky6vltgMToErjlaikF qc00NrfVzsLULVQLQaOPAhVMqjY+TQU= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=IJdjc6ff; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=ZqzsBhrL; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=IJdjc6ff; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=ZqzsBhrL; dmarc=none; spf=pass (imf28.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.130 as permitted sender) smtp.mailfrom=vbabka@suse.cz ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707511383; a=rsa-sha256; cv=none; b=vklXNLLdzldAt+jcnk+rIR6Zz3rlbPPYfq8KE7sGzVrAZy8rSsEt+cq7+YnkyIDVROgKFe iSoH0L816JrqmCgs4Obgf6it5clpEOuuzSbxjdYgoOfOi3XGU2Mpr3po6hm8Pe0ia/W2GO UDbi3Bmu4rsvpY+ltwLh45cQvyi8ALU= Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 7F91A21DDD; Fri, 9 Feb 2024 20:43:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1707511381; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MPJrFIpcUFp3ljkSzw+njm70TJFkUJE5UKVeap+Smwo=; b=IJdjc6ffE2sXRMPORezrFCcH10QAAgA6YrcZWCY/Gpi8ipg/ndAuyj8vrDB8K3UnfpkJOQ nvX7C9QSrT91VTlORvYAzVoRUZMg4Jk8neNNqB4Xa8ovt6GB81bdo1Qsx5RkVcoXCHVoz8 AMP4coUX4PU/f5FLnm85eCSqD0c3dWE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1707511381; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MPJrFIpcUFp3ljkSzw+njm70TJFkUJE5UKVeap+Smwo=; b=ZqzsBhrLrsaCWRnCo7gqEKFB/Qv6oOstLfTzhCMK9Ypp3KEMVTtf/xtAfy3C0cyYSQ0vHU f7IR/9p5IyrzY1Bw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1707511381; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MPJrFIpcUFp3ljkSzw+njm70TJFkUJE5UKVeap+Smwo=; b=IJdjc6ffE2sXRMPORezrFCcH10QAAgA6YrcZWCY/Gpi8ipg/ndAuyj8vrDB8K3UnfpkJOQ nvX7C9QSrT91VTlORvYAzVoRUZMg4Jk8neNNqB4Xa8ovt6GB81bdo1Qsx5RkVcoXCHVoz8 AMP4coUX4PU/f5FLnm85eCSqD0c3dWE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1707511381; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MPJrFIpcUFp3ljkSzw+njm70TJFkUJE5UKVeap+Smwo=; b=ZqzsBhrLrsaCWRnCo7gqEKFB/Qv6oOstLfTzhCMK9Ypp3KEMVTtf/xtAfy3C0cyYSQ0vHU f7IR/9p5IyrzY1Bw== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 4DD7F13353; Fri, 9 Feb 2024 20:43:01 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id MLGzElWOxmVyXAAAD6G6ig (envelope-from ); Fri, 09 Feb 2024 20:43:01 +0000 Message-ID: Date: Fri, 9 Feb 2024 21:43:01 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 1/3] mm/compaction: enable compacting >0 order folios. Content-Language: en-US To: Zi Yan Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Huang, Ying" , Ryan Roberts , Andrew Morton , "Matthew Wilcox (Oracle)" , David Hildenbrand , "Yin, Fengwei" , Yu Zhao , "Kirill A . Shutemov" , Johannes Weiner , Baolin Wang , Kemeng Shi , Mel Gorman , Rohan Puri , Mcgrof Chamberlain , Adam Manzanares , "Vishal Moola (Oracle)" References: <20240202161554.565023-1-zi.yan@sent.com> <20240202161554.565023-2-zi.yan@sent.com> <24D4AA55-42F5-4E9B-822D-2BE61D0FA51F@nvidia.com> From: Vlastimil Babka In-Reply-To: <24D4AA55-42F5-4E9B-822D-2BE61D0FA51F@nvidia.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 5A260C0012 X-Stat-Signature: yrgn7utt6boy4q7ecy1wce1bmuwbuqp4 X-HE-Tag: 1707511383-475382 X-HE-Meta: U2FsdGVkX19oOXH6VIUAhjFQDGajossoT47ZHsYlPN6ScgIFBcCXfFV+0uj6w1hepDjLQlTP6oQl+M5/c4io9gVct0MnTJUhtCQqr0xxYzbbbliscuDjjisRLZIeR6jFMkfhQlbKaqlEuFpvamU0TOLOi5qGAr+m2Ro0IkKZ6cnI9o0yiGYHB9pgbiFzZ0uTEwiZ+iREN72PUbqBRX3I0KciKrMpPaEn7c68468URfDPcsxydPYY0IeZaLtSEtPlSw/keve4gR3PDV93hiXrpXm2hlX6QrPNnqkTsMwh/ly8BD2MLQzh8gwfi1F07xvhWKEk6emE/EmrC+w8y/NTousEGBtXKfnGmZvAvuWicSirI1ROcjh3eXgwaUF4gsz2b/FiG1m4VVCyV8FyQkAkZsAP6VJXsBhT4pc/P6O1l1++KBCbFfVL+4ta0obJLIYBcQJFGeT0veloy/CSM+/A4l1NRATf17P62Bx/YkM9gJqQl7l4MSL9HyLdmPnmIWj3BCjawbgnudtafwETTaiYAwiRnsrQkeIn6u2WqCbTslDYpwD7OKkZj3Ks7VXabbDEzHLgRaWGr0b1iz3ggQtTDw5qhBS6qnNHxH+woeLsvWbuj57+eGqy7mFg9NH7gvdBM3bWuFan85gpAKrtC/6RvT4CUFESP2q+l2zc2lJ8u+XVQgMYvq6jVns/nZJ8OXHrnJdmQbdGSY2q3h35AXjHeqgszKc5KUdV6SgnllTXl1hu9GKeaurbfjbvRJtX5BWPc5AH0TbU9Y5j2LElS7LN6UYw0KHpEJisyYPngiZX3SwHHCNleU0J5WSUyh45xIIvNxkXS5GfehFmSGXNoLVpXe7+xUWOVLDkyye9g2y4owgLdb7evCz1jSu5eDNoM4PbUnpeEEMGrtLnmzVFAHQSDOU6lN++GbBJEbVkEAswUke/kUFC4eZpcFIYGAXtjSAKljX8cvo0YSqkP3AY3jj 1Fj36sIE ko+v6zpiZO1Sxlg0tIzx329ysKcETmf5iyy9/LM4osi3SxFDgxCjkpnn7SDbvVPFIwkMKWBTZZ9EzdcWkn1xyNtJnhyMdzln5csHG/MmPMcPSrGcp/ftr21AuCtbCHmZExdOXFheV1FN21tE2GukIRULO8pdekMWj3UwqoYdBuzyt0K1thELVTO65SDN4cUMevgJaQg0yBudK77VhpHS+qnUVd2m5izChv1C7SJ/oSdizM3RvlCbTIN/ZNyN+ry0AvuD1OgjzICHMVixXrTSgy0dashSGGNkoTyPgVTsjn555eAaV0K3jp8cww14AneGioxvK/2+Nknsc7rlFfzJm7TPJGleK075aCvhhqguuoPiqFCmO9yzpteo/iY6P6Sf8+2/60v4XaGRXQ3ZJE0ngh3vujWZ6jQND+1xRJF+lOe9OEMdMmNsvtYQT8eHjxy1vLMvm 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: List-Subscribe: List-Unsubscribe: On 2/9/24 20:25, Zi Yan wrote: > On 9 Feb 2024, at 9:32, Vlastimil Babka wrote: > >> On 2/2/24 17:15, Zi Yan wrote: >>> From: Zi Yan >>> >>> migrate_pages() supports >0 order folio migration and during compaction, >>> even if compaction_alloc() cannot provide >0 order free pages, >>> migrate_pages() can split the source page and try to migrate the base pages >>> from the split. It can be a baseline and start point for adding support for >>> compacting >0 order folios. >>> >>> Suggested-by: Huang Ying >>> Signed-off-by: Zi Yan >>> --- >>> mm/compaction.c | 43 +++++++++++++++++++++++++++++++++++-------- >>> 1 file changed, 35 insertions(+), 8 deletions(-) >>> >>> diff --git a/mm/compaction.c b/mm/compaction.c >>> index 4add68d40e8d..e43e898d2c77 100644 >>> --- a/mm/compaction.c >>> +++ b/mm/compaction.c >>> @@ -816,6 +816,21 @@ static bool too_many_isolated(struct compact_control *cc) >>> return too_many; >>> } >>> >>> +/* >>> + * 1. if the page order is larger than or equal to target_order (i.e., >>> + * cc->order and when it is not -1 for global compaction), skip it since >>> + * target_order already indicates no free page with larger than target_order >>> + * exists and later migrating it will most likely fail; >>> + * >>> + * 2. compacting > pageblock_order pages does not improve memory fragmentation, >>> + * skip them; >>> + */ >>> +static bool skip_isolation_on_order(int order, int target_order) >>> +{ >>> + return (target_order != -1 && order >= target_order) || >>> + order >= pageblock_order; >>> +} >>> + >>> /** >>> * isolate_migratepages_block() - isolate all migrate-able pages within >>> * a single pageblock >>> @@ -1010,7 +1025,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, >>> /* >>> * Regardless of being on LRU, compound pages such as THP and >>> * hugetlbfs are not to be compacted unless we are attempting >>> - * an allocation much larger than the huge page size (eg CMA). >>> + * an allocation larger than the compound page size. >>> * We can potentially save a lot of iterations if we skip them >>> * at once. The check is racy, but we can consider only valid >>> * values and the only danger is skipping too much. >>> @@ -1018,11 +1033,18 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, >>> if (PageCompound(page) && !cc->alloc_contig) { >>> const unsigned int order = compound_order(page); >>> >>> - if (likely(order <= MAX_PAGE_ORDER)) { >>> - low_pfn += (1UL << order) - 1; >>> - nr_scanned += (1UL << order) - 1; >>> + /* >>> + * Skip based on page order and compaction target order >>> + * and skip hugetlbfs pages. >>> + */ >>> + if (skip_isolation_on_order(order, cc->order) || >>> + PageHuge(page)) { >> >> Hm I'd try to avoid a new PageHuge() test here. >> >> Earlier we have a block that does >> if (PageHuge(page) && cc->alloc_contig) { >> ... >> >> think I'd rather rewrite it to handle the PageHuge() case completely and >> just make it skip the 1UL << order pages there for !cc->alloc_config. Even >> if it means duplicating a bit of the low_pfn and nr_scanned bumping code. >> >> Which reminds me the PageHuge() check there is probably still broken ATM: >> >> https://lore.kernel.org/all/8fa1c95c-4749-33dd-42ba-243e492ab109@suse.cz/ >> >> Even better reason not to add another one. >> If the huge page materialized since the first check, we should bail out when >> testing PageLRU later anyway. > > > OK, so basically something like: > > if (PageHuge(page)) { > if (cc->alloc_contig) { Yeah but I'd handle the !cc->alloc_contig first as that ends with a goto, and then the rest doesn't need to be "} else { ... }" with extra identation > // existing code for PageHuge(page) && cc->allc_contig > } else { > const unsigned int order = compound_order(page); > > if (order <= MAX_PAGE_ORDER) { > low_pfn += (1UL << order) - 1; > nr_scanned += (1UL << order) - 1; > } > goto isolate_fail; > } > }