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 DF39ACE79AD for ; Wed, 20 Sep 2023 08:15:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6A81E6B012D; Wed, 20 Sep 2023 04:15:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 631076B012E; Wed, 20 Sep 2023 04:15:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4D2D96B012F; Wed, 20 Sep 2023 04:15:06 -0400 (EDT) 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 394B16B012D for ; Wed, 20 Sep 2023 04:15:06 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 03F2E1605C4 for ; Wed, 20 Sep 2023 08:15:05 +0000 (UTC) X-FDA: 81256265412.22.C20A21B Received: from out30-133.freemail.mail.aliyun.com (out30-133.freemail.mail.aliyun.com [115.124.30.133]) by imf08.hostedemail.com (Postfix) with ESMTP id 136BD160011 for ; Wed, 20 Sep 2023 08:15:02 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=none; spf=pass (imf08.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.133 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695197704; 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; bh=+JWfPGsHasV9GbbuUYVNrmjTDYjemVcCfYxiLGmmdFA=; b=uu75kIOD+AXhPOtShL2S6wNTYhnkJ48YvAvmBcuAuxhpqmvM8/6c/Sl1G09/r9BSDDGRuS HgY8aVGx6iPV+/ZDmllDckhP/avMWmKczXZmT46hCuIEepOsVr++11vaJgwTl8M0sUSXO9 7rjMXAwhN/eWR5rO4n+zvFimON51+pY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695197704; a=rsa-sha256; cv=none; b=0r+kIFxbxOoHOp9GEf3AFkQ+P49cA1dX3l+i2Nkhf/8Ghk5DI98SGcXmmhJ1o/vJEE0OTP bLB3/vXVDOnGk83oyAPVTsGsE7E6J9sHKKkRYVUXEr81okyG0tR5nTOVJ+AlQEzxRxfyYP k7oohlctRFvcAFDw1tpp8f2pBVyovgM= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=none; spf=pass (imf08.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.133 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=alibaba.com X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R331e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046051;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=17;SR=0;TI=SMTPD_---0VsUU2iq_1695197698; Received: from 30.97.48.72(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0VsUU2iq_1695197698) by smtp.aliyun-inc.com; Wed, 20 Sep 2023 16:14:59 +0800 Message-ID: <0d92b375-c583-a21e-4e5b-355932a8b30e@linux.alibaba.com> Date: Wed, 20 Sep 2023 16:15:03 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.15.0 Subject: Re: [RFC PATCH 2/4] mm/compaction: optimize >0 order folio compaction with free page split. To: Zi Yan Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Ryan Roberts , Andrew Morton , "Matthew Wilcox (Oracle)" , David Hildenbrand , "Yin, Fengwei" , Yu Zhao , Vlastimil Babka , Johannes Weiner , Kemeng Shi , Mel Gorman , Rohan Puri , Mcgrof Chamberlain , Adam Manzanares , John Hubbard References: <20230912162815.440749-1-zi.yan@sent.com> <20230912162815.440749-3-zi.yan@sent.com> <28f76c7c-4b84-5e08-2f27-07592d8078a2@linux.alibaba.com> <40CD5F50-FC29-46FB-A3E2-76C6D14D390E@nvidia.com> From: Baolin Wang In-Reply-To: <40CD5F50-FC29-46FB-A3E2-76C6D14D390E@nvidia.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 136BD160011 X-Rspam-User: X-Stat-Signature: 73yu3wg1et9e8kx4rfg4ewkx79ueky51 X-Rspamd-Server: rspam03 X-HE-Tag: 1695197702-805496 X-HE-Meta: U2FsdGVkX19jyvnMEjj6I2lM8/OqcRhl/a1dqQg3XHpWuanpsj8EUPZVHCdkymZjqBpQinEfpbi+kFhLb50rOjbiUdqx0Tl8ZuLDlwg7LrYcH5kMWSTmB0SzPP/91Jh0uhSEeyq3SbSPUNXzGFLikJO8XYZ7yWD1Mt6vdJwe5PZS27KLYKtsCOID4pbtJ/KdB2GnpskcVUfuX6AMEsP0AV8ddQ35DdoPz30LkvvtpWgWda7iKjcQT/OQHgj7YTzrngeJx5HAWdWXyq/9lzI280FAck4y+O5lvGFmkhm85iVilvAXujYsLCBjmk46OQmQGpmAt9XnBeyznUWe4XHLng65V5XoITcEjcXBbw5U9cTebCkR3LZ7RjoNEYfyelzEe1OSDjhpkePViLioWX6jDoOf8zHWXt0r1C4dZH1DQ26ZU9CRczNfTUqzsW6Gt4TqH5YtyvkbjK2k2p60EPP0K/qXY4kWK/4NnLemJtGDBCHlXoYm18AWw6lprY7V4mO4I0sM1xCDzWljskjMjsBy3CMnmbMb4QKFnmsBJV9lArd9q7SiR0j3DwVJ6han2VffrUURIs09iLxWdSA10yRki351aXdIe50a3qwwroniBcCCO38Fhuwz+abZHczaEzKCCQm9bS+0W3FXufdFWrrlaXAn9NGXNx4vyAkiHeMcv7ovZNLw5yjO1rjgbhjdfh+NXEgCTLZdSLDRiqNhA/9SJJ1KCuFnoc0nS9A0y/4zBsm3gCMmhAWgEWxkjuGZjepGEwgdq1iGOQyrM9jVDa6zFM2oefDqVKexrLd0jHKPjzqpOUX6CCh29KhTa5TFK3lr00LKChzxZJeQ50/K1M49AIYpeUh/VmATCrdDYM7/NN1HqQ21FYP46QzUe7wIQwRvnjWNlrAdqTPEgcCXIQL8Uie+5EeF+XGbGZ5bZ6325TghFH+YR6F2NkkjTUoQqspt0zhMIy8SaYq8bTK42pj 1PWfplef 0OeMXcCAx6RgHd9+qK4gwGF83PUlVYfDvqb1zuppp30ButVrps/OuKCCxvFckzmA7eE3S+r8IwvA0n9burF11yJkMozrWSoizSB7IlUbAbObr5bbjw5bvYRqs2qUh1r6O5gSov4ERikBieC0f7kO0WuiIXfe/U8OWXde7AM0FnDGxok4= 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: On 9/19/2023 1:20 AM, Zi Yan wrote: > On 18 Sep 2023, at 3:34, Baolin Wang wrote: > >> On 9/13/2023 12:28 AM, 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. 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); >> >> IIUC, these split pages should also call functions to initialize? e.g. prep_compound_page()? > > Not at this place. It is done right below and above "done" label. When free pages > are on cc->freepages, we want to keep them without being post_alloc_hook() or > prep_compound_page() processed for a possible future split. A free page is > only initialized when it is returned by compaction_alloc(). Ah, I see. Thanks for explanation.