aboutsummaryrefslogtreecommitdiffstats
path: root/fs/gfs2/rgrp.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/gfs2/rgrp.c')
-rw-r--r--fs/gfs2/rgrp.c113
1 files changed, 85 insertions, 28 deletions
diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c
index c8d6161bd682..a1da21349235 100644
--- a/fs/gfs2/rgrp.c
+++ b/fs/gfs2/rgrp.c
@@ -57,6 +57,11 @@
57 * 3 = Used (metadata) 57 * 3 = Used (metadata)
58 */ 58 */
59 59
60struct gfs2_extent {
61 struct gfs2_rbm rbm;
62 u32 len;
63};
64
60static const char valid_change[16] = { 65static const char valid_change[16] = {
61 /* current */ 66 /* current */
62 /* n */ 0, 1, 1, 1, 67 /* n */ 0, 1, 1, 1,
@@ -65,8 +70,9 @@ static const char valid_change[16] = {
65 1, 0, 0, 0 70 1, 0, 0, 0
66}; 71};
67 72
68static int gfs2_rbm_find(struct gfs2_rbm *rbm, u8 state, u32 minext, 73static int gfs2_rbm_find(struct gfs2_rbm *rbm, u8 state, u32 *minext,
69 const struct gfs2_inode *ip, bool nowrap); 74 const struct gfs2_inode *ip, bool nowrap,
75 const struct gfs2_alloc_parms *ap);
70 76
71 77
72/** 78/**
@@ -635,9 +641,13 @@ static void __rs_deltree(struct gfs2_blkreserv *rs)
635 /* return reserved blocks to the rgrp */ 641 /* return reserved blocks to the rgrp */
636 BUG_ON(rs->rs_rbm.rgd->rd_reserved < rs->rs_free); 642 BUG_ON(rs->rs_rbm.rgd->rd_reserved < rs->rs_free);
637 rs->rs_rbm.rgd->rd_reserved -= rs->rs_free; 643 rs->rs_rbm.rgd->rd_reserved -= rs->rs_free;
644 /* The rgrp extent failure point is likely not to increase;
645 it will only do so if the freed blocks are somehow
646 contiguous with a span of free blocks that follows. Still,
647 it will force the number to be recalculated later. */
648 rgd->rd_extfail_pt += rs->rs_free;
638 rs->rs_free = 0; 649 rs->rs_free = 0;
639 clear_bit(GBF_FULL, &bi->bi_flags); 650 clear_bit(GBF_FULL, &bi->bi_flags);
640 smp_mb__after_clear_bit();
641 } 651 }
642} 652}
643 653
@@ -876,6 +886,7 @@ static int rgd_insert(struct gfs2_rgrpd *rgd)
876static int read_rindex_entry(struct gfs2_inode *ip) 886static int read_rindex_entry(struct gfs2_inode *ip)
877{ 887{
878 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); 888 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
889 const unsigned bsize = sdp->sd_sb.sb_bsize;
879 loff_t pos = sdp->sd_rgrps * sizeof(struct gfs2_rindex); 890 loff_t pos = sdp->sd_rgrps * sizeof(struct gfs2_rindex);
880 struct gfs2_rindex buf; 891 struct gfs2_rindex buf;
881 int error; 892 int error;
@@ -913,6 +924,8 @@ static int read_rindex_entry(struct gfs2_inode *ip)
913 goto fail; 924 goto fail;
914 925
915 rgd->rd_gl->gl_object = rgd; 926 rgd->rd_gl->gl_object = rgd;
927 rgd->rd_gl->gl_vm.start = rgd->rd_addr * bsize;
928 rgd->rd_gl->gl_vm.end = rgd->rd_gl->gl_vm.start + (rgd->rd_length * bsize) - 1;
916 rgd->rd_rgl = (struct gfs2_rgrp_lvb *)rgd->rd_gl->gl_lksb.sb_lvbptr; 929 rgd->rd_rgl = (struct gfs2_rgrp_lvb *)rgd->rd_gl->gl_lksb.sb_lvbptr;
917 rgd->rd_flags &= ~GFS2_RDF_UPTODATE; 930 rgd->rd_flags &= ~GFS2_RDF_UPTODATE;
918 if (rgd->rd_data > sdp->sd_max_rg_data) 931 if (rgd->rd_data > sdp->sd_max_rg_data)
@@ -1126,6 +1139,8 @@ int gfs2_rgrp_bh_get(struct gfs2_rgrpd *rgd)
1126 gfs2_rgrp_in(rgd, (rgd->rd_bits[0].bi_bh)->b_data); 1139 gfs2_rgrp_in(rgd, (rgd->rd_bits[0].bi_bh)->b_data);
1127 rgd->rd_flags |= (GFS2_RDF_UPTODATE | GFS2_RDF_CHECK); 1140 rgd->rd_flags |= (GFS2_RDF_UPTODATE | GFS2_RDF_CHECK);
1128 rgd->rd_free_clone = rgd->rd_free; 1141 rgd->rd_free_clone = rgd->rd_free;
1142 /* max out the rgrp allocation failure point */
1143 rgd->rd_extfail_pt = rgd->rd_free;
1129 } 1144 }
1130 if (cpu_to_be32(GFS2_MAGIC) != rgd->rd_rgl->rl_magic) { 1145 if (cpu_to_be32(GFS2_MAGIC) != rgd->rd_rgl->rl_magic) {
1131 rgd->rd_rgl->rl_unlinked = cpu_to_be32(count_unlinked(rgd)); 1146 rgd->rd_rgl->rl_unlinked = cpu_to_be32(count_unlinked(rgd));
@@ -1184,7 +1199,7 @@ int gfs2_rgrp_go_lock(struct gfs2_holder *gh)
1184 1199
1185 if (gh->gh_flags & GL_SKIP && sdp->sd_args.ar_rgrplvb) 1200 if (gh->gh_flags & GL_SKIP && sdp->sd_args.ar_rgrplvb)
1186 return 0; 1201 return 0;
1187 return gfs2_rgrp_bh_get((struct gfs2_rgrpd *)gh->gh_gl->gl_object); 1202 return gfs2_rgrp_bh_get(rgd);
1188} 1203}
1189 1204
1190/** 1205/**
@@ -1455,7 +1470,7 @@ static void rg_mblk_search(struct gfs2_rgrpd *rgd, struct gfs2_inode *ip,
1455 if (WARN_ON(gfs2_rbm_from_block(&rbm, goal))) 1470 if (WARN_ON(gfs2_rbm_from_block(&rbm, goal)))
1456 return; 1471 return;
1457 1472
1458 ret = gfs2_rbm_find(&rbm, GFS2_BLKST_FREE, extlen, ip, true); 1473 ret = gfs2_rbm_find(&rbm, GFS2_BLKST_FREE, &extlen, ip, true, ap);
1459 if (ret == 0) { 1474 if (ret == 0) {
1460 rs->rs_rbm = rbm; 1475 rs->rs_rbm = rbm;
1461 rs->rs_free = extlen; 1476 rs->rs_free = extlen;
@@ -1520,6 +1535,7 @@ static u64 gfs2_next_unreserved_block(struct gfs2_rgrpd *rgd, u64 block,
1520 * @rbm: The current position in the resource group 1535 * @rbm: The current position in the resource group
1521 * @ip: The inode for which we are searching for blocks 1536 * @ip: The inode for which we are searching for blocks
1522 * @minext: The minimum extent length 1537 * @minext: The minimum extent length
1538 * @maxext: A pointer to the maximum extent structure
1523 * 1539 *
1524 * This checks the current position in the rgrp to see whether there is 1540 * This checks the current position in the rgrp to see whether there is
1525 * a reservation covering this block. If not then this function is a 1541 * a reservation covering this block. If not then this function is a
@@ -1532,7 +1548,8 @@ static u64 gfs2_next_unreserved_block(struct gfs2_rgrpd *rgd, u64 block,
1532 1548
1533static int gfs2_reservation_check_and_update(struct gfs2_rbm *rbm, 1549static int gfs2_reservation_check_and_update(struct gfs2_rbm *rbm,
1534 const struct gfs2_inode *ip, 1550 const struct gfs2_inode *ip,
1535 u32 minext) 1551 u32 minext,
1552 struct gfs2_extent *maxext)
1536{ 1553{
1537 u64 block = gfs2_rbm_to_block(rbm); 1554 u64 block = gfs2_rbm_to_block(rbm);
1538 u32 extlen = 1; 1555 u32 extlen = 1;
@@ -1545,8 +1562,7 @@ static int gfs2_reservation_check_and_update(struct gfs2_rbm *rbm,
1545 */ 1562 */
1546 if (minext) { 1563 if (minext) {
1547 extlen = gfs2_free_extlen(rbm, minext); 1564 extlen = gfs2_free_extlen(rbm, minext);
1548 nblock = block + extlen; 1565 if (extlen <= maxext->len)
1549 if (extlen < minext)
1550 goto fail; 1566 goto fail;
1551 } 1567 }
1552 1568
@@ -1555,9 +1571,17 @@ static int gfs2_reservation_check_and_update(struct gfs2_rbm *rbm,
1555 * and skip if parts of it are already reserved 1571 * and skip if parts of it are already reserved
1556 */ 1572 */
1557 nblock = gfs2_next_unreserved_block(rbm->rgd, block, extlen, ip); 1573 nblock = gfs2_next_unreserved_block(rbm->rgd, block, extlen, ip);
1558 if (nblock == block) 1574 if (nblock == block) {
1559 return 0; 1575 if (!minext || extlen >= minext)
1576 return 0;
1577
1578 if (extlen > maxext->len) {
1579 maxext->len = extlen;
1580 maxext->rbm = *rbm;
1581 }
1560fail: 1582fail:
1583 nblock = block + extlen;
1584 }
1561 ret = gfs2_rbm_from_block(rbm, nblock); 1585 ret = gfs2_rbm_from_block(rbm, nblock);
1562 if (ret < 0) 1586 if (ret < 0)
1563 return ret; 1587 return ret;
@@ -1568,30 +1592,38 @@ fail:
1568 * gfs2_rbm_find - Look for blocks of a particular state 1592 * gfs2_rbm_find - Look for blocks of a particular state
1569 * @rbm: Value/result starting position and final position 1593 * @rbm: Value/result starting position and final position
1570 * @state: The state which we want to find 1594 * @state: The state which we want to find
1571 * @minext: The requested extent length (0 for a single block) 1595 * @minext: Pointer to the requested extent length (NULL for a single block)
1596 * This is updated to be the actual reservation size.
1572 * @ip: If set, check for reservations 1597 * @ip: If set, check for reservations
1573 * @nowrap: Stop looking at the end of the rgrp, rather than wrapping 1598 * @nowrap: Stop looking at the end of the rgrp, rather than wrapping
1574 * around until we've reached the starting point. 1599 * around until we've reached the starting point.
1600 * @ap: the allocation parameters
1575 * 1601 *
1576 * Side effects: 1602 * Side effects:
1577 * - If looking for free blocks, we set GBF_FULL on each bitmap which 1603 * - If looking for free blocks, we set GBF_FULL on each bitmap which
1578 * has no free blocks in it. 1604 * has no free blocks in it.
1605 * - If looking for free blocks, we set rd_extfail_pt on each rgrp which
1606 * has come up short on a free block search.
1579 * 1607 *
1580 * Returns: 0 on success, -ENOSPC if there is no block of the requested state 1608 * Returns: 0 on success, -ENOSPC if there is no block of the requested state
1581 */ 1609 */
1582 1610
1583static int gfs2_rbm_find(struct gfs2_rbm *rbm, u8 state, u32 minext, 1611static int gfs2_rbm_find(struct gfs2_rbm *rbm, u8 state, u32 *minext,
1584 const struct gfs2_inode *ip, bool nowrap) 1612 const struct gfs2_inode *ip, bool nowrap,
1613 const struct gfs2_alloc_parms *ap)
1585{ 1614{
1586 struct buffer_head *bh; 1615 struct buffer_head *bh;
1587 int initial_bii; 1616 int initial_bii;
1588 u32 initial_offset; 1617 u32 initial_offset;
1618 int first_bii = rbm->bii;
1619 u32 first_offset = rbm->offset;
1589 u32 offset; 1620 u32 offset;
1590 u8 *buffer; 1621 u8 *buffer;
1591 int n = 0; 1622 int n = 0;
1592 int iters = rbm->rgd->rd_length; 1623 int iters = rbm->rgd->rd_length;
1593 int ret; 1624 int ret;
1594 struct gfs2_bitmap *bi; 1625 struct gfs2_bitmap *bi;
1626 struct gfs2_extent maxext = { .rbm.rgd = rbm->rgd, };
1595 1627
1596 /* If we are not starting at the beginning of a bitmap, then we 1628 /* If we are not starting at the beginning of a bitmap, then we
1597 * need to add one to the bitmap count to ensure that we search 1629 * need to add one to the bitmap count to ensure that we search
@@ -1620,7 +1652,9 @@ static int gfs2_rbm_find(struct gfs2_rbm *rbm, u8 state, u32 minext,
1620 return 0; 1652 return 0;
1621 1653
1622 initial_bii = rbm->bii; 1654 initial_bii = rbm->bii;
1623 ret = gfs2_reservation_check_and_update(rbm, ip, minext); 1655 ret = gfs2_reservation_check_and_update(rbm, ip,
1656 minext ? *minext : 0,
1657 &maxext);
1624 if (ret == 0) 1658 if (ret == 0)
1625 return 0; 1659 return 0;
1626 if (ret > 0) { 1660 if (ret > 0) {
@@ -1655,6 +1689,24 @@ next_iter:
1655 break; 1689 break;
1656 } 1690 }
1657 1691
1692 if (minext == NULL || state != GFS2_BLKST_FREE)
1693 return -ENOSPC;
1694
1695 /* If the extent was too small, and it's smaller than the smallest
1696 to have failed before, remember for future reference that it's
1697 useless to search this rgrp again for this amount or more. */
1698 if ((first_offset == 0) && (first_bii == 0) &&
1699 (*minext < rbm->rgd->rd_extfail_pt))
1700 rbm->rgd->rd_extfail_pt = *minext;
1701
1702 /* If the maximum extent we found is big enough to fulfill the
1703 minimum requirements, use it anyway. */
1704 if (maxext.len) {
1705 *rbm = maxext.rbm;
1706 *minext = maxext.len;
1707 return 0;
1708 }
1709
1658 return -ENOSPC; 1710 return -ENOSPC;
1659} 1711}
1660 1712
@@ -1680,7 +1732,8 @@ static void try_rgrp_unlink(struct gfs2_rgrpd *rgd, u64 *last_unlinked, u64 skip
1680 1732
1681 while (1) { 1733 while (1) {
1682 down_write(&sdp->sd_log_flush_lock); 1734 down_write(&sdp->sd_log_flush_lock);
1683 error = gfs2_rbm_find(&rbm, GFS2_BLKST_UNLINKED, 0, NULL, true); 1735 error = gfs2_rbm_find(&rbm, GFS2_BLKST_UNLINKED, NULL, NULL,
1736 true, NULL);
1684 up_write(&sdp->sd_log_flush_lock); 1737 up_write(&sdp->sd_log_flush_lock);
1685 if (error == -ENOSPC) 1738 if (error == -ENOSPC)
1686 break; 1739 break;
@@ -1891,7 +1944,9 @@ int gfs2_inplace_reserve(struct gfs2_inode *ip, const struct gfs2_alloc_parms *a
1891 } 1944 }
1892 1945
1893 /* Skip unuseable resource groups */ 1946 /* Skip unuseable resource groups */
1894 if (rs->rs_rbm.rgd->rd_flags & (GFS2_RGF_NOALLOC | GFS2_RDF_ERROR)) 1947 if ((rs->rs_rbm.rgd->rd_flags & (GFS2_RGF_NOALLOC |
1948 GFS2_RDF_ERROR)) ||
1949 (ap->target > rs->rs_rbm.rgd->rd_extfail_pt))
1895 goto skip_rgrp; 1950 goto skip_rgrp;
1896 1951
1897 if (sdp->sd_args.ar_rgrplvb) 1952 if (sdp->sd_args.ar_rgrplvb)
@@ -1911,15 +1966,16 @@ int gfs2_inplace_reserve(struct gfs2_inode *ip, const struct gfs2_alloc_parms *a
1911 return 0; 1966 return 0;
1912 } 1967 }
1913 1968
1914 /* Drop reservation, if we couldn't use reserved rgrp */
1915 if (gfs2_rs_active(rs))
1916 gfs2_rs_deltree(rs);
1917check_rgrp: 1969check_rgrp:
1918 /* Check for unlinked inodes which can be reclaimed */ 1970 /* Check for unlinked inodes which can be reclaimed */
1919 if (rs->rs_rbm.rgd->rd_flags & GFS2_RDF_CHECK) 1971 if (rs->rs_rbm.rgd->rd_flags & GFS2_RDF_CHECK)
1920 try_rgrp_unlink(rs->rs_rbm.rgd, &last_unlinked, 1972 try_rgrp_unlink(rs->rs_rbm.rgd, &last_unlinked,
1921 ip->i_no_addr); 1973 ip->i_no_addr);
1922skip_rgrp: 1974skip_rgrp:
1975 /* Drop reservation, if we couldn't use reserved rgrp */
1976 if (gfs2_rs_active(rs))
1977 gfs2_rs_deltree(rs);
1978
1923 /* Unlock rgrp if required */ 1979 /* Unlock rgrp if required */
1924 if (!rg_locked) 1980 if (!rg_locked)
1925 gfs2_glock_dq_uninit(&rs->rs_rgd_gh); 1981 gfs2_glock_dq_uninit(&rs->rs_rgd_gh);
@@ -2064,25 +2120,24 @@ static struct gfs2_rgrpd *rgblk_free(struct gfs2_sbd *sdp, u64 bstart,
2064 * 2120 *
2065 */ 2121 */
2066 2122
2067int gfs2_rgrp_dump(struct seq_file *seq, const struct gfs2_glock *gl) 2123void gfs2_rgrp_dump(struct seq_file *seq, const struct gfs2_glock *gl)
2068{ 2124{
2069 struct gfs2_rgrpd *rgd = gl->gl_object; 2125 struct gfs2_rgrpd *rgd = gl->gl_object;
2070 struct gfs2_blkreserv *trs; 2126 struct gfs2_blkreserv *trs;
2071 const struct rb_node *n; 2127 const struct rb_node *n;
2072 2128
2073 if (rgd == NULL) 2129 if (rgd == NULL)
2074 return 0; 2130 return;
2075 gfs2_print_dbg(seq, " R: n:%llu f:%02x b:%u/%u i:%u r:%u\n", 2131 gfs2_print_dbg(seq, " R: n:%llu f:%02x b:%u/%u i:%u r:%u e:%u\n",
2076 (unsigned long long)rgd->rd_addr, rgd->rd_flags, 2132 (unsigned long long)rgd->rd_addr, rgd->rd_flags,
2077 rgd->rd_free, rgd->rd_free_clone, rgd->rd_dinodes, 2133 rgd->rd_free, rgd->rd_free_clone, rgd->rd_dinodes,
2078 rgd->rd_reserved); 2134 rgd->rd_reserved, rgd->rd_extfail_pt);
2079 spin_lock(&rgd->rd_rsspin); 2135 spin_lock(&rgd->rd_rsspin);
2080 for (n = rb_first(&rgd->rd_rstree); n; n = rb_next(&trs->rs_node)) { 2136 for (n = rb_first(&rgd->rd_rstree); n; n = rb_next(&trs->rs_node)) {
2081 trs = rb_entry(n, struct gfs2_blkreserv, rs_node); 2137 trs = rb_entry(n, struct gfs2_blkreserv, rs_node);
2082 dump_rs(seq, trs); 2138 dump_rs(seq, trs);
2083 } 2139 }
2084 spin_unlock(&rgd->rd_rsspin); 2140 spin_unlock(&rgd->rd_rsspin);
2085 return 0;
2086} 2141}
2087 2142
2088static void gfs2_rgrp_error(struct gfs2_rgrpd *rgd) 2143static void gfs2_rgrp_error(struct gfs2_rgrpd *rgd)
@@ -2184,18 +2239,20 @@ int gfs2_alloc_blocks(struct gfs2_inode *ip, u64 *bn, unsigned int *nblocks,
2184 int error; 2239 int error;
2185 2240
2186 gfs2_set_alloc_start(&rbm, ip, dinode); 2241 gfs2_set_alloc_start(&rbm, ip, dinode);
2187 error = gfs2_rbm_find(&rbm, GFS2_BLKST_FREE, 0, ip, false); 2242 error = gfs2_rbm_find(&rbm, GFS2_BLKST_FREE, NULL, ip, false, NULL);
2188 2243
2189 if (error == -ENOSPC) { 2244 if (error == -ENOSPC) {
2190 gfs2_set_alloc_start(&rbm, ip, dinode); 2245 gfs2_set_alloc_start(&rbm, ip, dinode);
2191 error = gfs2_rbm_find(&rbm, GFS2_BLKST_FREE, 0, NULL, false); 2246 error = gfs2_rbm_find(&rbm, GFS2_BLKST_FREE, NULL, NULL, false,
2247 NULL);
2192 } 2248 }
2193 2249
2194 /* Since all blocks are reserved in advance, this shouldn't happen */ 2250 /* Since all blocks are reserved in advance, this shouldn't happen */
2195 if (error) { 2251 if (error) {
2196 fs_warn(sdp, "inum=%llu error=%d, nblocks=%u, full=%d\n", 2252 fs_warn(sdp, "inum=%llu error=%d, nblocks=%u, full=%d fail_pt=%d\n",
2197 (unsigned long long)ip->i_no_addr, error, *nblocks, 2253 (unsigned long long)ip->i_no_addr, error, *nblocks,
2198 test_bit(GBF_FULL, &rbm.rgd->rd_bits->bi_flags)); 2254 test_bit(GBF_FULL, &rbm.rgd->rd_bits->bi_flags),
2255 rbm.rgd->rd_extfail_pt);
2199 goto rgrp_error; 2256 goto rgrp_error;
2200 } 2257 }
2201 2258