From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9F5F93148A8 for ; Wed, 17 Jun 2026 18:05:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781719560; cv=none; b=qhDPHSvDhog/j1iaWual5u8IN5YP+haAetxGRPTtLB/y+llqnQKK6dZoUvtU/HnPfp+aGrDEXwd3qAVWvDGkoDL35j3vGPWKb9OEQjLgreTXq4hYdSUPZFHVh9AyK0LPeBc/6FlVlTEZOjh1ho8ucldX5QgAfH6cIEXEk5Iyj0I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781719560; c=relaxed/simple; bh=bK9y89cFVRRi/6RnTXA9XsTo7k+5NoUbK+8G7Jomz70=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=D91mX5/hHUz8Km/qOZP0lEq654jyilA+MrRgfmHKI48OKcDvQqM6ymsjoVMUcjgqD4svYS6urH6pLEI1oOFdTXtic2XY7+Pb26acTjZ1syI5/LsWX4icLWhJUwdfo/oM6Ops94iXop9rBpo6HETwBSxaYexSlQIbrvc1mBWITGY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org; spf=pass smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=oseQyoO5; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="oseQyoO5" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Transfer-Encoding: Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Sender:Reply-To:Content-ID:Content-Description; bh=8HmsYzoZQB23PlhcgNC/p2emSesBqDNqnHdSEmq4pXc=; b=oseQyoO5dOEA2aW5Hcuigc0nkG 4Ebjp8OW3jnS0aaihRNqURT6spTs13E+KA7T8clX1gs52d5h5ewuXwdNkrFI2D5uNO4wuO2/J3f/x jWn/8ZboZZNIqnx/HAIVFWA72bjbOPVlEDYc5Krs1prDX6MuuuZGMBVk1uI9SBl/HyXf/DkM41WSP hhici8YaoU4K8VozscOKjoZ0yXoGpGdvqkAtxAYYJTkhhEOw/DajQX/Mfy8itFVOvfdjn7JaCR02y HTm39PPoYosOU9AhhvsjJkmm7ZacRE8bQye2POS4m3Om7VP61xYtm2CLeM7GCvlazmOLzdnayXDEu sIhufVbQ==; Received: from willy by casper.infradead.org with local (Exim 4.99.1 #2 (Red Hat Linux)) id 1wZue6-0000000D4EQ-2jof; Wed, 17 Jun 2026 18:05:50 +0000 Date: Wed, 17 Jun 2026 19:05:50 +0100 From: Matthew Wilcox To: Rik van Riel Cc: Jinjiang Tu , Rik van Riel , ziy@nvidia.com, linux-kernel@vger.kernel.org, kernel-team@meta.com, Andrew Morton , David Hildenbrand , Lorenzo Stoakes , Hugh Dickins , Baolin Wang , "Liam R. Howlett" , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , linux-mm@kvack.org Subject: Re: [PATCH] mm: khugepaged: free xarray nodes left behind by failed collapse_file() Message-ID: References: <20260616145413.1491961-1-riel@surriel.com> <8a4caadc-f414-4874-97d4-2fbaebe2af39@huawei.com> 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=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Wed, Jun 17, 2026 at 11:40:28AM -0400, Rik van Riel wrote: > On Tue, Jun 16, 2026 at 10:18 PM Matthew Wilcox wrote: > > > > On Wed, Jun 17, 2026 at 10:00:59AM +0800, Jinjiang Tu wrote: > > > > I can reproduce it easily with following steps. [1] > > > 1) create file /tmp/test_madvise_collapse and ftruncate to 4MB size, and > > > then mmap the file > > > 2) memset for the first 2MB > > > 3) madvise(MADV_COLLAPSE) for the second 2MB > > > 4) unlink the file > > > > Yes, but is there a problem? That is, do we need to clear this up > > before we get to clear_inode()? > > If there is no harm in leaving this xarray node hang around until > clear_inode() time, I agree we do not need this patch. > > Are there no issues with large folios getting inserted into the > xarray at a later time, after zapping little ones, and leaving > the empty xarray node dangling? That's not an issue. The code which handles this is in __filemap_add_folio(). You can see that we handle value (ie shadow) entries here: xas_for_each_conflict(&xas, entry) { old = entry; if (!xa_is_value(entry)) { xas_set_err(&xas, -EEXIST); goto unlock; } (this loop will iterate 0 times if there are only empty nodes in the "conflict" area) Then we just do xas_store() which will overwrite the nodes. That calls xas_free_nodes() on any nodes which are overwritten.