Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp6268385rwr; Mon, 1 May 2023 20:12:33 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5W1H7Z82v9wUlATP6Z+Z1W3VKcZmwqNR+Rroys8pNjGG4c44OvO+VcG5X3hbO716Ya4cCS X-Received: by 2002:a17:90a:d301:b0:24d:e3dc:4b10 with SMTP id p1-20020a17090ad30100b0024de3dc4b10mr8749338pju.23.1682997153255; Mon, 01 May 2023 20:12:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682997153; cv=none; d=google.com; s=arc-20160816; b=Drc9G0Tm30SispNicqk4zAOaiVfn5nWL7jCCYcB7zbIYapYvQuQwDSbwZLaVnAcG84 TL8M46ii0jyxhB+oQ1bk3gtnDq5fdDOCAUTbDRchph8RKKDJVaGl2G1wmcT4jH1304GW AtlC1j0zQnHh1YO6EmA8a9m/kDF0qDQxrCpDqrQjmsuC8NiksbmdeeVGQQYWGda7Roun n3F3uHyv0z4jSOMW1xJq8WOnztbzptseKu6Nu3GttVaATy9v1QvCxppjkp9XY8aUmUux eNTxTnJcvSO7f0qrGXaKOkYwjzN+2A9IUeGPI6e8KnhpybDzVPDqjaz3+bqaqh6sBf3X lF4g== 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=uBHdtbr5R5aE+/BDH3yA5uUokIjUDLmAGDFarLNOBCI=; b=Bk30Q41BhY4amTekSaKRy7Egh3zyXEYbZokJfn6QlQdxBum2AiOrsCKk9ket2+usuG lcxLTVdFMQgHNUULoVzaaPqDtnnnAw76VEc5hpN3cI3YNoH4hBk/RxeCOomFPp20bVG5 X50LuCfiL/g3JUks/K/x7jHd5Bcl0jvQyoBFJdEpSALPJuBvNEkpRDOxYhRgJhJWnMOP RRem6vJI/KGQrf2rYYPTJDT54C9PXPS6V3cWALurYKRFWDosMtBmzLaHTGezkJaidU/p hvf90c8mLg4CicSidZFWxbwu/R5fjz1kq4cLN0TEDEBExhFknxXaJFA8ECZK9Ai/R7MD vsvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=VJshB6a4; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k11-20020a170902760b00b001a1bbc5bea5si24443599pll.537.2023.05.01.20.12.15; Mon, 01 May 2023 20:12:33 -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=@redhat.com header.s=mimecast20190719 header.b=VJshB6a4; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233368AbjEBDEK (ORCPT + 99 others); Mon, 1 May 2023 23:04:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232958AbjEBDEI (ORCPT ); Mon, 1 May 2023 23:04:08 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9EA363C19 for ; Mon, 1 May 2023 20:03:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682996597; h=from:from:reply-to:subject:subject: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=uBHdtbr5R5aE+/BDH3yA5uUokIjUDLmAGDFarLNOBCI=; b=VJshB6a4stsePM/LzcMKilgrgs7edmXlZ2C15IgAbqIupwKMO9xZnZXM05wx9tvaVD/xKH 7USM+uFGrMrvlMbCUM1oVhUOWeOwgvIACzvKOFb0Pd6+W5Qawp+Yp+DeMiEbcTjl3U7Yhc xBhyFuaHvEqHoi02NAyOTDTCIvGEHuI= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-407-tDBkuZFvPhScyupDgUob9w-1; Mon, 01 May 2023 23:03:02 -0400 X-MC-Unique: tDBkuZFvPhScyupDgUob9w-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0D63C299E742; Tue, 2 May 2023 03:03:02 +0000 (UTC) Received: from ovpn-8-16.pek2.redhat.com (ovpn-8-16.pek2.redhat.com [10.72.8.16]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4D6CE40F169; Tue, 2 May 2023 03:02:53 +0000 (UTC) Date: Tue, 2 May 2023 11:02:49 +0800 From: Ming Lei To: Theodore Ts'o Cc: Baokun Li , Matthew Wilcox , linux-ext4@vger.kernel.org, Andreas Dilger , linux-block@vger.kernel.org, Andrew Morton , linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, Dave Chinner , Eric Sandeen , Christoph Hellwig , Zhang Yi , yangerkun , ming.lei@redhat.com Subject: Re: [ext4 io hang] buffered write io hang in balance_dirty_pages Message-ID: References: <663b10eb-4b61-c445-c07c-90c99f629c74@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 Sat, Apr 29, 2023 at 12:56:03AM -0400, Theodore Ts'o wrote: > On Sat, Apr 29, 2023 at 11:16:14AM +0800, Ming Lei wrote: > > > > bdi_unregister() is called in del_gendisk(), since bdi_register() has > > to be called in add_disk() where major/minor is figured out. > > > > > problem is that the block device shouldn't just *vanish*, with the > > > > That looks not realistic, removable disk can be gone any time, and device > > driver error handler often deletes disk as the last straw, and it shouldn't > > be hard to observe such error. > > It's not realistic to think that the file system can write back any > dirty pages, sure. At this point, the user has already yanked out the > thumb drive, and the physical device is gone. However, various fields > like bdi->dev shouldn't get deinitialized until after the > s_ops->shutdown() function has returned. Yeah, it makes sense. > > We need to give the file system a chance to shutdown any pending > writebacks; otherwise, we could be racing with writeback happening in > some other kernel thread, and while the I/O is certainly not going to > suceed, it would be nice if attempts to write to the block device > return an error, intead potentially causing the kernel to crash. > > The shutdown function might need to sleep while it waits for > workqueues or kernel threads to exit, or while it iterates over all > inodes and clears all of the dirty bits and/or drop all of the pages > associated with the file system on the disconnected block device. So > while this happens, I/O should just fail, and not result in a kernel > BUG or oops. > > Once the s_ops->shutdown() has returned, then del_gendisk can shutdown > and/or deallocate anything it wants, and if the file system tries to > use the bdi after s_ops->shutdown() has returned, well, it deserves > anything it gets. > > (Well, it would be nice if things didn't bug/oops in fs/buffer.c if > there is no s_ops->shutdown() function, since there are a lot of > legacy file systems that use the buffer cache and until we can add > some kind of generic shutdown function to fs/libfs.c and make sure One generic shutdown API is pretty nice, such as sb_force_shutdown() posted by Dave. > that all of the legacy file systems that are likely to be used on a > USB thumb drive are fixed, it would be nice if they were protected. > At the very least, we should make that things are no worse than they > currently are.) Yeah, things won't be worse than now for legacy FS, given the generic FS API could cover more generic FS cleanup, and block layer always calls it before removing one disk. Thanks, Ming