https://github.com/torvalds/linux
Revision 9230a0b65b47fe6856c4468ec0175c4987e5bede authored by Dave Chinner on 20 November 2018, 06:50:08 UTC, committed by Darrick J. Wong on 21 November 2018, 18:10:53 UTC
Long saga. There have been days spent following this through dead end
after dead end in multi-GB event traces. This morning, after writing
a trace-cmd wrapper that enabled me to be more selective about XFS
trace points, I discovered that I could get just enough essential
tracepoints enabled that there was a 50:50 chance the fsx config
would fail at ~115k ops. If it didn't fail at op 115547, I stopped
fsx at op 115548 anyway.

That gave me two traces - one where the problem manifested, and one
where it didn't. After refining the traces to have the necessary
information, I found that in the failing case there was a real
extent in the COW fork compared to an unwritten extent in the
working case.

Walking back through the two traces to the point where the CWO fork
extents actually diverged, I found that the bad case had an extra
unwritten extent in it. This is likely because the bug it led me to
had triggered multiple times in those 115k ops, leaving stray
COW extents around. What I saw was a COW delalloc conversion to an
unwritten extent (as they should always be through
xfs_iomap_write_allocate()) resulted in a /written extent/:

xfs_writepage:        dev 259:0 ino 0x83 pgoff 0x17000 size 0x79a00 offset 0 length 0
xfs_iext_remove:      dev 259:0 ino 0x83 state RC|LF|RF|COW cur 0xffff888247b899c0/2 offset 32 block 152 count 20 flag 1 caller xfs_bmap_add_extent_delay_real
xfs_bmap_pre_update:  dev 259:0 ino 0x83 state RC|LF|RF|COW cur 0xffff888247b899c0/1 offset 1 block 4503599627239429 count 31 flag 0 caller xfs_bmap_add_extent_delay_real
xfs_bmap_post_update: dev 259:0 ino 0x83 state RC|LF|RF|COW cur 0xffff888247b899c0/1 offset 1 block 121 count 51 flag 0 caller xfs_bmap_add_ex

Basically, Cow fork before:

	0 1            32          52
	+H+DDDDDDDDDDDD+UUUUUUUUUUU+
	   PREV		RIGHT

COW delalloc conversion allocates:

	  1	       32
	  +uuuuuuuuuuuu+
	  NEW

And the result according to the xfs_bmap_post_update trace was:

	0 1            32          52
	+H+wwwwwwwwwwwwwwwwwwwwwwww+
	   PREV

Which is clearly wrong - it should be a merged unwritten extent,
not an unwritten extent.

That lead me to look at the LEFT_FILLING|RIGHT_FILLING|RIGHT_CONTIG
case in xfs_bmap_add_extent_delay_real(), and sure enough, there's
the bug.

It takes the old delalloc extent (PREV) and adds the length of the
RIGHT extent to it, takes the start block from NEW, removes the
RIGHT extent and then updates PREV with the new extent.

What it fails to do is update PREV.br_state. For delalloc, this is
always XFS_EXT_NORM, while in this case we are converting the
delayed allocation to unwritten, so it needs to be updated to
XFS_EXT_UNWRITTEN. This LF|RF|RC case does not do this, and so
the resultant extent is always written.

