lkml.org 
[lkml]   [2013]   [Jan]   [31]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 3/6] fs: Provide function to take mapping lock in buffered write path
Date
Add a flag to grab_cache_page_write_begin() which makes the function grab
mapping range lock while creating the page in page cache. Callers that don't
need special lock ordering for the mapping range lock (e.g. xfs) can use
this flag.

Signed-off-by: Jan Kara <jack@suse.cz>
---
include/linux/fs.h | 2 ++
mm/filemap.c | 7 +++++++
2 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/include/linux/fs.h b/include/linux/fs.h
index 2027d25..1e0a1e4 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -281,6 +281,8 @@ enum positive_aop_returns {
#define AOP_FLAG_NOFS 0x0004 /* used by filesystem to direct
* helper code (eg buffer layer)
* to clear GFP_FS from alloc */
+#define AOP_FLAG_LOCK_MAPPING 0x0008 /* Lock mapping range where
+ * page is create */

/*
* oh the beauties of C type declarations.
diff --git a/mm/filemap.c b/mm/filemap.c
index 4826cb4..f4a9e9a 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -2266,6 +2266,7 @@ struct page *grab_cache_page_write_begin(struct address_space *mapping,
gfp_t gfp_mask;
struct page *page;
gfp_t gfp_notmask = 0;
+ struct range_lock mapping_lock;

gfp_mask = mapping_gfp_mask(mapping);
if (mapping_cap_account_dirty(mapping))
@@ -2280,8 +2281,14 @@ repeat:
page = __page_cache_alloc(gfp_mask & ~gfp_notmask);
if (!page)
return NULL;
+ if (flags & AOP_FLAG_LOCK_MAPPING) {
+ range_lock_init(&mapping_lock, index, index);
+ range_lock(&mapping->mapping_lock, &mapping_lock);
+ }
status = add_to_page_cache_lru(page, mapping, index,
GFP_KERNEL & ~gfp_notmask);
+ if (flags & AOP_FLAG_LOCK_MAPPING)
+ range_unlock(&mapping->mapping_lock, &mapping_lock);
if (unlikely(status)) {
page_cache_release(page);
if (status == -EEXIST)
--
1.7.1


\
 
 \ /
  Last update: 2013-01-31 23:42    [W:0.234 / U:0.156 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site