PERFORCE change 178858 for review
Zheng Liu
lz at FreeBSD.org
Thu May 27 06:50:10 UTC 2010
http://p4web.freebsd.org/@@178858?ac=10
Change 178858 by lz at gnehzuil-freebsd on 2010/05/27 06:49:22
Modify search reservation window algorithm.
* Fix a bug. When searching a reservation window, it maybe
does not find a empty window.
* Modify ext2_reclaim() function to destroy rsv lock.
Affected files ...
.. //depot/projects/soc2010/extfs/src/sys/fs/ext2fs/ext2_alloc.c#16 edit
.. //depot/projects/soc2010/extfs/src/sys/fs/ext2fs/ext2_inode.c#5 edit
Differences ...
==== //depot/projects/soc2010/extfs/src/sys/fs/ext2fs/ext2_alloc.c#16 (text+ko) ====
@@ -192,9 +192,7 @@
int32_t cur;
int size = EXT2_RSV_DEFAULT_RESERVE_BLKS;
- if (search == NULL && RB_EMPTY(&fs->e2fs_rsv_tree))
- return (-1);
- else
+ if (search == NULL)
search = RB_ROOT(&fs->e2fs_rsv_tree);
cur = bpref;
@@ -212,7 +210,7 @@
next = RB_NEXT(ext2_rsv_win_tree, &fs->e2fs_rsv_tree, rsv);
rsv = next;
- if (next == NULL);
+ if (next == NULL)
break;
if (cur + size <= rsv->rsv_start)
@@ -241,7 +239,7 @@
struct ext2_rsv_win *search_rsv;
struct ext2mount *ump;
int size, ret;
- int start, end, loc;
+ int start, end, loc, i;
char *bbp;
ump = ip->i_ump;
@@ -290,6 +288,7 @@
} else {
search_rsv = ext2_search_rsv_win(&fs->e2fs_rsv_tree, bpref);
+repeat:
ret = ext2_find_next_rsv_win(search_rsv, rp, fs, bpref, cg);
if (ret < 0) {
if (rp->rsv_end != EXT2_RSV_NOT_ALLOCATED)
@@ -303,47 +302,39 @@
}
EXT2_TREE_UNLOCK(fs);
- bpref = rp->rsv_start;
- if (dtog(fs, bpref) != cg) {
- EXT2_TREE_LOCK(fs);
- if (rp->rsv_end != EXT2_RSV_NOT_ALLOCATED)
- ext2_remove_rsv_win(fs, rp);
- EXT2_TREE_UNLOCK(fs);
+ start = rp->rsv_start;
+ for (i = 1; ;i++) {
+ if (dtog(fs, start) != cg) {
+ EXT2_TREE_LOCK(fs);
+ if (rp->rsv_end != EXT2_RSV_NOT_ALLOCATED)
+ ext2_remove_rsv_win(fs, rp);
+ EXT2_TREE_UNLOCK(fs);
+
+ bpref = ext2_mapsearch(fs, bbp, bpref);
+ if (bpref < 0)
+ return (0);
+ goto allocated1;
+ }
+
+ start = dtogd(fs, start);
+ if (isset(bbp, start)) {
+ start = rp->rsv_start + i;
+ continue;
+ }
- bpref = ext2_mapsearch(fs, bbp, bpref);
- if (bpref < 0)
- return (0);
- goto allocated1;
+ break;
}
- bpref = dtogd(fs, bpref);
- if (isclr(bbp, bpref) &&
- cg * fs->e2fs->e2fs_fpg + fs->e2fs->e2fs_first_dblock + bpref >= rp->rsv_start &&
- cg * fs->e2fs->e2fs_fpg + fs->e2fs->e2fs_first_dblock + bpref < rp->rsv_end)
+ if (cg * fs->e2fs->e2fs_fpg + fs->e2fs->e2fs_first_dblock + start >= rp->rsv_start &&
+ cg * fs->e2fs->e2fs_fpg + fs->e2fs->e2fs_first_dblock + start < rp->rsv_end) {
+ bpref = start;
goto allocated;
-
- start = dtogd(fs, bpref) / NBBY;
- end = howmany(fs->e2fs->e2fs_fpg, NBBY) - start;
- for (loc = start; loc < end; loc++) {
- if (bbp[loc] == 0 &&
- cg * fs->e2fs->e2fs_fpg + fs->e2fs->e2fs_first_dblock + loc * NBBY >= rp->rsv_start &&
- cg * fs->e2fs->e2fs_fpg + fs->e2fs->e2fs_first_dblock + loc * NBBY < rp->rsv_end) {
- bpref = loc * NBBY;
- goto allocated;
- }
}
- if (loc == end) {
- EXT2_TREE_LOCK(fs);
- if (rp->rsv_end != EXT2_RSV_NOT_ALLOCATED)
- ext2_remove_rsv_win(fs, rp);
- EXT2_TREE_UNLOCK(fs);
-
- bpref = ext2_mapsearch(fs, bbp, bpref);
- if (bpref < 0)
- return (0);
- goto allocated1;
- }
+ bpref = cg * fs->e2fs->e2fs_fpg + fs->e2fs->e2fs_first_dblock + start;
+ search_rsv = rp;
+ EXT2_TREE_LOCK(fs);
+ goto repeat;
}
gotit:
@@ -427,14 +418,15 @@
rp = ip->i_rsv;
- /* If window is empty or bpref is not in reservation window,
+ /*
+ * If window is empty or bpref is not in reservation window,
* we will try to allocate a new reservation window.
* Then we try to allocate a free block.
*/
if (rp->rsv_end == EXT2_RSV_NOT_ALLOCATED)
return (ext2_alloc_new_rsv_win(ip, rp, bpref, fs, cg, bp));
else if (rp->rsv_start + rp->rsv_alloc_hit > rp->rsv_end)
- return (ext2_alloc_new_rsv_win(ip, rp, rp->rsv_end, fs, cg, bp));
+ return (ext2_alloc_new_rsv_win(ip, rp, rp->rsv_end + 1, fs, cg, bp));
return (ext2_alloc_blk(fs, ip, cg, bp,
rp->rsv_start + rp->rsv_alloc_hit, rp));
==== //depot/projects/soc2010/extfs/src/sys/fs/ext2fs/ext2_inode.c#5 (text+ko) ====
@@ -547,8 +547,8 @@
free(ip->i_rsv, M_EXT2NODE);
ip->i_rsv = NULL;
}
- /*mtx_destroy(&ip->i_rsv_lock);*/
EXT2_RSV_UNLOCK(ip);
+ mtx_destroy(&ip->i_rsv_lock);
free(vp->v_data, M_EXT2NODE);
vp->v_data = 0;
More information about the p4-projects
mailing list