]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/commitdiff
[GFS2] Reduce inode size by moving i_alloc out of line
authorSteven Whitehouse <swhiteho@redhat.com>
Thu, 10 Jan 2008 15:18:55 +0000 (15:18 +0000)
committerSteven Whitehouse <swhiteho@redhat.com>
Fri, 25 Jan 2008 08:18:25 +0000 (08:18 +0000)
It is possible to reduce the size of GFS2 inodes by taking the i_alloc
structure out of the gfs2_inode. This patch allocates the i_alloc
structure whenever its needed, and frees it afterward. This decreases
the amount of low memory we use at the expense of requiring a memory
allocation for each page or partial page that we write. A quick test
with postmark shows that the overhead is not measurable and I also note
that OCFS2 use the same approach.

In the future I'd like to solve the problem by shrinking down the size
of the members of the i_alloc structure, but for now, this reduces the
immediate problem of using too much low-memory on x86 and doesn't add
too much overhead.

Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>
12 files changed:
fs/gfs2/bmap.c
fs/gfs2/dir.c
fs/gfs2/eattr.c
fs/gfs2/incore.h
fs/gfs2/inode.c
fs/gfs2/main.c
fs/gfs2/ops_address.c
fs/gfs2/ops_file.c
fs/gfs2/ops_inode.c
fs/gfs2/quota.c
fs/gfs2/rgrp.c
fs/gfs2/rgrp.h

index 2241141665296176c14cd49993b7519b01e7e303..73dfad70de66b53261a9472db2af6d65745f9335 100644 (file)
@@ -683,7 +683,7 @@ static int do_strip(struct gfs2_inode *ip, struct buffer_head *dibh,
        if (metadata)
                revokes = (height) ? sdp->sd_inptrs : sdp->sd_diptrs;
 
-       error = gfs2_rindex_hold(sdp, &ip->i_alloc.al_ri_gh);
+       error = gfs2_rindex_hold(sdp, &ip->i_alloc->al_ri_gh);
        if (error)
                return error;
 
@@ -785,7 +785,7 @@ out_rg_gunlock:
 out_rlist:
        gfs2_rlist_free(&rlist);
 out:
-       gfs2_glock_dq_uninit(&ip->i_alloc.al_ri_gh);
+       gfs2_glock_dq_uninit(&ip->i_alloc->al_ri_gh);
        return error;
 }
 
