aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ocfs2/reservations.h
diff options
context:
space:
mode:
authorMark Fasheh <mfasheh@suse.com>2009-12-07 16:10:48 -0500
committerJoel Becker <joel.becker@oracle.com>2010-05-05 21:17:30 -0400
commitd02f00cc057809d96c044cc72d5b9809d59f7d49 (patch)
tree44a6d81ecf9fb4b5aa91c0501a8da2ee36890a38 /fs/ocfs2/reservations.h
parentec20cec7a351584ca6c70ead012e73d61f9a8e04 (diff)
ocfs2: allocation reservations
This patch improves Ocfs2 allocation policy by allowing an inode to reserve a portion of the local alloc bitmap for itself. The reserved portion (allocation window) is advisory in that other allocation windows might steal it if the local alloc bitmap becomes full. Otherwise, the reservations are honored and guaranteed to be free. When the local alloc window is moved to a different portion of the bitmap, existing reservations are discarded. Reservation windows are represented internally by a red-black tree. Within that tree, each node represents the reservation window of one inode. An LRU of active reservations is also maintained. When new data is written, we allocate it from the inodes window. When all bits in a window are exhausted, we allocate a new one as close to the previous one as possible. Should we not find free space, an existing reservation is pulled off the LRU and cannibalized. Signed-off-by: Mark Fasheh <mfasheh@suse.com>
Diffstat (limited to 'fs/ocfs2/reservations.h')
-rw-r--r--fs/ocfs2/reservations.h154
1 files changed, 154 insertions, 0 deletions
diff --git a/fs/ocfs2/reservations.h b/fs/ocfs2/reservations.h
new file mode 100644
index 000000000000..8341cd0ef855
--- /dev/null
+++ b/fs/ocfs2/reservations.h
@@ -0,0 +1,154 @@
1/* -*- mode: c; c-basic-offset: 8; -*-
2 * vim: noexpandtab sw=8 ts=8 sts=0:
3 *
4 * reservations.h
5 *
6 * Allocation reservations function prototypes and structures.
7 *
8 * Copyright (C) 2010 Novell. All rights reserved.
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public
12 * License version 2 as published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 */
19
20#ifndef OCFS2_RESERVATIONS_H
21#define OCFS2_RESERVATIONS_H
22
23#include <linux/rbtree.h>
24
25#define OCFS2_DEFAULT_RESV_LEVEL 4
26#define OCFS2_MAX_RESV_LEVEL 9
27#define OCFS2_MIN_RESV_LEVEL 0
28
29struct ocfs2_alloc_reservation {
30 struct rb_node r_node;
31
32 unsigned int r_start; /* Begining of current window */
33 unsigned int r_len; /* Length of the window */
34
35 unsigned int r_last_len; /* Length of most recent alloc */
36 unsigned int r_last_start; /* Start of most recent alloc */
37 struct list_head r_lru; /* LRU list head */
38
39 unsigned int r_flags;
40};
41
42#define OCFS2_RESV_FLAG_INUSE 0x01 /* Set when r_node is part of a btree */
43#define OCFS2_RESV_FLAG_TMP 0x02 /* Temporary reservation, will be
44 * destroyed immedately after use */
45
46struct ocfs2_reservation_map {
47 struct rb_root m_reservations;
48 char *m_disk_bitmap;
49
50 struct ocfs2_super *m_osb;
51
52 /* The following are not initialized to meaningful values until a disk
53 * bitmap is provided. */
54 u32 m_bitmap_len; /* Number of valid
55 * bits available */
56
57 struct list_head m_lru; /* LRU of reservations
58 * structures. */
59
60};
61
62void ocfs2_resv_init_once(struct ocfs2_alloc_reservation *resv);
63
64#define OCFS2_RESV_TYPES (OCFS2_RESV_FLAG_TMP)
65void ocfs2_resv_set_type(struct ocfs2_alloc_reservation *resv,
66 unsigned int flags);
67
68/**
69 * ocfs2_resv_discard() - truncate a reservation
70 * @resmap:
71 * @resv: the reservation to truncate.
72 *
73 * After this function is called, the reservation will be empty, and
74 * unlinked from the rbtree.
75 */
76void ocfs2_resv_discard(struct ocfs2_reservation_map *resmap,
77 struct ocfs2_alloc_reservation *resv);
78
79
80/**
81 * ocfs2_resmap_init() - Initialize fields of a reservations bitmap
82 * @resmap: struct ocfs2_reservation_map to initialize
83 * @obj: unused for now
84 * @ops: unused for now
85 * @max_bitmap_bytes: Maximum size of the bitmap (typically blocksize)
86 *
87 * Only possible return value other than '0' is -ENOMEM for failure to
88 * allocation mirror bitmap.
89 */
90int ocfs2_resmap_init(struct ocfs2_super *osb,
91 struct ocfs2_reservation_map *resmap);
92
93/**
94 * ocfs2_resmap_restart() - "restart" a reservation bitmap
95 * @resmap: reservations bitmap
96 * @clen: Number of valid bits in the bitmap
97 * @disk_bitmap: the disk bitmap this resmap should refer to.
98 *
99 * Re-initialize the parameters of a reservation bitmap. This is
100 * useful for local alloc window slides.
101 *
102 * This function will call ocfs2_trunc_resv against all existing
103 * reservations. A future version will recalculate existing
104 * reservations based on the new bitmap.
105 */
106void ocfs2_resmap_restart(struct ocfs2_reservation_map *resmap,
107 unsigned int clen, char *disk_bitmap);
108
109/**
110 * ocfs2_resmap_uninit() - uninitialize a reservation bitmap structure
111 * @resmap: the struct ocfs2_reservation_map to uninitialize
112 */
113void ocfs2_resmap_uninit(struct ocfs2_reservation_map *resmap);
114
115/**
116 * ocfs2_resmap_resv_bits() - Return still-valid reservation bits
117 * @resmap: reservations bitmap
118 * @resv: reservation to base search from
119 * @cstart: start of proposed allocation
120 * @clen: length (in clusters) of proposed allocation
121 *
122 * Using the reservation data from resv, this function will compare
123 * resmap and resmap->m_disk_bitmap to determine what part (if any) of
124 * the reservation window is still clear to use. If resv is empty,
125 * this function will try to allocate a window for it.
126 *
127 * On success, zero is returned and the valid allocation area is set in cstart
128 * and clen.
129 *
130 * Returns -ENOSPC if reservations are disabled.
131 */
132int ocfs2_resmap_resv_bits(struct ocfs2_reservation_map *resmap,
133 struct ocfs2_alloc_reservation *resv,
134 int *cstart, int *clen);
135
136/**
137 * ocfs2_resmap_claimed_bits() - Tell the reservation code that bits were used.
138 * @resmap: reservations bitmap
139 * @resv: optional reservation to recalulate based on new bitmap
140 * @cstart: start of allocation in clusters
141 * @clen: end of allocation in clusters.
142 *
143 * Tell the reservation code that bits were used to fulfill allocation in
144 * resmap. The bits don't have to have been part of any existing
145 * reservation. But we must always call this function when bits are claimed.
146 * Internally, the reservations code will use this information to mark the
147 * reservations bitmap. If resv is passed, it's next allocation window will be
148 * calculated.
149 */
150void ocfs2_resmap_claimed_bits(struct ocfs2_reservation_map *resmap,
151 struct ocfs2_alloc_reservation *resv,
152 u32 cstart, u32 clen);
153
154#endif /* OCFS2_RESERVATIONS_H */