And that's the bug I've been chasing for a week - a bmap btree bug,
not a reflink/dedupe/copy_file_range bug, but a BMBT bug introduced
with the recent in core extent tree scalability enhancements.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
1 parent 2c30717
History
Tip revision: 9230a0b65b47fe6856c4468ec0175c4987e5bede authored by Dave Chinner on 20 November 2018, 06:50:08 UTC
xfs: delalloc -> unwritten COW fork allocation can go wrong
Tip revision: 9230a0b
File Mode Size
bitops
4level-fixup.h -rw-r--r-- 1.1 KB
5level-fixup.h -rw-r--r-- 1.2 KB
asm-offsets.h -rw-r--r-- 35 bytes
asm-prototypes.h -rw-r--r-- 507 bytes
atomic-instrumented.h -rw-r--r-- 11.6 KB
atomic-long.h -rw-r--r-- 7.9 KB
atomic.h -rw-r--r-- 4.3 KB
atomic64.h -rw-r--r-- 1.9 KB
audit_change_attr.h -rw-r--r-- 484 bytes
audit_dir_write.h -rw-r--r-- 528 bytes
audit_read.h -rw-r--r-- 241 bytes
audit_signal.h -rw-r--r-- 36 bytes
audit_write.h -rw-r--r-- 461 bytes
barrier.h -rw-r--r-- 6.0 KB
bitops.h -rw-r--r-- 1.1 KB
bitsperlong.h -rw-r--r-- 592 bytes
bug.h -rw-r--r-- 7.1 KB
bugs.h -rw-r--r-- 267 bytes
cache.h -rw-r--r-- 384 bytes
cacheflush.h -rw-r--r-- 1.3 KB
checksum.h -rw-r--r-- 2.3 KB
cmpxchg-local.h -rw-r--r-- 1.4 KB
cmpxchg.h -rw-r--r-- 2.2 KB
compat.h -rw-r--r-- 658 bytes
current.h -rw-r--r-- 256 bytes
delay.h -rw-r--r-- 1.1 KB
device.h -rw-r--r-- 245 bytes
div64.h -rw-r--r-- 7.3 KB
dma-contiguous.h -rw-r--r-- 238 bytes
dma-mapping.h -rw-r--r-- 259 bytes
dma.h -rw-r--r-- 553 bytes
early_ioremap.h -rw-r--r-- 1.7 KB
emergency-restart.h -rw-r--r-- 248 bytes
error-injection.h -rw-r--r-- 980 bytes
exec.h -rw-r--r-- 667 bytes
export.h -rw-r--r-- 2.1 KB
extable.h -rw-r--r-- 802 bytes
fb.h -rw-r--r-- 271 bytes
fixmap.h -rw-r--r-- 2.8 KB
ftrace.h -rw-r--r-- 460 bytes
futex.h -rw-r--r-- 2.6 KB
getorder.h -rw-r--r-- 1.5 KB
gpio.h -rw-r--r-- 4.5 KB
hardirq.h -rw-r--r-- 532 bytes
hugetlb.h -rw-r--r-- 2.7 KB
hw_irq.h -rw-r--r-- 270 bytes
ide_iops.h -rw-r--r-- 791 bytes
int-ll64.h -rw-r--r-- 863 bytes
io.h -rw-r--r-- 22.7 KB
ioctl.h -rw-r--r-- 506 bytes
iomap.h -rw-r--r-- 3.2 KB
irq.h -rw-r--r-- 403 bytes
irq_regs.h -rw-r--r-- 980 bytes
irq_work.h -rw-r--r-- 194 bytes
irqflags.h -rw-r--r-- 1.5 KB
kdebug.h -rw-r--r-- 182 bytes
kmap_types.h -rw-r--r-- 198 bytes
kprobes.h -rw-r--r-- 868 bytes
kvm_para.h -rw-r--r-- 549 bytes
linkage.h -rw-r--r-- 225 bytes
local.h -rw-r--r-- 2.2 KB
local64.h -rw-r--r-- 3.8 KB
mcs_spinlock.h -rw-r--r-- 260 bytes
memory_model.h -rw-r--r-- 2.2 KB
mm-arch-hooks.h -rw-r--r-- 388 bytes
mm_hooks.h -rw-r--r-- 885 bytes
mmu.h -rw-r--r-- 449 bytes
mmu_context.h -rw-r--r-- 881 bytes
module.h -rw-r--r-- 1.1 KB
msi.h -rw-r--r-- 838 bytes
page.h -rw-r--r-- 2.4 KB
param.h -rw-r--r-- 367 bytes
parport.h -rw-r--r-- 604 bytes
pci.h -rw-r--r-- 401 bytes
pci_iomap.h -rw-r--r-- 1.7 KB
percpu.h -rw-r--r-- 12.7 KB
pgalloc.h -rw-r--r-- 342 bytes
pgtable-nop4d-hack.h -rw-r--r-- 1.9 KB
pgtable-nop4d.h -rw-r--r-- 1.7 KB
pgtable-nopmd.h -rw-r--r-- 1.9 KB
pgtable-nopud.h -rw-r--r-- 2.0 KB
pgtable.h -rw-r--r-- 30.3 KB
preempt.h -rw-r--r-- 1.9 KB
ptrace.h -rw-r--r-- 1.6 KB
qrwlock.h -rw-r--r-- 3.8 KB
qrwlock_types.h -rw-r--r-- 682 bytes
qspinlock.h -rw-r--r-- 3.6 KB
qspinlock_types.h -rw-r--r-- 2.8 KB
resource.h -rw-r--r-- 1.1 KB
rwsem.h -rw-r--r-- 3.2 KB
seccomp.h -rw-r--r-- 1.3 KB
sections.h -rw-r--r-- 5.4 KB
segment.h -rw-r--r-- 249 bytes
serial.h -rw-r--r-- 345 bytes
set_memory.h -rw-r--r-- 362 bytes
signal.h -rw-r--r-- 308 bytes
simd.h -rw-r--r-- 436 bytes
sizes.h -rw-r--r-- 78 bytes
spinlock.h -rw-r--r-- 329 bytes
statfs.h -rw-r--r-- 169 bytes
string.h -rw-r--r-- 281 bytes
switch_to.h -rw-r--r-- 962 bytes
syscall.h -rw-r--r-- 6.2 KB
syscalls.h -rw-r--r-- 739 bytes
termios-base.h -rw-r--r-- 2.1 KB
termios.h -rw-r--r-- 2.8 KB
timex.h -rw-r--r-- 508 bytes
tlb.h -rw-r--r-- 10.7 KB
tlbflush.h -rw-r--r-- 485 bytes
topology.h -rw-r--r-- 2.2 KB
trace_clock.h -rw-r--r-- 391 bytes
uaccess.h -rw-r--r-- 5.2 KB
unaligned.h -rw-r--r-- 1.1 KB
user.h -rw-r--r-- 242 bytes
vga.h -rw-r--r-- 587 bytes
vmlinux.lds.h -rw-r--r-- 27.4 KB
vtime.h -rw-r--r-- 52 bytes
word-at-a-time.h -rw-r--r-- 2.8 KB
xor.h -rw-r--r-- 13.6 KB

back to top