From patchwork Wed Jun 14 17:23:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tahsin Erdogan X-Patchwork-Id: 9787075 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7472C602D9 for ; Wed, 14 Jun 2017 17:25:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5BE1220242 for ; Wed, 14 Jun 2017 17:25:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5064621E5A; Wed, 14 Jun 2017 17:25:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 43B2920242 for ; Wed, 14 Jun 2017 17:25:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752590AbdFNRXr (ORCPT ); Wed, 14 Jun 2017 13:23:47 -0400 Received: from mail-pg0-f42.google.com ([74.125.83.42]:36084 "EHLO mail-pg0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752496AbdFNRXp (ORCPT ); Wed, 14 Jun 2017 13:23:45 -0400 Received: by mail-pg0-f42.google.com with SMTP id a70so3021224pge.3 for ; Wed, 14 Jun 2017 10:23:45 -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=v91nw+cPTGklk2zVKtTqUuFQSgMXAwJntgzbUICiVQU=; b=XRZUrxnck6Pbx0/gACwRKpz7KnqzVaG7Vg458BQ1NZLrOBLjQYOmH9mPEsMKnozZQg UZL8bgbxD6Xm/R1FRgjOcF5f66yXUtudqm0Tlp86I+6+pcTcrZOdnljcWDeqw23dQL4S +6LtlUxvANbhpFib0KR+ftHu3ANcWrClCsRxnZ34Qf4Rl+N+WGrQet8h2+810cRjbWBB rRmJ1CEAiFm4Sel2gGJgFFrYN6qMdgaCfllSaKytu2FwuH7mO3CqPTdxpli3sque+dBo rP+e6EGxDkffTPkBjecZIuHwRLFAq9JiRf84sa+lTxWD/ScrmeG4ZBc0i9JmlpbSZU8a TKIA== 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=v91nw+cPTGklk2zVKtTqUuFQSgMXAwJntgzbUICiVQU=; b=HnfiXseazlehVzwMkQS2TZROrxNuSfI53naGNGP3vtoUiP+b0iHkBcp2WKlYiWyaaO Af//unrXmZar7iWuUkhhKY4V9nC7qEPeW8d2UUSdpk7Va3fmTnngH+CDujmihFcdM6vl kwrSKSEITC29lPSKvZw2l0+TX5G7iM6Umdm8/3yRhn5Gpygpd3XeaGdl/GGG4klojxGB U1wvPHqRcyuV+rlpw/bA9G2OvJfa98rV5uJxHskQwVUeB25ZX/Z8yaprFVcyESRhibsk T94zZnW6vgVhZvylsqbK2DluCXZ7gBk83lu96qz6RNM+/Di+nHBXXH522UZgdfIdGIvj hU1g== X-Gm-Message-State: AKS2vOwRoxs+8j9uNRo9/AttoCul4Vl06Bm1jHRdU3ZqOLSDe64kj1wQ 4EWW2reiwLb4ZgP5 X-Received: by 10.84.196.129 with SMTP id l1mr1240330pld.109.1497461024425; Wed, 14 Jun 2017 10:23:44 -0700 (PDT) Received: from tahsin1.svl.corp.google.com ([100.123.230.167]) by smtp.gmail.com with ESMTPSA id r5sm1114162pfe.94.2017.06.14.10.23.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 14 Jun 2017 10:23:43 -0700 (PDT) From: Tahsin Erdogan To: "Darrick J . Wong" , Jan Kara , Theodore Ts'o , Andreas Dilger , Dave Kleikamp , Alexander Viro , Mark Fasheh , Joel Becker , Jens Axboe , Deepa Dinamani , Mike Christie , Fabian Frederick , linux-ext4@vger.kernel.org Cc: linux-kernel@vger.kernel.org, jfs-discussion@lists.sourceforge.net, linux-fsdevel@vger.kernel.org, ocfs2-devel@oss.oracle.com, reiserfs-devel@vger.kernel.org, Tahsin Erdogan Subject: [PATCH 30/31] ext4: eliminate xattr entry e_hash recalculation for removes Date: Wed, 14 Jun 2017 10:23:40 -0700 Message-Id: <20170614172340.18720-1-tahsin@google.com> X-Mailer: git-send-email 2.13.1.508.gb3defc5cc-goog Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When an extended attribute block is modified, ext4_xattr_hash_entry() recalculates e_hash for the entry that is pointed by s->here. This is unnecessary if the modification is to remove an entry. Currently, if the removed entry is the last one and there are other entries remaining, hash calculation targets the just erased entry which has been filled with zeroes and effectively does nothing. If the removed entry is not the last one and there are more entries, this time it will recalculate hash on the next entry which is totally unnecessary. Fix these by moving the decision on when to recalculate hash to ext4_xattr_set_entry(). Signed-off-by: Tahsin Erdogan --- fs/ext4/xattr.c | 50 ++++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c index c9579d220a0c..6c6dce2f874e 100644 --- a/fs/ext4/xattr.c +++ b/fs/ext4/xattr.c @@ -77,8 +77,9 @@ static void ext4_xattr_block_cache_insert(struct mb_cache *, static struct buffer_head * ext4_xattr_block_cache_find(struct inode *, struct ext4_xattr_header *, struct mb_cache_entry **); -static void ext4_xattr_rehash(struct ext4_xattr_header *, - struct ext4_xattr_entry *); +static void ext4_xattr_hash_entry(struct ext4_xattr_entry *entry, + void *value_base); +static void ext4_xattr_rehash(struct ext4_xattr_header *); static const struct xattr_handler * const ext4_xattr_handler_map[] = { [EXT4_XATTR_INDEX_USER] = &ext4_xattr_user_handler, @@ -1436,7 +1437,8 @@ static int ext4_xattr_inode_lookup_create(handle_t *handle, struct inode *inode, static int ext4_xattr_set_entry(struct ext4_xattr_info *i, struct ext4_xattr_search *s, - handle_t *handle, struct inode *inode) + handle_t *handle, struct inode *inode, + bool is_block) { struct ext4_xattr_entry *last; struct ext4_xattr_entry *here = s->here; @@ -1500,8 +1502,8 @@ static int ext4_xattr_set_entry(struct ext4_xattr_info *i, * attribute block so that a long value does not occupy the * whole space and prevent futher entries being added. */ - if (ext4_has_feature_ea_inode(inode->i_sb) && new_size && - (s->end - s->base) == i_blocksize(inode) && + if (ext4_has_feature_ea_inode(inode->i_sb) && + new_size && is_block && (min_offs + old_size - new_size) < EXT4_XATTR_BLOCK_RESERVE(inode)) { ret = -ENOSPC; @@ -1631,6 +1633,13 @@ static int ext4_xattr_set_entry(struct ext4_xattr_info *i, } here->e_value_size = cpu_to_le32(i->value_len); } + + if (is_block) { + if (s->not_found || i->value) + ext4_xattr_hash_entry(here, s->base); + ext4_xattr_rehash((struct ext4_xattr_header *)s->base); + } + ret = 0; out: iput(old_ea_inode); @@ -1720,14 +1729,11 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode, mb_cache_entry_delete(ext4_mb_cache, hash, bs->bh->b_blocknr); ea_bdebug(bs->bh, "modifying in-place"); - error = ext4_xattr_set_entry(i, s, handle, inode); - if (!error) { - if (!IS_LAST_ENTRY(s->first)) - ext4_xattr_rehash(header(s->base), - s->here); + error = ext4_xattr_set_entry(i, s, handle, inode, + true /* is_block */); + if (!error) ext4_xattr_block_cache_insert(ext4_mb_cache, bs->bh); - } ext4_xattr_block_csum_set(inode, bs->bh); unlock_buffer(bs->bh); if (error == -EFSCORRUPTED) @@ -1787,7 +1793,7 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode, s->end = s->base + sb->s_blocksize; } - error = ext4_xattr_set_entry(i, s, handle, inode); + error = ext4_xattr_set_entry(i, s, handle, inode, true /* is_block */); if (error == -EFSCORRUPTED) goto bad_block; if (error) @@ -1810,9 +1816,6 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode, } } - if (!IS_LAST_ENTRY(s->first)) - ext4_xattr_rehash(header(s->base), s->here); - inserted: if (!IS_LAST_ENTRY(s->first)) { new_bh = ext4_xattr_block_cache_find(inode, header(s->base), @@ -2045,7 +2048,7 @@ int ext4_xattr_ibody_inline_set(handle_t *handle, struct inode *inode, if (EXT4_I(inode)->i_extra_isize == 0) return -ENOSPC; - error = ext4_xattr_set_entry(i, s, handle, inode); + error = ext4_xattr_set_entry(i, s, handle, inode, false /* is_block */); if (error) { if (error == -ENOSPC && ext4_has_inline_data(inode)) { @@ -2057,7 +2060,8 @@ int ext4_xattr_ibody_inline_set(handle_t *handle, struct inode *inode, error = ext4_xattr_ibody_find(inode, i, is); if (error) return error; - error = ext4_xattr_set_entry(i, s, handle, inode); + error = ext4_xattr_set_entry(i, s, handle, inode, + false /* is_block */); } if (error) return error; @@ -2083,7 +2087,7 @@ static int ext4_xattr_ibody_set(handle_t *handle, struct inode *inode, if (EXT4_I(inode)->i_extra_isize == 0) return -ENOSPC; - error = ext4_xattr_set_entry(i, s, handle, inode); + error = ext4_xattr_set_entry(i, s, handle, inode, false /* is_block */); if (error) return error; header = IHDR(inode, ext4_raw_inode(&is->iloc)); @@ -2909,8 +2913,8 @@ ext4_xattr_block_cache_find(struct inode *inode, * * Compute the hash of an extended attribute. */ -static inline void ext4_xattr_hash_entry(struct ext4_xattr_header *header, - struct ext4_xattr_entry *entry) +static void ext4_xattr_hash_entry(struct ext4_xattr_entry *entry, + void *value_base) { __u32 hash = 0; char *name = entry->e_name; @@ -2923,7 +2927,7 @@ static inline void ext4_xattr_hash_entry(struct ext4_xattr_header *header, } if (!entry->e_value_inum && entry->e_value_size) { - __le32 *value = (__le32 *)((char *)header + + __le32 *value = (__le32 *)((char *)value_base + le16_to_cpu(entry->e_value_offs)); for (n = (le32_to_cpu(entry->e_value_size) + EXT4_XATTR_ROUND) >> EXT4_XATTR_PAD_BITS; n; n--) { @@ -2945,13 +2949,11 @@ static inline void ext4_xattr_hash_entry(struct ext4_xattr_header *header, * * Re-compute the extended attribute hash value after an entry has changed. */ -static void ext4_xattr_rehash(struct ext4_xattr_header *header, - struct ext4_xattr_entry *entry) +static void ext4_xattr_rehash(struct ext4_xattr_header *header) { struct ext4_xattr_entry *here; __u32 hash = 0; - ext4_xattr_hash_entry(header, entry); here = ENTRY(header+1); while (!IS_LAST_ENTRY(here)) { if (!here->e_hash) {