Skip to content

Commit c515e1f

Browse files
author
Dan Magenheimer
committed
mm/fs: add hooks to support cleancache
This fourth patch of eight in this cleancache series provides the core hooks in VFS for: initializing cleancache per filesystem; capturing clean pages reclaimed by page cache; attempting to get pages from cleancache before filesystem read; and ensuring coherency between pagecache, disk, and cleancache. Note that the placement of these hooks was stable from 2.6.18 to 2.6.38; a minor semantic change was required due to a patchset in 2.6.39. All hooks become no-ops if CONFIG_CLEANCACHE is unset, or become a check of a boolean global if CONFIG_CLEANCACHE is set but no cleancache "backend" has claimed cleancache_ops. Details and a FAQ can be found in Documentation/vm/cleancache.txt [v8: minchan.kim@gmail.com: adapt to new remove_from_page_cache function] Signed-off-by: Chris Mason <chris.mason@oracle.com> Signed-off-by: Dan Magenheimer <dan.magenheimer@oracle.com> Reviewed-by: Jeremy Fitzhardinge <jeremy@goop.org> Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Al Viro <viro@ZenIV.linux.org.uk> Cc: Matthew Wilcox <matthew@wil.cx> Cc: Nick Piggin <npiggin@kernel.dk> Cc: Mel Gorman <mel@csn.ul.ie> Cc: Rik Van Riel <riel@redhat.com> Cc: Jan Beulich <JBeulich@novell.com> Cc: Andreas Dilger <adilger@sun.com> Cc: Ted Ts'o <tytso@mit.edu> Cc: Mark Fasheh <mfasheh@suse.com> Cc: Joel Becker <joel.becker@oracle.com> Cc: Nitin Gupta <ngupta@vflare.org>
1 parent 077b1f8 commit c515e1f

5 files changed

Lines changed: 32 additions & 0 deletions

File tree

‎fs/buffer.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include <linux/bitops.h>
4242
#include <linux/mpage.h>
4343
#include <linux/bit_spinlock.h>
44+
#include <linux/cleancache.h>
4445

4546
static int fsync_buffers_list(spinlock_t *lock, struct list_head *list);
4647

@@ -269,6 +270,10 @@ void invalidate_bdev(struct block_device *bdev)
269270
invalidate_bh_lrus();
270271
lru_add_drain_all(); /* make sure all lru add caches are flushed */
271272
invalidate_mapping_pages(mapping, 0, -1);
273+
/* 99% of the time, we don't need to flush the cleancache on the bdev.
274+
* But, for the strange corners, lets be cautious
275+
*/
276+
cleancache_flush_inode(mapping);
272277
}
273278
EXPORT_SYMBOL(invalidate_bdev);
274279

‎fs/mpage.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <linux/writeback.h>
2828
#include <linux/backing-dev.h>
2929
#include <linux/pagevec.h>
30+
#include <linux/cleancache.h>
3031

3132
/*
3233
* I/O completion handler for multipage BIOs.
@@ -271,6 +272,12 @@ do_mpage_readpage(struct bio *bio, struct page *page, unsigned nr_pages,
271272
SetPageMappedToDisk(page);
272273
}
273274

275+
if (fully_mapped && blocks_per_page == 1 && !PageUptodate(page) &&
276+
cleancache_get_page(page) == 0) {
277+
SetPageUptodate(page);
278+
goto confused;
279+
}
280+
274281
/*
275282
* This page will go to BIO. Do we need to send this BIO off first?
276283
*/

‎fs/super.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <linux/mutex.h>
3232
#include <linux/backing-dev.h>
3333
#include <linux/rculist_bl.h>
34+
#include <linux/cleancache.h>
3435
#include "internal.h"
3536

3637

@@ -112,6 +113,7 @@ static struct super_block *alloc_super(struct file_system_type *type)
112113
s->s_maxbytes = MAX_NON_LFS;
113114
s->s_op = &default_op;
114115
s->s_time_gran = 1000000000;
116+
s->cleancache_poolid = -1;
115117
}
116118
out:
117119
return s;
@@ -177,6 +179,7 @@ void deactivate_locked_super(struct super_block *s)
177179
{
178180
struct file_system_type *fs = s->s_type;
179181
if (atomic_dec_and_test(&s->s_active)) {
182+
cleancache_flush_fs(s);
180183
fs->kill_sb(s);
181184
/*
182185
* We need to call rcu_barrier so all the delayed rcu free

‎mm/filemap.c‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include <linux/hardirq.h> /* for BUG_ON(!in_atomic()) only */
3535
#include <linux/memcontrol.h>
3636
#include <linux/mm_inline.h> /* for page_is_file_cache() */
37+
#include <linux/cleancache.h>
3738
#include "internal.h"
3839

3940
/*
@@ -118,6 +119,16 @@ void __delete_from_page_cache(struct page *page)
118119
{
119120
struct address_space *mapping = page->mapping;
120121

122+
/*
123+
* if we're uptodate, flush out into the cleancache, otherwise
124+
* invalidate any existing cleancache entries. We can't leave
125+
* stale data around in the cleancache once our page is gone
126+
*/
127+
if (PageUptodate(page) && PageMappedToDisk(page))
128+
cleancache_put_page(page);
129+
else
130+
cleancache_flush_page(mapping, page);
131+
121132
radix_tree_delete(&mapping->page_tree, page->index);
122133
page->mapping = NULL;
123134
mapping->nrpages--;

‎mm/truncate.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <linux/task_io_accounting_ops.h>
2020
#include <linux/buffer_head.h> /* grr. try_to_release_page,
2121
do_invalidatepage */
22+
#include <linux/cleancache.h>
2223
#include "internal.h"
2324

2425

@@ -51,6 +52,7 @@ void do_invalidatepage(struct page *page, unsigned long offset)
5152
static inline void truncate_partial_page(struct page *page, unsigned partial)
5253
{
5354
zero_user_segment(page, partial, PAGE_CACHE_SIZE);
55+
cleancache_flush_page(page->mapping, page);
5456
if (page_has_private(page))
5557
do_invalidatepage(page, partial);
5658
}
@@ -214,6 +216,7 @@ void truncate_inode_pages_range(struct address_space *mapping,
214216
pgoff_t next;
215217
int i;
216218

219+
cleancache_flush_inode(mapping);
217220
if (mapping->nrpages == 0)
218221
return;
219222

@@ -291,6 +294,7 @@ void truncate_inode_pages_range(struct address_space *mapping,
291294
pagevec_release(&pvec);
292295
mem_cgroup_uncharge_end();
293296
}
297+
cleancache_flush_inode(mapping);
294298
}
295299
EXPORT_SYMBOL(truncate_inode_pages_range);
296300

@@ -440,6 +444,7 @@ int invalidate_inode_pages2_range(struct address_space *mapping,
440444
int did_range_unmap = 0;
441445
int wrapped = 0;
442446

447+
cleancache_flush_inode(mapping);
443448
pagevec_init(&pvec, 0);
444449
next = start;
445450
while (next <= end && !wrapped &&
@@ -498,6 +503,7 @@ int invalidate_inode_pages2_range(struct address_space *mapping,
498503
mem_cgroup_uncharge_end();
499504
cond_resched();
500505
}
506+
cleancache_flush_inode(mapping);
501507
return ret;
502508
}
503509
EXPORT_SYMBOL_GPL(invalidate_inode_pages2_range);

0 commit comments

Comments
 (0)