From patchwork Mon Dec 4 12:46:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_K=C3=B6nig?= X-Patchwork-Id: 10090185 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 0BDE660329 for ; Mon, 4 Dec 2017 12:46:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1FFE128C05 for ; Mon, 4 Dec 2017 12:46:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 126F62916B; Mon, 4 Dec 2017 12:46:22 +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_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, 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 A2FB128C05 for ; Mon, 4 Dec 2017 12:46:21 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 120396E378; Mon, 4 Dec 2017 12:46:19 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@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 F3D416E378; Mon, 4 Dec 2017 12:46:17 +0000 (UTC) Received: by mail-wm0-x243.google.com with SMTP id 64so13987464wme.3; Mon, 04 Dec 2017 04:46:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=gvJvLjozCLsZNwTbdjUDfFxOcdeK4EvZBL63AQ5I9Z8=; b=qxwskYuwHIK+ntlstOoWaQvrVRCJikKTzNHiak/8+CVLt9DV0nRp+pO2ys2G99fLwi 2ZslI2bJzritfv8h6zCktU7XfaZBs9jP6g3up/wg85nzHMnm6rDxdMcY1YiuPwyfUEXR opDVsv3jXDqR3kGcuzHiraZS+YDfPL2KjpXYWBRou3v/ObZ6cfYliiNslq161OQItndu +T6Idj4Ivg1hmRog/BTY7fWeeZ3zDpcvTX69DMYQzYZr8PK4Afn/3gjf5A2qm8Tx/4mt PXEMdn4wmOlGKsme5xQbgVKBM9/cwOD5vzwZEGn0Hhcl65SzjH6cup/cvERs8qSCqHEz 0Wxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=gvJvLjozCLsZNwTbdjUDfFxOcdeK4EvZBL63AQ5I9Z8=; b=ObbrPi7O5gYnDWddRJjAatQ23M91/2widKRks1yHDoy6kWKmFukNv0v0feynJjQVjR Ih+EdpmwPTYjQnN2w8dsNvIt2vGv6Aj1too09iFcxlKzs8JzWa0fcxZcPIeOG8QWnRml jxVrR/RmPKyK3uvoi3T8W9EXGQxde8L4I2ndKyGGdjXJr8Z6f0w72CJkbWxyGxw+fHcB aMKV/Xhwtrd+jpAa8BgXgmxZRzGtxLgMDdpesymbH/tUvL4QJi052PyCRLDpUNkXCLCn w4jU9kEw4Z3zAwRKIUVAm1c2DsAZIBajLemq6I+WbzkI6XEKivoRd5Q/3ISl+Un+uwsh w9uA== X-Gm-Message-State: AJaThX7V6ZcGNryeT5OnI3xn7SBg6wWBKThtxeRjW1NE1x1InUDFuTPz UhECYwMO+gV6eBnRHTFOcXOjRg== X-Google-Smtp-Source: AGs4zMZWfLYeucLM8CFB7pjhew3lldV+dHNriehBBOxc5tAnyAEN2CtqqbcP9zU79N4hRkqcV6vdWw== X-Received: by 10.28.62.20 with SMTP id l20mr7849676wma.6.1512391576443; Mon, 04 Dec 2017 04:46:16 -0800 (PST) Received: from localhost.localdomain ([2a02:908:1251:7981:c5f1:d194:ba71:cd9d]) by smtp.gmail.com with ESMTPSA id e197sm4441461wmf.42.2017.12.04.04.46.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Dec 2017 04:46:15 -0800 (PST) From: "=?UTF-8?q?Christian=20K=C3=B6nig?=" X-Google-Original-From: =?UTF-8?q?Christian=20K=C3=B6nig?= To: dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org, Hongbo.He@amd.com Subject: [PATCH 1/2] drm/ttm: swap consecutive allocated cached pages v3 Date: Mon, 4 Dec 2017 13:46:11 +0100 Message-Id: <20171204124612.17591-1-christian.koenig@amd.com> X-Mailer: git-send-email 2.11.0 MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP When we detect consecutive allocation of pages swap them to avoid accidentally freeing them as huge page. v2: use swap v3: check if it's really the first allocated page Signed-off-by: Christian König Reviewed-by: Michel Dänzer --- drivers/gpu/drm/ttm/ttm_page_alloc.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c index c82d94cbbabc..7c4d4edce0ba 100644 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c @@ -875,7 +875,7 @@ static int ttm_get_pages(struct page **pages, unsigned npages, int flags, #endif struct list_head plist; struct page *p = NULL; - unsigned count; + unsigned count, first; int r; /* No pool for cached pages */ @@ -914,6 +914,7 @@ static int ttm_get_pages(struct page **pages, unsigned npages, int flags, } #endif + first = i; while (npages) { p = alloc_page(gfp_flags); if (!p) { @@ -921,6 +922,10 @@ static int ttm_get_pages(struct page **pages, unsigned npages, int flags, return -ENOMEM; } + /* Swap the pages if we detect consecutive order */ + if (i > first && pages[i - 1] == p - 1) + swap(p, pages[i - 1]); + pages[i++] = p; --npages; }