Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp2227337rwl; Thu, 13 Apr 2023 03:36:50 -0700 (PDT) X-Google-Smtp-Source: AKy350Zl8A6lxWjZ3uQXDpmCueItdHJ4YHqGTjCeJogerJt68Vm22HGrP17V8RZ61PKtJhW1SOyv X-Received: by 2002:a17:90a:718b:b0:23d:816:faa9 with SMTP id i11-20020a17090a718b00b0023d0816faa9mr1493443pjk.12.1681382210580; Thu, 13 Apr 2023 03:36:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681382210; cv=none; d=google.com; s=arc-20160816; b=Cb+83uUd/HlpvCNV2+l3+Jc39uJhgR7NWCIV2Y8ZKOijX0K79/PD2m45gUn87YNRKK K8tOPK01IwnmjZg+4HW1P99z2/y89oDfIUJQ2HOz9RiuCpZcZHsvk8Orws0dKK6VRaVo bE5XTly+9PyO055Nf3pQrTt/wv8SpsARYKZ0QC6/Uyv8yPPKzdmUr7N2j2YVBF9CFR/Y 80WkJiDmj/23Wh8kX8Pv+wIfCPVEYvLYdk31/z/EBzTtJ8iC5uNBMXQh1c2RnD9x58cs Dy6GsXGMj3x+kZGJ/cVt8wblFqx4k1ZVW8itZ+PM8T2L6rVGsujK5lyznnyELX674NXo 388g== 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 :dkim-signature; bh=+7eB7KigwZiA+fH3A/5KghsP33/tCKMtEs+CajSqpnE=; b=iCBQzpV1Sao0ZuCwsuvUCs0UT+cSsQbwv3gv9cQMQh334hO3tWJPoLpLaF01GaApLC plZ0GpUa1shChWaspCrx8er7ukEGdikDi3hV8LaHlZSqhES2Mfx7IcUfw0nrNH1eyW8d oyKm9vEe1YbIX6k07dh6Ri7ON+PYalSRGf04eDtqWSrxK4DAv9Ur2Jd/JlRXaT+JFsKl XOLigGEM9jd8PzHddOaEhD7qlveBEJbd78k4IWFfgsEJB89xYA39/Wd8WDyt4zf6tZ+h H+5B1a70p7hCbJMiaqH7zd9UK8SZmY8bZAB11KPtoi3sPbAZ+pxlVMojapdJpcb4NbjF CUeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=hzToN3Lj; dkim=neutral (no key) header.i=@suse.cz; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-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 h1-20020a17090ac38100b002466901be5csi4537172pjt.150.2023.04.13.03.36.34; Thu, 13 Apr 2023 03:36:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-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=@suse.cz header.s=susede2_rsa header.b=hzToN3Lj; dkim=neutral (no key) header.i=@suse.cz; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229739AbjDMKaI (ORCPT + 99 others); Thu, 13 Apr 2023 06:30:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229479AbjDMKaH (ORCPT ); Thu, 13 Apr 2023 06:30:07 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 111BB2729; Thu, 13 Apr 2023 03:30:07 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id B743E218B1; Thu, 13 Apr 2023 10:30:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1681381805; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=+7eB7KigwZiA+fH3A/5KghsP33/tCKMtEs+CajSqpnE=; b=hzToN3Lj0u81vm8Ra98HP3NMJ0MbNnAfminwAJ34lXFb1Z9T18MPrDY8uzLcmhz7TqrqX2 1pToJ1ijT2HsnE3sWWhgQVvrcecVq4nbieHLPStdZ51eMNA3IXSk7s4X1KHIM7XaolG894 20xHvS2NSRqbGulkSGnFL/DYKU16nE8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1681381805; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=+7eB7KigwZiA+fH3A/5KghsP33/tCKMtEs+CajSqpnE=; b=S90bbPSs2ZSlJikspMNu7kaks5cTX5awuepNPPUN+lwqgxdwS48cBHZaH9KGndLXBLqJ0y yQ9hQMC+oChRl/Dw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id A58091390E; Thu, 13 Apr 2023 10:30:05 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 1xxeKK3ZN2RaTAAAMHmgww (envelope-from ); Thu, 13 Apr 2023 10:30:05 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id E494FA0732; Thu, 13 Apr 2023 12:30:04 +0200 (CEST) Date: Thu, 13 Apr 2023 12:30:04 +0200 From: Jan Kara To: Baokun Li Cc: linux-ext4@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, linux-kernel@vger.kernel.org, yi.zhang@huawei.com, yangerkun@huawei.com, yukuai3@huawei.com Subject: Re: [PATCH v3 3/8] ext4: use __GFP_NOFAIL if allocating extents_status cannot fail Message-ID: <20230413103004.a4hjlxgpfqnhcgtg@quack3> References: <20230412124126.2286716-1-libaokun1@huawei.com> <20230412124126.2286716-4-libaokun1@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230412124126.2286716-4-libaokun1@huawei.com> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED 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-ext4@vger.kernel.org On Wed 12-04-23 20:41:21, Baokun Li wrote: > If extent status tree update fails, we have inconsistency between what is > stored in the extent status tree and what is stored on disk. And that can > cause even data corruption issues in some cases. > > For extents that cannot be dropped we use __GFP_NOFAIL to allocate memory. > And with the above logic, the undo operation in __es_remove_extent that > may cause inconsistency if the split extent fails is unnecessary, so we > remove it as well. > > Suggested-by: Jan Kara > Signed-off-by: Baokun Li When I was looking through this patch, I've realized there's a problem with my plan :-|. See below... > static struct extent_status * > ext4_es_alloc_extent(struct inode *inode, ext4_lblk_t lblk, ext4_lblk_t len, > - ext4_fsblk_t pblk) > + ext4_fsblk_t pblk, int nofail) > { > struct extent_status *es; > - es = kmem_cache_alloc(ext4_es_cachep, GFP_ATOMIC); > + gfp_t gfp_flags = GFP_ATOMIC; > + > + if (nofail) > + gfp_flags |= __GFP_NOFAIL; > + > + es = kmem_cache_alloc(ext4_es_cachep, gfp_flags); > if (es == NULL) > return NULL; I have remembered that the combination of GFP_ATOMIC and GFP_NOFAIL is discouraged because the kernel has no sane way of refilling reserves for atomic allocations when in atomic context. So this combination can result in lockups. So what I think we'll have to do is that we'll just have to return error from __es_insert_extent() and __es_remove_extent() and in the callers we drop the i_es_lock, allocate needed status entries (one or two depending on the desired operation) with GFP_KERNEL | GFP_NOFAIL, get the lock again and pass the preallocated entries into __es_insert_extent / __es_remove_extent(). It's a bit ugly but we can at least remove those __es_shrink() calls which are not pretty either. Honza -- Jan Kara SUSE Labs, CR