/*
* Copyright (C) 2012 Red Hat. All rights reserved.
*
* This file is released under the GPL.
*/
#include "dm-cache-policy.h"
#include "dm.h"
#include <linux/hash.h>
#include <linux/jiffies.h>
#include <linux/module.h>
#include <linux/mutex.h>
#include <linux/slab.h>
#include <linux/vmalloc.h>
#define DM_MSG_PREFIX "cache-policy-mq"
static struct kmem_cache *mq_entry_cache;
/*----------------------------------------------------------------*/
static unsigned next_power(unsigned n, unsigned min)
{
return roundup_pow_of_two(max(n, min));
}
/*----------------------------------------------------------------*/
/*
* Large, sequential ios are probably better left on the origin device since
* spindles tend to have good bandwidth.
*
* The io_tracker tries to spot when the io is in one of these sequential
* modes.
*
* Two thresholds to switch between random and sequential io mode are defaulting
* as follows and can be adjusted via the constructor and message interfaces.
*/
#define RANDOM_THRESHOLD_DEFAULT 4
#define SEQUENTIAL_THRESHOLD_DEFAULT 512
enum io_pattern {
PATTERN_SEQUENTIAL,
PATTERN_RANDOM
};
struct io_tracker {
enum io_pattern pattern;
unsigned nr_seq_samples;
unsigned nr_rand_samples;
unsigned thresholds[2];
dm_oblock_t last_end_oblock;
};
static void iot_init(struct io_tracker *t,
int sequential_threshold, int random_threshold)
{
t->pattern = PATTERN_RANDOM;
t->nr_seq_samples