mirror of
https://github.com/torvalds/linux.git
synced 2025-04-11 04:53:02 +00:00

Provide a helper to shrink ttm_tt page-vectors on a per-page basis. A ttm_backup backend could then in theory get away with allocating a single temporary page for each struct ttm_tt. This is accomplished by splitting larger pages before trying to back them up. In the future we could allow ttm_backup to handle backing up large pages as well, but currently there's no benefit in doing that, since the shmem backup backend would have to split those anyway to avoid allocating too much temporary memory, and if the backend instead inserts pages into the swap-cache, those are split on reclaim by the core. Due to potential backup- and recover errors, allow partially swapped out struct ttm_tt's, although mark them as swapped out stopping them from being swapped out a second time. More details in the ttm_pool.c DOC section. v2: - A couple of cleanups and error fixes in ttm_pool_back_up_tt. - s/back_up/backup/ - Add a writeback parameter to the exported interface. v8: - Use a struct for flags for readability (Matt Brost) - Address misc other review comments (Matt Brost) v9: - Update the kerneldoc for the ttm_tt::backup field. v10: - Rebase. v13: - Rebase on ttm_backup interface change. Update kerneldoc. - Rebase and adjust ttm_tt_is_swapped(). v15: - Rebase on ttm_backup return value change. - Rebase on previous restructuring of ttm_pool_alloc() - Rework the ttm_pool backup interface (Christian König) - Remove cond_resched() (Christian König) - Get rid of the need to allocate an intermediate page array when restoring a multi-order page (Christian König) - Update documentation. Cc: Christian König <christian.koenig@amd.com> Cc: Somalapuram Amaranath <Amaranath.Somalapuram@amd.com> Cc: Matthew Brost <matthew.brost@intel.com> Cc: <dri-devel@lists.freedesktop.org> Signed-off-by: Thomas Hellström <thomas.hellstrom@linux.intel.com> Reviewed-by: Matthew Brost <matthew.brost@intel.com> Acked-by: Christian Koenig <christian.koenig@amd.com> Link: https://lore.kernel.org/intel-xe/20250305092220.123405-3-thomas.hellstrom@linux.intel.com
104 lines
3.2 KiB
C
104 lines
3.2 KiB
C
/* SPDX-License-Identifier: GPL-2.0 OR MIT */
|
|
/*
|
|
* Copyright 2020 Advanced Micro Devices, Inc.
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
* to deal in the Software without restriction, including without limitation
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be included in
|
|
* all copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
* OTHER DEALINGS IN THE SOFTWARE.
|
|
*
|
|
* Authors: Christian König
|
|
*/
|
|
|
|
#ifndef _TTM_PAGE_POOL_H_
|
|
#define _TTM_PAGE_POOL_H_
|
|
|
|
#include <linux/mmzone.h>
|
|
#include <linux/llist.h>
|
|
#include <linux/spinlock.h>
|
|
#include <drm/ttm/ttm_caching.h>
|
|
|
|
struct device;
|
|
struct seq_file;
|
|
struct ttm_backup_flags;
|
|
struct ttm_operation_ctx;
|
|
struct ttm_pool;
|
|
struct ttm_tt;
|
|
|
|
/**
|
|
* struct ttm_pool_type - Pool for a certain memory type
|
|
*
|
|
* @pool: the pool we belong to, might be NULL for the global ones
|
|
* @order: the allocation order our pages have
|
|
* @caching: the caching type our pages have
|
|
* @shrinker_list: our place on the global shrinker list
|
|
* @lock: protection of the page list
|
|
* @pages: the list of pages in the pool
|
|
*/
|
|
struct ttm_pool_type {
|
|
struct ttm_pool *pool;
|
|
unsigned int order;
|
|
enum ttm_caching caching;
|
|
|
|
struct list_head shrinker_list;
|
|
|
|
spinlock_t lock;
|
|
struct list_head pages;
|
|
};
|
|
|
|
/**
|
|
* struct ttm_pool - Pool for all caching and orders
|
|
*
|
|
* @dev: the device we allocate pages for
|
|
* @nid: which numa node to use
|
|
* @use_dma_alloc: if coherent DMA allocations should be used
|
|
* @use_dma32: if GFP_DMA32 should be used
|
|
* @caching: pools for each caching/order
|
|
*/
|
|
struct ttm_pool {
|
|
struct device *dev;
|
|
int nid;
|
|
|
|
bool use_dma_alloc;
|
|
bool use_dma32;
|
|
|
|
struct {
|
|
struct ttm_pool_type orders[NR_PAGE_ORDERS];
|
|
} caching[TTM_NUM_CACHING_TYPES];
|
|
};
|
|
|
|
int ttm_pool_alloc(struct ttm_pool *pool, struct ttm_tt *tt,
|
|
struct ttm_operation_ctx *ctx);
|
|
void ttm_pool_free(struct ttm_pool *pool, struct ttm_tt *tt);
|
|
|
|
void ttm_pool_init(struct ttm_pool *pool, struct device *dev,
|
|
int nid, bool use_dma_alloc, bool use_dma32);
|
|
void ttm_pool_fini(struct ttm_pool *pool);
|
|
|
|
int ttm_pool_debugfs(struct ttm_pool *pool, struct seq_file *m);
|
|
|
|
void ttm_pool_drop_backed_up(struct ttm_tt *tt);
|
|
|
|
long ttm_pool_backup(struct ttm_pool *pool, struct ttm_tt *ttm,
|
|
const struct ttm_backup_flags *flags);
|
|
int ttm_pool_restore_and_alloc(struct ttm_pool *pool, struct ttm_tt *tt,
|
|
const struct ttm_operation_ctx *ctx);
|
|
|
|
int ttm_pool_mgr_init(unsigned long num_pages);
|
|
void ttm_pool_mgr_fini(void);
|
|
|
|
#endif
|