From patchwork Tue Sep 3 08:38:07 2024
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Patchwork-Submitter: Huan Yang
X-Patchwork-Id: 13788291
Return-Path:
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on
aws-us-west-2-korg-lkml-1.web.codeaurora.org
Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177])
(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
(No client certificate requested)
by smtp.lore.kernel.org (Postfix) with ESMTPS id 71C54CD3427
for ; Tue, 3 Sep 2024 08:41:50 +0000 (UTC)
Received: from gabe.freedesktop.org (localhost [127.0.0.1])
by gabe.freedesktop.org (Postfix) with ESMTP id E518B10E3BE;
Tue, 3 Sep 2024 08:41:46 +0000 (UTC)
Authentication-Results: gabe.freedesktop.org;
dkim=pass (2048-bit key;
unprotected) header.d=vivo.com header.i=@vivo.com header.b="DKo6Zlde";
dkim-atps=neutral
Received: from APC01-PSA-obe.outbound.protection.outlook.com
(mail-psaapc01on2075.outbound.protection.outlook.com [40.107.255.75])
by gabe.freedesktop.org (Postfix) with ESMTPS id 4BE2F10E3AB
for ; Tue, 3 Sep 2024 08:41:45 +0000 (UTC)
ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none;
b=xxUwp1yEyUK4EvgQBLmQydU5conZpMlQMisXkRqV0oKQ6s06Do3A1dBF8hzl23z/WmBnx0jJC7pqirQ6WDl+1poZOtlZYPvjunTGBwYQIsoYvG8Kfbbozg0VKAFT9uN9D7XBsaP3Lgbl65yQ1AFoKkiQiBOeRepfed2zKnHpfPhxRtStKA/RUgqQTARr7g3awiDJjVUP0BgHEGXKt+0I+H5cCT5RK+McwHQX+XZGAXew1dhLtjkrLq2KTEOr8CORs5Loqzxlexg6uBz2P3f85fTuXSTY+OJ9DwAxnzwdAabAhtVSfUWlfTrRO/SjSQ5nIsqlM0OKMdQv/8DxT5OlmQ==
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=XIEQ3rlqzNJaqDoCL5uRxsy7PyfbHUkPJ0IE5caIGbk=;
b=v97dTY+2fAGsKsxuqH32jPbAz05RyaQbSpTys4aqKdxoq2wFoCpY9WvhQT62EIL9AHwzt1qQHjJYeamLYSmxltUjhwYqbCyZhLnqzBhljim6nT21XCVtQLwV3Tv+G66J74mzOyrzMkQYTSeQrZU/gzPQqHscHmjVoSP357n1LQRNTSe3BCIwWXa2kuHxJO0AlWu4mwHC4oiiEQSfPynJl89zgukqZzfSvmVtX5A4RczEMsorZDr/nl+y/OoB5UJoBucxOj1DxzbQQ6E09J5Hj5t75Uj9hqMDlrGdayyOCYFtzd1RUOvHJX8xFdZJefH4UZ9Ok91mBGZIjXhM1CdXOQ==
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=XIEQ3rlqzNJaqDoCL5uRxsy7PyfbHUkPJ0IE5caIGbk=;
b=DKo6Zldeca6M9Gr6TObpIlaYiD92BMBwP8YEuS1CQpuIH14O33znoJAxmEYd23BBs/zUUdoNyfFwWc61EoGHnznr5kjlfq51Y6azMnM1Wjei/RV+4ytt+jNzySzknMM0QpvCoJi1neKQ8KpWk7Fn9Ut7EO2bfhTlFnLhIcDEU0t2UUBfLBhsDywkJtlCsi1hcQFLWVU7aOaA1TppFJ5bXTBTe6f73BYz+MnLBxXlsXllLJrrrQGZdYMauIQFZpT62EXDphVA6gTyxj34qP7ahb/a9hKL5QSXl7zkiKeGInu3rovytFC3KANM/x7IljL0UPdqt72tfo3US8Ecr8xORQ==
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 SG2PR06MB5359.apcprd06.prod.outlook.com (2603:1096:4:1d7::11) with
Microsoft SMTP Server (version=TLS1_2,
cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.24; Tue, 3 Sep
2024 08:41:42 +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.7918.024; Tue, 3 Sep 2024
08:41:42 +0000
From: Huan Yang
To: vivek.kasireddy@intel.com, Sumit Semwal ,
=?utf-8?q?Christian_K=C3=B6nig?= ,
Gerd Hoffmann , linux-media@vger.kernel.org,
dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org,
linux-kernel@vger.kernel.org
Cc: opensource.kernel@vivo.com,
Huan Yang
Subject: [PATCH v5 2/7] udmabuf: change folios array from kmalloc to kvmalloc
Date: Tue, 3 Sep 2024 16:38:07 +0800
Message-ID: <20240903083818.3071759-3-link@vivo.com>
X-Mailer: git-send-email 2.45.2
In-Reply-To: <20240903083818.3071759-1-link@vivo.com>
References: <20240903083818.3071759-1-link@vivo.com>
X-ClientProxiedBy: SI1PR02CA0026.apcprd02.prod.outlook.com
(2603:1096:4:1f4::11) To PUZPR06MB5676.apcprd06.prod.outlook.com
(2603:1096:301:f8::10)
MIME-Version: 1.0
X-MS-PublicTrafficType: Email
X-MS-TrafficTypeDiagnostic: PUZPR06MB5676:EE_|SG2PR06MB5359:EE_
X-MS-Office365-Filtering-Correlation-Id: 24b1f3b8-3626-4974-a4ef-08dccbf43bf6
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: =?utf-8?q?SkS8J/paByaM+cBmIQRuXGjd560QPc4?=
=?utf-8?q?UqoAHq6qcHwVabl6X1XUgiJsjfeF41QP0bihOtZ2A3B81/SxKiAoSvx3BoimFtQlV?=
=?utf-8?q?p1xqfGayx/tUQGWyny+p0qTM35HXBP8m2OaCm0s9NGfiCtq/hQhJWYcCP1ukDwPPW?=
=?utf-8?q?RSmt992bDmz6zGLKDa/8B5JS8tHqpgZ0QX1fcvHvQHE0CCPMNb+rGkOjNzGxtCJ3t?=
=?utf-8?q?aKzHsxfE6WVaGx9GY9gU1x0KZFjRv1A5mYXOlw4HA9VmieZlMfXvdDtHliugXpAL3?=
=?utf-8?q?zYSRP5FDGkAJhKVhGC+SwL0umFb5mm6m/HvJDxXfuKUYiHB6DEQDcCUwlDhjewS/d?=
=?utf-8?q?tLmzdJiSYkcumVHPp6XOUbOlJ7JBpj9utvayQehzSrYUGZl27D1XBfI3MpUSS2zR8?=
=?utf-8?q?U2X3m212n0FqtG9yHkeXqmg7n+g1b2mM0YHE4hwPZ8r9cxbXEaicAOAEje5VRaAl0?=
=?utf-8?q?Vc03XA9u8RtRVSJLv87P9Y/TxfKsJQtJsfN/Au5SPgUDLobnRTw1l79jWCrK9kx1+?=
=?utf-8?q?JOArJkmdta+keL6i02abVB2dzCswMiua9/lmrqVoISc+UhbRwTIPstRi+/oNQRFvq?=
=?utf-8?q?TMYq9ZOTaddqSg9nEddG4Y/g+ft4CSqh0A65PBVzdaL6wAK9oy6XZhjYIjsIoOUQt?=
=?utf-8?q?Pf8vz5C6tKunJERYoCQ6wnws7a5NJzwqZjqs+R56OruhuddGJJf9Drvraif6q5RPF?=
=?utf-8?q?yhmh9U8YYBjTsi5tPH4YA3BnRa41P3YgHoYVKat0QgmHj6xlGwBGZL+f21cD7DiAD?=
=?utf-8?q?aMlL0zv0D/dqqAYX7CRPqWVb6h3YLVJQLv1BeQ3o0wp5zyEumNMZlQ03eKXGZKvWa?=
=?utf-8?q?RVRmvJdGMlGE4eE8rl2mGJ4waT1TGhGwqf4+4PYdsRj3jILl9EQS4FOXQt2+74dKh?=
=?utf-8?q?f3bnPkoojgNKsRlwFjgW0BIuaVR7f+xtNXE1JEs5TJ4pnPJk3o6m1XVDkW/vMWn2f?=
=?utf-8?q?2qTHLBv9pMoAeIUjzxLcTmIMlEJyazN/aA6ysU9jJSfnzxpzDXtIfi3gFFOUkRrkq?=
=?utf-8?q?tqTabDRFT39zPQhJw1QsimwyfdSmIAVMZ9RntRObyzHndqUSxNDECEhLx5a+8DvjV?=
=?utf-8?q?Vgj8x+t3r4d9+QZ3AChWAR9CnzMTPo0mXf1shJQbOwUsuHbEH2qg+uZ40FDys+mBa?=
=?utf-8?q?UxXBoYrqalOmsNJ1ocRy0cxH/sE1080j3N9c1YrR5U9BPXdDtY5sSk7F4b/USYngk?=
=?utf-8?q?voy8yOVYG7WORxepa2+PzfgkfYqBZ2Mc9zKvyiLQOPLyPCjfFPaHQCN9dSrw7L3Z/?=
=?utf-8?q?1JpR6MqBEZENp3COuq8iMB53Brqf/aFN+PeCPSH3La0lEa+82FUp0ZcPle7oEqhKA?=
=?utf-8?q?q++o2N7PA1TWBv5qygHtGUf6UQcBhLUiSw=3D=3D?=
X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:;
IPV:NLI; SFV:NSPM; H:PUZPR06MB5676.apcprd06.prod.outlook.com; PTR:; CAT:NONE;
SFS:(13230040)(366016)(1800799024)(52116014)(376014)(38350700014); DIR:OUT;
SFP:1101;
X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1
X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?7UmduumG5r87pyB62W5gu9bZ3zO8?=
=?utf-8?q?ss2Rkdjw9rgHmQMNkK1ZmkrQz993x2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nAJmeZrx9CL1B6WbNKpCZYV44AH5O4WosMPYQrjCK2ovK?=
=?utf-8?q?Z307Pt3u7D83OgfldPckAsMsdo0mc/w/82yOTVtXcVREbaBcmvmfcPxUwe6eLPY66?=
=?utf-8?q?I5B51kWERCNUSb920ZkRSAiZyz6FbiM7pCNmeU5txmicZXeGMyaDh5AhjeEjvqIOl?=
=?utf-8?q?PwAM0diGcRR0bsauLgxGDfUvIGUMZO2qJtTnQJ5xnVvLThbF0s1dCXkYjn/7Le5IH?=
=?utf-8?q?8x/YTW/ff44HK/Sp2SOUgicdQXC8f7kTAjo6aGL6qlPxBwY/X91S0oFqijYiHsZVq?=
=?utf-8?q?kwIocre2jqynbfCewyMEja+KKBWYw6ZQhp/ajEB4Qs99cuZZywWoQ/e1c5w2CoZG/?=
=?utf-8?q?99UXb/Nvmc7rZr7gK1px9Pzlk0g1YauTX5B9f6gx7X7M1o4fa8N9gVlFHQkNQFNmw?=
=?utf-8?q?PXHXbffK8M5TBp4ASsxZVDouUpyHHWtW2O6II9W2KRs6Fn2SQ/Z50VHQ1clO/IqmO?=
=?utf-8?q?6ljyzdj6W37/nq+bhh4df2ZtDcXuU+4yVlsRJwl5GnodJTqMcptDyT95RmONXPw4g?=
=?utf-8?q?LNOTMVrzq+kI97hdlSVBZo4YGOI+DRUsCr9kuKTEIoPWcwur4pArDIidlWnMD8mlj?=
=?utf-8?q?pL8Dz3sKH7j5?=
X-OriginatorOrg: vivo.com
X-MS-Exchange-CrossTenant-Network-Message-Id:
24b1f3b8-3626-4974-a4ef-08dccbf43bf6
X-MS-Exchange-CrossTenant-AuthSource: PUZPR06MB5676.apcprd06.prod.outlook.com
X-MS-Exchange-CrossTenant-AuthAs: Internal
X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Sep 2024 08:41:41.9549 (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:
Dso8+b8AUVvpim3qBIORCPxeiASKu+ZoOqQQ3vlNwrqx2unnpJtbbe5i7h9dBRHnte/0RwRyIwyCF5IT9IL1ew==
X-MS-Exchange-Transport-CrossTenantHeadersStamped: SG2PR06MB5359
X-BeenThere: dri-devel@lists.freedesktop.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Direct Rendering Infrastructure - Development
List-Unsubscribe: ,
List-Archive:
List-Post:
List-Help:
List-Subscribe: ,
Errors-To: dri-devel-bounces@lists.freedesktop.org
Sender: "dri-devel"
When PAGE_SIZE 4096, MAX_PAGE_ORDER 10, 64bit machine,
page_alloc only support 4MB.
If above this, trigger this warn and return NULL.
udmabuf can change size limit, if change it to 3072(3GB), and then alloc
3GB udmabuf, will fail create.
[ 4080.876581] ------------[ cut here ]------------
[ 4080.876843] WARNING: CPU: 3 PID: 2015 at mm/page_alloc.c:4556 __alloc_pages+0x2c8/0x350
[ 4080.878839] RIP: 0010:__alloc_pages+0x2c8/0x350
[ 4080.879470] Call Trace:
[ 4080.879473]
[ 4080.879473] ? __alloc_pages+0x2c8/0x350
[ 4080.879475] ? __warn.cold+0x8e/0xe8
[ 4080.880647] ? __alloc_pages+0x2c8/0x350
[ 4080.880909] ? report_bug+0xff/0x140
[ 4080.881175] ? handle_bug+0x3c/0x80
[ 4080.881556] ? exc_invalid_op+0x17/0x70
[ 4080.881559] ? asm_exc_invalid_op+0x1a/0x20
[ 4080.882077] ? udmabuf_create+0x131/0x400
Because MAX_PAGE_ORDER, kmalloc can max alloc 4096 * (1 << 10), 4MB
memory, each array entry is pointer(8byte), so can save 524288 pages(2GB).
Further more, costly order(order 3) may not be guaranteed that it can be
applied for, due to fragmentation.
This patch change udmabuf array use kvmalloc_array, this can fallback
alloc into vmalloc, which can guarantee allocation for any size and does
not affect the performance of kmalloc allocations.
Signed-off-by: Huan Yang
Acked-by: Christian König
Acked-by: Vivek Kasireddy
---
drivers/dma-buf/udmabuf.c | 26 +++++++++++++-------------
1 file changed, 13 insertions(+), 13 deletions(-)
diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c
index 0a8c231a36e1..789fba312a68 100644
--- a/drivers/dma-buf/udmabuf.c
+++ b/drivers/dma-buf/udmabuf.c
@@ -111,7 +111,7 @@ static int vmap_udmabuf(struct dma_buf *buf, struct iosys_map *map)
dma_resv_assert_held(buf->resv);
- pages = kmalloc_array(ubuf->pagecount, sizeof(*pages), GFP_KERNEL);
+ pages = kvmalloc_array(ubuf->pagecount, sizeof(*pages), GFP_KERNEL);
if (!pages)
return -ENOMEM;
@@ -119,7 +119,7 @@ static int vmap_udmabuf(struct dma_buf *buf, struct iosys_map *map)
pages[pg] = &ubuf->folios[pg]->page;
vaddr = vm_map_ram(pages, ubuf->pagecount, -1);
- kfree(pages);
+ kvfree(pages);
if (!vaddr)
return -EINVAL;
@@ -227,8 +227,8 @@ static void release_udmabuf(struct dma_buf *buf)
put_sg_table(dev, ubuf->sg, DMA_BIDIRECTIONAL);
unpin_all_folios(&ubuf->unpin_list);
- kfree(ubuf->offsets);
- kfree(ubuf->folios);
+ kvfree(ubuf->offsets);
+ kvfree(ubuf->folios);
kfree(ubuf);
}
@@ -353,14 +353,14 @@ static long udmabuf_create(struct miscdevice *device,
if (!ubuf->pagecount)
goto err;
- ubuf->folios = kmalloc_array(ubuf->pagecount, sizeof(*ubuf->folios),
- GFP_KERNEL);
+ ubuf->folios = kvmalloc_array(ubuf->pagecount, sizeof(*ubuf->folios),
+ GFP_KERNEL);
if (!ubuf->folios) {
ret = -ENOMEM;
goto err;
}
- ubuf->offsets = kcalloc(ubuf->pagecount, sizeof(*ubuf->offsets),
- GFP_KERNEL);
+ ubuf->offsets = kvcalloc(ubuf->pagecount, sizeof(*ubuf->offsets),
+ GFP_KERNEL);
if (!ubuf->offsets) {
ret = -ENOMEM;
goto err;
@@ -374,7 +374,7 @@ static long udmabuf_create(struct miscdevice *device,
goto err;
pgcnt = list[i].size >> PAGE_SHIFT;
- folios = kmalloc_array(pgcnt, sizeof(*folios), GFP_KERNEL);
+ folios = kvmalloc_array(pgcnt, sizeof(*folios), GFP_KERNEL);
if (!folios) {
ret = -ENOMEM;
goto err;
@@ -384,7 +384,7 @@ static long udmabuf_create(struct miscdevice *device,
ret = memfd_pin_folios(memfd, list[i].offset, end,
folios, pgcnt, &pgoff);
if (ret <= 0) {
- kfree(folios);
+ kvfree(folios);
if (!ret)
ret = -EINVAL;
goto err;
@@ -413,7 +413,7 @@ static long udmabuf_create(struct miscdevice *device,
}
}
- kfree(folios);
+ kvfree(folios);
fput(memfd);
memfd = NULL;
}
@@ -429,8 +429,8 @@ static long udmabuf_create(struct miscdevice *device,
if (memfd)
fput(memfd);
unpin_all_folios(&ubuf->unpin_list);
- kfree(ubuf->offsets);
- kfree(ubuf->folios);
+ kvfree(ubuf->offsets);
+ kvfree(ubuf->folios);
kfree(ubuf);
return ret;
}