From patchwork Mon Dec 4 12:46:12 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: 10090187 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 3815560329 for ; Mon, 4 Dec 2017 12:46:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4EBAC28C05 for ; Mon, 4 Dec 2017 12:46:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 432002916B; Mon, 4 Dec 2017 12:46:23 +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 0679328C05 for ; Mon, 4 Dec 2017 12:46:23 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3C0D76E37E; Mon, 4 Dec 2017 12:46:20 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x241.google.com (mail-wm0-x241.google.com [IPv6:2a00:1450:400c:c09::241]) by gabe.freedesktop.org (Postfix) with ESMTPS id C56D56E36C; Mon, 4 Dec 2017 12:46:18 +0000 (UTC) Received: by mail-wm0-x241.google.com with SMTP id n138so5555937wmg.2; Mon, 04 Dec 2017 04:46:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=ntonErkiaD0GP4MZiuE63jkqOc6OjdTZ9z29rN1istI=; b=JGxoh5mN6XceqR/7cZMDKRHN6MUMrsCYctirOwJV1IWH447rhwo+7ydhGhvPDqVCbg QdKMkGEOrhYqeCa2QYllccwWpxdIuRtwJof+27G0rSthD7QcDoKcDBOz0Zx8J2JKuXRf 5vVWFXRwjnioLA5bufY0jWcMoSs+XHkbIYINAMqs9zFEX2JLGzTc8Nn0E2yh5yTCzdSG Jr4aeOqcfCEXmHhM70Uahri3M+CmjnODhTdG9FocgYCZwtoXd1YwsYQ5QsORKoqaCPvN IC8qlKyJQtjseRot01/PD5zeK/Nyf+7bKHNWmBR2P1aMlyLmalxYHsAb5rPWicTfoFK4 VpwA== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=ntonErkiaD0GP4MZiuE63jkqOc6OjdTZ9z29rN1istI=; b=aLKWZh0sc71CB0eoz+yDmuNYAq7pyuSRSBJqvyL1KSRN7XhNkMY9+1d6UVRQW6OfPF 3CtFY2cmQGkNEUr4bnmM/FPx2MqtXGR/lJ+xG+d7pr14Nc45moztk4DWu0Ar8FavsZB/ lWY/C4d0pOyids4/dZmJkSIMSrH3+8lrYyi10vQHxhpWrEPqkXstVloxrDjPZ0kD12lG ccoIMgNd/tTNgDqR312/sNec8VctLBkaPnfQeALOfatdB/UrCGhUwKzYvEph6wJJftRx TucNSIc12MUZaEBX64JEFxP6ObWWkNklBRwPlxEinigQicxeAx/DNowrhtffXrspEGhC 5fNg== X-Gm-Message-State: AKGB3mKSnlUZTiVX4bA5EOmmSH8s89Dl53h/4lBZKHC+3CH65GVcvW35 MWkuKPS1LtmAM3VMjwMrhkhmsQ== X-Google-Smtp-Source: AGs4zMb9AqRzUKnB42lTS8B3i0eKGF1Y3XHjUh4oxqkqXoeIPZUD+uJvwcxRKcnkJlYq6lJ24ge5gQ== X-Received: by 10.28.108.11 with SMTP id h11mr7062714wmc.28.1512391577293; Mon, 04 Dec 2017 04:46:17 -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.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Dec 2017 04:46:16 -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 2/2] drm/ttm: swap consecutive allocated pooled pages v3 Date: Mon, 4 Dec 2017 13:46:12 +0100 Message-Id: <20171204124612.17591-2-christian.koenig@amd.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171204124612.17591-1-christian.koenig@amd.com> References: <20171204124612.17591-1-christian.koenig@amd.com> 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 --- 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 7c4d4edce0ba..da8a50f7c8fe 100644 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c @@ -954,8 +954,13 @@ static int ttm_get_pages(struct page **pages, unsigned npages, int flags, r = ttm_page_pool_get_pages(pool, &plist, flags, cstate, npages - count, 0); - list_for_each_entry(p, &plist, lru) + first = count; + list_for_each_entry(p, &plist, lru) { + /* Swap the pages if we detect consecutive order */ + if (count > first && pages[count - 1] == p - 1) + swap(p, pages[count - 1]); pages[count++] = p; + } if (r) { /* If there is any pages in the list put them back to