Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp703656pxf; Thu, 1 Apr 2021 11:18:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwHy/zppUEz9jiaCkGQVQqFz8Bo/rYDzxVyruf8YQrfzs8u7e6uFi7OynR9UjCHO2Nzpn2g X-Received: by 2002:a05:6402:17d6:: with SMTP id s22mr11260400edy.232.1617301092158; Thu, 01 Apr 2021 11:18:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617301092; cv=none; d=google.com; s=arc-20160816; b=e2QKFXsU0c0lYwMHmychI32hsKNmgsa956OxWiisIDhODTuXifyJljvsrk9PhtIWs+ 11QwK7bQTiNnTHV30ApRgygW1vKt2eZZoPLrU3XP0GkSYhBUS14aLGsf57hCsVmpgrw+ 5STxZuOMjyMcn1/g+VfAUuB9XrxScV2IszhgHb8UDj3MJKCymbt5hCMryY2I8vhk777a 4nmg0utMKsgPoRT2b2oAemw+heEVfH6sViu3gTJPGpEA03DOOd+ZD8Sw6GIdMCKfAN2u lgpMxgaE/KSljdpvH7nsKFpdZLC4XS2nI2sF9ycI78oirA3XNEdjYM+yQYw2yW3oeROF M5Aw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=iCMEzATsTfKSllJ0qHxWkotIZ1LmTIaj9wA1MfQzBRo=; b=MkPulhVYp1gnxhilzioMfmnz0RWoOOYpTM8aw8E9XeI63xTAqYXwRLHnrKOxPyjIro KWOOsHA5UCOr1oSWg+2q8pLXEFSLaO+pN01OHEr2Yi9SZgDeeJc6onJ3k4aCXVwSRW+P WehkXLr35Vay1MsH0eNxLNw0ZkI1u+f78jO1CsdOCyUvQVKmcFzKaNsftdZU5gK6h3DX HANOJwWYH9SrEPwJcMvCQ8MoUX/NHDef86NlSlhVLuuHcfIsJhcbJ9VuHIHSaiyVpr9k yXGMkDc3ejCKX4y3lnRg0j0lmNv0QBlNUHXCnDpkzXrZTK8m//66nYLTvn2JVd7WPzMa I0vg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=mN+K+tNl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k3si5407886edh.184.2021.04.01.11.17.49; Thu, 01 Apr 2021 11:18:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=mN+K+tNl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239090AbhDASP1 (ORCPT + 99 others); Thu, 1 Apr 2021 14:15:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236045AbhDAR5R (ORCPT ); Thu, 1 Apr 2021 13:57:17 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 64A95C031174; Thu, 1 Apr 2021 10:06:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=iCMEzATsTfKSllJ0qHxWkotIZ1LmTIaj9wA1MfQzBRo=; b=mN+K+tNl7VN1Zh9vGb6RBIGpcG URsI4ncd1qpZarWtFWlRAuRNMmA4vxy7ER+6UfyJh91G4FWy3JDQJovHDoLobLdF++cwQE3ixv75u /IpLjAFNZj+qdihlzk21Vt0dXA1rLWBj8S+3sH6KGWY4VF85iEnryKOjm9UL/vAdQqynMq6Q5kEox eNkMRVdwDGqWKaMrPiuEfzUa1aVuZMfSIqyuMRB/tpt0JhwrSc7aukHcJSUTbkxFVJ2Adz5qMYZAG Luv5Z3aHjdby3V6GOV7WPfj/gHcPy8wStsVn0PMG7jk8TY3zmwKa1amIZvDRJodtacJLlETBSOCxU dQkiQCAA==; Received: from willy by casper.infradead.org with local (Exim 4.94 #2 (Red Hat Linux)) id 1lS0lr-006OYt-NL; Thu, 01 Apr 2021 17:06:17 +0000 Date: Thu, 1 Apr 2021 18:06:15 +0100 From: Matthew Wilcox To: Hugh Dickins Cc: Andrew Morton , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-nvdimm@lists.01.org, linux-kernel@vger.kernel.org Subject: Re: BUG_ON(!mapping_empty(&inode->i_data)) Message-ID: <20210401170615.GH351017@casper.infradead.org> References: <20210331024913.GS351017@casper.infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Mar 31, 2021 at 02:58:12PM -0700, Hugh Dickins wrote: > I suspect there's a bug in the XArray handling in collapse_file(), > which sometimes leaves empty nodes behind. Urp, yes, that can easily happen. /* This will be less messy when we use multi-index entries */ do { xas_lock_irq(&xas); xas_create_range(&xas); if (!xas_error(&xas)) break; if (!xas_nomem(&xas, GFP_KERNEL)) { result = SCAN_FAIL; goto out; } xas_create_range() can absolutely create nodes with zero entries. So if we create m/n nodes and then it runs out of memory (or cgroup denies it), we can leave nodes in the tree with zero entries. There are three options for fixing it ... - Switch to using multi-index entries. We need to do this anyway, but I don't yet have a handle on the bugs that you found last time I pushed this into linux-next. At -rc5 seems like a late stage to be trying this solution. - Add an xas_prune_range() that gets called on failure. Should be straightforward to write, but will be obsolete as soon as we do the above and it's a pain for the callers. - Change how xas_create_range() works to merely preallocate the xa_nodes and not insert them into the tree until we're trying to insert data into them. I favour this option, and this scenario is amenable to writing a test that will simulate failure halfway through. I'm going to start on option 3 now.