Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp1766308rwi; Thu, 27 Oct 2022 21:39:04 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5Oh8iwG1HPe081lYhBoHUHvew7v4m4eZY+MLeeO+09uWhEGNzqcrzU9lmtyADkFnCeCTFx X-Received: by 2002:a17:902:e84a:b0:186:b8ff:c698 with SMTP id t10-20020a170902e84a00b00186b8ffc698mr20634710plg.143.1666931944353; Thu, 27 Oct 2022 21:39:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666931944; cv=none; d=google.com; s=arc-20160816; b=ORWFTf1zvVc82gLy+SftTq4e5RxxEjqXCgI/0qyiUQlLJKm2Pz2VmPx+0GdexnzcLU T5RbgIa4hU835C+lLv8G8wQGhmoltJfqx8Vf2bsoxBsi0nhz3hIPTdIQLSqiAVjIr7uQ B02HHe/7akoHgJt0cX0hdYKjOYdGmHMDsLYKiO7EwMcSpQUonk04iUZzEaI8QC8zVkr3 wxbluM3dQKpkZHetKECS45GxoMOaah4sDawIJ/gob4+ER+/2m+7BRCb5/HIMqToXj6ma ytrVIMFcptPHmkLhuMDrr0XYmXJSLf0sNWLjePUV5EUsNJgLmhtgCMcRf0JoavA5cLfl WI4g== 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=DjNDCmtaDyTi+sX4Pf3JIZExNUHwda3QT7q2egtTo8o=; b=FaPkP4xBLLVJkAJWGiQ76HSinckgbfT16Z4j1AKAjdYKpImXrdkVa2UDe7fAV7NejB v9WW+EnPCcrzKuEWGsK4n/WPHIPZYGUPBKOrk2DE+7dGz2A/2+yq3SKcoQdaGYcPfFR3 ny/D7mVH7DsmxMVPPP8lcqXJ/zBe6QbVI39oMCyIj47IIvuCWWcEPfJcSYFBt8OcHefn Ei2TVJ/Bkcd6tMX3k83zLYFB9eoGpZe9s/I7gd5ngcnTHOEOQDZQGVjUnFFWRKDkzULO hpgBrI7GPMOo2kLV0kKME37yr4CwAgMYMurKizFr5OLLXB2PHwZr3RCwC0dqaP1gRfCE s9dw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fromorbit-com.20210112.gappssmtp.com header.s=20210112 header.b=ehFygeg6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t1-20020a056a0021c100b0056bc9b188c6si4608572pfj.245.2022.10.27.21.38.52; Thu, 27 Oct 2022 21:39:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@fromorbit-com.20210112.gappssmtp.com header.s=20210112 header.b=ehFygeg6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229455AbiJ1EGE (ORCPT + 99 others); Fri, 28 Oct 2022 00:06:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229528AbiJ1EGB (ORCPT ); Fri, 28 Oct 2022 00:06:01 -0400 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C90F7868B0 for ; Thu, 27 Oct 2022 21:05:58 -0700 (PDT) Received: by mail-pj1-x102d.google.com with SMTP id t10-20020a17090a4e4a00b0020af4bcae10so3440146pjl.3 for ; Thu, 27 Oct 2022 21:05:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fromorbit-com.20210112.gappssmtp.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=DjNDCmtaDyTi+sX4Pf3JIZExNUHwda3QT7q2egtTo8o=; b=ehFygeg6pvPoUkRY2wnMRQX/o1fRtwAX2R3z3ASXeuUd78DEW1Z0nOfhPXJ7NogC0e E0UbLdWdbkarxIyEEd8gNYTSs6idNgMz4PDO7QZ1IccG63wEFOnKex96rkTUx9Z278JD qr46xCNErRJJXJ6MKtLu6n+gLu067+MrzJph+FoBOz23+WMqdL6X/7TBvxUgaerW23Pa RytfAcL/b5LdIpIUSZnF+HKARwDQSeUcTXpg5ae2oSMKp98nOmyjZiAq0jFTs+njWFaQ TlF9KYDEIny2rsoEnvGq23Kp798C1TIb7AVzzuhXOvDe1n4VrWKSRsafY0gvLDg4YjeN NkPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=DjNDCmtaDyTi+sX4Pf3JIZExNUHwda3QT7q2egtTo8o=; b=OAEnXZxCM9FPxJYmKFQ7J0uZBYhIFXr4hICBGZGOwUShrs7Ix1AWFoLFrKuGr1p2EP h4x6dmqNypnAkE1Lo1n8a3k8xF37BTItGBKmdPu59CVMIsI/cXmMXyU0j7XtkUXJP8bo XQr8J6OBOo80blxKDbl5xhk44G7ka1RmNpeuxT+hnE/uCwuSRntE7ySpkDTDnDfbY0pu 8u5Tv5whzSvz8FBQC67VjmjKjZo2yL1qPfV7LCISGNDhdUFOKMdV3e5u3rUGCmhqqu3K o4YpUrP5ZvSH0EnDFfqXivgqBEnWMCzdS5NOjlbzhqz/ZrMRIDL9qxQ0pbZAJi1NmtMn wjaQ== X-Gm-Message-State: ACrzQf243uIgEn9moYRNOe0I6HrWxMioVm3r+ZKEnPZ3llmQsHmqi+mX tBY+5ldJusWyv+vJZ6RDtxbZADIj0LhElQ== X-Received: by 2002:a17:902:74c3:b0:182:57fa:b9c4 with SMTP id f3-20020a17090274c300b0018257fab9c4mr566074plt.104.1666929958311; Thu, 27 Oct 2022 21:05:58 -0700 (PDT) Received: from dread.disaster.area (pa49-181-106-210.pa.nsw.optusnet.com.au. [49.181.106.210]) by smtp.gmail.com with ESMTPSA id a4-20020a1709027e4400b001801aec1f6bsm1945602pln.141.2022.10.27.21.05.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Oct 2022 21:05:57 -0700 (PDT) Received: from dave by dread.disaster.area with local (Exim 4.92.3) (envelope-from ) id 1ooGd0-007Gjv-PK; Fri, 28 Oct 2022 15:05:54 +1100 Date: Fri, 28 Oct 2022 15:05:54 +1100 From: Dave Chinner To: Matthew Wilcox Cc: Zhaoyang Huang , "zhaoyang.huang" , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, ke.wang@unisoc.com, steve.kang@unisoc.com, baocong.liu@unisoc.com, linux-fsdevel@vger.kernel.org Subject: Re: [RFC PATCH] mm: move xa forward when run across zombie page Message-ID: <20221028040554.GU2703033@dread.disaster.area> References: <20221018223042.GJ2703033@dread.disaster.area> <20221019220424.GO2703033@dread.disaster.area> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Oct 26, 2022 at 05:01:57PM +0100, Matthew Wilcox wrote: > On Thu, Oct 20, 2022 at 10:52:14PM +0100, Matthew Wilcox wrote: > > But I think the tests you've done refute that theory. I'm all out of > > ideas at the moment. > > I have a new idea. In page_cache_delete_batch(), we don't set the > order of the entry before calling xas_store(). That means we can end > up in a situation where we have an order-2 folio in the page cache, > delete it and end up with a NULL pointer at (say) index 20 and sibling > entries at indices 21-23. We can come along (potentially much later) > and put an order-0 folio back at index 20. Now all of indices 20-23 > point to the index-20, order-0 folio. Worse, the xarray node can be > freed with the sibling entries still intact and then be reallocated by > an entirely different xarray. > > I don't know if this is going to fix the problem you're seeing. I can't > quite draw a line from this situation to your symptoms. I came across > it while auditing all the places which set folio->mapping to NULL. > I did notice a mis-ordering; all the other places first remove the folio > from the xarray before setting folio to NULL, but I have a hard time > connecting that to your symptoms either. > > diff --git a/include/linux/xarray.h b/include/linux/xarray.h > index 44dd6d6e01bc..cc1fd1f849a7 100644 > --- a/include/linux/xarray.h > +++ b/include/linux/xarray.h > @@ -1617,6 +1617,12 @@ static inline void xas_advance(struct xa_state *xas, unsigned long index) > xas->xa_offset = (index >> shift) & XA_CHUNK_MASK; > } > > +static inline void xas_adjust_order(struct xa_state *xas, unsigned int order) > +{ > + xas->xa_shift = order - (order % XA_CHUNK_SHIFT); > + xas->xa_sibs = (1 << (order % XA_CHUNK_SHIFT)) - 1; > +} > + > /** > * xas_set_order() - Set up XArray operation state for a multislot entry. > * @xas: XArray operation state. > @@ -1628,8 +1634,7 @@ static inline void xas_set_order(struct xa_state *xas, unsigned long index, > { > #ifdef CONFIG_XARRAY_MULTI > xas->xa_index = order < BITS_PER_LONG ? (index >> order) << order : 0; > - xas->xa_shift = order - (order % XA_CHUNK_SHIFT); > - xas->xa_sibs = (1 << (order % XA_CHUNK_SHIFT)) - 1; > + xas_adjust_order(xas, order); > xas->xa_node = XAS_RESTART; > #else > BUG_ON(order > 0); > diff --git a/mm/filemap.c b/mm/filemap.c > index 08341616ae7a..6e3f486131e4 100644 > --- a/mm/filemap.c > +++ b/mm/filemap.c > @@ -305,11 +305,13 @@ static void page_cache_delete_batch(struct address_space *mapping, > > WARN_ON_ONCE(!folio_test_locked(folio)); > > + if (!folio_test_hugetlb(folio)) > + xas_adjust_order(&xas, folio_order(folio)); > + xas_store(&xas, NULL); > folio->mapping = NULL; > /* Leave folio->index set: truncation lookup relies on it */ > > i++; > - xas_store(&xas, NULL); > total_pages += folio_nr_pages(folio); > } > mapping->nrpages -= total_pages; Nope, that ain't it. I think I've got the data corruption fix sorted now (at least, g/270 isn't assert failing on stray delalloc extents anymore), so if that's the case, I can spend some time actively trying to track this down.... -Dave. -- Dave Chinner david@fromorbit.com