From patchwork Wed Mar 27 06:09:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "heming.zhao@suse.com" X-Patchwork-Id: 13605611 Received: from mail-lj1-f182.google.com (mail-lj1-f182.google.com [209.85.208.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 B03F81CAAF for ; Wed, 27 Mar 2024 06:09:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711519770; cv=none; b=NKTs9fJ4F4tqynSpwflzt3Z/xwSa2drmwXk5ZH0ckAxCgHcMs7WkGRK14kwn2SdkWkAzykmCmWsDtOKbm7rH0RydElAKQcVLcNQiNl/aCXtbBtnqn/8ojZ6y3w49j0/43Z27QPLYgKGfGmF523ehak1mf7ut29GWRJSqada2fz8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711519770; c=relaxed/simple; bh=6bw3QM/pJKaKCSIoNp59clzAc2zxOkCyNuzUYcC1568=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=IXdzNksCPdc1cVLLu2fXAt/fuAgFgVfhUEI9ConnIkv6UoLaGav404NvBmdy2CIrQDIHgSi9IYuPRPzuhH8Pu/H94/LxsRYrCeBFj39Qn1uiuyJAhtMCah9S8LCwaw65S5wIjwaPDDQbCDQDtrnDj9h7uU7h6PVIrVzTRB86wcw= 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=TnI36WPj; arc=none smtp.client-ip=209.85.208.182 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="TnI36WPj" Received: by mail-lj1-f182.google.com with SMTP id 38308e7fff4ca-2d109e82bd0so86338441fa.3 for ; Tue, 26 Mar 2024 23:09:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1711519766; x=1712124566; 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=NaLX0jRLlLWF4lzAIWsHvflQ9jNNLvrgmVniDQh9pXM=; b=TnI36WPjx0T6p0+3Z2D4DQfjso+AE2CpaPyzElDMP52uCofaKHRY4wfRlOoQ+G9+Tk IMGvHvBaEnxm68g0XW6BZYix5AoktNceyQozIOGo1d0qV/Czw7x+8T1JHC/UWAHh6f5q TR1MYTMrbVVwWJLHPvA6R6+FilgUG4J7XEj06mxK2VHD1HSo1WLkSagyTz93bfXOx4Dm kjTU2hUGWdSkY5rA1m41ZmCB0gAwZQ28EXm2UqapVDMaYXelQNVyVTVS5PihY1otcEtu pD3udcbX5B9hH6WDudeAjReMIM9uE2SBItmQqKYEdehSD1r+HwGpi5UNviIiZu1bwIyM VypQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711519766; x=1712124566; 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=NaLX0jRLlLWF4lzAIWsHvflQ9jNNLvrgmVniDQh9pXM=; b=ENbajAqGzaP7zrVfhTd11bCtoBQri8drYl1P6BvNo//+jnFHfcZJiRQRkMxHNnraTw MwKbwP8/NjGO7kZ50JuvgWyq29VPSTfE7Eygf/MNLsx24lAhvR9HxW11kDDsirg8c97S 7MN9PTYLaBUBpeADKZC8M3z4WbUAjm1U0JfNUODyHGJjbdgL+o78UIuOv2Ig0OEtfa57 pyuZwiXNKOecSnRHxfsBwdX6v5tNFL/iIegyp9Do5ztQS0FN4/2KHxEuDX6xvatV9dko VZC9gQmV9Vgr0925IruELoFU5uPufI2IESJz+BHdz+P1JsqEZWFBcyEje2N3p+4sK+7z xd3g== X-Forwarded-Encrypted: i=1; AJvYcCW403XTATbfUB/LFmEzUSJ7vjmWY1HGhT8puewVbup18l8PCaqhek1lNPk600PMzfJdqcHv5m5EZ2FiOLcSRmgyoO+Y54l/UkW/8Iw= X-Gm-Message-State: AOJu0YzWDGZOYNpqzVrAljXar/LpKVfhJ3s3dLwOHUbhTBRNDiGsuKWb CP9IqrLF9TGcMUpUn/aLR6oq1a0CmUHgseTQj4qvxpMyTDX0gt5uGcNGyZXExj/2lv5PMTmWnvl A X-Google-Smtp-Source: AGHT+IEGn3lY6rWsbV8ilKYDEnkxjiml7FR6SJr3RH9xvYhJtyEiFFUW5D3XIGkhf6UeIO+Y0di0IA== X-Received: by 2002:a2e:8201:0:b0:2d6:c630:c2bb with SMTP id w1-20020a2e8201000000b002d6c630c2bbmr177712ljg.35.1711519765778; Tue, 26 Mar 2024 23:09:25 -0700 (PDT) Received: from c73.suse.cz ([202.127.77.110]) by smtp.gmail.com with ESMTPSA id s1-20020aa78281000000b006eacefd8fabsm93445pfm.64.2024.03.26.23.09.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 23:09:25 -0700 (PDT) From: Heming Zhao To: joseph.qi@linux.alibaba.com Cc: Heming Zhao , ocfs2-devel@lists.linux.dev, ailiop@suse.com Subject: [PATCH 1/3] ocfs2: improve write IO performance when fragmentation is high Date: Wed, 27 Mar 2024 14:09:12 +0800 Message-Id: <20240327060914.2583-2-heming.zhao@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240327060914.2583-1-heming.zhao@suse.com> References: <20240327060914.2583-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 --- 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 | 99 +++++++++++++++++++++++++++++++++++++---- fs/ocfs2/suballoc.h | 6 ++- 5 files changed, 107 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..6fd67c8da9fe 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; + u16 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 = le16_to_cpu(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,7 @@ 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, 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 Wed Mar 27 06:09:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "heming.zhao@suse.com" X-Patchwork-Id: 13605612 Received: from mail-lj1-f169.google.com (mail-lj1-f169.google.com [209.85.208.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 B4DBE134C6 for ; Wed, 27 Mar 2024 06:09:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711519772; cv=none; b=vGFs9ETyg9e/cGhE/gM3WymS5+jL5G2B3IOxzNe0qWn5Vm4zG2d7nL6FykqeECFyeWRljZOyCWC5lfDIQcZlfbAyYFE1FEwoigxqSwpAwWfb24/WdqKNJdmsQRyALdvAulSXeFPU9z7YOtfXHwEn41TPEpLMqFImil5JVx7FAHQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711519772; c=relaxed/simple; bh=VfofPeXTNsuvRmYwRCOp8XUJOUDKtLzxpLDj9kA4z3Q=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=R9UPLFciOJ/ZtZV1OodEegbkfLMi67bifgPl/DjyS+iKC9x1/r/RNjCmHLMC1TYctIUmu2ZImNPEu7zbgxDW/5vQtsuC3tC9AE4Fw05BgvlrZNZzmhawjq5NTVtIL/BPp2Znyi41NDLQP1NnKuSBtv1HWTpQz1TOZEf3z7oW+UM= 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=BthlLotx; arc=none smtp.client-ip=209.85.208.169 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="BthlLotx" Received: by mail-lj1-f169.google.com with SMTP id 38308e7fff4ca-2d485886545so110271961fa.2 for ; Tue, 26 Mar 2024 23:09:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1711519768; x=1712124568; 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=Wzs9n6tbS/gF7JkxIfJeOaPjAATBWrXKYmGB2wfXofA=; b=BthlLotx0sHha8Bgm6EaNIAxOHI4g8owTVNvrzSztCOFWAyO37MtC9iBNRZBwx6hGG eSh5gEjuVUy2CVbyNmH8QVApo+85oZkYve9xnQc3XIlDs37mySCCv85l87uqR2u1Wp/j zEQwaAsILqpCEVft0kPpz0W3lKrY0SUs9yxtpvuVbxyJGgsvnWaBFLyxoKEojwTSQyNE aPA3Cb4Je117aS++u23pw6MtfqdkgHbQ2NWAaqSNKBe7sFXXBhZiVVBViXjRGKi0txlq f11AJzGrP5/NF/kZWmCWw8YdjsNbTeguM3SEQGzexjI2pW2/6h0YPYvGQqwMi5VHauHv bW1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711519768; x=1712124568; 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=Wzs9n6tbS/gF7JkxIfJeOaPjAATBWrXKYmGB2wfXofA=; b=kNMsT2Xcx9pqtpgIX5zPUAsLikl9PM7QIe6S5NpCtfsBTbT8M/v1npfNIX1YvkohDb mRTIL6J3OKfm5yc6/B+8s4vlbdtJlriZYzbq6JBf6w7SAbP4W4vrkknYFktHg0Qi3R9m 8t7JJw4gfmJljT2RlpvRDPyjQoFiFDCoxWeked+p1AioskfIHo5zhp2MeYPJo46Oge3B yUZviMCb4moEZ2/qBHhPhkF1yBu2VGyHTS1hZvMD/TEUsstaZtJ79g88hBzn63HoRiaC uD0yiG4VhN4nt6I6VPrFonri/mHblb82rmh/mA+L3+dLRM322cBM6RebDIpkoT2FXQvc 2n8g== X-Forwarded-Encrypted: i=1; AJvYcCXJX6w+FUAFuq0hZOVac5BkAbbNZ30mmBOkjwnjVQzke26u55QPdI+Z9W6S6trSXzROqqQxgvUldQfrvS1tRYLbWhjbeVFsgEFcebg= X-Gm-Message-State: AOJu0Yy1Z1AOA4pasvAMjs0AMdNtvSj9Qf1Qz2FKbnEIpJhNO8wGSqTD tTs962R75e7CTV1/FBuYMTEzShyWbC5dvTLxn6tpHeecMlHFewomt3YIfLrlA2I= X-Google-Smtp-Source: AGHT+IEooZYM/4FcR78dzYRjQTYQXbJcxDxE/wyBEOl1o92Xri3okPjhH1sAPlxAj3Dl7f8i1jTMlw== X-Received: by 2002:a2e:9018:0:b0:2d6:f698:7eca with SMTP id h24-20020a2e9018000000b002d6f6987ecamr1062482ljg.5.1711519767875; Tue, 26 Mar 2024 23:09:27 -0700 (PDT) Received: from c73.suse.cz ([202.127.77.110]) by smtp.gmail.com with ESMTPSA id s1-20020aa78281000000b006eacefd8fabsm93445pfm.64.2024.03.26.23.09.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 23:09:27 -0700 (PDT) From: Heming Zhao To: joseph.qi@linux.alibaba.com Cc: Heming Zhao , ocfs2-devel@lists.linux.dev, ailiop@suse.com Subject: [PATCH 2/3] ocfs2: adjust enabling place for la window Date: Wed, 27 Mar 2024 14:09:13 +0800 Message-Id: <20240327060914.2583-3-heming.zhao@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240327060914.2583-1-heming.zhao@suse.com> References: <20240327060914.2583-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 --- fs/ocfs2/localalloc.c | 15 ++++++++------- fs/ocfs2/suballoc.c | 9 ++------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c index c803c10dd97e..2391b96b8a3b 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); + + osb->local_alloc_state = OCFS2_LA_ENABLED; + 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 6fd67c8da9fe..4163554b0383 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 Wed Mar 27 06:09:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "heming.zhao@suse.com" X-Patchwork-Id: 13605613 Received: from mail-lj1-f174.google.com (mail-lj1-f174.google.com [209.85.208.174]) (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 E466317BB3 for ; Wed, 27 Mar 2024 06:09:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711519774; cv=none; b=TtPxpIMlmvO6JqqLgt70dLFNI+nH2sw0vaUOz1QeWPhnrXhT/mR7iM6M1Rhk6Q6Aj+8WL9g+/Opj7xau2ClDhhdA3xBocAFCGiw0uJ8QZ664uu02+gEI2uup2HueflUajgT0KradNUm0iiYGJwj6glTgF2zoBhbj+YvAFUXyCmc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711519774; c=relaxed/simple; bh=IOtCI6S3S8zwk0hxblJ4yO7qkjd+2iXxGbl2RuVdwUI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Aj8rDKzTGUr7x7sLnfnN1rQSx2h277zBeyd54YfQyD18p3kXdVXX6B1zNoaO5W5KRWAL3BACey3bgFVTzMjxF9z4Ec2kDo0RkL9o3mEr0gh4JaPMyyVKjSQH9/nZ83/gqQAyioD+HpuVjIRyox3fBAti1RUXkS5TL7fZaylM8cQ= 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=CKF3j2BQ; arc=none smtp.client-ip=209.85.208.174 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="CKF3j2BQ" Received: by mail-lj1-f174.google.com with SMTP id 38308e7fff4ca-2d68c6a4630so74197441fa.3 for ; Tue, 26 Mar 2024 23:09:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1711519770; x=1712124570; 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=GSHLKicfdHpoCUuEDOBtWZ/Mv/xYwg8o3haFByO2wf0=; b=CKF3j2BQXLgvY/bnNZ6wnkm+7HokK8k7JO4oSr/ozbsp/TR43p8AQi1zsHCB3V/h/+ JgHS8rgw8YK65h8f+ndyJvh0Hj0iG00DOjC7BcUK2QLT0JnamqAoMDQ7rDqYAt5L9FyX O6kx08GX0N9EDIpq3MC8/poLouetXiOUSJY+XemaJZTaYsbQzeTeC7MzZL2fUlhc2pBw dXsxX7rnrIq40l55YJJ0pTKimoi7F+/5QDVsBefy21ULuzsK4GA/BUQCzIPaBF6ywtS/ gZpBtheJXTPECFtTRItEg4o5uhlKRdAISold66fik2ol/WPCg5W/n504ZtVTDcqC0XQM l+8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711519770; x=1712124570; 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=GSHLKicfdHpoCUuEDOBtWZ/Mv/xYwg8o3haFByO2wf0=; b=D64DoaK4SWsoOzdUAFqAFaQ6fvp53XNo1U1xguEFQawnJwBMW4SmYXNuBvuyNN5RKM o+6zdxQmvf7NCVXbPRSfQN94aM1VFZr7y7ARvgpaHGuKGm7NkRWFyqWV64v715Te5f8V AMoWrr5g0KXlaEW5xTsuCIFInzXVnjMCIAyevVgHRbEgDJVHOOFJ1XfMusjzVt6dVVAm qoJWxmTnaaY9QeHBDXwHtGcPzDkCwOI/n3y2UQcAnlaxR1O7b8/XMdDqOgF6i4tniZRl R3k60TQMbCGRZpH0G3zigYpfMbn9ZXLGUjNN713qh4u1UiJcAsv94xNP/wPOAtHVTo1q gbdg== X-Forwarded-Encrypted: i=1; AJvYcCXqTOA4OLufj5GciyT9km4UzypM+ulREd3ncX970Io9W4d/UVpUi07x37rDPsdK8t+TwQe+iYj5ujL3+bGJymoV3QUPuniITbhnAOw= X-Gm-Message-State: AOJu0YxkyhfBnKJ6wdcteF4bcJsV/G+j8PdwEikLSGopPwsnVeNyF4r0 FhuLF6B/+cQz9jygVR8tAAjm6niM+NJZUoKIC6wZu7Inrty7jVnOzNsJD7Cin0g= X-Google-Smtp-Source: AGHT+IHxo8g9HYRZ0h9JGUTCGay4H6pKFJ9lZM1iZhaD3LNo+7N1wnoi6qPcQB/q/Pu/HZMmi6SMEA== X-Received: by 2002:a2e:9e41:0:b0:2d6:8ac7:455 with SMTP id g1-20020a2e9e41000000b002d68ac70455mr180805ljk.40.1711519770283; Tue, 26 Mar 2024 23:09:30 -0700 (PDT) Received: from c73.suse.cz ([202.127.77.110]) by smtp.gmail.com with ESMTPSA id s1-20020aa78281000000b006eacefd8fabsm93445pfm.64.2024.03.26.23.09.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 23:09:29 -0700 (PDT) From: Heming Zhao To: joseph.qi@linux.alibaba.com Cc: Heming Zhao , ocfs2-devel@lists.linux.dev, ailiop@suse.com Subject: [PATCH 3/3] ocfs2: speed up chain-list searching Date: Wed, 27 Mar 2024 14:09:14 +0800 Message-Id: <20240327060914.2583-4-heming.zhao@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240327060914.2583-1-heming.zhao@suse.com> References: <20240327060914.2583-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 ocfs2_claim_suballoc_bits(): - Add short-circuit code to speed up searching ocfs2_local_alloc_new_window(): - remove 1 sparse warning ``` 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 ``` Signed-off-by: Heming Zhao --- fs/ocfs2/localalloc.c | 2 +- fs/ocfs2/suballoc.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c index 2391b96b8a3b..2758ae9164f3 100644 --- a/fs/ocfs2/localalloc.c +++ b/fs/ocfs2/localalloc.c @@ -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/suballoc.c b/fs/ocfs2/suballoc.c index 4163554b0383..4c4c381b5148 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;