Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e9b73c67 authored by Chris Wilson's avatar Chris Wilson Committed by Daniel Vetter
Browse files

drm/i915: Reduce memory pressure during shrinker by preallocating swizzle pages



On a machine with bit17 swizzling, we need to store the bit17 of the
physical page address in put-pages. This requires a memory allocation,
on average less than a page, which may be difficult to satisfy is the
request to put-pages is on behalf of the shrinker. We could allow that
allocation to pull from the reserved memory pools, but it seems much
safer to preallocate the array for tiled objects on affected machines.

v2: Export i915_gem_object_needs_bit17_swizzle() for reuse.

Signed-off-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
parent e69d0bc1
Loading
Loading
Loading
Loading
+10 −0
Original line number Original line Diff line number Diff line
@@ -30,6 +30,8 @@
#ifndef _I915_DRV_H_
#ifndef _I915_DRV_H_
#define _I915_DRV_H_
#define _I915_DRV_H_


#include <uapi/drm/i915_drm.h>

#include "i915_reg.h"
#include "i915_reg.h"
#include "intel_bios.h"
#include "intel_bios.h"
#include "intel_ringbuffer.h"
#include "intel_ringbuffer.h"
@@ -1614,6 +1616,14 @@ i915_gem_object_create_stolen(struct drm_device *dev, u32 size);
void i915_gem_object_release_stolen(struct drm_i915_gem_object *obj);
void i915_gem_object_release_stolen(struct drm_i915_gem_object *obj);


/* i915_gem_tiling.c */
/* i915_gem_tiling.c */
inline static bool i915_gem_object_needs_bit17_swizzle(struct drm_i915_gem_object *obj)
{
	drm_i915_private_t *dev_priv = obj->base.dev->dev_private;

	return dev_priv->mm.bit_6_swizzle_x == I915_BIT_6_SWIZZLE_9_10_17 &&
		obj->tiling_mode != I915_TILING_NONE;
}

void i915_gem_detect_bit_6_swizzle(struct drm_device *dev);
void i915_gem_detect_bit_6_swizzle(struct drm_device *dev);
void i915_gem_object_do_bit_17_swizzle(struct drm_i915_gem_object *obj);
void i915_gem_object_do_bit_17_swizzle(struct drm_i915_gem_object *obj);
void i915_gem_object_save_bit_17_swizzle(struct drm_i915_gem_object *obj);
void i915_gem_object_save_bit_17_swizzle(struct drm_i915_gem_object *obj);
+0 −8
Original line number Original line Diff line number Diff line
@@ -271,14 +271,6 @@ i915_gem_create_ioctl(struct drm_device *dev, void *data,
			       args->size, &args->handle);
			       args->size, &args->handle);
}
}


static int i915_gem_object_needs_bit17_swizzle(struct drm_i915_gem_object *obj)
{
	drm_i915_private_t *dev_priv = obj->base.dev->dev_private;

	return dev_priv->mm.bit_6_swizzle_x == I915_BIT_6_SWIZZLE_9_10_17 &&
		obj->tiling_mode != I915_TILING_NONE;
}

static inline int
static inline int
__copy_to_user_swizzled(char __user *cpu_vaddr,
__copy_to_user_swizzled(char __user *cpu_vaddr,
			const char *gpu_vaddr, int gpu_offset,
			const char *gpu_vaddr, int gpu_offset,
+12 −0
Original line number Original line Diff line number Diff line
@@ -396,6 +396,18 @@ i915_gem_set_tiling(struct drm_device *dev, void *data,
	/* we have to maintain this existing ABI... */
	/* we have to maintain this existing ABI... */
	args->stride = obj->stride;
	args->stride = obj->stride;
	args->tiling_mode = obj->tiling_mode;
	args->tiling_mode = obj->tiling_mode;

	/* Try to preallocate memory required to save swizzling on put-pages */
	if (i915_gem_object_needs_bit17_swizzle(obj)) {
		if (obj->bit_17 == NULL) {
			obj->bit_17 = kmalloc(BITS_TO_LONGS(obj->base.size >> PAGE_SHIFT) *
					      sizeof(long), GFP_KERNEL);
		}
	} else {
		kfree(obj->bit_17);
		obj->bit_17 = NULL;
	}

	drm_gem_object_unreference(&obj->base);
	drm_gem_object_unreference(&obj->base);
	mutex_unlock(&dev->struct_mutex);
	mutex_unlock(&dev->struct_mutex);