From patchwork Wed Apr 3 17:19:31 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Whitney X-Patchwork-Id: 233560 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 91FF12C00B2 for ; Thu, 4 Apr 2013 04:19:38 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1762554Ab3DCRTh (ORCPT ); Wed, 3 Apr 2013 13:19:37 -0400 Received: from mail-ve0-f181.google.com ([209.85.128.181]:50063 "EHLO mail-ve0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1761722Ab3DCRTh (ORCPT ); Wed, 3 Apr 2013 13:19:37 -0400 Received: by mail-ve0-f181.google.com with SMTP id pa12so1903928veb.12 for ; Wed, 03 Apr 2013 10:19:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:date:from:to:cc:subject:message-id:mime-version :content-type:content-disposition:user-agent; bh=XeuFQ5J8EZ7RD9L4ZVOYZpEgDCRL44l9PaTiK6Q0KyY=; b=KcX3JRwrHxKg91BxQ4moJlmNXfQy2LoWJYuWpVMsRiGpqZmp3DToWr4fKPHA3gj5LG D/mXRUoJYQaxOvbvWb8LVU16LM37+fmsDh+8+k1tI8AfvfEdoZKY9iCYA5fQPMCLzrNX i/53Ytzq4djDcA8sAjFbxsmZ9krhbvpgkap0PnF7d2QCZHZS4PvasoUrjtKI+x+uzpoX oC0D0PW2/1GUfxi+hsyZPuAjrtlMP065nkHUBfSPpilAK9+lJ63P9UTR7Jg4BuxeaI2l j7Ws8xLTtu3It0DeWhK6JmI8WiflDZq1vmRvzchePWC1wGWqwQ5UNEasBykrt0IplrJ8 YS9g== X-Received: by 10.52.111.130 with SMTP id ii2mr1655350vdb.111.1365009576183; Wed, 03 Apr 2013 10:19:36 -0700 (PDT) Received: from wallace (c-75-68-62-236.hsd1.nh.comcast.net. [75.68.62.236]) by mx.google.com with ESMTPS id d13sm6900291vdj.8.2013.04.03.10.19.34 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 03 Apr 2013 10:19:35 -0700 (PDT) Date: Wed, 3 Apr 2013 13:19:31 -0400 From: Eric Whitney To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu Subject: [PATCH] ext4: fix free space estimate in ext4_nonda_switch() Message-ID: <20130403171931.GC3006@wallace> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Values stored in s_freeclusters_counter and s_dirtyclusters_counter are both in cluster units. Remove the cluster to block conversion applied to s_freeclusters_counter causing an inflated estimate of free space because s_dirtyclusters_counter is not similarly converted. Rename free_blocks and dirty_blocks to better reflect the units these variables contain to avoid future confusion. This fix corrects ENOSPC failures for xfstests 127 and 231 on bigalloc file systems. Signed-off-by: Eric Whitney --- fs/ext4/inode.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index b3a5213..5f5cc40 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -2661,7 +2661,7 @@ out_writepages: static int ext4_nonda_switch(struct super_block *sb) { - s64 free_blocks, dirty_blocks; + s64 free_clusters, dirty_clusters; struct ext4_sb_info *sbi = EXT4_SB(sb); /* @@ -2672,17 +2672,18 @@ static int ext4_nonda_switch(struct super_block *sb) * Delalloc need an accurate free block accounting. So switch * to non delalloc when we are near to error range. */ - free_blocks = EXT4_C2B(sbi, - percpu_counter_read_positive(&sbi->s_freeclusters_counter)); - dirty_blocks = percpu_counter_read_positive(&sbi->s_dirtyclusters_counter); + free_clusters = + percpu_counter_read_positive(&sbi->s_freeclusters_counter); + dirty_clusters = + percpu_counter_read_positive(&sbi->s_dirtyclusters_counter); /* * Start pushing delalloc when 1/2 of free blocks are dirty. */ - if (dirty_blocks && (free_blocks < 2 * dirty_blocks)) + if (dirty_clusters && (free_clusters < 2 * dirty_clusters)) try_to_writeback_inodes_sb(sb, WB_REASON_FS_FREE_SPACE); - if (2 * free_blocks < 3 * dirty_blocks || - free_blocks < (dirty_blocks + EXT4_FREECLUSTERS_WATERMARK)) { + if (2 * free_clusters < 3 * dirty_clusters || + free_clusters < (dirty_clusters + EXT4_FREECLUSTERS_WATERMARK)) { /* * free block count is less than 150% of dirty blocks * or free blocks is less than watermark