Skip to content

Commit 4ba8ebd

Browse files
zhaohemjfvogel
authored andcommitted
ocfs2: fix the issue with discontiguous allocation in the global_bitmap
commit 4eb7b93 ("ocfs2: improve write IO performance when fragmentation is high") introduced another regression. The following ocfs2-test case can trigger this issue: > discontig_runner.sh => activate_discontig_bg.sh => resv_unwritten: > ${RESV_UNWRITTEN_BIN} -f ${WORK_PLACE}/large_testfile -s 0 -l \ > $((${FILE_MAJOR_SIZE_M}*1024*1024)) In my env, test disk size (by "fdisk -l <dev>"): > 53687091200 bytes, 104857600 sectors. Above command is: > /usr/local/ocfs2-test/bin/resv_unwritten -f \ > /mnt/ocfs2/ocfs2-activate-discontig-bg-dir/large_testfile -s 0 -l \ > 53187969024 Error log: > [*] Reserve 50724M space for a LARGE file, reserve 200M space for future test. > ioctl error 28: "No space left on device" > resv allocation failed Unknown error -1 > reserve unwritten region from 0 to 53187969024. Call flow: __ocfs2_change_file_space //by ioctl OCFS2_IOC_RESVSP64 ocfs2_allocate_unwritten_extents //start:0 len:53187969024 while() + ocfs2_get_clusters //cpos:0, alloc_size:1623168 (cluster number) + ocfs2_extend_allocation + ocfs2_lock_allocators | + choose OCFS2_AC_USE_MAIN & ocfs2_cluster_group_search | + ocfs2_add_inode_data ocfs2_add_clusters_in_btree __ocfs2_claim_clusters ocfs2_claim_suballoc_bits + During the allocation of the final part of the large file (after ~47GB), no chain had the required contiguous bits_wanted. Consequently, the allocation failed. How to fix: When OCFS2 is encountering fragmented allocation, the file system should stop attempting bits_wanted contiguous allocation and instead provide the largest available contiguous free bits from the cluster groups. Link: https://lkml.kernel.org/r/[email protected] Fixes: 4eb7b93 ("ocfs2: improve write IO performance when fragmentation is high") Signed-off-by: Heming Zhao <[email protected]> Reported-by: Gautham Ananthakrishna <[email protected]> Reviewed-by: Joseph Qi <[email protected]> Cc: Mark Fasheh <[email protected]> Cc: Joel Becker <[email protected]> Cc: Junxiao Bi <[email protected]> Cc: Changwei Ge <[email protected]> Cc: Jun Piao <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Orabug: 38041352 (cherry picked from commit bd1261b16d9131d79723d982d54295e7f309797a) Signed-off-by: Gautham Ananthakrishna <[email protected]> Reviewed-by: Mark Tinguely <[email protected]>
1 parent 713dd15 commit 4ba8ebd

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

