Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Piotr Piórkowski" <piotr.piorkowski@intel.com>
To: Matthew Auld <matthew.auld@intel.com>
Cc: <intel-xe@lists.freedesktop.org>
Subject: Re: [PATCH v4 2/7] drm/xe: Define VRAM regions and pools
Date: Thu, 26 Nov 2026 10:41:49 +0100	[thread overview]
Message-ID: <20261126094149.bgphw3p44d6lud5k@intel.com> (raw)
In-Reply-To: <ba79e8af-c172-4ae6-83cd-d6964f2af3ab@intel.com>

Matthew Auld <matthew.auld@intel.com> wrote on śro [2026-lis-25 17:38:07 +0000]:
> On 16/11/2026 09:45, Piórkowski, Piotr wrote:
> > From: Piotr Piórkowski <piotr.piorkowski@intel.com>
> > 
> > Allocation paths place memory through a struct xe_vram_region, which is
> > both the physical carrier of a VRAM range (BAR mapping, DPA range, TTM
> > manager) and the only handle for the purpose an allocation serves. That
> > makes it impossible to dedicate part of a region to a given purpose,
> > e.g. to keep kernel allocations such as LRCs and page tables in a range
> > of their own, away from VRAM that may be reachable by other agents.
> 
> "other agents", what is meant by that?

Hi,

That wording is too vague, sorry. "Other agents" meant other users of
the device's VRAM whose memory must be kept separate from the PF's
allocations. One example is SR-IOV: we want to reserve a VRAM pool
for the VFs, with a guarantee that this pool is used by the VFs only.
Other sub-drivers that need a separate VRAM pool fall into the same
category.

The pool is meant as a generic mechanism for that, not something
specific to VFs.

