2023-01-25 20:00:44 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2016-12-15 09:57:31 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2017 Red Hat. All rights reserved.
|
|
|
|
*
|
|
|
|
* This file is released under the GPL.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef DM_CACHE_BACKGROUND_WORK_H
|
|
|
|
#define DM_CACHE_BACKGROUND_WORK_H
|
|
|
|
|
|
|
|
#include <linux/vmalloc.h>
|
|
|
|
#include "dm-cache-policy.h"
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------*/
|
|
|
|
|
2023-01-26 10:14:26 +00:00
|
|
|
/*
|
|
|
|
* The cache policy decides what background work should be performed,
|
|
|
|
* such as promotions, demotions and writebacks. The core cache target
|
|
|
|
* is in charge of performing the work, and does so when it sees fit.
|
|
|
|
*
|
|
|
|
* The background_tracker acts as a go between. Keeping track of future
|
|
|
|
* work that the policy has decided upon, and handing (issuing) it to
|
|
|
|
* the core target when requested.
|
|
|
|
*
|
|
|
|
* There is no locking in this, so calls will probably need to be
|
|
|
|
* protected with a spinlock.
|
|
|
|
*/
|
|
|
|
|
2024-11-11 15:51:02 +00:00
|
|
|
struct bt_work {
|
|
|
|
struct list_head list;
|
|
|
|
struct rb_node node;
|
|
|
|
struct policy_work work;
|
|
|
|
};
|
|
|
|
|
|
|
|
extern struct kmem_cache *btracker_work_cache;
|
|
|
|
|
2016-12-15 09:57:31 +00:00
|
|
|
struct background_work;
|
|
|
|
struct background_tracker;
|
|
|
|
|
|
|
|
/*
|
2023-01-26 10:14:26 +00:00
|
|
|
* Create a new tracker, it will not be able to queue more than
|
|
|
|
* 'max_work' entries.
|
2016-12-15 09:57:31 +00:00
|
|
|
*/
|
2023-01-25 20:14:58 +00:00
|
|
|
struct background_tracker *btracker_create(unsigned int max_work);
|
2023-01-26 10:14:26 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Destroy the tracker. No issued, but not complete, work should
|
|
|
|
* exist when this is called. It is fine to have queued but unissued
|
|
|
|
* work.
|
|
|
|
*/
|
2016-12-15 09:57:31 +00:00
|
|
|
void btracker_destroy(struct background_tracker *b);
|
|
|
|
|
2023-01-25 20:14:58 +00:00
|
|
|
unsigned int btracker_nr_writebacks_queued(struct background_tracker *b);
|
|
|
|
unsigned int btracker_nr_demotions_queued(struct background_tracker *b);
|
2016-12-15 09:57:31 +00:00
|
|
|
|
|
|
|
/*
|
2023-01-26 10:14:26 +00:00
|
|
|
* Queue some work within the tracker. 'work' should point to the work
|
|
|
|
* to queue, this will be copied (ownership doesn't pass). If pwork
|
|
|
|
* is not NULL then it will be set to point to the tracker's internal
|
|
|
|
* copy of the work.
|
|
|
|
*
|
2016-12-15 09:57:31 +00:00
|
|
|
* returns -EINVAL iff the work is already queued. -ENOMEM if the work
|
|
|
|
* couldn't be queued for another reason.
|
|
|
|
*/
|
|
|
|
int btracker_queue(struct background_tracker *b,
|
|
|
|
struct policy_work *work,
|
|
|
|
struct policy_work **pwork);
|
|
|
|
|
|
|
|
/*
|
2023-01-26 10:14:26 +00:00
|
|
|
* Hands out the next piece of work to be performed.
|
2016-12-15 09:57:31 +00:00
|
|
|
* Returns -ENODATA if there's no work.
|
|
|
|
*/
|
|
|
|
int btracker_issue(struct background_tracker *b, struct policy_work **work);
|
2023-01-26 10:14:26 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Informs the tracker that the work has been completed and it may forget
|
|
|
|
* about it.
|
|
|
|
*/
|
|
|
|
void btracker_complete(struct background_tracker *b, struct policy_work *op);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Predicate to see if an origin block is already scheduled for promotion.
|
|
|
|
*/
|
2016-12-15 09:57:31 +00:00
|
|
|
bool btracker_promotion_already_present(struct background_tracker *b,
|
|
|
|
dm_oblock_t oblock);
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------*/
|
|
|
|
|
|
|
|
#endif
|