From patchwork Thu Mar 28 12:52:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heming Zhao X-Patchwork-Id: 13608510 Received: from mail-lf1-f46.google.com (mail-lf1-f46.google.com [209.85.167.46]) (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 0313E6A00E for ; Thu, 28 Mar 2024 12:52:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711630337; cv=none; b=FqcU1Ep+YeGZOF4631bYdrw4GHmt2BgcCbD984PudlLY6SN/1mpbi8ufZQoPVzFbxEq9bzFgEG7Dz8UJtWM14E8cA1PoEbF+jv/+w1jSu9BgyyNXoBmmfyUQKYIPAB1uGM0qYMQxMljJNEfpmozYTyHyQteyiCsEfKL9GXGKKoI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711630337; c=relaxed/simple; bh=imb3MNf4Pp2vBOhzStoa3rlG1DotpG9IzJ5VrrCXNpI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=aKEkjY82Gv8ra/YYDjYjbyx4YIAt9RBGBFskdQhL5y9Nt7oRujNCvrxir6mr/f0GENGaZSFQmGf1ZNAF4P22nVCcfnxJ4NSCbsBrQHnBgw6Kf6gTvwprEnJVJ98QUEZhhP3q3AFoTVV1Tm3jdiXIPC5NS1HRdJIYFTo5jDdcTwM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=TBs8Mpqm; arc=none smtp.client-ip=209.85.167.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="TBs8Mpqm" Received: by mail-lf1-f46.google.com with SMTP id 2adb3069b0e04-515caffe2bcso293564e87.0 for ; Thu, 28 Mar 2024 05:52:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1711630332; x=1712235132; darn=lists.linux.dev; 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=kkpfNK7hnAe/EaYVUi8T+bWpK7zjkObEnm/mBVOkkHE=; b=TBs8MpqmnaDp2Hc8jCmrx8i2LUPy/KFzQhDk5egOEEoNVf4zYwUTmwi4ufNvSkSEWF 7VgLQVgBh+RtOxW/2pcr6Q1p5lWNPtbVcCdGhyre3EWKpsILmzrCgwZp3sJSyJwVY3Oz 7IbOFeD8efQzUFY+JHalawQO0c2Cfws0WM4T20p+BUW7uhQ8HebqudOTH4XE6y0GHwNW HT2Le8EP7c3GMvW8zVf0LaQOTfNEqxxdpxhK5LliaYDrOBFQXT+VMQ4XGDtGrzDHTNQI Q9wK9LhIk7Ppb0xZ8OEcOVLJxf0qsqV9w6XUvImxHhbdWl78iIOYoXrTGk6UfbbAIFKE 5TMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711630332; x=1712235132; 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=kkpfNK7hnAe/EaYVUi8T+bWpK7zjkObEnm/mBVOkkHE=; b=aH07c0hTlonlCy+Vy22kib3idinxYMe5qbxQsUCXZpWvBkwDLVTVQs251P0cFUoOhh O1HHJVLDKGRhEZtg9mqcENHvzyBnBIWPO2jXuuraODBrFi2hONnZiey2fqXo2XZgtLAM IXbif4zzlxCSm9OXsHWyibLtvXpHQftds/aXxVZYdDQcFqFPk7Uvlba1/SupS0vthyUQ Q/u9Qt1vKz0d3xfL2LiAMy7xwhxeFWzB/3QoTn6ESbz+J3ROO2x72fIHEy5GlLNfH4Aa 6q7JkQQJUQdkQlKCBrLndVSrFm2xWZaJlX5Qs4q6YNOS11KouBZMzzC/pVID9WMcjxm3 uqCg== X-Forwarded-Encrypted: i=1; AJvYcCXzAjHKy9jyTuzv5IxHa0E+XwuE4Uzbpoa//HCFQclNIT+CmOZynze2UCFcGlCyFDKT+qd3+6wpB5w+ZdlX91kiweZlOng+cXJsugg= X-Gm-Message-State: AOJu0Yyi3LPI//5gAU+/ccQxDBX8f0AvSIWRURG3JjYY9QXlHQM4qZ9r nxq09bZGJP+1dwo2sbFrmKr2i3yWg20kS5FtRcFs6PZpw7FaKIKl2sdpc/e8b64= X-Google-Smtp-Source: AGHT+IH79D5YYm4P+Fr2HHqUSZmt61xsNfw42c9TSuIjXNlgOqyzSCpVoaEFSaucRvrJKbb9aKUT6g== X-Received: by 2002:a2e:998d:0:b0:2d6:ab62:2eae with SMTP id w13-20020a2e998d000000b002d6ab622eaemr1645249lji.17.1711630331740; Thu, 28 Mar 2024 05:52:11 -0700 (PDT) Received: from c73.suse.cz ([202.127.77.110]) by smtp.gmail.com with ESMTPSA id mo4-20020a1709030a8400b001dd8d298693sm1485010plb.23.2024.03.28.05.52.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 05:52:11 -0700 (PDT) From: Heming Zhao To: joseph.qi@linux.alibaba.com Cc: Heming Zhao , ocfs2-devel@lists.linux.dev, ailiop@suse.com Subject: [PATCH v6 1/4] ocfs2: improve write IO performance when fragmentation is high Date: Thu, 28 Mar 2024 20:52:00 +0800 Message-Id: <20240328125203.20892-2-heming.zhao@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240328125203.20892-1-heming.zhao@suse.com> References: <20240328125203.20892-1-heming.zhao@suse.com> Precedence: bulk X-Mailing-List: ocfs2-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The group_search function ocfs2_cluster_group_search() should bypass groups with insufficient space to avoid unnecessary searches. This patch is particularly useful when ocfs2 is handling huge number small files, and volume fragmentation is very high. In this case, ocfs2 is busy with looking up available la window from //global_bitmap. This patch introduces a new member in the Group Description (gd) struct called 'bg_contig_free_bits', representing the max contigous free bits in this gd. When ocfs2 allocates a new la window from //global_bitmap, 'bg_contig_free_bits' helps expedite the search process. Let's image below path. 1. la state (->local_alloc_state) is set THROTTLED or DISABLED. 2. when user delete a large file and trigger ocfs2_local_alloc_seen_free_bits set osb->local_alloc_state unconditionally. 3. a write IOs thread run and trigger the worst performance path ``` ocfs2_reserve_clusters_with_limit ocfs2_reserve_local_alloc_bits ocfs2_local_alloc_slide_window //[1] + ocfs2_local_alloc_reserve_for_window //[2] + ocfs2_local_alloc_new_window //[3] ocfs2_recalc_la_window ``` [1]: will be called when la window bits used up. [2]: under la state is ENABLED, and this func only check global_bitmap free bits, it will succeed in general. [3]: will use the default la window size to search clusters then fail. ocfs2_recalc_la_window attempts other la window sizes. the timing complexity is O(n^4), resulting in a significant time cost for scanning global bitmap. This leads to a dramatic slowdown in write I/Os (e.g., user space 'dd'). i.e. an ocfs2 partition size: 1.45TB, cluster size: 4KB, la window default size: 106MB. The partition is fragmentation by creating & deleting huge mount of small files. before this patch, the timing of [3] should be (the number got from real world): - la window size change order (size: MB): 106, 53, 26.5, 13, 6.5, 3.25, 1.6, 0.8 only 0.8MB succeed, 0.8MB also triggers la window to disable. ocfs2_local_alloc_new_window retries 8 times, first 7 times totally runs in worst case. - group chain number: 242 ocfs2_claim_suballoc_bits calls for-loop 242 times - each chain has 49 block group ocfs2_search_chain calls while-loop 49 times - each bg has 32256 blocks ocfs2_block_group_find_clear_bits calls while-loop for 32256 bits. for ocfs2_find_next_zero_bit uses ffz() to find zero bit, let's use (32256/64) (this is not worst value) for timing calucation. the loop times: 7*242*49*(32256/64) = 41835024 (~42 million times) In the worst case, user space writes 1MB data will trigger 42M scanning times. under this patch, the timing is '7*242*49 = 83006', reduced by three orders of magnitude. Signed-off-by: Heming Zhao Reviewed-by: Joseph Qi --- v5: fix sparse warning for _ocfs2_free_suballoc_bits(), v4 fix is wrong. v4: fix sparse warning: - in ocfs2_update_last_group_and_inode(), change 'old_bg_contig_free_bits' type from 'u16' to '__le16'. - in _ocfs2_free_suballoc_bits(), do le16_to_cpu convert for assigning 'old_bg_contig_free_bits'. v3: 1. Fix wrong var length for 'struct ocfs2_group_desc' .bg_contig_free_bits, change from '__le32' to '__le16'. 2. change all related code to use '__le16' instead of '__le32'. Please note: change ocfs2_find_max_contig_free_bits() input parameters and return type to 'u16'. v2: 1. fix wrong length converting from cpu_to_le16() to cpu_to_le32() for setting bg->bg_contig_free_bits. 2. change ocfs2_find_max_contig_free_bits return type from 'void' to 'unsigned int'. 3. restore ocfs2_block_group_set_bits() input parameters style, change parameter 'failure_path' to 'fastpath'. 4. after <3>, add new parameter 'unsigned int max_contig_bits'. 5. after <3>, restore define 'struct ocfs2_suballoc_result' from 'suballoc.h' to 'suballoc.c'. 6. modify some code indent error. --- fs/ocfs2/move_extents.c | 2 +- fs/ocfs2/ocfs2_fs.h | 3 +- fs/ocfs2/resize.c | 8 ++++ fs/ocfs2/suballoc.c | 100 ++++++++++++++++++++++++++++++++++++---- fs/ocfs2/suballoc.h | 6 ++- 5 files changed, 108 insertions(+), 11 deletions(-) diff --git a/fs/ocfs2/move_extents.c b/fs/ocfs2/move_extents.c index 1f9ed117e78b..f9d6a4f9ca92 100644 --- a/fs/ocfs2/move_extents.c +++ b/fs/ocfs2/move_extents.c @@ -685,7 +685,7 @@ static int ocfs2_move_extent(struct ocfs2_move_extents_context *context, } ret = ocfs2_block_group_set_bits(handle, gb_inode, gd, gd_bh, - goal_bit, len); + goal_bit, len, 0, 0); if (ret) { ocfs2_rollback_alloc_dinode_counts(gb_inode, gb_bh, len, le16_to_cpu(gd->bg_chain)); diff --git a/fs/ocfs2/ocfs2_fs.h b/fs/ocfs2/ocfs2_fs.h index 7aebdbf5cc0a..c93689b568fe 100644 --- a/fs/ocfs2/ocfs2_fs.h +++ b/fs/ocfs2/ocfs2_fs.h @@ -883,7 +883,8 @@ struct ocfs2_group_desc __le16 bg_free_bits_count; /* Free bits count */ __le16 bg_chain; /* What chain I am in. */ /*10*/ __le32 bg_generation; - __le32 bg_reserved1; + __le16 bg_contig_free_bits; /* max contig free bits length */ + __le16 bg_reserved1; __le64 bg_next_group; /* Next group in my list, in blocks */ /*20*/ __le64 bg_parent_dinode; /* dinode which owns me, in diff --git a/fs/ocfs2/resize.c b/fs/ocfs2/resize.c index d65d43c61857..c4a4016d3866 100644 --- a/fs/ocfs2/resize.c +++ b/fs/ocfs2/resize.c @@ -91,6 +91,8 @@ static int ocfs2_update_last_group_and_inode(handle_t *handle, u16 cl_bpc = le16_to_cpu(cl->cl_bpc); u16 cl_cpg = le16_to_cpu(cl->cl_cpg); u16 old_bg_clusters; + u16 contig_bits; + __le16 old_bg_contig_free_bits; trace_ocfs2_update_last_group_and_inode(new_clusters, first_new_cluster); @@ -122,6 +124,11 @@ static int ocfs2_update_last_group_and_inode(handle_t *handle, le16_add_cpu(&group->bg_free_bits_count, -1 * backups); } + contig_bits = ocfs2_find_max_contig_free_bits(group->bg_bitmap, + le16_to_cpu(group->bg_bits), 0); + old_bg_contig_free_bits = group->bg_contig_free_bits; + group->bg_contig_free_bits = cpu_to_le16(contig_bits); + ocfs2_journal_dirty(handle, group_bh); /* update the inode accordingly. */ @@ -160,6 +167,7 @@ static int ocfs2_update_last_group_and_inode(handle_t *handle, le16_add_cpu(&group->bg_free_bits_count, backups); le16_add_cpu(&group->bg_bits, -1 * num_bits); le16_add_cpu(&group->bg_free_bits_count, -1 * num_bits); + group->bg_contig_free_bits = old_bg_contig_free_bits; } out: if (ret) diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c index 166c8918c825..1a7b53fd468d 100644 --- a/fs/ocfs2/suballoc.c +++ b/fs/ocfs2/suballoc.c @@ -50,6 +50,10 @@ struct ocfs2_suballoc_result { u64 sr_blkno; /* The first allocated block */ unsigned int sr_bit_offset; /* The bit in the bg */ unsigned int sr_bits; /* How many bits we claimed */ + unsigned int sr_max_contig_bits; /* The length for contiguous + * free bits, only available + * for cluster group + */ }; static u64 ocfs2_group_from_res(struct ocfs2_suballoc_result *res) @@ -1272,6 +1276,26 @@ static int ocfs2_test_bg_bit_allocatable(struct buffer_head *bg_bh, return ret; } +u16 ocfs2_find_max_contig_free_bits(void *bitmap, + u16 total_bits, u16 start) +{ + u16 offset, free_bits; + u16 contig_bits = 0; + + while (start < total_bits) { + offset = ocfs2_find_next_zero_bit(bitmap, total_bits, start); + if (offset == total_bits) + break; + + start = ocfs2_find_next_bit(bitmap, total_bits, offset); + free_bits = start - offset; + if (contig_bits < free_bits) + contig_bits = free_bits; + } + + return contig_bits; +} + static int ocfs2_block_group_find_clear_bits(struct ocfs2_super *osb, struct buffer_head *bg_bh, unsigned int bits_wanted, @@ -1280,6 +1304,7 @@ static int ocfs2_block_group_find_clear_bits(struct ocfs2_super *osb, { void *bitmap; u16 best_offset, best_size; + u16 prev_best_size = 0; int offset, start, found, status = 0; struct ocfs2_group_desc *bg = (struct ocfs2_group_desc *) bg_bh->b_data; @@ -1308,6 +1333,7 @@ static int ocfs2_block_group_find_clear_bits(struct ocfs2_super *osb, /* got a zero after some ones */ found = 1; start = offset + 1; + prev_best_size = best_size; } if (found > best_size) { best_size = found; @@ -1320,6 +1346,8 @@ static int ocfs2_block_group_find_clear_bits(struct ocfs2_super *osb, } } + /* best_size will be allocated, we save prev_best_size */ + res->sr_max_contig_bits = prev_best_size; if (best_size) { res->sr_bit_offset = best_offset; res->sr_bits = best_size; @@ -1337,11 +1365,15 @@ int ocfs2_block_group_set_bits(handle_t *handle, struct ocfs2_group_desc *bg, struct buffer_head *group_bh, unsigned int bit_off, - unsigned int num_bits) + unsigned int num_bits, + unsigned int max_contig_bits, + int fastpath) { int status; void *bitmap = bg->bg_bitmap; int journal_type = OCFS2_JOURNAL_ACCESS_WRITE; + unsigned int start = bit_off + num_bits; + u16 contig_bits; /* All callers get the descriptor via * ocfs2_read_group_descriptor(). Any corruption is a code bug. */ @@ -1373,6 +1405,28 @@ int ocfs2_block_group_set_bits(handle_t *handle, while(num_bits--) ocfs2_set_bit(bit_off++, bitmap); + /* + * this is optimize path, caller set old contig value + * in max_contig_bits to bypass finding action. + */ + if (fastpath) { + bg->bg_contig_free_bits = cpu_to_le16(max_contig_bits); + } else if (ocfs2_is_cluster_bitmap(alloc_inode)) { + /* + * Usually, the block group bitmap allocates only 1 bit + * at a time, while the cluster group allocates n bits + * each time. Therefore, we only save the contig bits for + * the cluster group. + */ + contig_bits = ocfs2_find_max_contig_free_bits(bitmap, + le16_to_cpu(bg->bg_bits), start); + if (contig_bits > max_contig_bits) + max_contig_bits = contig_bits; + bg->bg_contig_free_bits = cpu_to_le16(max_contig_bits); + } else { + bg->bg_contig_free_bits = 0; + } + ocfs2_journal_dirty(handle, group_bh); bail: @@ -1486,7 +1540,12 @@ static int ocfs2_cluster_group_search(struct inode *inode, BUG_ON(!ocfs2_is_cluster_bitmap(inode)); - if (gd->bg_free_bits_count) { + if (le16_to_cpu(gd->bg_contig_free_bits) && + le16_to_cpu(gd->bg_contig_free_bits) < bits_wanted) + return -ENOSPC; + + /* ->bg_contig_free_bits may un-initialized, so compare again */ + if (le16_to_cpu(gd->bg_free_bits_count) >= bits_wanted) { max_bits = le16_to_cpu(gd->bg_bits); /* Tail groups in cluster bitmaps which aren't cpg @@ -1555,7 +1614,7 @@ static int ocfs2_block_group_search(struct inode *inode, BUG_ON(min_bits != 1); BUG_ON(ocfs2_is_cluster_bitmap(inode)); - if (bg->bg_free_bits_count) { + if (le16_to_cpu(bg->bg_free_bits_count) >= bits_wanted) { ret = ocfs2_block_group_find_clear_bits(OCFS2_SB(inode->i_sb), group_bh, bits_wanted, le16_to_cpu(bg->bg_bits), @@ -1715,7 +1774,8 @@ static int ocfs2_search_one_group(struct ocfs2_alloc_context *ac, } ret = ocfs2_block_group_set_bits(handle, alloc_inode, gd, group_bh, - res->sr_bit_offset, res->sr_bits); + res->sr_bit_offset, res->sr_bits, + res->sr_max_contig_bits, 0); if (ret < 0) { ocfs2_rollback_alloc_dinode_counts(alloc_inode, ac->ac_bh, res->sr_bits, @@ -1849,7 +1909,9 @@ static int ocfs2_search_chain(struct ocfs2_alloc_context *ac, bg, group_bh, res->sr_bit_offset, - res->sr_bits); + res->sr_bits, + res->sr_max_contig_bits, + 0); if (status < 0) { ocfs2_rollback_alloc_dinode_counts(alloc_inode, ac->ac_bh, res->sr_bits, chain); @@ -2163,7 +2225,9 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle, bg, bg_bh, res->sr_bit_offset, - res->sr_bits); + res->sr_bits, + res->sr_max_contig_bits, + 0); if (ret < 0) { ocfs2_rollback_alloc_dinode_counts(ac->ac_inode, ac->ac_bh, res->sr_bits, chain); @@ -2382,11 +2446,13 @@ static int ocfs2_block_group_clear_bits(handle_t *handle, struct buffer_head *group_bh, unsigned int bit_off, unsigned int num_bits, + unsigned int max_contig_bits, void (*undo_fn)(unsigned int bit, unsigned long *bmap)) { int status; unsigned int tmp; + u16 contig_bits; struct ocfs2_group_desc *undo_bg = NULL; struct journal_head *jh; @@ -2433,6 +2499,20 @@ static int ocfs2_block_group_clear_bits(handle_t *handle, num_bits); } + /* + * TODO: even 'num_bits == 1' (the worst case, release 1 cluster), + * we still need to rescan whole bitmap. + */ + if (ocfs2_is_cluster_bitmap(alloc_inode)) { + contig_bits = ocfs2_find_max_contig_free_bits(bg->bg_bitmap, + le16_to_cpu(bg->bg_bits), 0); + if (contig_bits > max_contig_bits) + max_contig_bits = contig_bits; + bg->bg_contig_free_bits = cpu_to_le16(max_contig_bits); + } else { + bg->bg_contig_free_bits = 0; + } + if (undo_fn) spin_unlock(&jh->b_state_lock); @@ -2459,6 +2539,7 @@ static int _ocfs2_free_suballoc_bits(handle_t *handle, struct ocfs2_chain_list *cl = &fe->id2.i_chain; struct buffer_head *group_bh = NULL; struct ocfs2_group_desc *group; + __le16 old_bg_contig_free_bits = 0; /* The alloc_bh comes from ocfs2_free_dinode() or * ocfs2_free_clusters(). The callers have all locked the @@ -2483,9 +2564,11 @@ static int _ocfs2_free_suballoc_bits(handle_t *handle, BUG_ON((count + start_bit) > le16_to_cpu(group->bg_bits)); + if (ocfs2_is_cluster_bitmap(alloc_inode)) + old_bg_contig_free_bits = group->bg_contig_free_bits; status = ocfs2_block_group_clear_bits(handle, alloc_inode, group, group_bh, - start_bit, count, undo_fn); + start_bit, count, 0, undo_fn); if (status < 0) { mlog_errno(status); goto bail; @@ -2496,7 +2579,8 @@ static int _ocfs2_free_suballoc_bits(handle_t *handle, if (status < 0) { mlog_errno(status); ocfs2_block_group_set_bits(handle, alloc_inode, group, group_bh, - start_bit, count); + start_bit, count, + le16_to_cpu(old_bg_contig_free_bits), 1); goto bail; } diff --git a/fs/ocfs2/suballoc.h b/fs/ocfs2/suballoc.h index 9c74eace3adc..b481b834857d 100644 --- a/fs/ocfs2/suballoc.h +++ b/fs/ocfs2/suballoc.h @@ -79,12 +79,16 @@ void ocfs2_rollback_alloc_dinode_counts(struct inode *inode, struct buffer_head *di_bh, u32 num_bits, u16 chain); +u16 ocfs2_find_max_contig_free_bits(void *bitmap, + u16 total_bits, u16 start); int ocfs2_block_group_set_bits(handle_t *handle, struct inode *alloc_inode, struct ocfs2_group_desc *bg, struct buffer_head *group_bh, unsigned int bit_off, - unsigned int num_bits); + unsigned int num_bits, + unsigned int max_contig_bits, + int fastpath); int ocfs2_claim_metadata(handle_t *handle, struct ocfs2_alloc_context *ac, From patchwork Thu Mar 28 12:52:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heming Zhao X-Patchwork-Id: 13608511 Received: from mail-lj1-f176.google.com (mail-lj1-f176.google.com [209.85.208.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B2EAA7D081 for ; Thu, 28 Mar 2024 12:52:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711630338; cv=none; b=jPnC1Ba0pSRFqOOxa/hHgRofTln7+DXFffV0DHXuJVXrh7oufDH4O0uY/bYyD18I73CUtFB4bDK8oGlmZAFVahHzE84Qjqe4vi429DBhg5m88ceDb/kNoBOBqmTClHjRe6co1qxeEfMqgMvNrSdzKp1Hbsgw4klfEsUqL3vFdrM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711630338; c=relaxed/simple; bh=nTuHhvt8CyqP9dpP/QY6dNmL9bTXzerA/Fpc5OSxcx4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=gOiLP9mrY26Cxbold2aLPxSDFk/8SoZcbJKklIT1WvFU96bj59f9NWD5VzDukS4D5/YvqeiqivefKE3PV7hjiHgzWoeTtZ63kOijvSybxGY3KaPB76o18VFI9h4DPl0uDHurm1Rkbba8LGwr//EO7jOHa41dVCFjrqyZLqQMMrs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=dHjAkc+L; arc=none smtp.client-ip=209.85.208.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="dHjAkc+L" Received: by mail-lj1-f176.google.com with SMTP id 38308e7fff4ca-2d700beb60bso18266081fa.1 for ; Thu, 28 Mar 2024 05:52:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1711630334; x=1712235134; darn=lists.linux.dev; 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=33lTEKlfYZ+4TVHmeUJgqqIAct6UiE+Fxnnd1gmXmXk=; b=dHjAkc+L2DGsSPpLwRrTtRcfNvAHoAsgPPq2gWmqlb8TQTLm31Sp8BUB8Kzf+86vuZ SVX7mzREC8bBMxxlbuWd9HQXfMCzKJTHVy5v1fZ1uzqv09cj/MAh1gb7TL9r+z8L2Id8 OP/04dzJ3qxzxZe8gR07mVNV5KpTqmWSEdtqwDdtCmt05jwolWlxx9Wap03EXLHAAXpo EzoqHUVDDGX7Z5cvCekjPxFKvBORqca0Y3ExaundRXvaqbcrQfwJ7PSC3N9zX/MQbJoo Rx4XcpPZe9dpSW2YNLb7wpHHtk3YrzzDBsyA7bFxUvqFp5r5f5K0SWy8DSP3qkmKsBXM 7KYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711630334; x=1712235134; 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=33lTEKlfYZ+4TVHmeUJgqqIAct6UiE+Fxnnd1gmXmXk=; b=FV1YyMwzZQRhRPLXRQ41XZEKS1rQAl03A/xiWsd3iy+QJ7xMgX7MLZUV9CeKS9YqB7 AEofqsVyGGn0MAmbf2R+dI0fCWZsEL6G9hevwyv2jSp46I1h6IuymgX5ecBympNguk+a AdWdGFHIkis8n933W4Rd0WK+qUxl4DlvfG1RTmFRTasfM0p2AbWoK8a/dhoep1zj768+ Lk/znkFVrc2fRalfovqrJZ8bidoky8N1v7OJNQTx4HSejUwtdWDqlCLO8dLSo0UiTo/M r3/7BqZkYb4rt7cLMDHPy26VQTyGqXsoIPGpDex3AAlff5Mzwt+2TrCmn6DfEVisBSJq j3fA== X-Forwarded-Encrypted: i=1; AJvYcCXFqLUkwirwrHhR3JxMl9go16vcgiCYx3evOs+vDCjQoTTwvI+NARGVKSlYRJ5B2JyhCqpifM7/oZ1VXOBRVkjd8c4F5K/CXVkTdEg= X-Gm-Message-State: AOJu0YwwgE73qEGSXIqmWre+4mX0ChSFBj/O1Our3vTwxQOMuQexWuk2 bySHpQooWyQ3a2o11IGotJN8aXmRoh8rx0fWg8RcjqVhy8zTX1oph45d1KDP7KobdgW6xGi72PX l X-Google-Smtp-Source: AGHT+IFBf7+5jszUYdZnh8cChm333YO+YoCZlX4lhrnYkXeIcVtglJp6v2BT23cNGWXsiItsCDCJ6w== X-Received: by 2002:a2e:9018:0:b0:2d6:fa7a:a670 with SMTP id h24-20020a2e9018000000b002d6fa7aa670mr2645728ljg.33.1711630333876; Thu, 28 Mar 2024 05:52:13 -0700 (PDT) Received: from c73.suse.cz ([202.127.77.110]) by smtp.gmail.com with ESMTPSA id mo4-20020a1709030a8400b001dd8d298693sm1485010plb.23.2024.03.28.05.52.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 05:52:13 -0700 (PDT) From: Heming Zhao To: joseph.qi@linux.alibaba.com Cc: Heming Zhao , ocfs2-devel@lists.linux.dev, ailiop@suse.com Subject: [PATCH v6 2/4] ocfs2: adjust enabling place for la window Date: Thu, 28 Mar 2024 20:52:01 +0800 Message-Id: <20240328125203.20892-3-heming.zhao@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240328125203.20892-1-heming.zhao@suse.com> References: <20240328125203.20892-1-heming.zhao@suse.com> Precedence: bulk X-Mailing-List: ocfs2-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 After introducing gd->bg_contig_free_bits, the code path 'ocfs2_cluster_group_search() => ocfs2_local_alloc_seen_free_bits()' becomes death when all the gd->bg_contig_free_bits are set to the correct value. This patch relocates ocfs2_local_alloc_seen_free_bits() to a more appropriate location. (The new place being ocfs2_block_group_set_bits().) In ocfs2_local_alloc_seen_free_bits(), the scope of the spin-lock has been adjusted to reduce meaningless lock races. e.g: when userspace creates & deletes 1 cluster_size files in parallel, acquiring the spin-lock in ocfs2_local_alloc_seen_free_bits() is totally pointless and impedes IO performance. Signed-off-by: Heming Zhao Reviewed-by: Joseph Qi --- v5: put 'osb->local_alloc_state = OCFS2_LA_ENABLED' into the if block v4: first verion --- fs/ocfs2/localalloc.c | 11 ++++++----- fs/ocfs2/suballoc.c | 9 ++------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c index c803c10dd97e..b893ef56accd 100644 --- a/fs/ocfs2/localalloc.c +++ b/fs/ocfs2/localalloc.c @@ -212,14 +212,15 @@ static inline int ocfs2_la_state_enabled(struct ocfs2_super *osb) void ocfs2_local_alloc_seen_free_bits(struct ocfs2_super *osb, unsigned int num_clusters) { - spin_lock(&osb->osb_lock); - if (osb->local_alloc_state == OCFS2_LA_DISABLED || - osb->local_alloc_state == OCFS2_LA_THROTTLED) - if (num_clusters >= osb->local_alloc_default_bits) { + if (num_clusters >= osb->local_alloc_default_bits) { + spin_lock(&osb->osb_lock); + if (osb->local_alloc_state == OCFS2_LA_DISABLED || + osb->local_alloc_state == OCFS2_LA_THROTTLED) { cancel_delayed_work(&osb->la_enable_wq); osb->local_alloc_state = OCFS2_LA_ENABLED; } - spin_unlock(&osb->osb_lock); + spin_unlock(&osb->osb_lock); + } } void ocfs2_la_enable_worker(struct work_struct *work) diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c index 1a7b53fd468d..fc80cb3dbcd1 100644 --- a/fs/ocfs2/suballoc.c +++ b/fs/ocfs2/suballoc.c @@ -1374,6 +1374,7 @@ int ocfs2_block_group_set_bits(handle_t *handle, int journal_type = OCFS2_JOURNAL_ACCESS_WRITE; unsigned int start = bit_off + num_bits; u16 contig_bits; + struct ocfs2_super *osb = OCFS2_SB(alloc_inode->i_sb); /* All callers get the descriptor via * ocfs2_read_group_descriptor(). Any corruption is a code bug. */ @@ -1423,6 +1424,7 @@ int ocfs2_block_group_set_bits(handle_t *handle, if (contig_bits > max_contig_bits) max_contig_bits = contig_bits; bg->bg_contig_free_bits = cpu_to_le16(max_contig_bits); + ocfs2_local_alloc_seen_free_bits(osb, max_contig_bits); } else { bg->bg_contig_free_bits = 0; } @@ -1589,13 +1591,6 @@ static int ocfs2_cluster_group_search(struct inode *inode, * of bits. */ if (min_bits <= res->sr_bits) search = 0; /* success */ - else if (res->sr_bits) { - /* - * Don't show bits which we'll be returning - * for allocation to the local alloc bitmap. - */ - ocfs2_local_alloc_seen_free_bits(osb, res->sr_bits); - } } return search; From patchwork Thu Mar 28 12:52:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heming Zhao X-Patchwork-Id: 13608512 Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) (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 A8F707EEE2 for ; Thu, 28 Mar 2024 12:52:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711630339; cv=none; b=rvMXEW3n3HmDQydytgopbcPuAwoBNjepMHwWjgvEOTFZZEr+bksU6yXOXu1go74r4Yj9lh1gMRTUx7bCdNnlGcsQOhONHzeffwro9aPkQaVuxpeHRiHZvNbU20osg/5NeIl0oOp4VmDyAAewMycOSw7I9XRIA09btvgjb9DXuEg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711630339; c=relaxed/simple; bh=c2OcaMlBTf0OpwNL6uBEN13ipPiBvZxZhbmMHP7c7OQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=FI122Zk2/Y+623H+QXuNsrYAUTudgCEpsYSQgy7ZDb0a7AD4wz3QmD/LS9/lg6CRLQaMi+c1WZPZgqVLj/0kZLssciCntuIzqGQJikWZLPoupkDxBLgMRw0xVN8TbEykNW9isMeTNabtXwifX1bxvffoKHTR4iIwl4YoyvCBfJA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=Xuo2ASdK; arc=none smtp.client-ip=209.85.221.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="Xuo2ASdK" Received: by mail-wr1-f52.google.com with SMTP id ffacd0b85a97d-33ed6078884so1099604f8f.1 for ; Thu, 28 Mar 2024 05:52:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1711630336; x=1712235136; darn=lists.linux.dev; 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=OyQzkJYm6B+aiFDUTwEwfL8v6xKkMoU1AHOq5tAxH4k=; b=Xuo2ASdK5ypI0qBh3r/4zU9x6U99QLtUE57nz2sDQtBftiefrIUi0N9Isphm1dIuIV LRvqv537SagAYQl2z0tmcysxyFRWtbdqzcqqGhnOyEmSzFsQGJTG7TsAg9oN49EySxay jZ4d5bP1CJC0A/yItWczhb7t+x5nOaPk8aomsSo+WJPhEaqqrah5JetRDwnBXpRwTgp4 B1UQzbcbpt291kLLBqTSt4eZP2eiUE+9sFxWO2GgPhkaZzYxdk8LPqQgtmK2wnQZUY3+ Q2PkWqhdqv1mUH4QeLo7dI1ckBglmf8kmpEc+eroFZl/SQKvrXwHWN88DWnJ+PEKghp0 hHEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711630336; x=1712235136; 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=OyQzkJYm6B+aiFDUTwEwfL8v6xKkMoU1AHOq5tAxH4k=; b=Kfi1T96iOk9j5Yrf6v9DTxOrjyWmYEv2BNovnepGtHoxMBBbZIjEa1jhaswhT+gG2H WHCncW/CTTI97kP0h7Uufo2W32ixTcbIXOVpq3V8R4v5CWqaqmsMcBHP7+LzK906sMSU t6GaR1OBCCB2vzRrhU+C76Hl4zUPgtX5Q3mCtae6/ohytBtnQXV1evFs8b1YlUU5TPIh c1fUzGOSmY6t3JYI6FFtss9NSQ5vHjodbwtBHWO840xXId4VxouWQJd14DafIohmSADr 1WbumhPfkQQZ1LzliyPVbCAL2DuGuYZacPiIudvegZY6Vb3W9Ob0LZo/GwwfCKs63PK/ ZNZw== X-Forwarded-Encrypted: i=1; AJvYcCVAtn8IuemhGyTby6bgm+neEn40omoBDGpWUwQAdEv6q8lpYf67G9VtHJHW1Fji13scGDi0Bxif8t+PaIbaM1DZUXIoIxNgzKBJW0I= X-Gm-Message-State: AOJu0YxgQFbB1+CtV2EyUBK6KGQOP3XXbvMnGt1Zj0o4HCCF7PHwjjbP nMypsAPPa5wTeJvJS50Sc1Co6NPm0Wc5pHS2j0p93lCEnZBWCx5PbhW0DUe3JjU= X-Google-Smtp-Source: AGHT+IEty9VmNVcMJSzanveCr0ncnFa6Cb/bK/F4wJBOrKVCKarHhj8N5hXtxY1pzEViTKidHgL4HA== X-Received: by 2002:a5d:6d4c:0:b0:33e:aead:af07 with SMTP id k12-20020a5d6d4c000000b0033eaeadaf07mr2032440wri.27.1711630336015; Thu, 28 Mar 2024 05:52:16 -0700 (PDT) Received: from c73.suse.cz ([202.127.77.110]) by smtp.gmail.com with ESMTPSA id mo4-20020a1709030a8400b001dd8d298693sm1485010plb.23.2024.03.28.05.52.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 05:52:15 -0700 (PDT) From: Heming Zhao To: joseph.qi@linux.alibaba.com Cc: Heming Zhao , ocfs2-devel@lists.linux.dev, ailiop@suse.com Subject: [PATCH v6 3/4] ocfs2: speed up chain-list searching Date: Thu, 28 Mar 2024 20:52:02 +0800 Message-Id: <20240328125203.20892-4-heming.zhao@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240328125203.20892-1-heming.zhao@suse.com> References: <20240328125203.20892-1-heming.zhao@suse.com> Precedence: bulk X-Mailing-List: ocfs2-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add short-circuit code to speed up searching Signed-off-by: Heming Zhao Reviewed-by: Joseph Qi --- v5: - split 'sparse warnings' fix to a separate patch - amend the commit log according to patch change v4: first version --- fs/ocfs2/suballoc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c index fc80cb3dbcd1..823e2ec38b2d 100644 --- a/fs/ocfs2/suballoc.c +++ b/fs/ocfs2/suballoc.c @@ -2008,7 +2008,7 @@ static int ocfs2_claim_suballoc_bits(struct ocfs2_alloc_context *ac, for (i = 0; i < le16_to_cpu(cl->cl_next_free_rec); i ++) { if (i == victim) continue; - if (!cl->cl_recs[i].c_free) + if (le32_to_cpu(cl->cl_recs[i].c_free) < bits_wanted) continue; ac->ac_chain = i; From patchwork Thu Mar 28 12:52:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heming Zhao X-Patchwork-Id: 13608513 Received: from mail-lj1-f171.google.com (mail-lj1-f171.google.com [209.85.208.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EDD587F7D5 for ; Thu, 28 Mar 2024 12:52:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711630343; cv=none; b=mYtsaubJhPEHTUWp6Ac0eCUM2PiZX0qoWXkV2cCHJboQ9LbEhoWTwnrna2i/RpG5S17xQ2J4i1a35Z6TkJEks8CBlFEoZ+AsljRqj1ufaYmC2tuQ+2Ke24jqADtoJtQ8eyW2b23TwhqaD+nO+9IjZ6YJnm/B5rNzmQMiCLoBhp8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711630343; c=relaxed/simple; bh=4qAbtu7FC5oW6nCPkQEd2hw3p58+fVIsK3SHKEIsP+8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=OTQ4MsOw2e0JRtLkSM9vW3WiOIPr2vcoJdPoH1f02cECp+TnU+sPVLPGqDfHyUTLG5/WX4iZnO0Gx4qeD/CrUDFToKxq9epckFKLyDGGLv86Rbtb5u4wulM91yNJoHKFdJfhXWxJIzncOQePTS5Kle83FYcYNFH6mnDtbcvW298= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=ObpyLL3s; arc=none smtp.client-ip=209.85.208.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="ObpyLL3s" Received: by mail-lj1-f171.google.com with SMTP id 38308e7fff4ca-2d476d7972aso14073511fa.1 for ; Thu, 28 Mar 2024 05:52:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1711630338; x=1712235138; darn=lists.linux.dev; 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=aeIVdSIQ3vPuE5f2AnPiX76qckzruvyY7WupSUKfbbA=; b=ObpyLL3s+R/fD8kmPut9+MGhud4c18VCxsBbZucvopNHpDNtGYbEDe+IKIaSVAu2cV osoqKFg19EAxNkFYgXqTP362B8Cl4Z4zx8H9unMJG1ErqXmaXEJoqoddrqGowtdEVztV z+GnisdeLwN/bcbeWgmq63H9ccVB8qgHPC2N+CtHhw1qGoDH85Ba8bQMZM2W+QY8sD8z c6Hk7GTHV6R0Fx/GQnuOg97ry8J6Wi65vpAhJvDSvPbDZOjwu7iUqVlG3vLlubiUVn0o J+E8XtCdytDQKMTOM/L8n8gCGT/xZNmlK0MiDiXrXpu1fcvU312oI7SNKl+LKQKU1MgH mqYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711630338; x=1712235138; 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=aeIVdSIQ3vPuE5f2AnPiX76qckzruvyY7WupSUKfbbA=; b=eVeJya4aDC7E6ewEumoNZ3NSQIZcn6NN5cB3spWBedX25M5bIic3dBvvHHOrjFfrJH GEAwapy5hscsqWUtSr4HXjNXLWc4YDWshQgwEEXtgW7O+e9rrJYmb3KoPdrSkHxVS9qQ Iq/pNTsTp6FGgxtzgvZmRqtUDqwajRtxpQKmI93L/EnkRqzmPqvKMfBwfgYIjXBO0xft CR/2hUheXAxgEEBDuQ1m8qHtMQcAgRyinXrjwpZs/b/ro6vOm/kM+CizRagsq61TIppw 69i6e9vxuBbXcZPLgDXKleYQZtYeUK8l2y4/CYRAfXuz70LFVckqyAuTTWl1lVuQ73u1 u6tA== X-Forwarded-Encrypted: i=1; AJvYcCUBPvbGzNXyGOfOUro1OIssGF9wMPdBc5E8hpFsafO2az2BD2nC07/WBJGLBV/415fxuV5VNYvm4HJ78eXqnjFIIdPIAzR5ceHMDKk= X-Gm-Message-State: AOJu0Ywh0rqlEe/ieuqOYw+wSs1j2+nO7BN2r2gW8w/eCogYurvc8Fyr cdGqOVaNIPzhyVDShr9dJbcIqiFOIDwOoFhgk1h9j0Vu4KVxn6TVZ2q7C4ZSRiA= X-Google-Smtp-Source: AGHT+IHh+IznnHHyPx3I358EjPHLe8xKNM1fMpaxbdC7SbMMfEK2A5YIcUklVcGJcOHti5GcZrIW+Q== X-Received: by 2002:a2e:a721:0:b0:2d6:8ac7:455 with SMTP id s33-20020a2ea721000000b002d68ac70455mr1919686lje.40.1711630338181; Thu, 28 Mar 2024 05:52:18 -0700 (PDT) Received: from c73.suse.cz ([202.127.77.110]) by smtp.gmail.com with ESMTPSA id mo4-20020a1709030a8400b001dd8d298693sm1485010plb.23.2024.03.28.05.52.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 05:52:17 -0700 (PDT) From: Heming Zhao To: joseph.qi@linux.alibaba.com Cc: Heming Zhao , ocfs2-devel@lists.linux.dev, ailiop@suse.com Subject: [PATCH v6 4/4] ocfs2: fix sparse warnings Date: Thu, 28 Mar 2024 20:52:03 +0800 Message-Id: <20240328125203.20892-5-heming.zhao@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240328125203.20892-1-heming.zhao@suse.com> References: <20240328125203.20892-1-heming.zhao@suse.com> Precedence: bulk X-Mailing-List: ocfs2-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 1. fs/ocfs2/localalloc.c:1224:41: warning: incorrect type in argument 1 (different base types) fs/ocfs2/localalloc.c:1224:41: expected unsigned long long val1 fs/ocfs2/localalloc.c:1224:41: got restricted __le32 [usertype] la_bm_off 2. fs/ocfs2/export.c:258:32: warning: cast to restricted __le32 fs/ocfs2/export.c:259:33: warning: cast to restricted __le32 fs/ocfs2/export.c:260:32: warning: cast to restricted __le32 fs/ocfs2/export.c:272:32: warning: cast to restricted __le32 fs/ocfs2/export.c:273:33: warning: cast to restricted __le32 fs/ocfs2/export.c:274:32: warning: cast to restricted __le32 3. fs/ocfs2/inode.c:1623:13: warning: context imbalance in 'ocfs2_inode_cache_lock' - wrong count at exit fs/ocfs2/inode.c:1630:13: warning: context imbalance in 'ocfs2_inode_cache_unlock' - unexpected unlock 4. fs/ocfs2/refcounttree.c:633:27: warning: incorrect type in assignment (different base types) fs/ocfs2/refcounttree.c:633:27: expected restricted __le32 [usertype] rf_generation fs/ocfs2/refcounttree.c:633:27: got unsigned int 5. fs/ocfs2/dlm/dlmdomain.c:1316:20: warning: context imbalance in 'dlm_query_nodeinfo_handler' - different lock contexts for basic block Signed-off-by: Heming Zhao Reviewed-by: Joseph Qi --- v6: - restore the original code in dlm/dlmrecovery.c v5: (first version) - localalloc.c fix (No: 1) is split from v4 patch 3/3. - new sparse warnings fixes (No: 2~6) for other files. --- fs/ocfs2/dlm/dlmdomain.c | 11 +++++------ fs/ocfs2/export.c | 12 ++++++------ fs/ocfs2/inode.c | 2 ++ fs/ocfs2/localalloc.c | 4 ++-- fs/ocfs2/refcounttree.c | 2 +- 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/fs/ocfs2/dlm/dlmdomain.c b/fs/ocfs2/dlm/dlmdomain.c index 5c04dde99981..2e0a2f338282 100644 --- a/fs/ocfs2/dlm/dlmdomain.c +++ b/fs/ocfs2/dlm/dlmdomain.c @@ -1274,7 +1274,7 @@ static int dlm_query_nodeinfo_handler(struct o2net_msg *msg, u32 len, { struct dlm_query_nodeinfo *qn; struct dlm_ctxt *dlm = NULL; - int locked = 0, status = -EINVAL; + int status = -EINVAL; qn = (struct dlm_query_nodeinfo *) msg->buf; @@ -1290,12 +1290,11 @@ static int dlm_query_nodeinfo_handler(struct o2net_msg *msg, u32 len, } spin_lock(&dlm->spinlock); - locked = 1; if (dlm->joining_node != qn->qn_nodenum) { mlog(ML_ERROR, "Node %d queried nodes on domain %s but " "joining node is %d\n", qn->qn_nodenum, qn->qn_domain, dlm->joining_node); - goto bail; + goto unlock; } /* Support for node query was added in 1.1 */ @@ -1305,14 +1304,14 @@ static int dlm_query_nodeinfo_handler(struct o2net_msg *msg, u32 len, "but active dlm protocol is %d.%d\n", qn->qn_nodenum, qn->qn_domain, dlm->dlm_locking_proto.pv_major, dlm->dlm_locking_proto.pv_minor); - goto bail; + goto unlock; } status = dlm_match_nodes(dlm, qn); +unlock: + spin_unlock(&dlm->spinlock); bail: - if (locked) - spin_unlock(&dlm->spinlock); spin_unlock(&dlm_domain_lock); return status; diff --git a/fs/ocfs2/export.c b/fs/ocfs2/export.c index b8b6a191b5cb..96b684763b39 100644 --- a/fs/ocfs2/export.c +++ b/fs/ocfs2/export.c @@ -255,9 +255,9 @@ static struct dentry *ocfs2_fh_to_dentry(struct super_block *sb, if (fh_len < 3 || fh_type > 2) return NULL; - handle.ih_blkno = (u64)le32_to_cpu(fid->raw[0]) << 32; - handle.ih_blkno |= (u64)le32_to_cpu(fid->raw[1]); - handle.ih_generation = le32_to_cpu(fid->raw[2]); + handle.ih_blkno = (u64)le32_to_cpu((__force __le32)fid->raw[0]) << 32; + handle.ih_blkno |= (u64)le32_to_cpu((__force __le32)fid->raw[1]); + handle.ih_generation = le32_to_cpu((__force __le32)fid->raw[2]); return ocfs2_get_dentry(sb, &handle); } @@ -269,9 +269,9 @@ static struct dentry *ocfs2_fh_to_parent(struct super_block *sb, if (fh_type != 2 || fh_len < 6) return NULL; - parent.ih_blkno = (u64)le32_to_cpu(fid->raw[3]) << 32; - parent.ih_blkno |= (u64)le32_to_cpu(fid->raw[4]); - parent.ih_generation = le32_to_cpu(fid->raw[5]); + parent.ih_blkno = (u64)le32_to_cpu((__force __le32)fid->raw[3]) << 32; + parent.ih_blkno |= (u64)le32_to_cpu((__force __le32)fid->raw[4]); + parent.ih_generation = le32_to_cpu((__force __le32)fid->raw[5]); return ocfs2_get_dentry(sb, &parent); } diff --git a/fs/ocfs2/inode.c b/fs/ocfs2/inode.c index 999111bfc271..2cc5c99fe941 100644 --- a/fs/ocfs2/inode.c +++ b/fs/ocfs2/inode.c @@ -1621,6 +1621,7 @@ static struct super_block *ocfs2_inode_cache_get_super(struct ocfs2_caching_info } static void ocfs2_inode_cache_lock(struct ocfs2_caching_info *ci) +__acquires(&oi->ip_lock) { struct ocfs2_inode_info *oi = cache_info_to_inode(ci); @@ -1628,6 +1629,7 @@ static void ocfs2_inode_cache_lock(struct ocfs2_caching_info *ci) } static void ocfs2_inode_cache_unlock(struct ocfs2_caching_info *ci) +__releases(&oi->ip_lock) { struct ocfs2_inode_info *oi = cache_info_to_inode(ci); diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c index b893ef56accd..86cdd60bcaab 100644 --- a/fs/ocfs2/localalloc.c +++ b/fs/ocfs2/localalloc.c @@ -336,7 +336,7 @@ int ocfs2_load_local_alloc(struct ocfs2_super *osb) "found = %u, set = %u, taken = %u, off = %u\n", num_used, le32_to_cpu(alloc->id1.bitmap1.i_used), le32_to_cpu(alloc->id1.bitmap1.i_total), - OCFS2_LOCAL_ALLOC(alloc)->la_bm_off); + le32_to_cpu(OCFS2_LOCAL_ALLOC(alloc)->la_bm_off)); status = -EINVAL; goto bail; @@ -1221,7 +1221,7 @@ static int ocfs2_local_alloc_new_window(struct ocfs2_super *osb, OCFS2_LOCAL_ALLOC(alloc)->la_bitmap); trace_ocfs2_local_alloc_new_window_result( - OCFS2_LOCAL_ALLOC(alloc)->la_bm_off, + le32_to_cpu(OCFS2_LOCAL_ALLOC(alloc)->la_bm_off), le32_to_cpu(alloc->id1.bitmap1.i_total)); bail: diff --git a/fs/ocfs2/refcounttree.c b/fs/ocfs2/refcounttree.c index 3f80a56d0d60..1f303b1adf1a 100644 --- a/fs/ocfs2/refcounttree.c +++ b/fs/ocfs2/refcounttree.c @@ -630,7 +630,7 @@ static int ocfs2_create_refcount_tree(struct inode *inode, rb->rf_records.rl_count = cpu_to_le16(ocfs2_refcount_recs_per_rb(osb->sb)); spin_lock(&osb->osb_lock); - rb->rf_generation = osb->s_next_generation++; + rb->rf_generation = cpu_to_le32(osb->s_next_generation++); spin_unlock(&osb->osb_lock); ocfs2_journal_dirty(handle, new_bh);