Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp542433ybv; Wed, 19 Feb 2020 04:38:44 -0800 (PST) X-Google-Smtp-Source: APXvYqzN2RU41mK+mF7y6tiXeiWiFDE6M7Yv3N3R/6uaSAmKz7HCzCWKNkk7d3rqygrIfnK+E64E X-Received: by 2002:a05:6808:a8a:: with SMTP id q10mr4297874oij.66.1582115924614; Wed, 19 Feb 2020 04:38:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582115924; cv=none; d=google.com; s=arc-20160816; b=Z1gcQhpfMJHEeD6r9vu7lWiOi8d/7oCMEwlxGeYNal0HvY71MYYrACgeQeVe93KqsU 6AxkJcNz242pgiEsmkYJ8VI6ViuG79+dpnc/4QcsGOI959/40Tuvtmt0fF7OHO3PKjUE 7y5x1oj3LngnJpwL+VFgjks3UeE7eupUXnewucUaEczuTNraPRgFAghypMd6ra5aGm/I iPL3h1f6CejqGYZVlQGR/nHI5qkiB9BmkhwXLO3NQ0bbZXtGSzlH3LBNaW0ilJtvwMXw zl4ircH8dX9QH2Je9U5/j2+/5Ci3kcv+YETea3gKeRNkkLcZHPlUzKFfwWae+x9xHlCk jXbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=hHV2REZTwBVpHGeHKgB7n+ToqsqMxu33EgOfbT144pA=; b=bk/LVvhzMRgDH3ZCRkZ9yLcOBKKwJFuInsAH8o+BM/fW0IWSTgJJM/XY1cww3gYMmb YU6T9e9IPI6PDSGqUMVnFFNAxTDy+msz9HY0q4PHgvr2miQGpHQysBQwELYS2QqLUIa6 HmrFaDfkWlNs1MTmggQK+8BbP5ir2kZoBPmXRqkly5iz76eXCfOO2JUBmN2QFsdar3Ap 3+GSVA/SozSTh8zlC617pUH0kVCGftd0n0Q+WJmn3SRcUv8sy3l9wbKGi9+/QK0pKCbw nGkpkSLfLQLInKss9Wmwx1Nno12pgQU//177WW8jzwmcECErqNc1NXSOLnY17MRm4vBR 62aA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=QxlTibBt; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 9si9130377oir.71.2020.02.19.04.38.32; Wed, 19 Feb 2020 04:38:44 -0800 (PST) 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=@kernel.org header.s=default header.b=QxlTibBt; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727103AbgBSMhP (ORCPT + 99 others); Wed, 19 Feb 2020 07:37:15 -0500 Received: from mail.kernel.org ([198.145.29.99]:46482 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726491AbgBSMhP (ORCPT ); Wed, 19 Feb 2020 07:37:15 -0500 Received: from willie-the-truck (236.31.169.217.in-addr.arpa [217.169.31.236]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5505924654; Wed, 19 Feb 2020 12:37:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582115834; bh=U+Ccu+qodZQF5R9TKwMdKiDlgQqekTrccjPfmt2hzAM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=QxlTibBtDT5kOVybylM1mh7E9F5Fv+2NSpCsPVedk5Ge0FEuD5LqnEyP0P2bnhqKu KbgFaoznIVmXCPCezJXTpqcM+GuFHNPCcybbbWauQ0OoiBSmCa3I/axm41iVdGKkrt 8mUYeKW/8PeQBEfLtNTIBAdRpLcYWAhgvm9t+/e8= Date: Wed, 19 Feb 2020 12:37:04 +0000 From: Will Deacon To: Robin Murphy Cc: Liam Mark , Joerg Roedel , "Isaac J. Manjarres" , Pratik Patel , iommu@lists.linux-foundation.org, kernel-team@android.com, linux-kernel@vger.kernel.org Subject: Re: [RFC PATCH] iommu/iova: Support limiting IOVA alignment Message-ID: <20200219123704.GC19400@willie-the-truck> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Feb 17, 2020 at 04:46:14PM +0000, Robin Murphy wrote: > On 14/02/2020 8:30 pm, Liam Mark wrote: > > > > When the IOVA framework applies IOVA alignment it aligns all > > IOVAs to the smallest PAGE_SIZE order which is greater than or > > equal to the requested IOVA size. > > > > We support use cases that requires large buffers (> 64 MB in > > size) to be allocated and mapped in their stage 1 page tables. > > However, with this alignment scheme we find ourselves running > > out of IOVA space for 32 bit devices, so we are proposing this > > config, along the similar vein as CONFIG_CMA_ALIGNMENT for CMA > > allocations. > > As per [1], I'd really like to better understand the allocation patterns > that lead to such a sparsely-occupied address space to begin with, given > that the rbtree allocator is supposed to try to maintain locality as far as > possible, and the rcaches should further improve on that. Are you also > frequently cycling intermediate-sized buffers which are smaller than 64MB > but still too big to be cached? Are there a lot of non-power-of-two > allocations? Right, information on the allocation pattern would help with this change and also the choice of IOVA allocation algorithm. Without it, we're just shooting in the dark. > > Add CONFIG_IOMMU_LIMIT_IOVA_ALIGNMENT to limit the alignment of > > IOVAs to some desired PAGE_SIZE order, specified by > > CONFIG_IOMMU_IOVA_ALIGNMENT. This helps reduce the impact of > > fragmentation caused by the current IOVA alignment scheme, and > > gives better IOVA space utilization. > > Even if the general change did prove reasonable, this IOVA allocator is not > owned by the DMA API, so entirely removing the option of strict > size-alignment feels a bit uncomfortable. Personally I'd replace the bool > argument with an actual alignment value to at least hand the authority out > to individual callers. > > Furthermore, even in DMA API terms, is anyone really ever going to bother > tuning that config? Since iommu-dma is supposed to be a transparent layer, > arguably it shouldn't behave unnecessarily differently from CMA, so simply > piggy-backing off CONFIG_CMA_ALIGNMENT would seem logical. Agreed, reusing CONFIG_CMA_ALIGNMENT makes a lot of sense here as callers relying on natural alignment of DMA buffer allocations already have to deal with that limitation. We could fix it as an optional parameter at init time (init_iova_domain()), and have the DMA IOMMU implementation pass it in there. Will