From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ed1-f43.google.com (mail-ed1-f43.google.com [209.85.208.43]) (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 B5F0640D57A for ; Sat, 20 Jun 2026 07:39:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.43 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781941161; cv=none; b=sm5i84QkE+SoL7NsKhvJhsbl0yUpuKolAKVTX2ciVtfCh/Fp6TvbmIwnPqgPW15WYGVA5DhgspBiN90aF4WBc3+gQaRs1J24dbZfSEBjJ7gdlieY75vvFUF5nhTs0wrfl71ed6NtuRFaqRDqwZ/xhTf+VdEDK3mvBd0YWodQcFE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781941161; c=relaxed/simple; bh=nKeQ7rrUKZ9THl2tDpoaBhzXk+kd8XwcuuWgSDqbwnk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=mmM2fLVrUojS3294DKPBiR3QA9WrUCL8cP0sBOxS7T43tLqnqnLxPqYNeQhl+hr/bf5PuUZpn5MJhf4UJOWnnyZJWZK1J+yQ/i1U42d7ymxyUSGoG7uYMaVrwe5y6lhUC1qEM0/S84YlaqOoCy/rcsex08HYijEP2vqO2MoWcs4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=LrqFVLcL; arc=none smtp.client-ip=209.85.208.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LrqFVLcL" Received: by mail-ed1-f43.google.com with SMTP id 4fb4d7f45d1cf-693c51a8a19so4134048a12.3 for ; Sat, 20 Jun 2026 00:39:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781941158; x=1782545958; darn=vger.kernel.org; h=user-agent:in-reply-to:content-disposition:mime-version:references :reply-to:message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=j/Dx8yZbdV0tUU5+RWiOyp7h/hJ2ofnlgcFrB51X8kc=; b=LrqFVLcLHUWXFF+rzzCi+axFX9C0Dx0cz17VuUZmBctSOHEqsImm+x+Hnsc21ajAFn qH/k20wG4V4ltmjMyela5fqnK8A7jF579Y8MoTNpTkMm7JzlN6R3Yg4wHGx3cPfxjpZ4 LjoAbJwCA62Wiv+J7qQItMK+g8Qxps8wVdITW9J8zEh3fycYQQ1PwNOX6XH6LMK8y13c W5Y3Z2f9r8E3JfVFpfcY0TvqcT1vqJK1tFV4qoWwFb/AVO/2JKse1khYj58g/unwbGJg OUa9dk6JaLT6P/SzmM8JTU6mpVhYbNkd5KVsSUYZIM+m3GFG4M+gobAuHshRLnOtNH9Q 9KUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781941158; x=1782545958; h=user-agent:in-reply-to:content-disposition:mime-version:references :reply-to:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=j/Dx8yZbdV0tUU5+RWiOyp7h/hJ2ofnlgcFrB51X8kc=; b=j5A8VG2xApSPLEvG4Uf8i4GOi2fQz7wxMpcutOMGANPqxbkfjAaphbHO1lLASrQRVN tZRLDcrvEUvPNlVQRW9O9uzMKtvf5iS79Ct8CeNfV+DaguqZfXZSzM5Z9YdVbz5yrheF a5AUjX6Mbw8dU5RDbyyOkPIFoye2kNHLlpiyTpAd8qCZ2QVi26MGMKFkHIEfgEgPNGIe +BD14jRVpu7P4QL1rlV7F2IyrLZGOTUkIFYTe1jjHOBhVDv+TyH9zq5lxqMC3FF78JUp 40sz1wrwR4Ezr8m1cpNF+E/fyT5kqUXwIg+S2OSjUneov2Gl/wxzCyij5XVes5gC+Xlg qojA== X-Forwarded-Encrypted: i=1; AFNElJ/HIMh+GQfqfEmTlYrm2sARoxe3RivGxfsmRsYQRjMjCM4BW3bnh3QvuwZErnMxci2VIOFxL5aom0TXUrU=@vger.kernel.org X-Gm-Message-State: AOJu0Yws/9G+HQJqxmisDrEtGGJ1itr4iGx1VWBOBwrexqtGAbnqEYSJ bDSZ3NeuR6rifdWKsAGhexFF3kIllUqWb6hG6axR73b4IJka7R+Lqt8V X-Gm-Gg: AfdE7cmI+T2rhOgmoPyoaiJmVfQdNoXH3Ka49lbDl9KXgij8TaexoBSEvt6Rvwxbxmx O3IjnysIbc7mVR+wyYLOE4Y0wV2eYM/MlVcmzvLjwdS5iMLlVetbqvx57u6uj600lEp2idIuE8f iRtECoPa22arRS22MfPGcqX8gmrQEgRQgcIogWadGl7UNIKQVS8xu0HlU4CDN9/kMrl3WFogK53 rsbDeTmI0cjAVMNDO2rMnfS1tkgv3kZstnEDiCRNMie6Xn/T3NOrMYc3hNqxVTdCG/eeZlNEpDD fAT90sgF6PLJtbBolb8VycF2BiCIPIMaJUw/VaJhrXd+jWjv3xDRDF4eKe/VvgXQ4neynI12srr lalhmrdBVbSmiJ3YoPaLhOwUCPoj5UaptTcdU2dGjNq+KhzFLZIZWsdLthaWJXt5ltl7O5e3AEg JvM0wc0Peop9o= X-Received: by 2002:a05:6402:254d:b0:697:833e:9179 with SMTP id 4fb4d7f45d1cf-697833e999cmr53512a12.11.1781941158096; Sat, 20 Jun 2026 00:39:18 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-6977b856f92sm426279a12.11.2026.06.20.00.39.16 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 20 Jun 2026 00:39:16 -0700 (PDT) Date: Sat, 20 Jun 2026 07:39:16 +0000 From: Wei Yang To: Johannes Weiner Cc: Andrew Morton , David Hildenbrand , Lorenzo Stoakes , Shakeel Butt , Michal Hocko , Dave Chinner , Roman Gushchin , Muchun Song , Qi Zheng , Yosry Ahmed , Zi Yan , "Liam R . Howlett" , Usama Arif , Kiryl Shutsemau , Vlastimil Babka , Kairui Song , Mikhail Zaslonko , Vasily Gorbik , Baolin Wang , Barry Song , Dev Jain , Lance Yang , Nico Pache , Ryan Roberts , cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v5 9/9] mm: switch deferred split shrinker to list_lru Message-ID: <20260620073916.ico5v2kji4skpf5m@master> Reply-To: Wei Yang References: <20260527204757.2544958-1-hannes@cmpxchg.org> <20260527204757.2544958-10-hannes@cmpxchg.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260527204757.2544958-10-hannes@cmpxchg.org> User-Agent: NeoMutt/20170113 (1.7.2) On Wed, May 27, 2026 at 04:45:16PM -0400, Johannes Weiner wrote: [...] >@@ -3890,34 +3804,43 @@ static int __folio_freeze_and_split_unmapped(struct folio *folio, unsigned int n > struct folio *end_folio = folio_next(folio); > struct folio *new_folio, *next; > int old_order = folio_order(folio); >+ struct list_lru_one *lru; >+ bool dequeue_deferred; > int ret = 0; >- struct deferred_split *ds_queue; > > VM_WARN_ON_ONCE(!mapping && end); >- /* Prevent deferred_split_scan() touching ->_refcount */ >- ds_queue = folio_split_queue_lock(folio); >+ /* >+ * If this folio can be on the deferred split queue, lock out >+ * the shrinker before freezing the ref. If the shrinker sees >+ * a 0-ref folio, it assumes it beat folio_put() to the list >+ * lock and must clean up the LRU state - the same dequeue we >+ * will do below as part of the split. >+ */ >+ dequeue_deferred = folio_test_anon(folio) && old_order > 1; Looking at __folio_remove_rmap(), we check !folio_is_device_private() before deferred_split_folio(). __folio_freeze_and_split_unmapped() is used in folio_split_unmapped(). According to its comment, it could take device-private folio. This means for device-private folio, we still lock lru_list and try to remove it from deferred_split_lru. The good news is this doesn't harm the system, but does some extra work. Would it be better to add !folio_is_device_private() here? The purpose to lock here is to prevent shrinker seeing ref-0 folio. Since device-private folio is not on deferred_split_lru, shrink won't see it. >+ if (dequeue_deferred) { >+ struct mem_cgroup *memcg; >+ >+ rcu_read_lock(); >+ memcg = folio_memcg(folio); >+ lru = list_lru_lock(&deferred_split_lru, >+ folio_nid(folio), &memcg); >+ } > if (folio_ref_freeze(folio, folio_cache_ref_count(folio) + 1)) { > struct swap_cluster_info *ci = NULL; > struct lruvec *lruvec; > >- if (old_order > 1) { >- if (!list_empty(&folio->_deferred_list)) { >- ds_queue->split_queue_len--; >- /* >- * Reinitialize page_deferred_list after removing the >- * page from the split_queue, otherwise a subsequent >- * split will see list corruption when checking the >- * page_deferred_list. >- */ >- list_del_init(&folio->_deferred_list); >- } >+ if (dequeue_deferred) { >+ __list_lru_del(&deferred_split_lru, lru, >+ &folio->_deferred_list, folio_nid(folio)); > if (folio_test_partially_mapped(folio)) { > folio_clear_partially_mapped(folio); > mod_mthp_stat(old_order, > MTHP_STAT_NR_ANON_PARTIALLY_MAPPED, -1); > } >+ list_lru_unlock(lru); >+ rcu_read_unlock(); > } >- split_queue_unlock(ds_queue); >+ > if (mapping) { > int nr = folio_nr_pages(folio); > >@@ -4017,7 +3940,10 @@ static int __folio_freeze_and_split_unmapped(struct folio *folio, unsigned int n > if (ci) > swap_cluster_unlock(ci); > } else { >- split_queue_unlock(ds_queue); >+ if (dequeue_deferred) { >+ list_lru_unlock(lru); >+ rcu_read_unlock(); >+ } > return -EAGAIN; > } > -- Wei Yang Help you, Help me