fs/ocfs2/suballoc.c

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -698,10 +698,12 @@ static int ocfs2_block_group_alloc(struct ocfs2_super *osb,
698698

699699
bg_bh = ocfs2_block_group_alloc_contig(osb, handle, alloc_inode,
700700
ac, cl);
701-
if (PTR_ERR(bg_bh) == -ENOSPC)
701+
if (PTR_ERR(bg_bh) == -ENOSPC) {
702+
ac->ac_which = OCFS2_AC_USE_MAIN_DISCONTIG;
702703
bg_bh = ocfs2_block_group_alloc_discontig(handle,
703704
alloc_inode,
704705
ac, cl);
706+
}
705707
if (IS_ERR(bg_bh)) {
706708
status = PTR_ERR(bg_bh);
707709
bg_bh = NULL;
@@ -1794,6 +1796,7 @@ static int ocfs2_search_chain(struct ocfs2_alloc_context *ac,
17941796
{
17951797
int status;
17961798
u16 chain;
1799+
u32 contig_bits;
17971800
u64 next_group;
17981801
struct inode *alloc_inode = ac->ac_inode;
17991802
struct buffer_head *group_bh = NULL;
@@ -1819,10 +1822,21 @@ static int ocfs2_search_chain(struct ocfs2_alloc_context *ac,
18191822
status = -ENOSPC;
18201823
/* for now, the chain search is a bit simplistic. We just use
18211824
* the 1st group with any empty bits. */
1822-
while ((status = ac->ac_group_search(alloc_inode, group_bh,
1823-
bits_wanted, min_bits,
1824-
ac->ac_max_block,
1825-
res)) == -ENOSPC) {
1825+
while (1) {
1826+
if (ac->ac_which == OCFS2_AC_USE_MAIN_DISCONTIG) {
1827+
contig_bits = le16_to_cpu(bg->bg_contig_free_bits);
1828+
if (!contig_bits)
1829+
contig_bits = ocfs2_find_max_contig_free_bits(bg->bg_bitmap,
1830+
le16_to_cpu(bg->bg_bits), 0);
1831+
if (bits_wanted > contig_bits && contig_bits >= min_bits)
1832+
bits_wanted = contig_bits;
1833+
}
1834+
1835+
status = ac->ac_group_search(alloc_inode, group_bh,
1836+
bits_wanted, min_bits,
1837+
ac->ac_max_block, res);
1838+
if (status != -ENOSPC)
1839+
break;
18261840
if (!bg->bg_next_group)
18271841
break;
18281842

@@ -1982,6 +1996,7 @@ static int ocfs2_claim_suballoc_bits(struct ocfs2_alloc_context *ac,
19821996
victim = ocfs2_find_victim_chain(cl);
19831997
ac->ac_chain = victim;
19841998

1999+
search:
19852000
status = ocfs2_search_chain(ac, handle, bits_wanted, min_bits,
19862001
res, &bits_left);
19872002
if (!status) {
@@ -2022,6 +2037,16 @@ static int ocfs2_claim_suballoc_bits(struct ocfs2_alloc_context *ac,
20222037
}
20232038
}
20242039

2040+
/* Chains can't supply the bits_wanted contiguous space.
2041+
* We should switch to using every single bit when allocating
2042+
* from the global bitmap. */
2043+
if (i == le16_to_cpu(cl->cl_next_free_rec) &&
2044+
status == -ENOSPC && ac->ac_which == OCFS2_AC_USE_MAIN) {
2045+
ac->ac_which = OCFS2_AC_USE_MAIN_DISCONTIG;
2046+
ac->ac_chain = victim;
2047+
goto search;
2048+
}
2049+
20252050
set_hint:
20262051
if (status != -ENOSPC) {
20272052
/* If the next search of this group is not likely to
@@ -2365,7 +2390,8 @@ int __ocfs2_claim_clusters(handle_t *handle,
23652390
BUG_ON(ac->ac_bits_given >= ac->ac_bits_wanted);
23662391

23672392
BUG_ON(ac->ac_which != OCFS2_AC_USE_LOCAL
2368-
&& ac->ac_which != OCFS2_AC_USE_MAIN);
2393+
&& ac->ac_which != OCFS2_AC_USE_MAIN
2394+
&& ac->ac_which != OCFS2_AC_USE_MAIN_DISCONTIG);
23692395

23702396
if (ac->ac_which == OCFS2_AC_USE_LOCAL) {
23712397
WARN_ON(min_clusters > 1);

fs/ocfs2/suballoc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ struct ocfs2_alloc_context {
2929
#define OCFS2_AC_USE_MAIN 2
3030
#define OCFS2_AC_USE_INODE 3
3131
#define OCFS2_AC_USE_META 4
32+
#define OCFS2_AC_USE_MAIN_DISCONTIG 5
3233
u32 ac_which;
3334

3435
/* these are used by the chain search */

0 commit comments

Comments
 (0)