From patchwork Tue Dec 5 12:54:52 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: 10092893 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 EF02060329 for ; Tue, 5 Dec 2017 12:54:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CE80C29681 for ; Tue, 5 Dec 2017 12:54:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C1DD929684; Tue, 5 Dec 2017 12:54:59 +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 48CF029681 for ; Tue, 5 Dec 2017 12:54:59 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 963396E542; Tue, 5 Dec 2017 12:54:58 +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 A2EAC6E542; Tue, 5 Dec 2017 12:54:57 +0000 (UTC) Received: by mail-wm0-x243.google.com with SMTP id g75so1130825wme.0; Tue, 05 Dec 2017 04:54:57 -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=27RbGu9cY6Mqmzlg4PQ0+arLN03rWCnhMhg+ortByIs=; b=tAeTmgq9swZ4XfCyxROLeVN2kDa+hKz6HkFs4duBTMit3iQSgyP6t77mwUR9frhPYQ OOSP4xHaCkoCshg6sCO2kCUae/oGv/M88GHyuD9GsPtMq+Kh/DwRSmdv13K16zsbRMnV cXaoE8fJdkwBJ2cqFoyRr6mA2cQmMzCfKqBj9JKTU50aOlqRzPc5bfLRdJS5RoKzoXbJ XAPERj8MQ+0SQzm+KLeLIGOx+yTTqHqvjLvRhz0aH50ZTEBEVIzaUQyjUUmdoGttODLO XrCutflQGWjkN94QUk9Yweso510UbCUTIofUeZBfgRRrY4dEIfjGYndkBvPN241u3Esk mxOw== 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=27RbGu9cY6Mqmzlg4PQ0+arLN03rWCnhMhg+ortByIs=; b=S4RI9YjCMzr131542aazzMkOifCPL0X2Tjhhiea/rSvezhbQJO8YpkX0uzKTsR+EBt Qbz+hl28hxXf4cjc+dxwaMHoKDY++L1eQOj1rRPhxfDLlwgztG7RUln8Minf15jy79BV 3ddt7VFARW8gqxYZCXBwohTCMxYvUYnUAXAJ1MdE/rnA2SPRTtOFiUF9BUE3Rxdgqo/p Xd1xBrp1B4QB3nW5wgAdVPfY7L3zBEj0saeOjuN7yJC+gHfen6Px7q8DCw0u3TzW5OXa 8WKph0dBmE6qbWWVjozQA42HnbdX/EbJ7240HSbbaoXCOgPG4Hxc8WokmLELBkr1LEt5 c9jA== X-Gm-Message-State: AKGB3mLKXTenjYu3Lq/LmLBqXdft4IOgtxWcjawDMX5CoxgCfz6fgrKM HgAtzQHE/j2MGK46+t61dEd1vg== X-Google-Smtp-Source: AGs4zMbVL1yPKjWpmPsruNjhw/SdgbW2mN4i4s8j6JMNkKZ/5Foq91QUx44/mVvUQhr1StVwW3V0WA== X-Received: by 10.28.249.26 with SMTP id x26mr6204946wmh.36.1512478495997; Tue, 05 Dec 2017 04:54:55 -0800 (PST) Received: from localhost.localdomain ([2a02:908:1251:7981:74b3:3368:1fe:2d97]) by smtp.gmail.com with ESMTPSA id r15sm105019wrc.36.2017.12.05.04.54.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 05 Dec 2017 04:54:55 -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] drm/ttm: swap consecutive allocated pooled pages v4 Date: Tue, 5 Dec 2017 13:54:52 +0100 Message-Id: <20171205125452.7546-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 v4: don't touch the loop variable Signed-off-by: Christian König Reviewed-by: Michel Dänzer Tested-by: Dieter Nützel --- drivers/gpu/drm/ttm/ttm_page_alloc.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c index b6f7ce286fb1..44343a2bf55c 100644 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c @@ -958,8 +958,15 @@ 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) - pages[count++] = p; + first = count; + list_for_each_entry(p, &plist, lru) { + struct page *tmp = p; + + /* Swap the pages if we detect consecutive order */ + if (count > first && pages[count - 1] == tmp - 1) + swap(tmp, pages[count - 1]); + pages[count++] = tmp; + } if (r) { /* If there is any pages in the list put them back to