From patchwork Mon Dec 4 12:22:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "He, Hongbo" X-Patchwork-Id: 10090059 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 DAE586056E for ; Mon, 4 Dec 2017 12:22:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AA42629176 for ; Mon, 4 Dec 2017 12:22:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9F24E29174; Mon, 4 Dec 2017 12:22:41 +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 D342E29177 for ; Mon, 4 Dec 2017 12:22:40 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 189576E336; Mon, 4 Dec 2017 12:22:39 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from NAM03-DM3-obe.outbound.protection.outlook.com (mail-dm3nam03on0079.outbound.protection.outlook.com [104.47.41.79]) by gabe.freedesktop.org (Postfix) with ESMTPS id D08176E335; Mon, 4 Dec 2017 12:22:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=pUv2IbnfRe82K/HzDZW33Vx1nF3URcnNFp2J2c72FDI=; b=qPyo62NcZUujH9CEe1r0iZ3ZpgPYQkdNUal1CUhQE0Ef07Gfe+arSGbM1Kwl6ruruqLmbFJbwZ6KvZU5qWvCi25NMR4SAYdig4/hqAHZF8oKhvXHsuKPFmBO+KV811n2KoxC1qcBUcKL/yWBLXRMuS7iEW1XILOPNFjSabeayc0= Received: from MWHPR1201MB0127.namprd12.prod.outlook.com (10.174.98.142) by MWHPR1201MB0125.namprd12.prod.outlook.com (10.174.98.140) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.282.5; Mon, 4 Dec 2017 12:22:34 +0000 Received: from MWHPR1201MB0127.namprd12.prod.outlook.com ([10.174.98.142]) by MWHPR1201MB0127.namprd12.prod.outlook.com ([10.174.98.142]) with mapi id 15.20.0282.012; Mon, 4 Dec 2017 12:22:34 +0000 From: "He, Roger" To: =?utf-8?B?Q2hyaXN0aWFuIEvDtm5pZw==?= , "dri-devel@lists.freedesktop.org" , "amd-gfx@lists.freedesktop.org" Subject: RE: [PATCH 1/2] drm/ttm: swap consecutive allocated cached pages v2 Thread-Topic: [PATCH 1/2] drm/ttm: swap consecutive allocated cached pages v2 Thread-Index: AQHTbPkuAM3lBrBRKU6UwoFSVMMHKqMzGZOg Date: Mon, 4 Dec 2017 12:22:34 +0000 Message-ID: References: <20171204121233.9164-1-christian.koenig@amd.com> In-Reply-To: <20171204121233.9164-1-christian.koenig@amd.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Hongbo.He@amd.com; x-originating-ip: [116.228.147.241] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; MWHPR1201MB0125; 20:6h/uVCPnuJK0d0w4GcjVZeOllbFQld1eWWPhQtnKpEyeEyyZxD7kPm2rIqlynmT4zxYq+iAgUvgbU43ZlrhzB10oPncdP88ta9aPpoNFehmVg7KfWBwYNnMUIGU8xYEyOaM6tsEaS3vZm74/LPB1x+KQWecoXA7efEWtV1lPACQHMG/7Jdbw5XubqDTnkbwofzKQtyMZqg5CrUQWijy53Kg47Tpr1OiYLEAxZuyNURL/nRdGNa1V7cA/LGcsx1pI x-ms-exchange-antispam-srfa-diagnostics: SSOS; x-ms-office365-filtering-correlation-id: 2f777d1a-8d39-4211-f85f-08d53b11b30c x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(5600026)(4604075)(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(48565401081)(2017052603286); SRVR:MWHPR1201MB0125; x-ms-traffictypediagnostic: MWHPR1201MB0125: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(767451399110)(217544274631240); x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(6040450)(2401047)(5005006)(8121501046)(10201501046)(93006095)(93001095)(3002001)(3231022)(6055026)(6041248)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123558100)(20161123555025)(20161123564025)(20161123560025)(20161123562025)(6072148)(201708071742011); SRVR:MWHPR1201MB0125; BCL:0; PCL:0; RULEID:(100000803101)(100110400095); SRVR:MWHPR1201MB0125; x-forefront-prvs: 051158ECBB x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(6009001)(39860400002)(376002)(346002)(366004)(189002)(13464003)(199003)(9686003)(72206003)(6506006)(101416001)(110136005)(77096006)(3660700001)(53546010)(229853002)(86362001)(14454004)(7736002)(305945005)(74316002)(3280700002)(8936002)(55016002)(33656002)(189998001)(106356001)(105586002)(2501003)(6436002)(316002)(102836003)(6116002)(3846002)(66066001)(8676002)(81166006)(2900100001)(81156014)(2906002)(99286004)(97736004)(478600001)(2201001)(7696005)(39060400002)(5660300001)(54356011)(68736007)(53936002)(2950100002)(25786009)(76176011)(6246003); DIR:OUT; SFP:1101; SCL:1; SRVR:MWHPR1201MB0125; H:MWHPR1201MB0127.namprd12.prod.outlook.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; received-spf: None (protection.outlook.com: amd.com does not designate permitted sender hosts) spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2f777d1a-8d39-4211-f85f-08d53b11b30c X-MS-Exchange-CrossTenant-originalarrivaltime: 04 Dec 2017 12:22:34.5528 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR1201MB0125 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 -----Original Message----- From: Christian König [mailto:ckoenig.leichtzumerken@gmail.com] Sent: Monday, December 04, 2017 8:13 PM To: dri-devel@lists.freedesktop.org; amd-gfx@lists.freedesktop.org; He, Roger ; ckoenig.leichtzumerken@gmail.com Subject: [PATCH 1/2] drm/ttm: swap consecutive allocated cached pages v2 When we detect consecutive allocation of pages swap them to avoid accidentally freeing them as huge page. v2: use swap Signed-off-by: Christian König --- drivers/gpu/drm/ttm/ttm_page_alloc.c | 4 ++++ 1 file changed, 4 insertions(+) return -ENOMEM; } /* Swap the pages if we detect consecutive order */ if (i > first && pages[i - 1] == p - 1) //change to (i > first), because I worry if npages is 513, the first regular page is exactly consecutive with last page of huge page. Then swap them is not what I want here. swap(p, pages[i - 1]); pages[i++] = p; --npages; } pages[i++] = p; --npages; } -- 2.11.0 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c index c82d94cbbabc..b6c5148607e9 100644 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c @@ -921,6 +921,10 @@ static int ttm_get_pages(struct page **pages, unsigned npages, int flags, return -ENOMEM; } How about add first index as below? first = i; //init first here while (npages) { p = alloc_page(gfp_flags); if (!p) { pr_debug("Unable to allocate page\n");