Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp533145ybv; Wed, 19 Feb 2020 04:29:32 -0800 (PST) X-Google-Smtp-Source: APXvYqzvB8QMp3fJ5J7/A9qXkqpj8BqdV9HY4CmiAmWG2ZXF6Q0jbkyG4CjHH3I2tNQHq6LzcGHs X-Received: by 2002:a9d:62d8:: with SMTP id z24mr18698746otk.362.1582115372179; Wed, 19 Feb 2020 04:29:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582115372; cv=none; d=google.com; s=arc-20160816; b=q11r/9EOwjmF8FHLANsCgv+Hk3TI1bu+7uEZSueHUk4af03g8C5ogfKlUyQNxcby4E P6qcQr0qDfTnLlRrHu5CRIw4wpxQ+udv2rbbkZV0mrH8TLab8jDLk/5myiP+I7zQALMp GXaPEw/hobD8fEpCa3bCL/RYU3SQrwIQE5kLT3mEGPpDChMF3i/NcREsp3o0GV6Clz8X TbhFbMyEXXSyk1MxdTk/qZdbo5hjrU98YBEu2DGgEDAeLOXx2Sx/tXMYbmAmbT5lE6FU 0RP24rigBkeL8kBY9JjQtmTM1TZooiHxe1BpiRXxXNAnS3yDO0/EtyJfYfEqcM8Xj5fS asPw== 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=OYDln46beInVpQ/IoT9/QraYqhcRvPnPr+QtiBswiSI=; b=Qqn3DQc/B2o8vFB+7ec1Tw/0YX56oIwNj8PH+ucTMeNZYlgolsK6D163PR0y7LXXg6 nGrZXB2LiWygj3Fz79ujJtp0E3yiW/quhNWLJuqwpul364Uye3xO9jJYAjc6tI99tlLV 9w0kvItTVF18rAOt0OzY2uwvmZuE0gz4TtllSoMfB2cPuf11dI5R1+ew7KxxSVmS9Uf8 1BXDh1pr1+Physv4/pZGVsfHITEBofHqm3FsBdQfKrUg0CxgLkNm7oBdRUGzA1Ve3FHP 2esKuBszcUkNA+XmiyR7zbTZ5fnn8K0qiOpm1GMjY25R8Pjina6MBR8eGGWb7+ZvbkAI 1zzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="Umn/1xga"; 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 i124si9573427oif.214.2020.02.19.04.29.16; Wed, 19 Feb 2020 04:29:32 -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="Umn/1xga"; 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 S1727495AbgBSM25 (ORCPT + 99 others); Wed, 19 Feb 2020 07:28:57 -0500 Received: from mail.kernel.org ([198.145.29.99]:44270 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726491AbgBSM25 (ORCPT ); Wed, 19 Feb 2020 07:28:57 -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 F004B21D56; Wed, 19 Feb 2020 12:28:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582115337; bh=pZqcXAmiIFw4IeJtWb4Wcj8aOi5Y83+K1GOOaMEDO7E=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Umn/1xgaV43oz7F197cgo+A0c9gYfvgLHah+dwfpDMlsoOlwhteZSYiflE5BPlul/ DX1Ql9t919o+Z0DaA7Z7VQQKBfY019XpUOFh7TO8hKi2JKQYjXO1rIu44zNL5jANbV ZCHllR7RHSdLV8ZMw/usUo5/sCFW64rEnm3GA6uM= Date: Wed, 19 Feb 2020 12:28:52 +0000 From: Will Deacon To: Robin Murphy Cc: "Isaac J. Manjarres" , iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, kernel-team@android.com, pratikp@codeaurora.org, Liam Mark Subject: Re: [RFC PATCH] iommu/iova: Add a best-fit algorithm Message-ID: <20200219122852.GB19400@willie-the-truck> References: <1581721602-17010-1-git-send-email-isaacm@codeaurora.org> 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:03:54PM +0000, Robin Murphy wrote: > On 14/02/2020 11:06 pm, Isaac J. Manjarres wrote: > > From: Liam Mark > > > > Using the best-fit algorithm, instead of the first-fit > > algorithm, may reduce fragmentation when allocating > > IOVAs. > > What kind of pathological allocation patterns make that a serious problem? > Is there any scope for simply changing the order of things in the callers? > Do these drivers also run under other DMA API backends (e.g. 32-bit Arm)? > > More generally, if a driver knows enough to want to second-guess a generic > DMA API allocator, that's a reasonable argument that it should perhaps be > properly IOMMU-aware and managing its own address space anyway. Perhaps this > effort might be better spent finishing off the DMA ops bypass stuff to make > that approach more robust and welcoming. Anecdotally, it appears to be a fairly common problem for 32-bit capable DMA masters to hit fragmentation problems with the current IOVA allocator but yes, some numbers to show how that is improved using best-fit (as opposed to e.g. worst-fit) are definitely required here. It might be that we can simply swizzle the algorithm to focus on reduced fragmentation for smaller (i.e. 32-bit) address spaces, but leave larger domains with the current approach to avoid increasing the allocation overhead. Will