Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp6441057pxu; Thu, 24 Dec 2020 02:21:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJwexxP3Snjz80AEc2V+N25YKQ/vjvV3xNvjZHEWLzYWrFHg3ev5YCatLzawwLshF6Rwnmp2 X-Received: by 2002:a17:906:94c5:: with SMTP id d5mr26716045ejy.427.1608805306190; Thu, 24 Dec 2020 02:21:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608805306; cv=none; d=google.com; s=arc-20160816; b=Kz8w+7sll4rBat2W+ewL9I2/WdId0o3+i4dbZHi4F+x6LCEdSAKGwNaGXeBYdUR1Q8 UqBlb+oH0DOxvZ+O0E9cTmPL5rWPBLj8Byyz8/ynL020aQYi2swGqTVKayZuGM418VzI iv3RqlmzQiFi0gsWO4thxiZ8qqJWaPhghID1SAxORCIyhMt3O5gfx0PMKl4NtEIos+Lc NuFAGODtH8q1/DJVbM1RlszS5pygz4QdSGA82iqxEXlk2/DYsvJSpuf0zDx6cNxJ5dxl 766hGTFTJDPxMmpOYh2xww7pfHQnqz1hKALyZ4Xv1h5O7kY95mtnB/LtV58Q4+3sKTgy QjVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-language:in-reply-to:mime-version :user-agent:date:message-id:from:references:cc:to:subject :dkim-signature; bh=yeB6niYXa2OA9mrrL3D4yoNCSTaKFJOJV2ZNcVrGP7M=; b=XJjUDBENMlpROTbIEEi6V+l653yqEw1fa0bKqVN2werFBOY0pp+eBobq5B4FdW0sxw nI8Nos9UpfPEL28eD76IW0SIu48X5jP/wMumU40DoBg9uh8bShb0OzsRjwopEDjcnaxM BzmMXt7Zo1Hirww63XxGQmh1/WMm6acn7FRNgKW4PywZYQNbugUmY4EWrHejbM6VIH7f yEJRn3Mj9YfgvOlzxeH48rqSossMYcOrl5ITlYfd1ghnTqZlIRzTRNbfYXdiDAbzETvw wGlGoZS79QKIQ5V5A0Fd1jTmpTTN98ofLoNcvZVRDzoX71a0isj1wN4WbSXO4A3tU0YJ CQNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=IwXkUd3l; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s4si14616735edr.197.2020.12.24.02.21.23; Thu, 24 Dec 2020 02:21:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=IwXkUd3l; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727815AbgLXKUU (ORCPT + 99 others); Thu, 24 Dec 2020 05:20:20 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:38078 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726591AbgLXKUU (ORCPT ); Thu, 24 Dec 2020 05:20:20 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608805133; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=yeB6niYXa2OA9mrrL3D4yoNCSTaKFJOJV2ZNcVrGP7M=; b=IwXkUd3l7JJISMvbOzeT0gw6pVcfn1ETPv1FdSfyM/jHsSaus26ekczYKqQ5o4v8Rl5asp WNzDyL6oN0fXXn3Fcsc1WYYf+iewsiSLYbCJowX4SKleDn+Plc6XaWW9CSU1tx+SbEnyRi JHKRdy4iuW0+p11SeitPWlSboXqbcqs= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-293-EGMKA78YOPGybCBbFKbQWg-1; Thu, 24 Dec 2020 05:18:48 -0500 X-MC-Unique: EGMKA78YOPGybCBbFKbQWg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DFBF4801AC0; Thu, 24 Dec 2020 10:18:46 +0000 (UTC) Received: from localhost.localdomain (ovpn-8-28.pek2.redhat.com [10.72.8.28]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6C67760BFA; Thu, 24 Dec 2020 10:18:42 +0000 (UTC) Subject: Re: PROBLEM: Recent raid10 block discard patchset causes filesystem corruption on fstrim To: Song Liu , Matthew Ruffell Cc: linux-raid , Song Liu , lkml , Coly Li , Guoqing Jiang , "khalid.elmously@canonical.com" , Jay Vosburgh References: From: Xiao Ni Message-ID: Date: Thu, 24 Dec 2020 18:18:40 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/mixed; boundary="------------C9881F6387E4A199DD38C2E2" Content-Language: en-US X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This is a multi-part message in MIME format. --------------C9881F6387E4A199DD38C2E2 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit On 12/09/2020 12:17 PM, Song Liu wrote: > Hi Matthew, > >> On Dec 8, 2020, at 7:46 PM, Matthew Ruffell wrote: >> >> Hello, >> >> I recently backported the following patches into the Ubuntu stable kernels: >> >> md: add md_submit_discard_bio() for submitting discard bio >> md/raid10: extend r10bio devs to raid disks >> md/raid10: pull codes that wait for blocked dev into one function >> md/raid10: improve raid10 discard request >> md/raid10: improve discard request for far layout >> dm raid: fix discard limits for raid1 and raid10 >> dm raid: remove unnecessary discard limits for raid10 > Thanks for the report! > > Hi Xiao, > > Could you please take a look at this and let me know soon? We need to fix > this before 5.10 official release. > > Thanks, > Song > Hi all The root cause is found. Now we use a similar way with raid0 to handle discard request for raid10. Because the discard region is very big, we can calculate the start/end address for each disk. Then we can submit the discard request to each disk. But for raid10, it has copies. For near layout, if the discard request doesn't align with chunk size, we calculate a start_disk_offset. Now we only use start_disk_offset for the first disk, but it should be used for the near copies disks too. [ 789.709501] discard bio start : 70968, size : 191176 [ 789.709507] first stripe index 69, start disk index 0, start disk offset 70968 [ 789.709509] last stripe index 256, end disk index 0, end disk offset 262144 [ 789.709511] disk 0, dev start : 70968, dev end : 262144 [ 789.709515] disk 1, dev start : 70656, dev end : 262144 For example, in this test case, it has 2 near copies. The start_disk_offset for the first disk is 70968. It should use the same offset address for second disk. But it uses the start address of this chunk. It discard more region. The patch in the attachment can fix this problem. It split the region that doesn't align with chunk size. There is another problem. The stripe size should be calculated differently for near layout and far layout. @Song, do you want me to use a separate patch for this fix, or fix this in the original patch? Merry Christmas Xiao --------------C9881F6387E4A199DD38C2E2 Content-Type: text/plain; charset=UTF-8; name="fix-raid10-discard-patch" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="fix-raid10-discard-patch" Y29tbWl0IDBkNzRhYzY2ZWQwZWM1YWY3MDI5NjU0NWUyNjA0NDcyM2ExNDY1N2MKQXV0aG9y OiBYaWFvIE5pIDx4bmlAcmVkaGF0LmNvbT4KRGF0ZTogICBUaHUgRGVjIDI0IDE3OjU4OjQz IDIwMjAgKzA4MDAKCiAgICBmaXgKCmRpZmYgLS1naXQg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