index 9949bb746a52e2b0975c466e1b2bd9fe6b963766..57e2ed932adc1d910120d7d6c618210dfb20141f 100644 (file)
@@ -1876,7 +1876,7 @@ static int leaf_dealloc(struct gfs2_inode *dip, u32 index, u32 len,
        if (error)
                goto out;
 
-       error = gfs2_rindex_hold(sdp, &dip->i_alloc.al_ri_gh);
+       error = gfs2_rindex_hold(sdp, &dip->i_alloc->al_ri_gh);
        if (error)
                goto out_qs;
 
@@ -1949,7 +1949,7 @@ out_rg_gunlock:
        gfs2_glock_dq_m(rlist.rl_rgrps, rlist.rl_ghs);
 out_rlist:
        gfs2_rlist_free(&rlist);
-       gfs2_glock_dq_uninit(&dip->i_alloc.al_ri_gh);
+       gfs2_glock_dq_uninit(&dip->i_alloc->al_ri_gh);
 out_qs:
        gfs2_quota_unhold(dip);
 out:
index 2a7435b5c4dc54442fd464d2053742bea923a56d..bee99704ea10b55f49f8bdcdfb17cb69aac63649 100644 (file)
@@ -1418,7 +1418,7 @@ out:
 static int ea_dealloc_block(struct gfs2_inode *ip)
 {
        struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
-       struct gfs2_alloc *al = &ip->i_alloc;
+       struct gfs2_alloc *al = ip->i_alloc;
        struct gfs2_rgrpd *rgd;
        struct buffer_head *dibh;
        int error;
index 745dada4085ceb09eece544d6ac94e21b1c4e0f9..4cdda1a3e12c698e74f060c44b32c973bcebdb41 100644 (file)
@@ -264,7 +264,7 @@ struct gfs2_inode {
        struct gfs2_glock *i_gl; /* Move into i_gh? */
        struct gfs2_holder i_iopen_gh;
        struct gfs2_holder i_gh; /* for prepare/commit_write only */
-       struct gfs2_alloc i_alloc;
+       struct gfs2_alloc *i_alloc;
        u64 i_last_rg_alloc;
 
        spinlock_t i_spin;
index 53bca9978fb553e4d80b2509c3f32c2e72c6a758..c84764ad82b36982a3b13155941b2ad5a4b7cab6 100644 (file)
@@ -711,9 +711,10 @@ static int alloc_dinode(struct gfs2_inode *dip, u64 *no_addr, u64 *generation)
        struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode);
        int error;
 
-       gfs2_alloc_get(dip);
+       if (gfs2_alloc_get(dip) == NULL)
+               return -ENOMEM;
 
-       dip->i_alloc.al_requested = RES_DINODE;
+       dip->i_alloc->al_requested = RES_DINODE;
        error = gfs2_inplace_reserve(dip);
        if (error)
                goto out;
@@ -900,7 +901,7 @@ fail_end_trans:
        gfs2_trans_end(sdp);
 
 fail_ipreserv:
-       if (dip->i_alloc.al_rgd)
+       if (dip->i_alloc->al_rgd)
                gfs2_inplace_release(dip);
 
 fail_quota_locks:
index 653fd5a6203a551ba6f2c8fa75d570d4c3e02dba..88686fcdfb1b7e0a6b5c8d1bd5b20e0cb69717a4 100644 (file)
@@ -31,6 +31,7 @@ static void gfs2_init_inode_once(struct kmem_cache *cachep, void *foo)
        inode_init_once(&ip->i_inode);
        spin_lock_init(&ip->i_spin);
        init_rwsem(&ip->i_rw_mutex);
+       ip->i_alloc = NULL;
 }
 
 static void gfs2_init_glock_once(struct kmem_cache *cachep, void *foo)
index 37406a379e7abcf24ff541000713d7c59af837d6..38dbe99a30ede1ac388596278ef02ca9e9590bae 100644 (file)
@@ -646,7 +646,6 @@ static int gfs2_write_begin(struct file *file, struct address_space *mapping,
        if (error)
                goto out_unlock;
 
-       ip->i_alloc.al_requested = 0;
        if (alloc_required) {
                al = gfs2_alloc_get(ip);
 
@@ -823,7 +822,7 @@ static int gfs2_write_end(struct file *file, struct address_space *mapping,
        struct gfs2_inode *ip = GFS2_I(inode);
        struct gfs2_sbd *sdp = GFS2_SB(inode);
        struct buffer_head *dibh;
-       struct gfs2_alloc *al = &ip->i_alloc;
+       struct gfs2_alloc *al = ip->i_alloc;
        struct gfs2_dinode *di;
        unsigned int from = pos & (PAGE_CACHE_SIZE - 1);
        unsigned int to = from + len;
@@ -861,7 +860,7 @@ static int gfs2_write_end(struct file *file, struct address_space *mapping,
        brelse(dibh);
        gfs2_trans_end(sdp);
 failed:
-       if (al->al_requested) {
+       if (al) {
                gfs2_inplace_release(ip);
                gfs2_quota_unlock(ip);
                gfs2_alloc_put(ip);
index 597f7ff2bc11c88ea6956916894154cb68ec1258..d7f4726ae0ce17e4a0f01bb9373df27897bcd165 100644 (file)
@@ -364,9 +364,11 @@ static int gfs2_page_mkwrite(struct vm_area_struct *vma, struct page *page)
        ret = gfs2_write_alloc_required(ip, pos, PAGE_CACHE_SIZE, &alloc_required);
        if (ret || !alloc_required)
                goto out_unlock;
-
-       ip->i_alloc.al_requested = 0;
+       ret = -ENOMEM;
        al = gfs2_alloc_get(ip);
+       if (al == NULL)
+               goto out_unlock;
+
        ret = gfs2_quota_lock(ip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE);
        if (ret)
                goto out_alloc_put;
index 8386ab323e33acfebf383c09e2775045c797c71a..9f71372c1757b04f17c0295b01a4a6fc17398cde 100644 (file)
@@ -61,7 +61,7 @@ static int gfs2_create(struct inode *dir, struct dentry *dentry,
                inode = gfs2_createi(ghs, &dentry->d_name, S_IFREG | mode, 0);
                if (!IS_ERR(inode)) {
                        gfs2_trans_end(sdp);
-                       if (dip->i_alloc.al_rgd)
+                       if (dip->i_alloc->al_rgd)
                                gfs2_inplace_release(dip);
                        gfs2_quota_unlock(dip);
                        gfs2_alloc_put(dip);
@@ -376,7 +376,7 @@ static int gfs2_symlink(struct inode *dir, struct dentry *dentry,
        }
 
        gfs2_trans_end(sdp);
-       if (dip->i_alloc.al_rgd)
+       if (dip->i_alloc->al_rgd)
                gfs2_inplace_release(dip);
        gfs2_quota_unlock(dip);
        gfs2_alloc_put(dip);
@@ -452,7 +452,7 @@ static int gfs2_mkdir(struct inode *dir, struct dentry *dentry, int mode)
        gfs2_assert_withdraw(sdp, !error); /* dip already pinned */
 
        gfs2_trans_end(sdp);
-       if (dip->i_alloc.al_rgd)
+       if (dip->i_alloc->al_rgd)
                gfs2_inplace_release(dip);
        gfs2_quota_unlock(dip);
        gfs2_alloc_put(dip);
@@ -558,7 +558,7 @@ static int gfs2_mknod(struct inode *dir, struct dentry *dentry, int mode,
        }
 
        gfs2_trans_end(sdp);
-       if (dip->i_alloc.al_rgd)
+       if (dip->i_alloc->al_rgd)
                gfs2_inplace_release(dip);
        gfs2_quota_unlock(dip);
        gfs2_alloc_put(dip);
index 60cc50fe15b4aad243513c59ff8a05567e11fccf..a08dabd6ce904c4eb7a92cdc4255a7b779a674cd 100644 (file)
@@ -453,7 +453,7 @@ static void qdsb_put(struct gfs2_quota_data *qd)
 int gfs2_quota_hold(struct gfs2_inode *ip, u32 uid, u32 gid)
 {
        struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
-       struct gfs2_alloc *al = &ip->i_alloc;
+       struct gfs2_alloc *al = ip->i_alloc;
        struct gfs2_quota_data **qd = al->al_qd;
        int error;
 
@@ -501,7 +501,7 @@ out:
 void gfs2_quota_unhold(struct gfs2_inode *ip)
 {
        struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
-       struct gfs2_alloc *al = &ip->i_alloc;
+       struct gfs2_alloc *al = ip->i_alloc;
        unsigned int x;
 
        gfs2_assert_warn(sdp, !test_bit(GIF_QD_LOCKED, &ip->i_flags));
@@ -853,7 +853,7 @@ fail:
 int gfs2_quota_lock(struct gfs2_inode *ip, u32 uid, u32 gid)
 {
        struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
-       struct gfs2_alloc *al = &ip->i_alloc;
+       struct gfs2_alloc *al = ip->i_alloc;
        unsigned int x;
        int error = 0;
 
@@ -921,7 +921,7 @@ static int need_sync(struct gfs2_quota_data *qd)
 
 void gfs2_quota_unlock(struct gfs2_inode *ip)
 {
-       struct gfs2_alloc *al = &ip->i_alloc;
+       struct gfs2_alloc *al = ip->i_alloc;
        struct gfs2_quota_data *qda[4];
        unsigned int count = 0;
        unsigned int x;
@@ -969,7 +969,7 @@ static int print_message(struct gfs2_quota_data *qd, char *type)
 int gfs2_quota_check(struct gfs2_inode *ip, u32 uid, u32 gid)
 {
        struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
-       struct gfs2_alloc *al = &ip->i_alloc;
+       struct gfs2_alloc *al = ip->i_alloc;
        struct gfs2_quota_data *qd;
        s64 value;
        unsigned int x;
@@ -1013,7 +1013,7 @@ int gfs2_quota_check(struct gfs2_inode *ip, u32 uid, u32 gid)
 void gfs2_quota_change(struct gfs2_inode *ip, s64 change,
                       u32 uid, u32 gid)
 {
-       struct gfs2_alloc *al = &ip->i_alloc;
+       struct gfs2_alloc *al = ip->i_alloc;
        struct gfs2_quota_data *qd;
        unsigned int x;
 
index 68c4bf363c4662465fbc8b6c3ac744c637a94440..3552110b2e5f197ef4e1b1f905d868133f02a74a 100644 (file)
@@ -819,11 +819,9 @@ void gfs2_rgrp_repolish_clones(struct gfs2_rgrpd *rgd)
 
 struct gfs2_alloc *gfs2_alloc_get(struct gfs2_inode *ip)
 {
-       struct gfs2_alloc *al = &ip->i_alloc;
-
-       /* FIXME: Should assert that the correct locks are held here... */
-       memset(al, 0, sizeof(*al));
-       return al;
+       BUG_ON(ip->i_alloc != NULL);
+       ip->i_alloc = kzalloc(sizeof(struct gfs2_alloc), GFP_KERNEL);
+       return ip->i_alloc;
 }
 
 /**
@@ -1061,7 +1059,7 @@ static struct inode *get_local_rgrp(struct gfs2_inode *ip, u64 *last_unlinked)
        struct inode *inode = NULL;
        struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
        struct gfs2_rgrpd *rgd, *begin = NULL;
-       struct gfs2_alloc *al = &ip->i_alloc;
+       struct gfs2_alloc *al = ip->i_alloc;
        int flags = LM_FLAG_TRY;
        int skipped = 0;
        int loops = 0;
@@ -1176,7 +1174,7 @@ out:
 int gfs2_inplace_reserve_i(struct gfs2_inode *ip, char *file, unsigned int line)
 {
        struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
-       struct gfs2_alloc *al = &ip->i_alloc;
+       struct gfs2_alloc *al = ip->i_alloc;
        struct inode *inode;
        int error = 0;
        u64 last_unlinked = NO_BLOCK;
@@ -1222,7 +1220,7 @@ try_again:
 void gfs2_inplace_release(struct gfs2_inode *ip)
 {
        struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
-       struct gfs2_alloc *al = &ip->i_alloc;
+       struct gfs2_alloc *al = ip->i_alloc;
 
        if (gfs2_assert_warn(sdp, al->al_alloced <= al->al_requested) == -1)
                fs_warn(sdp, "al_alloced = %u, al_requested = %u "
@@ -1412,7 +1410,7 @@ static struct gfs2_rgrpd *rgblk_free(struct gfs2_sbd *sdp, u64 bstart,
 u64 gfs2_alloc_data(struct gfs2_inode *ip)
 {
        struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
-       struct gfs2_alloc *al = &ip->i_alloc;
+       struct gfs2_alloc *al = ip->i_alloc;
        struct gfs2_rgrpd *rgd = al->al_rgd;
        u32 goal, blk;
        u64 block;
@@ -1457,7 +1455,7 @@ u64 gfs2_alloc_data(struct gfs2_inode *ip)
 u64 gfs2_alloc_meta(struct gfs2_inode *ip)
 {
        struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
-       struct gfs2_alloc *al = &ip->i_alloc;
+       struct gfs2_alloc *al = ip->i_alloc;
        struct gfs2_rgrpd *rgd = al->al_rgd;
        u32 goal, blk;
        u64 block;
@@ -1503,7 +1501,7 @@ u64 gfs2_alloc_meta(struct gfs2_inode *ip)
 u64 gfs2_alloc_di(struct gfs2_inode *dip, u64 *generation)
 {
        struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode);
-       struct gfs2_alloc *al = &dip->i_alloc;
+       struct gfs2_alloc *al = dip->i_alloc;
        struct gfs2_rgrpd *rgd = al->al_rgd;
        u32 blk;
        u64 block;
index b4c6adfc6f2ebe447697c9bdadf8f7837ea7170e..149bb161f4b6628d76076ce0a4d1ff51247c8f65 100644 (file)
@@ -32,7 +32,9 @@ void gfs2_rgrp_repolish_clones(struct gfs2_rgrpd *rgd);
 struct gfs2_alloc *gfs2_alloc_get(struct gfs2_inode *ip);
 static inline void gfs2_alloc_put(struct gfs2_inode *ip)
 {
-       return; /* So we can see where ip->i_alloc is used */
+       BUG_ON(ip->i_alloc == NULL);
+       kfree(ip->i_alloc);
+       ip->i_alloc = NULL;
 }
 
 int gfs2_inplace_reserve_i(struct gfs2_inode *ip,