From patchwork Fri Oct 26 13:23:41 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zheng Liu X-Patchwork-Id: 194472 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 0C18E2C008A for ; Sat, 27 Oct 2012 00:13:01 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756395Ab2JZNM7 (ORCPT ); Fri, 26 Oct 2012 09:12:59 -0400 Received: from mail-pa0-f46.google.com ([209.85.220.46]:52319 "EHLO mail-pa0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755066Ab2JZNM7 (ORCPT ); Fri, 26 Oct 2012 09:12:59 -0400 Received: by mail-pa0-f46.google.com with SMTP id hz1so1922583pad.19 for ; Fri, 26 Oct 2012 06:12:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=xT4bp/xyZtgtxIrcBKhCfgcAB+JeJXcmdbxE59zf/po=; b=NYmcbzNG66M1uIPPr6TR2+iXNimCIKHkjhSXix+a6ur2OLZE9u23yGr4ZUN7xv7yV6 mEKWQ888SRJgft8JGoTRAP9vgaKXdNyrur9PNeulhon1I1wDnK98tOnH1pZzwSOBoCLa i0Sjtsv32edIMER9dwavhLMKlCxraEv4RerfDo9/VuJRyrrisQT1EiCcoau0JZf/len8 IkYypBMUaUmc8Q/WTFKt9sv8yNKYnP1bs1K7eI02S6Cuq+o6b6RNQDIryNaiAE75yefx xyI8m7jgK6maD9CwVrYm3AaP2dNbUfeSACbMAYZqKYvIwwsCQIlU7V6yRVjeWGev9zro yzqA== Received: by 10.68.135.168 with SMTP id pt8mr70729010pbb.24.1351257178913; Fri, 26 Oct 2012 06:12:58 -0700 (PDT) Received: from lz-desktop.hz.ali.com ([182.92.247.2]) by mx.google.com with ESMTPS id a10sm1000164paw.17.2012.10.26.06.12.55 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 26 Oct 2012 06:12:58 -0700 (PDT) From: Zheng Liu To: linux-ext4@vger.kernel.org, jeff.liu@oracle.com Cc: tytso@mit.edu, hughd@google.com, xiaoqiangnk@gmail.com, achender@linux.vnet.ibm.com, lczerner@redhat.com, Zheng Liu Subject: [PATCH 4/8 v3] ext4: let ext4 maintain extent status tree Date: Fri, 26 Oct 2012 21:23:41 +0800 Message-Id: <1351257825-3701-5-git-send-email-wenqing.lz@taobao.com> X-Mailer: git-send-email 1.7.12.rc2.18.g61b472e In-Reply-To: <1351257825-3701-1-git-send-email-wenqing.lz@taobao.com> References: <1351257825-3701-1-git-send-email-wenqing.lz@taobao.com> Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From: Zheng Liu This patch lets ext4 maintain extent status tree. Currently it only tracks delay extent status in extent status tree. When a delay allocation is issued, the related delay extent will be inserted into extent status tree. When a delay extent is written out or invalidated, it will be removed from this tree. CC: "Theodore Ts'o" Signed-off-by: Yongqiang Yang Signed-off-by: Allison Henderson Signed-off-by: Zheng Liu --- v3 <- v2: - remove delay extent in ext4_da_page_release_reservation() and ext4_da_block_invalidatepages(). fs/ext4/extents.c | 4 ++++ fs/ext4/indirect.c | 1 + fs/ext4/inode.c | 38 +++++++++++++++++++++++++++++++++++--- fs/ext4/super.c | 12 +++++++++++- 4 files changed, 51 insertions(+), 4 deletions(-) diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index 7011ac9..0e1a925 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -4344,6 +4344,8 @@ void ext4_ext_truncate(struct inode *inode) last_block = (inode->i_size + sb->s_blocksize - 1) >> EXT4_BLOCK_SIZE_BITS(sb); + err = ext4_es_remove_extent(inode, last_block, + EXT_MAX_BLOCKS - last_block); err = ext4_ext_remove_space(inode, last_block, EXT_MAX_BLOCKS - 1); /* In a multi-transaction truncate, we only make the final @@ -4971,6 +4973,8 @@ int ext4_ext_punch_hole(struct file *file, loff_t offset, loff_t length) ext4_ext_invalidate_cache(inode); ext4_discard_preallocations(inode); + err = ext4_es_remove_extent(inode, first_block, + stop_block - first_block); err = ext4_ext_remove_space(inode, first_block, stop_block - 1); ext4_ext_invalidate_cache(inode); diff --git a/fs/ext4/indirect.c b/fs/ext4/indirect.c index 792e388..9a6c2b1 100644 --- a/fs/ext4/indirect.c +++ b/fs/ext4/indirect.c @@ -1412,6 +1412,7 @@ void ext4_ind_truncate(struct inode *inode) down_write(&ei->i_data_sem); ext4_discard_preallocations(inode); + ext4_es_remove_extent(inode, last_block, EXT_MAX_BLOCKS - last_block); /* * The orphan list entry will now protect us from any crash which diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index b3c243b..e4da45d 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -574,7 +574,16 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode, up_read((&EXT4_I(inode)->i_data_sem)); if (retval > 0 && map->m_flags & EXT4_MAP_MAPPED) { - int ret = check_block_validity(inode, map); + int ret; + if (flags & EXT4_GET_BLOCKS_DELALLOC_RESERVE) { + /* delayed alloc may be allocated by fallocate and + * coverted to initialized by directIO. + * we need to handle delayed extent here. + */ + down_write((&EXT4_I(inode)->i_data_sem)); + goto delayed_mapped; + } + ret = check_block_validity(inode, map); if (ret != 0) return ret; } @@ -656,8 +665,16 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode, * set the BH_Da_Mapped bit on them. Its important to do this * under the protection of i_data_sem. */ - if (retval > 0 && map->m_flags & EXT4_MAP_MAPPED) + if (retval > 0 && map->m_flags & EXT4_MAP_MAPPED) { + int ret; set_buffers_da_mapped(inode, map); +delayed_mapped: + /* delayed allocation blocks has been allocated */ + ret = ext4_es_remove_extent(inode, map->m_lblk, + map->m_len); + if (ret < 0) + retval = ret; + } } up_write((&EXT4_I(inode)->i_data_sem)); @@ -1301,6 +1318,7 @@ static void ext4_da_page_release_reservation(struct page *page, struct inode *inode = page->mapping->host; struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); int num_clusters; + ext4_fsblk_t lblk; head = page_buffers(page); bh = head; @@ -1315,11 +1333,15 @@ static void ext4_da_page_release_reservation(struct page *page, curr_off = next_off; } while ((bh = bh->b_this_page) != head); + if (to_release) { + lblk = page->index << (PAGE_CACHE_SHIFT - inode->i_blkbits); + ext4_es_remove_extent(inode, lblk, to_release); + } + /* If we have released all the blocks belonging to a cluster, then we * need to release the reserved space for that cluster. */ num_clusters = EXT4_NUM_B2C(sbi, to_release); while (num_clusters > 0) { - ext4_fsblk_t lblk; lblk = (page->index << (PAGE_CACHE_SHIFT - inode->i_blkbits)) + ((num_clusters - 1) << sbi->s_cluster_bits); if (sbi->s_cluster_ratio == 1 || @@ -1500,9 +1522,15 @@ static void ext4_da_block_invalidatepages(struct mpage_da_data *mpd) struct pagevec pvec; struct inode *inode = mpd->inode; struct address_space *mapping = inode->i_mapping; + ext4_lblk_t start, last; index = mpd->first_page; end = mpd->next_page - 1; + + start = index << (PAGE_CACHE_SHIFT - inode->i_blkbits); + last = end << (PAGE_CACHE_SHIFT - inode->i_blkbits); + ext4_es_remove_extent(inode, start, last - start + 1); + while (index <= end) { nr_pages = pagevec_lookup(&pvec, mapping, index, PAGEVEC_SIZE); if (nr_pages == 0) @@ -1814,6 +1842,10 @@ static int ext4_da_map_blocks(struct inode *inode, sector_t iblock, goto out_unlock; } + retval = ext4_es_insert_extent(inode, map->m_lblk, map->m_len); + if (retval) + goto out_unlock; + /* Clear EXT4_MAP_FROM_CLUSTER flag since its purpose is served * and it should not appear on the bh->b_state. */ diff --git a/fs/ext4/super.c b/fs/ext4/super.c index e0c824b..6d4a712 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -50,6 +50,7 @@ #include "xattr.h" #include "acl.h" #include "mballoc.h" +#include "ext4_extents.h" #define CREATE_TRACE_POINTS #include @@ -1033,6 +1034,7 @@ void ext4_clear_inode(struct inode *inode) clear_inode(inode); dquot_drop(inode); ext4_discard_preallocations(inode); + ext4_es_remove_extent(inode, 0, EXT_MAX_BLOCKS); if (EXT4_I(inode)->jinode) { jbd2_journal_release_jbd_inode(EXT4_JOURNAL(inode), EXT4_I(inode)->jinode); @@ -5291,9 +5293,14 @@ static int __init ext4_init_fs(void) init_waitqueue_head(&ext4__ioend_wq[i]); } - err = ext4_init_pageio(); + err = ext4_init_es(); if (err) return err; + + err = ext4_init_pageio(); + if (err) + goto out7; + err = ext4_init_system_zone(); if (err) goto out6; @@ -5343,6 +5350,9 @@ out5: ext4_exit_system_zone(); out6: ext4_exit_pageio(); +out7: + ext4_exit_es(); + return err; }