From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6050BD116F3 for ; Mon, 1 Dec 2025 05:53:51 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1ADA810E2A4; Mon, 1 Dec 2025 05:53:51 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="FirrSvy7"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.17]) by gabe.freedesktop.org (Postfix) with ESMTPS id 821CB10E2A4 for ; Mon, 1 Dec 2025 05:53:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1764568429; x=1796104429; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3jkTZP+YdN4BR/aYxl3fMUxQlsAw0+BLHAZSJSS+6Kg=; b=FirrSvy7I5KjYFgJk5YAK9870k5d0H1mzM52bbLrQgkwDtNRh8QwTo0n cRnm2V5PFz05wNqml1kMax6oBMRBMEfbi72w3/8JsTjatZ/aMIwIkzFVm ve1upQ3F6Y+5Qw4Hm520Ou8xuFvCq25wZ7O24LEmVOf4a9eWAUYGQGiWe fH7Bcr6lhK6xHhHFeA9E9b8l6D5rJVIvXRVgx8NmV/tw/+o3e5u0MkbdQ EPXlOP+GX4pR8LBACOVPgz8kxD4/wYQkXGY/kUGsyL/6efjs+vUgSdH8H caDS16p20qzZmj0bx2g+Wx9ZUmHCyZHKxBYpv8qHGzqR1i8opghmV2kp8 A==; X-CSE-ConnectionGUID: iTWK3jZlSbKlvHFTz1mBRg== X-CSE-MsgGUID: 3AjRTtYPT02Ost+dFmmI7Q== X-IronPort-AV: E=McAfee;i="6800,10657,11629"; a="66457380" X-IronPort-AV: E=Sophos;i="6.20,240,1758610800"; d="scan'208";a="66457380" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2025 21:53:49 -0800 X-CSE-ConnectionGUID: XWjARXEHSr2Zh8cKNZaUAA== X-CSE-MsgGUID: 5FNK/NjwRu2u3mbxPKOIeQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.20,240,1758610800"; d="scan'208";a="224950821" Received: from varungup-desk.iind.intel.com ([10.190.238.71]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2025 21:53:47 -0800 From: Arvind Yadav To: intel-xe@lists.freedesktop.org Cc: matthew.brost@intel.com, himal.prasad.ghimiray@intel.com, thomas.hellstrom@linux.intel.com, pallavi.mishra@intel.com Subject: [RFC v2 2/9] drm/xe/bo: Add purgeable bo state tracking and field madv to xe_bo Date: Mon, 1 Dec 2025 11:20:12 +0530 Message-ID: <20251201055309.854074-3-arvind.yadav@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251201055309.854074-1-arvind.yadav@intel.com> References: <20251201055309.854074-1-arvind.yadav@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: intel-xe@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel Xe graphics driver List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-xe-bounces@lists.freedesktop.org Sender: "Intel-xe" Add infrastructure for tracking purgeable state of buffer objects. This includes: Introduce enum xe_madv_purgeable_state with three states: - XE_MADV_PURGEABLE_WILLNEED (0): BO is needed and should not be purged. This is the default state for all BOs. - XE_MADV_PURGEABLE_DONTNEED (1): BO is not currently needed and can be purged by the kernel under memory pressure to reclaim resources. Only non-shared BOs can be marked as DONTNEED. - XE_MADV_PURGEABLE_PURGED (2): BO has been purged by the kernel. Accessing a purged BO results in error. Follows i915 semantics where once purged, the BO remains permanently invalid ("once purged, always purged"). Add atomic_t madv field to struct xe_bo for state tracking of purgeable state across concurrent access paths v2: Add xe_bo_is_purged() helper, improve state documentation Cc: Matthew Brost Cc: Thomas Hellström Cc: Himal Prasad Ghimiray Signed-off-by: Arvind Yadav --- drivers/gpu/drm/xe/xe_bo.h | 27 +++++++++++++++++++++++++++ drivers/gpu/drm/xe/xe_bo_types.h | 3 +++ 2 files changed, 30 insertions(+) diff --git a/drivers/gpu/drm/xe/xe_bo.h b/drivers/gpu/drm/xe/xe_bo.h index 911d5b90461a..b0a31c77e612 100644 --- a/drivers/gpu/drm/xe/xe_bo.h +++ b/drivers/gpu/drm/xe/xe_bo.h @@ -85,6 +85,28 @@ #define XE_PCI_BARRIER_MMAP_OFFSET (0x50 << XE_PTE_SHIFT) +/** + * enum xe_madv_purgeable_state - Buffer object purgeable state enumeration + * + * This enum defines the possible purgeable states for a buffer object, + * allowing userspace to provide memory usage hints to the kernel for + * better memory management under pressure. + * + * @XE_MADV_PURGEABLE_WILLNEED: The buffer object is needed and should not be purged. + * This is the default state. + * @XE_MADV_PURGEABLE_DONTNEED: The buffer object is not currently needed and can be + * purged by the kernel under memory pressure. + * @XE_MADV_PURGEABLE_PURGED: The buffer object has been purged by the kernel. + * + * Accessing a purged buffer will result in an error. Per i915 semantics, + * once purged, a BO remains permanently invalid and must be destroyed and recreated. + */ +enum xe_madv_purgeable_state { + XE_MADV_PURGEABLE_WILLNEED, + XE_MADV_PURGEABLE_DONTNEED, + XE_MADV_PURGEABLE_PURGED, +}; + struct sg_table; struct xe_bo *xe_bo_alloc(void); @@ -213,6 +235,11 @@ static inline bool xe_bo_is_protected(const struct xe_bo *bo) return bo->pxp_key_instance; } +static inline bool xe_bo_is_purged(struct xe_bo *bo) +{ + return atomic_read(&bo->madv_purgeable) == XE_MADV_PURGEABLE_PURGED; +} + static inline void xe_bo_unpin_map_no_vm(struct xe_bo *bo) { if (likely(bo)) { diff --git a/drivers/gpu/drm/xe/xe_bo_types.h b/drivers/gpu/drm/xe/xe_bo_types.h index d4fe3c8dca5b..57b4dc7012e2 100644 --- a/drivers/gpu/drm/xe/xe_bo_types.h +++ b/drivers/gpu/drm/xe/xe_bo_types.h @@ -108,6 +108,9 @@ struct xe_bo { * from default */ u64 min_align; + + /** @madv_purgeable: user space advise on BO purgeability */ + atomic_t madv_purgeable; }; #endif -- 2.43.0