From patchwork Mon Oct 14 13:49:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Meir Elisha X-Patchwork-Id: 13835064 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2099.outbound.protection.outlook.com [40.107.22.99]) (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 3E2EF1D554 for ; Mon, 14 Oct 2024 13:49:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.22.99 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728913797; cv=fail; b=WTZb8Ofq/sGeJX+UwhhUglTRmYyhodjHhNthpWss7I6e8OvdDJTZSpmaP6sqVhe/RcMouUG7CIZkZvY2sC14cIxbTbj/pX0IePuxHZS8Uv3UAeKT1s09pRVkPyRuyvM+Fa7mhLSTjzkyizRzDgy2e0cWpt6XPivQq7CDWKcxx7k= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728913797; c=relaxed/simple; bh=+XshVtkwJM50XhOp8RJfMRFB4yhR2nIESrgmA/fL3YM=; h=From:To:Cc:Subject:Date:Message-Id:Content-Type:MIME-Version; b=kuPGmHpZiWMAWO6kx2d75BYwV0t3+7nQoTUjjbWLDlHPAlkSGHfszT7ojEDIAcZ1NmRUcxdyRgWsWtUtp5Ng9KhqjAYTw9LSx4MMxt59eq/4MH39Nog4K0kUC1xkGZELFIGcwpTwnIdLIM3K/nDIL57r4m4BVc1GczxkNkYwGB8= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=volumez.com; spf=pass smtp.mailfrom=volumez.com; dkim=pass (2048-bit key) header.d=storingio.onmicrosoft.com header.i=@storingio.onmicrosoft.com header.b=oxQm2jxJ; arc=fail smtp.client-ip=40.107.22.99 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=volumez.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=volumez.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=storingio.onmicrosoft.com header.i=@storingio.onmicrosoft.com header.b="oxQm2jxJ" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=EOl/eeuvYLzJMqAqTjstrGSfa/SeHwY23gVRsfYeWZB74qKpk8KYMhVmdp+MC+FC92mXr2vHpTl99r3x+yDhhftAAVUz3PeJJiEnhzW9RSR4+NQ1dj723PE1JCrt6FIHT71VvWJ0Vm2yU5Kl0jMT7bSfksJSiz0q4QEIbnHudAKKHRk4EiH/UspqUvfDkyntUF9taqyR6xmMqEwmfAY4+gS08jLxyc8h2gGqSBjNeNPcOr9Fp/ms//jieu6q3p81G+Q+G2UEMn0J62kE0kT/mvqmBqvbnJdKsbhpqJIUezho8psLi1cXkLihaKSNJ165cxK/XS5wosJEbUpmYSA51g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=yZhCcredzEC5Ptza90LFn4d+jGdzuMzx36DmD9TBbdA=; b=PAdFFKZdaPz2CrQ8e765S9NLivuPEnJizCZsaIpY3dqSfLp/2CU8HcWY/GNDgLSQPzCDxABIONvV8Z1DThLB+T2oI4FCkFJraDF801tr6TaUAtURatxrhua2S96vYY0qpqNtrt+Vo2GSyF/foHX77z60Lb7CkHsFPDvndNkUGj/3c+1Bv+pOkQ8ud69dKew34j5bb/i1FPsiSuG//tbFHvZ+OY+Ho73ZCSVRxt3FBzEP4pOg3ZbdeOvAovE+TloYZQDXnzoaBzr4sVURoZ9kli/fR74SSWRktBYji1Qt1VKxVgThK3hfIXmWCjcmXtBtNwMf90rePwwOMz8BXdfH5w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=volumez.com; dmarc=pass action=none header.from=volumez.com; dkim=pass header.d=volumez.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=storingio.onmicrosoft.com; s=selector1-storingio-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=yZhCcredzEC5Ptza90LFn4d+jGdzuMzx36DmD9TBbdA=; b=oxQm2jxJSvPW0cs5HZbW7/EFTqX004FsJ7RWY+KXXgKXi49CNmxo9EJ53Cn3sqF0/W11TnP1NjO7o0pfLx2vpt0/fRihzHknafEPtvWFUt8VfnFDYRy4aPh5b+nLdrNuJcdBsd+QnJ45Mxf2ppqHkUlTz02rvsloNOevi+cMmLPh8PPoHiGvYo1nbyhHTnKVrlwgiejWMB05FBy2hdJ8gvY/4Z514GZVW0r9HGFTStBvH8cI9KO6quXx4NCBIrnMmFmkAfZ7h6Sjv/Rh5ecEFVy0r85dFdkTINfcaLHDURVASZ1jCGcOj67fB3Mu33TqByOQXW/zS7u8kVRJlfvVTQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=volumez.com; Received: from DBBPR04MB6297.eurprd04.prod.outlook.com (2603:10a6:10:cd::14) by DU2PR04MB8567.eurprd04.prod.outlook.com (2603:10a6:10:2d6::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.26; Mon, 14 Oct 2024 13:49:52 +0000 Received: from DBBPR04MB6297.eurprd04.prod.outlook.com ([fe80::193b:a2c:45e8:4b4b]) by DBBPR04MB6297.eurprd04.prod.outlook.com ([fe80::193b:a2c:45e8:4b4b%7]) with mapi id 15.20.8048.020; Mon, 14 Oct 2024 13:49:52 +0000 From: Meir Elisha To: Alasdair Kergon , Mike Snitzer , Mikulas Patocka , Joe Thornber Cc: dm-devel@lists.linux.dev Subject: [PATCH] md/persistent-data: Set tm hash size via a module_param Date: Mon, 14 Oct 2024 16:49:44 +0300 Message-Id: <20241014134944.1264991-1-meir.elisha@volumez.com> X-Mailer: git-send-email 2.34.1 X-ClientProxiedBy: TL2P290CA0024.ISRP290.PROD.OUTLOOK.COM (2603:1096:950:3::8) To DBBPR04MB6297.eurprd04.prod.outlook.com (2603:10a6:10:cd::14) Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DBBPR04MB6297:EE_|DU2PR04MB8567:EE_ X-MS-Office365-Filtering-Correlation-Id: 9755e843-dbfd-4127-70af-08dcec5713d3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|1800799024|52116014|376014|38350700014; X-Microsoft-Antispam-Message-Info: m1vUb1bNmnDZZo0o8S4MsUM2P8wygaRj0Q6fcqEQTqED+vrW9F5Ua69utm/fZ0ao4rhNoElGjrTibDo/miWFYJ7jJOxZvFFyGcZ4LXZXdkU1jDXT5UQOBvxEHUEqCj96yIgDa/IeaPgE+H1GIUDdGDSX3wxYWe4mgVtsAuvanY/2ufq0cB0oc2/aHUvNGqWcD/Y4JksVi9dMXZqnXYIJDqhRqvyVVuqoZS8vuYp9squq+xW2OWWkj92MPgKIxVNHZMbTxAafeW+uOYqxMmgfPp4AHncLmIWcmt1DNgbJhaX8KEfB6Svu+IMvWItL3tFffbfAEbi9+N0rhZrodhRWWn2Oe/e6EA+uABaBii1YQRIs/p9pnFBCRGKcijQdiBCOo9jwSGAbgVSu9cDBhuhvvWJ42gQ9gcaR8LUhQFPZuux+6ifmZKroAForIfS41awEMafcEQQKlbkhRy5zEAQEmlOPbvVkAez19JcrN/zROQ/ps7dyXHelGPMmzuRwPQbtGCNJPsEXsBvYl5ru0zcSF576S8gGInqRhcVsP1RHVMuY00f2hRm+xT4zRd5Ys51f//Ux5Qi5xD83YPEUrG+UfNCON8hZNkKPllqJf/aOr7Xs9cJwKrEpa7xh3ntcCM0KGwB8VVCdpD1SnjX4y+NMOu8PNrs2WNtJmk79h9V/AwzNq1wKckmDpBf3hreb0e7aKyGLBGwbQIgaeB501FU/5FJx7lfesb9cZtgZ+ty8EtMwdL1c5p5NoEs0KW3hSSEd7DnNyI/OK95m3OfXWHOqUqO39EnOETbRCd9uX6e903EFHvAYo4NM6REV6GVYNBVur54DHWR7i9zy280LSbPOvFmDFR9FJdVWVLA3ebQP6C0tfVnNqkxLOtFC20uwSWNiKBvoua9lkJ+Z2qvUCwo8l00WMQ5Uewdz5iCwLBdLZPv7gaGsKYBp5/ovaeJupjAUSBtoMvQDZkcftMrc7ivdEW2qOdIkWCgSSMUtHaPOnuxy4ckI5WJiB6NM1mc7TllSI3V8lZN7MjQF154vLkP3DOwmR7o9nadRjPim6XGZveRClccCvD1PC2k8jRKRK/wNlaTfdYH4SKdTMpmbzRMY6EtdQ4aawCzaswRFJFdkAN9ta7I9KUACZUONAxFpzQgTCYZafLN+w0QZHD8I2Erako2HHYHvrtaEjQFHtHWPmNkik3b39GuAH63N2B1fBJaQoSPkjfaj7yIFoWpmsc35Ou2+J2uVsy735SKohe0wXJodeZRKZLKGSAg3CnAhp5QD9OAf4g+vuOP8zq9QZFpwGpBMxnZe11F6x54wTYB6k/XWL+HdOomle8M0r7EsHkOuAL3q3AJerESOU6Ayd9O6gw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DBBPR04MB6297.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(1800799024)(52116014)(376014)(38350700014);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSp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O0j9bY++eQGREnow/t22+lqG5Z0VeO73AVhP7HlXQmnnOlMdSLgPAfzmULQEFeKxtLUXxusJe7T8nCheSUAS2awaOFDsDjGlgnjVoPHK5FLIi1onJJFkocZ0iPvWqYCkTYStr6CMiXLzdt651bu0QEx1NEB6eV8k2oSAyqK0vwa92fGvGeb9UECSypvQS94yOCP2tZ4pGpYepM3sfi02I63VGYBcfG+1Iw5hyZlFOWjjAscPfMtkGPzAKLpsPhzG644GCWrrbaQTO+u2KbOe1h7p+sqwMe6w7CmQY5Pp4J+DLNJlAtysb2aTBCpQD1I4CsVh8+M0wcFZEh3CxauWDe9gEn9YH20C1zWJ4/AQaGoySgQRULu3sTT3tA/DFW6FKS2KwDIeIkidFUJge4ay3o01JbXDV10kK2MEIkDLSoPIewOMzkXJtHI74UWd/NCL8lhk/h2HyQMsv/3JFiIZU25+LFBeDaIIXRKMyK0uZi+W/u+hyZ2x1zW9A6WlrH+Qpmpz44TzIJeJwnSVOuLkBgod5XPnyPHbCQXEEGUM6bb1JQ== X-OriginatorOrg: volumez.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9755e843-dbfd-4127-70af-08dcec5713d3 X-MS-Exchange-CrossTenant-AuthSource: DBBPR04MB6297.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Oct 2024 13:49:52.0164 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b1841924-914b-4377-bb23-9f1fac784a1d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: oieZMDCd1eInvWKavI5lnmNVbSn00vEe0T3iBgzbP7xV+5lS2y62jrcS9+VYhh04Arbm11LHF7og4yB1V9Hf3g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU2PR04MB8567 Enlarging the hash table size can significantly improve transaction manager hash operations. This commit adds the tm_hash_table_size module_param that sets the hash size. For demonstration, I've created a thin volume, filled it with 4.8TiB of sequential data and took a snapshot. then, I overwritten the volume in a way that caused a maximum btree nodes to be allocated. I've repeated the process for 5 snapshots and measured the first snapshot deletion time. When using 128k hash size (instead of the 256 default value) I was able to reduce snapshot deletion time from 42min to 4min (10x improvement). Signed-off-by: Meir Elisha --- Script used for demonstration attached below. .../persistent-data/dm-transaction-manager.c | 51 ++++++++++++++++--- 1 file changed, 43 insertions(+), 8 deletions(-) diff --git a/drivers/md/persistent-data/dm-transaction-manager.c b/drivers/md/persistent-data/dm-transaction-manager.c index c7ba4e6cbbc7..8d486b1e6693 100644 --- a/drivers/md/persistent-data/dm-transaction-manager.c +++ b/drivers/md/persistent-data/dm-transaction-manager.c @@ -10,6 +10,7 @@ #include "dm-space-map-metadata.h" #include "dm-persistent-data-internal.h" +#include #include #include #include @@ -84,8 +85,35 @@ struct shadow_info { /* * It would be nice if we scaled with the size of transaction. */ -#define DM_HASH_SIZE 256 -#define DM_HASH_MASK (DM_HASH_SIZE - 1) +static uint tm_hash_table_size = 256; + +static int param_set_hash_size(const char *val, const struct kernel_param *kp) +{ + unsigned int num; + int ret; + + if (!val) + return -EINVAL; + + ret = kstrtouint(val, 0, &num); + if (ret) + return ret; + + /* Hash size must be a power of 2 */ + if (!(num && !(num & (num - 1)))) + return -EINVAL; + + *((unsigned int *)kp->arg) = num; + return 0; +} + +static const struct kernel_param_ops tm_hash_table_size_ops = { + .set = param_set_hash_size, + .get = param_get_uint +}; + +module_param_cb(tm_hash_table_size, &tm_hash_table_size_ops, &tm_hash_table_size, 0644); +MODULE_PARM_DESC(tm_hash_table_size, "transaction manager hash size"); struct dm_transaction_manager { int is_clone; @@ -95,8 +123,9 @@ struct dm_transaction_manager { struct dm_space_map *sm; spinlock_t lock; - struct hlist_head buckets[DM_HASH_SIZE]; - + struct hlist_head *buckets; + uint hash_size; + uint hash_mask; struct prefetch_set prefetches; }; @@ -105,7 +134,7 @@ struct dm_transaction_manager { static int is_shadow(struct dm_transaction_manager *tm, dm_block_t b) { int r = 0; - unsigned int bucket = dm_hash_block(b, DM_HASH_MASK); + unsigned int bucket = dm_hash_block(b, tm->hash_mask); struct shadow_info *si; spin_lock(&tm->lock); @@ -131,7 +160,7 @@ static void insert_shadow(struct dm_transaction_manager *tm, dm_block_t b) si = kmalloc(sizeof(*si), GFP_NOIO); if (si) { si->where = b; - bucket = dm_hash_block(b, DM_HASH_MASK); + bucket = dm_hash_block(b, tm->hash_mask); spin_lock(&tm->lock); hlist_add_head(&si->hlist, tm->buckets + bucket); spin_unlock(&tm->lock); @@ -146,7 +175,7 @@ static void wipe_shadow_table(struct dm_transaction_manager *tm) int i; spin_lock(&tm->lock); - for (i = 0; i < DM_HASH_SIZE; i++) { + for (i = 0; i < tm->hash_size; i++) { bucket = tm->buckets + i; hlist_for_each_entry_safe(si, tmp, bucket, hlist) kfree(si); @@ -169,13 +198,19 @@ static struct dm_transaction_manager *dm_tm_create(struct dm_block_manager *bm, if (!tm) return ERR_PTR(-ENOMEM); + tm->hash_size = tm_hash_table_size; + tm->buckets = kmalloc_array(tm->hash_size, sizeof(*tm->buckets), GFP_KERNEL); + if (!tm->buckets) + return ERR_PTR(-ENOMEM); + tm->is_clone = 0; tm->real = NULL; tm->bm = bm; tm->sm = sm; + tm->hash_mask = tm->hash_size - 1; spin_lock_init(&tm->lock); - for (i = 0; i < DM_HASH_SIZE; i++) + for (i = 0; i < tm->hash_size; i++) INIT_HLIST_HEAD(tm->buckets + i); prefetch_init(&tm->prefetches);