From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796475602; b=Z7uEosvWZpYSsP4x+SgWnaenN60iT8k37dlKuAdC6RwVf+ui/pVY+7PRfvtZ/hmSHiK+ l6dBr2DgrdAdO64EA2IiYCSqgqIBAOXDZtu/mNGyCyLu1jx+hxM5frFAmNjZTAgvrjKQL OPFVaAa8QAu31OrRocEoqWLnUQEfwHLZ6XIa4NA3Pok8/pzONo8SZylCW7oepKhv/nQkm yEVBmCx2be/HzPvnorxe0mUzR12vqxiaZ42nGmTXdxQgnHNbhtG4WlZPzr/2DTMgOoScz bJbzHJLk5wf6nJy4x8PGu/CG1weqmcCzk80pfZACV0ZhnhXJCWIFmiViQgIc6rsk04g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796475602; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=6pYwKRKP24nbXeZn26sCsKYlk4nA0d0Ri/ySYG0KgUc=; b=UO0idyLxKDB3BOIEJZi+GWztZtXq9sP7qUebDc5LHoDk0Iy4Kc8eUFmrCq38gxp6SMqC dqFHTY2ZAJw2g0+Zw9GLZxFfOGTjgXjtHTguBeLfq0/mtsVxWxV9pW2yx13IfkHNTG8ct ie1a+ETuPTXcENSUHGJqcpOQzRv5hvGXBlxLDdTOs7IFEkHpw7JQZPV1Gj/n0tYx6Jpz6 nofKkXvtSiyFotkWitcrUUnL2RrO6PmGfKair/ktlDNrKRQHQnriMuMnrGs5j6YbW9JtK bDCTnw2LZEg0xT2EhaOp/19kaA3QygTUxAyiVvHsSDTgMoC3qDMTuTcKq6GVkWQmcGQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Un12x6TK; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8A5C9606A322; Sat, 5 Dec 2026 13:00:02 +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=Un12x6TK Received: by smtp.kernel.org (Postfix) with ESMTPSA id 637BB1F00A07; Sat, 5 Dec 2026 12:59:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796475602; bh=6pYwKRKP24nbXeZn26sCsKYlk4nA0d0Ri/ySYG0KgUc=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=Un12x6TKkRgqc4YHsOfPvxxSLG9QV8vZVd5VhvEnANJunqdj8sMCbCO0nL5EDZlzi 6xRYtZZxOgq8Bd+1ILdYLbm6/1ZR04iWbNz4bT/FBYbAu3HiLETFmZNHdmGQ+VZW7e Tt2pLCCDpau6oIQYPpi9Tre6tczXLxbEWfHArHRPwu0BbbYlUs8DVqU75TvO/f9NEm vvjYAjUhNXfhRGa+miD/7JKn2ppoOgG597lJSWf4Xap9QeXzfjAonhYT2qJZDouo4e /ud8CsQNnUr1cScuQYZjpHTGBDtGJOneZ9pzlAvU/mYY+ZV3NXiwcaQpOmGX+aQmSk CLYTA72o5Lj0g== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v2 27/31] mm/ksm: don't convert a shared anon folio into a KSM folio Reply-To: sashiko-reviews@lists.linux.dev To: =?utf-8?b?RGF2aWQgSGlsZGVuYnJhbmQgKEFybSk=?= , "Hugh Dickins" , "Baolin Wang" , "Andrew Morton" , "Mike Rapoport" , "Peter Xu" , "Michal Hocko" , "Kiryl Shutsemau" , "Manfred Spraul" , "Davidlohr Bueso" , "Cyrill Gorcunov" , "Zi Yan" , "Liam R. Howlett" , "Nico Pache" , "Ryan Roberts" , "Dev Jain" , "Barry Song" , "Lance Yang" , "Usama Arif" , "Lorenzo Stoakes" , "Rik van Riel" , "Vlastimil Babka" , "Harry Yoo" , "Jann Horn" , "Yang Shi" , =?utf-8?b?WmFjaCBPJ0tlZWZl?= , "Song Liu" , "David Stevens" , "Kefeng Wang" , "Alex Williamson" , "Suren Baghdasaryan" , "Dave Jiang" , "Matthew Wilcox" , "Miaohe Lin" , "David Rientjes" , "Shakeel Butt" , "Jan Kara" , "Mel Gorman" , "Jason Gunthorpe" , "John Hubbard" , "Gerd Hoffmann" , "Vivek Kasireddy" , "Dave Airlie" , "Matthew Brost" , "Joshua Hahn" , "Byungchul Park" , "Gregory Price" , "Ying Huang" , "Alistair Popple" , "Hagen Paul Pfeifer" , "James Bottomley" , "Felix Kuehling" , "Alex Sierra" , "Balbir Singh" , "Kairui Song" , "Qi Zheng" , "Axel Rasmussen" , "Yuanchu Xie" , "Wei Xu" , "Baoquan He" , "Oscar Salvador" , "Muchun Song" , "Dan Williams" , "Rakie Kim" , "Hao Li" , "Christoph Lameter" , "Roman Gushchin" , "Sebastian Andrzej Siewior" , "Clark Williams" , "Steven Rostedt" , "Alexei Starovoitov" , "Xu Xin" , "Chengming Zhou" , "Shivank Garg" Cc: linux-mm@kvack.org, linux-cxl@vger.kernel.org, linux-rt-devel@lists.linux.dev, "SJ Park" , "Chris Mason" , linux-kernel@vger.kernel.org In-Reply-To: <20261204-fixes_core_3-v2-27-9aad65727632@kernel.org> References: <20261204-fixes_core_3-v2-0-9aad65727632@kernel.org> <20261204-fixes_core_3-v2-27-9aad65727632@kernel.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 05 Dec 2026 12:59:58 +0000 X-Mailing-List: linux-cxl@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] mm/ksm: cmp_and_merge_page() splits shared large folios after -EBUSY -- commit 999d85f121ae9110b9d07446c1254f5c0a633c39 Author: David Hildenbrand (Arm) mm/ksm: don't convert a shared anon folio into a KSM folio This commit refuses to convert an anonymous folio into a KSM folio when it may be shared with another mm or still has unfreeable swap entries, returni= ng -EBUSY before locking or splitting. When merging two non-KSM pages in cmp_and_merge_page(), it retries in the reverse direction if the first attempt returns ERR_PTR(-EBUSY). > diff --git a/mm/ksm.c b/mm/ksm.c > index 509bd78156583..fe7b3b60540db 100644 > --- a/mm/ksm.c > +++ b/mm/ksm.c [ ... ] > @@ -2359,8 +2384,19 @@ static void cmp_and_merge_page(struct page *page, = struct ksm_rmap_item *rmap_ite > struct folio *tree_folio; > bool split; > =20 > + /* > + * Try merging in both directions: if one folio is shared but > + * the other isn't, one direction will work. Merging will fail > + * if both folios are shared. > + */ > kfolio =3D try_to_merge_two_pages(rmap_item, page, > tree_rmap_item, tree_page); > + if (kfolio =3D=3D ERR_PTR(-EBUSY)) > + kfolio =3D try_to_merge_two_pages(tree_rmap_item, tree_page, > + rmap_item, page); > + if (IS_ERR(kfolio)) > + kfolio =3D NULL; > + > /* We might have split the folio. */ > folio =3D page_folio(page); > tree_folio =3D page_folio(tree_page); > @@ -2375,7 +2411,6 @@ static void cmp_and_merge_page(struct page *page, s= truct ksm_rmap_item *rmap_ite > * split_huge_page should succeed. > */ > split =3D folio =3D=3D tree_folio; > - folio_put(tree_folio); > if (kfolio) { > /* > * The pages were successfully merged: insert new > @@ -2401,7 +2436,9 @@ static void cmp_and_merge_page(struct page *page, s= truct ksm_rmap_item *rmap_ite > break_cow(tree_rmap_item); > break_cow(rmap_item); > } > - } else if (split) { > + } > + folio_put(tree_folio); > + if (!kfolio && split) { > /* > * We are here if we tried to merge two pages and > * failed because they both belonged to the same [Severity: Medium] Does flattening ERR_PTR(-EBUSY) to NULL cause cmp_and_merge_page() to split= a shared large folio anyway? When page and tree_page are two identical subpages of the same fork-shared large folio, try_to_merge_one_page() returns -EBUSY early to avoid locking = or splitting it. Overwriting ERR_PTR(-EBUSY) with NULL leaves split set to tr= ue (folio =3D=3D tree_folio), so if (!kfolio && split) still calls split_huge_= page(). That breaks up the shared THP across all processes mapping it for no deduplication gain, since the resulting order-0 folios remain shared and still return -EBUSY on later scans. Retrying try_to_merge_two_pages() in the reverse direction is also redundant when page and tree_page belong to the same folio. Setting split =3D !IS_ERR(kfolio) && folio =3D=3D tree_folio before clearin= g the error pointer, and skipping the reverse retry when page_folio(page) =3D=3D page_folio(tree_page), would avoid both. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204-fixes_core= _3-v2-0-9aad65727632@kernel.org?part=3D27