[PATCH 3/4] drm/i915: pre-alloc instead of drm_mm search/get_block

Chris Wilson chris at chris-wilson.co.uk
Thu Jul 25 07:14:53 PDT 2013


On Thu, Jul 25, 2013 at 03:56:01PM +0200, David Herrmann wrote:
> i915 is the last user of the weird search+get_block drm_mm API. Convert it
> to an explicit kmalloc()+insert_node(). This drops the last user of the
> node-cache in drm_mm. We can remove it now in a follow-up patch.
> 
> Cc: Daniel Vetter <daniel.vetter at ffwll.ch>
> Signed-off-by: David Herrmann <dh.herrmann at gmail.com>
> ---
>  drivers/gpu/drm/i915/i915_gem_stolen.c | 72 ++++++++++++++++++++++------------
>  1 file changed, 47 insertions(+), 25 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/i915_gem_stolen.c b/drivers/gpu/drm/i915/i915_gem_stolen.c
> index 5521833..7a2f040 100644
> --- a/drivers/gpu/drm/i915/i915_gem_stolen.c
> +++ b/drivers/gpu/drm/i915/i915_gem_stolen.c
> @@ -112,31 +112,39 @@ static int i915_setup_compression(struct drm_device *dev, int size)
>  {
>  	struct drm_i915_private *dev_priv = dev->dev_private;
>  	struct drm_mm_node *compressed_fb, *uninitialized_var(compressed_llb);
> +	int ret;
>  
> -	/* Try to over-allocate to reduce reallocations and fragmentation */
> -	compressed_fb = drm_mm_search_free(&dev_priv->mm.stolen,
> -					   size <<= 1, 4096, 0);
> -	if (!compressed_fb)
> -		compressed_fb = drm_mm_search_free(&dev_priv->mm.stolen,
> -						   size >>= 1, 4096, 0);
> -	if (compressed_fb)
> -		compressed_fb = drm_mm_get_block(compressed_fb, size, 4096);
> +	compressed_fb = kzalloc(sizeof(*compressed_fb), GFP_KERNEL);
>  	if (!compressed_fb)
>  		goto err;
>  
> +	/* Try to over-allocate to reduce reallocations and fragmentation */
> +	ret = drm_mm_insert_node(&dev_priv->mm.stolen, compressed_fb,
> +				 size <<= 1, 4096, false);
> +	if (ret)
> +		ret = drm_mm_insert_node(&dev_priv->mm.stolen, compressed_fb,
> +					 size >>= 1, 4096, false);
> +	if (ret) {
> +		kfree(compressed_fb);
> +		goto err;

kfree(NULL) is legal so move the kfree(compressed_fb) below err: and we
do a similar cleanup for err_fb:
-Chris

-- 
Chris Wilson, Intel Open Source Technology Centre


More information about the dri-devel mailing list