All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Krzysztof Karas" <krzysztof.karas@intel.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v3 4/5] drm/i915/gem: Read and shrink memory in a separate function
Date: Mon, 13 Jul 2026 10:10:15 +0000	[thread overview]
Message-ID: <20260713101015.BF4071F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260713095812.1014365-5-krzysztof.karas@intel.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Unnecessary double execution of the memory shrinker on the allocation failure path.
--

--- Patch [4]: [PATCH v3 4/5] drm/i915/gem: Read and shrink memory in a separate function ---
commit 323006b149f5bd15e61d31522a7aa9cdbf860e09
Author: Krzysztof Karas <krzysztof.karas@intel.com>

drm/i915/gem: Read and shrink memory in a separate function

This commit extracts the memory reading and shrinking logic from
shmem_sg_alloc_table into a new shmem_shrink_get_folio helper. It also
replaces the previous array-based iteration with a do-while loop.

> diff --git a/drivers/gpu/drm/i915/gem/i915_gem_shmem.c b/drivers/gpu/drm/i915/gem/i915_gem_shmem.c
> --- a/drivers/gpu/drm/i915/gem/i915_gem_shmem.c
> +++ b/drivers/gpu/drm/i915/gem/i915_gem_shmem.c
[ ... ]
> @@ -78,6 +78,55 @@ static int validate_size(size_t size, unsigned int page_count,
>  	return 0;
>  }
>  
> +static struct folio *shmem_shrink_get_folio(struct address_space *mapping,
> +					    unsigned long folio_index,
> +					    gfp_t gfp, unsigned int page_count,
> +					    struct drm_i915_private *i915)
> +{
> +	struct folio *folio = NULL;
> +	unsigned int retries = 2;
> +
> +	do {
> +		cond_resched();
> +		folio = shmem_read_folio_gfp(mapping, folio_index, gfp);
> +		if (IS_ERR(folio)) {
> +			i915_gem_shrink(NULL, i915, 2 * page_count, NULL,
> +					I915_SHRINK_BOUND | I915_SHRINK_UNBOUND);

[Severity: Medium]
Will this result in an unnecessary double execution of the memory shrinker
when allocations fail?

In the original code, the array-based state machine checked the shrink state
and jumped to the error path before calling i915_gem_shrink again on the
final failure. With the refactored do-while loop, if the second
shmem_read_folio_gfp call fails, the loop unconditionally executes the
shrinker a second time before decrementing the retries counter to 0 and
exiting.

Could this waste CPU cycles and increase lock contention on i915->mm.obj_lock
immediately before returning -ENOMEM to the caller, considering the memory
freed by this second pass is completely ignored?

> +
> +			/*
> +			 * We've tried hard to allocate the memory by reaping
[ ... ]

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260713095812.1014365-1-krzysztof.karas@intel.com?part=4

  reply	other threads:[~2026-07-13 10:10 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-13  9:58 [PATCH v3 0/5] drivers: Improve memory management for large object allocations when i915/shmem is used with iommu Krzysztof Karas
2026-07-13  9:58 ` [PATCH v3 1/5] drm/i915/gem: Count mapped pages in a folio Krzysztof Karas
2026-07-13  9:58 ` [PATCH v3 2/5] iommu/dma: Catch scatterlist length overflows Krzysztof Karas
2026-07-13 10:13   ` sashiko-bot
2026-07-13  9:58 ` [PATCH v3 3/5] drm/i915/gem: Pull out size validation into a separate function Krzysztof Karas
2026-07-13  9:58 ` [PATCH v3 4/5] drm/i915/gem: Read and shrink memory in " Krzysztof Karas
2026-07-13 10:10   ` sashiko-bot [this message]
2026-07-13  9:58 ` [PATCH v3 5/5] drm/i915/gem: Remove iterator and use while loop Krzysztof Karas
2026-07-13 10:09   ` sashiko-bot
2026-07-13 11:01 ` ✓ i915.CI.BAT: success for drivers: Improve memory management for large object allocations when i915/shmem is used with iommu Patchwork
2026-07-13 14:14 ` ✗ i915.CI.Full: 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=20260713101015.BF4071F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=krzysztof.karas@intel.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /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.