ext4: don't lock the next page in write_cache_pages if not needed
authorTheodore Ts'o <tytso@mit.edu>
Sat, 26 Feb 2011 19:09:14 +0000 (14:09 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Sat, 26 Feb 2011 19:09:14 +0000 (14:09 -0500)
If we have accumulated a contiguous region of memory to be written
out, and the next page can added to this region, don't bother locking
(and then unlocking the page) before writing out the memory.  In the
unlikely event that the next page was being written back by some other
CPU, we can also skip waiting that page to finish writeback.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
fs/ext4/inode.c

index 617c9cbba1828c41650cdc92c8be94d6e6d093b3..c2e6af33823414341c8e2f13e807ce648f72ebe3 100644 (file)
@@ -2761,6 +2761,16 @@ static int write_cache_pages_da(struct address_space *mapping,
 
                        *done_index = page->index + 1;
 
+                       /*
+                        * If we can't merge this page, and we have
+                        * accumulated an contiguous region, write it
+                        */
+                       if ((mpd->next_page != page->index) &&
+                           (mpd->next_page != mpd->first_page)) {
+                               mpage_da_map_and_submit(mpd);
+                               goto ret_extent_tail;
+                       }
+
                        lock_page(page);
 
                        /*
@@ -2784,24 +2794,7 @@ static int write_cache_pages_da(struct address_space *mapping,
 
                        BUG_ON(PageWriteback(page));
 
-                       /*
-                        * Can we merge this page to current extent?
-                        */
                        if (mpd->next_page != page->index) {
-                               /*
-                                * Nope, we can't. So, we map
-                                * non-allocated blocks and start IO
-                                * on them
-                                */
-                               if (mpd->next_page != mpd->first_page) {
-                                       mpage_da_map_and_submit(mpd);
-                                       /*
-                                        * skip rest of the page in the page_vec
-                                        */
-                                       unlock_page(page);
-                                       goto ret_extent_tail;
-                               }
-
                                /*
                                 * Start next extent of pages and blocks
                                 */