From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A364B30DEB5 for ; Wed, 17 Jun 2026 03:22:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.7 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781666550; cv=none; b=HzoqtcQ2pxYD9XK2TKx/vglwRIODVLqeZTkAcGJzHMjadi1UXMGQIUcSLDAGrhG/cHHcAHGpKmPctIZd1QSBZIsnxcwqxMcy20LSUz5xkqtvQv0j0hkhn9kGV2vmpCmRWR5vG/GMkKJntxT4akMMbs0GAJOLJsdT7PikOyTKhbI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781666550; c=relaxed/simple; bh=JhM7c5o70ybfdwXn6SKxKv1V4lXqjrtlzjyeowK/Ybs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=ePvAxbg7U7ZE6VamAwD/fnvnoiREFw5EXSF/Z9AWXOJBFuCOXoLu+sO8BODohk/ykb2+VjS52DVVXjJ+BjNOTQnmnzuGzjxELpMdgmnn91QeYcVjw5QP0/yPVHA0U+49BsAw8giRS7AsAc0bBL3SGTxoQW4rrIGIrzGtrXpy96Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=fH+vqzqN; arc=none smtp.client-ip=192.198.163.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="fH+vqzqN" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1781666549; x=1813202549; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=JhM7c5o70ybfdwXn6SKxKv1V4lXqjrtlzjyeowK/Ybs=; b=fH+vqzqNcqiK4/dkvsjdd6im0onhm1o8a6bY7KlVcgjeCgi+FAuiwdzF bJpQiSNH23oalogIIVZKC9MgavpzPN5ynGV767UGbuL0/6A3h4s9IPcgO Ne7abkqbWuuRxWIheEJRk3LNftRVxurFDrdnN8XLqMeBz/yXoLnx71iji DNG4kHpu7WMiDhicFHY3wJ4gfccGNDImt66r/WJNZQEzLMIWbV1S6emgq fm6F0gF8U83alCYt8OuNE85eJG9usNMNMuiwyEhQJTyuMQG17Nyr8I7Oh kANOYMOs1vP1Ivqlkvwbyq6gRtr0dGlSmr6yEcef4I0sf7cxzHeH7aRzU A==; X-CSE-ConnectionGUID: kGniliG3Svqe2mmaUHGrwg== X-CSE-MsgGUID: UDSDUT04QYGOq+n2ak5hZg== X-IronPort-AV: E=McAfee;i="6800,10657,11819"; a="107914563" X-IronPort-AV: E=Sophos;i="6.24,209,1774335600"; d="scan'208";a="107914563" Received: from orviesa007.jf.intel.com ([10.64.159.147]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jun 2026 20:22:26 -0700 X-CSE-ConnectionGUID: +ZClgS0VSr+yHpa6nm6ycw== X-CSE-MsgGUID: Xt7l2jTsQAm2vq6Yk3nP1Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.24,209,1774335600"; d="scan'208";a="248017807" Received: from gsse-cloud1.jf.intel.com ([10.54.39.91]) by orviesa007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jun 2026 20:22:26 -0700 From: Matthew Brost To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org Cc: Andrew Morton , Dave Chinner , Qi Zheng , Roman Gushchin , Muchun Song , David Hildenbrand , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Johannes Weiner , Shakeel Butt , Kairui Song , Barry Song , Axel Rasmussen , Yuanchu Xie , Wei Xu , =?UTF-8?q?Thomas=20Hellstr=C3=B6m?= Subject: [PATCH v6 2/2] drm/xe: Make use of shrink_control::opportunistic_compaction hint Date: Tue, 16 Jun 2026 20:22:18 -0700 Message-Id: <20260617032218.1165929-3-matthew.brost@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260617032218.1165929-1-matthew.brost@intel.com> References: <20260617032218.1165929-1-matthew.brost@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Xe/TTM backup reclaim can be extremely expensive under fragmentation pressure as reclaim may migrate or destroy actively used GPU working sets despite the system still having substantial free memory available. Under high-order opportunistic reclaim, repeatedly backing up GPU memory can lead to reclaim/rebind ping-pong behavior where active GPU working sets are continuously torn down and reconstructed without materially improving allocation success. Use the new shrink_control::opportunistic_compaction hint to avoid Xe backup reclaim during fragmentation-driven high-order reclaim attempts. In this mode the shrinker skips advertising backup-backed reclaimable memory and avoids initiating backup operations entirely. Order-0 and non-opportunistic reclaim behavior remain unchanged, so Xe backup reclaim still participates normally during genuine memory pressure. Cc: Andrew Morton Cc: Dave Chinner Cc: Qi Zheng Cc: Roman Gushchin Cc: Muchun Song Cc: David Hildenbrand Cc: Lorenzo Stoakes Cc: "Liam R. Howlett" Cc: Vlastimil Babka Cc: Mike Rapoport Cc: Suren Baghdasaryan Cc: Michal Hocko Cc: Johannes Weiner Cc: Shakeel Butt Cc: Kairui Song Cc: Barry Song Cc: Axel Rasmussen Cc: Yuanchu Xie Cc: Wei Xu Cc: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org Assisted-by: Claude:claude-opus-4.6 Signed-off-by: Matthew Brost Reviewed-by: Thomas Hellström --- drivers/gpu/drm/xe/xe_shrinker.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/xe/xe_shrinker.c b/drivers/gpu/drm/xe/xe_shrinker.c index 83374cd57660..198149f266c6 100644 --- a/drivers/gpu/drm/xe/xe_shrinker.c +++ b/drivers/gpu/drm/xe/xe_shrinker.c @@ -139,10 +139,17 @@ static unsigned long xe_shrinker_count(struct shrinker *shrink, struct shrink_control *sc) { struct xe_shrinker *shrinker = to_xe_shrinker(shrink); - unsigned long num_pages; + unsigned long num_pages = 0; bool can_backup = !!(sc->gfp_mask & __GFP_FS); - num_pages = ttm_backup_bytes_avail() >> PAGE_SHIFT; + /* + * Skip accounting backup-able pages when this is an opportunistic + * high-order pass: TTM backup work shrinks at native page granularity + * and is unlikely to produce the contiguous block the caller wants, + * so don't advertise it as reclaimable for this hint. + */ + if (!sc->opportunistic_compaction) + num_pages = ttm_backup_bytes_avail() >> PAGE_SHIFT; read_lock(&shrinker->lock); if (can_backup) @@ -233,7 +240,14 @@ static unsigned long xe_shrinker_scan(struct shrinker *shrink, struct shrink_con } sc->nr_scanned = nr_scanned; - if (nr_scanned >= nr_to_scan || !can_backup) + /* + * Stop after the purge pass for opportunistic high-order reclaim: + * the subsequent backup/writeback pass works at native page order + * and is unlikely to free a contiguous high-order block, so doing + * it here would just churn working sets for no compaction benefit. + */ + if (nr_scanned >= nr_to_scan || !can_backup || + sc->opportunistic_compaction) goto out; /* If we didn't wake before, try to do it now if needed. */ -- 2.34.1