From patchwork Wed Jul 10 14:09:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lei Liu X-Patchwork-Id: 13729628 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 E8553C3DA41 for ; Wed, 10 Jul 2024 20:10:22 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id F070010E027; Wed, 10 Jul 2024 20:10:21 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=vivo.com header.i=@vivo.com header.b="Slec6BHt"; dkim-atps=neutral Received: from APC01-TYZ-obe.outbound.protection.outlook.com (mail-tyzapc01on2070.outbound.protection.outlook.com [40.107.117.70]) by gabe.freedesktop.org (Postfix) with ESMTPS id A160210E7E7 for ; Wed, 10 Jul 2024 14:10:20 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gYuU/+Vr/j1FBoiakqKsyeoK/KlCf820pLltB2Wj1NlQXFe/DBIpRJ7Yxko5VMAG2Orui+hMgqVRcSeg92VGTRkpjrzSki4f7FNHf0uR+Or48+jZFRHFk2ajnoGe7gSpl8y/WtoGb0RFD5ShYhwRH9up72szwfdADbnxN8+KAvikGvuyED5VppGAZLMry8cYKmFIraire6kTzU/IokrHtrr94antfe2YIZI2vQjOH181p37a64MPMyJ5QOYmRCz6PWgzbvhcCsfYHsn8Fo5z6vyjELmGMNE6HR1CtL8/9brmGF0ABw1sBwkRfb2AiBDLTuk667XGmFnoCvAc9M3Zgg== 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=ZGQLyyp4O5Uf6YpKS7Lwp4qMYi9ESWvBfGifXLA6dNc=; b=LKTfRrxJQ4BHyK0cSNGSw55ABvKRAcs6LSBkZ5zuB4gOSgkCJ80g4RE0wyw2JcrugKPPIzZ1eUHsd97x99T7NtHfs3hxPni8Wc+drgWCZHGOF7TmzMJXQ4xIZ1uSiGGEfToa8mvXi51nHDTqrf+P8nRo3rt2x1DKeb++E/+HwNOjLbza+6j4F2yOs9+oN6l8YN5qBQoIjXK+lTb3sztOPMrt1HATr/zdTGs/D7czLBeIa6I9Qzjo3MP2Yk5VQY/f+XH6u0Bo40gj8VYmEgrzKthPZUcEBORhMzrcZ6sZx2MbdE6kqRW31I9+GGgrL2vOgUwajxP6CSemRYPka1fpnA== 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=ZGQLyyp4O5Uf6YpKS7Lwp4qMYi9ESWvBfGifXLA6dNc=; b=Slec6BHtOm8BvZyT4FtWypfXyaH5Gj+65WWNm0+BnWXsZdxtg/2BB4R7aDkMLi5UyDexgWhEUYR2DzglnxjqJIlZ+X6H41iGr8s/FCkhqZz2sjAfWc4oWMXZbeKK/tbOFe2YR8m1nBB2uX+kMKCs279rjwZrnvtlxrdOY9kVcexG5thhKCKehsPttSLxOpQej6kFRNaRxlXllxRPFD3vEhQhIpsGkfMnFDlLXGp8V9SKUN4JsjFH0QioCeZ+eXUobnNBd0nUzZzLEMUS4095I8Qkl+qGL7qIlhbD4RCeMY9gQArwkUjJBDt9hD+/hpjx1c2kPB7qOxiOKV/pcQa1Zg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=vivo.com; Received: from SEZPR06MB5624.apcprd06.prod.outlook.com (2603:1096:101:c8::14) by SEZPR06MB7077.apcprd06.prod.outlook.com (2603:1096:101:1f4::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7741.35; Wed, 10 Jul 2024 14:10:14 +0000 Received: from SEZPR06MB5624.apcprd06.prod.outlook.com ([fe80::e837:10e3:818e:bdfd]) by SEZPR06MB5624.apcprd06.prod.outlook.com ([fe80::e837:10e3:818e:bdfd%5]) with mapi id 15.20.7741.033; Wed, 10 Jul 2024 14:10:14 +0000 From: Lei Liu To: Sumit Semwal , Benjamin Gaignard , Brian Starkey , John Stultz , "T.J. Mercier" , =?utf-8?q?Christian_K=C3=B6nig?= , Andrew Morton , David Hildenbrand , Matthew Wilcox , Muhammad Usama Anjum , Andrei Vagin , Ryan Roberts , Peter Xu , Kefeng Wang , linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Cc: opensource.kernel@vivo.com, Lei Liu Subject: [PATCH 1/2] mm: dmabuf_direct_io: Support direct_io for memory allocated by dmabuf Date: Wed, 10 Jul 2024 22:09:43 +0800 Message-Id: <20240710140948.25870-2-liulei.rjpt@vivo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240710140948.25870-1-liulei.rjpt@vivo.com> References: <20240710140948.25870-1-liulei.rjpt@vivo.com> X-ClientProxiedBy: SI2PR02CA0031.apcprd02.prod.outlook.com (2603:1096:4:195::16) To SEZPR06MB5624.apcprd06.prod.outlook.com (2603:1096:101:c8::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SEZPR06MB5624:EE_|SEZPR06MB7077:EE_ X-MS-Office365-Filtering-Correlation-Id: 3cfefde5-2dad-47c5-0a0c-08dca0ea049d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|366016|376014|52116014|7416014|38350700014|921020; X-Microsoft-Antispam-Message-Info: u/aGUDZfojbwWYKcNYHVDFmiCyKFIraR2sPvEsUh9bPqEMVkTm4NsMpRBgIHFJgex0cMg/Wxu7n/zIw5B7kH2zn+ICj0vidb2crEgOjpFHaC+aMwcE9khh0ieo3+fHQE7Nh0VbgGh4wOpvMtZ/FNj/thBep1lSOsl1mBiVfklxrFWNK53T0UQ4FDmgc/pfEOD7yI9FN4aujyuh6jfH/KvNEEdNEk9KXxS7KLB7Tjq8w4FZQpKxLpHWsSAlihziPJpSkAf9QpJswImGVKmD65q7/Mxn8ZdPSGjZhhY49Vpv7pC3q5zsV8XyhnudLmL6Trbe0xIkmDtUXAiFpcreBGjEpPKIjZTFrIvPlD7M+j4/yfVCRf7eRUTvduRfA2F0VmaXk2mJ2JHKvcMUBz9wRNnP91PvM+8zVNmRA0WnQFEy/4uyqxfZ52GKcHuwAnsodcEWBUVKbNsWgfHxRowaN1hkDMHMSaJdwmZkjMG2bXvAMxEYdx5B5JydD/uufvOCnrCFGltUFHv7ftWb/Rs709CX3sWvuZlDDgJCEHL3bWs0C9Uggbj75cMhgDtprCB5NQDEXiNARcl1riCHZd+2BbKkq6qEhEuVqmxpRPsuhvXdxO3og7KJCNYF4b06heKto1NQzffb2vT6qO48D/k/BCO1x5X+z6GyqnmmGexd0CMBfggZHy7Z3kk9OgHawJdINSy5l/MR3ermHAw2CgcFnfixSx2/FGk53yZ9Exxtg7pCicSgyskddeCYzoUAA95dFeXgdoh2lDLaFfeYFvagTJ8mSLp46JPGZx0JFAgexWhikL0nxrqJYZUEhtpQUbDYnNc7yhQyzSf1nXRh+BqXPZ0jQT4bWwHwg+KJG7dyybirvthLC/qNbyo6vAelTIpIGztCnF1O62R9Hhjrn2vZB2+LbWp9QhySM7ihcsGBWiTMvE+9TBc7W194Ff/oEh8zDzb78//S34TvgpI8tyTw1RbToRhi/hTCOa/Uz/hoWQmruW0OhLixvOH/8PMy9Iq92qLL08FZ0YIi+Kr6TvpbCFS61ieJEmsWUR5DytFGniOIJcXPfD0m6EGx+r34jhLElbHmDoZOhBD0dPFj0r6PbV64p4LqCa2+3eldziTYcGpu1Vk+WcCssNRnGJxHYlYUfx7PtKR0vZM/38xGhKRmnVsL3Tk3kxwfK4jgHdhEbFV7iCVE2AriEeP9zhJmpTc7al7vHyj3KdqZppvQfs0aqH61IhA3PgihCO3s0LmRCLa2CzsaV/tNwIUebXDdprCpnt/VgBgrp29JAdWZFD565IlaXfH8QSxL0sY6cY6M/n0bPMFiQSYViigNyQyv+WBQIKZM9CtSpguseQCApZaqJVsexVICWLOLsaIQ0PA3dt3WwMiVhqeUH2cMBbIXZkvd2xz9jXNs3aVEkJUol8S6MYptV4ompIz7JWr0bRXivU3hg= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SEZPR06MB5624.apcprd06.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(1800799024)(366016)(376014)(52116014)(7416014)(38350700014)(921020); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: FqdvLa6Suw/HRehljZh1WxQ4ZNEJp6x5N7gjltMqknWku/y/ggrBocwzW++O7297z7sXDkQpY9xP3aApFOKP2qARr60Zp07VkmZqhEGGP8GAv557mLw3fX8eoxNSAtnhj2L2gvC/uc/xxAS4ZvitCWI/xo+UjUOhdMc1jookolYN3zuw3kgy98AejJn/vh1hk0z/tYH3oIKTwxXbZ9mH0+vMd/hSSgqdUYvNbHtUELbGS4B5qaMRIx2H3lqSCWvIoygzv06+sm27+37O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x3NJquaJjrBE9TuDJoSU2XXRYfZj5IBVV87i+APu/Lzat06mX7SuvFk+KiMXGmAY4MUOG/rZhLwyARmc+3z//2fiTLHc0t0rG0IqRXhEf28Rk87YU7w6QYo0h8+gmbLk7F2ZtGWRnHf4hYbCHvhAGMtpmLmy1S5+Q9RT8ntuYHQt4+7MHrtOVQfSh33ItJC3pTJ4co89ZfczHFXNH8aRZjlNsX1xgEz6ksuBy0ey8sB9QSyhFep90G X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3cfefde5-2dad-47c5-0a0c-08dca0ea049d X-MS-Exchange-CrossTenant-AuthSource: SEZPR06MB5624.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jul 2024 14:10:14.1583 (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: QGL90Q66LYoNFkc0DM+n5/187aGLq51wvJsu2b4Za5/kfeFoyTt8x30U4YS6JqGlJ9jkH2xpfpwfxgExyoxFUw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SEZPR06MB7077 X-Mailman-Approved-At: Wed, 10 Jul 2024 20:10:21 +0000 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" 1.Effects and reasons for lack of support: Currently, memory allocated by dmabuf cannot be read from files using direct_io. With the increasing use of AI models in mobile applications, there is a growing need to load large model files occupying up to 3-4GB into mobile memory. Presently, the only way to read is through buffer_io, which limits performance. In low memory scenarios on 12GB RAM smartphones, buffer_io requires additional memory, leading to a 3-4 times degradation in read performance with significant fluctuations. The reason for the lack of support for direct_io reading is that the current system establishes mappings for memory allocated by dmabuf using remap_pfn_range, which includes the VM_PFN_MAP flag. When attempting direct_io reads, the get_user_page process intercepts the VM_PFN_MAP flag, preventing the page from being returned and resulting in read failures. 2.Proposed solution: (1) Establish mmap mappings for memory allocated by dmabuf using the vm_insert_page method to support direct_io read and write. 3.Advantages and benefits: (1) Faster and more stable reading speed. (2) Reduced pagecache memory usage. (3) Reduction in CPU data copying and unnecessary power consumption. 4.In a clean and stressapptest(a 16GB memory phone consumed 4GB of memory). A comparison of the time taken to read a 3.2GB large AI model file using buffer_io and direct_io. Read 3.21G AI large model file on mobilephone Memstress Rounds DIO-Time/ms BIO-Time/ms 01 1432 2034 Clean 02 1406 2225 03 1476 2097 average 1438 2118 Memstress Rounds DIO-Time/ms BIO-Time/ms 01 1585 4821 Eat 4GB 02 1560 4957 03 1519 4936 average 1554 4905 Signed-off-by: Lei Liu --- drivers/dma-buf/heaps/system_heap.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/dma-buf/heaps/system_heap.c b/drivers/dma-buf/heaps/system_heap.c index 9076d47ed2ef..87547791f9e1 100644 --- a/drivers/dma-buf/heaps/system_heap.c +++ b/drivers/dma-buf/heaps/system_heap.c @@ -203,8 +203,7 @@ static int system_heap_mmap(struct dma_buf *dmabuf, struct vm_area_struct *vma) for_each_sgtable_page(table, &piter, vma->vm_pgoff) { struct page *page = sg_page_iter_page(&piter); - ret = remap_pfn_range(vma, addr, page_to_pfn(page), PAGE_SIZE, - vma->vm_page_prot); + ret = vm_insert_page(vma, addr, page); if (ret) return ret; addr += PAGE_SIZE;