Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp1117440rdb; Fri, 9 Feb 2024 10:43:57 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWDhDeOJy7Y6ooaMUbTvyKfq3Fzhx1SaAe9KU0R2japD2+9F4qI+g3IGt4ZD4aFDhC4Gxp8DMtTQw0G+4OPeGBz0CDYRsAfpuQGXnpw8w== X-Google-Smtp-Source: AGHT+IF9QVS1OkI5A7NqDN1ZqDwzxcjhr9C3xqdklbDN+QKi+BkfJTw4pA0sYxOGJXA+97caR3ir X-Received: by 2002:a17:906:16c4:b0:a38:29e5:e6e6 with SMTP id t4-20020a17090616c400b00a3829e5e6e6mr1761829ejd.8.1707504237442; Fri, 09 Feb 2024 10:43:57 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707504237; cv=pass; d=google.com; s=arc-20160816; b=fzOyo9cr8t+oHhzjvW80Xtl7HinzkjMeh38/BeoJ7R0fya55/qHOsLjPQVPsLOi9/o MsN1l/omLohDhzwg9ojkKlB/JI45/ztHkHL5BnxNO8cm8IVGNIKhf4Hd8OoShx01aS5c UiMdHLCAca8y8c1K5HwYWM5EQsOuASgUnTysU0YPS0VBy1SChP3z/j3ORjKx5NbSs/0d qvJnIiBz8un6t9n2H+B1jA3IkNL1Ya0Dk6Bub/5eGowDsJUL1a8SVJUErr/d65RM8F8T 7idbKUG48yn7/ER9V4HcFUFTLOWU1DBMFA4IA3ZYuF86G6sa8J1o8fBjIqpAOKoF0QrD sEHQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature :dkim-signature:dkim-signature:dkim-signature; bh=lEYLn4TkDj+5w5M8frhbdwGFmGUrN6QrUzMzWCOgpfU=; fh=Op8qKy72LCNismfR+lA38bvCneeYZb9JpOe1nNSVTBQ=; b=iaSraBQhN+4i6vw/cAJjM9cKG68tbiA55kNUvUw0JTWEh/buc8Cy9cfTi/d7SLZiRR jJEuKU6klkrhhxAQDOEYfbJuj4piB9mOMwmuHcHG6iXb1rGEigcmqDbpY1jAM2SjCvr7 +8BjdGsx3qCVvTo/xCRWKWRXN1Gu/2SR316h4e39qhM8jxDVTxNPkWgnM/A7tInvVIXB /tXl9Bcd0MEDgOADBr+YBdH+WG13Z8wXM16cTCqxZfdEE4Ig6Q6/5zFyFHMOLdkFacsl OVvvY7SP+mtw9O73ARpvEtIYLRBnIZqkLasn/PgOxZYrR0bZIe8BFZxlair526xIJctf 3YMw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=oDksP+4a; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=oDksP+4a; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; arc=pass (i=1 spf=pass spfdomain=suse.cz dkim=pass dkdomain=suse.cz dkim=pass dkdomain=suse.cz); spf=pass (google.com: domain of linux-kernel+bounces-59823-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-59823-linux.lists.archive=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCWdui2OsLDAE8WWHcQP5KRIlPKNJjXz2wbt9wumAt0jynxdHwyjYygzvT73fx5vYVNZX3qlpdeh7rqHkr5ZufMtZC1kLORPzwNqyQ3+EA== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id lv6-20020a170906bc8600b00a37cfdfde7bsi1105285ejb.370.2024.02.09.10.43.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Feb 2024 10:43:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-59823-linux.lists.archive=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=@suse.cz header.s=susede2_rsa header.b=oDksP+4a; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=oDksP+4a; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; arc=pass (i=1 spf=pass spfdomain=suse.cz dkim=pass dkdomain=suse.cz dkim=pass dkdomain=suse.cz); spf=pass (google.com: domain of linux-kernel+bounces-59823-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-59823-linux.lists.archive=gmail.com@vger.kernel.org" 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 107C61F2191D for ; Fri, 9 Feb 2024 18:43:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9FD4379DD0; Fri, 9 Feb 2024 18:43:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b="oDksP+4a"; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b="ql57Be3l"; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b="oDksP+4a"; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b="ql57Be3l" Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8C12E57339 for ; Fri, 9 Feb 2024 18:43:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707504208; cv=none; b=uiBeCKVjhFF4P3301IFHVwPQZ4ipf/S87vWkL1bsifo1ikS11EIUTKAjJgK/6Eiyw/gPWDvMC8E2x3xu88JoozDi2N82cElumZT30F9gfASr9xgEQdFBuvsUm0NWkXv3MbIT4UZv+ushsZmquPPN8z0ub7ul/AZhRtBWHTvDfj0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707504208; c=relaxed/simple; bh=8BNu6pIGu7uFfufiBUNIOSzn6hHb44tdCsXSjKBi27Q=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=OfOcUB4Qcq8+7svIhoyifsH4KMnFymjt4T8/iM7XQ/0YtiIxWiepCO4Lyh9awTbESLBwCIs5l56wWBqjjyZZuINRPYEeLhB5LGd+Hq6TIUvVHQyhn3Qs5l4kqjlOy7UKYRJ2tqsbbQsQAbuANo8xtAH/VZy1D0UkcpIIkB9DZ44= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz; spf=pass smtp.mailfrom=suse.cz; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b=oDksP+4a; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b=ql57Be3l; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b=oDksP+4a; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b=ql57Be3l; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.cz Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104: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-out2.suse.de (Postfix) with ESMTPS id 6C2F71F823; Fri, 9 Feb 2024 18:43:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1707504204; 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=lEYLn4TkDj+5w5M8frhbdwGFmGUrN6QrUzMzWCOgpfU=; b=oDksP+4a6mK9R7SbcISBVXnlhEr2HRVuI2SVyCZk/mRa/n1u9RW17Na6EZvLNBrO7H8lWu AJHZQSu9Mhpp873ZBYCALox9V2a1AELbDJZV/OqaEcSpKxpgEq0OmOMm2VqdrnfQLKKIom njvOZNL0xhjBnLamyalffZlYF4R2rXI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1707504204; 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=lEYLn4TkDj+5w5M8frhbdwGFmGUrN6QrUzMzWCOgpfU=; b=ql57Be3lwdHXayCYGQVnolMO/pvNZRDF3YscjV9kIumUUvtynQXIiX0la1ikcpJJyplzY/ zsb6o0nIN3j+7gAQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1707504204; 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=lEYLn4TkDj+5w5M8frhbdwGFmGUrN6QrUzMzWCOgpfU=; b=oDksP+4a6mK9R7SbcISBVXnlhEr2HRVuI2SVyCZk/mRa/n1u9RW17Na6EZvLNBrO7H8lWu AJHZQSu9Mhpp873ZBYCALox9V2a1AELbDJZV/OqaEcSpKxpgEq0OmOMm2VqdrnfQLKKIom njvOZNL0xhjBnLamyalffZlYF4R2rXI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1707504204; 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=lEYLn4TkDj+5w5M8frhbdwGFmGUrN6QrUzMzWCOgpfU=; b=ql57Be3lwdHXayCYGQVnolMO/pvNZRDF3YscjV9kIumUUvtynQXIiX0la1ikcpJJyplzY/ zsb6o0nIN3j+7gAQ== 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 3C85013353; Fri, 9 Feb 2024 18:43:24 +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 A5voDUxyxmVfPwAAD6G6ig (envelope-from ); Fri, 09 Feb 2024 18:43:24 +0000 Message-ID: <84dfedc4-a0a2-4e02-9be4-2cffc6e9fd06@suse.cz> Date: Fri, 9 Feb 2024 19:43:23 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 3/3] mm/compaction: optimize >0 order folio compaction with free page split. Content-Language: en-US To: Zi Yan , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: "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-4-zi.yan@sent.com> From: Vlastimil Babka In-Reply-To: <20240202161554.565023-4-zi.yan@sent.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Level: Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=oDksP+4a; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=ql57Be3l X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spamd-Result: default: False [-3.00 / 50.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; XM_UA_NO_VERSION(0.01)[]; TO_DN_SOME(0.00)[]; R_RATELIMIT(0.00)[to_ip_from(RLfsxmn1qwoupcjwdqfx65548p)]; RCVD_COUNT_THREE(0.00)[3]; DKIM_TRACE(0.00)[suse.cz:+]; MX_GOOD(-0.01)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; BAYES_HAM(-3.00)[99.99%]; MID_RHS_MATCH_FROM(0.00)[]; ARC_NA(0.00)[]; R_DKIM_ALLOW(-0.20)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; FROM_HAS_DN(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TAGGED_RCPT(0.00)[]; MIME_GOOD(-0.10)[text/plain]; NEURAL_HAM_LONG(-1.00)[-1.000]; DKIM_SIGNED(0.00)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; RCPT_COUNT_TWELVE(0.00)[19]; FUZZY_BLOCKED(0.00)[rspamd.com]; FREEMAIL_CC(0.00)[intel.com,arm.com,linux-foundation.org,infradead.org,redhat.com,google.com,linux.intel.com,cmpxchg.org,linux.alibaba.com,huaweicloud.com,techsingularity.net,gmail.com,kernel.org,samsung.com]; RCVD_TLS_ALL(0.00)[]; SUSPICIOUS_RECIPS(1.50)[] X-Spam-Score: -3.00 X-Rspamd-Queue-Id: 6C2F71F823 X-Spam-Flag: NO On 2/2/24 17:15, Zi Yan wrote: > 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 58a4e3fb72ec..fa9993c8a389 100644 > --- a/mm/compaction.c > +++ b/mm/compaction.c > @@ -1832,9 +1832,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++) { You could probably just start with a loop that finds the start_order (and do the isolate_freepages() attempt if there's none) and then handle the rest outside of the loop. No need to separately handle the case where you have the exact order available? > + 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) { With exact order available this while loop will just be skipped and that's all the difference to it? > + 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; > } > @@ -1842,6 +1876,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);