Received: from out30-110.freemail.mail.aliyun.com (out30-110.freemail.mail.aliyun.com [115.124.30.110]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3D0C122612 for ; Mon, 18 Mar 2024 05:49:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.110 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710740985; cv=none; b=tqmx9toEuvgQ8euNlSSdL9O66UoFVBhbQ2rzGBUWa4IWtlQBSbEmTkO4MuZgL4zx8KK9Tee8KNYGTU1xd9Cwm17cEbj9+R9LWD9Sym/kiln/Owu7yCWqrPqKXSX4nCUkr1V0dxSKmrhRY+Hwha5ZC+xrvr+F7gKQz1KPjRJyT94= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710740985; c=relaxed/simple; bh=9smNY1nj7tPQFREtITUvs70J8Fdi6sCA7ncmSs4moPI=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=RuDdZfkIhe3tkA64MSQR4ay+6SFbN0CLAy6yOR7o/ud77HMDeR5sAS9NLXZS5vVeVHkcmkrD7YO2Bfa36xG+MVh+5WZQyEws/j8Ajn7NvdKMMB6VhqMQe/D856w/RqtuH22Nw/ge6sgj0nYgXYPHdmv8SuTTGywf4tQw076GJuQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=GhMMuvSl; arc=none smtp.client-ip=115.124.30.110 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="GhMMuvSl" DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1710740973; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=8P4xmbSVdO/glNF/qI+MQYgnJ9+crU13YWQwcJX0B9s=; b=GhMMuvSlj6e02DXDhcKZOsmWpRXaObuxt4bKWXtNMrq25gCinfj0GpcFMoLOn3sqUlklg2ndIv62dp0+ffoGuVPW/Pw44Wh/G/tj4TlY2sDpTQsWI6985zfW4DuCVkWfv2oi5WpcdzsaLnDSXTCVGPUHj91Oa8jJutYA64c+yko= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R661e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046056;MF=joseph.qi@linux.alibaba.com;NM=1;PH=DS;RN=3;SR=0;TI=SMTPD_---0W2fT1iv_1710740972; Received: from 30.221.64.205(mailfrom:joseph.qi@linux.alibaba.com fp:SMTPD_---0W2fT1iv_1710740972) by smtp.aliyun-inc.com; Mon, 18 Mar 2024 13:49:33 +0800 Message-ID: <75a0425a-1e31-42bf-9095-e4a3e00b0e01@linux.alibaba.com> Date: Mon, 18 Mar 2024 13:49:32 +0800 Precedence: bulk X-Mailing-List: ocfs2-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] ocfs2: improve write IO performance when fragmentation is high Content-Language: en-US To: Heming Zhao Cc: ocfs2-devel@lists.linux.dev, ailiop@suse.com References: <20240316034457.16893-1-heming.zhao@suse.com> <1f8715a2-cc77-4203-9d38-ecf99bb71198@suse.com> From: Joseph Qi In-Reply-To: <1f8715a2-cc77-4203-9d38-ecf99bb71198@suse.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 3/18/24 1:29 PM, Heming Zhao wrote: > On 3/18/24 09:39, Joseph Qi wrote: >> >> >> On 3/16/24 11:44 AM, Heming Zhao wrote: >>> 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 >>> --- >>> 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     |  4 +- >>>   fs/ocfs2/resize.c       |  7 +++ >>>   fs/ocfs2/suballoc.c     | 99 +++++++++++++++++++++++++++++++++++++---- >>>   fs/ocfs2/suballoc.h     |  6 ++- >>>   5 files changed, 106 insertions(+), 12 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..eae18d772e93 100644 >>> --- a/fs/ocfs2/ocfs2_fs.h >>> +++ b/fs/ocfs2/ocfs2_fs.h >>> @@ -883,14 +883,14 @@ 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; >>> +    __le32   bg_contig_free_bits;  /* max contig free bits length */ >> >> I've found some parts you are using le32, while others using le16. >> It seems that le16 is enough here. So why not: >> __le16 bg_contig_free_bits; >> __le16 bg_reserved1; >> >> Joseph > > IIUC, From the comment before ocfs2_la_default_mb(), the max cluster > size is 1MB. And from 'struct ocfs2_group_desc', the offset of > bg_bitmap is 0x40. Therefore, the max contiguous bit of gd: > (1024*1024 - 0x40)*8 = 8388096 (23-bit length, bigger than __le16) > bg_bits and bg_free_bits_count are already using __le16 now.