> 
> > 
> > Separate the two concepts. A struct xe_vram_pool represents an allocation
> > domain: it identifies the purpose served by a range within a VRAM region,
> > whether that range is available for general use or dedicated to
> > a particular purpose. A struct xe_vram_region owns the physical resources
> > and embeds its pools as partitions, keeping pool pointers published during
> > initialization stable when the region is later split. The region also
> > records its binding, distinguishing a device-wide aggregate from a tile
> > region, since both may use ID 0 for the first tile.
> > 
> > Signed-off-by: Piotr Piórkowski <piotr.piorkowski@intel.com>
> > ---
> >   drivers/gpu/drm/xe/xe_vram_types.h | 159 ++++++++++++++++++++++++++++-
> >   1 file changed, 158 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/gpu/drm/xe/xe_vram_types.h b/drivers/gpu/drm/xe/xe_vram_types.h
> > index 646e3c12ae9f7..a3e421f2f32d4 100644
> > --- a/drivers/gpu/drm/xe/xe_vram_types.h
> > +++ b/drivers/gpu/drm/xe/xe_vram_types.h
> > @@ -15,6 +15,142 @@
> >   struct xe_device;
> >   struct xe_migrate;
> > +/**
> > + * enum xe_vram_binding - VRAM region binding types
> > + * @XE_VRAM_BINDING_NONE: no binding assigned, default value of a zeroed region
> > + * @XE_VRAM_BINDING_DEVICE: device-level region aggregating all tile VRAM regions
> > + * @XE_VRAM_BINDING_TILE: VRAM region bound to a tile
> > + */
> > +enum xe_vram_binding {
> > +	XE_VRAM_BINDING_NONE = 0,
> > +	XE_VRAM_BINDING_DEVICE,
> > +	XE_VRAM_BINDING_TILE,
> > +};
> > +
> > +/**
> > + * enum xe_vram_pool_purpose - What a VRAM pool serves
> > + * @XE_VRAM_POOL_GENERAL: general-purpose memory, available to userspace
> > + * @XE_VRAM_POOL_KERNEL: kernel-only memory, never exposed to userspace
> > + */
> > +enum xe_vram_pool_purpose {
> > +	XE_VRAM_POOL_GENERAL = 0,
> > +	XE_VRAM_POOL_KERNEL,
> > +};
> > +
> > +/**
> > + * XE_VRAM_MAX_PARTITIONS - Max partitions a single VRAM region can be split into
> > + *
> > + * A region currently holds its default pool and at most one pool dedicated
> > + * to another purpose. The TTM manager mirrors the partitions of a region one
> > + * by one, so a region cannot hold more of them than the manager can back.
> > + */
> > +#define XE_VRAM_MAX_PARTITIONS	XE_TTM_VRAM_MGR_MAX_PARTS
> > +
> > +/**
> > + * DOC: VRAM pools, regions and partitions
> > + *
> > + * Allocation paths place memory through a struct xe_vram_pool. A pool names
> > + * a purpose (general-purpose, kernel-only ...) and resolves to a TTM
> > + * placement plus the address range serving it, see xe_vram_pool_place().
> > + * Whether that range is the whole region, or one of several partitions
> > + * sharing a region, is a backend detail pool consumers do not need to know.
> > + *
> > + * A struct xe_vram_region is the physical carrier: it owns the BAR mapping,
> > + * the DPA range and the TTM resource manager. A non-aggregate region
> > + * initially contains one partition spanning its whole usable range. That
> > + * partition is the region's default, general-purpose pool. It always
> > + * occupies partitions[0].
> > + *
> > + * Each partition is described by a struct xe_vram_pool embedded in the
> > + * region, so a pointer published during initialization remains valid if a
> > + * later split changes the pool's offset and size. A split never changes a
> > + * pool's purpose and may only happen before the region's TTM manager is
> > + * initialized.
> > + *
> > + * The device aggregate described below is the only region type that has no
> > + * manager and no partitions.
> > + *
> > + * The id shown below is the VRAM region instance id. For a tile region it
> > + * is the id of the tile, which the uAPI relies on. The pair (binding, id)
> > + * must uniquely identify a region.
> > + *
> > + * Partitioned region:
> > + * A tile's VRAM region can be split so that a pool dedicated to some purpose,
> > + * e.g. kernel-only, gets a range of its own and the default pool keeps the
> > + * rest. The dedicated partition is carved out at the start of the region, at
> > + * the lowest addresses, and takes the next free index. The default partition
> > + * keeps index 0 and is moved above the dedicated range. A tile without such
> > + * a reservation keeps one partition spanning the whole usable range::
> > + *
> > + *         xe_vram_region "tile0" (VRAM region id 0, binding TILE)
> > + *         ,-------------------------------------------------------------.
> > + *         | ttm: struct xe_ttm_vram_mgr (one manager, shared)           |
> > + *         | .---------------------------------------------------------. |
> > + *         | |  partitions[1]            |  partitions[0]              | |
> > + *         | |  offset 0                 |  offset pool_size           | |
> > + *         | |  size   pool_size         |  size   usable - pool_size  | |
> > + *         | `---------------------------------------------------------' |
> > + *         `-------------------------------------------------------------'
> > + *                  ^                               ^
> > + *                  |                               |
> > + *             dedicated pool                  general-purpose pool
> > + *
> > + *         xe_vram_region "tile1" (VRAM region id 1, binding TILE)
> > + *         ,-------------------------------------------------------------.
> > + *         | ttm: struct xe_ttm_vram_mgr (one manager)                   |
> > + *         | .---------------------------------------------------------. |
> > + *         | |  partitions[0]                                          | |
> > + *         | |  offset 0                                               | |
> > + *         | |  size   whole usable range                              | |
> > + *         | `---------------------------------------------------------' |
> > + *         `-------------------------------------------------------------'
> > + *                                     ^
> > + *                                     |
> > + *                            general-purpose pool
> > + *
> > + * Device aggregate:
> > + * A device-level aggregate region is unrelated to the tile regions. It is
> > + * never backed by a resource manager and has no partitions. It only
> > + * aggregates the sizes and DPA ranges of every tile for reporting purposes.
> > + * Nothing is ever allocated from it::
> > + *
> > + *         xe_vram_region "device" (VRAM region id 0, binding DEVICE)
> > + *         ,-------------------------------------------------------------.
> > + *         | ttm:        unused, not backed by any resource manager      |
> > + *         | partitions: none, this region is never allocated from       |
> > + *         | size:       total VRAM summed across all tiles              |
> > + *         `-------------------------------------------------------------'
> > + */
> > +
> > +/**
> > + * struct xe_vram_pool - VRAM range used for a given allocation purpose
> > + *
> > + * VRAM allocations are placed through this frontend. It identifies an
> > + * allocation purpose and resolves it to a TTM placement and the address
> > + * range serving it. Whether that range is a whole region of its own - and
> > + * thus has its own placement, mapping and address range - or one of several
> > + * partitions of a region is a backend detail the allocation paths do not
> > + * need to know, see xe_vram_pool_place().
> > + *
> > + * A pool stays valid for the lifetime of its region and its purpose is fixed
> > + * once published.
> > + */
> > +struct xe_vram_pool {
> > +	/** @region: region this pool belongs to */
> > +	struct xe_vram_region *region;
> > +	/**
> > +	 * @part: TTM partition backing this pool, or NULL until the manager
> > +	 * is initialized
> > +	 */
> > +	struct xe_ttm_vram_mgr_part *part;
> > +	/** @offset: byte offset of the pool from the start of @region */
> > +	u64 offset;
> > +	/** @size: size of the pool in bytes */
> > +	u64 size;
> > +	/** @purpose: allocation purpose served by this pool */
> > +	enum xe_vram_pool_purpose purpose;
> > +};
> 
> Can this not somehow be merged with the zone? Or why does this need to be a
> separate layer on top?

I thought about it, but I would like to keep them separate.

The pool says what a VRAM range is used for: its purpose and its
range. This is what users of the memory hold, like
tile->mem.kernel_vram or the BO placement code. The zone is internal
allocator state (the buddy and the CPU visible accounting). It is
about how we allocate from that range.

