2014-11-21 10:51:34 +00:00
|
|
|
/*
|
|
|
|
* MARS Long Distance Replication Software
|
|
|
|
*
|
|
|
|
* This file is part of MARS project: http://schoebel.github.io/mars/
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010-2014 Thomas Schoebel-Theuer
|
|
|
|
* Copyright (C) 2011-2014 1&1 Internet AG
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
2010-07-07 14:09:16 +00:00
|
|
|
#ifndef MARS_BUF_H
|
|
|
|
#define MARS_BUF_H
|
|
|
|
|
|
|
|
#include <linux/list.h>
|
2010-07-23 11:55:18 +00:00
|
|
|
#include <asm/atomic.h>
|
2010-07-07 14:09:16 +00:00
|
|
|
|
2010-08-11 16:02:08 +00:00
|
|
|
//#define MARS_BUF_HASH_MAX 512
|
|
|
|
#define MARS_BUF_HASH_MAX 2048
|
2010-07-07 14:09:16 +00:00
|
|
|
|
2010-12-10 17:40:20 +00:00
|
|
|
#define LIST_FREE 0
|
|
|
|
#define LIST_FORGET 1
|
|
|
|
#define LIST_LRU 2
|
|
|
|
#define LIST_MAX 3
|
|
|
|
|
2010-12-15 12:13:18 +00:00
|
|
|
struct buf_mref_aspect {
|
|
|
|
GENERIC_ASPECT(mref);
|
2010-08-07 15:02:16 +00:00
|
|
|
struct buf_head *rfa_bf;
|
2010-12-10 17:40:20 +00:00
|
|
|
//struct list_head rfa_bf_head;
|
2010-08-07 15:02:16 +00:00
|
|
|
struct list_head rfa_pending_head;
|
2010-12-10 17:40:20 +00:00
|
|
|
//struct list_head tmp_head;
|
2010-07-07 14:09:16 +00:00
|
|
|
};
|
|
|
|
|
2010-08-09 16:57:56 +00:00
|
|
|
struct cache_anchor {
|
|
|
|
spinlock_t hash_lock;
|
|
|
|
struct list_head hash_anchor;
|
|
|
|
};
|
|
|
|
|
2010-07-07 14:09:16 +00:00
|
|
|
struct buf_brick {
|
|
|
|
MARS_BRICK(buf);
|
2010-07-23 11:55:18 +00:00
|
|
|
/* brick parameters */
|
2010-07-07 14:09:16 +00:00
|
|
|
int backing_order;
|
|
|
|
int backing_size;
|
|
|
|
int max_count;
|
2010-12-10 17:40:20 +00:00
|
|
|
bool optimize_chains;
|
2010-07-23 11:55:18 +00:00
|
|
|
|
|
|
|
/* internals */
|
2010-08-07 15:02:16 +00:00
|
|
|
spinlock_t brick_lock;
|
2010-08-09 16:57:56 +00:00
|
|
|
atomic_t alloc_count;
|
2010-12-10 17:40:20 +00:00
|
|
|
atomic_t list_count[LIST_MAX];
|
2010-08-09 16:57:56 +00:00
|
|
|
atomic_t hashed_count;
|
2010-08-05 15:54:48 +00:00
|
|
|
atomic_t nr_io_pending;
|
2010-08-09 16:57:56 +00:00
|
|
|
atomic_t nr_collisions;
|
2010-11-26 13:45:10 +00:00
|
|
|
struct mars_info base_info;
|
2010-12-10 17:40:20 +00:00
|
|
|
bool got_info;
|
2010-07-07 14:09:16 +00:00
|
|
|
|
|
|
|
// lists for caching
|
2010-12-10 17:40:20 +00:00
|
|
|
struct list_head list_anchor[LIST_MAX]; // members are hashed and not in use
|
|
|
|
struct list_head forget_anchor; // like lru_anchor, but likely
|
2010-08-09 16:57:56 +00:00
|
|
|
struct cache_anchor cache_anchors[MARS_BUF_HASH_MAX]; // hash table
|
2010-07-07 14:09:16 +00:00
|
|
|
|
2010-08-05 15:54:48 +00:00
|
|
|
// statistics
|
|
|
|
unsigned long last_jiffies;
|
|
|
|
atomic_t hit_count;
|
|
|
|
atomic_t miss_count;
|
2010-12-10 17:40:20 +00:00
|
|
|
atomic_t opt_count;
|
|
|
|
atomic_t chain_count;
|
|
|
|
atomic_t post_count;
|
|
|
|
atomic_t write_count;
|
2010-08-05 15:54:48 +00:00
|
|
|
atomic_t io_count;
|
2010-07-07 14:09:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct buf_input {
|
|
|
|
MARS_INPUT(buf);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct buf_output {
|
|
|
|
MARS_OUTPUT(buf);
|
|
|
|
};
|
|
|
|
|
|
|
|
MARS_TYPES(buf);
|
|
|
|
|
|
|
|
struct buf_head {
|
2010-12-10 17:40:20 +00:00
|
|
|
void *bf_data; // this MUST come first
|
2010-08-07 15:02:16 +00:00
|
|
|
spinlock_t bf_lock;
|
2010-08-07 07:59:34 +00:00
|
|
|
struct buf_brick *bf_brick;
|
2010-08-07 15:02:16 +00:00
|
|
|
loff_t bf_pos;
|
2010-08-26 17:12:30 +00:00
|
|
|
loff_t bf_base_index;
|
2010-08-07 15:02:16 +00:00
|
|
|
int bf_flags;
|
2010-11-26 13:45:10 +00:00
|
|
|
int bf_error;
|
2010-12-10 17:40:20 +00:00
|
|
|
atomic_t bf_hash_count; // # references pinning the hash
|
|
|
|
atomic_t bf_mref_count; // # mrefs (only used for checking, no real semantics)
|
|
|
|
atomic_t bf_io_count; // # IOs in flight
|
|
|
|
// statistics / data for strategic decisions
|
|
|
|
atomic_t bf_mfu_stat;
|
|
|
|
atomic_t bf_chain_len;
|
|
|
|
bool bf_chain_detected;
|
2010-07-07 14:09:16 +00:00
|
|
|
// lists for caching
|
2010-08-05 15:54:48 +00:00
|
|
|
//struct list_head bf_mref_anchor; // all current mref members
|
2010-12-10 17:40:20 +00:00
|
|
|
struct list_head bf_list_head;
|
2010-08-07 15:02:16 +00:00
|
|
|
struct list_head bf_hash_head;
|
2010-12-10 17:40:20 +00:00
|
|
|
unsigned long bf_jiffies;
|
|
|
|
int bf_member;
|
2010-07-07 14:09:16 +00:00
|
|
|
// lists for IO
|
2010-08-07 15:02:16 +00:00
|
|
|
struct list_head bf_io_pending_anchor;
|
|
|
|
struct list_head bf_postpone_anchor;
|
2010-07-07 14:09:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|