Received: by 10.192.165.148 with SMTP id m20csp3695398imm; Mon, 23 Apr 2018 10:42:49 -0700 (PDT) X-Google-Smtp-Source: AIpwx49D62MPuw0pxJRDse9D+g37amOjFVEoAwNzXUxcB6U5F90cHJEwK4M/0shrUddrQN1N5E0f X-Received: by 10.99.95.5 with SMTP id t5mr17391369pgb.165.1524505369161; Mon, 23 Apr 2018 10:42:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524505369; cv=none; d=google.com; s=arc-20160816; b=SDshZ3m2k3+53a6KkKdIOemkcKPgGH02yINjHFE6hehHm2I9jpvlCR7kjgGrR9OT6n bdOAw6gwxjHa9/+oGzrTny0PBNDkkVauZPCvLhnFOKwB0mPAlJe5eVPNG9C6LdIZtrq9 xUFOuiaYZWSQg6cNFHosaRnqVLxgc4bbriopVzKPxlfcqwPTzghY32GCJyp1OxHtO2OR a1OGl/QS6thVSkHC7v0HBfeFSKW8l+0fvu+y3BiskjbsMHoqhqcBhGttuX0U8X4uYaq4 izzZRUuJiy1AXEMFX0WNsExKvA6PXXu1/J6ayV4A4d2Wcer7q3+bake8Fzd/q6hSO7m+ rqEw== 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=y28RtaTuDJphwWBmgZz7mp+xDAJzqP61I4P/AV2e/QM=; b=gm0Mt8Z5lE3eqO9vES0IXyuHWhfl0YYiUmzvfUFmoOK3XIbajtENV/545qmOVbIels 3EX7xuFPOITgdg0qQ7Kf/rSsW4cI/7nDPN1y5iK7MMndi/XE4+cUi98ZJVqXU2emZx0T kUZDfpd2pr9aP0ZfV4KJkS+anShp9FA/u99cqM1TRKLr0Fga5ayxyC2ATUpee6SYFazc PQSOKKrKpf8jgLe5fcobhI5RSnc59qHEipn9RPESU1hIIfCWYTUlOW/XRCLXPRRncmU+ 9rQgDH9E0XHCiUnOK4k4V66LDzqhLQ8whxoTa9WbvzY53mWr3fP31V4Tv4GRtGlXNbSq CMCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=M+NU/Nz8; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k8si3872671pgt.211.2018.04.23.10.42.34; Mon, 23 Apr 2018 10:42:49 -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=@gmail.com header.s=20161025 header.b=M+NU/Nz8; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932297AbeDWRlW (ORCPT + 99 others); Mon, 23 Apr 2018 13:41:22 -0400 Received: from mail-ot0-f196.google.com ([74.125.82.196]:44667 "EHLO mail-ot0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932079AbeDWRlO (ORCPT ); Mon, 23 Apr 2018 13:41:14 -0400 Received: by mail-ot0-f196.google.com with SMTP id g7-v6so8916601otj.11 for ; Mon, 23 Apr 2018 10:41:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=y28RtaTuDJphwWBmgZz7mp+xDAJzqP61I4P/AV2e/QM=; b=M+NU/Nz8jqUg7M0jNZwpVHz93EeQQVqmgBd4/P/KZjIQYnxmZkOUusrVLkcvCFd4C6 0mnBZmgSuclT05bci7iexy6sa2tr/4VXp0CFMgBsOG2klBr99BJCQHzSXMWh9WZtg/xa UiwL4tbZ4q52Ic/oE4+vnRHNtf+8biFvjDWBo1iKAqlUOaD3bF1EEkRcGos0zv1uF0Er 5wgz/D24eozKfDOGXovrU+7mpbD0hhgWUzBUA68OzvEDtN6V0mEhamPoEIT1uhkMLgzk btze5LxAbX/x1Uwy972OlhHdPLq794hw/mJIlvHFzBRNdIqwl/WuBzkxH8VG2BcMFWWt 5UVw== 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=y28RtaTuDJphwWBmgZz7mp+xDAJzqP61I4P/AV2e/QM=; b=TgDTy/krjZcRv0seGn1UbSgyrhtPksyXErpYdEuzqEXOpHJF7Mj73L8LvisRu+z354 jIoF61CPEaeCcnugBbTBH2Mqmiojl2LzoL7l7qqAYL+0J38nJkCSYQZCnBnFP+9lovIG 6QDdP8t7OWGJfVrcN3Bv8Nwrkr/XTXoA8hcn/27jQ2rPsJ4OgbJ3DbZimjDPtSZ2itfu aKCQTLNxKvmricy3OUuMD9S4PacZiuUobtuTFYJiNCG2itDuypOv5LAle2Y+bX+RrpTp 9kmBIcRiPfUHsM8ZMm9tczadRTXSKj7OOyBJft3V5pn5ZbAkgyddDN2q+kncSi5sKpD4 hwXA== X-Gm-Message-State: ALQs6tCLrdOXnsTB8KXlqlZIL7VvAjcRwzUYQ3Rg+WDiyZAorUCcShMY FpIWffiE6QrcMssJDbrW7+ODQYydVrIJ7BxEp4Q= X-Received: by 2002:a9d:2842:: with SMTP id h2-v6mr9981345otd.210.1524505273975; Mon, 23 Apr 2018 10:41:13 -0700 (PDT) MIME-Version: 1.0 Received: by 10.201.116.209 with HTTP; Mon, 23 Apr 2018 10:41:13 -0700 (PDT) In-Reply-To: References: <20180419171234.11053-1-ganapatrao.kulkarni@cavium.com> From: Ganapatrao Kulkarni Date: Mon, 23 Apr 2018 23:11:13 +0530 Message-ID: Subject: Re: [PATCH] iommu/iova: Update cached node pointer when current node fails to get any free IOVA To: Robin Murphy Cc: Ganapatrao Kulkarni , Joerg Roedel , iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, tomasz.nowicki@cavium.com, jnair@caviumnetworks.com, Robert Richter , Vadim.Lomovtsev@cavium.com, Jan.Glauber@cavium.com 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 Mon, Apr 23, 2018 at 10:07 PM, Robin Murphy wrote: > On 19/04/18 18:12, Ganapatrao Kulkarni wrote: >> >> The performance drop is observed with long hours iperf testing using 40G >> cards. This is mainly due to long iterations in finding the free iova >> range in 32bit address space. >> >> In current implementation for 64bit PCI devices, there is always first >> attempt to allocate iova from 32bit(SAC preferred over DAC) address >> range. Once we run out 32bit range, there is allocation from higher range, >> however due to cached32_node optimization it does not suppose to be >> painful. cached32_node always points to recently allocated 32-bit node. >> When address range is full, it will be pointing to last allocated node >> (leaf node), so walking rbtree to find the available range is not >> expensive affair. However this optimization does not behave well when >> one of the middle node is freed. In that case cached32_node is updated >> to point to next iova range. The next iova allocation will consume free >> range and again update cached32_node to itself. From now on, walking >> over 32-bit range is more expensive. >> >> This patch adds fix to update cached node to leaf node when there are no >> iova free range left, which avoids unnecessary long iterations. > > > The only trouble with this is that "allocation failed" doesn't uniquely mean > "space full". Say that after some time the 32-bit space ends up empty except > for one page at 0x1000 and one at 0x80000000, then somebody tries to > allocate 2GB. If we move the cached node down to the leftmost entry when > that fails, all subsequent allocation attempts are now going to fail despite > the space being 99.9999% free! > > I can see a couple of ways to solve that general problem of free space above > the cached node getting lost, but neither of them helps with the case where > there is genuinely insufficient space (and if anything would make it even > slower). In terms of the optimisation you want here, i.e. fail fast when an > allocation cannot possibly succeed, the only reliable idea which comes to > mind is free-PFN accounting. I might give that a go myself to see how ugly > it looks. i see 2 problems in current implementation, 1. We don't replenish the 32 bits range, until first attempt of second allocation(64 bit) fails. 2. Having per cpu cache might not yield good hit on platforms with more number of CPUs. however irrespective of current issues, It makes sense to update cached node as done in this patch , when there is failure to get iova range using current cached pointer which is forcing for the unnecessary time consuming do-while iterations until any replenish happens! thanks Ganapat > > Robin. > > >> Signed-off-by: Ganapatrao Kulkarni >> --- >> drivers/iommu/iova.c | 6 ++++++ >> 1 file changed, 6 insertions(+) >> >> diff --git a/drivers/iommu/iova.c b/drivers/iommu/iova.c >> index 83fe262..e6ee2ea 100644 >> --- a/drivers/iommu/iova.c >> +++ b/drivers/iommu/iova.c >> @@ -201,6 +201,12 @@ static int __alloc_and_insert_iova_range(struct >> iova_domain *iovad, >> } while (curr && new_pfn <= curr_iova->pfn_hi); >> if (limit_pfn < size || new_pfn < iovad->start_pfn) { >> + /* No more cached node points to free hole, update to leaf >> node. >> + */ >> + struct iova *prev_iova; >> + >> + prev_iova = rb_entry(prev, struct iova, node); >> + __cached_rbnode_insert_update(iovad, prev_iova); >> spin_unlock_irqrestore(&iovad->iova_rbtree_lock, flags); >> return -ENOMEM; >> } >> >