Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp2079408rda; Tue, 24 Oct 2023 11:36:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHZehfkgEvIyTf2D8XX5U2pSU/o06ny33Y/eSJHI46xfyl46dqQ99UP//8/Hs3y2wzvahYa X-Received: by 2002:a17:90a:f315:b0:27d:4d0:5d7f with SMTP id ca21-20020a17090af31500b0027d04d05d7fmr10513361pjb.28.1698172566266; Tue, 24 Oct 2023 11:36:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698172566; cv=none; d=google.com; s=arc-20160816; b=FLffuvSal5FBhMLeT0RVBPNa+/oQ0HudDyHFQGtSbeumXI+pFb3eqEfHiBjX3/F3Q2 izb6BF3HMJdG19iV0x894H6+Y2hYJ+QLbauSdHuR+X9bRABlYvDCxR8dDMGo4OoxxeuX 8aN8HZRVTTFtG/hlMOQiW2VvwxciOp4ahqLKW3aVkbyf0lq3aLq5ngUgsyl2RtnP5c3Y 1AqrTkyJa9mgUPfhClHcz3dX7fMpAX7TYkTX7FdP1jBDWfmr1oTDx5++0DtZfu0CONz0 u9ZS4bKEu6uqjEWk+kcdXPVek0PsjDh+nUCNFAWLGtlsgl6MT4alfEPzz41sJ+AKEigM QUzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:references :cc:to:from:content-language:subject:user-agent:mime-version:date :message-id:dkim-signature; bh=Rh49hnxveSHpPqxFNsKHQhjblqpWbfArPQXsCbv9Cx8=; fh=qX41HoSTZi38rj1FsY/FpFqENsQG5zlooxESYx9WVhU=; b=AJudsPlhx2ZjKU+fHzGfwjHn+IwWIYqQ2sFEHP5pDd0eVnR6GfTCGA+pixsxsUL5J3 jKFuYVs49ZZUi6oRgxoWXDL7Oe6mBfOMIEWPeL/3Vtk4bY4PL/v4DCahm73GwZQU9U4h lN0Eh3D+x3UjtVebDChr1eSzSdAA1hxugJWn21SYQ/xFCRSwQ0q61gyWb/fAPfLgCSRx IW7b0bK5kJCL3eMHwZhXh+7baxQvc63O72wUHZIDRXtMkX+XD/6/FZ1JWsmek1grL5HT 2XZTWYMCbL4hm2h0WRJqxruPWU/ZyN3rXrA8Fb7PVpEk/yntKL5BAwK8PdfF9VHWeQ4b lgtw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel-dk.20230601.gappssmtp.com header.s=20230601 header.b=RXMdEFoY; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id oj11-20020a17090b4d8b00b00268a8e0cab3si11458845pjb.178.2023.10.24.11.36.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 11:36:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel-dk.20230601.gappssmtp.com header.s=20230601 header.b=RXMdEFoY; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 4A093807CED5; Tue, 24 Oct 2023 11:35:38 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344135AbjJXSfc (ORCPT + 99 others); Tue, 24 Oct 2023 14:35:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343992AbjJXSfb (ORCPT ); Tue, 24 Oct 2023 14:35:31 -0400 Received: from mail-io1-xd33.google.com (mail-io1-xd33.google.com [IPv6:2607:f8b0:4864:20::d33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B9415186 for ; Tue, 24 Oct 2023 11:35:28 -0700 (PDT) Received: by mail-io1-xd33.google.com with SMTP id ca18e2360f4ac-7a680e6a921so54414139f.1 for ; Tue, 24 Oct 2023 11:35:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1698172528; x=1698777328; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=Rh49hnxveSHpPqxFNsKHQhjblqpWbfArPQXsCbv9Cx8=; b=RXMdEFoYXYYclct+iLzPu37sZehnQ8EUeoE+F0tQkz9ROEAP9KpyhC3yygxjnzxB5f CsV2wNgUx6h8O0fEwOq3Quilx8S6AZSi/xHHlfxlRH065LemGBSw8d+tJPLifbbaYsFS POd8V2ZcsFxuumMgqW+ByTisYUq02Iny3Sb5tvPlbnfq4q58kH4BBl3QdDfX/44/rsyT cAmFzssiUicLysGS2IeMJmbn/LODppRvXEPNXAZMfCjpkBruqnPaESKho9ac2hNb4j2z Kxr2+JlyrYEUaaXShZbyecvdCHI+p20LdONNiEMQuCG40OeKkWfndDFcAcY/OAkqQNKj LZGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698172528; x=1698777328; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Rh49hnxveSHpPqxFNsKHQhjblqpWbfArPQXsCbv9Cx8=; b=EHbgZPHp1hVjfTAKOOj406NjGal7jYIlUgWM7IdmzASyEddJwL/qOh3AzzIHtpdmy8 zLCBGCl6AsHXhD5gkmuk2OJMRVVhDGbegTX5TZv2IOzuXCcbt+e170/ZUvjJmZOXBS76 5l6BlcuKoN/3ZsJI5lZ9Zcaa146BN1402VGcrKZ56ewQg8KisBwuyEqgAN2WdeS4DNjp 8gna4TpO7p1oGbcvAxuUFV7zVNI24yhguHtD86kFnajlhtrwZrvM8qJ0XMQvu5hArHqM CSGe2B+QkybVzf3/GDhsdc9LmeGr71PNSNSxVwlZD74/0/XqL2mlA6o777v5qQaG86tY mwoQ== X-Gm-Message-State: AOJu0YyAEHMI/gHunQ1YKS5Lo/sUxL0fpO172J8ZnqCSaYQQUn7xxX5B zJ7THz33/WSfgDaK36rj2lchKA== X-Received: by 2002:a05:6e02:4ac:b0:34e:2a69:883c with SMTP id e12-20020a056e0204ac00b0034e2a69883cmr11603414ils.1.1698172527817; Tue, 24 Oct 2023 11:35:27 -0700 (PDT) Received: from [192.168.1.94] ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id dp35-20020a0566381ca300b0042b068d921esm3025149jab.16.2023.10.24.11.35.26 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 24 Oct 2023 11:35:27 -0700 (PDT) Message-ID: Date: Tue, 24 Oct 2023 12:35:26 -0600 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: task hung in ext4_fallocate #2 Content-Language: en-US From: Jens Axboe To: Dave Chinner , Andres Freund Cc: Theodore Ts'o , Thorsten Leemhuis , Shreeya Patel , linux-ext4@vger.kernel.org, =?UTF-8?Q?Ricardo_Ca=C3=B1uelo?= , gustavo.padovan@collabora.com, zsm@google.com, garrick@google.com, Linux regressions mailing list , io-uring@vger.kernel.org References: <20231017033725.r6pfo5a4ayqisct7@awork3.anarazel.de> <20231018004335.GA593012@mit.edu> <20231018025009.ulkykpefwdgpfvzf@awork3.anarazel.de> <74921cba-6237-4303-bb4c-baa22aaf497b@kernel.dk> In-Reply-To: <74921cba-6237-4303-bb4c-baa22aaf497b@kernel.dk> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Tue, 24 Oct 2023 11:35:38 -0700 (PDT) On 10/24/23 8:30 AM, Jens Axboe wrote: > I don't think this is related to the io-wq workers doing non-blocking > IO. The callback is eventually executed by the task that originally > submitted the IO, which is the owner and not the async workers. But... > If that original task is blocked in eg fallocate, then I can see how > that would potentially be an issue. > > I'll take a closer look. I think the best way to fix this is likely to have inode_dio_wait() be interruptible, and return -ERESTARTSYS if it should be restarted. Now the below is obviously not a full patch, but I suspect it'll make ext4 and xfs tick, because they should both be affected. Andres, any chance you can throw this into the testing mix? diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index 202c76996b62..0d946b6d36fe 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -4747,7 +4747,9 @@ long ext4_fallocate(struct file *file, int mode, loff_t offset, loff_t len) } /* Wait all existing dio workers, newcomers will block on i_rwsem */ - inode_dio_wait(inode); + ret = inode_dio_wait(inode); + if (ret) + goto out; ret = file_modified(file); if (ret) diff --git a/fs/inode.c b/fs/inode.c index 84bc3c76e5cc..c4eca812b16b 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -2417,17 +2417,24 @@ EXPORT_SYMBOL(inode_owner_or_capable); /* * Direct i/o helper functions */ -static void __inode_dio_wait(struct inode *inode) +static int __inode_dio_wait(struct inode *inode) { wait_queue_head_t *wq = bit_waitqueue(&inode->i_state, __I_DIO_WAKEUP); DEFINE_WAIT_BIT(q, &inode->i_state, __I_DIO_WAKEUP); + int ret = 0; do { - prepare_to_wait(wq, &q.wq_entry, TASK_UNINTERRUPTIBLE); - if (atomic_read(&inode->i_dio_count)) - schedule(); + prepare_to_wait(wq, &q.wq_entry, TASK_INTERRUPTIBLE); + if (!atomic_read(&inode->i_dio_count)) + break; + schedule(); + if (signal_pending(current)) { + ret = -ERESTARTSYS; + break; + } } while (atomic_read(&inode->i_dio_count)); finish_wait(wq, &q.wq_entry); + return ret; } /** @@ -2440,10 +2447,11 @@ static void __inode_dio_wait(struct inode *inode) * Must be called under a lock that serializes taking new references * to i_dio_count, usually by inode->i_mutex. */ -void inode_dio_wait(struct inode *inode) +int inode_dio_wait(struct inode *inode) { if (atomic_read(&inode->i_dio_count)) - __inode_dio_wait(inode); + return __inode_dio_wait(inode); + return 0; } EXPORT_SYMBOL(inode_dio_wait); diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index 203700278ddb..8ea0c414b173 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -936,7 +936,9 @@ xfs_file_fallocate( * the on disk and in memory inode sizes, and the operations that follow * require the in-memory size to be fully up-to-date. */ - inode_dio_wait(inode); + error = inode_dio_wait(inode); + if (error) + goto out_unlock; /* * Now AIO and DIO has drained we flush and (if necessary) invalidate diff --git a/include/linux/fs.h b/include/linux/fs.h index 4a40823c3c67..7dff3167cb0c 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2971,7 +2971,7 @@ static inline ssize_t blockdev_direct_IO(struct kiocb *iocb, } #endif -void inode_dio_wait(struct inode *inode); +int inode_dio_wait(struct inode *inode); /** * inode_dio_begin - signal start of a direct I/O requests -- Jens Axboe