Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp1131889pxf; Fri, 9 Apr 2021 00:19:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxbIW714VM3WohyhcYGN3l6AO+LGMX5zBhkkBzIZ1gc/VSllqn0m9kCkT0alZXCRKR5+yNS X-Received: by 2002:aa7:8702:0:b029:200:50a8:2354 with SMTP id b2-20020aa787020000b029020050a82354mr11405593pfo.72.1617952761265; Fri, 09 Apr 2021 00:19:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617952761; cv=none; d=google.com; s=arc-20160816; b=0gPK7bxBGrgtzkeKGhRizpf9wbZYKbAeBcFZgIOunbwMkzS9XdhG6mykxUzTauM5j+ lz2hyolqpMsc/E+562vjtEw5o+9Fn7S5UzPTPG3LM0i18g39XWx6J6QoKsvmBgbJ5MMg RBzEVsPLHmdS/5I9qc9kcAhisJQ8BxPRCJGLzZ02C3Belwz6ZXP4vP8yBsRq6KrPwD9G v8XgGK/0hfr6gUoULSo96vIZQFfNW5DtUiEEjeZZLqcJ8WEuy7oz/QxeQzmh5U57TlsL WQ7kwHx3cOryZTmKD94onaP9VetKY5KxLWcaOkHn6egsuxLlnP4XrQWltxC+sDTerjXY 7YIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=gbjvidtHezwGj4SvL2Dc9DE4DP5+DorOADCoNSePk0o=; b=AUyDTuDSDHq8N2FWz/CoKp7fdfi56H9DGV4ECcq6VsPDd5K2sdiRXo1UodafdF9lUK N8yqHlLY2md7Dai8pXBsMyzXMRs1I1KBTcebcJFvk+wBSMOWzFH4RDkeDRTLLYpzFZhZ NbJKtiu3CXNeM5+/m1ygzStpYKAirJ3GRZHmcEIhYRIYjaTFIADNTo4It31J8m1dhhm5 yQBxn9C7I6htVOEAt5OdufCPd1O4QWFVLNN6uGDeQoTjKjs3xs8yt0TFHq8W1L6K7zl/ 0I5PwI20Yi/IMYZAxDR6XZJzCO/hfNLUx00vyz1OTUYmu/8zFTiZBfEzjRLKPlcQeAlU zOfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=r5imc+no; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e22si1954532pgl.481.2021.04.09.00.19.09; Fri, 09 Apr 2021 00:19:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=r5imc+no; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231526AbhDIHRm (ORCPT + 99 others); Fri, 9 Apr 2021 03:17:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45972 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230430AbhDIHRl (ORCPT ); Fri, 9 Apr 2021 03:17:41 -0400 Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [IPv6:2a00:1450:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DAA41C061761 for ; Fri, 9 Apr 2021 00:17:28 -0700 (PDT) Received: by mail-ed1-x52d.google.com with SMTP id h10so5307663edt.13 for ; Fri, 09 Apr 2021 00:17:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gbjvidtHezwGj4SvL2Dc9DE4DP5+DorOADCoNSePk0o=; b=r5imc+noURb/sXKErdXVdbUdGts2IWxjfj5so6adBwjlq4IAcXJeNbVW/IydyIy8OE /ZvbzxhoSjZIJV8g3P3QepUFZSpKDDI+DbQJb2QHBnYlNkP6yByWo0arkonzdJRLYO6w juj+aswm7fZYfMB9yeZooUD2jpvciU2nweFoe3A2EeoCHr52pdDRQMTK1XzGU5Ntj+/e 3gApRInc3hLv+qTx0pwI91QTLvAJ7RJYti7IJSVTrBM09paQbZwEKVSDb+s4dA0fqkRg 1oUeeSfJJzvJQ3eLQwuWZFgsq895QmaCLfL080HYqTo8gZBp3teFwrPqQz55ckn8ZuEA riEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gbjvidtHezwGj4SvL2Dc9DE4DP5+DorOADCoNSePk0o=; b=Q8GIXvyeZzGsk6bYHwWgw+VTJdE/9oWEs1f7GZaemBfXji4321LffJzAVGy9u0uENY Akw/oK0eyqE2v7NcL4mx9ZBg1iovtJkjxjwSXqT8rF2DHZpNfn/x8irXhFyxl+QA2rIz XDTLVQp2hw2wnGB2PhVgB4bhIsNnwLx20uMozCLhEOX5on69Zw/cgymEK+kNnahKvH3y bkQZvp6uFgBTPOSbQI36Q6EGoaNGpTIw2gCEOZBBB5JPixWwp7Xr7RteslNWh4Ib6Tl4 dX/4dxrpvesDlxIzD1vRgQU+LhRCm10BhT5jEm7YGUKeMPTbk95W4FA3r8PdiD5crnpc /NCQ== X-Gm-Message-State: AOAM532/eWWyOfz+NXZHD0ZA+CqAvvFyCbBeFnDL48eQDT374smSc0ZB +NQKdKwXljqGnoId8COnEKk= X-Received: by 2002:a05:6402:2786:: with SMTP id b6mr16140557ede.310.1617952647643; Fri, 09 Apr 2021 00:17:27 -0700 (PDT) Received: from abel.fritz.box ([2a02:908:1252:fb60:216f:9340:7a2b:4f98]) by smtp.gmail.com with ESMTPSA id w1sm905369edt.89.2021.04.09.00.17.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Apr 2021 00:17:27 -0700 (PDT) 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, linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: ray.huang@amd.com, daniel@ffwll.ch, akpm@linux-foundation.org Subject: [PATCH 2/2] drm/ttm: optimize the pool shrinker a bit Date: Fri, 9 Apr 2021 09:17:25 +0200 Message-Id: <20210409071725.1532-2-christian.koenig@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210409071725.1532-1-christian.koenig@amd.com> References: <20210409071725.1532-1-christian.koenig@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Switch back to using a spinlock again by moving the IOMMU unmap outside of the locked region. Signed-off-by: Christian König --- drivers/gpu/drm/ttm/ttm_pool.c | 40 +++++++++++++++------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/drivers/gpu/drm/ttm/ttm_pool.c b/drivers/gpu/drm/ttm/ttm_pool.c index cb38b1a17b09..a8b4abe687ce 100644 --- a/drivers/gpu/drm/ttm/ttm_pool.c +++ b/drivers/gpu/drm/ttm/ttm_pool.c @@ -70,7 +70,7 @@ static struct ttm_pool_type global_uncached[MAX_ORDER]; static struct ttm_pool_type global_dma32_write_combined[MAX_ORDER]; static struct ttm_pool_type global_dma32_uncached[MAX_ORDER]; -static struct mutex shrinker_lock; +static spinlock_t shrinker_lock; static struct list_head shrinker_list; static struct shrinker mm_shrinker; @@ -263,9 +263,9 @@ static void ttm_pool_type_init(struct ttm_pool_type *pt, struct ttm_pool *pool, spin_lock_init(&pt->lock); INIT_LIST_HEAD(&pt->pages); - mutex_lock(&shrinker_lock); + spin_lock(&shrinker_lock); list_add_tail(&pt->shrinker_list, &shrinker_list); - mutex_unlock(&shrinker_lock); + spin_unlock(&shrinker_lock); } /* Remove a pool_type from the global shrinker list and free all pages */ @@ -273,9 +273,9 @@ static void ttm_pool_type_fini(struct ttm_pool_type *pt) { struct page *p; - mutex_lock(&shrinker_lock); + spin_lock(&shrinker_lock); list_del(&pt->shrinker_list); - mutex_unlock(&shrinker_lock); + spin_unlock(&shrinker_lock); while ((p = ttm_pool_type_take(pt))) ttm_pool_free_page(pt->pool, pt->caching, pt->order, p); @@ -313,24 +313,19 @@ static struct ttm_pool_type *ttm_pool_select_type(struct ttm_pool *pool, static unsigned int ttm_pool_shrink(void) { struct ttm_pool_type *pt; - unsigned int num_freed; struct page *p; - mutex_lock(&shrinker_lock); + spin_lock(&shrinker_lock); pt = list_first_entry(&shrinker_list, typeof(*pt), shrinker_list); + list_move_tail(&pt->shrinker_list, &shrinker_list); + spin_unlock(&shrinker_lock); p = ttm_pool_type_take(pt); - if (p) { - ttm_pool_free_page(pt->pool, pt->caching, pt->order, p); - num_freed = 1 << pt->order; - } else { - num_freed = 0; - } - - list_move_tail(&pt->shrinker_list, &shrinker_list); - mutex_unlock(&shrinker_lock); + if (!p) + return 0; - return num_freed; + ttm_pool_free_page(pt->pool, pt->caching, pt->order, p); + return 1 << pt->order; } /* Return the allocation order based for a page */ @@ -530,6 +525,7 @@ void ttm_pool_fini(struct ttm_pool *pool) for (j = 0; j < MAX_ORDER; ++j) ttm_pool_type_fini(&pool->caching[i].orders[j]); } + sync_shrinkers(); } /* As long as pages are available make sure to release at least one */ @@ -604,7 +600,7 @@ static int ttm_pool_debugfs_globals_show(struct seq_file *m, void *data) { ttm_pool_debugfs_header(m); - mutex_lock(&shrinker_lock); + spin_lock(&shrinker_lock); seq_puts(m, "wc\t:"); ttm_pool_debugfs_orders(global_write_combined, m); seq_puts(m, "uc\t:"); @@ -613,7 +609,7 @@ static int ttm_pool_debugfs_globals_show(struct seq_file *m, void *data) ttm_pool_debugfs_orders(global_dma32_write_combined, m); seq_puts(m, "uc 32\t:"); ttm_pool_debugfs_orders(global_dma32_uncached, m); - mutex_unlock(&shrinker_lock); + spin_unlock(&shrinker_lock); ttm_pool_debugfs_footer(m); @@ -640,7 +636,7 @@ int ttm_pool_debugfs(struct ttm_pool *pool, struct seq_file *m) ttm_pool_debugfs_header(m); - mutex_lock(&shrinker_lock); + spin_lock(&shrinker_lock); for (i = 0; i < TTM_NUM_CACHING_TYPES; ++i) { seq_puts(m, "DMA "); switch (i) { @@ -656,7 +652,7 @@ int ttm_pool_debugfs(struct ttm_pool *pool, struct seq_file *m) } ttm_pool_debugfs_orders(pool->caching[i].orders, m); } - mutex_unlock(&shrinker_lock); + spin_unlock(&shrinker_lock); ttm_pool_debugfs_footer(m); return 0; @@ -693,7 +689,7 @@ int ttm_pool_mgr_init(unsigned long num_pages) if (!page_pool_size) page_pool_size = num_pages; - mutex_init(&shrinker_lock); + spin_lock_init(&shrinker_lock); INIT_LIST_HEAD(&shrinker_list); for (i = 0; i < MAX_ORDER; ++i) { -- 2.25.1