linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jan Kara <jack@suse.cz>
To: Ted Tso <tytso@mit.edu>
Cc: Andreas Gruenbacher <agruenba@redhat.com>,
	linux-ext4@vger.kernel.org, Jan Kara <jack@suse.cz>
Subject: [PATCH 10/11] ext4: Shortcut setting of xattr to the same value
Date: Mon, 22 Feb 2016 08:48:20 +0100	[thread overview]
Message-ID: <1456127301-7702-11-git-send-email-jack@suse.cz> (raw)
In-Reply-To: <1456127301-7702-1-git-send-email-jack@suse.cz>

When someone tried to set xattr to the same value (i.e., not changing
anything) we did all the work of removing original xattr, possibly
breaking references to shared xattr block, inserting new xattr, and
merging xattr blocks again. Since this is not so rare operation and it
is relatively cheap for us to detect this case, check for this and
shortcut xattr setting in that case.

Signed-off-by: Jan Kara <jack@suse.cz>
---
 fs/ext4/xattr.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
index c6af8a7a436a..b661ae8332e3 100644
--- a/fs/ext4/xattr.c
+++ b/fs/ext4/xattr.c
@@ -1096,6 +1096,17 @@ static int ext4_xattr_ibody_set(handle_t *handle, struct inode *inode,
 	return 0;
 }
 
+static int ext4_xattr_value_same(struct ext4_xattr_search *s,
+				 struct ext4_xattr_info *i)
+{
+	void *value;
+
+	if (le32_to_cpu(s->here->e_value_size) != i->value_len)
+		return 0;
+	value = ((void *)s->base) + le16_to_cpu(s->here->e_value_offs);
+	return !memcmp(value, i->value, i->value_len);
+}
+
 /*
  * ext4_xattr_set_handle()
  *
@@ -1172,6 +1183,13 @@ ext4_xattr_set_handle(handle_t *handle, struct inode *inode, int name_index,
 		else if (!bs.s.not_found)
 			error = ext4_xattr_block_set(handle, inode, &i, &bs);
 	} else {
+		error = 0;
+		/* Xattr value did not change? Save us some work and bail out */
+		if (!is.s.not_found && ext4_xattr_value_same(&is.s, &i))
+			goto cleanup;
+		if (!bs.s.not_found && ext4_xattr_value_same(&bs.s, &i))
+			goto cleanup;
+
 		error = ext4_xattr_ibody_set(handle, inode, &i, &is);
 		if (!error && !bs.s.not_found) {
 			i.value = NULL;
-- 
2.6.2


  parent reply	other threads:[~2016-02-22  7:48 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-22  7:48 [PATCH 0/11 v3] ext[24]: MBCache rewrite Jan Kara
2016-02-22  7:48 ` [PATCH 01/11] mbcache2: Reimplement mbcache Jan Kara
2016-02-22  7:48 ` [PATCH 02/11] ext4: Convert to mbcache2 Jan Kara
2016-02-22  7:48 ` [PATCH 03/11] ext2: " Jan Kara
2016-02-22  7:48 ` [PATCH 04/11] mbcache: Remove Jan Kara
2016-02-22  7:48 ` [PATCH 05/11] mbcache2: Limit cache size Jan Kara
2016-02-22  7:48 ` [PATCH 06/11] mbcache2: Use referenced bit instead of LRU Jan Kara
2016-02-22  7:48 ` [PATCH 07/11] mbcache2: Rename to mbcache Jan Kara
2016-02-22  7:48 ` [PATCH 08/11] ext4: Kill ext4_mballoc_ready Jan Kara
2016-02-22  7:48 ` [PATCH 09/11] mbcache: Get rid of _e_hash_list_head Jan Kara
2016-02-22  7:48 ` Jan Kara [this message]
2016-02-22  7:48 ` [PATCH 11/11] mbcache: Add reusable flag to cache entries Jan Kara
2016-02-22 16:31 ` [PATCH 0/11 v3] ext[24]: MBCache rewrite Theodore Ts'o
2016-02-22 18:45   ` Jan Kara

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1456127301-7702-11-git-send-email-jack@suse.cz \
    --to=jack@suse.cz \
    --cc=agruenba@redhat.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=tytso@mit.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).