*/
 STATIC int
 xfs_inobt_insert(
-       struct xfs_mount        *mp,
+       struct xfs_perag        *pag,
        struct xfs_trans        *tp,
        struct xfs_buf          *agbp,
-       struct xfs_perag        *pag,
        xfs_agino_t             newino,
        xfs_agino_t             newlen,
        xfs_btnum_t             btnum)
 {
+       struct xfs_mount        *mp = pag->pag_mount;
        struct xfs_btree_cur    *cur;
        xfs_agino_t             thisino;
        int                     i;
  */
 STATIC int
 xfs_inobt_insert_sprec(
-       struct xfs_mount                *mp,
+       struct xfs_perag                *pag,
        struct xfs_trans                *tp,
        struct xfs_buf                  *agbp,
-       struct xfs_perag                *pag,
        int                             btnum,
        struct xfs_inobt_rec_incore     *nrec,  /* in/out: new/merged rec. */
        bool                            merge)  /* merge or replace */
 {
+       struct xfs_mount                *mp = pag->pag_mount;
        struct xfs_btree_cur            *cur;
        int                             error;
        int                             i;
  */
 STATIC int
 xfs_ialloc_ag_alloc(
+       struct xfs_perag        *pag,
        struct xfs_trans        *tp,
-       struct xfs_buf          *agbp,
-       struct xfs_perag        *pag)
+       struct xfs_buf          *agbp)
 {
        struct xfs_agi          *agi;
        struct xfs_alloc_arg    args;
                 * if necessary. If a merge does occur, rec is updated to the
                 * merged record.
                 */
-               error = xfs_inobt_insert_sprec(args.mp, tp, agbp, pag,
+               error = xfs_inobt_insert_sprec(pag, tp, agbp,
                                XFS_BTNUM_INO, &rec, true);
                if (error == -EFSCORRUPTED) {
                        xfs_alert(args.mp,
                 * existing record with this one.
                 */
                if (xfs_has_finobt(args.mp)) {
-                       error = xfs_inobt_insert_sprec(args.mp, tp, agbp, pag,
+                       error = xfs_inobt_insert_sprec(pag, tp, agbp,
                                       XFS_BTNUM_FINO, &rec, false);
                        if (error)
                                return error;
                }
        } else {
                /* full chunk - insert new records to both btrees */
-               error = xfs_inobt_insert(args.mp, tp, agbp, pag, newino, newlen,
+               error = xfs_inobt_insert(pag, tp, agbp, newino, newlen,
                                         XFS_BTNUM_INO);
                if (error)
                        return error;
 
                if (xfs_has_finobt(args.mp)) {
-                       error = xfs_inobt_insert(args.mp, tp, agbp, pag, newino,
+                       error = xfs_inobt_insert(pag, tp, agbp, newino,
                                                 newlen, XFS_BTNUM_FINO);
                        if (error)
                                return error;
  */
 STATIC int
 xfs_dialloc_ag_inobt(
+       struct xfs_perag        *pag,
        struct xfs_trans        *tp,
        struct xfs_buf          *agbp,
-       struct xfs_perag        *pag,
        xfs_ino_t               parent,
        xfs_ino_t               *inop)
 {
  */
 static int
 xfs_dialloc_ag(
+       struct xfs_perag        *pag,
        struct xfs_trans        *tp,
        struct xfs_buf          *agbp,
-       struct xfs_perag        *pag,
        xfs_ino_t               parent,
        xfs_ino_t               *inop)
 {
        int                             i;
 
        if (!xfs_has_finobt(mp))
-               return xfs_dialloc_ag_inobt(tp, agbp, pag, parent, inop);
+               return xfs_dialloc_ag_inobt(pag, tp, agbp, parent, inop);
 
        /*
         * If pagino is 0 (this is the root inode allocation) use newino.
 
 static bool
 xfs_dialloc_good_ag(
-       struct xfs_trans        *tp,
        struct xfs_perag        *pag,
+       struct xfs_trans        *tp,
        umode_t                 mode,
        int                     flags,
        bool                    ok_alloc)
        int                     needspace;
        int                     error;
 
+       if (!pag)
+               return false;
        if (!pag->pagi_inodeok)
                return false;
 
 
 static int
 xfs_dialloc_try_ag(
-       struct xfs_trans        **tpp,
        struct xfs_perag        *pag,
+       struct xfs_trans        **tpp,
        xfs_ino_t               parent,
        xfs_ino_t               *new_ino,
        bool                    ok_alloc)
                        goto out_release;
                }
 
-               error = xfs_ialloc_ag_alloc(*tpp, agbp, pag);
+               error = xfs_ialloc_ag_alloc(pag, *tpp, agbp);
                if (error < 0)
                        goto out_release;
 
        }
 
        /* Allocate an inode in the found AG */
-       error = xfs_dialloc_ag(*tpp, agbp, pag, parent, &ino);
+       error = xfs_dialloc_ag(pag, *tpp, agbp, parent, &ino);
        if (!error)
                *new_ino = ino;
        return error;
        agno = start_agno;
        flags = XFS_ALLOC_FLAG_TRYLOCK;
        for (;;) {
-               pag = xfs_perag_get(mp, agno);
-               if (xfs_dialloc_good_ag(*tpp, pag, mode, flags, ok_alloc)) {
-                       error = xfs_dialloc_try_ag(tpp, pag, parent,
+               pag = xfs_perag_grab(mp, agno);
+               if (xfs_dialloc_good_ag(pag, *tpp, mode, flags, ok_alloc)) {
+                       error = xfs_dialloc_try_ag(pag, tpp, parent,
                                        &ino, ok_alloc);
                        if (error != -EAGAIN)
                                break;
                        if (low_space)
                                ok_alloc = true;
                }
-               xfs_perag_put(pag);
+               xfs_perag_rele(pag);
        }
 
        if (!error)
                *new_ino = ino;
-       xfs_perag_put(pag);
+       xfs_perag_rele(pag);
        return error;
 }
 
 
 STATIC int
 xfs_difree_inobt(
-       struct xfs_mount                *mp,
+       struct xfs_perag                *pag,
        struct xfs_trans                *tp,
        struct xfs_buf                  *agbp,
-       struct xfs_perag                *pag,
        xfs_agino_t                     agino,
        struct xfs_icluster             *xic,
        struct xfs_inobt_rec_incore     *orec)
 {
+       struct xfs_mount                *mp = pag->pag_mount;
        struct xfs_agi                  *agi = agbp->b_addr;
        struct xfs_btree_cur            *cur;
        struct xfs_inobt_rec_incore     rec;
  */
 STATIC int
 xfs_difree_finobt(
-       struct xfs_mount                *mp,
+       struct xfs_perag                *pag,
        struct xfs_trans                *tp,
        struct xfs_buf                  *agbp,
-       struct xfs_perag                *pag,
        xfs_agino_t                     agino,
        struct xfs_inobt_rec_incore     *ibtrec) /* inobt record */
 {
+       struct xfs_mount                *mp = pag->pag_mount;
        struct xfs_btree_cur            *cur;
        struct xfs_inobt_rec_incore     rec;
        int                             offset = agino - ibtrec->ir_startino;
        /*
         * Fix up the inode allocation btree.
         */
-       error = xfs_difree_inobt(mp, tp, agbp, pag, agino, xic, &rec);
+       error = xfs_difree_inobt(pag, tp, agbp, agino, xic, &rec);
        if (error)
                goto error0;
 
         * Fix up the free inode btree.
         */
        if (xfs_has_finobt(mp)) {
-               error = xfs_difree_finobt(mp, tp, agbp, pag, agino, &rec);
+               error = xfs_difree_finobt(pag, tp, agbp, agino, &rec);
                if (error)
                        goto error0;
        }
  */
 int
 xfs_ialloc_check_shrink(
+       struct xfs_perag        *pag,
        struct xfs_trans        *tp,
-       xfs_agnumber_t          agno,
        struct xfs_buf          *agibp,
        xfs_agblock_t           new_length)
 {
        struct xfs_inobt_rec_incore rec;
        struct xfs_btree_cur    *cur;
        struct xfs_mount        *mp = tp->t_mountp;
-       struct xfs_perag        *pag;
        xfs_agino_t             agino = XFS_AGB_TO_AGINO(mp, new_length);
        int                     has;
        int                     error;
        if (!xfs_has_sparseinodes(mp))
                return 0;
 
-       pag = xfs_perag_get(mp, agno);
        cur = xfs_inobt_init_cursor(mp, tp, agibp, pag, XFS_BTNUM_INO);
 
        /* Look up the inobt record that would correspond to the new EOFS. */
        }
 out:
        xfs_btree_del_cursor(cur, error);
-       xfs_perag_put(pag);
        return error;
 }