Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp5224001rdb; Sat, 16 Sep 2023 07:47:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH1h6sdil7e2OFibKg6C3duqnNoDmXiuBChe3abftkFtW7cjQXRxdYtpPpSLCOsmhJFCXqr X-Received: by 2002:aca:2b18:0:b0:3ac:b429:f991 with SMTP id i24-20020aca2b18000000b003acb429f991mr4844946oik.3.1694875664204; Sat, 16 Sep 2023 07:47:44 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1694875664; cv=pass; d=google.com; s=arc-20160816; b=E84I//lBrqeRcm/sO3cQQjGRLmy0v180UfkHdrx4RpUiabHPG8GPluSa7Go+p1YA2h /+zbyKFGGmbI45giCS+oGrOU8BE5slBi+g3DBr3IdZ4YSSWLGjdkMOcGMcmakHHc9KYZ zlWvGQXEPtE1x8nrmeiAwxsZx7XkliZ+kO/m8lB1BSM3lz2uSkTG9mNS/ewpdVXK6f51 9Z1RZmcuNvoC9cSYd6hw9FpWGL+zTcxZS6kBsGE1qlbSrnrviiyJ359R0ElZwcfulWfA Sev6Bo7uZK0D7ViuIx9Nj6jDYnTfais2Y8lLJKhGN6u2o7vh5xxr+LYgqOlMTyeVbjjT Y7IQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :message-id:date:subject:cc:to:from:dkim-signature; bh=4hm+lhYvKGPsgiAdh1aD0tYmNntDmEqvBMPH/tRN53U=; fh=tA90HDJEwUFMibU7ST6PYixfE4UcgZeroKXmS5Q67Hw=; b=gqespykHNFUHN7ARZIq6DVkucuJSdM3uHz7wsvz69F15/zNxI72mG05uEu7eMjbBST k12wUtYgRf543BjahXLKt51kw0fG80E8LCY7Gs+HL8zmIFwJVK81oddChOhJUZ2G8482 HHmIxXkb3r7YldLB3G1mDuK9pTs/VUfoPIYTrL6vXwHmjvTnlkMuBRn0ZC9Q7DihmImR 33oppq/PPWfJX9TxbnlWuQdeVl8/cQrjSdSpFlPWQPHG3cCT1eoa0a2L4dTNFPk8Xd0v q60hpsgY6mpgJM/noqVpQWmub1GZKOFzCqBZLKSOAcsXe6GL7bIUh7cQ5NawocuJYgyn 3e9g== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@vivo.com header.s=selector2 header.b=btv3VC6T; arc=pass (i=1 spf=pass spfdomain=vivo.com dkim=pass dkdomain=vivo.com dmarc=pass fromdomain=vivo.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=vivo.com Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id e23-20020a637457000000b00565e01815f2si4935667pgn.732.2023.09.16.07.47.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Sep 2023 07:47:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@vivo.com header.s=selector2 header.b=btv3VC6T; arc=pass (i=1 spf=pass spfdomain=vivo.com dkim=pass dkdomain=vivo.com dmarc=pass fromdomain=vivo.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=vivo.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id C950083CBB23; Fri, 15 Sep 2023 23:03:37 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236512AbjIPF7Q (ORCPT + 99 others); Sat, 16 Sep 2023 01:59:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234360AbjIPF7C (ORCPT ); Sat, 16 Sep 2023 01:59:02 -0400 Received: from APC01-PSA-obe.outbound.protection.outlook.com (mail-psaapc01on2094.outbound.protection.outlook.com [40.107.255.94]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D19EE1BD3; Fri, 15 Sep 2023 22:58:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RDk0O/YaH7xyvSADWY04a1Kq8EGI/a5uCsp6KhZSYSo4mcQBTC0K3FqoyMmQCOuyzszKHoeaSQK+sVOXWXq6YvUInntUHT79NriY//cdDeFd7evD64LHrUFtTXQanYjWt8HVgx/5fg7d40n/shjSTKTnNIvPo6sGvnc0YRHutLX/PSH9Ike3MnBzhSAy04MMaLIHu9bfe/RZqCM6wICJtPAAVkh2ESlbQJTzAQMgGZZrQOyTrXZebI/BcmhAazTAeNUWQzdzEFUbDH76JyhbOoWfsjKObUixo6RJ1eB8Ual3s5lZaHcubiLCGbH+VyoEwPAVUB07Zmf3OJOKcqQ3dw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=4hm+lhYvKGPsgiAdh1aD0tYmNntDmEqvBMPH/tRN53U=; b=HAJ/1kvn5pYDgOKvk/eLTfQYyglZK+qStSAM2VKVa5AlU/uE9ixBKDwIv+6tqTCr1f7NnJaXeC7q57ROqIS5o4Xhgn7t0NdBAw2oTzyMiW56dCr3XlVz7k88cUMdxvLqDUPlM/pGaqTp+4m5OWtgX8QAC6zVK9WFECJCnDlMKbj7Rr/J9nL1h5khB6fZNqoeHgbXCrB78qblTXgFnD8T9EsGUVUuPtiXsFCdNr8yXpYLs2hPSZcmSrGh5nYH/TDFw+YrvC8gXssSyAOX7Xd6jkMhMvQz/QFUk4BQYPmP/5rNLsiSzk4z6dSkjx7Cr1XeI8qVjuLXDgWEtqhte8SGqw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=vivo.com; dmarc=pass action=none header.from=vivo.com; dkim=pass header.d=vivo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vivo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=4hm+lhYvKGPsgiAdh1aD0tYmNntDmEqvBMPH/tRN53U=; b=btv3VC6TnuJ3GYAppBIfYTusj/NvRsKBVRckd8FNktlLTqUqV+0ULcLcazUgu68ihEYzULikPliYTb7SnBeqn6hHrYxBL5izl2G1juQbEl3Ku/lyW7Vf+cWynu34XlwVt4Yqj02pH/A+3kCB9vQdP5VPeBFc3Vuo96vBj99aJ0/Kp0YjnnlFxPSzhR2koFMX60JTQuWD6aAjP6Dg/JtTGvQDL0/CoWu4OJuA5ASriUokvwTbsUtft2hfwmA26POfF2hjfQmkcy6SKz6l1psZTebF/GtsrMzdvw/n8zVKwii4ih5vduovw0HS5PNDRZI08SQL84H+zEEUkHAHQ+aMpw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=vivo.com; Received: from TY2PR06MB3342.apcprd06.prod.outlook.com (2603:1096:404:fb::23) by TYZPR06MB6308.apcprd06.prod.outlook.com (2603:1096:400:41d::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.23; Sat, 16 Sep 2023 05:58:53 +0000 Received: from TY2PR06MB3342.apcprd06.prod.outlook.com ([fe80::60d3:1ef9:d644:3959]) by TY2PR06MB3342.apcprd06.prod.outlook.com ([fe80::60d3:1ef9:d644:3959%4]) with mapi id 15.20.6792.023; Sat, 16 Sep 2023 05:58:52 +0000 From: Chunhai Guo To: jack@suse.cz Cc: brauner@kernel.org, viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Chunhai Guo Subject: [PATCH] fs-writeback: do not requeue a clean inode having skipped pages Date: Fri, 15 Sep 2023 22:51:31 -0600 Message-Id: <20230916045131.957929-1-guochunhai@vivo.com> X-Mailer: git-send-email 2.25.1 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: SI2P153CA0001.APCP153.PROD.OUTLOOK.COM (2603:1096:4:140::7) To TY2PR06MB3342.apcprd06.prod.outlook.com (2603:1096:404:fb::23) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: TY2PR06MB3342:EE_|TYZPR06MB6308:EE_ X-MS-Office365-Filtering-Correlation-Id: e47af366-76b8-4c1d-602e-08dbb67a0120 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: J9Db6LnaDZ0M4MtzW8SxMRsXalYGwjEdGsQg/MbD3ZHfSUJiMcTSFeY0UA0f9GML1zsQVyGYpxXAoRdj1KFxcrrwNze+m9k/9IshFbopAaWi5SHIrsowFZ2zurSsl+p9wcxDcf9gSzOapCZchUAxRTT+nmFh7jQeoD5vHIy9uccFFyGI0eFqH4ifuhS7kx/oDDN74J5oFqPtHqVSSG5Jma99Oz+esMkWoxB1z/pca3ozPycC3PyxHCAAAtGPodjLBpcH9khcfYJzVApTEJufnRYROcCFF2ug7obwd2ZrsFEHrG831Ve68QGwhEzp3ipFy03BJeFIFK+FpsdQmZ74UALDNrNNfB5aOgw+2d7n2Xm0HaVP2Fl7Iz8VhRsiCNuMA7V6WuHq2/acEmCjsp74IKTRSvtAfj/tBn3icvq9pykBGwfsE7RW45H4bvfg8mRnxnMBCAXXUJBB/bgk3V4I73xazRe4zyLcUaq1hvRyUWkkN4oMpGD55ByFYhvT1UBV3n+jO423yZi2zWKklT3V4zeFlOCxuJ0+uTSPgOtZ53HCInFwvXq/BdvQe3EiBPg58Q9D6fSm8FKwdsfrYhzfsNZytJNOU8deTbDtBIlGPexa55IVoQ/jspDlucF+GOLT X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:TY2PR06MB3342.apcprd06.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(396003)(136003)(376002)(366004)(346002)(39850400004)(186009)(1800799009)(451199024)(2616005)(1076003)(107886003)(26005)(6486002)(6506007)(52116002)(6512007)(38100700002)(36756003)(38350700002)(86362001)(83380400001)(5660300002)(478600001)(41300700001)(316002)(66556008)(66476007)(8676002)(8936002)(6916009)(4326008)(6666004)(66946007)(2906002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?qDGpopi8JF+iX8k2A8cJbYksi0DF+lcIGt8efgluxczroKjnV104l0c197qs?= =?us-ascii?Q?z0oPJ1j6xXylpwks5VTXmg30DlrNajw5Ygdzga90a1XfIFRnJUxs03u0JEf1?= =?us-ascii?Q?/U6XPbCQ6r2hW+2gZwlEdDSW5fPrChOAIrwwvjLPTj4pcCAG4ZkZ0xoBuNWt?= =?us-ascii?Q?qGp+uWtu6uXW7PhzZM3yWW9yqNm/INIUUY7F7fENtjJHJ5OrWFES/G3OwZGU?= =?us-ascii?Q?ZWlD7nttv3iRPd5OXs5wAuTNSnJZMg//WnnZghyTO9sEdB9dGNOXqNt5+zY8?= =?us-ascii?Q?8geegdjcrA+4IsO9W1WftHuxT9C3tD16NIfRpTxgT4y6jndkzw0iorra/qgJ?= =?us-ascii?Q?ED3KfBx55vkRXtR68dR4u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?Q?EDaeU3NujTyKV5ufwTqPj/6aR6XmdQOQAL/EcQ+dd8COa7Z8i4WTeUhoTv8z?= =?us-ascii?Q?uvC/wJkc12mIN6oYOKlFSQgyP0RcQK9+sqVALzrhKTnK68c2TvGJYApwARbr?= =?us-ascii?Q?gkvlFoMr0xwd3JW9pp3MprPZ8Dgh2M8lObkPw7QZMpeyQXQj9TPv9LU4i3I1?= =?us-ascii?Q?CA/26+DDYVD4jWMp4UbbxbVi1r99k9yegd4CeQLS4wDpJEic9u/WLNDiT9F4?= =?us-ascii?Q?Y6gALjdWqlcI3RGBN621WWg9rqQzOdUbydrb8E2unonLtgjsq7lO59aJKv0g?= =?us-ascii?Q?j9Z8T9I160m2VBnlwz7KqSx8G3IZnCL9Hzgf1pxd?= X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: e47af366-76b8-4c1d-602e-08dbb67a0120 X-MS-Exchange-CrossTenant-AuthSource: TY2PR06MB3342.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Sep 2023 05:58:52.6948 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 923e42dc-48d5-4cbe-b582-1a797a6412ed X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 4n8aSjGY5OZHHIcmWGuAmxPW/FfYqPX8gXcY4l4JizId39cU7XkDPrbY+YoOCbKq8O07/SxDjJm4GR0hsRVmNQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYZPR06MB6308 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Fri, 15 Sep 2023 23:03:37 -0700 (PDT) When writing back an inode and performing an fsync on it concurrently, a deadlock issue may arise as shown below. In each writeback iteration, a clean inode is requeued to the wb->b_dirty queue due to non-zero pages_skipped, without anything actually being written. This causes an infinite loop and prevents the plug from being flushed, resulting in a deadlock. We now avoid requeuing the clean inode to prevent this issue. wb_writeback fsync (inode-Y) blk_start_plug(&plug) for (;;) { iter i-1: some reqs with page-X added into plug->mq_list // f2fs node page-X with PG_writeback filemap_fdatawrite __filemap_fdatawrite_range // write inode-Y with sync_mode WB_SYNC_ALL do_writepages f2fs_write_data_pages __f2fs_write_data_pages // wb_sync_req[DATA]++ for WB_SYNC_ALL f2fs_write_cache_pages f2fs_write_single_data_page f2fs_do_write_data_page f2fs_outplace_write_data f2fs_update_data_blkaddr f2fs_wait_on_page_writeback wait_on_page_writeback // wait for f2fs node page-X iter i: progress = __writeback_inodes_wb(wb, work) . writeback_sb_inodes . __writeback_single_inode // write inode-Y with sync_mode WB_SYNC_NONE . . do_writepages . . f2fs_write_data_pages . . . __f2fs_write_data_pages // skip writepages due to (wb_sync_req[DATA]>0) . . . wbc->pages_skipped += get_dirty_pages(inode) // wbc->pages_skipped = 1 . if (!(inode->i_state & I_DIRTY_ALL)) // i_state = I_SYNC | I_SYNC_QUEUED . total_wrote++; // total_wrote = 1 . requeue_inode // requeue inode-Y to wb->b_dirty queue due to non-zero pages_skipped if (progress) // progress = 1 continue; iter i+1: queue_io // similar process with iter i, infinite for-loop ! } blk_finish_plug(&plug) // flush plug won't be called Signed-off-by: Chunhai Guo --- fs/fs-writeback.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c index 969ce991b0b0..c1af01b2c42d 100644 --- a/fs/fs-writeback.c +++ b/fs/fs-writeback.c @@ -1535,10 +1535,15 @@ static void requeue_inode(struct inode *inode, struct bdi_writeback *wb, if (wbc->pages_skipped) { /* - * writeback is not making progress due to locked - * buffers. Skip this inode for now. + * Writeback is not making progress due to locked buffers. + * Skip this inode for now. Although having skipped pages + * is odd for clean inodes, it can happen for some + * filesystems so handle that gracefully. */ - redirty_tail_locked(inode, wb); + if (inode->i_state & I_DIRTY_ALL) + redirty_tail_locked(inode, wb); + else + inode_cgwb_move_to_attached(inode, wb); return; } -- 2.25.1