Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2146130imm; Sat, 2 Jun 2018 19:12:36 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJPbK51VO3rOAnOSzbBRFei655QdLm0w5Tx4/IhZSSqy/TbE9rBf9KZEWTzjGCaxHpyINLL X-Received: by 2002:a17:902:8207:: with SMTP id x7-v6mr16674555pln.100.1527991956920; Sat, 02 Jun 2018 19:12:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527991956; cv=none; d=google.com; s=arc-20160816; b=fOfsA7Vy0OIe5bcdbvrKZC/kOopTW43HDRKiTI2oTpG3ti7NWaV01IhTqRfwHkGnux Vry0pTu9JBgp1ToRKgSUYrSO77AZtXramfWTPCpI0ZbYuAHW3IdkWNFWlXBrP749QliT bvhr6T95UakmZLVr87NPwfgLYvzXabzG4KmLOgSZXTcBBidHkqu7G+74Yj+rLkxeUzo1 ic7HMu8I4GzPoeSHR+GrGvHIfSEMKfMHutWeRCjJwCosckISwh+MfPHNeeZUAlPp1PK8 Z45Kz4cnbopOC0SpFWp1Sb6eNhTEcWyFR903INcYiRikqjmoN81PSgy/fKkw+o5JwBDy XGmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=WggnlEq03NAqQC5H4JirXiWn5c1+zk6MRN9vRbiQtnY=; b=BMeXZtlPDUbWwvd6FI7DNlEe3iX1wMmwd2yWGv+EjAWS/HHKt11D5JBjyRYm8SZDwH 6BWMQXz0AxmLC/LgsXRameRvN0DwMvVKw+kmPq8O0oBfTCVGZjvHE9h0b6POC+Tg4lSI xdHzgwB7taYBp1xYEa1QpiYnn5wWyJNYfiKKxGVL4YE7JI8WhQObKubp5tb7s/TEVb0K arJW46+nNncx1dn5rB1Kal3CFmBPwRaQlpEOWbtiI5z7Cu74hFh7SOs8ZFpTKRbh9Et/ 64+CakQpq8djnuZCd/afOkRcNm7TNxgrFdw5P6m9bYGh3ciwxBjdEPoT4/cDEZTvKg5b XxJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CBjZpFSc; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u4-v6si21542389plj.43.2018.06.02.19.12.22; Sat, 02 Jun 2018 19:12:36 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CBjZpFSc; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751093AbeFCCL6 (ORCPT + 99 others); Sat, 2 Jun 2018 22:11:58 -0400 Received: from mail-oi0-f67.google.com ([209.85.218.67]:45878 "EHLO mail-oi0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750983AbeFCCL5 (ORCPT ); Sat, 2 Jun 2018 22:11:57 -0400 Received: by mail-oi0-f67.google.com with SMTP id b130-v6so25557583oif.12 for ; Sat, 02 Jun 2018 19:11:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=WggnlEq03NAqQC5H4JirXiWn5c1+zk6MRN9vRbiQtnY=; b=CBjZpFScGwWqSuXXR1yOqLNWwJI6DeyyF9Ctk5zd92rw3uvWFnYzaQ8KtZvJNLhqOq Dl3Wn0QUErcy2a2zykJGPGETa/IiHIn4J4iYQW54YkXV9f3kuP5T0a1GBEhGz65j+GmN 8jPk9lWIptAqWX2qd3hJ3vtnCQcHlwkTOZFO4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=WggnlEq03NAqQC5H4JirXiWn5c1+zk6MRN9vRbiQtnY=; b=Hhtb4+Hf4d4z8AeXgEAYgVvVMrgs87AiaYWaDrcnfj3ZIzUSZF90wFyvpFi6hqN94q OwZG3izFwheB5Ay5mv85H5+dRQwUc+/75zMcTH3TEJfTUFgNq6AYeULlGWTEvXjTWmd0 wOy3Gh7b9GDkRan4x0DRxiC6LVoRZZLJMjZNnPpRQ5RJV/Muq3etAY6tjSBNVStKmDVY qIbhVhE5DtDooN3cN7mZt/wdX6Z5Axp1Ul9z+YEMunw5wOIxBj2ZAm1oHyZ8OZhktunT +WmlgSkx0LUG6QArDTevmsKMyAddKHrhAAqiFYx8onqA8dg/DliHWJzhnq/ouwL8dP6A 2KAA== X-Gm-Message-State: APt69E0w61t+b9qcey9oXgafAeGLkny0MKLCKIg+8IAy1obVg48PZhK7 hiKrN1TFP9I+tDArs/WOsNkRj3iv8/XLkFhvjWK40Q== X-Received: by 2002:aca:3c07:: with SMTP id j7-v6mr9823741oia.128.1527991916459; Sat, 02 Jun 2018 19:11:56 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a9d:2d44:0:0:0:0:0 with HTTP; Sat, 2 Jun 2018 19:11:55 -0700 (PDT) In-Reply-To: <8ef2eacf-97af-3449-c3ef-c64516ee05ea@arm.com> References: <892fabb55ebe7bb35aa3f0be03ee3f93132b7acc.1527745258.git.baolin.wang@linaro.org> <8ef2eacf-97af-3449-c3ef-c64516ee05ea@arm.com> From: Baolin Wang Date: Sun, 3 Jun 2018 10:11:55 +0800 Message-ID: Subject: Re: [PATCH 2/2] dma-coherent: Change the bitmap APIs To: Robin Murphy Cc: hch@lst.de, Marek Szyprowski , Greg KH , iommu@lists.linux-foundation.org, LKML , Arnd Bergmann , Mark Brown Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 1 June 2018 at 01:38, Robin Murphy wrote: > On 31/05/18 06:55, Baolin Wang wrote: >> >> The device coherent memory uses the bitmap helper functions, which take an >> order of PAGE_SIZE, that means the pages size is always a power of 2 as >> the >> allocation region. For Example, allocating 33 MB from a 33 MB dma_mem >> region >> requires 64MB free memory in that region. >> >> Thus we can change to use bitmap_find_next_zero_area()/bitmap_set()/ >> bitmap_clear() to present the allocation coherent memory, and reduce the >> allocation granularity to be one PAGE_SIZE. >> >> Moreover from Arnd's description: >> "I believe that bitmap_allocate_region() was chosen here because it is >> more efficient than bitmap_find_next_zero_area(), at least that is the >> explanation given in >> https://en.wikipedia.org/wiki/Buddy_memory_allocation. >> >> It's quite possible that we don't actually care about efficiency of >> dma_alloc_*() since a) it's supposed to be called very rarely, and >> b) the overhead of accessing uncached memory is likely higher than the >> search through a relatively small bitmap". >> >> Thus I think we can convert to change the allocation granularity to be >> one PAGE_SIZE replacing with new bitmap APIs, which will not cause >> efficiency issue. > > > To quote the DMA API docs: > > "The CPU virtual address and the DMA address are both > guaranteed to be aligned to the smallest PAGE_SIZE order which > is greater than or equal to the requested size. This invariant > exists (for example) to guarantee that if you allocate a chunk > which is smaller than or equal to 64 kilobytes, the extent of the > buffer you receive will not cross a 64K boundary." > > Now obviously there's a point above which that stops being practical, but Agree. > it's probably safe to assume that a device asking for a multi-megabyte > buffer doesn't actually have stringent boundary requirements either. For > smaller sizes, though, it definitely can matter. At the very least up to > 64KB, and probably up as far as MAX_ORDER-size requests, we need to preserve > the existing behaviour or something, somewhere, will break. Some devices really don't care the boundary issue, and as you said maybe some devices will care for smaller sizes. So I think this is depend on the devices' requirement, then can we add one boundary parameter for the allocation according to the devices requirement? Or like I said, we will waste lots of reserved memory if the granularity is so large. Thanks for your comments. -- Baolin.wang Best Regards