From patchwork Sat Jul 15 00:25:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tahsin Erdogan X-Patchwork-Id: 788830 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 3x8VjB4mcFz9s0Z for ; Sat, 15 Jul 2017 10:26:22 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="UuBhsWlN"; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751192AbdGOA0J (ORCPT ); Fri, 14 Jul 2017 20:26:09 -0400 Received: from mail-pg0-f54.google.com ([74.125.83.54]:36736 "EHLO mail-pg0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751035AbdGOA0H (ORCPT ); Fri, 14 Jul 2017 20:26:07 -0400 Received: by mail-pg0-f54.google.com with SMTP id 123so2054671pgd.3 for ; Fri, 14 Jul 2017 17:26:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=r8I34XpHDO5T6BrqHdTKuKrT9+wlvAFqBBSVh2wlORA=; b=UuBhsWlNgV92vvHPFWUgeDdUyl7dxYVslyYSgBRBmfeHriIEjkK0opYK+8xTkfEokR NTepiotfkuKnGAfTCQFlQzTS+MlsRTckUR7WNJVay44q/1wEmsTY9QjlOZSysR7FQubo RZnKNrWxsD/OWboPROm7/RNcWSuc6b389i+XC756gcbtFokDGzdviq/2N5nTr7Mr7xf5 g1jR3g9zqCuN2fhjIr3yqX/4I4/p37Z4uNKQGkPRmS+SWRxBclFwgBoEGK00zx13mQww axMIotbytnF7XTx1S2iMguS74nKHdAEMllBFpp5bsYPFLbYfR/7zXB01eSbbZQpwymOz GgbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=r8I34XpHDO5T6BrqHdTKuKrT9+wlvAFqBBSVh2wlORA=; b=G2LKN9eEHu6am1HjqgcT6RSBRducEEXWrjF7dwQoxx2/UXtyu8aaDrzbRNjjdTspY1 +W6c1IFEgU1c/8I6kiJY9Mj0msOPxmKDBJn7dB59Q7AwKBMnAv0R7VKvnEsdbj3k2+2+ 0ruQuZIbsIDOVEq5sXOxmxf88uQ3YlJuTdchcXOUY+FdERrSSn0w7puIPdVbmTBMvcJY 0tX1nZb22OvF+Xz0U/OPewPvFwBY0l0W/CaCwedKqI1yY5P64Pl0clrpwXlijytMoKpn xg4nbZXwpAEPhg55f6G6Dn89vcMaW82KbDNysvcWwN2X9SDU1y+cLCSFFBruD7bWykcj Ze3Q== X-Gm-Message-State: AIVw113V8cyezxw165wgzh4Gkv+dZwsSZmim69PQ/CMQyXs17QoQbvCo +OQy3C3QqnBYy4JA X-Received: by 10.99.97.4 with SMTP id v4mr17687089pgb.254.1500078367195; Fri, 14 Jul 2017 17:26:07 -0700 (PDT) Received: from tahsin1.svl.corp.google.com ([100.123.230.167]) by smtp.gmail.com with ESMTPSA id p28sm23974867pfl.102.2017.07.14.17.26.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 14 Jul 2017 17:26:06 -0700 (PDT) From: Tahsin Erdogan To: Theodore Ts'o , Andreas Dilger , linux-ext4@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Tahsin Erdogan Subject: [PATCH] ext4: inplace xattr block update fails to deduplicate blocks Date: Fri, 14 Jul 2017 17:25:29 -0700 Message-Id: <20170715002529.31045-1-tahsin@google.com> X-Mailer: git-send-email 2.13.2.932.g7449e964c-goog Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org When an xattr block has a single reference, block is updated inplace and it is reinserted to the cache. Later, a cache lookup is performed to see whether an existing block has the same contents. This cache lookup will most of the time return the just inserted entry so deduplication is not achieved. Running the following test script will produce two xattr blocks which can be observed in "File ACL: " line of debugfs output: mke2fs -b 1024 -I 128 -F -O extent /dev/sdb 1G mount /dev/sdb /mnt/sdb touch /mnt/sdb/{x,y} setfattr -n user.1 -v aaa /mnt/sdb/x setfattr -n user.2 -v bbb /mnt/sdb/x setfattr -n user.1 -v aaa /mnt/sdb/y setfattr -n user.2 -v bbb /mnt/sdb/y debugfs -R 'stat x' /dev/sdb | cat debugfs -R 'stat y' /dev/sdb | cat This patch defers the reinsertion to the cache so that we can locate other blocks with the same contents. Signed-off-by: Tahsin Erdogan Reviewed-by: Andreas Dilger --- fs/ext4/xattr.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c index cff4f41ced61..ad4ea1cf685f 100644 --- a/fs/ext4/xattr.c +++ b/fs/ext4/xattr.c @@ -1815,9 +1815,6 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode, ea_bdebug(bs->bh, "modifying in-place"); error = ext4_xattr_set_entry(i, s, handle, inode, true /* is_block */); - if (!error) - ext4_xattr_block_cache_insert(ea_block_cache, - bs->bh); ext4_xattr_block_csum_set(inode, bs->bh); unlock_buffer(bs->bh); if (error == -EFSCORRUPTED) @@ -1973,6 +1970,7 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode, } else if (bs->bh && s->base == bs->bh->b_data) { /* We were modifying this block in-place. */ ea_bdebug(bs->bh, "keeping this block"); + ext4_xattr_block_cache_insert(ea_block_cache, bs->bh); new_bh = bs->bh; get_bh(new_bh); } else {