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 EE211E77183 for ; Wed, 18 Dec 2024 07:58:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 866186B0083; Wed, 18 Dec 2024 02:58:04 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7EECD6B0088; Wed, 18 Dec 2024 02:58:04 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 690226B0089; Wed, 18 Dec 2024 02:58:04 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 45A246B0083 for ; Wed, 18 Dec 2024 02:58:04 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id E75DA1C7275 for ; Wed, 18 Dec 2024 07:58:03 +0000 (UTC) X-FDA: 82907324976.03.905D3C2 Received: from out30-113.freemail.mail.aliyun.com (out30-113.freemail.mail.aliyun.com [115.124.30.113]) by imf18.hostedemail.com (Postfix) with ESMTP id E59C81C0004 for ; Wed, 18 Dec 2024 07:57:46 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b="rjj/+jC3"; spf=pass (imf18.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.113 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1734508658; 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=73PG00jNypyVuZ+U9GLfUx2Y2h80nJwkdo7O7xfYAZE=; b=8X31nyCzcJW/euvIKdZIsts82eoE5vgE1FtqdxGC11i0V7CaIrTnyMF9eshggPFs7Q5ZmM con898p3LJjw4S7I/ZuYFR8R4aO0PLU2/ankJfRxY/I0IEyXE/en2LGIF8XRuQ8Bz8vUxF QKUNdF8t/oELawT6fGTANfji7kcOV5A= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b="rjj/+jC3"; spf=pass (imf18.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.113 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734508658; a=rsa-sha256; cv=none; b=J/PQdronPrfifB3Gab4UTc4cDoEkqwWVKjlKVPG8unW+j94EB9cJMmdqCtWdKPOjMGKLoU O1oh+eNwI/h0Zl6c69PqiV1h1+fzHoxc0ZGB3+SOQQHLIeaK7smuuuUhKdrLy99NsUq0uT uErxJ1Dm6wt7MR49xkEJrXCt2x7Sim4= DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1734508677; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=73PG00jNypyVuZ+U9GLfUx2Y2h80nJwkdo7O7xfYAZE=; b=rjj/+jC3hdhKefUrY/LcXaRNOf8uNZg+IduxJAkgLk/vBSFg/tB37VnB815VnCsVBjQMuHrk575jr3nMzCr6fPq0t2f9D2e2KKufIIm9gbQFP6Tew3RQf7v2MVk/rUkoXIQAx4at7sQVLSzIcrf+M7ACq8MDgd+QJ0Inx95t8z0= Received: from 30.74.144.132(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0WLloubY_1734508675 cluster:ay36) by smtp.aliyun-inc.com; Wed, 18 Dec 2024 15:57:56 +0800 Message-ID: Date: Wed, 18 Dec 2024 15:57:54 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH V7] mm, compaction: don't use ALLOC_CMA for unmovable allocations To: Johannes Weiner , yangge1116@126.com Cc: akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, 21cnbao@gmail.com, david@redhat.com, vbabka@suse.cz, liuzixing@hygon.cn References: <1734436004-1212-1-git-send-email-yangge1116@126.com> <20241217155551.GA37530@cmpxchg.org> From: Baolin Wang In-Reply-To: <20241217155551.GA37530@cmpxchg.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: E59C81C0004 X-Rspamd-Server: rspam12 X-Stat-Signature: kxuees6w6mrbfrjxp6mm84rwbeu5ow4g X-Rspam-User: X-HE-Tag: 1734508666-245530 X-HE-Meta: U2FsdGVkX1+qRhcIUK+COq2A2hgQFhcOWXaYz0NFprJRpEGcXR2bjDQkAnPm6pgQ1Lfm6nLFmiBv5P9TrYiiKmUWw6q/ZYrj0oCUg5vG/Qw0183LcHXKfWf3KxklNQFTZCT4eCIzo5IiXZ1GsW2CASDYbR0/HG9soPzO1xs4MoBc0+ImByEBFz4IPR9W55R0/RXdxDrjnFkQB/cOPqFHSkpxC8IUR/g0bxd93hJ7d2hTpHR4EwYZAct7FzMZ1plr96RbLlpFn4f70xjTy/e5RZ20jRrqF6MCDkAm06LjWlSO/y6nHAl8fs388QD2u1T4z+zVoi8Y9quXC1SpEa+tx4mfGBY/jVxBuf8tIqgSReHZ/sz0ovd2bpb2wUa4IiyVWKsfezVjEyQ4rgxcC3vRmhaqb5PGvIFrmUpJnx9JUJv6mxYvBaRvbxoY24ALrDO8qjPWY6LvecuQMzik7dy7EwFPpLC+wi+eblRuTsC24J7pXQZrr8VLWXud3YCZzuw6QStlcgcNRowpVYOGDq7iUGqbC2muUrXPaloLV2BuHTpis4S+S1RPeOtmBg/kzqRHe7y0iN0wyFPb7T4vnq+CYCOlccfz514q8QX1o+28OiSw3Zq7bnpNPwKTjGoowLaj2yW396trBN5zrtU1QrC+dwDZg1nzU/tQtHktt1wocc+n838qrxPBu8YQmpCBanTd2+4ohSAkmbq0DTRNZfGzxksPrvamtT4B4bNURiO8U+tLijIXDt1fnHSDClWKa4Ns11vvOCcF5gEzFghWMO322jxfOdTWmSu1jEQiZ2zGFj+jDXVJyUqfvGsjR4jTaOF0Lki0pW4HsZCUvgC2HKGXZneoR/IKeTQC9ghErgRUsPvqUVSvK00EQkoPogcITKP5f/nrxyOIhtp7jNhYhZrMHU4iq1jbNIl17DwczzlWvkt+GLl/02q+7aUgQdheyNk+rMUmkGFjsVx4rxKORpB q6jIb8af fEL1HM8tcnBMPURfY5R4x0tJd3G9ZceS+dUtCsobY72DA7EC87LGUQak4Yr3im3o6/xliPeP3HxRjH08MdUShHINnSqXsB8V6THr8EtXEu/lwq4AFUEmSavLGrdfbecs1jADxmWg//bnlF1waxtIZLtDNbjF1f6i7nFmFdB/GV0XXlBIzbwo7Wy8aSbw7CBU1x3xbM1y8/tAFg2MzPIwMnaNNJh97b/XwasvcC9qg08P8m0WiEXd0QeFz8lGPPnwQWH0BSmv4Zz0+rsskowsj14M1HRuJgtx0TGHDFVIiSI7YmYWiGEMoUAVLzbA7/Q/9R+x/7XY9ii3NTjgkqn+wlSHEV195sGUZWwdltK5JY20Bq+s= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000002, 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 2024/12/17 23:55, Johannes Weiner wrote: > Hello Yangge, > > On Tue, Dec 17, 2024 at 07:46:44PM +0800, yangge1116@126.com wrote: >> From: yangge >> >> Since commit 984fdba6a32e ("mm, compaction: use proper alloc_flags >> in __compaction_suitable()") allow compaction to proceed when free >> pages required for compaction reside in the CMA pageblocks, it's >> possible that __compaction_suitable() always returns true, and in >> some cases, it's not acceptable. >> >> There are 4 NUMA nodes on my machine, and each NUMA node has 32GB >> of memory. I have configured 16GB of CMA memory on each NUMA node, >> and starting a 32GB virtual machine with device passthrough is >> extremely slow, taking almost an hour. >> >> During the start-up of the virtual machine, it will call >> pin_user_pages_remote(..., FOLL_LONGTERM, ...) to allocate memory. >> Long term GUP cannot allocate memory from CMA area, so a maximum >> of 16 GB of no-CMA memory on a NUMA node can be used as virtual >> machine memory. Since there is 16G of free CMA memory on the NUMA >> node, watermark for order-0 always be met for compaction, so >> __compaction_suitable() always returns true, even if the node is >> unable to allocate non-CMA memory for the virtual machine. >> >> For costly allocations, because __compaction_suitable() always >> returns true, __alloc_pages_slowpath() can't exit at the appropriate >> place, resulting in excessively long virtual machine startup times. >> Call trace: >> __alloc_pages_slowpath >> if (compact_result == COMPACT_SKIPPED || >> compact_result == COMPACT_DEFERRED) >> goto nopage; // should exit __alloc_pages_slowpath() from here >> >> Other unmovable alloctions, like dma_buf, which can be large in a >> Linux system, are also unable to allocate memory from CMA, and these >> allocations suffer from the same problems described above. In order >> to quickly fall back to remote node, we should remove ALLOC_CMA both >> in __compaction_suitable() and __isolate_free_page() for unmovable >> alloctions. After this fix, starting a 32GB virtual machine with >> device passthrough takes only a few seconds. > > The symptom is obviously bad, but I don't understand this fix. > > The reason we do ALLOC_CMA is that, even for unmovable allocations, > you can create space in non-CMA space by moving migratable pages over > to CMA space. This is not a property we want to lose. But I also don't Good point. I missed that and I need to withdraw my reviewed tag. Thanks.