From patchwork Wed Jul 31 03:34:49 2024
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
X-Patchwork-Submitter: Huan Yang
X-Patchwork-Id: 815847
Received: from APC01-TYZ-obe.outbound.protection.outlook.com
(mail-tyzapc01on2049.outbound.protection.outlook.com [40.107.117.49])
(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 EC68A10A3E;
Wed, 31 Jul 2024 03:35:17 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org;
arc=fail smtp.client-ip=40.107.117.49
ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
t=1722396920; cv=fail;
b=PQVH3lXWfn80AqukWqLIU0I2qV+yl9hzlu5UburqeYZ1ps4K+mOAsVLS43zJGcT92QqGLCsE76kj53n5vzwsTFxEygB5KC/wuoOKwztjeMhxDPUA4FSTuyBZQqNxuGt2Mqg4yHqV7n6g237tr8CN8BQmiOBiWQjqo5Ggb+Fuqco=
ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org;
s=arc-20240116; t=1722396920; c=relaxed/simple;
bh=9uFZmWGaXj9p2bdu0I+H8JAbLo/5scHOoE+bPxYwAHk=;
h=From:To:Cc:Subject:Date:Message-ID:Content-Type:MIME-Version;
b=fqMioULwpI0U87qUk2oF5QkJI17jHgNs2dKNEzDu16hHVVE42N5T3qkJncd6J8v33V98uaRTBwM73fhUAc4/VxPx0WZoEOS/OpL/srou8dWXATSuEsN55YT5ZJhJk6dOwJzDbQQvAQAuN7DVUdMyQNewVcRRhMu37lwxOAAUFFg=
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=cYiq1Hiw; arc=fail smtp.client-ip=40.107.117.49
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
Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key) header.d=vivo.com header.i=@vivo.com
header.b="cYiq1Hiw"
ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none;
b=I5cG3OBXObiY6kDF4IQgziHIOEMjqVWVEQFZeaxLb+CFrV9IbHHpMRTiHSOGWhUGo7GGkbW2Jvlu0HHV9w9TlYVimTbWJ/QNj4+/fk36acjEqknvX6S1ysBWgufyGOlSj0U00mhH1rhaFn6Czym6WjsRFnd9oUbk1OGMAsd9l8pHupZwo5wnPibfQaXn+3yRlKX6MI82tjPG7p73kGzTagr7BRcfemUeQaOKLYQT/2+bbjzNH48cZ0q6Sd4zunUxq8IpWMyOY1GSgjxfyjR4tToyWqjydKKxbjR7a3ENjKu+rpyqpcyrmBYT8AKqKnPQnAJrvMb2nyLXsjbhdmHCRw==
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=Z5vatior3QIBxnjTsWnWYzvzzd+xpPly3AJ4sehktgk=;
b=v/fLCOUvDL9qN4bRjow0v74I4ngRuL+1B3ob6wUziFGhxZLg2vX9g2//DziArp+9QkMFsMTr6QKoZajYnuduFysMeKsBDDrQ5X3FbIiD6mynHWdT2Oze9JenC6JXtKs4pLBMrSUbeuaC6UVzWGO/DAp6Gs0cLpGqBeiBdiwQQcx0qB9n1j7MjoY/hbU5chgwggj16Wt4hdOwUm2migXxR6ltywR9z/ks3puTgeEBD8UYiX06vcNa2WWghkSaPouHuDOPNjOtf2+oMXfcN1pibHRkD8rGw3QFzRCE79zon57mTXGpM0yuYrhY5dT2II8+uelHoAfKV51Lka7HtMVvmw==
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=Z5vatior3QIBxnjTsWnWYzvzzd+xpPly3AJ4sehktgk=;
b=cYiq1HiweRqY3ySnx8aTHa7zOebKkr7cwvksLv+l+JCrwGgNhI/D13NwqfValX2N7kzsYdPYN1bOr2LYwejg7FhnU4FIcDJXr9xIGf6qjL8CHKvqUvH7WTxkrpfKY6PJLRWYSTDS5juvuw9a6qReOIdpXgxbkEfLKuYeEjE6FOinsgw5IWIsw4wpZVGYLLPeQ3wJ3RMoFiuTx+AfL1IbWDPpaWHZMaE3R9s80wgj3t+bS8AcxHdczlHiwDx/B1KbVbKkUphAkPQn6ZNDYgnGbMhsGjWgh5W72/IqIKLXdnOOAk07o1wgzpWSHT/zNDBGWOW3x6JbiJJ85hGzpOHpog==
Authentication-Results: dkim=none (message not signed)
header.d=none;dmarc=none action=none header.from=vivo.com;
Received: from PUZPR06MB5676.apcprd06.prod.outlook.com (2603:1096:301:f8::10)
by TYZPR06MB6953.apcprd06.prod.outlook.com (2603:1096:405:3f::10)
with Microsoft SMTP Server (version=TLS1_2,
cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7807.27; Wed, 31 Jul
2024 03:35:13 +0000
Received: from PUZPR06MB5676.apcprd06.prod.outlook.com
([fe80::a00b:f422:ac44:636f]) by PUZPR06MB5676.apcprd06.prod.outlook.com
([fe80::a00b:f422:ac44:636f%6]) with mapi id 15.20.7807.026; Wed, 31 Jul 2024
03:35:13 +0000
From: Huan Yang
To: Gerd Hoffmann , Sumit Semwal ,
=?utf-8?q?Christian_K=C3=B6nig?= ,
dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org,
linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org
Cc: opensource.kernel@vivo.com,
Huan Yang
Subject: [PATCH] udmabuf: use kmem_cache to alloc udmabuf folio
Date: Wed, 31 Jul 2024 11:34:49 +0800
Message-ID: <20240731033449.1016195-1-link@vivo.com>
X-Mailer: git-send-email 2.45.2
X-ClientProxiedBy: SG2P153CA0052.APCP153.PROD.OUTLOOK.COM (2603:1096:4:c6::21)
To PUZPR06MB5676.apcprd06.prod.outlook.com
(2603:1096:301:f8::10)
Precedence: bulk
X-Mailing-List: linux-media@vger.kernel.org
List-Id:
List-Subscribe:
List-Unsubscribe:
MIME-Version: 1.0
X-MS-PublicTrafficType: Email
X-MS-TrafficTypeDiagnostic: PUZPR06MB5676:EE_|TYZPR06MB6953:EE_
X-MS-Office365-Filtering-Correlation-Id: 881bd12e-ac79-482d-2636-08dcb111c984
X-MS-Exchange-SenderADCheck: 1
X-MS-Exchange-AntiSpam-Relay: 0
X-Microsoft-Antispam: BCL:0;
ARA:13230040|366016|376014|1800799024|52116014|38350700014;
X-Microsoft-Antispam-Message-Info: O7FqwNa3K3q5ZGMv7jJoXyetSvQs5lorhLy87FlZ8kp9glTbzZBpcPyyLdNrnINZgRT+RzkBnb3twGb6XwX15CBXq/rR4Gb7/JmabS7q244B7ldxjDlVcwHN3vOdEIZf/FW2RYwyxkmIC5Rk2YFrBsfSMKZ7nhsclROEXlr+Y0jlRseYJ1LN8WvkVRrQwfwaRCO5cc8n/ZuB7jipGVL3GtgQKUPLTyCGOV9v0RSWYYbk6DoiBXevVpb/fioufWdMCWp0angv3jRKqN4ThayQlH5CEpe8WjV8B5D0s4JGjwQCIFFJ59s6foPfIvH0N3YFkqIV6w9dC8qsN9oJiVcDhfLdp4+apUjpME8ZLp9C1u1X9xGzTQOlCuPVdepdjU4LLFiSPk1nUgP1WydA2V3EZdWBMddH4jGy0KIK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; SFV:NSPM; H:PUZPR06MB5676.apcprd06.prod.outlook.com; PTR:; CAT:NONE;
SFS:(13230040)(366016)(376014)(1800799024)(52116014)(38350700014); DIR:OUT;
SFP:1101;
X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1
X-MS-Exchange-AntiSpam-MessageData-0: AQR1yh7CgQ1RhtEkBA0wCFKgduj3wfNjaWrOBp6NFUgf7QZqK3R1uxVuGm2/+nORE7YYpl/49MG7mRYGB8DkyNN/LfB8qTKeP/S0RAnCWOiTMHbWISli5WYtj9XgH7PxovWx0SR8c1K1EkEtORSmchvBs9Xe/M9xZ/rWwpKnUITjf+zPpWFR4Gj76Xa01uLJNssnBHWBpW//fonI4oG3zy0JdgmteI8Zu3Q4Lj3DXA9/vhJQLl2VtAbnFIbLT3VPDqD2fLX/o7BOuxf92H4oqCIC8lFN6XCdaTGOh7XAOkzbxFVISxhSb6PCnXQi4ZHI8wkgOfLRxn3quj4yQAKEO2HpqmiE6P2+GghQOlmF3WAul4WYd8lznSBvjAguTd2fp/IDiJ2e6jUW/6gnuUz1+X+pli25IrcD6MTKjyRW5iTy2J9I/zplxenb3w5Lsr520IL3oeyGH9tra/0o6ly2JVEHMg1cVsKjb4awv/AUopqHDNr90e9GtpdzGHm9cGBiDl1AldLAUBQTJ3yhKpr8BS54JSFTgAbBX03ucQzNS9ys6ZlDkLeSFvxZSPvxhu+HWT9HHHSu6VsGxh+MNtZGpnlegfqOK4lBZO5eryif2pigK8+UwAVt0gqdfPTs72FhX1Wm2qklLdYPvQh334SjnfLKZOD80H5Gyicvbun+7TIGXWVRVafZFwWIvR9ebhu/Y5zGL0x4k2ev7GBKHTBnkLVXdewJrgSQynjz9qDjz71L4QH8kqeKj+lzep2rau65OV/HL/OJO/3c5xZOOpBEQrrisUbqt3Q+cZqCIyMJjVXuZMxtA5Afqdyj46cILChmM5yL5OoR89G+ABwpVoT9rQ1ZyKAr6nnevsCerwmlyw0Xmc6zXKANaQpqzcO1t6V0WXBeUKqD1LpFYigOHTl8dLg6R0YgjPO3VBDKXBkNkIeYSJFSk25rcAbq6YpKXzna6eNzt2CLHxyCiESQutUpiIj/aFuDFU3+nPNm0S8Q/CP2uyehTychTs3XrooHFtOyp/NIaeU0zsuw5UOcLwpqROBJBchPKKh3oKVMb937QiYh+a6GLZW5tHRRAnJp0JZH6SmnrMSFpmWnRTfItGC3jqnDsjISCz4yU9ZLPptl5rdoLSAUn4sMy97kY1L5tfuqXNuisDE6OUEXPVZTLMNcm16VBVrnLuOd8wGPPKE5OaVZk9chPyTLLteePBdPGEiKWlWAYLyhzZEVfPGuLjk5riGQD9s1jpl/1nYG+l+Kz70UJ7OMywEl4iX1gZl6Zhsw53Zz+KkS5JE0GhncxGbBajUI4Aw6aEL+LBdwJXyG9JUVl8U4l7kU7b5zs7zGhrlpvPENbZbzwk9mu6ke44YtXK9OlGImmhAAD7PY88/Ey4+kJ7cbm2phEwKht1bGO8FH3XiZWwRV0i9CLxoaodEWM7Avx9OdgHgOnlmAh4DuJQNVALvr1phBq4Jc4ShqJOfm7P5ZWgbbRQM91RgaH9YyiYXhC3cvBI0qsY0dTtIWK9+RJWlf/1qcYV90+d1pIjYSZ5Oxsb6mQ3OEE+h9ntB9M1S8MI5iXG62epiPX9kSc4TEmftOTEAu+wgUZBwmTimq
X-OriginatorOrg: vivo.com
X-MS-Exchange-CrossTenant-Network-Message-Id: 881bd12e-ac79-482d-2636-08dcb111c984
X-MS-Exchange-CrossTenant-AuthSource: PUZPR06MB5676.apcprd06.prod.outlook.com
X-MS-Exchange-CrossTenant-AuthAs: Internal
X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jul 2024 03:35:13.5156 (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: Q31jzX3iBbRZM1QrvMSxxr7BF0Q90+H+CCm2yyNF/dVl9TzEzWH9H2huWMBflGGazR11tZaHvaC/sStfSFedKA==
X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYZPR06MB6953
The current udmabuf_folio contains a list_head and the corresponding
folio pointer, with a size of 24 bytes. udmabuf_folio uses kmalloc to
allocate memory.
However, kmalloc is a public pool, starting from 64 bytes. This means
that each udmabuf_folio allocation will waste 40 bytes.
Considering that each udmabuf creates a folio corresponding to a
udmabuf_folio, the wasted memory can be significant in the case of
memory fragmentation.
Furthermore, if udmabuf is frequently used, the allocation and
deallocation of udmabuf_folio will also be frequent.
Therefore, this patch adds a kmem_cache dedicated to the allocation and
deallocation of udmabuf_folio.This is expected to improve the
performance of allocation and deallocation within the expected range,
while also avoiding memory waste.
Signed-off-by: Huan Yang
---
drivers/dma-buf/udmabuf.c | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
base-commit: cd19ac2f903276b820f5d0d89de0c896c27036ed
diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c
index 047c3cd2ceff..db4de8c745ce 100644
--- a/drivers/dma-buf/udmabuf.c
+++ b/drivers/dma-buf/udmabuf.c
@@ -24,6 +24,8 @@ static int size_limit_mb = 64;
module_param(size_limit_mb, int, 0644);
MODULE_PARM_DESC(size_limit_mb, "Max size of a dmabuf, in megabytes. Default is 64.");
+static struct kmem_cache *udmabuf_folio_cachep;
+
struct udmabuf {
pgoff_t pagecount;
struct folio **folios;
@@ -169,7 +171,7 @@ static void unpin_all_folios(struct list_head *unpin_list)
unpin_folio(ubuf_folio->folio);
list_del(&ubuf_folio->list);
- kfree(ubuf_folio);
+ kmem_cache_free(udmabuf_folio_cachep, ubuf_folio);
}
}
@@ -178,7 +180,7 @@ static int add_to_unpin_list(struct list_head *unpin_list,
{
struct udmabuf_folio *ubuf_folio;
- ubuf_folio = kzalloc(sizeof(*ubuf_folio), GFP_KERNEL);
+ ubuf_folio = kmem_cache_alloc(udmabuf_folio_cachep, GFP_KERNEL);
if (!ubuf_folio)
return -ENOMEM;
@@ -492,10 +494,20 @@ static int __init udmabuf_dev_init(void)
if (ret < 0) {
pr_err("Could not setup DMA mask for udmabuf device\n");
misc_deregister(&udmabuf_misc);
- return ret;
+ goto err;
+ }
+
+ udmabuf_folio_cachep = KMEM_CACHE(udmabuf_folio, 0);
+ if (unlikely(!udmabuf_folio_cachep)) {
+ ret = -ENOMEM;
+ goto err;
}
return 0;
+
+err:
+ misc_deregister(&udmabuf_misc);
+ return ret;
}
static void __exit udmabuf_dev_exit(void)