They are also filled in by different parts of the driver. xe_vram
sets up the pool during probe, and changes it only if the region is
split, all before the TTM manager is initialized. The zone belongs
to the manager and is set up only when the manager is initialized.
With two types, it is clear which code is responsible for which
fields.

Today there is one zone per pool, but this may change. Your
visible/non-visible idea is a good example. That split is about the
allocator, not about the purpose, so one general-purpose pool on a
small BAR would be backed by two zones. With separate types, this is
mostly a change in the manager. The tile and the BO code would not
need to change. If pool and zone were the same thing, we would need
to split them again.

Also, a pool does not have to be a slice of a region. It can also
cover a whole VRAM region of its own, with its own placement, mapping
and TTM manager. The user of the pool does not need to know which
case it is.

I agree that right now it looks like duplication, with counters on
both sides and pointers in both directions. I will try to reduce this
in v5, for example the manager will not keep its own zone count next
to the region's partition count. I will also explain in the commit
message and in the DOC section how pools and zones relate.

Thanks,
Piotr


> 
> > +
> >   /**
> >    * struct xe_vram_region - memory region structure
> >    * This is used to describe a memory region in xe
> > @@ -26,9 +162,11 @@ struct xe_vram_region {
> >   	/**
> >   	 * @id: VRAM region instance id
> >   	 *
> > -	 * The value should be unique for VRAM region.
> > +	 * The pair (@binding, @id) must uniquely identify a VRAM region.
> >   	 */
> >   	u8 id;
> > +	/** @binding: VRAM region instance binding */
> > +	enum xe_vram_binding binding;
> >   	/** @io_start: IO start address of this VRAM instance */
> >   	resource_size_t io_start;
> >   	/**
> > @@ -57,6 +195,25 @@ struct xe_vram_region {
> >   	 * (e.g stolen mem)
> >   	 */
> >   	resource_size_t actual_physical_size;
> > +	/**
> > +	 * @partitions: partitions this region is split into
> > +	 *
> > +	 * A non-aggregate region initially has @partitions[0] spanning its
> > +	 * whole usable range. It is the region's default, general-purpose
> > +	 * pool. An optional split may adjust its range and create another
> > +	 * partition before the TTM resource manager is initialized.
> > +	 *
> > +	 * A device aggregate region has no partitions. Allocation paths do
> > +	 * not take a region pointer, they take a &xe_vram_pool pointing into
> > +	 * this array, see the DOC above.
> > +	 */
> > +	struct xe_vram_pool partitions[XE_VRAM_MAX_PARTITIONS];
> > +	/**
> > +	 * @num_partitions: number of valid entries in @partitions
> > +	 *
> > +	 * Zero for a device aggregate region.
> > +	 */
> > +	unsigned int num_partitions;
> >   	/** @mapping: pointer to VRAM mappable space */
> >   	void __iomem *mapping;
> >   	/** @ttm: VRAM TTM manager */
> 

-- 

  reply	other threads:[~2026-11-26  9:43 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16  9:45 [PATCH v4 0/7] Introduce purpose-specific VRAM pools Piórkowski, Piotr
2026-11-16  9:45 ` [PATCH v4 1/7] drm/xe: Define partitioned VRAM manager types Piórkowski, Piotr
2026-11-25 14:30   ` Matthew Auld
2026-11-26  9:01     ` Piotr Piórkowski
2026-11-16  9:45 ` [PATCH v4 2/7] drm/xe: Define VRAM regions and pools Piórkowski, Piotr
2026-11-25 17:38   ` Matthew Auld
2026-11-26  9:41     ` Piotr Piórkowski [this message]
2026-11-26 11:14       ` Matthew Auld
2026-11-26 11:36         ` Matthew Auld
2026-11-16  9:45 ` [PATCH v4 3/7] drm/xe/vram: Make VRAM pools the allocation handle Piórkowski, Piotr
2026-11-16  9:45 ` [PATCH v4 4/7] drm/xe/ttm: Back each VRAM pool with its own buddy allocator Piórkowski, Piotr
2026-11-16  9:45 ` [PATCH v4 5/7] drm/xe/vram: Allow splitting a region into pools Piórkowski, Piotr
2026-11-16  9:45 ` [PATCH v4 6/7] drm/xe/kunit: Test partitioned VRAM manager Piórkowski, Piotr
2026-11-16  9:45 ` [PATCH v4 7/7] drm/xe/kunit: Test VRAM pool allocation Piórkowski, Piotr
2026-11-16 11:17 ` ✗ CI.checkpatch: warning for Introduce purpose-specific VRAM pools (rev4) Patchwork
2026-11-16 11:20 ` ✓ CI.KUnit: success " Patchwork
2026-11-16 12:07 ` ✓ Xe.CI.BAT: " Patchwork
2026-11-16 17:24 ` ✓ Xe.CI.FULL: " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261126094149.bgphw3p44d6lud5k@intel.com \
    --to=piotr.piorkowski@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=matthew.auld@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox