Skip to content

Commit d02f00c

Browse files
Mark FashehJoel Becker
authored andcommitted
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>
1 parent ec20cec commit d02f00c

10 files changed

Lines changed: 1094 additions & 11 deletions

File tree

‎Documentation/filesystems/ocfs2.txt‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,6 @@ user_xattr (*) Enables Extended User Attributes.
8080
nouser_xattr Disables Extended User Attributes.
8181
acl Enables POSIX Access Control Lists support.
8282
noacl (*) Disables POSIX Access Control Lists support.
83+
resv_level=4 (*) Set how agressive allocation reservations will be.
84+
Valid values are between 0 (reservations off) to 8
85+
(maximum space for reservations).

‎fs/ocfs2/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ ocfs2-objs := \
2929
mmap.o \
3030
namei.o \
3131
refcounttree.o \
32+
reservations.o \
3233
resize.o \
3334
slot_map.o \
3435
suballoc.o \

‎fs/ocfs2/cluster/masklog.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ static struct mlog_attribute mlog_attrs[MLOG_MAX_BITS] = {
116116
define_mask(ERROR),
117117
define_mask(NOTICE),
118118
define_mask(KTHREAD),
119+
define_mask(RESERVATIONS),
119120
};
120121

121122
static struct attribute *mlog_attr_ptrs[MLOG_MAX_BITS] = {NULL, };

‎fs/ocfs2/cluster/masklog.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@
119119
#define ML_ERROR 0x0000000100000000ULL /* sent to KERN_ERR */
120120
#define ML_NOTICE 0x0000000200000000ULL /* setn to KERN_NOTICE */
121121
#define ML_KTHREAD 0x0000000400000000ULL /* kernel thread activity */
122+
#define ML_RESERVATIONS 0x0000000800000000ULL /* ocfs2 alloc reservations */
122123

123124
#define MLOG_INITIAL_AND_MASK (ML_ERROR|ML_NOTICE)
124125
#define MLOG_INITIAL_NOT_MASK (ML_ENTRY|ML_EXIT)

‎fs/ocfs2/localalloc.c‎

Lines changed: 53 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ static u32 ocfs2_local_alloc_count_bits(struct ocfs2_dinode *alloc);
5252

5353
static int ocfs2_local_alloc_find_clear_bits(struct ocfs2_super *osb,
5454
struct ocfs2_dinode *alloc,
55-
u32 numbits);
55+
u32 *numbits,
56+
struct ocfs2_alloc_reservation *resv);
5657

5758
static void ocfs2_clear_local_alloc(struct ocfs2_dinode *alloc);
5859

@@ -262,6 +263,8 @@ void ocfs2_shutdown_local_alloc(struct ocfs2_super *osb)
262263

263264
osb->local_alloc_state = OCFS2_LA_DISABLED;
264265

266+
ocfs2_resmap_uninit(&osb->osb_la_resmap);
267+
265268
main_bm_inode = ocfs2_get_system_file_inode(osb,
266269
GLOBAL_BITMAP_SYSTEM_INODE,
267270
OCFS2_INVALID_SLOT);
@@ -493,7 +496,7 @@ static int ocfs2_local_alloc_in_range(struct inode *inode,
493496
alloc = (struct ocfs2_dinode *) osb->local_alloc_bh->b_data;
494497
la = OCFS2_LOCAL_ALLOC(alloc);
495498

496-
start = ocfs2_local_alloc_find_clear_bits(osb, alloc, bits_wanted);
499+
start = ocfs2_local_alloc_find_clear_bits(osb, alloc, &bits_wanted, NULL);
497500
if (start == -1) {
498501
mlog_errno(-ENOSPC);
499502
return 0;
@@ -659,7 +662,8 @@ int ocfs2_claim_local_alloc_bits(struct ocfs2_super *osb,
659662
alloc = (struct ocfs2_dinode *) osb->local_alloc_bh->b_data;
660663
la = OCFS2_LOCAL_ALLOC(alloc);
661664

662-
start = ocfs2_local_alloc_find_clear_bits(osb, alloc, bits_wanted);
665+
start = ocfs2_local_alloc_find_clear_bits(osb, alloc, &bits_wanted,
666+
ac->ac_resv);
663667
if (start == -1) {
664668
/* TODO: Shouldn't we just BUG here? */
665669
status = -ENOSPC;
@@ -669,8 +673,6 @@ int ocfs2_claim_local_alloc_bits(struct ocfs2_super *osb,
669673

670674
bitmap = la->la_bitmap;
671675
*bit_off = le32_to_cpu(la->la_bm_off) + start;
672-
/* local alloc is always contiguous by nature -- we never
673-
* delete bits from it! */
674676
*num_bits = bits_wanted;
675677

676678
status = ocfs2_journal_access_di(handle,
@@ -682,6 +684,9 @@ int ocfs2_claim_local_alloc_bits(struct ocfs2_super *osb,
682684
goto bail;
683685
}
684686

687+
ocfs2_resmap_claimed_bits(&osb->osb_la_resmap, ac->ac_resv, start,
688+
bits_wanted);
689+
685690
while(bits_wanted--)
686691
ocfs2_set_bit(start++, bitmap);
687692

@@ -711,20 +716,48 @@ static u32 ocfs2_local_alloc_count_bits(struct ocfs2_dinode *alloc)
711716
}
712717

713718
static int ocfs2_local_alloc_find_clear_bits(struct ocfs2_super *osb,
714-
struct ocfs2_dinode *alloc,
715-
u32 numbits)
719+
struct ocfs2_dinode *alloc,
720+
u32 *numbits,
721+
struct ocfs2_alloc_reservation *resv)
716722
{
717723
int numfound, bitoff, left, startoff, lastzero;
724+
int local_resv = 0;
725+
struct ocfs2_alloc_reservation r;
718726
void *bitmap = NULL;
727+
struct ocfs2_reservation_map *resmap = &osb->osb_la_resmap;
719728

720-
mlog_entry("(numbits wanted = %u)\n", numbits);
729+
mlog_entry("(numbits wanted = %u)\n", *numbits);
721730

722731
if (!alloc->id1.bitmap1.i_total) {
723732
mlog(0, "No bits in my window!\n");
724733
bitoff = -1;
725734
goto bail;
726735
}
727736

737+
if (!resv) {
738+
local_resv = 1;
739+
ocfs2_resv_init_once(&r);
740+
ocfs2_resv_set_type(&r, OCFS2_RESV_FLAG_TMP);
741+
resv = &r;
742+
}
743+
744+
numfound = *numbits;
745+
if (ocfs2_resmap_resv_bits(resmap, resv, &bitoff, &numfound) == 0) {
746+
if (numfound < *numbits)
747+
*numbits = numfound;
748+
goto bail;
749+
}
750+
751+
/*
752+
* Code error. While reservations are enabled, local
753+
* allocation should _always_ go through them.
754+
*/
755+
BUG_ON(osb->osb_resv_level != 0);
756+
757+
/*
758+
* Reservations are disabled. Handle this the old way.
759+
*/
760+
728761
bitmap = OCFS2_LOCAL_ALLOC(alloc)->la_bitmap;
729762

730763
numfound = bitoff = startoff = 0;
@@ -750,7 +783,7 @@ static int ocfs2_local_alloc_find_clear_bits(struct ocfs2_super *osb,
750783
startoff = bitoff+1;
751784
}
752785
/* we got everything we needed */
753-
if (numfound == numbits) {
786+
if (numfound == *numbits) {
754787
/* mlog(0, "Found it all!\n"); */
755788
break;
756789
}
@@ -759,12 +792,18 @@ static int ocfs2_local_alloc_find_clear_bits(struct ocfs2_super *osb,
759792
mlog(0, "Exiting loop, bitoff = %d, numfound = %d\n", bitoff,
760793
numfound);
761794

762-
if (numfound == numbits)
795+
if (numfound == *numbits) {
763796
bitoff = startoff - numfound;
764-
else
797+
*numbits = numfound;
798+
} else {
799+
numfound = 0;
765800
bitoff = -1;
801+
}
766802

767803
bail:
804+
if (local_resv)
805+
ocfs2_resv_discard(resmap, resv);
806+
768807
mlog_exit(bitoff);
769808
return bitoff;
770809
}
@@ -1087,6 +1126,9 @@ static int ocfs2_local_alloc_new_window(struct ocfs2_super *osb,
10871126
memset(OCFS2_LOCAL_ALLOC(alloc)->la_bitmap, 0,
10881127
le16_to_cpu(la->la_size));
10891128

1129+
ocfs2_resmap_restart(&osb->osb_la_resmap, cluster_count,
1130+
OCFS2_LOCAL_ALLOC(alloc)->la_bitmap);
1131+
10901132
mlog(0, "New window allocated:\n");
10911133
mlog(0, "window la_bm_off = %u\n",
10921134
OCFS2_LOCAL_ALLOC(alloc)->la_bm_off);

‎fs/ocfs2/ocfs2.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
/* For struct ocfs2_blockcheck_stats */
4848
#include "blockcheck.h"
4949

50+
#include "reservations.h"
5051

5152
/* Caching of metadata buffers */
5253

@@ -349,6 +350,10 @@ struct ocfs2_super
349350

350351
u64 la_last_gd;
351352

353+
struct ocfs2_reservation_map osb_la_resmap;
354+
355+
unsigned int osb_resv_level;
356+
352357
/* Next three fields are for local node slot recovery during
353358
* mount. */
354359
int dirty;

0 commit comments

Comments
 (0)