From patchwork Thu May 8 17:59:00 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harshad Shirwadkar X-Patchwork-Id: 2083059 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=G0fFSCgd; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=2404:9400:2221:ea00::3; helo=mail.ozlabs.org; envelope-from=srs0=tcop=xy=vger.kernel.org=linux-ext4+bounces-7769-patchwork-incoming=ozlabs.org@ozlabs.org; receiver=patchwork.ozlabs.org) Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4ZtfzB0f2xz1xnT for ; Fri, 9 May 2025 03:59:34 +1000 (AEST) Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4ZtfzQ45RGz4xRB for ; Fri, 9 May 2025 03:59:46 +1000 (AEST) Received: by gandalf.ozlabs.org (Postfix) id 4ZtfzQ41Vqz4xRj; Fri, 9 May 2025 03:59:46 +1000 (AEST) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; arc=pass smtp.remote-ip="2604:1380:45e3:2400::1" arc.chain=subspace.kernel.org ARC-Seal: i=2; a=rsa-sha256; d=ozlabs.org; s=201707; t=1746727186; cv=pass; b=tX5q8sDQ3YJLxm4m/K3wmLYigzsHgLWlct81X/mCGc4Fe9aSPkZI01WJvB2M2hfAgEursJ2neg2djSQAAoTj3z/uH6N4vSd/pgWcytKjHN0AoYBn23aDI23xe89S9YUOCy1mKDXuZWVvjgSVYczJvHe+7vGm3fdyMFknRwUwhT7wV3b9KwQzokFWcTNTtKpv/emSJisw6+l/kI3bqRh72kvDr9yTwg1720Q9ICmS9p00sUxqjeCEkie3B+Xb4VN9bNYpwXFVhkeKwKZGnh6IBV0jp10JGgJunLR92JPTiK0ofdJqJYPzv9jK4sVxH/yJ+oIUi9HwR09EBv9/J0Emig== ARC-Message-Signature: i=2; a=rsa-sha256; d=ozlabs.org; s=201707; t=1746727186; c=relaxed/relaxed; bh=PHYPtr7EGhcmivZjeZ/FSny71tLJ11EFlKC1kKH5xzs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MNPQXgBK9i9nPNb5VjZKorVyIEy9z6ZTx6CDfqzxgi/ue2QY5bv2DLlrRRZgCUcfkcWI7z7vLHsjdNJ2iZIT0e42VLei/0CXapxNZWb3FpamqXzZLS0HaCyZ1FwGAExrfTFwgU2G3SfmCLtVuOUv6o9/Ij9QAQjRcZcHugHaHMTcp4A4PVsIXk5klaTwrgrjC64zHJ0WVO9unLey2Da6PHdfNGC6K0UqjD6SiigXoQfIyPtwqkeNEqxrVr4o4vIeJihO4tGecNijzbii7EjiuRK/6KZ+7rBGnHvaHBF/i9Er5SI0e3h0mmTYske3tcJm14pWHoQ2qDJgydgnbO54QQ== ARC-Authentication-Results: i=2; gandalf.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=vger.kernel.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=G0fFSCgd; dkim-atps=neutral Authentication-Results: gandalf.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: gandalf.ozlabs.org; spf=pass smtp.mailfrom=vger.kernel.org Authentication-Results: gandalf.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=G0fFSCgd; dkim-atps=neutral Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org [IPv6:2604:1380:45e3:2400::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by gandalf.ozlabs.org (Postfix) with ESMTPS id 4ZtfzM2JpXz4xRB for ; Fri, 9 May 2025 03:59:43 +1000 (AEST) Received: from smtp.subspace.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 3968B3AABBB for ; Thu, 8 May 2025 17:59:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7A1D3286D4D; Thu, 8 May 2025 17:59:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="G0fFSCgd" X-Original-To: linux-ext4@vger.kernel.org Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AF59F2868B9 for ; Thu, 8 May 2025 17:59:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746727175; cv=none; b=ZVDmsCApVqpLd3yVByWAMJRbwC/uiqKkJYdF0N0pFe1bIuTZHb2LUqTu/SUq5O6wCn1wPpEKVTJN+X0paWWtPkL+aQrP0fWJk/Ozo/cKzd0jTOAewTsczLqeHSyGNGKBbwCKJaqXrva+tS5fgXjYEgfh0zJW6DvzhnwK3XsV0jE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746727175; c=relaxed/simple; bh=UMhJptDCoxFbOr/DgzplbaSy1iUoHDY7iVhruCdi2Qk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jlx8vQO2FF4x/MLK1tgBZ1OYmcZkh5U9DvhdCANrmVGJQ+GMX8ZvAgbAYisg2W1LweKjjlh/TN4MNaVZ64vYJs6nOGh4XgHZGAPVlx0N5nYwHGK1GhR5M+DA/g4Ejg0/m0C8Mw3hfkukgR/bNpCebg56tP6N1Pd+2d56cjbHOxE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=G0fFSCgd; arc=none smtp.client-ip=209.85.214.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-22e3b069f23so14544465ad.2 for ; Thu, 08 May 2025 10:59:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1746727173; x=1747331973; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=PHYPtr7EGhcmivZjeZ/FSny71tLJ11EFlKC1kKH5xzs=; b=G0fFSCgdXv8TDDPnobUPxfMY5eLXSEw7fjdHmBwANzleynSFRydj1aiNgnGCJm6b06 b4VY4MItJDFcuwcnmqEygCXyVk0SFfm/TQ79X2jynMiUxVRdLk+9YK7NdeOHN1yVv2AH w6k9NlEA1+LsAFPnLhw2v9MyY04qq1OQ6VcgNU5BImt7MqWB484x0d6VDgeKCU2z5TPg Is1YLMVQm6xeqBAAV3nG6rWc3Wm5d55kRHIXpmx2FmndV7yBtvYnCYJlyEnBQ2b4EGZ8 q6yd0C7d8U+iyIZ+qilMf76yuDBVqUEGT2buXP/CYw/tV6TGU8TpYAcI7XguZeb1img3 d8PQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746727173; x=1747331973; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PHYPtr7EGhcmivZjeZ/FSny71tLJ11EFlKC1kKH5xzs=; b=oTD1AadA+xBkKfa6+rsx/h68KvNhNNpQxwgt4PW8gGi2j6nf8Ff9PrC8asXlNwb3zt 06DVHGiDTCAZRwOFGD3PQEzHr/RTkmeMtMPLIhep1byWl6rekeJC/P/kQne63vY8sKLm P45tOV3CF3FLfQ7HGWIeoekKSQhO/SlOMrfGL3czJxrHC//DNeSxYEjNzwgg90a5QY+0 J3WMSYvzXAWUuh70q5LQpXZ/czjnTnQ+BL6Q6F9oE3IUwtH5AjuIzN7llobXp6sQ6c7R Q6yijGVW3QEhvpeh1nh0WpJ7C7GPZY0SuLDKmX/xZXKHFuvS37A5MLM+n1Gi6f3j3NKt aJZQ== X-Gm-Message-State: AOJu0YwlG3BLgXoPpnb+4UmqqYVvDKmHxhyi59j0rEY2A/6yKeNEkkTP fd7ZsAU7Ei4Ktnt2BfO1MXPjnFVacP7Xl7tNtcTwuQmhoDA7nyxf1btquxNk X-Gm-Gg: ASbGnctxJxg8b5127FjrmANGlMcsGZ7H6FDWa/siDKFIHA6H5r802WThkNEBHNgOQ/G 6niFWRpZRY0PxyB6vZQXZX/WNlSdG8KihJ8vhgij6GBOqyxtkw7yhO2CQxOJ+GwrY4H//4WIM+X 3ww88zUbEnf1RNUE0LLwp9nUmY3VW7MwwgW33YSf8UIehhAGvO0H4ETgxxlSPWj9IxWvvBzKcDe GaIU6IJ+hu0fyIE3MeFPL5kF/cdOU0CJkp+J16nwVeFlgDn2DjQZgw9fG/inc50vULBO7bwPhvE pbKLbN3nXb1eK9ZKTmEbgW/w8tSLFoJUhrvhebrip8lEy7aISPFAFdrG3s3Y6wdH7c9ophQMr+F HK2eWmXFEwASP2V6i1lcpqXuKSjAt0/ChoGTO X-Google-Smtp-Source: AGHT+IFtora0wLy7ObSusPxsaDuQExvi7KgA7S61jDLUJEo97ej42tcShAPCFmLY4tuCNScjgpUxkw== X-Received: by 2002:a17:902:e94d:b0:224:c46:d166 with SMTP id d9443c01a7336-22fc9185e22mr4356285ad.40.1746727172542; Thu, 08 May 2025 10:59:32 -0700 (PDT) Received: from harshads.c.googlers.com.com (156.242.82.34.bc.googleusercontent.com. [34.82.242.156]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-22fc828939asm2153535ad.164.2025.05.08.10.59.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 May 2025 10:59:32 -0700 (PDT) From: Harshad Shirwadkar To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, jack@suse.cz, harshads@google.com, Harshad Shirwadkar Subject: [PATCH v9 1/9] ext4: convert i_fc_lock to spinlock Date: Thu, 8 May 2025 17:59:00 +0000 Message-ID: <20250508175908.1004880-2-harshadshirwadkar@gmail.com> X-Mailer: git-send-email 2.49.0.1045.g170613ef41-goog In-Reply-To: <20250508175908.1004880-1-harshadshirwadkar@gmail.com> References: <20250508175908.1004880-1-harshadshirwadkar@gmail.com> Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=0.8 required=5.0 tests=ARC_SIGNED,ARC_VALID, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DMARC_PASS, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=disabled version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on gandalf.ozlabs.org Convert ext4_inode_info->i_fc_lock to spinlock to avoid sleeping in invalid contexts. Reviewed-by: Jan Kara Signed-off-by: Harshad Shirwadkar --- fs/ext4/ext4.h | 7 +++++-- fs/ext4/fast_commit.c | 19 +++++++++---------- fs/ext4/super.c | 2 +- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 5a20e9cd7..79dfb57a7 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -1069,8 +1069,11 @@ struct ext4_inode_info { /* Fast commit wait queue for this inode */ wait_queue_head_t i_fc_wait; - /* Protect concurrent accesses on i_fc_lblk_start, i_fc_lblk_len */ - struct mutex i_fc_lock; + /* + * Protect concurrent accesses on i_fc_lblk_start, i_fc_lblk_len + * and inode's EXT4_FC_STATE_COMMITTING state bit. + */ + spinlock_t i_fc_lock; /* * i_disksize keeps track of what the inode size is ON DISK, not diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c index da4263a14..63859ec6d 100644 --- a/fs/ext4/fast_commit.c +++ b/fs/ext4/fast_commit.c @@ -385,7 +385,7 @@ static int ext4_fc_track_template( int ret; tid = handle->h_transaction->t_tid; - mutex_lock(&ei->i_fc_lock); + spin_lock(&ei->i_fc_lock); if (tid == ei->i_sync_tid) { update = true; } else { @@ -393,8 +393,7 @@ static int ext4_fc_track_template( ei->i_sync_tid = tid; } ret = __fc_track_fn(handle, inode, args, update); - mutex_unlock(&ei->i_fc_lock); - + spin_unlock(&ei->i_fc_lock); if (!enqueue) return ret; @@ -428,19 +427,19 @@ static int __track_dentry_update(handle_t *handle, struct inode *inode, struct super_block *sb = inode->i_sb; struct ext4_sb_info *sbi = EXT4_SB(sb); - mutex_unlock(&ei->i_fc_lock); + spin_unlock(&ei->i_fc_lock); if (IS_ENCRYPTED(dir)) { ext4_fc_mark_ineligible(sb, EXT4_FC_REASON_ENCRYPTED_FILENAME, handle); - mutex_lock(&ei->i_fc_lock); + spin_lock(&ei->i_fc_lock); return -EOPNOTSUPP; } node = kmem_cache_alloc(ext4_fc_dentry_cachep, GFP_NOFS); if (!node) { ext4_fc_mark_ineligible(sb, EXT4_FC_REASON_NOMEM, handle); - mutex_lock(&ei->i_fc_lock); + spin_lock(&ei->i_fc_lock); return -ENOMEM; } @@ -471,7 +470,7 @@ static int __track_dentry_update(handle_t *handle, struct inode *inode, list_add_tail(&node->fcd_dilist, &ei->i_fc_dilist); } spin_unlock(&sbi->s_fc_lock); - mutex_lock(&ei->i_fc_lock); + spin_lock(&ei->i_fc_lock); return 0; } @@ -893,15 +892,15 @@ static int ext4_fc_write_inode_data(struct inode *inode, u32 *crc) struct ext4_extent *ex; int ret; - mutex_lock(&ei->i_fc_lock); + spin_lock(&ei->i_fc_lock); if (ei->i_fc_lblk_len == 0) { - mutex_unlock(&ei->i_fc_lock); + spin_unlock(&ei->i_fc_lock); return 0; } old_blk_size = ei->i_fc_lblk_start; new_blk_size = ei->i_fc_lblk_start + ei->i_fc_lblk_len - 1; ei->i_fc_lblk_len = 0; - mutex_unlock(&ei->i_fc_lock); + spin_unlock(&ei->i_fc_lock); cur_lblk_off = old_blk_size; ext4_debug("will try writing %d to %d for inode %ld\n", diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 181934499..ed8166fe2 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -1415,7 +1415,7 @@ static struct inode *ext4_alloc_inode(struct super_block *sb) ei->i_datasync_tid = 0; INIT_WORK(&ei->i_rsv_conversion_work, ext4_end_io_rsv_work); ext4_fc_init_inode(&ei->vfs_inode); - mutex_init(&ei->i_fc_lock); + spin_lock_init(&ei->i_fc_lock); return &ei->vfs_inode; } From patchwork Thu May 8 17:59:01 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harshad Shirwadkar X-Patchwork-Id: 2083061 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=XIerUTvw; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=150.107.74.76; helo=mail.ozlabs.org; envelope-from=srs0=/zqx=xy=vger.kernel.org=linux-ext4+bounces-7770-patchwork-incoming=ozlabs.org@ozlabs.org; receiver=patchwork.ozlabs.org) Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4ZtfzD3vGJz1xnT for ; Fri, 9 May 2025 03:59:36 +1000 (AEST) Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4ZtfzX5LKmz4xRj for ; Fri, 9 May 2025 03:59:52 +1000 (AEST) Received: by gandalf.ozlabs.org (Postfix) id 4ZtfzX5Jcrz4xRB; Fri, 9 May 2025 03:59:52 +1000 (AEST) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; arc=pass smtp.remote-ip=147.75.80.249 arc.chain=subspace.kernel.org ARC-Seal: i=2; a=rsa-sha256; d=ozlabs.org; s=201707; t=1746727192; cv=pass; b=RuWqFcKLVr1ssxS2koLcnN6tOlUpWIU6Tpg7fdFt4ET8uahaE6MFZikssvgOxj+M1txLcEwyP2XoOdehOFkwQGynLZrjpVmr9XkwBXtZ3bwVSeGCmhNlWSgA/zNilH6O6R0pyCafxyuufuMgimzB2l8vopvqp73Zv+kt0V78gpp/antA5VklGZXS+BNOSLFb9qqcRUKh8wHfntQrR80fk/Wg2JcTjwEnzTkfQbO8J/NuZdEdGc1elvqAtICM1HUKF7CdmNVKc6wxt2O0nrKNhPW5+cs+Ovp0QzK/Kqw5VmOSIpOk3HMfXIQ5jp5AWXUSvY/65U2o3/QQytskprkE7A== ARC-Message-Signature: i=2; a=rsa-sha256; d=ozlabs.org; s=201707; t=1746727192; c=relaxed/relaxed; bh=F3v4Uu7RM19taHKPPYlIfAPfDGMsscwFvhEcFJtV9Ek=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FLUVCgRL27mDERsMXeoyRqH4ZPD3u9De3wfbYjgD+lfhgbZIpInmT2R411TietAwyPFbfshismNs48UXH82FNK+HSAzjigtwCI9YSw8EqcZNavRGmbs+NQstJ2SICC/BEUpXnJLIhacGYqHxxvnnJ9EFONIS3VSAo3U+QOAK2X1DrMrFHvGLtwjT79sHsmwk6B6k+7+PHHmHUSjljZJePx0ZmoiW3c5oSxFxGrwVnmQ70igcbRiH/JaQYC49NPQw4Tsr4m4NvkRm2cls3DNfyWETHjnWLWvfEo4JZGPPAGIdHpYFZo9LEAWUdcoTWoTUiJfYUULbqMf/mpRs/drWBQ== ARC-Authentication-Results: i=2; gandalf.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=vger.kernel.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=XIerUTvw; dkim-atps=neutral Authentication-Results: gandalf.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: gandalf.ozlabs.org; spf=pass smtp.mailfrom=vger.kernel.org Authentication-Results: gandalf.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=XIerUTvw; dkim-atps=neutral Received: from am.mirrors.kernel.org (am.mirrors.kernel.org [147.75.80.249]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by gandalf.ozlabs.org (Postfix) with ESMTPS id 4ZtfzS5JcGz4xS5 for ; Fri, 9 May 2025 03:59:48 +1000 (AEST) Received: from smtp.subspace.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 06D371BA785C for ; Thu, 8 May 2025 17:59:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5301A286D58; Thu, 8 May 2025 17:59:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XIerUTvw" X-Original-To: linux-ext4@vger.kernel.org Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 879CA286D40 for ; Thu, 8 May 2025 17:59:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746727176; cv=none; b=Z2O91sHX6JVaI0A5tm1iI//93L9FxiWxGEUSCX2GB94itxUhHTVVPXha74wdiOpt13ENccsn13JmPrumI5SEJ5RpfDJIbrec0qZntGCbHI6STRnJkCG/ViIlXhuEx9ORKRFtjbzuBlsLg4aRQgFwaDgtx3+mvn7EE/jwCUYZR7g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746727176; c=relaxed/simple; bh=z345HmiXRblzh9RR3dTjnXWi5tMWsvqosRjz4pAnSbI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=R55d1JFfaHkIxRqxbU/x5Daoo/cgqI5aUjjiXw4DQpSpQ7/PzwpkFHlJbFQEXHiibRuaIdzD1o/Bp5Wm8dIyOGB7ctyE9iEpNfYR1XQmW4b74V6Cpp5pht2MAKXuwALVDuPVGF9DbUU93qwAxs/y+/0+U/aX1Aufvyhjmmw1sBw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=XIerUTvw; arc=none smtp.client-ip=209.85.210.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-7390d21bb1cso1417495b3a.2 for ; Thu, 08 May 2025 10:59:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1746727173; x=1747331973; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=F3v4Uu7RM19taHKPPYlIfAPfDGMsscwFvhEcFJtV9Ek=; b=XIerUTvwvwIJH6FrOwVYT1MtWZEiiUzYeFc3w1Rp77SGKK7wRRq1hhimcUFr2/OAVA 45XWSp1NoLfaYBxQYbglWCAn2+UNVqSsWyAfs6OyAesgfbBJtJFByM4VcKS9DfXbeVfW xHyeTh5GMegOebxdiJPvdTdZGkvAeP/1f7QEcDPzHGn7SN+IbEBfLBatBPQ3UdPOJ8yR eoQvQ5hxJZ8DqyXUHnk1wnfLKZRuF7Es7/CWbvEbyTEzTYm0p1j0d7mUbmau5dLzFXla 1b0fJsbhjspGBM6qKZp2VXCxzEcu9GHwBS/mvK5kMhzhtd3aKU6CMhIx8I7pL3hFeWaN AMwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746727173; x=1747331973; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=F3v4Uu7RM19taHKPPYlIfAPfDGMsscwFvhEcFJtV9Ek=; b=MDB7qjn7lZphW2ZbKWs8k1n8L+MDObFageuNHbAjG6eKYhDK7Vvd3Ux0uRkHO454jZ 7ONpIa6vZgfY44RBuIxuFNP0z/syvQRvRijT6HB0eN9ZF0akoNShVfEphTGw1bylHrct eRuZmeUtAx5bA7ZS2qmXa+vu9OXMhnaIFAgcUHTYgODs5N55nGwdB3rIgMA3EMUoeXHR QcI0rU6oJB3NxodZizcchGuHjv37bwgcLAcns9Xenebi5K5XSIxbfNm7feWh0bPbW2Ch Poil1GeDfVW1XClQoINYIK3iApeO+hagyCFfUH5ZKbFmH2TtHMLH5pa21vfxe5PdW8bN f3iw== X-Gm-Message-State: AOJu0Yz+0S5b4g9B1R5ggSTDh52sjNWNzXBqLCRmlFAq2Jl6ngu4nbF3 3lCSgtxr5wVllxtmr1ZxF6Cj8W/r4eXLaCrFu7SmqNmZoFH4KsKQ5Lib3/8Q X-Gm-Gg: ASbGncuUiviLdznnku7frS6BtrNNC5OrmDWSzKJCTbOhls7f0dCIlLOS/bOgYOdtzaj t7cqZruEJ0I6L/zb+LtgamVoJ15HnxHtLI5n4oxbJxdhOsHgogupsFiZYsGXx4aIk6XdS/6hV4X 8uSjAdFT5sTUcAeW7I63CROfVBxD2jJv+23ewLHm8/wrOSPZh/Sc/M4/iBCc2i76ELeR6dD2Dr7 roNQSce9OmUA2ZZWnHXgegjvkFAPr9dXvWVcsJYQZa4JH2+Vk9gYkO/LfDwIKQ/LP59wt4pfaK+ 3nCcBVS+VvGbYD0Oi5MTnzcferEfL8UGQ3rcIYWA5OnYDKQ2HdmePP4VqTrESW4UH2VJMyor0vf 3qQQFwog8DNOB7/OmhL5p2TEz6HcjA6VKBhjH X-Google-Smtp-Source: AGHT+IHAEZOfcR0nigbt5Mgl0RXYnZ9UjdaobEamaPuKxjxH4DEtPh99YbJ9jEzAc8qxxoVmPe9xvw== X-Received: by 2002:a17:902:f709:b0:224:1af1:87f4 with SMTP id d9443c01a7336-22fc8b73b24mr4619785ad.22.1746727173148; Thu, 08 May 2025 10:59:33 -0700 (PDT) Received: from harshads.c.googlers.com.com (156.242.82.34.bc.googleusercontent.com. [34.82.242.156]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-22fc828939asm2153535ad.164.2025.05.08.10.59.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 May 2025 10:59:32 -0700 (PDT) From: Harshad Shirwadkar To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, jack@suse.cz, harshads@google.com, Harshad Shirwadkar Subject: [PATCH v9 2/9] ext4: for committing inode, make ext4_fc_track_inode wait Date: Thu, 8 May 2025 17:59:01 +0000 Message-ID: <20250508175908.1004880-3-harshadshirwadkar@gmail.com> X-Mailer: git-send-email 2.49.0.1045.g170613ef41-goog In-Reply-To: <20250508175908.1004880-1-harshadshirwadkar@gmail.com> References: <20250508175908.1004880-1-harshadshirwadkar@gmail.com> Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-1.5 required=5.0 tests=ARC_SIGNED,ARC_VALID, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DMARC_PASS, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=disabled version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on gandalf.ozlabs.org If the inode that's being requested to track using ext4_fc_track_inode is being committed, then wait until the inode finishes the commit. Also, add calls to ext4_fc_track_inode at the right places. With this patch, now calling ext4_reserve_inode_write() results in inode being tracked for next fast commit. This ensures that by the time ext4_reserve_inode_write() returns, it is ready to be modified and won't be committed until the corresponding handle is open. A subtle lock ordering requirement with i_data_sem (which is documented in the code) requires that ext4_fc_track_inode() be called before grabbing i_data_sem. So, this patch also adds explicit ext4_fc_track_inode() calls in places where i_data_sem grabbed. Signed-off-by: Harshad Shirwadkar --- fs/ext4/fast_commit.c | 35 +++++++++++++++++++++++++++++++++++ fs/ext4/inline.c | 1 + fs/ext4/inode.c | 5 +++++ 3 files changed, 41 insertions(+) diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c index 63859ec6d..c4d3c71d5 100644 --- a/fs/ext4/fast_commit.c +++ b/fs/ext4/fast_commit.c @@ -12,6 +12,7 @@ #include "ext4_extents.h" #include "mballoc.h" +#include /* * Ext4 Fast Commits * ----------------- @@ -570,6 +571,8 @@ static int __track_inode(handle_t *handle, struct inode *inode, void *arg, void ext4_fc_track_inode(handle_t *handle, struct inode *inode) { + struct ext4_inode_info *ei = EXT4_I(inode); + wait_queue_head_t *wq; int ret; if (S_ISDIR(inode->i_mode)) @@ -587,6 +590,38 @@ void ext4_fc_track_inode(handle_t *handle, struct inode *inode) if (ext4_test_mount_flag(inode->i_sb, EXT4_MF_FC_INELIGIBLE)) return; + if (!list_empty(&ei->i_fc_list)) + return; + + /* + * If we come here, we may sleep while waiting for the inode to + * commit. We shouldn't be holding i_data_sem when we go to sleep since + * the commit path needs to grab the lock while committing the inode. + */ + lockdep_assert_not_held(&ei->i_data_sem); + + while (ext4_test_inode_state(inode, EXT4_STATE_FC_COMMITTING)) { +#if (BITS_PER_LONG < 64) + DEFINE_WAIT_BIT(wait, &ei->i_state_flags, + EXT4_STATE_FC_COMMITTING); + wq = bit_waitqueue(&ei->i_state_flags, + EXT4_STATE_FC_COMMITTING); +#else + DEFINE_WAIT_BIT(wait, &ei->i_flags, + EXT4_STATE_FC_COMMITTING); + wq = bit_waitqueue(&ei->i_flags, + EXT4_STATE_FC_COMMITTING); +#endif + prepare_to_wait(wq, &wait.wq_entry, TASK_UNINTERRUPTIBLE); + if (ext4_test_inode_state(inode, EXT4_STATE_FC_COMMITTING)) + schedule(); + finish_wait(wq, &wait.wq_entry); + } + + /* + * From this point on, this inode will not be committed either + * by fast or full commit as long as the handle is open. + */ ret = ext4_fc_track_template(handle, inode, __track_inode, NULL, 1); trace_ext4_fc_track_inode(handle, inode, ret); } diff --git a/fs/ext4/inline.c b/fs/ext4/inline.c index 2c9b76292..fbc1c84b5 100644 --- a/fs/ext4/inline.c +++ b/fs/ext4/inline.c @@ -601,6 +601,7 @@ static int ext4_convert_inline_data_to_extent(struct address_space *mapping, goto out; } + ext4_fc_track_inode(handle, inode); ret = ext4_destroy_inline_data_nolock(handle, inode); if (ret) goto out; diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 94c7d2d82..d58b99407 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -696,6 +696,8 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode, if (!(flags & EXT4_GET_BLOCKS_CONVERT_UNWRITTEN)) return retval; + + ext4_fc_track_inode(handle, inode); /* * New blocks allocate and/or writing to unwritten extent * will possibly result in updating i_data, so we take @@ -4072,6 +4074,7 @@ int ext4_punch_hole(struct file *file, loff_t offset, loff_t length) if (end_lblk > start_lblk) { ext4_lblk_t hole_len = end_lblk - start_lblk; + ext4_fc_track_inode(handle, inode); down_write(&EXT4_I(inode)->i_data_sem); ext4_discard_preallocations(inode); @@ -4224,6 +4227,7 @@ int ext4_truncate(struct inode *inode) if (err) goto out_stop; + ext4_fc_track_inode(handle, inode); down_write(&EXT4_I(inode)->i_data_sem); ext4_discard_preallocations(inode); @@ -5895,6 +5899,7 @@ ext4_reserve_inode_write(handle_t *handle, struct inode *inode, brelse(iloc->bh); iloc->bh = NULL; } + ext4_fc_track_inode(handle, inode); } ext4_std_error(inode->i_sb, err); return err; From patchwork Thu May 8 17:59:02 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harshad Shirwadkar X-Patchwork-Id: 2083065 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=I2PqFmua; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=2404:9400:2221:ea00::3; helo=mail.ozlabs.org; envelope-from=srs0=iicz=xy=vger.kernel.org=linux-ext4+bounces-7772-patchwork-incoming=ozlabs.org@ozlabs.org; receiver=patchwork.ozlabs.org) Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4ZtfzT6NVcz1xnT for ; Fri, 9 May 2025 03:59:49 +1000 (AEST) Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Ztfzp0j6Nz4x89 for ; Fri, 9 May 2025 04:00:06 +1000 (AEST) Received: by gandalf.ozlabs.org (Postfix) id 4Ztfzp0gNKz4xRj; Fri, 9 May 2025 04:00:06 +1000 (AEST) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; arc=pass smtp.remote-ip="2604:1380:45d1:ec00::1" arc.chain=subspace.kernel.org ARC-Seal: i=2; a=rsa-sha256; d=ozlabs.org; s=201707; t=1746727206; cv=pass; b=enzmMBm828lTNaBRs2ZSOT8nJvhiC8INjzBYZ5iHpw2QPByx7DffURodUgL6eF1ONTF2toZucqRMv1deROXP50U/R/umqae85cxafItnjdq/kONRCXdid7pJ1fL/a5wmYrfbQKReWnE9vzgsUlvYVCM3RjYMSSgw3dgyIXPKkIFVgNzqLRH7esYH4MZHZyILEZGxNunmncehSzGMIWkrT5XzmG6bAoZVrbnn4QNwbfrKvtk32qgEChCRR6Zq3BWdGAXil63hDf6y/0HAZerfWx2QkWBmqBNGJTPv1Y31Y7nQT/wvqYkoSf0MD7YVE6IzLkftGm2Txq9zYKhZ+zoo3w== ARC-Message-Signature: i=2; a=rsa-sha256; d=ozlabs.org; s=201707; t=1746727206; c=relaxed/relaxed; bh=3J3ONY8vgdLjhe4cTDoDJfzp8TTcSljQEGDbEciEr/E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hJCLzd/WYRWe01Hn3SAQhbxvGDZeS6RJHmihpu3Zdxio+H1DKEUwbRKIEV2M5TH8GUxx01rDIrttSsZoGNnZFAhCx0qrTyZGy3hFcYLMv64mLo9BcCcV0yhu/NmfomcynNk1mD7hHAdECixYmBn5wm+radWYuymbIpgcu+13UFX8U1jnOw0/uHFRiXUnAREYuUIAD5Iu1hwpg8WF5NW2i5WcZU/uv/INpbI9Dlo3wO3jLOT4Z8dZ2U8s4uPKoyDltnbYuPthlfJMRlx7mgbki6f1004JtqOS0AXw/jaVqodORRjJ8D8tfNV5paRhOVbxNTbr/LgMQDoXnm5h4I4tKg== ARC-Authentication-Results: i=2; gandalf.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=vger.kernel.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=I2PqFmua; dkim-atps=neutral Authentication-Results: gandalf.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: gandalf.ozlabs.org; spf=pass smtp.mailfrom=vger.kernel.org Authentication-Results: gandalf.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=I2PqFmua; dkim-atps=neutral Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org [IPv6:2604:1380:45d1:ec00::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by gandalf.ozlabs.org (Postfix) with ESMTPS id 4Ztfzk58hlz4x89 for ; Fri, 9 May 2025 04:00:02 +1000 (AEST) Received: from smtp.subspace.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 0DAF94C039C for ; Thu, 8 May 2025 17:59:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DC5DA286D64; Thu, 8 May 2025 17:59:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="I2PqFmua" X-Original-To: linux-ext4@vger.kernel.org Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 327BF286D57 for ; Thu, 8 May 2025 17:59:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746727177; cv=none; b=HBD7qugJKNnC1i991L8O1ef00ybAoSrvUkLft9wpAcItT0kedcP96Us4umKckAXOxhMzpjZCxoDdKQwmcQzTMWRlCv+N34OMHDIfDdn88NECBEvehojDsTeHjORAxU1aNRVEOwKUNNdnfCXuq6spQ1niFiAVVciFhYi9cRgFPe8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746727177; c=relaxed/simple; bh=euzDy5W3RCCN/7/FFqniDYNWbLu9Sf8b8BbLwh6BIW0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uwUtBtP+IdEsrVXIwNlOE+6fS7dQkUdwMQovy7LxzTt0M/hHN0TxmhjPR1aTNiraq5YdqTTSgQXfVhJMJXWoKSJcPxcTQ6dNfR7s74QHU6IePUWdmZOU8etV2RRHOJ8n2TVqnPVJsGPE9UWYd+7Z6aUKGaQxfAWUwfYP4laYads= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=I2PqFmua; arc=none smtp.client-ip=209.85.215.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pg1-f182.google.com with SMTP id 41be03b00d2f7-b200047a6a5so766720a12.0 for ; Thu, 08 May 2025 10:59:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1746727174; x=1747331974; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3J3ONY8vgdLjhe4cTDoDJfzp8TTcSljQEGDbEciEr/E=; b=I2PqFmuasJ1NDvIYbEpTze8zYNXvt5Q7BCBn0kyqg1S3y/DELBcGPJ9NvLfdqkqoNl MMgOakjFX0MO/FqzyLNH5sIhw73n/4/jwnDtMpypCbcgUhgNd13UDG5Q37BvlA2aqpMO yw4lG7pOdY8pI/uZtOEmkpGh6mLU0iJIT1Ef09eiM9MSv3ZoJ6g+dppBkB32yEwp2BRA iQTdDumuYbpgkEWezMm0l60dkb1ELuGknnL2NguHXdbsSKxbD/fOtSh7TMbhJpELk2a4 u29bC/ibCgVIswRojWhaDk7wImfT916sCw/phIUqSrWX3ZpVUqkFnMJE9phzqPdWFq2W FN0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746727174; x=1747331974; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3J3ONY8vgdLjhe4cTDoDJfzp8TTcSljQEGDbEciEr/E=; b=bChp1oTeVESqmO4ukq0v54KmDNrysG3YwL8aSAd+iB0h9Yn+uGf0VhOEWHYjOmvyp+ DHvgRn71aLj/IuQts49allrsfg0RxajvKiK2SlONCXPTQIj2QEc790TukXwWmDQc5wX6 6vptCLOZKYv85I6I5kGhaE7QOMnJShTJLzUUTq9JzHIfTrVxOPCe96NjsMH8PEN7g8E+ 35LUbctqbawIxwg+h/a93GZCHAnFzjnsJtk/Kg7R+QGkEvtuC9kQo0KW5mvEyhTf1+Og bxZZrbhh/MceX1bOzHzOzQMkaQeaCaMmG5+sUVXs238b9yc90NE4iU1AVH6dYF08SwFg DESw== X-Gm-Message-State: AOJu0YzY2G5r4iUySxngptGHhZMEm8uvzXjGPTNCUN1LGR1MNYRSYgYw d56uosX1ohgIDOH/zScYxv/Fh1OjoL7UZooobOXTHKbfZYOk+41sAEi4KEHjbCc= X-Gm-Gg: ASbGnctpEVJljsQtj6l79s6kZNQtlloWau/n2pqkrkRc6NHAQYcfYZDMvPtPnOD9UOm VLKWGEShf0t+QZrE+6juvG9hyZIAHoehxtqNdVYLNl8ml2AP4pOOluXinOUN9OxYgASIcEWi0VQ 9GghUkQ4iE/Hw88ZRur+x+wTMaRpNd35yIupiPhEeVkplO+XlvUdRsdViGTpPMx99Lma2OaAtZl N1PIYIQXn4ziczmuG0TBZZ9DilIhq4gnLmpiGs1ptjv7J7NaBF8FZIlg2a/qBt6Mab0GKg6kC2s AwZYSW8lAt/tb/F8wGF3sYO49N44j28KZ20uOBW5G3J+Kn3y9TCpCk6SaqjGVAZM1GEiYjGZkKF PM0LuV8V3v1t54+xurZjs8hMLADR3xMV85Vv+ X-Google-Smtp-Source: AGHT+IGH7W4aIu4onz8qGaRGeceN0YjRFsSg95EdhhCr3dnak6AQxV7YBi3TofZOWGSN0G0n97u6WA== X-Received: by 2002:a17:903:1744:b0:224:3994:8a8c with SMTP id d9443c01a7336-22e8470d946mr61701005ad.8.1746727173718; Thu, 08 May 2025 10:59:33 -0700 (PDT) Received: from harshads.c.googlers.com.com (156.242.82.34.bc.googleusercontent.com. [34.82.242.156]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-22fc828939asm2153535ad.164.2025.05.08.10.59.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 May 2025 10:59:33 -0700 (PDT) From: Harshad Shirwadkar To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, jack@suse.cz, harshads@google.com, Harshad Shirwadkar Subject: [PATCH v9 3/9] ext4: mark inode dirty before grabbing i_data_sem in ext4_setattr Date: Thu, 8 May 2025 17:59:02 +0000 Message-ID: <20250508175908.1004880-4-harshadshirwadkar@gmail.com> X-Mailer: git-send-email 2.49.0.1045.g170613ef41-goog In-Reply-To: <20250508175908.1004880-1-harshadshirwadkar@gmail.com> References: <20250508175908.1004880-1-harshadshirwadkar@gmail.com> Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=0.8 required=5.0 tests=ARC_SIGNED,ARC_VALID, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DMARC_PASS, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=disabled version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on gandalf.ozlabs.org Mark inode dirty first and then grab i_data_sem in ext4_setattr(). Signed-off-by: Harshad Shirwadkar --- fs/ext4/inode.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index d58b99407..3005053e9 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -5568,9 +5568,7 @@ int ext4_setattr(struct mnt_idmap *idmap, struct dentry *dentry, down_write(&EXT4_I(inode)->i_data_sem); old_disksize = EXT4_I(inode)->i_disksize; EXT4_I(inode)->i_disksize = attr->ia_size; - rc = ext4_mark_inode_dirty(handle, inode); - if (!error) - error = rc; + /* * We have to update i_size under i_data_sem together * with i_disksize to avoid races with writeback code @@ -5581,6 +5579,9 @@ int ext4_setattr(struct mnt_idmap *idmap, struct dentry *dentry, else EXT4_I(inode)->i_disksize = old_disksize; up_write(&EXT4_I(inode)->i_data_sem); + rc = ext4_mark_inode_dirty(handle, inode); + if (!error) + error = rc; ext4_journal_stop(handle); if (error) goto out_mmap_sem; From patchwork Thu May 8 17:59:03 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harshad Shirwadkar X-Patchwork-Id: 2083064 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=Yrgt9fuD; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=2404:9400:2221:ea00::3; helo=mail.ozlabs.org; envelope-from=srs0=zs4l=xy=vger.kernel.org=linux-ext4+bounces-7774-patchwork-incoming=ozlabs.org@ozlabs.org; receiver=patchwork.ozlabs.org) Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4ZtfzN59M0z1xnT for ; Fri, 9 May 2025 03:59:44 +1000 (AEST) Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Ztfzh6sjjz4x89 for ; Fri, 9 May 2025 04:00:00 +1000 (AEST) Received: by gandalf.ozlabs.org (Postfix) id 4Ztfzh6r31z4xQq; Fri, 9 May 2025 04:00:00 +1000 (AEST) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; arc=pass smtp.remote-ip=147.75.80.249 arc.chain=subspace.kernel.org ARC-Seal: i=2; a=rsa-sha256; d=ozlabs.org; s=201707; t=1746727200; cv=pass; b=I0VerpXVhs70dc50WW2U/FaF9DFIEbIQQ0iXA9z1k+vxHJXaL8adx7smctD5iNxSYqN5DVBCFtQx8KvZxiIhXQM0W4h4tlSPvyjnBZj391qggqYzIusHCEMrvjwuAMRAyzhexhlnTH57z+5+vjIQYe5+Nw3GTIRZ1jjDcnXK8YKQ2KbTJ2b5hhU1RPpGAm/U3JlxMDevhEqwBZ2A4A7+2uD7GxqjHV5Y77XzkIKp/hmY5n7D7UjSxjRzM0VOaiWQTr3e9uWLlmiXoD8F6y6/u/aUoXkx4SdmWql98nzOCDkTT2ta0gRpyFa2DyglJunwmuig2wY95TRTYavVyyd3Wg== ARC-Message-Signature: i=2; a=rsa-sha256; d=ozlabs.org; s=201707; t=1746727200; c=relaxed/relaxed; bh=87uznKkkSVtzO9DIjK4jjC6UUt+uP7TU1rrta1GizHs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=W1v5BcOXLTw2gNLLcBbHYHgfHLYA6IHgL8nKvp6qcPtN0xZmagceMusc04vgocOJdiG1x9SBXR/jAPMahNEERdvkjfucQzGSt2wxhUIjdwuuFb2MGMANaLbY9KK5exJLv11TpZYI9wQh4Ew++TwL5wZkiixknFaUQ7iG+e1aNux1PrafulmUkLnZpZPLcWOsxNxksyVeRTUF95fFq6VEF3RxJAB6Vh6DYNj4s6lI9Ioq9B7b1okYh1OACbaJT0dAxvwCtUDStEn7XEEmYIhe49jqYeMKtCWYY/bTCsrgXhPamBQlvxTAnZ/14HXgbe8LKMjVaNWZlWst0tLvt3gD/A== ARC-Authentication-Results: i=2; gandalf.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=vger.kernel.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=Yrgt9fuD; dkim-atps=neutral Authentication-Results: gandalf.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: gandalf.ozlabs.org; spf=pass smtp.mailfrom=vger.kernel.org Authentication-Results: gandalf.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=Yrgt9fuD; dkim-atps=neutral Received: from am.mirrors.kernel.org (am.mirrors.kernel.org [147.75.80.249]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by gandalf.ozlabs.org (Postfix) with ESMTPS id 4Ztfzd3bsfz4x89 for ; Fri, 9 May 2025 03:59:57 +1000 (AEST) Received: from smtp.subspace.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id B88451BA7875 for ; Thu, 8 May 2025 18:00:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9B7DA286D7B; Thu, 8 May 2025 17:59:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Yrgt9fuD" X-Original-To: linux-ext4@vger.kernel.org Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8D57C286D5D for ; Thu, 8 May 2025 17:59:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746727178; cv=none; b=XH0ffGeF2DlVkTZXbyOVTIIrMfyDH6DMcBReRoKx+90HSW+CtIQBfX60/WtZP9R+rF1cJw0pysohm18ngDZE5eTvluPCSGBfvx0eQyoLzSmL5Tts1V+Af2oudkx1xieFS/pYOMT2TMQQarVLqOWjFZ62buXZqLeYJR18RvpwW5o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746727178; c=relaxed/simple; bh=fjFst4/ZwL9utROtErveJRaLhk2doxUaI3n4DjL/ivU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Oft7NZQBnxJ+L/8qBk6iqn7f+zFSgnP+g5aq+r6mudUud9DsZ6DZOCOUPd6kW+YffzFOMRhHuv7vHQo8PFaIPl+lOIVstaUEts1GVtMV8tiNs+NgaUlq05M/ByiQ30NPmP3oHxeLfahBoU/um7LMmIDylyGpxiXTNQXoyVemt8Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Yrgt9fuD; arc=none smtp.client-ip=209.85.215.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pg1-f180.google.com with SMTP id 41be03b00d2f7-af5085f7861so862448a12.3 for ; Thu, 08 May 2025 10:59:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1746727174; x=1747331974; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=87uznKkkSVtzO9DIjK4jjC6UUt+uP7TU1rrta1GizHs=; b=Yrgt9fuDpF2KqX5UMFbRVevxju0GhW+frxDFe+/4ZOtRrkWLxtE/P4LLN6jqT84hsj DuzeOniWjOosZtLyuHuq/YmFgcpdXnEboAVAmYVCoqE9xhhtVThlxlMbdRm0+Q7ElxYO Ux6ZmlO9xtLMAJcC9bBscob1xns96ahuw+sKW7oXx1dDS2WwnOt26l3UtP/f6oik0PnI OQfxxkfUeLXV5UPeb1tRMXh4LDpu19WhBkBJQ1Yl4gjPE5hGq9U6/8FnKIwKTVKIJl7I zgYDDOyoFvZ2e/y9eUTvC5bXzK/F9i5p62g/bLaKSvTufoNuA3X/5iyuk9MgTNrY2x2f ANXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746727174; x=1747331974; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=87uznKkkSVtzO9DIjK4jjC6UUt+uP7TU1rrta1GizHs=; b=T3aMeMuzqAdh/8EomC4LKd4mpctd/Tufg3G9N8hOUOgU1BeDaXuw9uaLjcPKjbu/ES 20Po7M8+zNARdFShe1Klcu7wY7BwuwrLh/nXtesGr39QpTvnozYLJwC3rHjN2Bk3K8OQ xQIlAmzFJUuNHbOi7RWpkPPxuH9zr8FrW17S1mTzywOufPy5RIUPAC9ep+6ydf3qeskk 5OA0n+PaJ/5LFo6+nvLMq+G6sBsCuSLL93Kt69iqYrPDnKz08k1woAwoCOtJlpUYBICe qTzRMXCXskVL63yzrezVKbt+8Hf5su/FB2fdTkIz9/4W/tpKXr11lOXre3bi76ASnTd+ g72Q== X-Gm-Message-State: AOJu0Yy/80Y/L4M/5ZQDm+nhubfFgxJO7vu5vfXek6rBJpzP0erI2SwS PDoyfBbzjhSVj4ksJK9cEzfCaKL8X1+R4rRqXM75GBDH+nOvvXt45UVkrnt7S3Q= X-Gm-Gg: ASbGncsVmiAGenouNx3diJhDaDJkoM9h7JcIFUykn7Wp2odtVut64yswTZvh266aweC sgKCHCYT9eBIuHrU7AxLRymPXUZff8KydIJR+TUk2r9/aVN0Pa9Es1fuEO5mCzmfFLtkNJLAsGA 0pAvC+Sh87ewUE1APqFJiOCB4n0ckuO9EAq11HMusZiUAQK7j1sLEVnm5OH7y+OBkSKAkFCIQO8 6cRk22aGPXXC2mj+5ZvfVqpfSiIquE/HsTaTJoLaLtU6mHOvOcieHAXJN5/mWAAHJBFwHvyEeBt a9HUf8dg5oDWnJhSPf5VbMUBsx3ANWtaMZ8R+hbPx6HUTU3nBYas9NYAvpSD4kLDUTjoXuz8Lsc pP4YaHKO5SMcXh5wlyTdBQykghnlF+4xdFvMM X-Google-Smtp-Source: AGHT+IHf1Q7bXbhKMwLLNIMainBv2H17O3A0Xag7tx4ObSvyL1fej9B1eeyrjDt4cch7XBXdQSzLMg== X-Received: by 2002:a17:903:1a2c:b0:224:c47:cb7 with SMTP id d9443c01a7336-22fc894ed3amr5356305ad.0.1746727174334; Thu, 08 May 2025 10:59:34 -0700 (PDT) Received: from harshads.c.googlers.com.com (156.242.82.34.bc.googleusercontent.com. [34.82.242.156]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-22fc828939asm2153535ad.164.2025.05.08.10.59.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 May 2025 10:59:33 -0700 (PDT) From: Harshad Shirwadkar To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, jack@suse.cz, harshads@google.com, Harshad Shirwadkar Subject: [PATCH v9 4/9] ext4: rework fast commit commit path Date: Thu, 8 May 2025 17:59:03 +0000 Message-ID: <20250508175908.1004880-5-harshadshirwadkar@gmail.com> X-Mailer: git-send-email 2.49.0.1045.g170613ef41-goog In-Reply-To: <20250508175908.1004880-1-harshadshirwadkar@gmail.com> References: <20250508175908.1004880-1-harshadshirwadkar@gmail.com> Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-1.5 required=5.0 tests=ARC_SIGNED,ARC_VALID, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DMARC_PASS, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=disabled version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on gandalf.ozlabs.org This patch reworks fast commit's commit path to remove locking the journal for the entire duration of a fast commit. Instead, we only lock the journal while marking all the eligible inodes as "committing". This allows handles to make progress in parallel with the fast commit. Signed-off-by: Harshad Shirwadkar --- fs/ext4/ext4.h | 1 + fs/ext4/fast_commit.c | 199 ++++++++++++++++++++++++++---------------- fs/jbd2/journal.c | 2 - 3 files changed, 126 insertions(+), 76 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 79dfb57a7..493d9ac7a 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -1916,6 +1916,7 @@ enum { EXT4_STATE_LUSTRE_EA_INODE, /* Lustre-style ea_inode */ EXT4_STATE_VERITY_IN_PROGRESS, /* building fs-verity Merkle tree */ EXT4_STATE_FC_COMMITTING, /* Fast commit ongoing */ + EXT4_STATE_FC_FLUSHING_DATA, /* Fast commit flushing data */ EXT4_STATE_ORPHAN_FILE, /* Inode orphaned in orphan file */ }; diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c index c4d3c71d5..a2cb4d965 100644 --- a/fs/ext4/fast_commit.c +++ b/fs/ext4/fast_commit.c @@ -287,24 +287,55 @@ void ext4_fc_del(struct inode *inode) struct ext4_inode_info *ei = EXT4_I(inode); struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); struct ext4_fc_dentry_update *fc_dentry; + wait_queue_head_t *wq; if (ext4_fc_disabled(inode->i_sb)) return; -restart: spin_lock(&sbi->s_fc_lock); if (list_empty(&ei->i_fc_list) && list_empty(&ei->i_fc_dilist)) { spin_unlock(&sbi->s_fc_lock); return; } - if (ext4_test_inode_state(inode, EXT4_STATE_FC_COMMITTING)) { - ext4_fc_wait_committing_inode(inode); - goto restart; + /* + * Since ext4_fc_del is called from ext4_evict_inode while having a + * handle open, there is no need for us to wait here even if a fast + * commit is going on. That is because, if this inode is being + * committed, ext4_mark_inode_dirty would have waited for inode commit + * operation to finish before we come here. So, by the time we come + * here, inode's EXT4_STATE_FC_COMMITTING would have been cleared. So, + * we shouldn't see EXT4_STATE_FC_COMMITTING to be set on this inode + * here. + * + * We may come here without any handles open in the "no_delete" case of + * ext4_evict_inode as well. However, if that happens, we first mark the + * file system as fast commit ineligible anyway. So, even in that case, + * it is okay to remove the inode from the fc list. + */ + WARN_ON(ext4_test_inode_state(inode, EXT4_STATE_FC_COMMITTING) + && !ext4_test_mount_flag(inode->i_sb, EXT4_MF_FC_INELIGIBLE)); + while (ext4_test_inode_state(inode, EXT4_STATE_FC_FLUSHING_DATA)) { +#if (BITS_PER_LONG < 64) + DEFINE_WAIT_BIT(wait, &ei->i_state_flags, + EXT4_STATE_FC_FLUSHING_DATA); + wq = bit_waitqueue(&ei->i_state_flags, + EXT4_STATE_FC_FLUSHING_DATA); +#else + DEFINE_WAIT_BIT(wait, &ei->i_flags, + EXT4_STATE_FC_FLUSHING_DATA); + wq = bit_waitqueue(&ei->i_flags, + EXT4_STATE_FC_FLUSHING_DATA); +#endif + prepare_to_wait(wq, &wait.wq_entry, TASK_UNINTERRUPTIBLE); + if (ext4_test_inode_state(inode, EXT4_STATE_FC_FLUSHING_DATA)) { + spin_unlock(&sbi->s_fc_lock); + schedule(); + spin_lock(&sbi->s_fc_lock); + } + finish_wait(wq, &wait.wq_entry); } - - if (!list_empty(&ei->i_fc_list)) - list_del_init(&ei->i_fc_list); + list_del_init(&ei->i_fc_list); /* * Since this inode is getting removed, let's also remove all FC @@ -325,8 +356,6 @@ void ext4_fc_del(struct inode *inode) release_dentry_name_snapshot(&fc_dentry->fcd_name); kmem_cache_free(ext4_fc_dentry_cachep, fc_dentry); - - return; } /* @@ -590,9 +619,6 @@ void ext4_fc_track_inode(handle_t *handle, struct inode *inode) if (ext4_test_mount_flag(inode->i_sb, EXT4_MF_FC_INELIGIBLE)) return; - if (!list_empty(&ei->i_fc_list)) - return; - /* * If we come here, we may sleep while waiting for the inode to * commit. We shouldn't be holding i_data_sem when we go to sleep since @@ -988,61 +1014,25 @@ static int ext4_fc_write_inode_data(struct inode *inode, u32 *crc) } -/* Submit data for all the fast commit inodes */ -static int ext4_fc_submit_inode_data_all(journal_t *journal) +/* Flushes data of all the inodes in the commit queue. */ +static int ext4_fc_flush_data(journal_t *journal) { struct super_block *sb = journal->j_private; struct ext4_sb_info *sbi = EXT4_SB(sb); struct ext4_inode_info *ei; int ret = 0; - spin_lock(&sbi->s_fc_lock); list_for_each_entry(ei, &sbi->s_fc_q[FC_Q_MAIN], i_fc_list) { - ext4_set_inode_state(&ei->vfs_inode, EXT4_STATE_FC_COMMITTING); - while (atomic_read(&ei->i_fc_updates)) { - DEFINE_WAIT(wait); - - prepare_to_wait(&ei->i_fc_wait, &wait, - TASK_UNINTERRUPTIBLE); - if (atomic_read(&ei->i_fc_updates)) { - spin_unlock(&sbi->s_fc_lock); - schedule(); - spin_lock(&sbi->s_fc_lock); - } - finish_wait(&ei->i_fc_wait, &wait); - } - spin_unlock(&sbi->s_fc_lock); ret = jbd2_submit_inode_data(journal, ei->jinode); if (ret) return ret; - spin_lock(&sbi->s_fc_lock); } - spin_unlock(&sbi->s_fc_lock); - - return ret; -} - -/* Wait for completion of data for all the fast commit inodes */ -static int ext4_fc_wait_inode_data_all(journal_t *journal) -{ - struct super_block *sb = journal->j_private; - struct ext4_sb_info *sbi = EXT4_SB(sb); - struct ext4_inode_info *pos, *n; - int ret = 0; - spin_lock(&sbi->s_fc_lock); - list_for_each_entry_safe(pos, n, &sbi->s_fc_q[FC_Q_MAIN], i_fc_list) { - if (!ext4_test_inode_state(&pos->vfs_inode, - EXT4_STATE_FC_COMMITTING)) - continue; - spin_unlock(&sbi->s_fc_lock); - - ret = jbd2_wait_inode_data(journal, pos->jinode); + list_for_each_entry(ei, &sbi->s_fc_q[FC_Q_MAIN], i_fc_list) { + ret = jbd2_wait_inode_data(journal, ei->jinode); if (ret) return ret; - spin_lock(&sbi->s_fc_lock); } - spin_unlock(&sbi->s_fc_lock); return 0; } @@ -1123,26 +1113,81 @@ static int ext4_fc_perform_commit(journal_t *journal) int ret = 0; u32 crc = 0; - ret = ext4_fc_submit_inode_data_all(journal); - if (ret) - return ret; + /* + * Step 1: Mark all inodes on s_fc_q[MAIN] with + * EXT4_STATE_FC_FLUSHING_DATA. This prevents these inodes from being + * freed until the data flush is over. + */ + spin_lock(&sbi->s_fc_lock); + list_for_each_entry(iter, &sbi->s_fc_q[FC_Q_MAIN], i_fc_list) { + ext4_set_inode_state(&iter->vfs_inode, + EXT4_STATE_FC_FLUSHING_DATA); + } + spin_unlock(&sbi->s_fc_lock); + + /* Step 2: Flush data for all the eligible inodes. */ + ret = ext4_fc_flush_data(journal); - ret = ext4_fc_wait_inode_data_all(journal); + /* + * Step 3: Clear EXT4_STATE_FC_FLUSHING_DATA flag, before returning + * any error from step 2. This ensures that waiters waiting on + * EXT4_STATE_FC_FLUSHING_DATA can resume. + */ + spin_lock(&sbi->s_fc_lock); + list_for_each_entry(iter, &sbi->s_fc_q[FC_Q_MAIN], i_fc_list) { + ext4_clear_inode_state(&iter->vfs_inode, + EXT4_STATE_FC_FLUSHING_DATA); +#if (BITS_PER_LONG < 64) + wake_up_bit(&iter->i_state_flags, EXT4_STATE_FC_FLUSHING_DATA); +#else + wake_up_bit(&iter->i_flags, EXT4_STATE_FC_FLUSHING_DATA); +#endif + } + + /* + * Make sure clearing of EXT4_STATE_FC_FLUSHING_DATA is visible before + * the waiter checks the bit. Pairs with implicit barrier in + * prepare_to_wait() in ext4_fc_del(). + */ + smp_mb(); + spin_unlock(&sbi->s_fc_lock); + + /* + * If we encountered error in Step 2, return it now after clearing + * EXT4_STATE_FC_FLUSHING_DATA bit. + */ if (ret) return ret; + + /* Step 4: Mark all inodes as being committed. */ + jbd2_journal_lock_updates(journal); /* - * If file system device is different from journal device, issue a cache - * flush before we start writing fast commit blocks. + * The journal is now locked. No more handles can start and all the + * previous handles are now drained. We now mark the inodes on the + * commit queue as being committed. + */ + spin_lock(&sbi->s_fc_lock); + list_for_each_entry(iter, &sbi->s_fc_q[FC_Q_MAIN], i_fc_list) { + ext4_set_inode_state(&iter->vfs_inode, + EXT4_STATE_FC_COMMITTING); + } + spin_unlock(&sbi->s_fc_lock); + jbd2_journal_unlock_updates(journal); + + /* + * Step 5: If file system device is different from journal device, + * issue a cache flush before we start writing fast commit blocks. */ if (journal->j_fs_dev != journal->j_dev) blkdev_issue_flush(journal->j_fs_dev); blk_start_plug(&plug); + /* Step 6: Write fast commit blocks to disk. */ if (sbi->s_fc_bytes == 0) { /* - * Add a head tag only if this is the first fast commit - * in this TID. + * Step 6.1: Add a head tag only if this is the first fast + * commit in this TID. */ head.fc_features = cpu_to_le32(EXT4_FC_SUPPORTED_FEATURES); head.fc_tid = cpu_to_le32( @@ -1154,6 +1199,7 @@ static int ext4_fc_perform_commit(journal_t *journal) } } + /* Step 6.2: Now write all the dentry updates. */ spin_lock(&sbi->s_fc_lock); ret = ext4_fc_commit_dentry_updates(journal, &crc); if (ret) { @@ -1161,6 +1207,7 @@ static int ext4_fc_perform_commit(journal_t *journal) goto out; } + /* Step 6.3: Now write all the changed inodes to disk. */ list_for_each_entry(iter, &sbi->s_fc_q[FC_Q_MAIN], i_fc_list) { inode = &iter->vfs_inode; if (!ext4_test_inode_state(inode, EXT4_STATE_FC_COMMITTING)) @@ -1173,10 +1220,8 @@ static int ext4_fc_perform_commit(journal_t *journal) ret = ext4_fc_write_inode(inode, &crc); if (ret) goto out; - spin_lock(&sbi->s_fc_lock); } - spin_unlock(&sbi->s_fc_lock); - + /* Step 6.4: Finally write tail tag to conclude this fast commit. */ ret = ext4_fc_write_tail(sb, crc); out: @@ -1298,7 +1343,7 @@ static void ext4_fc_cleanup(journal_t *journal, int full, tid_t tid) { struct super_block *sb = journal->j_private; struct ext4_sb_info *sbi = EXT4_SB(sb); - struct ext4_inode_info *iter, *iter_n; + struct ext4_inode_info *ei; struct ext4_fc_dentry_update *fc_dentry; if (full && sbi->s_fc_bh) @@ -1308,13 +1353,15 @@ static void ext4_fc_cleanup(journal_t *journal, int full, tid_t tid) jbd2_fc_release_bufs(journal); spin_lock(&sbi->s_fc_lock); - list_for_each_entry_safe(iter, iter_n, &sbi->s_fc_q[FC_Q_MAIN], - i_fc_list) { - list_del_init(&iter->i_fc_list); - ext4_clear_inode_state(&iter->vfs_inode, + while (!list_empty(&sbi->s_fc_q[FC_Q_MAIN])) { + ei = list_first_entry(&sbi->s_fc_q[FC_Q_MAIN], + struct ext4_inode_info, + i_fc_list); + list_del_init(&ei->i_fc_list); + ext4_clear_inode_state(&ei->vfs_inode, EXT4_STATE_FC_COMMITTING); - if (tid_geq(tid, iter->i_sync_tid)) { - ext4_fc_reset_inode(&iter->vfs_inode); + if (tid_geq(tid, ei->i_sync_tid)) { + ext4_fc_reset_inode(&ei->vfs_inode); } else if (full) { /* * We are called after a full commit, inode has been @@ -1325,15 +1372,19 @@ static void ext4_fc_cleanup(journal_t *journal, int full, tid_t tid) * time in that case (and tid doesn't increase so * tid check above isn't reliable). */ - list_add_tail(&EXT4_I(&iter->vfs_inode)->i_fc_list, + list_add_tail(&ei->i_fc_list, &sbi->s_fc_q[FC_Q_STAGING]); } - /* Make sure EXT4_STATE_FC_COMMITTING bit is clear */ + /* + * Make sure clearing of EXT4_STATE_FC_COMMITTING is + * visible before we send the wakeup. Pairs with implicit + * barrier in prepare_to_wait() in ext4_fc_track_inode(). + */ smp_mb(); #if (BITS_PER_LONG < 64) - wake_up_bit(&iter->i_state_flags, EXT4_STATE_FC_COMMITTING); + wake_up_bit(&ei->i_state_flags, EXT4_STATE_FC_COMMITTING); #else - wake_up_bit(&iter->i_flags, EXT4_STATE_FC_COMMITTING); + wake_up_bit(&ei->i_flags, EXT4_STATE_FC_COMMITTING); #endif } diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c index 743a1d763..bfaa14bb1 100644 --- a/fs/jbd2/journal.c +++ b/fs/jbd2/journal.c @@ -728,7 +728,6 @@ int jbd2_fc_begin_commit(journal_t *journal, tid_t tid) } journal->j_flags |= JBD2_FAST_COMMIT_ONGOING; write_unlock(&journal->j_state_lock); - jbd2_journal_lock_updates(journal); return 0; } @@ -742,7 +741,6 @@ static int __jbd2_fc_end_commit(journal_t *journal, tid_t tid, bool fallback) { if (journal->j_fc_cleanup_callback) journal->j_fc_cleanup_callback(journal, 0, tid); - jbd2_journal_unlock_updates(journal); write_lock(&journal->j_state_lock); journal->j_flags &= ~JBD2_FAST_COMMIT_ONGOING; if (fallback) From patchwork Thu May 8 17:59:04 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harshad Shirwadkar X-Patchwork-Id: 2083063 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=WJ1GdKR8; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=150.107.74.76; helo=mail.ozlabs.org; envelope-from=srs0=p5yx=xy=vger.kernel.org=linux-ext4+bounces-7771-patchwork-incoming=ozlabs.org@ozlabs.org; receiver=patchwork.ozlabs.org) Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4ZtfzL0GTLz1yWr for ; Fri, 9 May 2025 03:59:42 +1000 (AEST) Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Ztfzf1hj5z4xRB for ; Fri, 9 May 2025 03:59:58 +1000 (AEST) Received: by gandalf.ozlabs.org (Postfix) id 4Ztfzf1g8Bz4xQq; Fri, 9 May 2025 03:59:58 +1000 (AEST) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; arc=pass smtp.remote-ip="2604:1380:40f1:3f00::1" arc.chain=subspace.kernel.org ARC-Seal: i=2; a=rsa-sha256; d=ozlabs.org; s=201707; t=1746727198; cv=pass; b=nsSGM4NOF3mr4g1zUqHNgVAFKJocysinv1U3tAU2KJZaa0CW3ZB1XEADAUGcNsKL/82pyafvTDoPZTZumRI+kOX1uc46qtpc18QTso2VBLBU/CVepM/sLbRURbEW4Gm1m1CTBiNMlJonziY9+wvFfp/Lokwn4g3/gTtBjza4uu5rEmfTmdj8wQt6E27FoWBttSoauOlf2EiISjM7ZLJwtnYENAF2QB1Oyra9NuLILqjVUTT03bcbIT3/i7dNjQNMqf2f72rLEKP4+VM4c/pdD3W0jdJiMWxXDIvRSjtD/qmaJQ0NCi1STpPn0cG5M7Maf+01dwEM1khFf3tBkgaSrA== ARC-Message-Signature: i=2; a=rsa-sha256; d=ozlabs.org; s=201707; t=1746727198; c=relaxed/relaxed; bh=ZOvVBJYrnMiNzk7zUHBiRwItkfw8ANCuqE/C1Bp2rf4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=od9Eads7FawFY/mG4cq+n4Y3ghfr3b4Mnhy1OUCdNrPs/bG8A7HP+o3T1+14g9WD1j4lpTp2BvIFFQ6NOq8cHGj2rT3kQIZk5S16TEb365PaBJ6N6CsOym6dbHLyL0qbCBo/VWwLYQz7NB3O0DwWsHzZofrh/C8l5CeqIKVP9ht6ZkDqIJtPTBYuqfZrYXG+Jla11lFM65qmULvTEcJP0XsPUWhuV6eEMHDQHLU7ao4QJXHfC2fLkM60ZMyuP5s3OVAciSZdtBI5PJc+QsJQoGzXtqtiMJA900bogj3PtuFyjo2HMlkj3UPQ+G87Fpsee/rHKsQAfAVaLm9I5oQVRg== ARC-Authentication-Results: i=2; gandalf.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=vger.kernel.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=WJ1GdKR8; dkim-atps=neutral Authentication-Results: gandalf.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: gandalf.ozlabs.org; spf=pass smtp.mailfrom=vger.kernel.org Authentication-Results: gandalf.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=WJ1GdKR8; dkim-atps=neutral Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org [IPv6:2604:1380:40f1:3f00::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by gandalf.ozlabs.org (Postfix) with ESMTPS id 4Ztfzb2ScRz4xRB for ; Fri, 9 May 2025 03:59:55 +1000 (AEST) Received: from smtp.subspace.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id CF2417BAA1E for ; Thu, 8 May 2025 17:58:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DC644286D66; Thu, 8 May 2025 17:59:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="WJ1GdKR8" X-Original-To: linux-ext4@vger.kernel.org Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2DEE4286D56 for ; Thu, 8 May 2025 17:59:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746727177; cv=none; b=LiaWkule5h392mW8+wr4hEkjztvT7+6XlYnv7toUDnQI2O0JY2WAvyTPyZK+iqu4Fwg19ELLLPOPGvnwcmODjVH9qeV5bANoFLJmT//MTnCFnnI0OxICTjxfCth+ShM1u7Dzz1j9WZHAjZcUc3yENpOSiuVpX4RtgOrZSe7YLiY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746727177; c=relaxed/simple; bh=x0YJJ08B0/DY3wqb9g0trv1BYi9N2GTWQu1oJb0rgUo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BlkFohIf4d/YQLV8yDK6+lxSLMUgO9fhqgWAHzqmD7na5wqc7tGFOfsz821QUFQJaLec/LjFDerlUT4FUstLYuRfrnvBtfECIqtMUSDXWlbZK/eeAZuUz8pBL/dEtPk26+0uBefBiV2FNQTqmKq3Q8gIDANPWrISaXqhrjfOk3o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=WJ1GdKR8; arc=none smtp.client-ip=209.85.215.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pg1-f170.google.com with SMTP id 41be03b00d2f7-b170c99aa49so875156a12.1 for ; Thu, 08 May 2025 10:59:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1746727175; x=1747331975; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ZOvVBJYrnMiNzk7zUHBiRwItkfw8ANCuqE/C1Bp2rf4=; b=WJ1GdKR8tf31iB8qVd9kLDEdxDxRxhzHbcrk9rQmthdMnZxGJqT/N6lyEoqAalQjWz 15RRx/v4WWc0KeCwxvjXIc883FqnXRLNHHalhd8OF4t61/FoXTYz0JUYFd/wCwj8WMTb QLtkL9MwA10OsLwFOw/q2R5xOcsa2Rr63mBAUo2WJXqUpMUsOGjdvpXar+VAb3wX27c7 18p5+zyXUf5+hKKyX/nO6gYv8t/OzVzKai4xqVOJRZOKE7jOiYKXN4zLvt0KjsUpqDcD R6swItT2Vzw9xmttEOzDGK1XS5xziK8da4u9IiSljS6fweuXt9utODkSeFH5GDn1I4bu 3N6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746727175; x=1747331975; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZOvVBJYrnMiNzk7zUHBiRwItkfw8ANCuqE/C1Bp2rf4=; b=OGCFB4j1/6RQFYs1wF6DR70B74S5GeYIp0stgzaylR+bwRo/UV5kwCCoTRJn8enDW4 X2mmfBKAD9h2H+E2+1DolYkn8dSrM/QAxNfWhIkPI5lzSdm19sZGRflUlZTxKUCltHpW 2aUjTbSAPVaGdtTR7VgeWas6cSgyKSz6ToYxXF5VolkwuiYJiFqODytT8RrF1/7RGajD jtC0cEt0rDyEm7scl+k1k/osl5zXvtTWVw+fXA7ygxZmlr+O+zDyaS4m4Ncsa88c5qgF M7CmP8y47JNLEHtQPTqjV+yuadU2z4SoBrQik42EvI/Al6KatugKvpWCuMEzF8AJgdCZ F6lQ== X-Gm-Message-State: AOJu0YxJPEVBg0qDdY23CvJJtpLR3lrCnOsymNwGaSv0rMnb2ihCYqF+ m1JSF+Zi/k/hSvE0YdHNRYh0OhvFpKCsXuw6u9hOPLpLUWDWWY/kTc96RKYwwFI= X-Gm-Gg: ASbGncsUUP16OYzwmdOGdv5jLrDm4Pt4jRhOXZTUWQsBRE3TRcjWc7vlOwPQf+OUYZh Ge343I0t7TIcStv6CdmlE2/hPIz0553sVKFCYS9ZdKk99LYwcy6ZLUUiGE20Q8/miwWsq2UStXn /A4WSnxPYMxA+EPUnGIMsnEZ7ReO75DBID2BlrFn1wzRSY9vBF2X7CJVfTfBdQG5sfr9zFXJufe iOxkMNQo79ETNxEFjUQ9aNXh9Laozazi9dgJT8WaTzMdVhFq5G9KZkp5IvO7SYXcUZ1xn7N2Mew BYKX0UOyyn9oAk9gO4pwFTY078G2kCwQAtwTvn02ZvbHqISsZg+pbqN480TjiqLsatnXXnxn+tZ Kie67wl4vpX+9LoU94ae19PEEjjHSsEZkqhHP X-Google-Smtp-Source: AGHT+IE03OLAqxYdyFHhVN8TaXGRy1rMHBRzYj3T8YGBirkECS/YV6dVgYo4eez55Bbgr/L1JtBbTA== X-Received: by 2002:a17:903:988:b0:220:c63b:d93c with SMTP id d9443c01a7336-22fc91aca1emr4166395ad.44.1746727175121; Thu, 08 May 2025 10:59:35 -0700 (PDT) Received: from harshads.c.googlers.com.com (156.242.82.34.bc.googleusercontent.com. [34.82.242.156]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-22fc828939asm2153535ad.164.2025.05.08.10.59.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 May 2025 10:59:34 -0700 (PDT) From: Harshad Shirwadkar To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, jack@suse.cz, harshads@google.com, Harshad Shirwadkar Subject: [PATCH v9 5/9] ext4: drop i_fc_updates from inode fc info Date: Thu, 8 May 2025 17:59:04 +0000 Message-ID: <20250508175908.1004880-6-harshadshirwadkar@gmail.com> X-Mailer: git-send-email 2.49.0.1045.g170613ef41-goog In-Reply-To: <20250508175908.1004880-1-harshadshirwadkar@gmail.com> References: <20250508175908.1004880-1-harshadshirwadkar@gmail.com> Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=0.8 required=5.0 tests=ARC_SIGNED,ARC_VALID, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DMARC_PASS, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=disabled version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on gandalf.ozlabs.org The new logic introduced in this series does not require tracking number of active handles open on an inode. So, drop it. Signed-off-by: Harshad Shirwadkar Reviewed-by: Jan Kara --- fs/ext4/ext4.h | 5 ---- fs/ext4/fast_commit.c | 68 ------------------------------------------- 2 files changed, 73 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 493d9ac7a..0cb34a06e 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -1061,9 +1061,6 @@ struct ext4_inode_info { /* End of lblk range that needs to be committed in this fast commit */ ext4_lblk_t i_fc_lblk_len; - /* Number of ongoing updates on this inode */ - atomic_t i_fc_updates; - spinlock_t i_raw_lock; /* protects updates to the raw inode */ /* Fast commit wait queue for this inode */ @@ -2926,8 +2923,6 @@ void __ext4_fc_track_create(handle_t *handle, struct inode *inode, void ext4_fc_track_create(handle_t *handle, struct dentry *dentry); void ext4_fc_track_inode(handle_t *handle, struct inode *inode); void ext4_fc_mark_ineligible(struct super_block *sb, int reason, handle_t *handle); -void ext4_fc_start_update(struct inode *inode); -void ext4_fc_stop_update(struct inode *inode); void ext4_fc_del(struct inode *inode); bool ext4_fc_replay_check_excluded(struct super_block *sb, ext4_fsblk_t block); void ext4_fc_replay_cleanup(struct super_block *sb); diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c index a2cb4d965..f2e8a5f22 100644 --- a/fs/ext4/fast_commit.c +++ b/fs/ext4/fast_commit.c @@ -202,32 +202,6 @@ void ext4_fc_init_inode(struct inode *inode) INIT_LIST_HEAD(&ei->i_fc_list); INIT_LIST_HEAD(&ei->i_fc_dilist); init_waitqueue_head(&ei->i_fc_wait); - atomic_set(&ei->i_fc_updates, 0); -} - -/* This function must be called with sbi->s_fc_lock held. */ -static void ext4_fc_wait_committing_inode(struct inode *inode) -__releases(&EXT4_SB(inode->i_sb)->s_fc_lock) -{ - wait_queue_head_t *wq; - struct ext4_inode_info *ei = EXT4_I(inode); - -#if (BITS_PER_LONG < 64) - DEFINE_WAIT_BIT(wait, &ei->i_state_flags, - EXT4_STATE_FC_COMMITTING); - wq = bit_waitqueue(&ei->i_state_flags, - EXT4_STATE_FC_COMMITTING); -#else - DEFINE_WAIT_BIT(wait, &ei->i_flags, - EXT4_STATE_FC_COMMITTING); - wq = bit_waitqueue(&ei->i_flags, - EXT4_STATE_FC_COMMITTING); -#endif - lockdep_assert_held(&EXT4_SB(inode->i_sb)->s_fc_lock); - prepare_to_wait(wq, &wait.wq_entry, TASK_UNINTERRUPTIBLE); - spin_unlock(&EXT4_SB(inode->i_sb)->s_fc_lock); - schedule(); - finish_wait(wq, &wait.wq_entry); } static bool ext4_fc_disabled(struct super_block *sb) @@ -236,48 +210,6 @@ static bool ext4_fc_disabled(struct super_block *sb) (EXT4_SB(sb)->s_mount_state & EXT4_FC_REPLAY)); } -/* - * Inform Ext4's fast about start of an inode update - * - * This function is called by the high level call VFS callbacks before - * performing any inode update. This function blocks if there's an ongoing - * fast commit on the inode in question. - */ -void ext4_fc_start_update(struct inode *inode) -{ - struct ext4_inode_info *ei = EXT4_I(inode); - - if (ext4_fc_disabled(inode->i_sb)) - return; - -restart: - spin_lock(&EXT4_SB(inode->i_sb)->s_fc_lock); - if (list_empty(&ei->i_fc_list)) - goto out; - - if (ext4_test_inode_state(inode, EXT4_STATE_FC_COMMITTING)) { - ext4_fc_wait_committing_inode(inode); - goto restart; - } -out: - atomic_inc(&ei->i_fc_updates); - spin_unlock(&EXT4_SB(inode->i_sb)->s_fc_lock); -} - -/* - * Stop inode update and wake up waiting fast commits if any. - */ -void ext4_fc_stop_update(struct inode *inode) -{ - struct ext4_inode_info *ei = EXT4_I(inode); - - if (ext4_fc_disabled(inode->i_sb)) - return; - - if (atomic_dec_and_test(&ei->i_fc_updates)) - wake_up_all(&ei->i_fc_wait); -} - /* * Remove inode from fast commit list. If the inode is being committed * we wait until inode commit is done. From patchwork Thu May 8 17:59:05 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harshad Shirwadkar X-Patchwork-Id: 2083062 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=Bbw6lYfg; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=2404:9400:2221:ea00::3; helo=mail.ozlabs.org; envelope-from=srs0=rjpb=xy=vger.kernel.org=linux-ext4+bounces-7773-patchwork-incoming=ozlabs.org@ozlabs.org; receiver=patchwork.ozlabs.org) Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4ZtfzK6K3Qz1xnT for ; Fri, 9 May 2025 03:59:41 +1000 (AEST) Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Ztfzf0ZwMz4xQq for ; Fri, 9 May 2025 03:59:58 +1000 (AEST) Received: by gandalf.ozlabs.org (Postfix) id 4Ztfzf0XCxz4xRj; Fri, 9 May 2025 03:59:58 +1000 (AEST) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; arc=pass smtp.remote-ip="2604:1380:45e3:2400::1" arc.chain=subspace.kernel.org ARC-Seal: i=2; a=rsa-sha256; d=ozlabs.org; s=201707; t=1746727198; cv=pass; b=fL15OX6zoHcNJxEx4HUHc61w1dMc5pI3g4JZB8/RoMrR7qWD24I9l0Ijr4EqQ+DPX8GhGa7Y1GHSaTqrI29cvnnc7yW8KKM4x1hTyAOrss1KIqFoCxc5SGyq/3zr5ZBKYHMUuB3vDFEtwgHTse3UQC/7UWrBJRT/tGEW/xMXb+u1CziqE4SuhIHkbODVA7KesLLCBXD5UIVcyuJEIQu2t/TXhTZaylK6hG7h6LWF/cEDqEVquLUQuSMMvlqdGJj3MRi3oj02pg8ke7Drm2wmit8zBUvAZPJgFKZTezWXMJH3e43AFH5yszDv6Gx1RAg7FKAhkvqEdinANaYjTeXJWA== ARC-Message-Signature: i=2; a=rsa-sha256; d=ozlabs.org; s=201707; t=1746727198; c=relaxed/relaxed; bh=FN7NgPynjQ2ZAvz3OmbqzXIzdZx7B5ob1vAJEalfJdo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=az/VEXJ7WkWdUFurrztNjjsYzVWxNC6JqoTDH7wsYXnMSAMV+6E43Jmqm+bl90Ut98yonyj5u9hLqq/dEdIRR6dGMK5cxjT5t312O0GKS2SJrusrpwSeqixR44/nyiWp8uGhhLBkVqYcb91NhSmjAwuee4rTdDH0JqQnrcznw4PAtV5TmMdgHQKu7LdIy/+VlpTHiopxvn2ZK7SYPVWbuxWpdploEOj+8O3u1nIN82bLupC42eFZk/Yiu/AW6imKQe6oVQXIVY+W67KWrzNCS1P+foYEaCiFwT4Qg56e2+eYbb9Ridg5NrUxEe7pM5wNBgJoSNUFWlcxcK30UVT/oQ== ARC-Authentication-Results: i=2; gandalf.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=vger.kernel.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=Bbw6lYfg; dkim-atps=neutral Authentication-Results: gandalf.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: gandalf.ozlabs.org; spf=pass smtp.mailfrom=vger.kernel.org Authentication-Results: gandalf.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=Bbw6lYfg; dkim-atps=neutral Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org [IPv6:2604:1380:45e3:2400::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by gandalf.ozlabs.org (Postfix) with ESMTPS id 4ZtfzZ68lnz4xQq for ; Fri, 9 May 2025 03:59:54 +1000 (AEST) Received: from smtp.subspace.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id BB66D3ADA26 for ; Thu, 8 May 2025 17:59:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 81D0F286D57; Thu, 8 May 2025 17:59:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Bbw6lYfg" X-Original-To: linux-ext4@vger.kernel.org Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C23CC286D5F for ; Thu, 8 May 2025 17:59:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746727178; cv=none; b=JU0vr1WQtFgrZQuRfUY+YRng8evM0Yv48GrOWlAnSWOq4pXXI1mWMuWFjvOahf4rZCmWvWHOSwI2nYDdy2D2sjGIJgdm+OrXdESzEWamRhG6LX0VU2Y/hl/osXVwaN9cbZHmiz4OgxvVM8IQpWA5vnK5k4/TcF3TIXtih12DAno= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746727178; c=relaxed/simple; bh=wPm2PnFaFqJdG+tou6tHu0ps+um9SO/2Dq48HVSDnGw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Rn2YXI+IEZUsee2kcA14qVWm4klm3z+WE0JxwIVskcaX6iZM7xUt7C/yDkaAAff6rw1KRLChLzjEitC50d7CVL8iq+uN2jPk1gLedjX5nQlI9RjB/DQXP03h2pMp36PQ7gt1GP5ilEHVp8f+yiY+1ZkfWLPAnLRX1Ty0J0nlrlI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Bbw6lYfg; arc=none smtp.client-ip=209.85.210.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-736a7e126c7so1339964b3a.3 for ; Thu, 08 May 2025 10:59:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1746727176; x=1747331976; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FN7NgPynjQ2ZAvz3OmbqzXIzdZx7B5ob1vAJEalfJdo=; b=Bbw6lYfgkbKozeBUCvVadAKjXOH0qW9k8cC85RTU21myxJbzktDLvprTpcTigwowxi +EMiGPneYVhiXS2yUYqBLk/79YZ4hijIBD/AcNwoNjjmGDZqvDdVHcgvZeKyyrj+V/f/ AtLTwt31iv3sonJZHSPLUBKgdZ8rIKywZaGpTEr8f+lzcN+C0JYtjDPNawXbVnlGRbld UCUa2Q0bFK3G2aGiMQEj2BPLsSCr9BBmt5a40qx5m9R1vXIrQNHeHVJyvL8DaCnJorWo PocbytPadJwjpHRNPbeHH8hvZzrSrFRxIDsqxGDy1ZxHHOeJS8k3fWjdcSb56/IDYAbb vQmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746727176; x=1747331976; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FN7NgPynjQ2ZAvz3OmbqzXIzdZx7B5ob1vAJEalfJdo=; b=XDkhkMd8ku+HfUzlSghU2GUL0bPmlu82iZPjwZ9Obhdezh4pz7r3I+1Ay8oYVOOrP5 e5fyCuXD/EIhpaXpb/5kNH2f4KrXG1+otkPvNoqKyrsEXeteDas/eWnXHGcWwtzyumOS JYFhkRwyRCbwUGy33/za71cBK/qxAelgF6fw72sNA3LeXDldfH+HV6k1aFFnX1r+F67E FCkyhaQ/6nz3qrVXT/9ZvWua9Kbh/KvmpFhOFq9KIs9olkSie1Q0CL/D5/6YKtiEeGkm ucaTwNteU/wvu1u18dwT1mTgXv2tfzB0tc6MUdQXBS3ER3wOh1szClaRKmBZJ1rdjOc3 6kIQ== X-Gm-Message-State: AOJu0YxxNMqaajlowvLwkHHtwUwT3++nAyIXlG9GWyO1ZJM33cgdaXTK Mog6ir7g4hnPGGJdQbs0/tjtmeRDYfOmh5xO6BaIwHoTzy4nFIorp1oW9rBQv/4= X-Gm-Gg: ASbGnctflFTAdthThcq3fLyYTlIz24nt6KS6lMPknl7k8zzuc+mreNGGdQBasUggRn5 4h+1GhZnLDKb5cOSUdm2sOQ3elPbsw7H+Ix2sWA6xxDIfyjkFx/1bx0jExcbZTlNfZalZV2JMoG 7nVWYIGKmCv4EqPpItuHMDs8PTS9PjDwnlyRJlrs4/LBJsrdZw+PgFCd2iB6RThpDQJrS0ARCwu fnt/TtJpa89dyPNkwKxjLZQrMhgDf8QHwOGGrLweRuQDnQ83/dCbY2oHy4d+ShH697OQx5jGQtg iErlsPjp384eNPvXuRC2GnvA5I119XJ1j8aUa+NsfSVjwsJChlMpSU/QkjVfj2Xs0OZMUFE7Xsc Aga7t+37bbHLXp0B2mltW0aLOXXnXMogigjB8gZO4rwVyAJc= X-Google-Smtp-Source: AGHT+IFO8fgUYaNrBt+19U8pJ21LpsMDzZm2fTdI/ktB0rbRIa6Cj3au11ga075UbbxsDXg3Sc+mkA== X-Received: by 2002:a17:903:2351:b0:223:2cae:4a96 with SMTP id d9443c01a7336-22fc918c11emr3575515ad.42.1746727175587; Thu, 08 May 2025 10:59:35 -0700 (PDT) Received: from harshads.c.googlers.com.com (156.242.82.34.bc.googleusercontent.com. [34.82.242.156]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-22fc828939asm2153535ad.164.2025.05.08.10.59.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 May 2025 10:59:35 -0700 (PDT) From: Harshad Shirwadkar To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, jack@suse.cz, harshads@google.com, Harshad Shirwadkar Subject: [PATCH v9 6/9] ext4: update code documentation Date: Thu, 8 May 2025 17:59:05 +0000 Message-ID: <20250508175908.1004880-7-harshadshirwadkar@gmail.com> X-Mailer: git-send-email 2.49.0.1045.g170613ef41-goog In-Reply-To: <20250508175908.1004880-1-harshadshirwadkar@gmail.com> References: <20250508175908.1004880-1-harshadshirwadkar@gmail.com> Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=0.8 required=5.0 tests=ARC_SIGNED,ARC_VALID, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DMARC_PASS, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=disabled version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on gandalf.ozlabs.org This patch updates code documentation to reflect the commit path changes made in this series. Signed-off-by: Harshad Shirwadkar Reviewed-by: Jan Kara code docs --- fs/ext4/fast_commit.c | 48 ++++++++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c index f2e8a5f22..06dda3932 100644 --- a/fs/ext4/fast_commit.c +++ b/fs/ext4/fast_commit.c @@ -50,19 +50,27 @@ * that need to be committed during a fast commit in another in memory queue of * inodes. During the commit operation, we commit in the following order: * - * [1] Lock inodes for any further data updates by setting COMMITTING state - * [2] Submit data buffers of all the inodes - * [3] Wait for [2] to complete - * [4] Commit all the directory entry updates in the fast commit space - * [5] Commit all the changed inode structures - * [6] Write tail tag (this tag ensures the atomicity, please read the following + * [1] Prepare all the inodes to write out their data by setting + * "EXT4_STATE_FC_FLUSHING_DATA". This ensures that inode cannot be + * deleted while it is being flushed. + * [2] Flush data buffers to disk and clear "EXT4_STATE_FC_FLUSHING_DATA" + * state. + * [3] Lock the journal by calling jbd2_journal_lock_updates. This ensures that + * all the exsiting handles finish and no new handles can start. + * [4] Mark all the fast commit eligible inodes as undergoing fast commit + * by setting "EXT4_STATE_FC_COMMITTING" state. + * [5] Unlock the journal by calling jbd2_journal_unlock_updates. This allows + * starting of new handles. If new handles try to start an update on + * any of the inodes that are being committed, ext4_fc_track_inode() + * will block until those inodes have finished the fast commit. + * [6] Commit all the directory entry updates in the fast commit space. + * [7] Commit all the changed inodes in the fast commit space and clear + * "EXT4_STATE_FC_COMMITTING" for these inodes. + * [8] Write tail tag (this tag ensures the atomicity, please read the following * section for more details). - * [7] Wait for [4], [5] and [6] to complete. * - * All the inode updates must call ext4_fc_start_update() before starting an - * update. If such an ongoing update is present, fast commit waits for it to - * complete. The completion of such an update is marked by - * ext4_fc_stop_update(). + * All the inode updates must be enclosed within jbd2_jounrnal_start() + * and jbd2_journal_stop() similar to JBD2 journaling. * * Fast Commit Ineligibility * ------------------------- @@ -143,6 +151,13 @@ * similarly. Thus, by converting a non-idempotent procedure into a series of * idempotent outcomes, fast commits ensured idempotence during the replay. * + * Locking + * ------- + * sbi->s_fc_lock protects the fast commit inodes queue and the fast commit + * dentry queue. ei->i_fc_lock protects the fast commit related info in a given + * inode. Most of the code avoids acquiring both the locks, but if one must do + * that then sbi->s_fc_lock must be acquired before ei->i_fc_lock. + * * TODOs * ----- * @@ -157,13 +172,12 @@ * fast commit recovery even if that area is invalidated by later full * commits. * - * 1) Fast commit's commit path locks the entire file system during fast - * commit. This has significant performance penalty. Instead of that, we - * should use ext4_fc_start/stop_update functions to start inode level - * updates from ext4_journal_start/stop. Once we do that we can drop file - * system locking during commit path. + * 1) Handle more ineligible cases. * - * 2) Handle more ineligible cases. + * 2) Change ext4_fc_commit() to lookup logical to physical mapping using extent + * status tree. This would get rid of the need to call ext4_fc_track_inode() + * before acquiring i_data_sem. To do that we would need to ensure that + * modified extents from the extent status tree are not evicted from memory. */ #include From patchwork Thu May 8 17:59:06 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harshad Shirwadkar X-Patchwork-Id: 2083067 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=BFNse3V9; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=150.107.74.76; helo=mail.ozlabs.org; envelope-from=srs0=59sb=xy=vger.kernel.org=linux-ext4+bounces-7775-patchwork-incoming=ozlabs.org@ozlabs.org; receiver=patchwork.ozlabs.org) Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Ztfzg3qrVz1yQ7 for ; Fri, 9 May 2025 03:59:59 +1000 (AEST) Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Ztfzz5Dpmz4xRj for ; Fri, 9 May 2025 04:00:15 +1000 (AEST) Received: by gandalf.ozlabs.org (Postfix) id 4Ztfzz5BXmz4x89; Fri, 9 May 2025 04:00:15 +1000 (AEST) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; arc=pass smtp.remote-ip=147.75.199.223 arc.chain=subspace.kernel.org ARC-Seal: i=2; a=rsa-sha256; d=ozlabs.org; s=201707; t=1746727215; cv=pass; b=Q4wni6zA/XGz6wgzo062GWoivgboM1oZxaj3KslPo4nWCGn/EBn3qg8BQkYcuoLLXrV7xQXgyaCPK6wJ7ywjUIbhTd5o8P1PArpkpoKW4HpHgoEezhpA35QcCIgXJ1UpzAFVAoY4PAuK8C8LpINvYATgjPKnE61pXw+rZzoUYS1d1qXag6fWms4EE7bk8pajsxz3dHpTcTV0NHgNuMOA0cLYozeaoD1emMZtiJR53ZDM4nqyFiA67d2Iw2LYUw/ERwIFc7N4pozTQyzIyRxBsdn6cO3Lwtry/ZkRBWA3D96fxrMmQqaRX+wom9kfDisf1LyFMCW/0VVofMIWMmmqNw== ARC-Message-Signature: i=2; a=rsa-sha256; d=ozlabs.org; s=201707; t=1746727215; c=relaxed/relaxed; bh=g2VrrzhdHZB2eILkScO2krV2YHpCCjmqI0kTB/bqnlA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fMwKdKia9L+nFsX9GcGsHKxyrwM7iUoySfXHT+X0hOt2P0Vb3UvZiVoJmNcXXdaM/hanUlz/DU6ieZXC9cH8j2IvAjOplu70je205oF1R2IWKlARKG2AszibUWP0Q7iJqg6tX1WTe20RuCzZgXOZC4eJ8dn3DxcRgmVFBD6vtZvxQR/n6nepGllseMS+ntHve/KhCFbKKKphobvFwYZB7tUM4K9ojG93O0ZJ9cKRH0qhO5NGKdImJHR8pFh2efu1cCfwH77cIi0j+7m4bU+1R3vhIJVvuRhnsSuyU0Cr7J+/fHBQhwdNSTqXcmKCg7LqKZTsnxsAhjy+/YLpJRBTPA== ARC-Authentication-Results: i=2; gandalf.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=vger.kernel.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=BFNse3V9; dkim-atps=neutral Authentication-Results: gandalf.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: gandalf.ozlabs.org; spf=pass smtp.mailfrom=vger.kernel.org Authentication-Results: gandalf.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=BFNse3V9; dkim-atps=neutral Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org [147.75.199.223]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by gandalf.ozlabs.org (Postfix) with ESMTPS id 4Ztfzw1y9sz4xRj for ; Fri, 9 May 2025 04:00:12 +1000 (AEST) Received: from smtp.subspace.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 034B94C0D62 for ; Thu, 8 May 2025 18:00:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2AC832874EC; Thu, 8 May 2025 17:59:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BFNse3V9" X-Original-To: linux-ext4@vger.kernel.org Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6DAB9286D40 for ; Thu, 8 May 2025 17:59:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746727179; cv=none; b=Umwrj5riyjpMHdILNrYkmANQOlHZa++LxqzY3AwmGMYEXowY6CyPCRztbb0U9W0csC0tK6pm5rBqW4C3hbrps2MAC57AHVRz3UW5wk6/FZxk764NmNCdO8CqMUmG4mV600JZg2gyCkcb+cC12AJuPy2w9b+juUpTHcNRXf+lPsw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746727179; c=relaxed/simple; bh=iaKZh34dqAf/iJCU/8vqAQyADLdr7vSyN18P90kqMOw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=W6gyNtzTB4qZLmQqIV+G9XTDTrzfdwFdTohl06nDQ2nxlyaFTEVrmYrSl/lO5HjM0+NMR8YftV3FnRJiDhCsaf9RiFh/l67DWznWknxMQrWD0UNVOjZtRDqv+e1hVJtmv3GuZkyZ0HJZltDS+v5Xjyqhq6oju0HD5L1zkFPJdNk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=BFNse3V9; arc=none smtp.client-ip=209.85.214.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-227b828de00so14068185ad.1 for ; Thu, 08 May 2025 10:59:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1746727176; x=1747331976; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=g2VrrzhdHZB2eILkScO2krV2YHpCCjmqI0kTB/bqnlA=; b=BFNse3V9jr8V8Qp0lKKb9+IiUbGflcqhEKRCBpI8GQISBR0fkzjvsjma+HsQhJGpbB dX5+RheHSFQazpuiMsK11+SbT+uCyfMzjC54oruAQK6BTmll5iAp7HKv5nGXnhfB/ho+ 0ZXg7DVYCfqD+E2NttrPzwmxKxQnaeAx/dB1IHe3tfbgaK025cEEHyGnCoc+U0ipm1cA q8w1S1wWleiWvSqPHhAe6meNWrohLRxh8ddK9SYjhHtjq9uvEBC/lpbtm6wVsPtu4Ziz uTwX2ij0ktiWt3q33uA3I75OablhmYsKJcWx460TQuvZ+QXMDjFhqzePuEGFlEN0TQ1q 0rOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746727176; x=1747331976; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=g2VrrzhdHZB2eILkScO2krV2YHpCCjmqI0kTB/bqnlA=; b=IuITPkOgka9CTh7iw1xMHCGyVPzkqb8TFZ5gilSNlbC7M5qrCoVfugldnhnsKCMh/q M+ES/euHCdyTqG1UaaKUY+8/y9KRYpX8xOF8f3QE+9dOAC6mMryr2qhFOi4jUA16lWpR 3mlneRF1Gd9BJRJsOgL/wV6+2uLFCu8NjmkSxP2Qpz3bLsG3y9GaU5Oza9fKG3WBLzYC JDQJGnEOXrR3Y4tV9UaQRh2w/DHJ/7ATeYC7mMKFeZap1+DvDtS4aRjMQI6aCyJmX1iQ dWZ3syrQgmMK30/7of8ttS7uLi4MrY3BLSrTPlOgAjUDLXiF54zkiaQ95Yoa3rFXozmM l7zg== X-Gm-Message-State: AOJu0YzJxw+ffg0e3NX0+2RzqHVqpgP5FtVxlj1RGWm5ONe+5DezI1H8 THoyDLfpLppkKq8irtBLFEqxvQDM5oCNvxS4t7YCUmNuvftZ4kUqhrS6JxCDCPw= X-Gm-Gg: ASbGnct8Oixu/J7KdLTBhLZNqLT2olBg14zWRaxjLBQ8PCAnPbF8+T8eYYrEKYkZG1K Tul/M/k4lLpWK4TXk3pLQAsXGHubqxJhy0ixCDpVGdm6QYuL9V4f53TPVLGtDt2WYD/29HQmCGx GgvbghVtyskFeUow5/Tc00wKN2srnCtMKAN7DpfKiYFH59Y/cKJSnmHrwSJU52rQhrsxnM1FTa6 UHzsZOjz32o4IVRuqiCY/ZnG8lWcQk6JmFl8ElppHO63kgLtMxPfBCQSjA/s0i8KC0z4CFZU1Qp AMFiPohpU9ab53Iwtm4MCnd+cQ6ycXP8fi1JG/qNr+elxcqqptATLW2hJY1c7nhDoOpg+i4QtbG aoWc6XZ4yW1TWYm0ucjcQBbxO+L1b4uIvy16L X-Google-Smtp-Source: AGHT+IGED7PmwUnJIj1Ecwo4Ov2DGAeEQHMP6eo73j521u/YvmQGTZSoFVw/QJW1R81jnKophjCTcA== X-Received: by 2002:a17:903:194b:b0:223:fb3a:8647 with SMTP id d9443c01a7336-22fc918fe99mr3815015ad.41.1746727176044; Thu, 08 May 2025 10:59:36 -0700 (PDT) Received: from harshads.c.googlers.com.com (156.242.82.34.bc.googleusercontent.com. [34.82.242.156]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-22fc828939asm2153535ad.164.2025.05.08.10.59.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 May 2025 10:59:35 -0700 (PDT) From: Harshad Shirwadkar To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, jack@suse.cz, harshads@google.com, Harshad Shirwadkar Subject: [PATCH v9 7/9] ext4: temporarily elevate commit thread priority Date: Thu, 8 May 2025 17:59:06 +0000 Message-ID: <20250508175908.1004880-8-harshadshirwadkar@gmail.com> X-Mailer: git-send-email 2.49.0.1045.g170613ef41-goog In-Reply-To: <20250508175908.1004880-1-harshadshirwadkar@gmail.com> References: <20250508175908.1004880-1-harshadshirwadkar@gmail.com> Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-1.5 required=5.0 tests=ARC_SIGNED,ARC_VALID, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DMARC_PASS, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=disabled version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on gandalf.ozlabs.org Unlike JBD2 based full commits, there is no dedicated journal thread for fast commits. Thus to reduce scheduling delays between IO submission and completion, temporarily elevate the committer thread's priority to match the configured priority of the JBD2 journal thread. Signed-off-by: Harshad Shirwadkar Reviewed-by: Jan Kara --- fs/ext4/ext4.h | 4 +++- fs/ext4/fast_commit.c | 13 +++++++++++++ fs/ext4/super.c | 5 ++--- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 0cb34a06e..3987c5bf2 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -2296,10 +2296,12 @@ static inline int ext4_emergency_state(struct super_block *sb) #define EXT4_DEFM_NODELALLOC 0x0800 /* - * Default journal batch times + * Default journal batch times and ioprio. */ #define EXT4_DEF_MIN_BATCH_TIME 0 #define EXT4_DEF_MAX_BATCH_TIME 15000 /* 15ms */ +#define EXT4_DEF_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3)) + /* * Default values for superblock update diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c index 06dda3932..5f6a8ec24 100644 --- a/fs/ext4/fast_commit.c +++ b/fs/ext4/fast_commit.c @@ -1216,6 +1216,7 @@ int ext4_fc_commit(journal_t *journal, tid_t commit_tid) int subtid = atomic_read(&sbi->s_fc_subtid); int status = EXT4_FC_STATUS_OK, fc_bufs_before = 0; ktime_t start_time, commit_time; + int old_ioprio, journal_ioprio; if (!test_opt2(sb, JOURNAL_FAST_COMMIT)) return jbd2_complete_transaction(journal, commit_tid); @@ -1223,6 +1224,7 @@ int ext4_fc_commit(journal_t *journal, tid_t commit_tid) trace_ext4_fc_commit_start(sb, commit_tid); start_time = ktime_get(); + old_ioprio = get_current_ioprio(); restart_fc: ret = jbd2_fc_begin_commit(journal, commit_tid); @@ -1253,6 +1255,15 @@ int ext4_fc_commit(journal_t *journal, tid_t commit_tid) goto fallback; } + /* + * Now that we know that this thread is going to do a fast commit, + * elevate the priority to match that of the journal thread. + */ + if (journal->j_task->io_context) + journal_ioprio = sbi->s_journal->j_task->io_context->ioprio; + else + journal_ioprio = EXT4_DEF_JOURNAL_IOPRIO; + set_task_ioprio(current, journal_ioprio); fc_bufs_before = (sbi->s_fc_bytes + bsize - 1) / bsize; ret = ext4_fc_perform_commit(journal); if (ret < 0) { @@ -1267,6 +1278,7 @@ int ext4_fc_commit(journal_t *journal, tid_t commit_tid) } atomic_inc(&sbi->s_fc_subtid); ret = jbd2_fc_end_commit(journal); + set_task_ioprio(current, old_ioprio); /* * weight the commit time higher than the average time so we * don't react too strongly to vast changes in the commit time @@ -1276,6 +1288,7 @@ int ext4_fc_commit(journal_t *journal, tid_t commit_tid) return ret; fallback: + set_task_ioprio(current, old_ioprio); ret = jbd2_fc_end_commit_fallback(journal); ext4_fc_update_stats(sb, status, 0, 0, commit_tid); return ret; diff --git a/fs/ext4/super.c b/fs/ext4/super.c index ed8166fe2..356a96269 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -1809,7 +1809,6 @@ static const struct fs_parameter_spec ext4_param_specs[] = { {} }; -#define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3)) #define MOPT_SET 0x0001 #define MOPT_CLEAR 0x0002 @@ -5255,7 +5254,7 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb) /* Set defaults for the variables that will be set during parsing */ if (!(ctx->spec & EXT4_SPEC_JOURNAL_IOPRIO)) - ctx->journal_ioprio = DEFAULT_JOURNAL_IOPRIO; + ctx->journal_ioprio = EXT4_DEF_JOURNAL_IOPRIO; sbi->s_inode_readahead_blks = EXT4_DEF_INODE_READAHEAD_BLKS; sbi->s_sectors_written_start = @@ -6495,7 +6494,7 @@ static int __ext4_remount(struct fs_context *fc, struct super_block *sb) ctx->journal_ioprio = sbi->s_journal->j_task->io_context->ioprio; else - ctx->journal_ioprio = DEFAULT_JOURNAL_IOPRIO; + ctx->journal_ioprio = EXT4_DEF_JOURNAL_IOPRIO; } From patchwork Thu May 8 17:59:07 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harshad Shirwadkar X-Patchwork-Id: 2083068 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=j/fdAbfY; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=2404:9400:2221:ea00::3; helo=mail.ozlabs.org; envelope-from=srs0=imlt=xy=vger.kernel.org=linux-ext4+bounces-7776-patchwork-incoming=ozlabs.org@ozlabs.org; receiver=patchwork.ozlabs.org) Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Ztfzj5WVlz1yQ7 for ; Fri, 9 May 2025 04:00:01 +1000 (AEST) Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Ztg016vdBz4wnp for ; Fri, 9 May 2025 04:00:17 +1000 (AEST) Received: by gandalf.ozlabs.org (Postfix) id 4Ztg016rxdz4x89; Fri, 9 May 2025 04:00:17 +1000 (AEST) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; arc=pass smtp.remote-ip="2604:1380:45d1:ec00::1" arc.chain=subspace.kernel.org ARC-Seal: i=2; a=rsa-sha256; d=ozlabs.org; s=201707; t=1746727217; cv=pass; b=K9TZqwWtwop+7ulG/GRYOqr3OtP9bLqcOYjunmUR0zaJkjIfJCc9ykW9oEqWt0RXFuR6XKRGU5z/8hO5xsMyKi1GUvJGSuCNhpU/5IQZ4hGTzGa02WK7PtnE8fuH9V+YhFBaITT3QN4yL8HD1M0HZ0fLFdpC82PElrCRsQk1jsnH767FkyTxqEdPqOVed9azRWPxaC0xlGygMWIIPvcQ9AORRLCEbRyuAQaAXAo62L28oGQXNEr8hF0RmW0cVNUFqrJ32Ztb9HIeqV+QYvKM3bWO8/y7rRyTshEHGzp72Pw9VHmJ2N9qFPHyF5PCooh7/z7YI8v6SPtDX5uakaZ7bA== ARC-Message-Signature: i=2; a=rsa-sha256; d=ozlabs.org; s=201707; t=1746727217; c=relaxed/relaxed; bh=OiZ3IPvnOLD6bjPHFC0LENkY3LPdBb7EPB2/lZuSe4E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aqXMl4SWGOci7znYWNWgUKjsbf7pASbrSTkLnkbr2+1Rtwbi+b8Xs1xbt+34f1CVEm5fvb3kDuebt0mn3GiGmfgK9GkSJqWedz8bUmpmCUZ46blYwBOZZJnbUFcxCAjn9VvgK59ylmivV16Bg8XJGA3yQfsdhJ51pYjaHA8c4w9ueK5Ok/ngQ9fGrIYWrzWzjlohs/d/x4rF73KpZNOg42ukL0XJWZYuuOD89CithP4cEKRwO+shE+SaZ+VEGkSit0cpCFx4PDUHrHSnDPvZ6pqFo4NZ/+zhGXlBLW6Q4j5PobLJPsMUB7lY/0WlIBhPieTRqEyU3PZgyGMTP2jB0Q== ARC-Authentication-Results: i=2; gandalf.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=vger.kernel.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=j/fdAbfY; dkim-atps=neutral Authentication-Results: gandalf.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: gandalf.ozlabs.org; spf=pass smtp.mailfrom=vger.kernel.org Authentication-Results: gandalf.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=j/fdAbfY; dkim-atps=neutral Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org [IPv6:2604:1380:45d1:ec00::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by gandalf.ozlabs.org (Postfix) with ESMTPS id 4Ztfzy4LD5z4wnp for ; Fri, 9 May 2025 04:00:14 +1000 (AEST) Received: from smtp.subspace.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 3EC514C038A for ; Thu, 8 May 2025 18:00:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 008C62874F0; Thu, 8 May 2025 17:59:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="j/fdAbfY" X-Original-To: linux-ext4@vger.kernel.org Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2163D286D70 for ; Thu, 8 May 2025 17:59:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746727179; cv=none; b=PBz44EBu5TtkMBM+pUS1ZCWWv3SYzlNc47/dHtcU+ErDkAjURkt7COyMFG6alZd5zuxzSreMG3wH1FHSovplJRrlHyL6AxBxUKpJkBiWTtd6aXboMPEulD9xTFc+kexVm8kUuqAXpc4uHW1XWuk3lCKUwFMwqtfFYkrJh9euUzA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746727179; c=relaxed/simple; bh=/UK6aAhx8ljycKMSL2mOqg03MO6erx/hycf6kZAJS0o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=B6u9nikucH6/b1Nx2PTAfomdypPiFEorW/Ya3B6hKdxMKszYOzLM7nSxwyUcpUoBK6QAvVJNguIdbge+X2JnzfEPX6sRVbVfV4Rwednb4Aoegd0ihKBI4osAuBiUqvZ+WKqT5hgdL3XWPP+uo+xoQ8DDlCjLYR+wJzu/sXP5ddU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=j/fdAbfY; arc=none smtp.client-ip=209.85.214.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-22e70a9c6bdso22079935ad.3 for ; Thu, 08 May 2025 10:59:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1746727177; x=1747331977; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=OiZ3IPvnOLD6bjPHFC0LENkY3LPdBb7EPB2/lZuSe4E=; b=j/fdAbfYJaVS7hLHVtA4/mnEcUpvOgJRty8HCs12/dqJCZi65BYMR1we6TeSr+lYcY VLnuWgFsO5JVn5OjIuJbEcLBYiTmer8Lv8nXe3IpyJqzBy0A4hX275h8U9WyQbGt8hsL tpZX2e1pT7go+B4ctF/9MdJEDSvVea2LuEi8EwKimCCcy1Xrz6b568laAOMkIT9Sf3Gz 0NyE9POdtfkhhGiy9fovqdqpt4jRPLadp7MCn1Gaz2BxapOvwojYI4gqQahccuZ6tejZ SP3D39ylBEjYal7y2FvvsoocHd90F+OOhfWUXK6Ac5yADoAd7gvkwIpNCCoIECeBq3jA hr+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746727177; x=1747331977; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OiZ3IPvnOLD6bjPHFC0LENkY3LPdBb7EPB2/lZuSe4E=; b=lBGkPPhjyUNRwaokQQebqZuINDLq9bA0Iw1OVjAtVLxbjET/vXC8I+yilNAX94zvmq pvJ67QGgN1A0O/F7I6VtOjxIhbqw+C3UsTSOYSlLAEPyMZxeL1AkdAdtBCOr0vYuUYIE H6YDPyNSUB5PQkYEzwwkHmlLyRWUa2OtaoZFps8I69NjhAE/mhlKqwXwfCpy9P4+0CpX KaSHTCpiyc8b/orYYOAnBt+AkpnkR4kcuWQECDdxYDQr3NvmHnSvERdQGXjRr/hbVUbn ya/oKc7wGzmlV3YM6fCs3/Vj4Zi0HsVtlUX3l9/V0dysoCGZ+dxR3gBFys+XclcbGh0p 9ziw== X-Gm-Message-State: AOJu0YwhG4GyaXWwxM1sSZfWDkPZhhvWMJHVRDBsBGwIi53iKWxa8gvU G4BzHwS7nTpwHTpyZzvIAv2u/xX+pXbCWZynulOIXcAn4GFG+jombPSN+ZZCF6A= X-Gm-Gg: ASbGnct6J9/1X6rjqF/AejHV8YjEgUI+cuKcNH8U7ineL04ng3Ul5R1MY78Ug8KnWiW F9W52U37JGxyOrqbubqagKomEX1rGB7ZJwqQ/fSJcnWpBxBdG/cqHszVCglpiidLBLThocsZUj1 HLnYODcLWlKX5VbEPTcVf8mv5YvFEvNd2EbTC6Im6F2GBaMmJNgp7ieLvip8PaQk6rEwD+y2rYp 9JrysXMk/APn0sr7T6quZcdIKHdL8TMCw5p78mGw8bXDDFm13PXQQqk2SSOVgO0bHNDur90hc26 42eVCzyz9UsYXtRQmjZgmv4aLjkbRU1mr8xo6kxBVPWtWxyvdGBuq3USDWxWZwOGLnpQp76vc8/ Dlf9kRFiWF82DQqdg4zdrYdBAOdbYp78oqVGahHcCm7JRUlU= X-Google-Smtp-Source: AGHT+IH3N6nyyLq0WSBQvjeqJlnw7cZarCZysfEtFvWeY7lO2Wyh24QMpflEZKGGQEPsg/zyI1YvuQ== X-Received: by 2002:a17:902:e747:b0:22e:5e70:b2d3 with SMTP id d9443c01a7336-22fc8afeec8mr4226315ad.1.1746727176663; Thu, 08 May 2025 10:59:36 -0700 (PDT) Received: from harshads.c.googlers.com.com (156.242.82.34.bc.googleusercontent.com. [34.82.242.156]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-22fc828939asm2153535ad.164.2025.05.08.10.59.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 May 2025 10:59:36 -0700 (PDT) From: Harshad Shirwadkar To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, jack@suse.cz, harshads@google.com, Harshad Shirwadkar Subject: [PATCH v9 8/9] ext4: convert s_fc_lock to mutex type Date: Thu, 8 May 2025 17:59:07 +0000 Message-ID: <20250508175908.1004880-9-harshadshirwadkar@gmail.com> X-Mailer: git-send-email 2.49.0.1045.g170613ef41-goog In-Reply-To: <20250508175908.1004880-1-harshadshirwadkar@gmail.com> References: <20250508175908.1004880-1-harshadshirwadkar@gmail.com> Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=0.8 required=5.0 tests=ARC_SIGNED,ARC_VALID, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DMARC_PASS, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=disabled version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on gandalf.ozlabs.org This allows us to hold s_fc_lock during kmem_cache_* functions, which is needed in the following patch. Signed-off-by: Harshad Shirwadkar Reviewed-by: Jan Kara --- fs/ext4/ext4.h | 2 +- fs/ext4/fast_commit.c | 60 +++++++++++++++++++++---------------------- fs/ext4/super.c | 2 +- 3 files changed, 32 insertions(+), 32 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 3987c5bf2..052d7afee 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -1754,7 +1754,7 @@ struct ext4_sb_info { * following fields: * ei->i_fc_list, s_fc_dentry_q, s_fc_q, s_fc_bytes, s_fc_bh. */ - spinlock_t s_fc_lock; + struct mutex s_fc_lock; struct buffer_head *s_fc_bh; struct ext4_fc_stats s_fc_stats; tid_t s_fc_ineligible_tid; diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c index 5f6a8ec24..eb888e522 100644 --- a/fs/ext4/fast_commit.c +++ b/fs/ext4/fast_commit.c @@ -238,9 +238,9 @@ void ext4_fc_del(struct inode *inode) if (ext4_fc_disabled(inode->i_sb)) return; - spin_lock(&sbi->s_fc_lock); + mutex_lock(&sbi->s_fc_lock); if (list_empty(&ei->i_fc_list) && list_empty(&ei->i_fc_dilist)) { - spin_unlock(&sbi->s_fc_lock); + mutex_unlock(&sbi->s_fc_lock); return; } @@ -275,9 +275,9 @@ void ext4_fc_del(struct inode *inode) #endif prepare_to_wait(wq, &wait.wq_entry, TASK_UNINTERRUPTIBLE); if (ext4_test_inode_state(inode, EXT4_STATE_FC_FLUSHING_DATA)) { - spin_unlock(&sbi->s_fc_lock); + mutex_unlock(&sbi->s_fc_lock); schedule(); - spin_lock(&sbi->s_fc_lock); + mutex_lock(&sbi->s_fc_lock); } finish_wait(wq, &wait.wq_entry); } @@ -288,7 +288,7 @@ void ext4_fc_del(struct inode *inode) * dentry create references, since it is not needed to log it anyways. */ if (list_empty(&ei->i_fc_dilist)) { - spin_unlock(&sbi->s_fc_lock); + mutex_unlock(&sbi->s_fc_lock); return; } @@ -298,7 +298,7 @@ void ext4_fc_del(struct inode *inode) list_del_init(&fc_dentry->fcd_dilist); WARN_ON(!list_empty(&ei->i_fc_dilist)); - spin_unlock(&sbi->s_fc_lock); + mutex_unlock(&sbi->s_fc_lock); release_dentry_name_snapshot(&fc_dentry->fcd_name); kmem_cache_free(ext4_fc_dentry_cachep, fc_dentry); @@ -329,12 +329,12 @@ void ext4_fc_mark_ineligible(struct super_block *sb, int reason, handle_t *handl has_transaction = false; read_unlock(&sbi->s_journal->j_state_lock); } - spin_lock(&sbi->s_fc_lock); + mutex_lock(&sbi->s_fc_lock); is_ineligible = ext4_test_mount_flag(sb, EXT4_MF_FC_INELIGIBLE); if (has_transaction && (!is_ineligible || tid_gt(tid, sbi->s_fc_ineligible_tid))) sbi->s_fc_ineligible_tid = tid; ext4_set_mount_flag(sb, EXT4_MF_FC_INELIGIBLE); - spin_unlock(&sbi->s_fc_lock); + mutex_unlock(&sbi->s_fc_lock); WARN_ON(reason >= EXT4_FC_REASON_MAX); sbi->s_fc_stats.fc_ineligible_reason_count[reason]++; } @@ -373,14 +373,14 @@ static int ext4_fc_track_template( if (!enqueue) return ret; - spin_lock(&sbi->s_fc_lock); + mutex_lock(&sbi->s_fc_lock); if (list_empty(&EXT4_I(inode)->i_fc_list)) list_add_tail(&EXT4_I(inode)->i_fc_list, (sbi->s_journal->j_flags & JBD2_FULL_COMMIT_ONGOING || sbi->s_journal->j_flags & JBD2_FAST_COMMIT_ONGOING) ? &sbi->s_fc_q[FC_Q_STAGING] : &sbi->s_fc_q[FC_Q_MAIN]); - spin_unlock(&sbi->s_fc_lock); + mutex_unlock(&sbi->s_fc_lock); return ret; } @@ -424,7 +424,7 @@ static int __track_dentry_update(handle_t *handle, struct inode *inode, node->fcd_ino = inode->i_ino; take_dentry_name_snapshot(&node->fcd_name, dentry); INIT_LIST_HEAD(&node->fcd_dilist); - spin_lock(&sbi->s_fc_lock); + mutex_lock(&sbi->s_fc_lock); if (sbi->s_journal->j_flags & JBD2_FULL_COMMIT_ONGOING || sbi->s_journal->j_flags & JBD2_FAST_COMMIT_ONGOING) list_add_tail(&node->fcd_list, @@ -445,7 +445,7 @@ static int __track_dentry_update(handle_t *handle, struct inode *inode, WARN_ON(!list_empty(&ei->i_fc_dilist)); list_add_tail(&node->fcd_dilist, &ei->i_fc_dilist); } - spin_unlock(&sbi->s_fc_lock); + mutex_unlock(&sbi->s_fc_lock); spin_lock(&ei->i_fc_lock); return 0; @@ -1000,12 +1000,12 @@ __releases(&sbi->s_fc_lock) list_for_each_entry_safe(fc_dentry, fc_dentry_n, &sbi->s_fc_dentry_q[FC_Q_MAIN], fcd_list) { if (fc_dentry->fcd_op != EXT4_FC_TAG_CREAT) { - spin_unlock(&sbi->s_fc_lock); + mutex_unlock(&sbi->s_fc_lock); if (!ext4_fc_add_dentry_tlv(sb, crc, fc_dentry)) { ret = -ENOSPC; goto lock_and_exit; } - spin_lock(&sbi->s_fc_lock); + mutex_lock(&sbi->s_fc_lock); continue; } /* @@ -1018,7 +1018,7 @@ __releases(&sbi->s_fc_lock) inode = &ei->vfs_inode; WARN_ON(inode->i_ino != fc_dentry->fcd_ino); - spin_unlock(&sbi->s_fc_lock); + mutex_unlock(&sbi->s_fc_lock); /* * We first write the inode and then the create dirent. This @@ -1040,11 +1040,11 @@ __releases(&sbi->s_fc_lock) goto lock_and_exit; } - spin_lock(&sbi->s_fc_lock); + mutex_lock(&sbi->s_fc_lock); } return 0; lock_and_exit: - spin_lock(&sbi->s_fc_lock); + mutex_lock(&sbi->s_fc_lock); return ret; } @@ -1064,12 +1064,12 @@ static int ext4_fc_perform_commit(journal_t *journal) * EXT4_STATE_FC_FLUSHING_DATA. This prevents these inodes from being * freed until the data flush is over. */ - spin_lock(&sbi->s_fc_lock); + mutex_lock(&sbi->s_fc_lock); list_for_each_entry(iter, &sbi->s_fc_q[FC_Q_MAIN], i_fc_list) { ext4_set_inode_state(&iter->vfs_inode, EXT4_STATE_FC_FLUSHING_DATA); } - spin_unlock(&sbi->s_fc_lock); + mutex_unlock(&sbi->s_fc_lock); /* Step 2: Flush data for all the eligible inodes. */ ret = ext4_fc_flush_data(journal); @@ -1079,7 +1079,7 @@ static int ext4_fc_perform_commit(journal_t *journal) * any error from step 2. This ensures that waiters waiting on * EXT4_STATE_FC_FLUSHING_DATA can resume. */ - spin_lock(&sbi->s_fc_lock); + mutex_lock(&sbi->s_fc_lock); list_for_each_entry(iter, &sbi->s_fc_q[FC_Q_MAIN], i_fc_list) { ext4_clear_inode_state(&iter->vfs_inode, EXT4_STATE_FC_FLUSHING_DATA); @@ -1096,7 +1096,7 @@ static int ext4_fc_perform_commit(journal_t *journal) * prepare_to_wait() in ext4_fc_del(). */ smp_mb(); - spin_unlock(&sbi->s_fc_lock); + mutex_unlock(&sbi->s_fc_lock); /* * If we encountered error in Step 2, return it now after clearing @@ -1113,12 +1113,12 @@ static int ext4_fc_perform_commit(journal_t *journal) * previous handles are now drained. We now mark the inodes on the * commit queue as being committed. */ - spin_lock(&sbi->s_fc_lock); + mutex_lock(&sbi->s_fc_lock); list_for_each_entry(iter, &sbi->s_fc_q[FC_Q_MAIN], i_fc_list) { ext4_set_inode_state(&iter->vfs_inode, EXT4_STATE_FC_COMMITTING); } - spin_unlock(&sbi->s_fc_lock); + mutex_unlock(&sbi->s_fc_lock); jbd2_journal_unlock_updates(journal); /* @@ -1146,10 +1146,10 @@ static int ext4_fc_perform_commit(journal_t *journal) } /* Step 6.2: Now write all the dentry updates. */ - spin_lock(&sbi->s_fc_lock); + mutex_lock(&sbi->s_fc_lock); ret = ext4_fc_commit_dentry_updates(journal, &crc); if (ret) { - spin_unlock(&sbi->s_fc_lock); + mutex_unlock(&sbi->s_fc_lock); goto out; } @@ -1159,7 +1159,7 @@ static int ext4_fc_perform_commit(journal_t *journal) if (!ext4_test_inode_state(inode, EXT4_STATE_FC_COMMITTING)) continue; - spin_unlock(&sbi->s_fc_lock); + mutex_unlock(&sbi->s_fc_lock); ret = ext4_fc_write_inode_data(inode, &crc); if (ret) goto out; @@ -1311,7 +1311,7 @@ static void ext4_fc_cleanup(journal_t *journal, int full, tid_t tid) trace_ext4_fc_cleanup(journal, full, tid); jbd2_fc_release_bufs(journal); - spin_lock(&sbi->s_fc_lock); + mutex_lock(&sbi->s_fc_lock); while (!list_empty(&sbi->s_fc_q[FC_Q_MAIN])) { ei = list_first_entry(&sbi->s_fc_q[FC_Q_MAIN], struct ext4_inode_info, @@ -1353,11 +1353,11 @@ static void ext4_fc_cleanup(journal_t *journal, int full, tid_t tid) fcd_list); list_del_init(&fc_dentry->fcd_list); list_del_init(&fc_dentry->fcd_dilist); - spin_unlock(&sbi->s_fc_lock); + mutex_unlock(&sbi->s_fc_lock); release_dentry_name_snapshot(&fc_dentry->fcd_name); kmem_cache_free(ext4_fc_dentry_cachep, fc_dentry); - spin_lock(&sbi->s_fc_lock); + mutex_lock(&sbi->s_fc_lock); } list_splice_init(&sbi->s_fc_dentry_q[FC_Q_STAGING], @@ -1372,7 +1372,7 @@ static void ext4_fc_cleanup(journal_t *journal, int full, tid_t tid) if (full) sbi->s_fc_bytes = 0; - spin_unlock(&sbi->s_fc_lock); + mutex_unlock(&sbi->s_fc_lock); trace_ext4_fc_stats(sb); } diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 356a96269..5bd81dd97 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -4481,7 +4481,7 @@ static void ext4_fast_commit_init(struct super_block *sb) sbi->s_fc_bytes = 0; ext4_clear_mount_flag(sb, EXT4_MF_FC_INELIGIBLE); sbi->s_fc_ineligible_tid = 0; - spin_lock_init(&sbi->s_fc_lock); + mutex_init(&sbi->s_fc_lock); memset(&sbi->s_fc_stats, 0, sizeof(sbi->s_fc_stats)); sbi->s_fc_replay_state.fc_regions = NULL; sbi->s_fc_replay_state.fc_regions_size = 0; From patchwork Thu May 8 17:59:08 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harshad Shirwadkar X-Patchwork-Id: 2083066 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=OrIQyurP; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=2404:9400:2221:ea00::3; helo=mail.ozlabs.org; envelope-from=srs0=agul=xy=vger.kernel.org=linux-ext4+bounces-7777-patchwork-incoming=ozlabs.org@ozlabs.org; receiver=patchwork.ozlabs.org) Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4ZtfzX5f8Qz1xnT for ; Fri, 9 May 2025 03:59:52 +1000 (AEST) Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Ztfzr73XWz4xRB for ; Fri, 9 May 2025 04:00:08 +1000 (AEST) Received: by gandalf.ozlabs.org (Postfix) id 4Ztfzr719wz4xRj; Fri, 9 May 2025 04:00:08 +1000 (AEST) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; arc=pass smtp.remote-ip=147.75.80.249 arc.chain=subspace.kernel.org ARC-Seal: i=2; a=rsa-sha256; d=ozlabs.org; s=201707; t=1746727208; cv=pass; b=QHXDOauz7yfH9d2AitbZ/YIMg+B1YnefjlxA8BTlPz+8/icsVRl5wV6pzGbBJd1pD/Rf7d8F+g/BMDqwJgbmhPaXIPV1TaySOj8m+y1xGhhgrAVLsST4AHZDXxDxkFYnTnK2NRqr9zGI0hn0dDvvD1BjxdlRISz706vtJW2isSRQ7q/JjTdY1nCcRe4BdFRbt0iqX4Y7ByeFXexEQgpqIBkzvqNidoMKcDuaYuqoIz5FCrs6hJIYq7uZyJQfxS/Aw1g6oVNxHwDhduj3rk/8JthuL7GIHEJ8xlSMnWFczIGzPVzhu9h3ZtGcooeLyNMlag0v83/9aaYmdOZlCOHXjw== ARC-Message-Signature: i=2; a=rsa-sha256; d=ozlabs.org; s=201707; t=1746727208; c=relaxed/relaxed; bh=TkNakbZ3I/jJnUJlrPFtE58abfJJ8pR6wAdHQWq6G/A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=L19i4IWI9vO0KH/YU9fn4lC2+5+VHYV9eAss0bDx/kRUEtS1KeoJv31qhJc5aH0sj838Q//Pci7f+tnpIRaoAiMSaekhi4nJvcxtxnpn0cjp6BP0oAvEDzWetCgL+goxhGEoXRqT0R3bFXph5mMbyZoQLayMIRRK60SpSSePbXAVuT8xkiOGBbY7zH3nY256bQuhgk3cxoS9VQwDsVZmJwHjS1IA5xU2uhIbZyrYbozVAS2gIEGxu7/JPHh8Co3v2exX/MkXsCvmzCXnbNPE49rnB9mLeGUdLCA/oGCXG/+75w4XiaQFPbnTx3FXJGPGgjlfFWyJDAAMre+TLohONA== ARC-Authentication-Results: i=2; gandalf.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=vger.kernel.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=OrIQyurP; dkim-atps=neutral Authentication-Results: gandalf.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: gandalf.ozlabs.org; spf=pass smtp.mailfrom=vger.kernel.org Authentication-Results: gandalf.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=OrIQyurP; dkim-atps=neutral Received: from am.mirrors.kernel.org (am.mirrors.kernel.org [147.75.80.249]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by gandalf.ozlabs.org (Postfix) with ESMTPS id 4Ztfzn3slTz4xRB for ; Fri, 9 May 2025 04:00:05 +1000 (AEST) Received: from smtp.subspace.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id CCC931BA77EF for ; Thu, 8 May 2025 18:00:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 147D62874F2; Thu, 8 May 2025 17:59:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="OrIQyurP" X-Original-To: linux-ext4@vger.kernel.org Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 673E0286D76 for ; Thu, 8 May 2025 17:59:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746727179; cv=none; b=X/CjQj8NbYMX5X+OeUFjpXjgmUBiq9t+5i6T7MKN2PFpWREVqGl0+BcmnXwJXDToiPuQoyA9uAw9QL9wI2nCTHI5lmUTVQtAdtU+Y0VhV4hqJCEi5xqB4Hee85dGnn1qrjh8LnlMuQduqFkxL6XkK9KHoH6910+GfHuDLL4zqvM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746727179; c=relaxed/simple; bh=X7n7Wtq2qhB5VaRW7EcFGNoLqtyyUYK8On7Cm9uoqKg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=chIXZksORTJQz+bT5yGGTE/wjpLFjh8oQPzlLalTFBATQJWUpHwit6GOb+SzvZ6DdnCzHdrRSLRUvRD5PZrXGuP3obTS+W/G+HzM3cWPOl2cz2adNlkN8fTw/UQNRzrjFqTPyaZ1WeX8C4wNSL4PsnV+A6T/ghKAUC2DYNH2JLo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=OrIQyurP; arc=none smtp.client-ip=209.85.210.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-739be717eddso1177598b3a.2 for ; Thu, 08 May 2025 10:59:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1746727177; x=1747331977; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=TkNakbZ3I/jJnUJlrPFtE58abfJJ8pR6wAdHQWq6G/A=; b=OrIQyurPh2dpt2KDBaoZPPbTZKLv8XbuBgw9Hi5ynhHeefetV9Fzo2Y/p4L6QNPDEE 0BCJwIUDF1ofSTH9ldZTRrA5YpuSs8oz3mD/zhiLClzeKbsk0TvU4gU6QMSqwRobyL+H 4LWP/XKx4P0yxh+Jj55VbvFHdRWpF/LRS2NKgdyZjc7ZvAaJq7uv/WN2r5lkCmsDO2CV uDGn90A+eLY/1NQPpLw2xBNH0at4DrbOYjEep0rNcXSDue/xvquRuv4EcbIsD20OubY+ xuqp9qw9OOH5JnGKBgE9k6Mazo4eZ+V4G+1++cTQ2NfWsfO4KAF+9esDfkoGDDDeqGhA lmyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746727177; x=1747331977; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TkNakbZ3I/jJnUJlrPFtE58abfJJ8pR6wAdHQWq6G/A=; b=rYsP3U6nuMC8ZQ6KtBltDpcxsFHI3e8F9ZAZ5gvA39dV32dfCSA+68+TgzgWnKx733 A2PxirbMyv8cEkYleMLyWDLy/dYk+1oW/tFkvh15tBd//kpy4IWqVsWllCWsusQN0YDu XZzDzYA+0v5vnAsrc4EhsZHtmsvPA2Ud7Dn0olZTtjcrDU5XPEhmxI4Ex/HZk1SiuduQ ZDseZtrGprpIiC4NcNYnbsk9PWlqR5yII3DQfIRC4a8RvsyneZysoE0JXnFRIbcpVnH+ LUT9KJmA21476SQxyUIO6A1WpXlkHhA87DFxkzDOBeraiqvTgzBCt7RLFvYmg4XxVVva 7QQQ== X-Gm-Message-State: AOJu0Yzdhw9zrzmTBADSAIAhD+A4SWMOkUniRKOCBnp+5S83AFbWPUJa nAXUIBMx+Q1zRjR/OZb3v25634rahTAu2175vbplRNkYkd60IsmTj8oNuL0T6P8= X-Gm-Gg: ASbGnct+I/Xj/uxvp84W76lwV60geFMzvw/2vms3yLjWEYWrS3aRy8uQpMAHpkNM04Z PrPcAs5jgfxYHoLQKbLczFkLXDTJzFHDL5f9W6sMOYaCJg/Y4C02dZbTcpi3bfd49HCXmgdCg3T ZImWNT66Ia8BbIf6FF87boHac4BkpoBYYB5jXfbK5nCcygWHXvqzXqiDYTYNsbtBDohdYifGhBk 6xKrYayl6hNQd2kXxHDtJuaEBwNv2TZxk/iRAVmMeSmFAaDKJz0Jy+pN4pEjHyL97Cvx3hlYwg3 /+j2Q43ou79WFnve3+PYHx46X/HfAl5nssnfAz1Ds+q9b3c4AxgA4xStxpTK58T1dNCGDnJH671 qBOED9p99xgmT/8/242pg3bW4vRviXBs1poAX X-Google-Smtp-Source: AGHT+IGFVNXSf39l43wTFSEfAXg4KsmuHPg0dweGrNzB/vCG1+IY/Sfyi3wPVEHp0XAEawTxFZ0a2w== X-Received: by 2002:a17:903:230e:b0:223:325c:89f6 with SMTP id d9443c01a7336-22fc8b1b1a6mr4024815ad.10.1746727177251; Thu, 08 May 2025 10:59:37 -0700 (PDT) Received: from harshads.c.googlers.com.com (156.242.82.34.bc.googleusercontent.com. [34.82.242.156]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-22fc828939asm2153535ad.164.2025.05.08.10.59.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 May 2025 10:59:36 -0700 (PDT) From: Harshad Shirwadkar To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, jack@suse.cz, harshads@google.com, Harshad Shirwadkar Subject: [PATCH v9 9/9] ext4: hold s_fc_lock while during fast commit Date: Thu, 8 May 2025 17:59:08 +0000 Message-ID: <20250508175908.1004880-10-harshadshirwadkar@gmail.com> X-Mailer: git-send-email 2.49.0.1045.g170613ef41-goog In-Reply-To: <20250508175908.1004880-1-harshadshirwadkar@gmail.com> References: <20250508175908.1004880-1-harshadshirwadkar@gmail.com> Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-1.5 required=5.0 tests=ARC_SIGNED,ARC_VALID, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DMARC_PASS, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=disabled version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on gandalf.ozlabs.org Leaving s_fc_lock in between during commit in ext4_fc_perform_commit() function leaves room for subtle concurrency bugs where ext4_fc_del() may delete an inode from the fast commit list, leaving list in an inconsistent state. Signed-off-by: Harshad Shirwadkar Reviewed-by: Jan Kara --- fs/ext4/fast_commit.c | 44 +++++++++++++------------------------------ 1 file changed, 13 insertions(+), 31 deletions(-) diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c index eb888e522..7ac672e35 100644 --- a/fs/ext4/fast_commit.c +++ b/fs/ext4/fast_commit.c @@ -424,6 +424,7 @@ static int __track_dentry_update(handle_t *handle, struct inode *inode, node->fcd_ino = inode->i_ino; take_dentry_name_snapshot(&node->fcd_name, dentry); INIT_LIST_HEAD(&node->fcd_dilist); + INIT_LIST_HEAD(&node->fcd_list); mutex_lock(&sbi->s_fc_lock); if (sbi->s_journal->j_flags & JBD2_FULL_COMMIT_ONGOING || sbi->s_journal->j_flags & JBD2_FAST_COMMIT_ONGOING) @@ -985,8 +986,6 @@ static int ext4_fc_flush_data(journal_t *journal) /* Commit all the directory entry updates */ static int ext4_fc_commit_dentry_updates(journal_t *journal, u32 *crc) -__acquires(&sbi->s_fc_lock) -__releases(&sbi->s_fc_lock) { struct super_block *sb = journal->j_private; struct ext4_sb_info *sbi = EXT4_SB(sb); @@ -1000,26 +999,22 @@ __releases(&sbi->s_fc_lock) list_for_each_entry_safe(fc_dentry, fc_dentry_n, &sbi->s_fc_dentry_q[FC_Q_MAIN], fcd_list) { if (fc_dentry->fcd_op != EXT4_FC_TAG_CREAT) { - mutex_unlock(&sbi->s_fc_lock); - if (!ext4_fc_add_dentry_tlv(sb, crc, fc_dentry)) { - ret = -ENOSPC; - goto lock_and_exit; - } - mutex_lock(&sbi->s_fc_lock); + if (!ext4_fc_add_dentry_tlv(sb, crc, fc_dentry)) + return -ENOSPC; continue; } /* * With fcd_dilist we need not loop in sbi->s_fc_q to get the - * corresponding inode pointer + * corresponding inode. Also, the corresponding inode could have been + * deleted, in which case, we don't need to do anything. */ - WARN_ON(list_empty(&fc_dentry->fcd_dilist)); + if (list_empty(&fc_dentry->fcd_dilist)) + continue; ei = list_first_entry(&fc_dentry->fcd_dilist, struct ext4_inode_info, i_fc_dilist); inode = &ei->vfs_inode; WARN_ON(inode->i_ino != fc_dentry->fcd_ino); - mutex_unlock(&sbi->s_fc_lock); - /* * We first write the inode and then the create dirent. This * allows the recovery code to create an unnamed inode first @@ -1029,23 +1024,14 @@ __releases(&sbi->s_fc_lock) */ ret = ext4_fc_write_inode(inode, crc); if (ret) - goto lock_and_exit; - + return ret; ret = ext4_fc_write_inode_data(inode, crc); if (ret) - goto lock_and_exit; - - if (!ext4_fc_add_dentry_tlv(sb, crc, fc_dentry)) { - ret = -ENOSPC; - goto lock_and_exit; - } - - mutex_lock(&sbi->s_fc_lock); + return ret; + if (!ext4_fc_add_dentry_tlv(sb, crc, fc_dentry)) + return -ENOSPC; } return 0; -lock_and_exit: - mutex_lock(&sbi->s_fc_lock); - return ret; } static int ext4_fc_perform_commit(journal_t *journal) @@ -1148,10 +1134,8 @@ static int ext4_fc_perform_commit(journal_t *journal) /* Step 6.2: Now write all the dentry updates. */ mutex_lock(&sbi->s_fc_lock); ret = ext4_fc_commit_dentry_updates(journal, &crc); - if (ret) { - mutex_unlock(&sbi->s_fc_lock); + if (ret) goto out; - } /* Step 6.3: Now write all the changed inodes to disk. */ list_for_each_entry(iter, &sbi->s_fc_q[FC_Q_MAIN], i_fc_list) { @@ -1159,7 +1143,6 @@ static int ext4_fc_perform_commit(journal_t *journal) if (!ext4_test_inode_state(inode, EXT4_STATE_FC_COMMITTING)) continue; - mutex_unlock(&sbi->s_fc_lock); ret = ext4_fc_write_inode_data(inode, &crc); if (ret) goto out; @@ -1171,6 +1154,7 @@ static int ext4_fc_perform_commit(journal_t *journal) ret = ext4_fc_write_tail(sb, crc); out: + mutex_unlock(&sbi->s_fc_lock); blk_finish_plug(&plug); return ret; } @@ -1353,11 +1337,9 @@ static void ext4_fc_cleanup(journal_t *journal, int full, tid_t tid) fcd_list); list_del_init(&fc_dentry->fcd_list); list_del_init(&fc_dentry->fcd_dilist); - mutex_unlock(&sbi->s_fc_lock); release_dentry_name_snapshot(&fc_dentry->fcd_name); kmem_cache_free(ext4_fc_dentry_cachep, fc_dentry); - mutex_lock(&sbi->s_fc_lock); } list_splice_init(&sbi->s_fc_dentry_q[FC_Q_STAGING],