Add patch SR-ext4-resize-mark-new-group-EXT_BG_INODE_ZEROED.patch
[ext4-patch-queue/an.git] / okajima-2-ext3-implement-releasepage
blob12716c2f0aad91f125cb11ba8da3bab4d00bda22
1 ext3: provide function to release metadata pages under memory pressure
3 From: Toshiyuki Okajima <toshi.okajima@jp.fujitsu.com>
5 Pages in the page cache belonging to ext3 data files are released via
6 the ext3_releasepage() function specified in the ext3 inode's
7 address_space_ops.  However, metadata blocks (such as indirect blocks,
8 directory blocks, etc) are managed via the block device
9 address_space_ops, and they can not be released by
10 try_to_free_buffers() if they have a journal head attached to them.
12 To address this, we supply a release_metadata function which is called
13 by the block device's blkdev_releasepage() function, which calls
14 journal_try_to_free_buffers() function to free the metadata.
16 Signed-off-by: Toshiyuki Okajima <toshi.okajima@jp.fujitsu.com>
17 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
18 Cc: linux-fsdevel@vger.kernel.org
19 ---
20  fs/ext3/inode.c         |   16 ++++++++++++++++
21  fs/ext3/super.c         |    2 ++
22  include/linux/ext3_fs.h |    2 ++
23  3 files changed, 20 insertions(+)
25 diff -Nurp linux-2.6.28-rc4.orig/fs/ext3/inode.c linux-2.6.28-rc4/fs/ext3/inode.c
26 --- linux-2.6.28-rc4.orig/fs/ext3/inode.c       2008-11-10 09:36:15.000000000 +0900
27 +++ linux-2.6.28-rc4/fs/ext3/inode.c    2008-11-11 09:31:13.000000000 +0900
28 @@ -1680,6 +1680,28 @@ static int ext3_releasepage(struct page 
29  }
31  /*
32 + * Try to release metadata pages (indirect blocks, directories) which are
33 + * mapped via the block device.  Since these pages could have journal heads
34 + * which would prevent try_to_free_buffers() from freeing them, we must use
35 + * jbd layer's try_to_free_buffers() function to release them.
36 + */
37 +int ext3_release_metadata(void *client, struct page *page, gfp_t wait)
39 +       struct super_block *sb = (struct super_block*)client;
40 +       journal_t *journal;
42 +       WARN_ON(PageChecked(page));
43 +       if (!page_has_buffers(page))
44 +               return 0;
45 +       BUG_ON(EXT3_SB(sb) == NULL);
46 +       journal = EXT3_SB(sb)->s_journal;
47 +       if (journal != NULL)
48 +               return journal_try_to_free_buffers(journal, page, wait);
49 +       else
50 +               return try_to_free_buffers(page);
53 +/*
54   * If the O_DIRECT write will extend the file then add this inode to the
55   * orphan list.  So recovery will truncate it back to the original size
56   * if the machine crashes during the write.
57 diff -Nurp linux-2.6.28-rc4.orig/fs/ext3/super.c linux-2.6.28-rc4/fs/ext3/super.c
58 --- linux-2.6.28-rc4.orig/fs/ext3/super.c       2008-11-10 09:36:15.000000000 +0900
59 +++ linux-2.6.28-rc4/fs/ext3/super.c    2008-11-11 09:01:53.000000000 +0900
60 @@ -2972,6 +2972,8 @@ static struct file_system_type ext3_fs_t
61         .name           = "ext3",
62         .get_sb         = ext3_get_sb,
63         .kill_sb        = kill_block_super,
64 +       .release_metadata 
65 +                       = ext3_release_metadata,
66         .fs_flags       = FS_REQUIRES_DEV,
67  };
69 diff -Nurp linux-2.6.28-rc4.orig/include/linux/ext3_fs.h linux-2.6.28-rc4/include/linux/ext3_fs.h
70 --- linux-2.6.28-rc4.orig/include/linux/ext3_fs.h       2008-11-10 09:36:15.000000000 +0900
71 +++ linux-2.6.28-rc4/include/linux/ext3_fs.h    2008-11-10 18:33:52.000000000 +0900
72 @@ -841,6 +841,8 @@ extern void ext3_get_inode_flags(struct 
73  extern void ext3_set_aops(struct inode *inode);
74  extern int ext3_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
75                        u64 start, u64 len);
76 +extern int ext3_release_metadata(void *client, struct page *page, 
77 +                       gfp_t wait);
79  /* ioctl.c */
80  extern int ext3_ioctl (struct inode *, struct file *, unsigned int,
82 To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
83 the body of a message to majordomo@vger.kernel.org
84 More majordomo info at  http://vger.kernel.org/majordomo-info.html