From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 39081606A31A for ; Wed, 2 Dec 2026 02:20:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=QRsoba3v Received: by kanga.kvack.org (Postfix) id 08C8D6B05EC; Tue, 1 Dec 2026 21:20:05 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 03E2E6B05F2; Tue, 1 Dec 2026 21:20:04 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E960A6B05F4; Tue, 1 Dec 2026 21:20:04 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id BDAB36B05EC for ; Tue, 1 Dec 2026 21:20:04 -0500 (EST) Received: from smtpin20.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 3CB2AA726A for ; Wed, 2 Dec 2026 02:20:04 +0000 (UTC) X-FDA: 85497437928.20.C72559D Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by imf06.hostedemail.com (Postfix) with ESMTP id 8884A180006 for ; Wed, 2 Dec 2026 02:20:02 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=QRsoba3v; spf=pass (imf06.hostedemail.com: domain of harry@kernel.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=harry@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796178002; b=IjKVNh1Kw8X2jm1N7gyZDYe6dp0MSzpVFXrPPLQM8Fty4ayxGqtRhxjlNX1+/kYoy4O0Mh Bgg3gGkg+CRoNXImcTzb1cfd0LEDI+fU+24y72hwXCxittEY8+TU9zbvex1o3VweExdLXm VnD+encWdiqh3+F1bDJx7qYgV6ss0ks= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796178002; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=wwt9TYMvre0iTiGTi1qxkHS7JnLkBzBG5YdwoLHipnk=; b=duzhQMk3l0A2fZNpoJ7IhkkoeVSKYyUfeN6llGBs2rD9FzilRtnIXZVGuUCrWIFRUcDxXk rksNsxpjnr79FUAS4bZgkm0KjKpGzgkxVI1jDt3dHEwD+DlACeSa9r/islPRfP6hwdzTZM RxzRxoTp3hoyFvqcbg/oQbHAXoWMhGc= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=QRsoba3v; spf=pass (imf06.hostedemail.com: domain of harry@kernel.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=harry@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 135824153F; Wed, 2 Dec 2026 02:20:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A13641F00893; Wed, 2 Dec 2026 02:20:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796178001; bh=wwt9TYMvre0iTiGTi1qxkHS7JnLkBzBG5YdwoLHipnk=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=QRsoba3vqTKokt6SjuRUdjI0TeNP+Wyn2wapJsgB2sZv3z740KmzsfKdB8Vk4JzBh 578MmHOQxMlZNlA9F0WQxwwbtv+k89VXrJoiPFuhA713fY/Lq94Cnoc9Pi0jiM1JSn +CU03z6IRooYSbsyrnnNo0M4BBDIsitqHCDUvg6FD/iq4FmRT2qejQEkFi75/TQ3bg ZT2/NerlY6R1J6GyVZfjVcbz3UBTvm9ZiukXIhgFPK47VU4IYjHi1kk5ZBdZXaMUJ4 DJngTyW0eGgcWSGbgbQuI+fgWK0jI0wbGhj4Ae7TR2EDlHf5cwnD1OSs3axMKYCEKM w7n+FWJ0RkaeA== Date: Wed, 2 Dec 2026 02:19:58 +0000 From: Harry Yoo To: "David Hildenbrand (Arm)" Cc: Jialin Wang , Andrew Morton , Vlastimil Babka , Johannes Weiner , Suren Baghdasaryan , Michal Hocko , Brendan Jackman , Zi Yan , Khalid Aziz , linux-mm@kvack.org, linux-kernel@vger.kernel.org, kas@kernel.org Subject: Re: [PATCH] mm: compaction: skip DMA-pinned folios during isolation Message-ID: References: <20261201154606.548937-1-wjl.linux@gmail.com> <5cda167e-4e2b-4267-b6df-a85242684de7@kernel.org> X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5cda167e-4e2b-4267-b6df-a85242684de7@kernel.org> X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 8884A180006 X-Stat-Signature: cisdg5apua58rx1n38w31nm1hzwbpdxs X-Rspam-User: X-Spam-Status: No, score=-5.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-HE-Tag: 1796178002-825147 X-HE-Meta: U2FsdGVkX1+hjM581R+LiJmX4IhP7gsIEgb76BhdyMrVVZzJWCayjZRCNj9j0De8jydolDY8yUotdM1q9QIQ7rkrVN9y7a+n+LkQ2PBzbil3dFqzjWPATNZvheSj1JxeLIOyc61VezYDqp/DRPUOomYKQzLAPfIuMJ6h5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UH4VRZzTryNSih5DL+g7lpMaj4asI5hBpWZ8ydF33sYljwXA1yCe/V8vQ8q2uqw6Ve1ocZwLnNbh3Rep06nssmoYBx+I493lsix8t+DypEFV5Fheb8pJRe4/oE+ScFqiSQvDzkO6a1TUz33j3d+yHMF8ZPFljXbfvG7UxBBmWMJTyWqprLN2uwn4eTrw8YzBL8y6nUmQ3a1HW5NmhXYsAV0mKKzhPYhi5nrOz8p0nEJFwOYAOsBtUBVzuLCliUihJunkOMDort32iPr32x8sspKlOrJ3jzu4jcJhof5LFtucUdAOVU9xug== Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 On Tue, Dec 01, 2026 at 06:48:01PM +0100, David Hildenbrand (Arm) wrote: > On 12/1/26 16:46, Jialin Wang wrote: > > Migration fails while a folio is pinned, so isolating it during compaction > > wastes CPU. Currently, isolate_migratepages_block() only checks for extra > > references when folio_mapping() is NULL (anonymous folios not in the > > swapcache). Folios with a mapping are not checked, including: > > > > - shmem folios allocated by cudaHostAlloc() via > > mmap(MAP_SHARED | MAP_ANONYMOUS) and pinned by the NVIDIA driver > > with FOLL_PIN | FOLL_LONGTERM; > > - shmem/memfd folios pinned by VFIO with FOLL_PIN | FOLL_LONGTERM [1]; > > - other folios that can be long-term DMA-pinned, such as swapcache > > folios, ramfs folios, and file-backed folios pinned read-only > > (without FOLL_WRITE). > > > > During direct compaction and kcompactd runs, compaction repeatedly > > isolates these pinned folios, unmaps them via rmap, flushes TLBs, fails > > migration, and restores the mappings. On GPU hosts with lots of pinned > > memory and heavy high-order allocations, this makes direct compaction > > very slow and keeps kcompactd at 100% CPU for long periods. > > > > Skip these folios early in isolate_migratepages_block(). To avoid > > hurting other workloads: > > > > - Do not change cc->alloc_contig (such as CMA and virtio-mem). > > - Only target FOLL_PIN, not every extra reference (such as FOLL_GET or > > short-lived pagecache references). Checking for any extra refcount > > could skip normal pagecache folios during read(), or folios with extra > > references that can still migrate (such as AIO ring folios). > > - Add a helper folio_likely_dma_pinned() instead of calling > > folio_maybe_dma_pinned() directly. For folios without _pincount, it > > uses folio_expected_ref_count() so a folio mapped many times (around > > GUP_PIN_COUNTING_BIAS, i.e., 1024) is not always treated as pinned. > > - Check folio_is_longterm_pinnable() so we do not skip folios in areas > > where long-term pinning is not allowed (such as ZONE_MOVABLE and > > MIGRATE_CMA). Any pin there must be short-term. > > > > Also move the !folio_test_lru() check right after > > folio_get_nontail_page(). It makes sure folio_mapping(), > > folio_likely_dma_pinned() (which may call folio_expected_ref_count()), > > and the anonymous refcount check only run on LRU folios. If a page is > > freed and reused as a non-LRU or typed page, we will not inspect its > > non-LRU fields or risk hitting folio_expected_ref_count()'s > > WARN_ON_ONCE(). > > > > Benchmark results (8GB VM, 4 vCPUs, 5120MB of 4KB shmem pages pinned with > > FOLL_PIN | FOLL_LONGTERM, 50 x 2MB GFP_TRANSHUGE allocations per trial, > > with fragments memory, mean over 3 trials) [2]: > > But what about short-term pins that are long gone until you actually try migrating? Forcing all long-term pins to migrate pages to an unmovable pageblock would probably help here? Movable allocations won't try to isolate nonmovable pageblocks until we're really desperate. Separately from this issue, long-term pins shouldn't really cause trouble for compaction even outside ZONE_MOVABLE :) (The idea is originally from an independent off-list discussion with Kiryl a while ago) -- Cheers, Harry / Hyeonggon