From patchwork Thu Nov 8 18:44:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Darrick Wong X-Patchwork-Id: 995138 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.b="rOUnUdWe"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 42rXJZ10lQz9s7h for ; Fri, 9 Nov 2018 05:44:46 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727028AbeKIEVc (ORCPT ); Thu, 8 Nov 2018 23:21:32 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:42952 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726751AbeKIEVc (ORCPT ); Thu, 8 Nov 2018 23:21:32 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id wA8IYJf1034308; Thu, 8 Nov 2018 18:44:34 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : mime-version : content-type; s=corp-2018-07-02; bh=EohRYFF1EEv+bz577lmvqO+PvHOkNHvsTTwP/Fj3gUI=; b=rOUnUdWeMmRBcLm+5X1biTFVQ6d8oiPZhvwXP+kCXWD3RGLi6jFcYi0iB4r4dhPWTWjU 6D0aWqqE8bw7zUYIGlE3gaY+uZ27OJfVrrrelHCZs88i2grHq6cUPkWSDGd7xHSzm8cI sVN7ZcvJSwDmbFhe/oYSg24JkD1/26OW5fUGeeFKvYjxESHumjjZ9WpustsKy2j/tQMM 2L1ijYNmfePAyp1L3+3wzx/BLi7JqGKAO3VbmObOcBKUz9ceIlSMd5OzyWFpk5XEhLGC PJPyMK1Y7uQQmZ8mxQZeYS+a/uKi0Xa8ja9JDXHgwGy7TTeqCjOUmRNqidy8O9O0uLyw Vg== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp2120.oracle.com with ESMTP id 2nh4ar347h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 08 Nov 2018 18:44:34 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id wA8IiXF8022460 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 8 Nov 2018 18:44:33 GMT Received: from abhmp0011.oracle.com (abhmp0011.oracle.com [141.146.116.17]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id wA8IiW6Y012447; Thu, 8 Nov 2018 18:44:32 GMT Received: from localhost (/67.169.218.210) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 08 Nov 2018 10:44:32 -0800 Date: Thu, 8 Nov 2018 10:44:31 -0800 From: "Darrick J. Wong" To: "Theodore Ts'o" Cc: linux-ext4 , Elana.Hashman@twosigma.com Subject: [PATCH] e2freefrag: fix free blocks count during live scan Message-ID: <20181108184431.GA27852@magnolia> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.4 (2018-02-28) X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9071 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=2 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1811080157 Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From: Darrick J. Wong In e2freefrag live scan mode, we take the free block count from the ondisk superblock. This leads to screwy histogram percentages: Extent Size Range : Free extents Free Blocks Percent 4M... 8M- : 5 8234 1.05% 64M... 128M- : 2 52279 6.64% 512M... 1024M- : 1 202752 25.74% ...because there could be superblock updates in the journal that haven't yet been checkpointed. The online scan is perfectly capable of tallying the free blocks on its own, so teach it do that and make a more accurate report. Reported-by: Elana Hashman Signed-off-by: Darrick J. Wong --- misc/e2freefrag.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/misc/e2freefrag.c b/misc/e2freefrag.c index 6eb4c736d..f7fede54b 100644 --- a/misc/e2freefrag.c +++ b/misc/e2freefrag.c @@ -163,7 +163,8 @@ static void scan_block_bitmap(ext2_filsys fs, struct chunk_info *info) #if defined(HAVE_EXT2_IOCTLS) && !defined(DEBUGFS) # define FSMAP_EXTENTS 1024 -static int scan_online(ext2_filsys fs, struct chunk_info *info) +static int scan_online(ext2_filsys fs, struct chunk_info *info, + blk64_t *free_blks) { struct fsmap_head *fsmap; struct fsmap *extent; @@ -204,6 +205,7 @@ static int scan_online(ext2_filsys fs, struct chunk_info *info) fsmap->fmh_keys[1].fmr_offset = ULLONG_MAX; fsmap->fmh_keys[1].fmr_flags = UINT_MAX; + *free_blks = 0; /* Fill the extent histogram with live data */ while (1) { ret = ioctl(fd, FS_IOC_GETFSMAP, fsmap); @@ -225,6 +227,7 @@ static int scan_online(ext2_filsys fs, struct chunk_info *info) continue; update_chunk_stats(info, extent->fmr_length / fs->blocksize); + *free_blks += (extent->fmr_length / fs->blocksize); } p = &fsmap->fmh_recs[fsmap->fmh_entries - 1]; @@ -236,13 +239,15 @@ static int scan_online(ext2_filsys fs, struct chunk_info *info) return 1; } #else -# define scan_online(fs, info) (0) +# define scan_online(fs, info, free_blks) (0) #endif /* HAVE_EXT2_IOCTLS */ -static errcode_t scan_offline(ext2_filsys fs, struct chunk_info *info) +static errcode_t scan_offline(ext2_filsys fs, struct chunk_info *info, + blk64_t *free_blks) { errcode_t retval; + *free_blks = ext2fs_free_blocks_count(fs->super); retval = ext2fs_read_block_bitmap(fs); if (retval) return retval; @@ -251,7 +256,7 @@ static errcode_t scan_offline(ext2_filsys fs, struct chunk_info *info) } static errcode_t dump_chunk_info(ext2_filsys fs, struct chunk_info *info, - FILE *f) + FILE *f, blk64_t free_blks) { unsigned long total_chunks; const char *unitp = "KMGTPEZY"; @@ -261,8 +266,8 @@ static errcode_t dump_chunk_info(ext2_filsys fs, struct chunk_info *info, fprintf(f, "Total blocks: %llu\nFree blocks: %llu (%0.1f%%)\n", ext2fs_blocks_count(fs->super), - ext2fs_free_blocks_count(fs->super), - (double)ext2fs_free_blocks_count(fs->super) * 100 / + free_blks, + (double)free_blks * 100 / ext2fs_blocks_count(fs->super)); if (info->chunkbytes) { @@ -306,7 +311,7 @@ static errcode_t dump_chunk_info(ext2_filsys fs, struct chunk_info *info, info->histogram.fc_chunks[i], info->histogram.fc_blocks[i], (double)info->histogram.fc_blocks[i] * 100 / - ext2fs_free_blocks_count(fs->super)); + free_blks); } start = end; if (start == 1<<10) { @@ -330,14 +335,15 @@ static void close_device(char *device_name, ext2_filsys fs) static void collect_info(ext2_filsys fs, struct chunk_info *chunk_info, FILE *f) { unsigned int retval = 0; + blk64_t free_blks = 0; fprintf(f, "Device: %s\n", fs->device_name); fprintf(f, "Blocksize: %u bytes\n", fs->blocksize); init_chunk_info(fs, chunk_info); - if (!scan_online(fs, chunk_info)) { + if (!scan_online(fs, chunk_info, &free_blks)) { init_chunk_info(fs, chunk_info); - retval = scan_offline(fs, chunk_info); + retval = scan_offline(fs, chunk_info, &free_blks); } if (retval) { com_err(fs->device_name, retval, "while reading block bitmap"); @@ -345,7 +351,7 @@ static void collect_info(ext2_filsys fs, struct chunk_info *chunk_info, FILE *f) exit(1); } - retval = dump_chunk_info(fs, chunk_info, f); + retval = dump_chunk_info(fs, chunk_info, f, free_blks); if (retval) { com_err(fs->device_name, retval, "while dumping chunk info"); close_device(fs->device_name, fs);