From patchwork Wed Dec 28 11:58:53 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 9490283 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9D1EA60488 for ; Wed, 28 Dec 2016 11:59:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 82A1525F31 for ; Wed, 28 Dec 2016 11:59:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 772B026247; Wed, 28 Dec 2016 11:59:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 25FD925F31 for ; Wed, 28 Dec 2016 11:59:03 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E1E4F89EAE; Wed, 28 Dec 2016 11:59:00 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-wm0-x243.google.com (mail-wm0-x243.google.com [IPv6:2a00:1450:400c:c09::243]) by gabe.freedesktop.org (Postfix) with ESMTPS id DFCB289EAE for ; Wed, 28 Dec 2016 11:58:58 +0000 (UTC) Received: by mail-wm0-x243.google.com with SMTP id c85so23450955wmi.1 for ; Wed, 28 Dec 2016 03:58:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id; bh=jruNcMWkZ0ZGPdqRosOzuCZ4bZw5YdOWHJkmNylgctI=; b=XIhEY5Kfgi6z+/A0QXV+y+NO7AWG+rFws4cE33k3S9nhLRCsDIv3WAADQq+puAlz4x 5yud6V6CQbD+0jnXn5jOiG9mIFnRMJtcwVZIVysc3JPszRu+CDQGjBuY51H19yBibN5a 4ZDN0TuXQpKhH0DZ+71UBm6Thw01duM3UphMxkur9Al7AMQmXGoec/U29ja/rvdgoojC I/lzLt6U8DedQftGZwTLbq+M6L9yZ+PonkpUnXyYtveJQUOSPsgPNO3xhOLSCuESe8ki yr3qlBAkYkOUJ098H3SuzjDpefYE9KWtiGyFNNrPQ9u+wvb2n9cvaWcyL3ahIq6cEwtE N7qA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=jruNcMWkZ0ZGPdqRosOzuCZ4bZw5YdOWHJkmNylgctI=; b=h8Cyo3jWblTSGXv9ditEXqGnKXYPaduvBnodC8WPWEEA9FJOHskgBXNvewc7hN7Qww 4odRW8klq4Huj7yhAJ5ziQ8ZgTTTsSyG9H9BrEqq+LsV1qaCj9LdNMmCo+KBMLEWZeib rKEcw4qfE6Dp4d2k2X5qbq3w++5BYDkGN/c0n3BnduYt1Ns/6NOytG/HSKgH3w755S6t NCQbbhAb6akGutrrhDCPj6AWJXE6iWZmMN07gCbrdTH+tlTWt60Ka5+Q7c6gLjgXLcs/ ISEggv/ndpEm0gPyPy0hHe7N/dcvxX3ZuaQCFzot4C6GO4bKK9OTDz+e8jqta7vo8Jdt SR4g== X-Gm-Message-State: AIkVDXK8BHpRcOdQP81DEpzk77/GtsazCVjbmnx+YLku4R62qTIPTBDfkZL4ixv888JyxQ== X-Received: by 10.28.225.138 with SMTP id y132mr32964147wmg.52.1482926336951; Wed, 28 Dec 2016 03:58:56 -0800 (PST) Received: from haswell.alporthouse.com ([78.156.65.138]) by smtp.gmail.com with ESMTPSA id ei2sm63824344wjd.47.2016.12.28.03.58.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 28 Dec 2016 03:58:56 -0800 (PST) From: Chris Wilson To: intel-gfx@lists.freedesktop.org Date: Wed, 28 Dec 2016 11:58:53 +0000 Message-Id: <20161228115853.2298-1-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.11.0 Subject: [Intel-gfx] [PATCH] drm/i915: Purge loose pages if we run out of DMA remap space X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP If the DMA remap fails, one cause can be that we have too many objects pinned in a small remapping table, such as swiotlb. (DMA remapping does not trigger the shrinker by itself on its normal failure paths.) So try purging all other objects (using i915_gem_shrink_all(), sparing our own pages as we have yet to assign them to the obj->pages) and try again. If there are no pages to reclaim (and consequently no pages to unmap), the shrinker will report 0 and we fail with -ENOSPC as before. Signed-off-by: Chris Wilson --- drivers/gpu/drm/i915/i915_gem_gtt.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c b/drivers/gpu/drm/i915/i915_gem_gtt.c index bc2b4421cbd6..b04581035953 100644 --- a/drivers/gpu/drm/i915/i915_gem_gtt.c +++ b/drivers/gpu/drm/i915/i915_gem_gtt.c @@ -2361,10 +2361,24 @@ void i915_gem_suspend_gtt_mappings(struct drm_i915_private *dev_priv) int i915_gem_gtt_prepare_pages(struct drm_i915_gem_object *obj, struct sg_table *pages) { - if (dma_map_sg(&obj->base.dev->pdev->dev, - pages->sgl, pages->nents, - PCI_DMA_BIDIRECTIONAL)) - return 0; + do { + if (dma_map_sg(&obj->base.dev->pdev->dev, + pages->sgl, pages->nents, + PCI_DMA_BIDIRECTIONAL)) + return 0; + + /* If the DMA remap fails, one cause can be that we have + * too many objects pinned in a small remapping table, + * such as swiotlb. Incrementally purge all other objects and + * try again - if there are no more pages to remove from + * the DMA remapper, i915_gem_shrink will return 0. + */ + GEM_BUG_ON(obj->mm.pages == pages); + } while (i915_gem_shrink(to_i915(obj->base.dev), + obj->base.size >> PAGE_SHIFT, + I915_SHRINK_BOUND | + I915_SHRINK_UNBOUND | + I915_SHRINK_ACTIVE)); return -ENOSPC; }