From mboxrd@z Thu Jan 1 00:00:00 1970 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9D535C19F2B for ; Thu, 4 Aug 2022 10:07:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E291B8E0002; Thu, 4 Aug 2022 06:07:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DB1EB8E0001; Thu, 4 Aug 2022 06:07:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C52858E0002; Thu, 4 Aug 2022 06:07:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id B303C8E0001 for ; Thu, 4 Aug 2022 06:07:49 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 7D62B80CB8 for ; Thu, 4 Aug 2022 10:07:49 +0000 (UTC) X-FDA: 79761483858.15.E5D463B Received: from sender4-op-o18.zoho.com (sender4-op-o18.zoho.com [136.143.188.18]) by imf14.hostedemail.com (Postfix) with ESMTP id CF6E8100134 for ; Thu, 4 Aug 2022 10:07:48 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; t=1659607643; cv=none; d=zohomail.com; s=zohoarc; b=K3qQct6hiCA/qe/3eqqnDutSYrR9u7uP3HOb7EIP8GEJqUAitwA91frWueKA3Mr9XKptJ6bpo6FhLheBB04Zgi+2fmlAtBxoD4y1q05l6/fk9IYKpTJnf687Gz8wLe9OWSaSwcQCg6cRz71LAILzPbIpeKu+HX/RA5ornVRRr54= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1659607643; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=BHejHdt53IEYuzqZbZN4EusFHlxvwpJaRPIFVXZsQ/w=; b=oA7dFRe5t/efFEy7oUCXGA+CSU5zAU+r4dZ5zGXI+ICM+7SHvMdFHQzrSlsCjYgx/6XvF4nQZ4ym2jGNiDAMSDeeqsGRRZAfL+IAiUq8TyqdbM817KrnAkY2/pxmJnZL9H8A0vSeLfrVX0ysZe2oWvbr51v/R+zujEzsPW5ZG+I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=linux.beauty; spf=pass smtp.mailfrom=me@linux.beauty; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1659607643; s=zmail; d=linux.beauty; i=me@linux.beauty; h=Date:Date:From:From:To:To:Cc:Cc:Message-ID:In-Reply-To:References:Subject:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Reply-To; bh=BHejHdt53IEYuzqZbZN4EusFHlxvwpJaRPIFVXZsQ/w=; b=XpS5AYaon+tYseVZnl44dhmDfl317SyeYKksKDmAij+hF8ZNQHj7flbeunxif3lN f6DW50VFI4RnnL8davV2RenrhkQSR5Gxncnl1EAkDY0+LBzAHCALXqVnc2obmYGgTdK 8uJM9nU2fj1HhZcAFqV6c9gbGAaql7cqIK/jma54= Received: from mail.zoho.com by mx.zohomail.com with SMTP id 1659607640663544.5780582971333; Thu, 4 Aug 2022 03:07:20 -0700 (PDT) Date: Thu, 04 Aug 2022 19:07:20 +0900 From: Li Chen To: "Arnd Bergmann" Cc: "Catalin Marinas" , "Will Deacon" , "Rob Herring" , "Frank Rowand" , "Andrew Morton" , "Li Chen" , "Linux ARM" , "Linux Kernel Mailing List" , "DTML" , "Linux-MM" Message-ID: <1826852ea3a.10a917cc826728.6077661125986568031@linux.beauty> In-Reply-To: References: <20220711122459.13773-1-me@linux.beauty> <20220711122459.13773-5-me@linux.beauty> <181efcca6ae.de84203d522625.7740936811073442334@linux.beauty> <18267b7a61f.12b26bd91245310.4476663913461696630@linux.beauty> Subject: Re: [PATCH 4/4] sample/reserved_mem: Introduce a sample of struct page and dio support to no-map rmem MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Importance: Medium User-Agent: Zoho Mail X-Mailer: Zoho Mail ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1659607669; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=BHejHdt53IEYuzqZbZN4EusFHlxvwpJaRPIFVXZsQ/w=; b=oly3Hd1RZLWXQv+D5p32fg1d49m3Wgf3klb/y4Ly8VXObKeHIjy2MHmJKIFL5HRFLy9lPl 36rsm6p8zCCXuTwv3DVIHy1DxcqwHMR1KX0ZdEB0pzjlrXhJuBQOGk5WuqAdtrvhl7sxyc nla/f2mP1ugQmmj3G9cRBPdiujEf6yQ= ARC-Authentication-Results: i=2; imf14.hostedemail.com; dkim=pass header.d=linux.beauty header.s=zmail header.b=XpS5AYao; spf=pass (imf14.hostedemail.com: domain of me@linux.beauty designates 136.143.188.18 as permitted sender) smtp.mailfrom=me@linux.beauty; arc=pass ("zohomail.com:s=zohoarc:i=1"); dmarc=none ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1659607669; a=rsa-sha256; cv=pass; b=k30Loj0en+1g1BOv1rMjxblpWDPXD5d6fxipSY7nRZnWm7nDh5Top1NmNPJT9PVptNwhmK sktc73aXyqqzx5JGycwdbwa+CvIgygFcHXw746btrpz/mq8qMzST4HcTwksv8vXvkv+sV+ 3vXqZY7c02t+y7kXSvB2uJbe75o+U6s= X-Rspam-User: Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=linux.beauty header.s=zmail header.b=XpS5AYao; spf=pass (imf14.hostedemail.com: domain of me@linux.beauty designates 136.143.188.18 as permitted sender) smtp.mailfrom=me@linux.beauty; arc=pass ("zohomail.com:s=zohoarc:i=1"); dmarc=none X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: CF6E8100134 X-Stat-Signature: eiqcbc8pg5fbbj8kyumsrbxjp96ashws X-HE-Tag: 1659607668-170848 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: ---- On Thu, 04 Aug 2022 17:24:20 +0900 Arnd Bergmann wrote --- > On Thu, Aug 4, 2022 at 9:17 AM Li Chen me@linux.beauty> wrote: > > ---- On Tue, 12 Jul 2022 16:50:46 +0900 Arnd Bergmann wrote --- > > > Does your hardware require a fixed address for the buffer? If it can be > > > anywhere in memory (or at least within a certain range) but just has to > > > be physically contiguous, the normal way would be to use a CMA area > > > to allocate from, which gives you 'struct page' backed pages. > > > > CMA does support Direct I/O, but it has its own issue: > > It does not guarantee that the memory previously borrowed by the OS will be returned to the device. > > > > We've been plagued by examples like this in the past: > > Many other kernel modules/subsystems have already allocated much memory from both non-CMA and CMA memory, > > When our DSP driver got probed then, cma_alloc will fail in that non-CMA system memory is not enough > > for CMA memory to migrate. > > This part should at least be possible to solve by declaring the amount > and location of > CMA areas in the right way. It's not great to fine-tune the DT for a > particular kernel's > use, but if you know which other drivers require CMA type allocations > you can find a lower > bound that should suffice. That's the problem, haha. End users(customers) may modprobe many other modules and modprobe our driver in the end. We cannot decide the probe order for end users. Apart from our cases, I heard there are some other cases where cma_alloc failed even non-cma system memory has enough memory because pages in CMA memory are pinned and cannot move out of CMA. There are some fixes like 1. move these memory out of CMA before pinned 2. only allow non-long-time pinned memory allocation from CMA. But these two solutions are not merged into the mainline yet. > > Most coherent allocations tend to be long-lived and only for very > small memory regions. > If you have another driver that uses large or periodic > dma_alloc_coherent() type allocations, > you can consider either giving that device its own CMA area, or fixing > it to use streaming > mappings. Device-wise CMA also suffers from the problems I mentioned, other modules/subsystems may have already alloc from this CMA area and refuse to return it back. Regards, Li