From cdf199679c1814902f181bec81a5bfe9902b8217 Mon Sep 17 00:00:00 2001 From: Bobi Jam Date: Fri, 4 Nov 2011 17:18:19 +0800 Subject: [PATCH] LU-620 llite: add delete/remove_from_page_cache check Later 2.6.32 kernel use memory cgroup feature but does not export truncate_complete_page but export delete_from_page_cache or remove_from_page_cache, we need properly use them for pachless client code. Signed-off-by: Bobi Jam Change-Id: I4b95da2b4cac7f2c2f63b69896dd91c3544a5473 Reviewed-on: http://review.whamcloud.com/1649 Tested-by: Hudson Tested-by: Maloo Reviewed-by: Johann Lombardi --- lustre/autoconf/lustre-core.m4 | 23 +++++++++++------ lustre/include/linux/lustre_compat25.h | 2 -- lustre/include/linux/lustre_patchless_compat.h | 35 ++++++++++++++++++-------- lustre/llite/dir.c | 4 +-- lustre/llite/file.c | 2 +- lustre/llite/rw.c | 4 +-- 6 files changed, 45 insertions(+), 25 deletions(-) diff --git a/lustre/autoconf/lustre-core.m4 b/lustre/autoconf/lustre-core.m4 index 3891416..d8a7461 100644 --- a/lustre/autoconf/lustre-core.m4 +++ b/lustre/autoconf/lustre-core.m4 @@ -899,14 +899,23 @@ LB_LINUX_TRY_COMPILE([ ]) ]) +# truncate_complete_page() was exported from RHEL5/SLES10/SLES11 +# remove_from_page_cache() was exported between 2.6.35 and 2.6.38 +# delete_from_page_cache() is exported from 2.6.39 AC_DEFUN([LC_EXPORT_TRUNCATE_COMPLETE_PAGE], -[LB_CHECK_SYMBOL_EXPORT([truncate_complete_page], -[mm/truncate.c],[ -AC_DEFINE(HAVE_TRUNCATE_COMPLETE_PAGE, 1, - [kernel export truncate_complete_page]) -],[ -]) -]) + [LB_CHECK_SYMBOL_EXPORT([truncate_complete_page], + [mm/truncate.c], + [AC_DEFINE(HAVE_TRUNCATE_COMPLETE_PAGE, 1, + [kernel export truncate_complete_page])]) + LB_CHECK_SYMBOL_EXPORT([remove_from_page_cache], + [mm/filemap.c], + [AC_DEFINE(HAVE_REMOVE_FROM_PAGE_CACHE, 1, + [kernel export remove_from_page_cache])]) + LB_CHECK_SYMBOL_EXPORT([delete_from_page_cache], + [mm/filemap.c], + [AC_DEFINE(HAVE_DELETE_FROM_PAGE_CACHE, 1, + [kernel export delete_from_page_cache])]) + ]) AC_DEFUN([LC_EXPORT_TRUNCATE_RANGE], [LB_CHECK_SYMBOL_EXPORT([truncate_inode_pages_range], diff --git a/lustre/include/linux/lustre_compat25.h b/lustre/include/linux/lustre_compat25.h index 0783b7b..9c2732f 100644 --- a/lustre/include/linux/lustre_compat25.h +++ b/lustre/include/linux/lustre_compat25.h @@ -194,8 +194,6 @@ void groups_free(struct group_info *ginfo); (inode)->i_mapping->a_ops->writepage(page, NULL) #define ll_invalidate_inode_pages(inode) \ invalidate_inode_pages((inode)->i_mapping) -#define ll_truncate_complete_page(page) \ - truncate_complete_page(page->mapping, page) #define ll_vfs_create(a,b,c,d) vfs_create(a,b,c,d) #define ll_dev_t dev_t diff --git a/lustre/include/linux/lustre_patchless_compat.h b/lustre/include/linux/lustre_patchless_compat.h index e69fa58..3b68cdd 100644 --- a/lustre/include/linux/lustre_patchless_compat.h +++ b/lustre/include/linux/lustre_patchless_compat.h @@ -45,6 +45,16 @@ #include #include +#ifndef HAVE_CANCEL_DIRTY_PAGE /* 2.6.20 */ +#define cancel_dirty_page(page, size) clear_page_dirty(page) +#endif + +#ifndef HAVE_DELETE_FROM_PAGE_CACHE /* 2.6.39 */ +#ifndef HAVE_REMOVE_FROM_PAGE_CACHE /* 2.6.35 - 2.6.38 */ +#ifdef HAVE_NR_PAGECACHE /* 2.6.18 */ +#define __dec_zone_page_state(page, flag) atomic_add(-1, &nr_pagecache); +#endif /* HAVE_NR_PAGECACHE */ + /* XXX copy & paste from 2.6.15 kernel */ static inline void ll_remove_from_page_cache(struct page *page) { @@ -60,17 +70,25 @@ static inline void ll_remove_from_page_cache(struct page *page) radix_tree_delete(&mapping->page_tree, page->index); page->mapping = NULL; mapping->nrpages--; -#ifdef HAVE_NR_PAGECACHE - atomic_add(-1, &nr_pagecache); // XXX pagecache_acct(-1); -#else __dec_zone_page_state(page, NR_FILE_PAGES); -#endif #ifdef HAVE_RW_TREE_LOCK write_unlock_irq(&mapping->tree_lock); #else spin_unlock_irq(&mapping->tree_lock); #endif } +#else /* HAVE_REMOVE_FROM_PAGE_CACHE */ +#define ll_remove_from_page_cache(page) remove_from_page_cache(page) +#endif /* !HAVE_REMOVE_FROM_PAGE_CACHE */ + +static inline void ll_delete_from_page_cache(struct page *page) +{ + ll_remove_from_page_cache(page); + page_cache_release(page); +} +#else /* HAVE_DELETE_FROM_PAGE_CACHE */ +#define ll_delete_from_page_cache(page) delete_from_page_cache(page) +#endif /* !HAVE_DELETE_FROM_PAGE_CACHE */ static inline void truncate_complete_page(struct address_space *mapping, struct page *page) @@ -81,16 +99,11 @@ truncate_complete_page(struct address_space *mapping, struct page *page) if (PagePrivate(page)) page->mapping->a_ops->invalidatepage(page, 0); -#ifdef HAVE_CANCEL_DIRTY_PAGE cancel_dirty_page(page, PAGE_SIZE); -#else - clear_page_dirty(page); -#endif ClearPageMappedToDisk(page); - ll_remove_from_page_cache(page); - page_cache_release(page); /* pagecache ref */ + ll_delete_from_page_cache(page); } -#endif /* HAVE_TRUNCATE_COMPLETE_PAGE */ +#endif /* !HAVE_TRUNCATE_COMPLETE_PAGE */ #if !defined(HAVE_D_REHASH_COND) && !defined(HAVE___D_REHASH) /* megahack */ diff --git a/lustre/llite/dir.c b/lustre/llite/dir.c index 2e3aaf3..fef415d 100644 --- a/lustre/llite/dir.c +++ b/lustre/llite/dir.c @@ -686,7 +686,7 @@ static struct page *ll_dir_page_locate(struct inode *dir, __u64 *hash, if (*hash > *end || (*end != *start && *hash == *end)) { kunmap(page); lock_page(page); - ll_truncate_complete_page(page); + truncate_complete_page(page->mapping, page); unlock_page(page); page_cache_release(page); page = NULL; @@ -777,7 +777,7 @@ static struct page *ll_get_dir_page_20(struct file *filp, struct inode *dir, CDEBUG(D_INFO, "Stale readpage page %p: %#lx != %#lx\n", page, (unsigned long)lhash, (unsigned long)start); lock_page(page); - ll_truncate_complete_page(page); + truncate_complete_page(page->mapping, page); unlock_page(page); page_cache_release(page); } else { diff --git a/lustre/llite/file.c b/lustre/llite/file.c index 3b2cf2e..e13b1a0 100644 --- a/lustre/llite/file.c +++ b/lustre/llite/file.c @@ -740,7 +740,7 @@ int ll_page_removal_cb(void *data, int discard) LL_CDEBUG_PAGE(D_PAGE, page, "truncating\n"); if (llap) ll_ra_accounting(llap, page->mapping); - ll_truncate_complete_page(page); + truncate_complete_page(page->mapping, page); } EXIT; out: diff --git a/lustre/llite/rw.c b/lustre/llite/rw.c index e8f7761..8a28086 100644 --- a/lustre/llite/rw.c +++ b/lustre/llite/rw.c @@ -621,7 +621,7 @@ static inline int llap_shrink_cache_internal(struct ll_sb_info *sbi, ~CFS_PAGE_MASK); if (!PageDirty(page) && !page_mapped(page)) { ll_ra_accounting(llap, page->mapping); - ll_truncate_complete_page(page); + truncate_complete_page(page->mapping, page); ++count; } else { LL_CDEBUG_PAGE(D_PAGE, page, @@ -2281,7 +2281,7 @@ int ll_readpage(struct file *filp, struct page *page) /* File with no objects - one big hole */ /* We use this just for remove_from_page_cache that is not * exported, we'd make page back up to date. */ - ll_truncate_complete_page(page); + truncate_complete_page(page->mapping, page); clear_page(kmap(page)); kunmap(page); SetPageUptodate(page); -- 1.8.3.1