Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp2552034lqo; Tue, 14 May 2024 02:06:01 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWl3BtI/2Qmbtv+z40xSe+ZaYdsOXe4pmE9inNPh/UIn6Pv1+rxq3Iuq/oQzUgvIWgZA/ve7ErLPF+ipQTUiAe3x+RFNtXXtHfoWP01sA== X-Google-Smtp-Source: AGHT+IELLRUYMVwwfdkm+Y5yZDuTAgtOI/uB0LHRgfia6HdiQo1ZP+7+FtIpmKwA2EI5xz5eHnEi X-Received: by 2002:a17:90a:cc17:b0:2b6:209f:c36b with SMTP id 98e67ed59e1d1-2b66001a46fmr21238796a91.22.1715677561631; Tue, 14 May 2024 02:06:01 -0700 (PDT) Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 41be03b00d2f7-63412a4dea9si8678786a12.699.2024.05.14.02.06.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 May 2024 02:06:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-178480-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@vivo.com header.s=selector2 header.b=nTEl3qxi; arc=fail (signature failed); spf=pass (google.com: domain of linux-kernel+bounces-178480-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-178480-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=vivo.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id CCE15283600 for ; Tue, 14 May 2024 09:05:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1A75B23776; Tue, 14 May 2024 09:05:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=vivo.com header.i=@vivo.com header.b="nTEl3qxi" Received: from APC01-SG2-obe.outbound.protection.outlook.com (mail-sgaapc01on2073.outbound.protection.outlook.com [40.107.215.73]) (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 E3B5A156E4 for ; Tue, 14 May 2024 09:05:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.215.73 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715677549; cv=fail; b=hPq0qHF3yxPnMCTxuCp4M0oCYL/nV3GWxwZdHB4zcWLENgbLcn+2MSBYB+m/uTEXQ+vwhr4/h2Gp0Lh1nMM+nRF0xIPMxeQTvz4Hf3xZqy59tn4l6LObacBy1m7QoTVmsJ9rDW1fEkA4gyXvoGIPMYg/NinK7Or9qEZukMZmKko= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715677549; c=relaxed/simple; bh=liVHYinpXH3a2/7J6fbY7ikGg3OeqjmcxDvXrthCT+A=; h=From:To:Cc:Subject:Date:Message-Id:Content-Type:MIME-Version; b=BEn4kUaf/JAjKh+g9UB+9EwBJD0Sjvc0ful6wUCYzAJNCJZkaZJDe02NNg8/4mE1m4bYqPl4a7t2PjEDzzLdISd+Eu2xmVFQbQy+Q0sV7Oxn8bpN/pu97+tvXrv1dRmTUamT+E3xP31gjofdufMTdXkpXHRDWi11OaxUaXDW6jU= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=vivo.com; spf=pass smtp.mailfrom=vivo.com; dkim=pass (2048-bit key) header.d=vivo.com header.i=@vivo.com header.b=nTEl3qxi; arc=fail smtp.client-ip=40.107.215.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=vivo.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=vivo.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IGKsAX1hVQGxC/g2srUzUVvkSvKuZu8UepW1Sfk/8sJD2uw21I4fBhCN8i3zg5LTqL/BXvAHrDZzAT18U0MKrEBeBoi3vJUP7h2h8xgJuwfLCKbUiYgV/FGkLkJM6o+BlJgvv4vgL/lq1NUynITw60LASkNwnMltKtj5xIVsep8Y2wwXlKXA8XBH7lMb01aYs505lsbNWbAgyj3jE6uuCYa6Vt3o4H3XoJQVlCkQPUowC50IFE+kAcRxr8KqW7gE/S8pV0LnEZTJhaiB1LzL/wRkhdABD3Bjkl731uPvEY7ClCCRhMf7Mn2Z4uFvzRM7VzAo4vDKgGiNt8ATDUR6vA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=BaE3wqdZHaqdvXtGnMdNijadmmg118QT7oTKiNY6NRM=; b=V30nQO7eoPzoBdOTQxdpkUE8RpjrJ58cyN4PcQlomRuNRn/0mCopcmWXwHQTuquiEDuggZDD6hbupjsh1MN/mIeDrnu54JAlsTeESYdTwiendzrG7a1ReoILaMmR1G9MZfhWQjBDH1m1h18T29t7RCEM9LKudZD0QQkP1oM13AY9LnjR/FYJ/dFa1PieopI0TLyXskgKF4XMF/tUSxtJVfnISENP5jOIEsPsiIZ2EHK1PJknwZM49rhJFullsmFxSPuI4zzccswlPbgqGMu6YQvIfPRuFmx5MZvhasQt+B0edkNhj79GTgJmHsY50PO3RKxfZxeFOU0x3oWLwbZmnQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=vivo.com; dmarc=pass action=none header.from=vivo.com; dkim=pass header.d=vivo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vivo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=BaE3wqdZHaqdvXtGnMdNijadmmg118QT7oTKiNY6NRM=; b=nTEl3qxi6EmIOddEsMhb5cPmeOYHhmVXCdHCLf02zgT+dH16+JFZtV4DzKafdNjItVpD37SlyP7JbP015utXEbbndsBNhBRKGZ+Osk+vu8spvqsBVp9Z/sefSsPY70y5msZqivobz7FXgpIFlN33cUQxGScTg2/HM/MR3IO+wt0yzVOycM8Ea0BbPLCkk7P1CBfIS9oLa+CxftUeqain/n+ZxJxTYxjTGvTVkVQW/Tp0zkhu6AFAyFv9Jj01JlEDAYygw8wob6U0+k5kVHvEKLdSL6A9hSkJpi6y1qYn1mY4wLatM0Bzm5+FGRoYEh5nRBbSS/b2nuTp5ha4KvFYDQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=vivo.com; Received: from SEYPR06MB6398.apcprd06.prod.outlook.com (2603:1096:101:145::9) by PUZPR06MB6102.apcprd06.prod.outlook.com (2603:1096:301:112::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.55; Tue, 14 May 2024 09:05:44 +0000 Received: from SEYPR06MB6398.apcprd06.prod.outlook.com ([fe80::9784:d8bc:5eb5:b60e]) by SEYPR06MB6398.apcprd06.prod.outlook.com ([fe80::9784:d8bc:5eb5:b60e%6]) with mapi id 15.20.7544.052; Tue, 14 May 2024 09:05:44 +0000 From: Yang Yang To: Alasdair Kergon , Mike Snitzer , Mikulas Patocka , dm-devel@lists.linux.dev, linux-kernel@vger.kernel.org Cc: Yang Yang Subject: [PATCH 0/5] dm: empty flush optimization Date: Tue, 14 May 2024 17:04:39 +0800 Message-Id: <20240514090445.2847-1-yang.yang@vivo.com> X-Mailer: git-send-email 2.34.1 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: SI1PR02CA0046.apcprd02.prod.outlook.com (2603:1096:4:1f5::14) To SEYPR06MB6398.apcprd06.prod.outlook.com (2603:1096:101:145::9) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SEYPR06MB6398:EE_|PUZPR06MB6102:EE_ X-MS-Office365-Filtering-Correlation-Id: d1326706-5b1b-4440-71fb-08dc73f50973 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|376005|52116005|1800799015|366007|38350700005; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?3c+LMXYh1G00/9coL4yrniZB4lbR6kKQEw+/W38bim2QTWxB6cJIUvSoZApR?= =?us-ascii?Q?1udTg6dof5Rv67B0UG9W43Mb7uzC53S4pXZ/KLFQ8JjbV1gfFUY+Vsu6un5y?= =?us-ascii?Q?lJvwOyGtye4Y5DYkmj76woDKNJxrJHRmVetmZGyIOT0OKv6LlNvdRFsNq5Ab?= =?us-ascii?Q?5OkLlgjPoHGYJIvRoi2BuF9tgfYzySn+2lKGdAMMFF3E/FIf67ltlEjpURQ/?= =?us-ascii?Q?grIerMdXGUCK1qbs+CCZNwBGtcNXsGYZ0dE1p3/2WRAWg9Qhmsi3p632LvIU?= =?us-ascii?Q?/1zvx8WuC0KzobZHEYM880clTx3Iy1WSgmod7kV/zPjOcKp1xbtsBH4A3zet?= =?us-ascii?Q?9Pdatf4p7aJyW1ll+Ot/u4EcquxpWli5WKNDW84V45PbIrxpepunOA9VOGs5?= =?us-ascii?Q?WNF01gu2gdx00L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?= =?us-ascii?Q?NDgXn9FQmQvXRu/0IESHWPn+5SkgUqrKmLDXU/mE48Xqcw=3D=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SEYPR06MB6398.apcprd06.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(376005)(52116005)(1800799015)(366007)(38350700005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?CwmoEReDlZaCydgVHFHAvVlpTKRd/5SUzqVZOKiGLKljZDPvKXvxXQLAk+Xu?= =?us-ascii?Q?Grpq1CdBh+mSQEa9b026CWBq7uExw21SmpRrbB1YU+esQnN7y7ZO13te5V7y?= =?us-ascii?Q?K//2/9THdcinqcZu8RCNEts+YGHBzKU34KiMNhYFUr0dhDg+2WDfjHv1VeE2?= =?us-ascii?Q?b3rLEn+gmb14pX5ZrLTgA6eJ2706PbahKGV9kPx6D1rhXm/t+rbX14t8mCew?= =?us-ascii?Q?d5sPAwc+Y4/FSqG5Qnd5dvZY37WJ//+E0WBnsxi9eZqZxVHbTBfBm0uTcbfm?= =?us-ascii?Q?TobU/uMz7OhJ/i/yX/kuRvFWXcS+SY0kx5oYkn6XFcSWksdvpFTpAEN70EGn?= =?us-ascii?Q?3bGlakA94O7t7NM/Ym16lZkm0imy2cQuJvbfNfCNZeNElBxq+9s8H6UPClkT?= =?us-ascii?Q?4ZON6Fhoj9YvvPuHl2FTyqcmMJA07oLK+1K+uChk6N7anjSZNxV2Hlr5TRnJ?= =?us-ascii?Q?HPY3Lic5DbvVkqgC84XK9BM4gVubmVrBGWZ5s3NbXhEnd10Xo/gUR/DDNuIn?= =?us-ascii?Q?MJPKyE7JR3MVfaerwOZ1Sf1LZiyoghGONcoLNOrDLvZY6uXrqXny7KxtjwH7?= =?us-ascii?Q?vNxYzJ+J35UJtd4Rjl+mzmFrV9UE8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ii?Q?hkSPGYWmcf+V1pJoTLrnzStVgyv5viJSacAtlLmOdS+C3DsfJCI4rwCbfL30?= =?us-ascii?Q?o029Vjg2hYfL7VFUIC82ssZ7YlcX4SfgXCjzK28b?= X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: d1326706-5b1b-4440-71fb-08dc73f50973 X-MS-Exchange-CrossTenant-AuthSource: SEYPR06MB6398.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 May 2024 09:05:44.4552 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 923e42dc-48d5-4cbe-b582-1a797a6412ed X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: E2NdhLQMuV9wt4G0+UcdqnWvGwCPEs3XRk3u1H/GtjSdF5ZkIjW9ISvK49JNXoXJP5F//UtDi+0oVFnoceHTuQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PUZPR06MB6102 __send_empty_flush() sends empty flush bios to every target in the dm_table. However, if the num_targets exceeds the number of block devices in the dm_table's device list, it could lead to multiple invocations of __send_duplicate_bios() for the same block device. Typically, a single thread sending numerous empty flush bios to one block device is redundant, as these bios are likely to be merged by the flush state machine. In scenarios where num_targets significantly outweighs the number of block devices, such behavior may result in a noteworthy decrease in performance. This is a real-world scenario that we have encountered: 1) Call fallocate(file_fd, 0, 0, SZ_8G) 2) Call ioctl(file_fd, FS_IOC_FIEMAP, fiemap). In situations of severe file system fragmentation, fiemap->fm_mapped_extents may exceed 1000. 3) Create a dm-linear device based on fiemap->fm_extents 4) Create a snapshot-cow device based on the dm-linear device Perf diff of fio test: fio --group_reporting --name=benchmark --filename=/dev/mapper/example \ --ioengine=sync --invalidate=1 --numjobs=16 --rw=randwrite \ --blocksize=4k --size=2G --time_based --runtime=30 --fdatasync=1 Scenario one: for i in {0..1023}; do echo $((8000*$i)) 8000 linear /dev/sda2 $((16384*$i)) done | sudo dmsetup create example Before: bw=857KiB/ After: bw=30.8MiB/s +3580% Scenario two: for i in {0..1023}; do if [[ $i -gt 511 ]]; then echo $((8000*$i)) 8000 linear /dev/nvme0n1p6 $((16384*$i)) else echo $((8000*$i)) 8000 linear /dev/sda2 $((16384*$i)) fi done | sudo dmsetup create example Before: bw=1470KiB/ After: bw=33.9MiB/s +2261% Any comments are welcome! V2: -- Split into smaller pieces that are easier to review -- Add flush_pass_around, suggested by Mikulas Patocka -- Handling different target types separately Yang Yang (5): dm: introduce flush_pass_around flag dm: add __send_empty_flush_bios() helper dm: support retrieving struct dm_target from struct dm_dev dm: Avoid sending redundant empty flush bios to the same block device dm linear: enable flush optimization function drivers/md/dm-core.h | 3 +++ drivers/md/dm-ioctl.c | 4 ++++ drivers/md/dm-linear.c | 1 + drivers/md/dm-table.c | 39 +++++++++++++++++++++++++++++++++++ drivers/md/dm.c | 37 +++++++++++++++++++++++++-------- include/linux/device-mapper.h | 8 +++++++ 6 files changed, 83 insertions(+), 9 deletions(-) -- 2.34.1