From: Matthew Auld <matthew.auld@intel.com>
To: intel-gfx@lists.freedesktop.org
Cc: dri-devel@lists.freedesktop.org,
Arunpravin <Arunpravin.PaneerSelvam@amd.com>
Subject: [Intel-gfx] [PATCH 03/20] drm: implement a method to free unused pages
Date: Wed, 26 Jan 2022 15:21:38 +0000 [thread overview]
Message-ID: <20220126152155.3070602-4-matthew.auld@intel.com> (raw)
In-Reply-To: <20220126152155.3070602-1-matthew.auld@intel.com>
From: Arunpravin <Arunpravin.PaneerSelvam@amd.com>
On contiguous allocation, we round up the size
to the *next* power of 2, implement a function
to free the unused pages after the newly allocate block.
v2(Matthew Auld):
- replace function name 'drm_buddy_free_unused_pages' with
drm_buddy_block_trim
- replace input argument name 'actual_size' with 'new_size'
- add more validation checks for input arguments
- add overlaps check to avoid needless searching and splitting
- merged the below patch to see the feature in action
- add free unused pages support to i915 driver
- lock drm_buddy_block_trim() function as it calls mark_free/mark_split
are all globally visible
v3(Matthew Auld):
- remove trim method error handling as we address the failure case
at drm_buddy_block_trim() function
v4:
- in case of trim, at __alloc_range() split_block failure path
marks the block as free and removes it from the original list,
potentially also freeing it, to overcome this problem, we turn
the drm_buddy_block_trim() input node into a temporary node to
prevent recursively freeing itself, but still retain the
un-splitting/freeing of the other nodes(Matthew Auld)
- modify the drm_buddy_block_trim() function return type
v5(Matthew Auld):
- revert drm_buddy_block_trim() function return type changes in v4
- modify drm_buddy_block_trim() passing argument n_pages to original_size
as n_pages has already been rounded up to the next power-of-two and
passing n_pages results noop
v6:
- fix warnings reported by kernel test robot <lkp@intel.com>
Signed-off-by: Arunpravin <Arunpravin.PaneerSelvam@amd.com>
---
drivers/gpu/drm/drm_buddy.c | 65 +++++++++++++++++++
drivers/gpu/drm/i915/i915_ttm_buddy_manager.c | 10 +++
include/drm/drm_buddy.h | 4 ++
3 files changed, 79 insertions(+)
diff --git a/drivers/gpu/drm/drm_buddy.c b/drivers/gpu/drm/drm_buddy.c
index 6aa5c1ce25bf..c5902a81b8c5 100644
--- a/drivers/gpu/drm/drm_buddy.c
+++ b/drivers/gpu/drm/drm_buddy.c
@@ -546,6 +546,71 @@ static int __drm_buddy_alloc_range(struct drm_buddy *mm,
return __alloc_range(mm, &dfs, start, size, blocks);
}
+/**
+ * drm_buddy_block_trim - free unused pages
+ *
+ * @mm: DRM buddy manager
+ * @new_size: original size requested
+ * @blocks: output list head to add allocated blocks
+ *
+ * For contiguous allocation, we round up the size to the nearest
+ * power of two value, drivers consume *actual* size, so remaining
+ * portions are unused and it can be freed.
+ *
+ * Returns:
+ * 0 on success, error code on failure.
+ */
+int drm_buddy_block_trim(struct drm_buddy *mm,
+ u64 new_size,
+ struct list_head *blocks)
+{
+ struct drm_buddy_block *parent;
+ struct drm_buddy_block *block;
+ LIST_HEAD(dfs);
+ u64 new_start;
+ int err;
+
+ if (!list_is_singular(blocks))
+ return -EINVAL;
+
+ block = list_first_entry(blocks,
+ struct drm_buddy_block,
+ link);
+
+ if (!drm_buddy_block_is_allocated(block))
+ return -EINVAL;
+
+ if (new_size > drm_buddy_block_size(mm, block))
+ return -EINVAL;
+
+ if (!new_size && !IS_ALIGNED(new_size, mm->chunk_size))
+ return -EINVAL;
+
+ if (new_size == drm_buddy_block_size(mm, block))
+ return 0;
+
+ list_del(&block->link);
+ mark_free(mm, block);
+ mm->avail += drm_buddy_block_size(mm, block);
+
+ /* Prevent recursively freeing this node */
+ parent = block->parent;
+ block->parent = NULL;
+
+ new_start = drm_buddy_block_offset(block);
+ list_add(&block->tmp_link, &dfs);
+ err = __alloc_range(mm, &dfs, new_start, new_size, blocks);
+ if (err) {
+ mark_allocated(block);
+ mm->avail -= drm_buddy_block_size(mm, block);
+ list_add(&block->link, blocks);
+ }
+
+ block->parent = parent;
+ return err;
+}
+EXPORT_SYMBOL(drm_buddy_block_trim);
+
/**
* drm_buddy_alloc_blocks - allocate power-of-two blocks
*
diff --git a/drivers/gpu/drm/i915/i915_ttm_buddy_manager.c b/drivers/gpu/drm/i915/i915_ttm_buddy_manager.c
index 3662434b64bb..53eb100688a6 100644
--- a/drivers/gpu/drm/i915/i915_ttm_buddy_manager.c
+++ b/drivers/gpu/drm/i915/i915_ttm_buddy_manager.c
@@ -97,6 +97,16 @@ static int i915_ttm_buddy_man_alloc(struct ttm_resource_manager *man,
if (unlikely(err))
goto err_free_blocks;
+ if (place->flags & TTM_PL_FLAG_CONTIGUOUS) {
+ u64 original_size = (u64)bman_res->base.num_pages << PAGE_SHIFT;
+
+ mutex_lock(&bman->lock);
+ drm_buddy_block_trim(mm,
+ original_size,
+ &bman_res->blocks);
+ mutex_unlock(&bman->lock);
+ }
+
*res = &bman_res->base;
return 0;
diff --git a/include/drm/drm_buddy.h b/include/drm/drm_buddy.h
index 424fc443115e..17ca928fce8e 100644
--- a/include/drm/drm_buddy.h
+++ b/include/drm/drm_buddy.h
@@ -145,6 +145,10 @@ int drm_buddy_alloc_blocks(struct drm_buddy *mm,
struct list_head *blocks,
unsigned long flags);
+int drm_buddy_block_trim(struct drm_buddy *mm,
+ u64 new_size,
+ struct list_head *blocks);
+
void drm_buddy_free_block(struct drm_buddy *mm, struct drm_buddy_block *block);
void drm_buddy_free_list(struct drm_buddy *mm, struct list_head *objects);
--
2.34.1
WARNING: multiple messages have this Message-ID (diff)
From: Matthew Auld <matthew.auld@intel.com>
To: intel-gfx@lists.freedesktop.org
Cc: dri-devel@lists.freedesktop.org,
Arunpravin <Arunpravin.PaneerSelvam@amd.com>
Subject: [PATCH 03/20] drm: implement a method to free unused pages
Date: Wed, 26 Jan 2022 15:21:38 +0000 [thread overview]
Message-ID: <20220126152155.3070602-4-matthew.auld@intel.com> (raw)
In-Reply-To: <20220126152155.3070602-1-matthew.auld@intel.com>
From: Arunpravin <Arunpravin.PaneerSelvam@amd.com>
On contiguous allocation, we round up the size
to the *next* power of 2, implement a function
to free the unused pages after the newly allocate block.
v2(Matthew Auld):
- replace function name 'drm_buddy_free_unused_pages' with
drm_buddy_block_trim
- replace input argument name 'actual_size' with 'new_size'
- add more validation checks for input arguments
- add overlaps check to avoid needless searching and splitting
- merged the below patch to see the feature in action
- add free unused pages support to i915 driver
- lock drm_buddy_block_trim() function as it calls mark_free/mark_split
are all globally visible
v3(Matthew Auld):
- remove trim method error handling as we address the failure case
at drm_buddy_block_trim() function
v4:
- in case of trim, at __alloc_range() split_block failure path
marks the block as free and removes it from the original list,
potentially also freeing it, to overcome this problem, we turn
the drm_buddy_block_trim() input node into a temporary node to
prevent recursively freeing itself, but still retain the
un-splitting/freeing of the other nodes(Matthew Auld)
- modify the drm_buddy_block_trim() function return type
v5(Matthew Auld):
- revert drm_buddy_block_trim() function return type changes in v4
- modify drm_buddy_block_trim() passing argument n_pages to original_size
as n_pages has already been rounded up to the next power-of-two and
passing n_pages results noop
v6:
- fix warnings reported by kernel test robot <lkp@intel.com>
Signed-off-by: Arunpravin <Arunpravin.PaneerSelvam@amd.com>
---
drivers/gpu/drm/drm_buddy.c | 65 +++++++++++++++++++
drivers/gpu/drm/i915/i915_ttm_buddy_manager.c | 10 +++
include/drm/drm_buddy.h | 4 ++
3 files changed, 79 insertions(+)
diff --git a/drivers/gpu/drm/drm_buddy.c b/drivers/gpu/drm/drm_buddy.c
index 6aa5c1ce25bf..c5902a81b8c5 100644
--- a/drivers/gpu/drm/drm_buddy.c
+++ b/drivers/gpu/drm/drm_buddy.c
@@ -546,6 +546,71 @@ static int __drm_buddy_alloc_range(struct drm_buddy *mm,
return __alloc_range(mm, &dfs, start, size, blocks);
}
+/**
+ * drm_buddy_block_trim - free unused pages
+ *
+ * @mm: DRM buddy manager
+ * @new_size: original size requested
+ * @blocks: output list head to add allocated blocks
+ *
+ * For contiguous allocation, we round up the size to the nearest
+ * power of two value, drivers consume *actual* size, so remaining
+ * portions are unused and it can be freed.
+ *
+ * Returns:
+ * 0 on success, error code on failure.
+ */
+int drm_buddy_block_trim(struct drm_buddy *mm,
+ u64 new_size,
+ struct list_head *blocks)
+{
+ struct drm_buddy_block *parent;
+ struct drm_buddy_block *block;
+ LIST_HEAD(dfs);
+ u64 new_start;
+ int err;
+
+ if (!list_is_singular(blocks))
+ return -EINVAL;
+
+ block = list_first_entry(blocks,
+ struct drm_buddy_block,
+ link);
+
+ if (!drm_buddy_block_is_allocated(block))
+ return -EINVAL;
+
+ if (new_size > drm_buddy_block_size(mm, block))
+ return -EINVAL;
+
+ if (!new_size && !IS_ALIGNED(new_size, mm->chunk_size))
+ return -EINVAL;
+
+ if (new_size == drm_buddy_block_size(mm, block))
+ return 0;
+
+ list_del(&block->link);
+ mark_free(mm, block);
+ mm->avail += drm_buddy_block_size(mm, block);
+
+ /* Prevent recursively freeing this node */
+ parent = block->parent;
+ block->parent = NULL;
+
+ new_start = drm_buddy_block_offset(block);
+ list_add(&block->tmp_link, &dfs);
+ err = __alloc_range(mm, &dfs, new_start, new_size, blocks);
+ if (err) {
+ mark_allocated(block);
+ mm->avail -= drm_buddy_block_size(mm, block);
+ list_add(&block->link, blocks);
+ }
+
+ block->parent = parent;
+ return err;
+}
+EXPORT_SYMBOL(drm_buddy_block_trim);
+
/**
* drm_buddy_alloc_blocks - allocate power-of-two blocks
*
diff --git a/drivers/gpu/drm/i915/i915_ttm_buddy_manager.c b/drivers/gpu/drm/i915/i915_ttm_buddy_manager.c
index 3662434b64bb..53eb100688a6 100644
--- a/drivers/gpu/drm/i915/i915_ttm_buddy_manager.c
+++ b/drivers/gpu/drm/i915/i915_ttm_buddy_manager.c
@@ -97,6 +97,16 @@ static int i915_ttm_buddy_man_alloc(struct ttm_resource_manager *man,
if (unlikely(err))
goto err_free_blocks;
+ if (place->flags & TTM_PL_FLAG_CONTIGUOUS) {
+ u64 original_size = (u64)bman_res->base.num_pages << PAGE_SHIFT;
+
+ mutex_lock(&bman->lock);
+ drm_buddy_block_trim(mm,
+ original_size,
+ &bman_res->blocks);
+ mutex_unlock(&bman->lock);
+ }
+
*res = &bman_res->base;
return 0;
diff --git a/include/drm/drm_buddy.h b/include/drm/drm_buddy.h
index 424fc443115e..17ca928fce8e 100644
--- a/include/drm/drm_buddy.h
+++ b/include/drm/drm_buddy.h
@@ -145,6 +145,10 @@ int drm_buddy_alloc_blocks(struct drm_buddy *mm,
struct list_head *blocks,
unsigned long flags);
+int drm_buddy_block_trim(struct drm_buddy *mm,
+ u64 new_size,
+ struct list_head *blocks);
+
void drm_buddy_free_block(struct drm_buddy *mm, struct drm_buddy_block *block);
void drm_buddy_free_list(struct drm_buddy *mm, struct list_head *objects);
--
2.34.1
next prev parent reply other threads:[~2022-01-26 15:22 UTC|newest]
Thread overview: 105+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-26 15:21 [Intel-gfx] [PATCH 00/20] Initial support for small BAR recovery Matthew Auld
2022-01-26 15:21 ` Matthew Auld
2022-01-26 15:21 ` [Intel-gfx] [PATCH 01/20] drm: improve drm_buddy_alloc function Matthew Auld
2022-01-26 15:21 ` Matthew Auld
2022-01-26 18:03 ` [Intel-gfx] " Jani Nikula
2022-01-26 15:21 ` [Intel-gfx] [PATCH 02/20] drm: implement top-down allocation method Matthew Auld
2022-01-26 15:21 ` Matthew Auld
2022-01-26 18:42 ` [Intel-gfx] " Robert Beckett
2022-01-26 15:21 ` Matthew Auld [this message]
2022-01-26 15:21 ` [PATCH 03/20] drm: implement a method to free unused pages Matthew Auld
2022-01-26 15:21 ` [Intel-gfx] [PATCH 04/20] drm/i915: add io_size plumbing Matthew Auld
2022-01-26 15:21 ` Matthew Auld
2022-01-31 15:14 ` [Intel-gfx] " Thomas Hellström
2022-01-31 15:14 ` Thomas Hellström
2022-01-26 15:21 ` [Intel-gfx] [PATCH 05/20] drm/i915/ttm: require mappable by default Matthew Auld
2022-01-26 15:21 ` Matthew Auld
2022-01-26 15:21 ` [Intel-gfx] [PATCH 06/20] drm/i915: add I915_BO_ALLOC_TOPDOWN Matthew Auld
2022-01-26 15:21 ` Matthew Auld
2022-01-31 15:28 ` [Intel-gfx] " Thomas Hellström
2022-01-31 15:28 ` Thomas Hellström
2022-01-31 15:49 ` [Intel-gfx] " Matthew Auld
2022-01-31 15:49 ` Matthew Auld
2022-01-26 15:21 ` [Intel-gfx] [PATCH 07/20] drm/i915/buddy: track available visible size Matthew Auld
2022-01-26 15:21 ` Matthew Auld
2022-01-31 16:12 ` [Intel-gfx] " Thomas Hellström
2022-01-31 16:12 ` Thomas Hellström
2022-01-26 15:21 ` [Intel-gfx] [PATCH 08/20] drm/i915/buddy: adjust res->start Matthew Auld
2022-01-26 15:21 ` Matthew Auld
2022-02-01 10:38 ` [Intel-gfx] " Thomas Hellström
2022-02-01 10:38 ` Thomas Hellström
2022-01-26 15:21 ` [Intel-gfx] [PATCH 09/20] drm/i915/buddy: tweak 2big check Matthew Auld
2022-01-26 15:21 ` Matthew Auld
2022-02-01 10:39 ` [Intel-gfx] " Thomas Hellström
2022-02-01 10:39 ` Thomas Hellström
2022-01-26 15:21 ` [Intel-gfx] [PATCH 10/20] drm/i915/selftests: mock test io_size Matthew Auld
2022-01-26 15:21 ` Matthew Auld
2022-02-02 10:24 ` [Intel-gfx] " Thomas Hellström
2022-02-02 10:24 ` Thomas Hellström
2022-01-26 15:21 ` [Intel-gfx] [PATCH 11/20] drm/i915/ttm: tweak priority hint selection Matthew Auld
2022-01-26 15:21 ` Matthew Auld
2022-02-02 13:34 ` [Intel-gfx] " Thomas Hellström
2022-02-02 13:34 ` Thomas Hellström
2022-01-26 15:21 ` [Intel-gfx] [PATCH 12/20] drm/i915/ttm: make eviction mappable aware Matthew Auld
2022-01-26 15:21 ` Matthew Auld
2022-02-02 13:41 ` [Intel-gfx] " Thomas Hellström
2022-02-02 13:41 ` Thomas Hellström
2022-01-26 15:21 ` [Intel-gfx] [PATCH 13/20] drm/i915/ttm: mappable migration on fault Matthew Auld
2022-01-26 15:21 ` Matthew Auld
2022-02-03 7:59 ` [Intel-gfx] " Thomas Hellström
2022-02-03 7:59 ` Thomas Hellström
2022-01-26 15:21 ` [Intel-gfx] [PATCH 14/20] drm/i915/selftests: exercise mmap migration Matthew Auld
2022-01-26 15:21 ` Matthew Auld
2022-02-03 9:01 ` [Intel-gfx] " Thomas Hellström
2022-02-03 9:01 ` Thomas Hellström
2022-02-03 9:12 ` [Intel-gfx] " Matthew Auld
2022-02-03 9:12 ` Matthew Auld
2022-01-26 15:21 ` [Intel-gfx] [PATCH 15/20] drm/i915/selftests: handle allocation failures Matthew Auld
2022-01-26 15:21 ` Matthew Auld
2022-02-03 9:05 ` [Intel-gfx] " Thomas Hellström
2022-02-03 9:05 ` Thomas Hellström
2022-02-03 9:11 ` [Intel-gfx] " Matthew Auld
2022-02-03 9:11 ` Matthew Auld
2022-01-26 15:21 ` [Intel-gfx] [PATCH 16/20] drm/i915/create: apply ALLOC_TOPDOWN by default Matthew Auld
2022-01-26 15:21 ` Matthew Auld
2022-02-03 9:17 ` [Intel-gfx] " Thomas Hellström
2022-02-03 9:17 ` Thomas Hellström
2022-02-03 9:32 ` [Intel-gfx] " Matthew Auld
2022-02-03 9:32 ` Matthew Auld
2022-01-26 15:21 ` [Intel-gfx] [PATCH 17/20] drm/i915/uapi: add NEEDS_CPU_ACCESS hint Matthew Auld
2022-01-26 15:21 ` Matthew Auld
2022-02-03 9:28 ` [Intel-gfx] " Thomas Hellström
2022-02-03 9:28 ` Thomas Hellström
2022-02-03 11:38 ` [Intel-gfx] " Matthew Auld
2022-02-03 11:38 ` Matthew Auld
2022-02-03 13:29 ` [Intel-gfx] " Thomas Hellström
2022-02-03 13:29 ` Thomas Hellström
2022-01-26 15:21 ` [Intel-gfx] [PATCH 18/20] drm/i915/uapi: forbid ALLOC_TOPDOWN for error capture Matthew Auld
2022-01-26 15:21 ` Matthew Auld
2022-01-26 19:42 ` [Intel-gfx] " kernel test robot
2022-01-26 19:42 ` kernel test robot
2022-01-26 20:03 ` kernel test robot
2022-01-26 20:03 ` kernel test robot
2022-01-26 20:03 ` kernel test robot
2022-02-03 9:43 ` Thomas Hellström
2022-02-03 9:43 ` Thomas Hellström
2022-02-03 9:44 ` [Intel-gfx] " Matthew Auld
2022-02-03 9:44 ` Matthew Auld
2022-01-26 15:21 ` [Intel-gfx] [PATCH 19/20] drm/i915/lmem: don't treat small BAR as an error Matthew Auld
2022-01-26 15:21 ` Matthew Auld
2022-02-03 9:48 ` [Intel-gfx] " Thomas Hellström
2022-02-03 9:48 ` Thomas Hellström
2022-02-03 11:18 ` [Intel-gfx] " Matthew Auld
2022-02-03 11:18 ` Matthew Auld
2022-02-03 13:56 ` [Intel-gfx] " Thomas Hellström
2022-02-03 13:56 ` Thomas Hellström
2022-02-03 14:09 ` [Intel-gfx] " Matthew Auld
2022-02-03 14:09 ` Matthew Auld
2022-01-26 15:21 ` [Intel-gfx] [PATCH 20/20] HAX: DG1 small BAR Matthew Auld
2022-01-26 15:21 ` Matthew Auld
2022-01-26 21:07 ` [Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for Initial support for small BAR recovery Patchwork
2022-01-26 21:08 ` [Intel-gfx] ✗ Fi.CI.SPARSE: " Patchwork
2022-01-26 21:41 ` [Intel-gfx] ✗ Fi.CI.BAT: failure " Patchwork
2022-01-27 16:27 ` [Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for Initial support for small BAR recovery (rev2) Patchwork
2022-01-27 16:28 ` [Intel-gfx] ✗ Fi.CI.SPARSE: " Patchwork
2022-01-27 16:57 ` [Intel-gfx] ✗ Fi.CI.BAT: failure " 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=20220126152155.3070602-4-matthew.auld@intel.com \
--to=matthew.auld@intel.com \
--cc=Arunpravin.PaneerSelvam@amd.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-gfx@lists.freedesktop.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.