From patchwork Wed May 29 01:19:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: harshad shirwadkar X-Patchwork-Id: 1940857 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=lvbU0z7x; 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=0hxt=na=vger.kernel.org=linux-ext4+bounces-2684-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 4Vps5f4Sj1z20Pr for ; Wed, 29 May 2024 11:20:54 +1000 (AEST) Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Vps5f3zZXz4wqK for ; Wed, 29 May 2024 11:20:54 +1000 (AEST) Received: by gandalf.ozlabs.org (Postfix) id 4Vps5f3xfKz4wqM; Wed, 29 May 2024 11:20:54 +1000 (AEST) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com 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=lvbU0z7x; dkim-atps=neutral Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:40f1:3f00::1; helo=sy.mirrors.kernel.org; envelope-from=linux-ext4+bounces-2684-patchwork-incoming=ozlabs.org@vger.kernel.org; receiver=ozlabs.org) 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) server-digest SHA256) (No client certificate requested) by gandalf.ozlabs.org (Postfix) with ESMTPS id 4Vps5f3qmZz4wqK for ; Wed, 29 May 2024 11:20:54 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id E410BB20E5A for ; Wed, 29 May 2024 01:20:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AC16715A86F; Wed, 29 May 2024 01:20:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lvbU0z7x" X-Original-To: linux-ext4@vger.kernel.org Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) (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 19DF3632 for ; Wed, 29 May 2024 01:20:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716945648; cv=none; b=o8c0jV8h6zSMAtLU6XPAmuicrGu9jiwlu7UtNAJVO6ULhu5PDsRJxmnjkkUHQAW3WgoF7ar3h15yY8ej/pCl3cyyRDgDEX45icKFImmXnxkIJVIG1l4/SK38zRkjAeqMDOQ9bQE1GvXSvKpITkcONQPt+m7taO5aYuNMG6Ak0cI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716945648; c=relaxed/simple; bh=6ClwghjqacipfUFIlG3kmDQoRHL1C7vIWkmmhUb9uqY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nJUOqz+N7oaI+Floj/Gp1Fc1i8Qu5fyi2+E4VQEy2x0HmPgpte+TxcnOIqmIgRE5391FZmRYYJSPg2fi7giBNq7nHjozXh92ZZdE+AwomyOc8QF2eyoPs8rfX2bfPM4dgClQKZQaocQZ+DNpE+wDDnkMDA6hTxucaPY/WmKdi2c= 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=lvbU0z7x; arc=none smtp.client-ip=209.85.216.53 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-pj1-f53.google.com with SMTP id 98e67ed59e1d1-2bf5ee192b1so297034a91.1 for ; Tue, 28 May 2024 18:20:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716945645; x=1717550445; 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=hK37RO54JishXQn1liveQo1Ra2HinNn7lcYyS3kqgSY=; b=lvbU0z7xgyQd/b0Sh9AYU0GBK3W10Ly73L2prw6S0gWLFwKbRPCj1Mnm15iljV1A6u 3RbX4zC/S9/jed58HtbMIE3/M4NA1UjJHUfe55ojDxaKFN4t0zhPWHke2I70D3qFHcur ww7BApGPlaPjsoYP379RW9hAav6UWRDBl5TznqWpqzm7GlU+eOV9yiFQhbsQcOPzgsaR QS2B9tMl3QYGTs8unVpn7Pz8GYKG3wO4CLtg4qbue97Mz+nj3Qs+exjwOlSz7e0X6AtD cwz1H/LZshtmQC4pOlfFFvIVpFBSxNBCLn7BUWS6bodwOdziYzdvCnJhwt3etQz05MGm 4AmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716945645; x=1717550445; 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=hK37RO54JishXQn1liveQo1Ra2HinNn7lcYyS3kqgSY=; b=kXqa2ml/g+z4a66o7aa4TVN6OzKnrWHFdDapk1kH/OPiBzJ2lZNe45iazDqBC+p73+ 0KmjqKKHQF9BkAXn+ris483/TcHEcuTfnvTfbyDH6EAk4u6tyZpgCKX1LU5b3bbFZJzd IO7M0kunaFktSJTXMeeUgMKdujeI2FxdDnJiq/X/qQiV18BSxCPUI6wlzFG8cJwadpHu QQgp7+gvr25DIWJh2Jl7yuAgdeaxnJ2oKcswXUm/D6OINYjDJjHSL8bQX+xvHZwIX1SQ wSLnbplJHSbbOILjcw3J3fQfZ1/+xGMNJ2EfgMsrfEtei0ECSBZGpRTtNGZIpx7Zpavs Fksw== X-Gm-Message-State: AOJu0YxihlHLpdTMhh0KcjM4/XRVjcZs43MP4RedJl9bRO2EBm9/A6ob 5UY8xVBp0zh2scoAbwUqSpIJ0b1z43b2Fw7/pL5cyCsBX0oG8jQd5r4/uyX/ X-Google-Smtp-Source: AGHT+IFRRMtfrXuxrklmKfn8HEw5BHPUEH0FwngM2J0eT+HmQ91v/+frObL4uoSwcCssCssFomBrkg== X-Received: by 2002:a17:90a:d512:b0:2bf:9eb3:cea7 with SMTP id 98e67ed59e1d1-2c02ec1f042mr881841a91.24.1716945645092; Tue, 28 May 2024 18:20:45 -0700 (PDT) Received: from harshads.c.googlers.com.com (34.85.168.34.bc.googleusercontent.com. [34.168.85.34]) by smtp.googlemail.com with ESMTPSA id 98e67ed59e1d1-2bde008a188sm10139388a91.53.2024.05.28.18.20.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 18:20:44 -0700 (PDT) From: Harshad Shirwadkar To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, saukad@google.com, harshads@google.com, Harshad Shirwadkar Subject: [PATCH v6 01/10] ext4: convert i_fc_lock to spinlock Date: Wed, 29 May 2024 01:19:54 +0000 Message-ID: <20240529012003.4006535-2-harshadshirwadkar@gmail.com> X-Mailer: git-send-email 2.45.1.288.g0e0cd299f1-goog In-Reply-To: <20240529012003.4006535-1-harshadshirwadkar@gmail.com> References: <20240529012003.4006535-1-harshadshirwadkar@gmail.com> Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Convert ext4_inode_info->i_fc_lock to spinlock to avoid sleeping in invalid contexts. Signed-off-by: Harshad Shirwadkar Reviewed-by: Jan Kara --- fs/ext4/ext4.h | 7 +++++-- fs/ext4/fast_commit.c | 24 +++++++++++------------- fs/ext4/super.c | 2 +- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 983dad8c07ec..611b8c80d99c 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -1062,8 +1062,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 87c009e0c59a..a1aadebfcd66 100644 --- a/fs/ext4/fast_commit.c +++ b/fs/ext4/fast_commit.c @@ -382,7 +382,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 { @@ -390,7 +390,7 @@ static int ext4_fc_track_template( ei->i_sync_tid = tid; } ret = __fc_track_fn(inode, args, update); - mutex_unlock(&ei->i_fc_lock); + spin_unlock(&ei->i_fc_lock); if (!enqueue) return ret; @@ -424,19 +424,19 @@ static int __track_dentry_update(struct inode *inode, void *arg, bool update) 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, NULL); - 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, NULL); - mutex_lock(&ei->i_fc_lock); + spin_lock(&ei->i_fc_lock); return -ENOMEM; } @@ -448,7 +448,7 @@ static int __track_dentry_update(struct inode *inode, void *arg, bool update) if (!node->fcd_name.name) { kmem_cache_free(ext4_fc_dentry_cachep, node); ext4_fc_mark_ineligible(sb, EXT4_FC_REASON_NOMEM, NULL); - mutex_lock(&ei->i_fc_lock); + spin_lock(&ei->i_fc_lock); return -ENOMEM; } memcpy((u8 *)node->fcd_name.name, dentry->d_name.name, @@ -482,7 +482,7 @@ static int __track_dentry_update(struct inode *inode, void *arg, bool update) 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; } @@ -614,10 +614,8 @@ static int __track_range(struct inode *inode, void *arg, bool update) struct __track_range_args *__arg = (struct __track_range_args *)arg; - if (inode->i_ino < EXT4_FIRST_INO(inode->i_sb)) { - ext4_debug("Special inode %ld being modified\n", inode->i_ino); + if (inode->i_ino < EXT4_FIRST_INO(inode->i_sb)) return -ECANCELED; - } oldstart = ei->i_fc_lblk_start; @@ -896,15 +894,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 f9a4a4e89dac..77173ec91e49 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -1436,7 +1436,7 @@ static struct inode *ext4_alloc_inode(struct super_block *sb) atomic_set(&ei->i_unwritten, 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 Wed May 29 01:19:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: harshad shirwadkar X-Patchwork-Id: 1940858 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=Tc2TwK28; 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=lznc=na=vger.kernel.org=linux-ext4+bounces-2685-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 4Vps5n0m0zz20Pr for ; Wed, 29 May 2024 11:21: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 4Vps5n0Kc1z4wqK for ; Wed, 29 May 2024 11:21:01 +1000 (AEST) Received: by gandalf.ozlabs.org (Postfix) id 4Vps5n0HFJz4wyY; Wed, 29 May 2024 11:21:01 +1000 (AEST) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com 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=Tc2TwK28; dkim-atps=neutral Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=147.75.80.249; helo=am.mirrors.kernel.org; envelope-from=linux-ext4+bounces-2685-patchwork-incoming=ozlabs.org@vger.kernel.org; receiver=ozlabs.org) 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 4Vps5m3GJSz4wqK for ; Wed, 29 May 2024 11:21:00 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 8FA3A1F2699F for ; Wed, 29 May 2024 01:20:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 256B915AAB8; Wed, 29 May 2024 01:20:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Tc2TwK28" X-Original-To: linux-ext4@vger.kernel.org Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) (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 745981E86E for ; Wed, 29 May 2024 01:20:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716945648; cv=none; b=Ug8PfAG2L4HoZVykEMMMg3R8pX84PFogLZTx/Ld5NwkCkh6VLfGDD8IP7jXXyAJINJNGg4lCXhzc5Xx16rZR41G3FtNbjmHONiponmFFZtQNpgGevMweLh406xTP/QVdGPlFBINY9ozc+RnSjO76sOpaqxN//G6XmNJp633VKFM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716945648; c=relaxed/simple; bh=4XPxsX8sQ2GXcseex3wUkrzhI1XzuQofoIcsIDhXLI8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KILFuc59QpJ3rB9qPoWHb6Na/AZukVjXBQXiGVIWsD5Y9gaV7HlOzV8Mw2yOXJvxYVydz/D5Gqaz43PUtND3oj5w+dFaDCTgi+ri0KhMv+JnPf9owFQ4QLZEE59L4A0nHS302oajDPCxRqoXtoPCEmv/BzaRS8ajDqE6QlUb9kw= 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=Tc2TwK28; arc=none smtp.client-ip=209.85.216.51 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-pj1-f51.google.com with SMTP id 98e67ed59e1d1-2bf62b121ccso307105a91.0 for ; Tue, 28 May 2024 18:20:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716945646; x=1717550446; 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=juejHXi1btkqPVBPv4LvDkZ/0p8lu23sMTaQ4tMTggc=; b=Tc2TwK28HdHrYPT1AW2/oFeO6IErJEUF6B8kbywdTHawcJoYSsXRvJD0WtAAqMH52O +y9Sh4o8V4aQwdIh1AYi4EDVsy822VIaSs5wrNLYC4Y0FZf95RTaKdPpRfKcTe3ZmJV5 FbXeKLYpvAAGrokYCKBsa5ZflEKckahvxEimbReWam8czevG8yQ9hOyIoU7Ba2thF0sh uhjTy0hv0KowCbZm1b1lFkf0xUiyTmXRJ1vxuHPxKNZjlGeJ+e12Y/fG6Gg+8A0E78r6 5+qs1fc+7dzxyYFqjtrBs3/Hx92/VaQzhSjv6Bz0qqAaGeZ0al9cZnZNNsXijoS8HCT1 BXeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716945646; x=1717550446; 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=juejHXi1btkqPVBPv4LvDkZ/0p8lu23sMTaQ4tMTggc=; b=Y870dhT7/pQVlWSNl4NeSOhjESHV4oHNq+0pUEEk+6wKTXf1VpvZOLxO1/aXla1wqC RO6/msP4T+XsImBxflnUpEIHbNgx5VV10dJdBQLK8nrSPQpZ22bajS2uSD2dJY4pblR/ Y+3xc2ZalwRcQ1gz0dCWE8e0EAyD38UKPx3/2t0ilS3fCK1HL9IVoWNeaLy81Ltv/LtR 9h1QXZhPoih3F/qH8aSVpmlFYwsbiZeByUZ+jiunVFXJalzBMb3qCOy7k8blOTtLNz01 TnnmRnHbZQ+IzW5MP8yor3+NdAcVUqGuM42zZkRMnftmfP9JJxDaRE/mj2g/+1IB28ij xnpw== X-Gm-Message-State: AOJu0Yxcao7fyINZCFwtb6DtuGrFGA/gxQ61tj6tiCXcrFQMLChHmJgJ qwgjz0SBaac9nKVPvN3Mi3mcPdHapuMG7LenqMYDiR7AG9vm3CzpkvtMsmJr X-Google-Smtp-Source: AGHT+IE9Bjvw4pPNleShWfUZNpzGjosvzsshmEEASeD9+uBueanK9MhNa2aVhC4cL5djsK+qx0tWdA== X-Received: by 2002:a17:90a:4d82:b0:2bd:9284:d673 with SMTP id 98e67ed59e1d1-2c02ebc3f3cmr1001207a91.8.1716945645519; Tue, 28 May 2024 18:20:45 -0700 (PDT) Received: from harshads.c.googlers.com.com (34.85.168.34.bc.googleusercontent.com. [34.168.85.34]) by smtp.googlemail.com with ESMTPSA id 98e67ed59e1d1-2bde008a188sm10139388a91.53.2024.05.28.18.20.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 18:20:45 -0700 (PDT) From: Harshad Shirwadkar To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, saukad@google.com, harshads@google.com, Harshad Shirwadkar Subject: [PATCH v6 02/10] ext4: for committing inode, make ext4_fc_track_inode wait Date: Wed, 29 May 2024 01:19:55 +0000 Message-ID: <20240529012003.4006535-3-harshadshirwadkar@gmail.com> X-Mailer: git-send-email 2.45.1.288.g0e0cd299f1-goog In-Reply-To: <20240529012003.4006535-1-harshadshirwadkar@gmail.com> References: <20240529012003.4006535-1-harshadshirwadkar@gmail.com> Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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. 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 | 34 ++++++++++++++++++++++++++++++++++ fs/ext4/inline.c | 3 +++ fs/ext4/inode.c | 4 ++++ 3 files changed, 41 insertions(+) diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c index a1aadebfcd66..fa93ce399440 100644 --- a/fs/ext4/fast_commit.c +++ b/fs/ext4/fast_commit.c @@ -581,6 +581,8 @@ static int __track_inode(struct inode *inode, void *arg, bool update) 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)) @@ -598,6 +600,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 (!test_opt2(inode->i_sb, JOURNAL_FAST_COMMIT) || + (EXT4_SB(inode->i_sb)->s_mount_state & EXT4_FC_REPLAY) || + ext4_test_mount_flag(inode->i_sb, EXT4_MF_FC_INELIGIBLE) || + !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 in write mode when we go + * to sleep since the commit path needs to grab the lock while + * committing the inode. + */ + WARN_ON(lockdep_is_held_type(&ei->i_data_sem, 1)); + + 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); + } + 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 d5bd1e3a5d36..bd5778e680c0 100644 --- a/fs/ext4/inline.c +++ b/fs/ext4/inline.c @@ -596,6 +596,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; @@ -696,6 +697,7 @@ int ext4_try_to_write_inline_data(struct address_space *mapping, goto convert; } + ext4_fc_track_inode(handle, inode); ret = ext4_journal_get_write_access(handle, inode->i_sb, iloc.bh, EXT4_JTR_NONE); if (ret) @@ -948,6 +950,7 @@ int ext4_da_write_inline_data_begin(struct address_space *mapping, if (ret < 0) goto out_release_page; } + ext4_fc_track_inode(handle, inode); ret = ext4_journal_get_write_access(handle, inode->i_sb, iloc.bh, EXT4_JTR_NONE); if (ret) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 4bae9ccf5fe0..aa6440992a55 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -607,6 +607,7 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode, */ map->m_flags &= ~EXT4_MAP_FLAGS; + 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 @@ -3978,6 +3979,7 @@ int ext4_punch_hole(struct file *file, loff_t offset, loff_t length) if (stop_block > first_block) { ext4_lblk_t hole_len = stop_block - first_block; + ext4_fc_track_inode(handle, inode); down_write(&EXT4_I(inode)->i_data_sem); ext4_discard_preallocations(inode); @@ -4131,6 +4133,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); @@ -5727,6 +5730,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 Wed May 29 01:19:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: harshad shirwadkar X-Patchwork-Id: 1940856 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=np3GjdMg; 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=whwr=na=vger.kernel.org=linux-ext4+bounces-2683-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 4Vps5d0vRXz20Pr for ; Wed, 29 May 2024 11:20:53 +1000 (AEST) Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Vps5d0Tl2z4wqK for ; Wed, 29 May 2024 11:20:53 +1000 (AEST) Received: by gandalf.ozlabs.org (Postfix) id 4Vps5d0R6yz4wqM; Wed, 29 May 2024 11:20:53 +1000 (AEST) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com 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=np3GjdMg; dkim-atps=neutral Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:45e3:2400::1; helo=sv.mirrors.kernel.org; envelope-from=linux-ext4+bounces-2683-patchwork-incoming=ozlabs.org@vger.kernel.org; receiver=ozlabs.org) 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 4Vps5c522qz4wqK for ; Wed, 29 May 2024 11:20:52 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 21FEC2828E9 for ; Wed, 29 May 2024 01:20:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6081915A85E; Wed, 29 May 2024 01:20:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="np3GjdMg" X-Original-To: linux-ext4@vger.kernel.org Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) (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 DE45F14269 for ; Wed, 29 May 2024 01:20:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716945648; cv=none; b=lg16yPCBja3AJcthA18ypKix07yaDn2rpix4t5wdRFp9XxTRV45oJ34iuTXlYNk+C8AJWTfim+76Tzcehe0QJkLHhFGpidCAHg3HAK0Py0loVbsHY1v5XTCFEsFh+Ti5dbEvIB7vJTIBB1/gnwabu2lKv/zMVkAUGgha+VjebOI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716945648; c=relaxed/simple; bh=Z3IiSd1bUpDNnZfJydD8F5PvwmU8QRtMWPI+KSDWo1k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DBkAltDuBKwhj3AHBApCAI9i3QbC6C4kCDnhE1l5Vbo/Ab+Qi6vTN+sUPojbk/ZTVWdPIBqZqnpe5zKF+ZW3kN+DTSlsaoYM0w+yge5gsISzLR6ycYWpvwemf+cvYb112t43/f5GR8755mpjBd89Wv3vPlGrQlgHJ+2x8yjxoPU= 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=np3GjdMg; arc=none smtp.client-ip=209.85.215.169 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-f169.google.com with SMTP id 41be03b00d2f7-68187c5534cso983393a12.0 for ; Tue, 28 May 2024 18:20:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716945646; x=1717550446; 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=LezNvFRay6RLhkgYdsCUxGmhEyschzanOjZ4vSGULOM=; b=np3GjdMgXx4BwxC0HFtX07NKth7Km00o2r8KSv463hSSCxbnxAYQ0RpqkrDRjRcCLx nExLY4WIzEwaBHymswmJSM4L2Zm38jNLm8hpUQ6TGkeyYlaGp4G6ihybh8Pnuf63NtNl koP9J6qqkHyY78IbRov6YP5MhqW0Mbcqn+k6xlw8BXHzLIX5NZVnssSs+dM9sS0oXjkq V0+vtacnc/qOjPw2hPvIpkshO+Boz/VRq39G47f1yHw410ZzzRLVeOKi9G5yUP4Ck0Fo nFw5Ou2lhaEUTXvdv5n/UkKjBInlsMeXZu9VDf9F6KCuA7s39CWggi6DXzYPDkOXQll0 mJmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716945646; x=1717550446; 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=LezNvFRay6RLhkgYdsCUxGmhEyschzanOjZ4vSGULOM=; b=JPAo/oHYDHGxfHd5RgCIK6kANhReDbF87lmVyPGea6YLkeXcMSDAK4Nvkq2K7j+v+l wnxZpcpti3KUno1t43GYmVwkXLHj7ek0V6fRgIXgYxLWxTkAUCvaq85bOMSiEPQDYjem yCjSxCbnQOk4MoYWYPAgO40fTpq5ARILtLhqZwmgG2wJ3y5o48i/vv9MvJdaAyH8KFSM rXc0cm2TwNo3BCxU6f5TTSnbSw7SmDMNihBOwGtKuYk2ej4JjU4z+1EoGulbT4W/MIb2 xwaVhSUadQUZf2fM54SZoqsr4dK6Jzt8ojRlPQivxT6GjrEzmdxsJoQdvhanqX6Q+B0Z r6PQ== X-Gm-Message-State: AOJu0YzF8glDJEVH1By29LM+CjXP9BujE3UT9dOnvmD2eWm04g0Yrnh0 y9Eho0GrBVbg2H39Wr+ybmtQjhcW/LO5F8/enW0vs69zQO5Pr6YK9dbQN8Dq X-Google-Smtp-Source: AGHT+IGzxsJV7+4T4fRaq6NADGhKyNQQd965SlIbXkVoiXctdqPSvULNmnprZz2lBS9Be4hDAc2kmg== X-Received: by 2002:a05:6a20:5647:b0:1af:b89b:a7f5 with SMTP id adf61e73a8af0-1b212d2ba8amr14056761637.24.1716945646018; Tue, 28 May 2024 18:20:46 -0700 (PDT) Received: from harshads.c.googlers.com.com (34.85.168.34.bc.googleusercontent.com. [34.168.85.34]) by smtp.googlemail.com with ESMTPSA id 98e67ed59e1d1-2bde008a188sm10139388a91.53.2024.05.28.18.20.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 18:20:45 -0700 (PDT) From: Harshad Shirwadkar To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, saukad@google.com, harshads@google.com, Harshad Shirwadkar Subject: [PATCH v6 03/10] ext4: mark inode dirty before grabbing i_data_sem in ext4_setattr Date: Wed, 29 May 2024 01:19:56 +0000 Message-ID: <20240529012003.4006535-4-harshadshirwadkar@gmail.com> X-Mailer: git-send-email 2.45.1.288.g0e0cd299f1-goog In-Reply-To: <20240529012003.4006535-1-harshadshirwadkar@gmail.com> References: <20240529012003.4006535-1-harshadshirwadkar@gmail.com> Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 aa6440992a55..61ffbdc2fb16 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -5410,12 +5410,13 @@ int ext4_setattr(struct mnt_idmap *idmap, struct dentry *dentry, (attr->ia_size > 0 ? attr->ia_size - 1 : 0) >> inode->i_sb->s_blocksize_bits); - 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; + down_write(&EXT4_I(inode)->i_data_sem); + old_disksize = EXT4_I(inode)->i_disksize; + EXT4_I(inode)->i_disksize = attr->ia_size; + /* * We have to update i_size under i_data_sem together * with i_disksize to avoid races with writeback code From patchwork Wed May 29 01:19:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: harshad shirwadkar X-Patchwork-Id: 1940860 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=O+SK4L30; 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=jbpw=na=vger.kernel.org=linux-ext4+bounces-2686-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 4Vps5z2RGmz20Q9 for ; Wed, 29 May 2024 11:21:11 +1000 (AEST) Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Vps5n17l7z4wqM for ; Wed, 29 May 2024 11:21:01 +1000 (AEST) Received: by gandalf.ozlabs.org (Postfix) id 4Vps5n155rz4wqK; Wed, 29 May 2024 11:21:01 +1000 (AEST) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com 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=O+SK4L30; dkim-atps=neutral Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=147.75.80.249; helo=am.mirrors.kernel.org; envelope-from=linux-ext4+bounces-2686-patchwork-incoming=ozlabs.org@vger.kernel.org; receiver=ozlabs.org) 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 4Vps5m3vsGz4wqM for ; Wed, 29 May 2024 11:21:00 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id E03631F269B8 for ; Wed, 29 May 2024 01:20:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3EB3215AAC1; Wed, 29 May 2024 01:20:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="O+SK4L30" 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 79D252B9A9 for ; Wed, 29 May 2024 01:20:47 +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=1716945649; cv=none; b=Y9mFCTg4xhtmWmJgi3IhsRN2+ZtwYohtz66QW11eiO+gSDHO1TEUWhJLjG6xsdbIaTXciFDLQrH7BcBoAAmS/GH0wNf1ej9cK8Swy0+7TC/XbKfdZL6lCllhqukhhryM2fare2FZn76CxIWaKEh+pZroynwJH0K0tP1v0YmMqdk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716945649; c=relaxed/simple; bh=H9H7TwY7QEtvysmUnwkRxxrHdFizlerwakv9M0DNQH4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sp6ljjMYokrYw3BStpYouTnhnuDVBQFOcDx7v7WnPvPVx6jIvd/HiULG1eWw+hHzoAD+la7552ePT5lANe1CIOS4mmHjxVcs0fOMBpMw6X/Hu99DdcBq74mdoyC6RGdzj2H27lgghHp0bCFBKrVx//uM+WL/DWFA+d4qnEZNtyc= 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=O+SK4L30; 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-657a07878easo1291164a12.0 for ; Tue, 28 May 2024 18:20:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716945647; x=1717550447; 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=5KN0nAiO9ez93L/NVJUdKGcBM+CWxauy5ZWUl78F2fo=; b=O+SK4L30ZaBFBOajKzreS048PMWVfb1UdJnT63a53FRlCR984Me9mnf6d215WvH+P4 tRB5zECTPswbg7OGrhw9Q13qeoLFS1//VbKos1Z8TeQxg1T4FdlsCP7KDtSObP1pULUZ BRvE5qlUqqLjCnTEMKtw9H1W1jMrOB3YA58ueWutAv53XmsRxlnETptFD3HOUA7eWcI6 /v8TkUlEYUd77/9JauXauBVMOWQ8JrVGjwHp9/KSlwVdsyoYGKQKHl+4lGBAoHteb+SY fdf2u7+CB+3qenZZBnXD4CUs3ol4hxiomC/az6y1wIomYeARomvMjEeLtxXjpIjug/mU QL7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716945647; x=1717550447; 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=5KN0nAiO9ez93L/NVJUdKGcBM+CWxauy5ZWUl78F2fo=; b=W4MiH74K8L0dBtIaD8BTqkPPQYxQOWqCQYo7b+uunvecsTAR9o3foxJIB3JyhK3aAp 9YHbJqif8oVzJ18k2H1d2+uZE3hdVUBR0dskPeSy3MPdh4eyLxg9/PJZt0cfTn9SfFI/ Wa/xCh6MPlFSEHcUNbFrYSfsX9MYGcYChNdh79YXoiFPXPqU/RfrtetML/o6+dNhMnvD 1OcZhS4rSfwXWJNpB6VekfcB11RkKQfZCCllmGJYq5nGkj+BG5N23kSBWRCM2gwsq3f+ b+Xxljpzi1kbFQ+bx6+yMiDKpr9YdEHYi20UW6R3jWhrNn6Ckgj3x0pu+khzwBH5khkW ph2A== X-Gm-Message-State: AOJu0YwyCjcJ6NAwBK69dYjUZ8067nFsuufth4Dw/oTZG+uHkmC4fJgE b7JCCIIOmxsZ4+ODpKRLAoXMiN7OPnuEO0h6Nt3nOaxjzBkiUDTHS6n6dZex X-Google-Smtp-Source: AGHT+IG3TIeM7bG90Hl28kXJNIFnIxCO4OeIrROQcsA1/0Httr8NQjq6TK8elqpWezTXcekVm9EPeg== X-Received: by 2002:a05:6a21:3417:b0:1ac:3b5d:a3eb with SMTP id adf61e73a8af0-1b212df0c63mr18391788637.39.1716945646514; Tue, 28 May 2024 18:20:46 -0700 (PDT) Received: from harshads.c.googlers.com.com (34.85.168.34.bc.googleusercontent.com. [34.168.85.34]) by smtp.googlemail.com with ESMTPSA id 98e67ed59e1d1-2bde008a188sm10139388a91.53.2024.05.28.18.20.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 18:20:46 -0700 (PDT) From: Harshad Shirwadkar To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, saukad@google.com, harshads@google.com, Harshad Shirwadkar Subject: [PATCH v6 04/10] ext4: rework fast commit commit path Date: Wed, 29 May 2024 01:19:57 +0000 Message-ID: <20240529012003.4006535-5-harshadshirwadkar@gmail.com> X-Mailer: git-send-email 2.45.1.288.g0e0cd299f1-goog In-Reply-To: <20240529012003.4006535-1-harshadshirwadkar@gmail.com> References: <20240529012003.4006535-1-harshadshirwadkar@gmail.com> Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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/fast_commit.c | 75 ++++++++++++++++++++++++++++--------------- fs/jbd2/journal.c | 3 +- fs/jbd2/transaction.c | 41 +++++++++++++++-------- include/linux/jbd2.h | 1 + 4 files changed, 80 insertions(+), 40 deletions(-) diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c index fa93ce399440..3aca5b20aac5 100644 --- a/fs/ext4/fast_commit.c +++ b/fs/ext4/fast_commit.c @@ -290,20 +290,30 @@ void ext4_fc_del(struct inode *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) && list_empty(&ei->i_fc_dilist)) { spin_unlock(&EXT4_SB(inode->i_sb)->s_fc_lock); return; } - if (ext4_test_inode_state(inode, EXT4_STATE_FC_COMMITTING)) { - ext4_fc_wait_committing_inode(inode); - goto restart; - } - - if (!list_empty(&ei->i_fc_list)) - list_del_init(&ei->i_fc_list); + /* + * 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)); + list_del_init(&ei->i_fc_list); /* * Since this inode is getting removed, let's also remove all FC @@ -326,8 +336,6 @@ void ext4_fc_del(struct inode *inode) fc_dentry->fcd_name.len > DNAME_INLINE_LEN) kfree(fc_dentry->fcd_name.name); kmem_cache_free(ext4_fc_dentry_cachep, fc_dentry); - - return; } /* @@ -999,19 +1007,6 @@ static int ext4_fc_submit_inode_data_all(journal_t *journal) 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) @@ -1124,6 +1119,20 @@ static int ext4_fc_perform_commit(journal_t *journal) int ret = 0; u32 crc = 0; + /* + * Wait for all the handles of the current transaction to complete + * and then lock the journal. Since this is essentially the commit + * path, we don't need to wait for reserved handles. + */ + jbd2_journal_lock_updates_no_rsv(journal); + 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); + ret = ext4_fc_submit_inode_data_all(journal); if (ret) return ret; @@ -1174,6 +1183,18 @@ static int ext4_fc_perform_commit(journal_t *journal) ret = ext4_fc_write_inode(inode, &crc); if (ret) goto out; + ext4_clear_inode_state(inode, EXT4_STATE_FC_COMMITTING); + /* + * 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); +#else + wake_up_bit(&iter->i_flags, EXT4_STATE_FC_COMMITTING); +#endif spin_lock(&sbi->s_fc_lock); } spin_unlock(&sbi->s_fc_lock); @@ -1311,13 +1332,17 @@ static void ext4_fc_cleanup(journal_t *journal, int full, tid_t tid) 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, EXT4_STATE_FC_COMMITTING); if (iter->i_sync_tid <= tid) ext4_fc_reset_inode(&iter->vfs_inode); - /* 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(); + list_del_init(&iter->i_fc_list); #if (BITS_PER_LONG < 64) wake_up_bit(&iter->i_state_flags, EXT4_STATE_FC_COMMITTING); #else diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c index b6c114c11b97..7df1720f013b 100644 --- a/fs/jbd2/journal.c +++ b/fs/jbd2/journal.c @@ -58,6 +58,7 @@ MODULE_PARM_DESC(jbd2_debug, "Debugging level for jbd2"); EXPORT_SYMBOL(jbd2_journal_extend); EXPORT_SYMBOL(jbd2_journal_stop); EXPORT_SYMBOL(jbd2_journal_lock_updates); +EXPORT_SYMBOL(jbd2_journal_lock_updates_no_rsv); EXPORT_SYMBOL(jbd2_journal_unlock_updates); EXPORT_SYMBOL(jbd2_journal_get_write_access); EXPORT_SYMBOL(jbd2_journal_get_create_access); @@ -742,7 +743,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; } @@ -754,7 +754,6 @@ EXPORT_SYMBOL(jbd2_fc_begin_commit); */ static int __jbd2_fc_end_commit(journal_t *journal, tid_t tid, bool fallback) { - jbd2_journal_unlock_updates(journal); if (journal->j_fc_cleanup_callback) journal->j_fc_cleanup_callback(journal, 0, tid); write_lock(&journal->j_state_lock); diff --git a/fs/jbd2/transaction.c b/fs/jbd2/transaction.c index cb0b8d6fc0c6..4361e5c56490 100644 --- a/fs/jbd2/transaction.c +++ b/fs/jbd2/transaction.c @@ -865,25 +865,15 @@ void jbd2_journal_wait_updates(journal_t *journal) } } -/** - * jbd2_journal_lock_updates () - establish a transaction barrier. - * @journal: Journal to establish a barrier on. - * - * This locks out any further updates from being started, and blocks - * until all existing updates have completed, returning only once the - * journal is in a quiescent state with no updates running. - * - * The journal lock should not be held on entry. - */ -void jbd2_journal_lock_updates(journal_t *journal) +static void __jbd2_journal_lock_updates(journal_t *journal, bool wait_on_rsv) { jbd2_might_wait_for_commit(journal); write_lock(&journal->j_state_lock); ++journal->j_barrier_count; - /* Wait until there are no reserved handles */ - if (atomic_read(&journal->j_reserved_credits)) { + if (wait_on_rsv && atomic_read(&journal->j_reserved_credits)) { + /* Wait until there are no reserved handles */ write_unlock(&journal->j_state_lock); wait_event(journal->j_wait_reserved, atomic_read(&journal->j_reserved_credits) == 0); @@ -904,6 +894,31 @@ void jbd2_journal_lock_updates(journal_t *journal) mutex_lock(&journal->j_barrier); } +/** + * jbd2_journal_lock_updates () - establish a transaction barrier. + * @journal: Journal to establish a barrier on. + * + * This locks out any further updates from being started, and blocks + * until all existing updates have completed, returning only once the + * journal is in a quiescent state with no updates running. + * + * The journal lock should not be held on entry. + */ +void jbd2_journal_lock_updates(journal_t *journal) +{ + __jbd2_journal_lock_updates(journal, true); +} + +/** + * jbd2_journal_lock_updates_no_rsv - same as above, but doesn't + * wait for reserved handles to finish. + * @journal: Journal to establish barrier on. + */ +void jbd2_journal_lock_updates_no_rsv(journal_t *journal) +{ + __jbd2_journal_lock_updates(journal, false); +} + /** * jbd2_journal_unlock_updates () - release barrier * @journal: Journal to release the barrier on. diff --git a/include/linux/jbd2.h b/include/linux/jbd2.h index 7479f64c0939..cfac287c0ad4 100644 --- a/include/linux/jbd2.h +++ b/include/linux/jbd2.h @@ -1531,6 +1531,7 @@ bool jbd2_journal_try_to_free_buffers(journal_t *journal, struct folio *folio); extern int jbd2_journal_stop(handle_t *); extern int jbd2_journal_flush(journal_t *journal, unsigned int flags); extern void jbd2_journal_lock_updates (journal_t *); +extern void jbd2_journal_lock_updates_no_rsv(journal_t *journal); extern void jbd2_journal_unlock_updates (journal_t *); void jbd2_journal_wait_updates(journal_t *); From patchwork Wed May 29 01:19:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: harshad shirwadkar X-Patchwork-Id: 1940863 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=U2RYR9OD; 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=4ft9=na=vger.kernel.org=linux-ext4+bounces-2687-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 4Vps5z5BF8z23vC for ; Wed, 29 May 2024 11:21:11 +1000 (AEST) Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Vps5r1CtGz4wqK for ; Wed, 29 May 2024 11:21:04 +1000 (AEST) Received: by gandalf.ozlabs.org (Postfix) id 4Vps5r19MYz4wyY; Wed, 29 May 2024 11:21:04 +1000 (AEST) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com 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=U2RYR9OD; dkim-atps=neutral Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=147.75.80.249; helo=am.mirrors.kernel.org; envelope-from=linux-ext4+bounces-2687-patchwork-incoming=ozlabs.org@vger.kernel.org; receiver=ozlabs.org) 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 4Vps5q46WJz4wqK for ; Wed, 29 May 2024 11:21:03 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 0AF7A1F26B4B for ; Wed, 29 May 2024 01:21:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8DDD015AAD1; Wed, 29 May 2024 01:20:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="U2RYR9OD" X-Original-To: linux-ext4@vger.kernel.org Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) (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 DF21015A841 for ; Wed, 29 May 2024 01:20:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716945649; cv=none; b=SLZD6joDzkg17tYIehg7V+YPuH43Fk9ST0VJH30OkwOyzU+IMAfAbeHYIOWYJABsFYXLYEzjZrYEr0Z5l6kkoTqMPFX71J9/MUwu+nlC1K25zBFrUxuC0QEKtCRWgMaJgKf29pRtbxJneFaohT4gAXnPnGX/wkQZT+2aTex24Zo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716945649; c=relaxed/simple; bh=Ifn8cMlkb43xQWnu/4e+T3JV04rmE8Wyerjm7Ny33PM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HgtRIg03j5EoM7C3HUmdxc9dGCLlZwMAaS8sIoHdoEoYXfZlWnCs74tHpg4tkugW4EU1SzJ3WRi4UY6dIfVlBpkfmaN5RMNe5NWjb9EuuC2IoVNssdjbr5hPppbiCglyQhiyRK/uOxSwwRr+ONN988slYUjkZCxebi/Jse3dzAI= 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=U2RYR9OD; arc=none smtp.client-ip=209.85.216.53 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-pj1-f53.google.com with SMTP id 98e67ed59e1d1-2bfffa3c748so1325543a91.3 for ; Tue, 28 May 2024 18:20:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716945647; x=1717550447; 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=2/S79vAi7iafvt1rSzjw7cX2kBSQxhS+GF6wMgbq7Tg=; b=U2RYR9ODubolHUF13DkgOmHgh+KAVQ+hVV9L2XAwxGeQEZ/N81fNXqFlSdAhYUUjfH kWNYCDOHpzGVrmTE1hp3IV60gd4Llv6tVv02d3+volvgh6ZZdslqqU/ry96Q2vBV0sna tEHZ0FUcaJfV1yEc10AlUEACBNyKHRZjfsneWeHvmIk2409T3iJk3cjqLD2qC1Z/5Pn1 akJ0MxwEa4lqfLD454hXNGikhM+uy9r++f3K0+A2flVPa8dm9CAi+InMOGQXDaJ0iawm 0VQZnJc5hmojQwd/i7HmiXcDgmrhQrZsekfX+liTTL6DgUI2MIclJ95Jbt2tzSrXtUmU b1fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716945647; x=1717550447; 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=2/S79vAi7iafvt1rSzjw7cX2kBSQxhS+GF6wMgbq7Tg=; b=ab7IQBjWaFN4Gd49AKf4DIhM8XzY4gDcsFIzkFynRlJeN6ggmhCvK/xwvSfp1z//3N /oA4tNX5xvjfBnwoNzB9VR2upsqcZ6olH+l7mCt2h+MkdwI1c8JcW5cac0QwgSqute3J QPs+8kzVJnRG2gVJqS4+DM+K1d2HSh6vGMUbLDvCrF7+ghfSDaPh40ip2XobMibX/8Th 8KUhg9haYqyrgidw8HlZhMF9N55pXNd7kp/90amrYoCQo/gZ3mJpYUGQcpwOlATp7+Mt 5BdmUneudFBQ1fH78gEWouwlVeqox0rtpxYvIJllbL1gCx1gpckBvG8hXEzWr4oa6sAq YQ/A== X-Gm-Message-State: AOJu0YxUGM37waw40YV/k4Y7xQZWVXixeoLsavXuG+PwO09n49rEhip+ z6StC6ZP0kKN9Be/kpigtpuEMwe39zzKEIVZfobmORm4zWSYC6pzzCs7V9IN X-Google-Smtp-Source: AGHT+IE44ETEkNcdanPT7c/K9pxoYAIw7NX62HGMFfQvw695QYwXKko237U6PAlmUr0uOyeFCag5wg== X-Received: by 2002:a17:90a:c582:b0:2c0:336f:4bfd with SMTP id 98e67ed59e1d1-2c0336f4cdamr166025a91.44.1716945646947; Tue, 28 May 2024 18:20:46 -0700 (PDT) Received: from harshads.c.googlers.com.com (34.85.168.34.bc.googleusercontent.com. [34.168.85.34]) by smtp.googlemail.com with ESMTPSA id 98e67ed59e1d1-2bde008a188sm10139388a91.53.2024.05.28.18.20.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 18:20:46 -0700 (PDT) From: Harshad Shirwadkar To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, saukad@google.com, harshads@google.com, Harshad Shirwadkar , Jan Kara Subject: [PATCH v6 05/10] ext4: drop i_fc_updates from inode fc info Date: Wed, 29 May 2024 01:19:58 +0000 Message-ID: <20240529012003.4006535-6-harshadshirwadkar@gmail.com> X-Mailer: git-send-email 2.45.1.288.g0e0cd299f1-goog In-Reply-To: <20240529012003.4006535-1-harshadshirwadkar@gmail.com> References: <20240529012003.4006535-1-harshadshirwadkar@gmail.com> Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 611b8c80d99c..d802040e94df 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -1056,9 +1056,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; - /* Fast commit wait queue for this inode */ wait_queue_head_t i_fc_wait; @@ -2903,8 +2900,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 3aca5b20aac5..ecbbcaf78598 100644 --- a/fs/ext4/fast_commit.c +++ b/fs/ext4/fast_commit.c @@ -201,32 +201,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) @@ -235,48 +209,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 Wed May 29 01:19:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: harshad shirwadkar X-Patchwork-Id: 1940862 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=fdR+LMod; 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=anax=na=vger.kernel.org=linux-ext4+bounces-2688-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 4Vps5z3y0dz20f3 for ; Wed, 29 May 2024 11:21:11 +1000 (AEST) Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Vps5v5Gdlz4wyY for ; Wed, 29 May 2024 11:21:07 +1000 (AEST) Received: by gandalf.ozlabs.org (Postfix) id 4Vps5v57bvz4wyh; Wed, 29 May 2024 11:21:07 +1000 (AEST) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com 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=fdR+LMod; dkim-atps=neutral Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:4601:e00::3; helo=am.mirrors.kernel.org; envelope-from=linux-ext4+bounces-2688-patchwork-incoming=ozlabs.org@vger.kernel.org; receiver=ozlabs.org) Received: from am.mirrors.kernel.org (am.mirrors.kernel.org [IPv6:2604:1380:4601:e00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by gandalf.ozlabs.org (Postfix) with ESMTPS id 4Vps5v0dZzz4wyY for ; Wed, 29 May 2024 11:21:07 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 6612F1F2670C for ; Wed, 29 May 2024 01:21:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 14CD115AD81; Wed, 29 May 2024 01:20:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fdR+LMod" X-Original-To: linux-ext4@vger.kernel.org Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.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 739D215A862 for ; Wed, 29 May 2024 01:20:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716945649; cv=none; b=dSRsvR/1AckBWTz9Zjozg71A17ARHIkBMzsT1lRdVjtsY3VnfmXTIgnI+8ZsiSVIEYWB3HuhHL18iiF46UaQgTrmFX4+AJT7wyt2WtlclbQcNuITjK2+J59j9S0TmvZX22OIBTpIXCAuzm3ZETUZ8qjs3vR2yvktKPvT6Po7kCU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716945649; c=relaxed/simple; bh=2LjMOOdwCaq2f8AXla3z/nxLp8FAHRkWrf1X1AMlyog=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AlxS1q2+vRNHM+7HfTKLeJ4+4yr83kFkJ4n6GSBvH/nvakY7st8lrznYo8M9vAOm/xt9mc2hDlemXM+AWFkWcHtquVkJaAHPzAvXQs/NQYmq9DEnHBqIbNB7kL1w923N5SiBtYtrDLw0Lb+6fHg1dK2Vf/4MZco9/H6DW1cocn4= 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=fdR+LMod; arc=none smtp.client-ip=209.85.210.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-pf1-f182.google.com with SMTP id d2e1a72fcca58-701ae8698d8so1203421b3a.0 for ; Tue, 28 May 2024 18:20:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716945647; x=1717550447; 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=Zk1zOlPM5uCYCDX0J2Mswhw9r0DOdP5uOQ3TU9dpH6w=; b=fdR+LModQ1YQAyZR16X7qupu+P4YO1NUexX4iv3HE/l/b0kFlgWfPQ7lPQtG55+UNp OM6IaOnmi54IHuft/wvTQqa3aIhSpCsGI5yIr0veMKuEHBy9XSO6+1bZGlw3mJPuJ60U 0NCRSbe6vTchgOhiWCv0UbpM7FdFVLx/w1NdkZAxkrjnJ+yp4xjSLpMCr0NNDT9GpjET bwg6sHkvCd4mQ95tAC/o4ZA151R87TealeLUzjKIFo/7n1Q0cvX0WUWq+oCwQDB5dDB9 hOX1h3BqSqzhlYLHcp13PDwHSeeJG/DDYl5p5aXQGM8wNd4+G9IHtuhJPsr5JIuk+/Tk 2p2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716945647; x=1717550447; 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=Zk1zOlPM5uCYCDX0J2Mswhw9r0DOdP5uOQ3TU9dpH6w=; b=Jv/nnhCm+dhcAaswFok5eFqFRCXA8napYDJxyXJomlqzTFOdspa3rcEhfK+RkRxGfx 3U3Y1pWzO1Lj2asfMByGfJYLgYyZ1dykSobigMd4AFx/QhKiHuPmaGRWV5lr8Y4ith0C LrEapUgCmaiJYaKKpN3XWPpd0VkCdCifo9aYQmZ8ugp83zSRQiCkLSNnEsvLzAlCsM+z 0j3w1RR25z1Z6rvrrlgOc6k3gQ5UFeGQZH1xW+Z1DLre0f3awManFTZmDPV81FKSPzg7 BuV+NPxILV4o+xJclQ9nEixOcuoVEFXfCO91yomhMGRn+JaSeVMqMWuZq6aWgQSRtiQU 2wsA== X-Gm-Message-State: AOJu0Yy4RryTf9HqeJDs/4mHF307HAZ6luN+wQ4/vWt6LBZK98hfrSir tuRxJfkN/rBKqBEunIcUOzfVsBwgR6iUq4rxyMWWD7qUKBemAclO0RPUjnuZ X-Google-Smtp-Source: AGHT+IEK6FmImKwsCDhJTMOSDqNtAASS6G+IU1pOAAGeOCU4xXqK7QrQi90OksOltz0ZAxGOQFMVEg== X-Received: by 2002:a05:6a20:de14:b0:1b1:d402:a93f with SMTP id adf61e73a8af0-1b212df0551mr11647152637.37.1716945647451; Tue, 28 May 2024 18:20:47 -0700 (PDT) Received: from harshads.c.googlers.com.com (34.85.168.34.bc.googleusercontent.com. [34.168.85.34]) by smtp.googlemail.com with ESMTPSA id 98e67ed59e1d1-2bde008a188sm10139388a91.53.2024.05.28.18.20.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 18:20:47 -0700 (PDT) From: Harshad Shirwadkar To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, saukad@google.com, harshads@google.com, Harshad Shirwadkar , Jan Kara Subject: [PATCH v6 06/10] ext4: update code documentation Date: Wed, 29 May 2024 01:19:59 +0000 Message-ID: <20240529012003.4006535-7-harshadshirwadkar@gmail.com> X-Mailer: git-send-email 2.45.1.288.g0e0cd299f1-goog In-Reply-To: <20240529012003.4006535-1-harshadshirwadkar@gmail.com> References: <20240529012003.4006535-1-harshadshirwadkar@gmail.com> Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This patch updates code documentation to reflect the commit path changes made in this series. Signed-off-by: Harshad Shirwadkar Reviewed-by: Jan Kara --- fs/ext4/fast_commit.c | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c index ecbbcaf78598..b81b0292aa59 100644 --- a/fs/ext4/fast_commit.c +++ b/fs/ext4/fast_commit.c @@ -49,14 +49,21 @@ * 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] Lock the journal by calling jbd2_journal_lock_updates. This ensures that + * all the exsiting handles finish and no new handles can start. + * [2] Mark all the fast commit eligible inodes as undergoing fast commit + * by setting "EXT4_STATE_FC_COMMITTING" state. + * [3] 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. + * [4] Submit data buffers of all the committing inodes. + * [5] Wait for [4] to complete. + * [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 @@ -142,6 +149,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 * ----- * @@ -156,13 +170,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 Wed May 29 01:20:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: harshad shirwadkar X-Patchwork-Id: 1940861 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=OIyuYvX2; 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=nxyu=na=vger.kernel.org=linux-ext4+bounces-2689-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 4Vps5z3R9vz20Tw for ; Wed, 29 May 2024 11:21:11 +1000 (AEST) Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Vps5w20Xnz4wyh for ; Wed, 29 May 2024 11:21:08 +1000 (AEST) Received: by gandalf.ozlabs.org (Postfix) id 4Vps5w1xq9z4wyj; Wed, 29 May 2024 11:21:08 +1000 (AEST) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com 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=OIyuYvX2; dkim-atps=neutral Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:45d1:ec00::1; helo=ny.mirrors.kernel.org; envelope-from=linux-ext4+bounces-2689-patchwork-incoming=ozlabs.org@vger.kernel.org; receiver=ozlabs.org) 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 4Vps5v5s7Vz4wyh for ; Wed, 29 May 2024 11:21:07 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 04A9F1C225C9 for ; Wed, 29 May 2024 01:21:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AFA9F15A862; Wed, 29 May 2024 01:20:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="OIyuYvX2" X-Original-To: linux-ext4@vger.kernel.org Received: from mail-pj1-f43.google.com (mail-pj1-f43.google.com [209.85.216.43]) (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 09A6F15A87D for ; Wed, 29 May 2024 01:20:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716945650; cv=none; b=eJGX9/sczvbxrvlgQNG853nFu1UrWGnb+i5GoYgnlue77ZjXjHSQzIgVaWXC4qZ5N+ISRtAqHWKmxQSq4LBPqymwjEivKAe2cy6DKa6ROJXe5+Xd4JAfx/05L4PsMWU1AuetQViVan433RwNigDGXfRB2lUnpdtR1Iuxy2LY9y4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716945650; c=relaxed/simple; bh=z0oHd50cwVGs4WfCJPtlgbmzObP05NYNcKZjoGZlkLc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UDhXCQEWWd25VJcvNx2CfVfyIH+TAoty+84nBLK8FcO75XkyDZ8SZQLK/mrN35FhmhTjXCVq0/xKulSRFTGnzHLxIo8ZoLFnlce2DJ5VwyF+98MHeUhlyKB4CWgX5O7CrcX+eRxLPX7ImiGKdE9KznacKKZuMLqx7ka02AYcnQ0= 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=OIyuYvX2; arc=none smtp.client-ip=209.85.216.43 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-pj1-f43.google.com with SMTP id 98e67ed59e1d1-2bf5797973fso1308917a91.3 for ; Tue, 28 May 2024 18:20:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716945648; x=1717550448; 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=kVHN4sweglGqgyFV6V/7lREgp9t6tVbynbVY+ZIXHO0=; b=OIyuYvX2upcxDnY14RefEGSLHeDTmjCH8KjAp0RF5c7WBb7Cm8noz5EKAzAWpT/l5X vKo+se2KvdRwnm9gyifCWQDriKJptejZb0pmsPt/+NN8kLtGpnByzdrznHgMOkaIlzCi txfmNcAYn3eXweMo2O8wx9bGYDOgYlxDp7Qec7IgBng3jsN1SBYYqWBjTp3ZLk7AtSZ9 t/kaWeElAo7BAgbkL9n0g+piNkjZAeyZtgkD56nQl3psAsoSo3AGx0oyCVtaHrWjwCOJ UC9Cr+uJ9o8Q/Qc6Y4SpFISIBX9FcLr73D+gq5Q+NmFb1fm6pLgEU7ksg/OjtUZ2lPTV 01IQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716945648; x=1717550448; 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=kVHN4sweglGqgyFV6V/7lREgp9t6tVbynbVY+ZIXHO0=; b=OdyjPlxhsS+snM+cXE/83gdp1DoCUEnRDVRMkjW+vw17id5BjwI8HS26FWCjmltStj bpP1P31oXy9yHJUdKKpGDvOY/vutOGODoq9wjXOBx86nzabkY0pcqaBDRcczVNiopsQ3 1liWfuGoIFqo6B25NACQ8JdW/aHif6HDKEhuThEppzwaM7z0H650r+Gtc7+r3LDAnCLw MnLQ6QAL8CPv2rEYvXkUq58KRxqkSG1nScIVX6a8IsUC1cW7KGrXbfoltHq3loOhEhUm YmIyuGwYyCAM132cKoQ5tnNUK3x4egcBtf4ACqIpvUjo44OT099G8sEx7z94wxDO9PGT KflA== X-Gm-Message-State: AOJu0YxS2byL7tMtiroSBv5bQIJ2tGVOWift85tnLIZtHEsZ8f5xIZ63 d2/1BOzk9PTDxMEkozRquj0x0ZXbdZPwBhqxYMErK2EVCBdzwBQFLKm8xDil X-Google-Smtp-Source: AGHT+IEV9m5qmBzbsKzxZkFF5JvUA8cNwe1oi7o9cOLQd4Jt/MG75gHkaLcUyqEBquga8Bf85ogXqw== X-Received: by 2002:a17:90b:80e:b0:2bf:ae7d:4894 with SMTP id 98e67ed59e1d1-2bfae7d4bf1mr8434553a91.19.1716945648002; Tue, 28 May 2024 18:20:48 -0700 (PDT) Received: from harshads.c.googlers.com.com (34.85.168.34.bc.googleusercontent.com. [34.168.85.34]) by smtp.googlemail.com with ESMTPSA id 98e67ed59e1d1-2bde008a188sm10139388a91.53.2024.05.28.18.20.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 18:20:47 -0700 (PDT) From: Harshad Shirwadkar To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, saukad@google.com, harshads@google.com, Harshad Shirwadkar Subject: [PATCH v6 07/10] ext4: add nolock mode to ext4_map_blocks() Date: Wed, 29 May 2024 01:20:00 +0000 Message-ID: <20240529012003.4006535-8-harshadshirwadkar@gmail.com> X-Mailer: git-send-email 2.45.1.288.g0e0cd299f1-goog In-Reply-To: <20240529012003.4006535-1-harshadshirwadkar@gmail.com> References: <20240529012003.4006535-1-harshadshirwadkar@gmail.com> Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add nolock flag to ext4_map_blocks() which skips grabbing i_data_sem in ext4_map_blocks. In FC commit path, we first mark the inode as committing and thereby prevent any mutations on it. Thus, it should be safe to call ext4_map_blocks() without i_data_sem in this case. This is a workaround to the problem mentioned in RFC V4 version cover letter[1] of this patch series which pointed out that there is in incosistency between ext4_map_blocks() behavior when EXT4_GET_BLOCKS_CACHED_NOWAIT is passed. This patch gets rid of the need to call ext4_map_blocks() with EXT4_GET_BLOCKS_CACHED_NOWAIT and instead call it with EXT4_GET_BLOCKS_NOLOCK. I verified that generic/311 which failed in cached_nowait mode passes with nolock mode. [1] https://lwn.net/Articles/902022/ Signed-off-by: Harshad Shirwadkar --- fs/ext4/ext4.h | 1 + fs/ext4/fast_commit.c | 16 ++++++++-------- fs/ext4/inode.c | 14 ++++++++++++-- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index d802040e94df..196c513f82dd 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -720,6 +720,7 @@ enum { #define EXT4_GET_BLOCKS_IO_SUBMIT 0x0400 /* Caller is in the atomic contex, find extent if it has been cached */ #define EXT4_GET_BLOCKS_CACHED_NOWAIT 0x0800 +#define EXT4_GET_BLOCKS_NOLOCK 0x1000 /* * The bit position of these flags must not overlap with any of the diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c index b81b0292aa59..0b7064f8dfa5 100644 --- a/fs/ext4/fast_commit.c +++ b/fs/ext4/fast_commit.c @@ -559,13 +559,6 @@ void ext4_fc_track_inode(handle_t *handle, struct inode *inode) !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 in write mode when we go - * to sleep since the commit path needs to grab the lock while - * committing the inode. - */ - WARN_ON(lockdep_is_held_type(&ei->i_data_sem, 1)); while (ext4_test_inode_state(inode, EXT4_STATE_FC_COMMITTING)) { #if (BITS_PER_LONG < 64) @@ -898,7 +891,14 @@ static int ext4_fc_write_inode_data(struct inode *inode, u32 *crc) while (cur_lblk_off <= new_blk_size) { map.m_lblk = cur_lblk_off; map.m_len = new_blk_size - cur_lblk_off + 1; - ret = ext4_map_blocks(NULL, inode, &map, 0); + /* + * Given that this inode is being committed, + * EXT4_STATE_FC_COMMITTING is already set on this inode. + * Which means all the mutations on the inode are paused + * until the commit operation is complete. Thus it is safe + * call ext4_map_blocks() in no lock mode. + */ + ret = ext4_map_blocks(NULL, inode, &map, EXT4_GET_BLOCKS_NOLOCK); if (ret < 0) return -ECANCELED; diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 61ffbdc2fb16..f00408017c7a 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -546,7 +546,8 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode, * Try to see if we can get the block without requesting a new * file system block. */ - down_read(&EXT4_I(inode)->i_data_sem); + if (!(flags & EXT4_GET_BLOCKS_NOLOCK)) + down_read(&EXT4_I(inode)->i_data_sem); if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)) { retval = ext4_ext_map_blocks(handle, inode, map, 0); } else { @@ -573,7 +574,15 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode, ext4_es_insert_extent(inode, map->m_lblk, map->m_len, map->m_pblk, status); } - up_read((&EXT4_I(inode)->i_data_sem)); + /* + * We should never call ext4_map_blocks() in nolock mode outside + * of fast commit path. + */ + WARN_ON((flags & EXT4_GET_BLOCKS_NOLOCK) && + !ext4_test_inode_state(inode, + EXT4_STATE_FC_COMMITTING)); + if (!(flags & EXT4_GET_BLOCKS_NOLOCK)) + up_read((&EXT4_I(inode)->i_data_sem)); found: if (retval > 0 && map->m_flags & EXT4_MAP_MAPPED) { @@ -614,6 +623,7 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode, * the write lock of i_data_sem, and call get_block() * with create == 1 flag. */ + WARN_ON((flags & EXT4_GET_BLOCKS_NOLOCK) != 0); down_write(&EXT4_I(inode)->i_data_sem); /* From patchwork Wed May 29 01:20:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: harshad shirwadkar X-Patchwork-Id: 1940859 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=SXpHak+m; 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=jdfk=na=vger.kernel.org=linux-ext4+bounces-2690-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 4Vps5z1Qlgz20Pr for ; Wed, 29 May 2024 11:21:11 +1000 (AEST) Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Vps5x5qs2z4wyj for ; Wed, 29 May 2024 11:21:09 +1000 (AEST) Received: by gandalf.ozlabs.org (Postfix) id 4Vps5x5hBPz4x0H; Wed, 29 May 2024 11:21:09 +1000 (AEST) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com 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=SXpHak+m; dkim-atps=neutral Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:45d1:ec00::1; helo=ny.mirrors.kernel.org; envelope-from=linux-ext4+bounces-2690-patchwork-incoming=ozlabs.org@vger.kernel.org; receiver=ozlabs.org) 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 4Vps5x2S1Vz4wyj for ; Wed, 29 May 2024 11:21:09 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 818D01C227C5 for ; Wed, 29 May 2024 01:21:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DEC3A15AD9D; Wed, 29 May 2024 01:20:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="SXpHak+m" X-Original-To: linux-ext4@vger.kernel.org Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) (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 4351315AAC2 for ; Wed, 29 May 2024 01:20:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716945650; cv=none; b=Qa5nHA9wN6dzNyyjpjb6nOgg+Y0dQbPAacdW6y8KehJlZH0FkDeLnNZYcd5FgOdopLENvGfjiLzeWhnK9iCUCiRRofeRkYyn0x6kitIHODSwy0wWX6CZWoxJjkGgLmQt/hXv4ziCz9Rr7hpVFoQn0oU6m+QJcj2HytGHgm3sUrg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716945650; c=relaxed/simple; bh=KSCPSgwhLnLyFW+SoK3pBn60F4mgp0DKBrU7RzfDUVA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FiQHZYz7lz7ZyFFXiUT95o99J5jlXqf6JS2RKsJW6aDq+CvFWxRh5PuYlTwdc3PkRS6pIJ/U584gQKAVJzp/P3z5Hr259ojGDBpEUU+g157z4UVFH4f5pBaA9JfL9iJ+ZpM1XXGqcMsiK5P1w+/fS2eT+6imEt/qgxpFlPYqrGU= 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=SXpHak+m; arc=none smtp.client-ip=209.85.216.53 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-pj1-f53.google.com with SMTP id 98e67ed59e1d1-2bdefdeb545so1269771a91.2 for ; Tue, 28 May 2024 18:20:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716945648; x=1717550448; 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=S2S2/GMIYfaiISMrDZ46rs0IeHJKqj6oVyJRZM0V3UM=; b=SXpHak+mKeVEKjRqLsiOEFSTyXiWP5wtJi1k2ZXNK+tj6wMN/ZaqOK6ujc17LQxB1K 4YmLCZBM3qlBylT0BSIxPyrksJFD0cbsr+bYsHfKoyU6qn1UMynlL68EVZjbjcyBHORf tgKvmDeHEM2DcbCDkjlGLNUpGzD2J2RINnRR6UdoZYjEkSAo++BA6C8uSinFyX5R/Dy1 3qY8flTQJCoGfnui42fg179VEUO7uFLzJaGrX42FE1NyUK9E84Qxj+bHbuPwrg/3+6qt atqNd15Pycx7VjLT7R9JS5MZQs5eRyBcwg10HEALtc3qwwxJo+VtzbDizuAry7PnEpFB 46rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716945648; x=1717550448; 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=S2S2/GMIYfaiISMrDZ46rs0IeHJKqj6oVyJRZM0V3UM=; b=BTBg21nSE7p3JdIIvaOabgMXS706YugsJKjckUV/u04wqYIXBJRO3kP3NtTY6v/gi4 gUaSCqCaYX1WnHCUIm/gziHaB6kKGqo5ezATjqzW1pGDlfDVOaxxbTPmgsJXegqmv/X5 8IC6UQQN+u/bSsogWlAequNTqkIQEN86yahnlMcrUr3IPldZvmF8g79vMS705mrLJ4wz wUxCjf6S2eS7nAy4yMmHNE3o8PRR5byz439cZMp0IQGtmk7RVqsRE/iLRiO29gYWz/Ca mIluZFtjpo6xzGyBW0sce/3bQ2BL5YhFTDKUHQVBB1MjFMrmIHdgTGJZTSqJf021glV8 DkcA== X-Gm-Message-State: AOJu0Yz498mOTB2Wy6aC3YqynFQSsmr2TRmGIGpx+M4er1eca1w+cNoU pM7FptnJuQSZlWzzr90MTJENlq9GeMUQc6aLO+GmY0V+ymPyGkfdluG9mSo5 X-Google-Smtp-Source: AGHT+IHhTpv8Y0Xt7F2x3sFr7GhSwIhQSKBHDFp8BaSlU5rt+pLun3gQCVBUKvHpQwXvkrJlakz3Uw== X-Received: by 2002:a17:90b:917:b0:2bd:b3da:87d0 with SMTP id 98e67ed59e1d1-2bf5f4075dbmr12437855a91.41.1716945648434; Tue, 28 May 2024 18:20:48 -0700 (PDT) Received: from harshads.c.googlers.com.com (34.85.168.34.bc.googleusercontent.com. [34.168.85.34]) by smtp.googlemail.com with ESMTPSA id 98e67ed59e1d1-2bde008a188sm10139388a91.53.2024.05.28.18.20.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 18:20:48 -0700 (PDT) From: Harshad Shirwadkar To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, saukad@google.com, harshads@google.com, Harshad Shirwadkar Subject: [PATCH v6 08/10] ext4: introduce selective flushing in fast commit Date: Wed, 29 May 2024 01:20:01 +0000 Message-ID: <20240529012003.4006535-9-harshadshirwadkar@gmail.com> X-Mailer: git-send-email 2.45.1.288.g0e0cd299f1-goog In-Reply-To: <20240529012003.4006535-1-harshadshirwadkar@gmail.com> References: <20240529012003.4006535-1-harshadshirwadkar@gmail.com> Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 With fast commits, if the entire commit is contained within a single block and there isn't any data that needs a flush, we can avoid sending expensive cache flush to disk. Single block metadata only fast commits can be written using FUA to guarantee consistency. Signed-off-by: Harshad Shirwadkar --- fs/ext4/ext4.h | 12 ++++++++++++ fs/ext4/ext4_jbd2.h | 20 ++++++++++++-------- fs/ext4/fast_commit.c | 23 ++++++++++++++++++----- 3 files changed, 42 insertions(+), 13 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 196c513f82dd..3721daea2890 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -1744,6 +1744,13 @@ struct ext4_sb_info { */ struct list_head s_fc_dentry_q[2]; /* directory entry updates */ unsigned int s_fc_bytes; + + /* + * This flag indicates whether a full flush is needed on + * next fast commit. + */ + int fc_flush_required; + /* * Main fast commit lock. This lock protects accesses to the * following fields: @@ -2905,6 +2912,11 @@ 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); int ext4_fc_commit(journal_t *journal, tid_t commit_tid); +static inline void ext4_fc_mark_needs_flush(struct super_block *sb) +{ + EXT4_SB(sb)->fc_flush_required = 1; +} + int __init ext4_fc_init_dentry_cache(void); void ext4_fc_destroy_dentry_cache(void); int ext4_fc_record_regions(struct super_block *sb, int ino, diff --git a/fs/ext4/ext4_jbd2.h b/fs/ext4/ext4_jbd2.h index 0c77697d5e90..e3a4f5c49b6e 100644 --- a/fs/ext4/ext4_jbd2.h +++ b/fs/ext4/ext4_jbd2.h @@ -420,19 +420,23 @@ static inline int ext4_journal_force_commit(journal_t *journal) static inline int ext4_jbd2_inode_add_write(handle_t *handle, struct inode *inode, loff_t start_byte, loff_t length) { - if (ext4_handle_valid(handle)) - return jbd2_journal_inode_ranged_write(handle, - EXT4_I(inode)->jinode, start_byte, length); - return 0; + if (!ext4_handle_valid(handle)) + return 0; + + ext4_fc_mark_needs_flush(inode->i_sb); + return jbd2_journal_inode_ranged_write(handle, + EXT4_I(inode)->jinode, start_byte, length); } static inline int ext4_jbd2_inode_add_wait(handle_t *handle, struct inode *inode, loff_t start_byte, loff_t length) { - if (ext4_handle_valid(handle)) - return jbd2_journal_inode_ranged_wait(handle, - EXT4_I(inode)->jinode, start_byte, length); - return 0; + if (!ext4_handle_valid(handle)) + return 0; + + ext4_fc_mark_needs_flush(inode->i_sb); + return jbd2_journal_inode_ranged_wait(handle, + EXT4_I(inode)->jinode, start_byte, length); } static inline void ext4_update_inode_fsync_trans(handle_t *handle, diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c index 0b7064f8dfa5..35c89bee452c 100644 --- a/fs/ext4/fast_commit.c +++ b/fs/ext4/fast_commit.c @@ -638,11 +638,24 @@ void ext4_fc_track_range(handle_t *handle, struct inode *inode, ext4_lblk_t star static void ext4_fc_submit_bh(struct super_block *sb, bool is_tail) { blk_opf_t write_flags = REQ_SYNC; - struct buffer_head *bh = EXT4_SB(sb)->s_fc_bh; + struct ext4_sb_info *sbi = EXT4_SB(sb); + struct buffer_head *bh = sbi->s_fc_bh; + int old = 1, new = 0; + + if (!is_tail) { + /* + * This commit has at least 1 non-tail block, + * thus FLUSH is required. + */ + ext4_fc_mark_needs_flush(sb); + } else { + /* Use cmpxchg to ensure that no flush requrest is lost. */ + if (cmpxchg(&sbi->fc_flush_required, old, new)) + /* Old value was 1, so request a flush. */ + write_flags |= REQ_PREFLUSH; + write_flags |= REQ_FUA; + } - /* Add REQ_FUA | REQ_PREFLUSH only its tail */ - if (test_opt(sb, BARRIER) && is_tail) - write_flags |= REQ_FUA | REQ_PREFLUSH; lock_buffer(bh); set_buffer_dirty(bh); set_buffer_uptodate(bh); @@ -1090,7 +1103,7 @@ static int ext4_fc_perform_commit(journal_t *journal) * 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) + if (sbi->fc_flush_required && journal->j_fs_dev != journal->j_dev) blkdev_issue_flush(journal->j_fs_dev); blk_start_plug(&plug); From patchwork Wed May 29 01:20:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: harshad shirwadkar X-Patchwork-Id: 1940864 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=mXNkQt7l; 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=vicn=na=vger.kernel.org=linux-ext4+bounces-2691-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 4Vps613QP3z20Pr for ; Wed, 29 May 2024 11:21:13 +1000 (AEST) Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Vps6130Fkz4wqK for ; Wed, 29 May 2024 11:21:13 +1000 (AEST) Received: by gandalf.ozlabs.org (Postfix) id 4Vps612y4Xz4wqM; Wed, 29 May 2024 11:21:13 +1000 (AEST) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com 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=mXNkQt7l; dkim-atps=neutral Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:45d1:ec00::1; helo=ny.mirrors.kernel.org; envelope-from=linux-ext4+bounces-2691-patchwork-incoming=ozlabs.org@vger.kernel.org; receiver=ozlabs.org) 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 4Vps606p2jz4wqK for ; Wed, 29 May 2024 11:21:12 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 1CAEC1C223A9 for ; Wed, 29 May 2024 01:21:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7341615AAC2; Wed, 29 May 2024 01:20:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mXNkQt7l" X-Original-To: linux-ext4@vger.kernel.org Received: from mail-pj1-f50.google.com (mail-pj1-f50.google.com [209.85.216.50]) (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 CA50E2B9A9 for ; Wed, 29 May 2024 01:20:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716945651; cv=none; b=bEBlP98tyb1zCV42bNOFxkuKmAowzHMrXafmyLD2h2+f3wzaXpK9P9bhKbgla2VTFq5cIjUzS9M7N9oTQ1eoeqRvAKqv8ztqL+9BRe8nxiWyC4P0OehHOdj5ZCYGihZTf4yVrE/Iwh1w0RqcYUSyPE5t5T4YAVx8PWtLF16R8I8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716945651; c=relaxed/simple; bh=xh2TQYl+ZvamQoGDbFVmHEXtnnu9utvOxnTPrySxZ8I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aXGxBD9Wx1HWVEYYri7xWymD09qu2Dv1VfSz+LXHJsq+hdyZgZnXNLSPFtlwLzqRo/VNclWZhsbWmstuALrFJyePUrdjYV99gioYaLTVivaTnpPReImpAtJBAYJioXOIAerxYfmSsiGn3D/oPKOvpfA8bm3hSBnNQYASFNcBzJQ= 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=mXNkQt7l; arc=none smtp.client-ip=209.85.216.50 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-pj1-f50.google.com with SMTP id 98e67ed59e1d1-2bf59381a11so1333121a91.1 for ; Tue, 28 May 2024 18:20:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716945649; x=1717550449; 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=fQK6pvOzGFoN+zAtNDhFm96sqdDQj9t0TKCt5gMtB/M=; b=mXNkQt7l0565LC8wVVBm3GSPyCV8qEPgklDKNOv8TQRe2OBCebEzCq7gRZ3gsM0c5d 9Hl0iHi3k6SeNtmuQdGEWJrHJNj5ZaEf5mCit5/OXSzkiBRNyRyUzlnt88m1nvHuDWtq Q6rIO2n97WPH1H5sXwKcDcSE1ozyHooumNhdkURknu3d6FFmOFDxJmlrJbFuTcIEiHUq 6tdXnkuFx4l/04Djzokzw6lv+Avf9qsgB7FP/fJDwtV1wbJyEpHTNh2c1YFgYLwNh3Qb kyIi8mByTYvA2NMPTiwonDfzceVtwSm6yFl51kY50rsfXWUCydGUv1Be337bc+k/2KKp p9dQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716945649; x=1717550449; 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=fQK6pvOzGFoN+zAtNDhFm96sqdDQj9t0TKCt5gMtB/M=; b=D8zJCsEoHCFqOteNwV3o+j/o4BtjbjT4ocpXIZFy6PAXmbq0Clrt3JWK+AfVrTV/eq Vufd+icNBT55PdbWbfq6D8Le8R4JqecZxsyj6++0EsP+P5D+NIGlF17jD6FsOfyhe+1D 4jSKz4odCMO98z4AHF/5h/wUKSqCSBh1mcafTqd5E5CdXANYkg1BKzZDYYB/k07ba4CQ bEhpH8M2hndMAxHBseD3ph6DlSUFltOX5tGlHpsHCPgWLaAfSDM9Rg1u+et/XsIGKjhF uW13tI7fKY1U4FwMwAcg3pEH+ZFj6IopGjeSglBnt2fFAZQ5KqohQDNItEy105wWBNrj fPTQ== X-Gm-Message-State: AOJu0YwuQUE+UGuUaIZKCxer9flFGbK6bhvMh7QvOqdQp3biZG7nVKpE L3cLqfP3eq9vCOq6UCPnb9EblNEs9AR6FLTZ8I0745ZmCFVQ+dHBdxzd/tw9 X-Google-Smtp-Source: AGHT+IFqTeKMoaliqHpkPPpDvA55l2n0oow3vYOM4/KE8lKBk2jD4sdeAEZrFR54nYxYiKfD4SrXjQ== X-Received: by 2002:a17:90a:1fc9:b0:2bd:f45e:6105 with SMTP id 98e67ed59e1d1-2bf5ee1be4cmr12821325a91.22.1716945648869; Tue, 28 May 2024 18:20:48 -0700 (PDT) Received: from harshads.c.googlers.com.com (34.85.168.34.bc.googleusercontent.com. [34.168.85.34]) by smtp.googlemail.com with ESMTPSA id 98e67ed59e1d1-2bde008a188sm10139388a91.53.2024.05.28.18.20.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 18:20:48 -0700 (PDT) From: Harshad Shirwadkar To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, saukad@google.com, harshads@google.com, Harshad Shirwadkar Subject: [PATCH v6 09/10] ext4: temporarily elevate commit thread priority Date: Wed, 29 May 2024 01:20:02 +0000 Message-ID: <20240529012003.4006535-10-harshadshirwadkar@gmail.com> X-Mailer: git-send-email 2.45.1.288.g0e0cd299f1-goog In-Reply-To: <20240529012003.4006535-1-harshadshirwadkar@gmail.com> References: <20240529012003.4006535-1-harshadshirwadkar@gmail.com> Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 --- 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 3721daea2890..d52df8a85271 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -2287,10 +2287,12 @@ static inline int ext4_forced_shutdown(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)) + /* * Minimum number of groups in a flexgroup before we separate out diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c index 35c89bee452c..55a13d3ff681 100644 --- a/fs/ext4/fast_commit.c +++ b/fs/ext4/fast_commit.c @@ -1205,6 +1205,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); @@ -1212,6 +1213,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); @@ -1242,6 +1244,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) { @@ -1256,6 +1267,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 @@ -1265,6 +1277,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 77173ec91e49..18d9d2631559 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -1833,7 +1833,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 @@ -5211,7 +5210,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 = @@ -6471,7 +6470,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 Wed May 29 01:20:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: harshad shirwadkar X-Patchwork-Id: 1940865 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=Ix4iOjgN; 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=vman=na=vger.kernel.org=linux-ext4+bounces-2692-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 4Vps6415wgz20Pr for ; Wed, 29 May 2024 11:21:16 +1000 (AEST) Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Vps640f4zz4wqK for ; Wed, 29 May 2024 11:21:16 +1000 (AEST) Received: by gandalf.ozlabs.org (Postfix) id 4Vps640bM6z4wqM; Wed, 29 May 2024 11:21:16 +1000 (AEST) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com 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=Ix4iOjgN; dkim-atps=neutral Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:45d1:ec00::1; helo=ny.mirrors.kernel.org; envelope-from=linux-ext4+bounces-2692-patchwork-incoming=ozlabs.org@vger.kernel.org; receiver=ozlabs.org) 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 4Vps634V0Zz4wqK for ; Wed, 29 May 2024 11:21:15 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id B3F0A1C2253B for ; Wed, 29 May 2024 01:21:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0653E15ADAB; Wed, 29 May 2024 01:20:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Ix4iOjgN" X-Original-To: linux-ext4@vger.kernel.org Received: from mail-pg1-f179.google.com (mail-pg1-f179.google.com [209.85.215.179]) (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 612C615AD90 for ; Wed, 29 May 2024 01:20:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716945651; cv=none; b=mtFBP89jV/K9dFTbj9iFwhYyk7s0QmWjXTGKX44tEDQSUZIqw/aIGoce/WsMKsfjHTE1epG0NN9OgbW1Jhlqd8vSzHTqPw/4qjhZlaocc9oqlgZI/ZKBCDlgwZMG8dLgBs+lFTfnx+C2aoHgnANXPOBTfR3MPE8jf96h19kxrdA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716945651; c=relaxed/simple; bh=bwGBMgQbowWGAFfW/cK1IFyBxqCMtPKEyEzNT093x5k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Gsm1mUICdzDNHwgO2mZwAN036VMKQT0f0Sfb2BvsatyJhrmQWrx+Hi5A+CXE8Q14PPp12M5uZktfOwHxI3qFtylyFcol7B2YsiMgcwP2hdGWQ/Zi5ryxNYSUoHaPzadOAQq5qwYhaYoAbQMj5FTwN/MlSxo8UyVEoDgacfkOiRs= 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=Ix4iOjgN; arc=none smtp.client-ip=209.85.215.179 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-f179.google.com with SMTP id 41be03b00d2f7-6818e31e5baso1289591a12.1 for ; Tue, 28 May 2024 18:20:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716945649; x=1717550449; 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=1+/x2/YkXI59JKMsbGunwKDNHOeQj6UDhHq+onbOIj0=; b=Ix4iOjgN6sCDIjWNQXaLKDGHPxwvBh85AYUjYP7YMYA8iv7SXOyACsmTXdXeFJNV9N 5tl5xfekxnJuN5nvwyZ9erSbTQeVLndYIe4Z50aFTuqY6xh6vkY4QuOt1dnERnO2syvW BMQf5hVw7vnsZpMYsIz2cw26ehoPaE6MtBAzYJOkwZSRmr4DxyHFGubmIjbrnkP3YL01 XRqiMXo8IaIEIsV+hDjF90QvRdh0f4L83LXRFK9H2aJbdw/18OjiuX9fuMGjArjt+2tO tQ+IGSWjYs8ZapkqcFuiWcnzRgBbKWnKe9QsZdqFN9r7Jb1ZeE3inRwPASjY11/MXsR8 1wiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716945649; x=1717550449; 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=1+/x2/YkXI59JKMsbGunwKDNHOeQj6UDhHq+onbOIj0=; b=jHaD8Um7nPFCo5CrkWIAAfunMKGL4YpTjSmXuQVCJyMMtUiAfWnrJIrvbxo0TkJHpu RU4V76lJPuF+cdE52/yBGsyBv/Wvp6zbt6mRncDDB5NwY6Yu6Y07Nz2/KdwF0yJYRKRS 4w2bVJ7Z37QStdqaLwQ+Qqyri3SwjhWyrXKipn4Ee746Z8IP8vM76XFeXQDgPmFcYqeF clF1nBlPN84u2hQq9Li83l8wtUpZUeQpMavZVQ+tSPuyQE7TwsDVEmWNfYq7kHb5Z5sl 9p7iYn5ginJuxeLhrWRHSBnEiy1FGOxI3hjBq7lfwEXlWmdePqWqeA9aotsVHVTyLk7e 6ZsQ== X-Gm-Message-State: AOJu0YwMdjlYYEcs8+hUwjL1QVNoCVExNP+kwi7fpdysADPNW2Jsj8wg BKvwCSGlprURD8RANAB/0Rzy4O5elT8RTIXlKLd2zmqw0Wr8Zymzq7V6/q0S X-Google-Smtp-Source: AGHT+IF/w5w/yzTa/hb/VnaeYIJK7Y0Z4jS4rioe5FyRPhEIW9xdJKxuQoJGR8YTSI5+9GbT5t0B6w== X-Received: by 2002:a05:6a21:2d05:b0:1b0:260e:fe71 with SMTP id adf61e73a8af0-1b212e7fba7mr16600370637.60.1716945649374; Tue, 28 May 2024 18:20:49 -0700 (PDT) Received: from harshads.c.googlers.com.com (34.85.168.34.bc.googleusercontent.com. [34.168.85.34]) by smtp.googlemail.com with ESMTPSA id 98e67ed59e1d1-2bde008a188sm10139388a91.53.2024.05.28.18.20.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 18:20:49 -0700 (PDT) From: Harshad Shirwadkar To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, saukad@google.com, harshads@google.com, Harshad Shirwadkar Subject: [PATCH v6 10/10] ext4: make fast commit ineligible on ext4_reserve_inode_write failure Date: Wed, 29 May 2024 01:20:03 +0000 Message-ID: <20240529012003.4006535-11-harshadshirwadkar@gmail.com> X-Mailer: git-send-email 2.45.1.288.g0e0cd299f1-goog In-Reply-To: <20240529012003.4006535-1-harshadshirwadkar@gmail.com> References: <20240529012003.4006535-1-harshadshirwadkar@gmail.com> Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Fast commit by default makes every inode on which ext4_reserve_inode_write() is called. Thus, if that function fails for some reason, make the next fast commit ineligible. Signed-off-by: Harshad Shirwadkar --- fs/ext4/fast_commit.c | 1 + fs/ext4/fast_commit.h | 1 + fs/ext4/inode.c | 29 ++++++++++++++++++----------- include/trace/events/ext4.h | 7 +++++-- 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c index 55a13d3ff681..e7cac190527c 100644 --- a/fs/ext4/fast_commit.c +++ b/fs/ext4/fast_commit.c @@ -2291,6 +2291,7 @@ static const char * const fc_ineligible_reasons[] = { [EXT4_FC_REASON_FALLOC_RANGE] = "Falloc range op", [EXT4_FC_REASON_INODE_JOURNAL_DATA] = "Data journalling", [EXT4_FC_REASON_ENCRYPTED_FILENAME] = "Encrypted filename", + [EXT4_FC_REASON_INODE_RSV_WRITE_FAIL] = "Inode reserve write failure" }; int ext4_fc_info_show(struct seq_file *seq, void *v) diff --git a/fs/ext4/fast_commit.h b/fs/ext4/fast_commit.h index 2fadb2c4780c..f7f85c3dd3af 100644 --- a/fs/ext4/fast_commit.h +++ b/fs/ext4/fast_commit.h @@ -97,6 +97,7 @@ enum { EXT4_FC_REASON_FALLOC_RANGE, EXT4_FC_REASON_INODE_JOURNAL_DATA, EXT4_FC_REASON_ENCRYPTED_FILENAME, + EXT4_FC_REASON_INODE_RSV_WRITE_FAIL, EXT4_FC_REASON_MAX }; diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index f00408017c7a..8fd6e5637542 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -5729,20 +5729,27 @@ ext4_reserve_inode_write(handle_t *handle, struct inode *inode, { int err; - if (unlikely(ext4_forced_shutdown(inode->i_sb))) - return -EIO; + if (unlikely(ext4_forced_shutdown(inode->i_sb))) { + err = -EIO; + goto out; + } err = ext4_get_inode_loc(inode, iloc); - if (!err) { - BUFFER_TRACE(iloc->bh, "get_write_access"); - err = ext4_journal_get_write_access(handle, inode->i_sb, - iloc->bh, EXT4_JTR_NONE); - if (err) { - brelse(iloc->bh); - iloc->bh = NULL; - } - ext4_fc_track_inode(handle, inode); + if (err) + goto out; + + BUFFER_TRACE(iloc->bh, "get_write_access"); + err = ext4_journal_get_write_access(handle, inode->i_sb, + iloc->bh, EXT4_JTR_NONE); + if (err) { + brelse(iloc->bh); + iloc->bh = NULL; } + ext4_fc_track_inode(handle, inode); +out: + if (err) + ext4_fc_mark_ineligible(inode->i_sb, + EXT4_FC_REASON_INODE_RSV_WRITE_FAIL, handle); ext4_std_error(inode->i_sb, err); return err; } diff --git a/include/trace/events/ext4.h b/include/trace/events/ext4.h index a697f4b77162..597845d5c1e8 100644 --- a/include/trace/events/ext4.h +++ b/include/trace/events/ext4.h @@ -105,6 +105,7 @@ TRACE_DEFINE_ENUM(EXT4_FC_REASON_RENAME_DIR); TRACE_DEFINE_ENUM(EXT4_FC_REASON_FALLOC_RANGE); TRACE_DEFINE_ENUM(EXT4_FC_REASON_INODE_JOURNAL_DATA); TRACE_DEFINE_ENUM(EXT4_FC_REASON_ENCRYPTED_FILENAME); +TRACE_DEFINE_ENUM(EXT4_FC_REASON_INODE_RSV_WRITE_FAIL); TRACE_DEFINE_ENUM(EXT4_FC_REASON_MAX); #define show_fc_reason(reason) \ @@ -118,7 +119,8 @@ TRACE_DEFINE_ENUM(EXT4_FC_REASON_MAX); { EXT4_FC_REASON_RENAME_DIR, "RENAME_DIR"}, \ { EXT4_FC_REASON_FALLOC_RANGE, "FALLOC_RANGE"}, \ { EXT4_FC_REASON_INODE_JOURNAL_DATA, "INODE_JOURNAL_DATA"}, \ - { EXT4_FC_REASON_ENCRYPTED_FILENAME, "ENCRYPTED_FILENAME"}) + { EXT4_FC_REASON_ENCRYPTED_FILENAME, "ENCRYPTED_FILENAME"}, \ + { EXT4_FC_REASON_INODE_RSV_WRITE_FAIL, "INODE_RSV_WRITE_FAIL"}) TRACE_DEFINE_ENUM(CR_POWER2_ALIGNED); TRACE_DEFINE_ENUM(CR_GOAL_LEN_FAST); @@ -2805,7 +2807,7 @@ TRACE_EVENT(ext4_fc_stats, ), TP_printk("dev %d,%d fc ineligible reasons:\n" - "%s:%u, %s:%u, %s:%u, %s:%u, %s:%u, %s:%u, %s:%u, %s:%u, %s:%u, %s:%u" + "%s:%u, %s:%u, %s:%u, %s:%u, %s:%u, %s:%u, %s:%u, %s:%u, %s:%u, %s:%u, %s:%u" "num_commits:%lu, ineligible: %lu, numblks: %lu", MAJOR(__entry->dev), MINOR(__entry->dev), FC_REASON_NAME_STAT(EXT4_FC_REASON_XATTR), @@ -2818,6 +2820,7 @@ TRACE_EVENT(ext4_fc_stats, FC_REASON_NAME_STAT(EXT4_FC_REASON_FALLOC_RANGE), FC_REASON_NAME_STAT(EXT4_FC_REASON_INODE_JOURNAL_DATA), FC_REASON_NAME_STAT(EXT4_FC_REASON_ENCRYPTED_FILENAME), + FC_REASON_NAME_STAT(EXT4_FC_REASON_INODE_RSV_WRITE_FAIL), __entry->fc_commits, __entry->fc_ineligible_commits, __entry->fc_numblks) );