linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Erez Zadok <ezk@cs.sunysb.edu>
To: akpm@linux-foundation.org
Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	viro@zeniv.linux.org.uk, hch@infradead.org, miklos@szeredi.hu,
	Hugh Dickins <hugh@veritas.com>, Erez Zadok <ezk@cs.sunysb.edu>,
	Michael Halcrow <mhalcrow@us.ibm.com>, <hooanon05@yahoo.co.jp>,
	Christoph Hellwig <hch@lst.de>,
	Andrew Morton <akpm@linux-foundation.org>
Subject: [PATCH 01/19] LTP's iogen01 doio tests used to hang nicely on 32-bit SMP when /tmp was a
Date: Tue, 29 Jul 2008 22:43:31 -0400	[thread overview]
Message-ID: <12173858301951-git-send-email-ezk@cs.sunysb.edu> (raw)
In-Reply-To: <12173858291233-git-send-email-ezk@cs.sunysb.edu>

From: Hugh Dickins <hugh@veritas.com>

But akpm was dissatisfied with the resulting patch: its lack of
commentary, the #ifs, the nesting around i_size_read, the lack of
attention to i_blocks.  I promised to redo it with the general
spin_lock_32bit() he proposed; but disliked the result, partly because
"32bit" obscures the real constraints, which are best commented within
fsstack_copy_inode_size itself.

This version adds those comments, and uses sizeof comparisons which the
compiler can optimize out, instead of CONFIG_SMP, CONFIG_LSF.
BITS_PER_LONG.

Signed-off-by: Hugh Dickins <hugh@veritas.com>
Cc: Erez Zadok <ezk@cs.sunysb.edu>
Cc: Michael Halcrow <mhalcrow@us.ibm.com>
Cc: <hooanon05@yahoo.co.jp>
Cc: Christoph Hellwig <hch@lst.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Erez Zadok <ezk@cs.sunysb.edu>
---
 fs/stack.c               |   58 ++++++++++++++++++++++++++++++++++++++-------
 include/linux/fs_stack.h |    3 +-
 2 files changed, 50 insertions(+), 11 deletions(-)

diff --git a/fs/stack.c b/fs/stack.c
index 4336f2b..a66ff6c 100644
--- a/fs/stack.c
+++ b/fs/stack.c
@@ -19,16 +19,56 @@
  * This function cannot be inlined since i_size_{read,write} is rather
  * heavy-weight on 32-bit systems
  */
-void fsstack_copy_inode_size(struct inode *dst, const struct inode *src)
+void fsstack_copy_inode_size(struct inode *dst, struct inode *src)
 {
-#if BITS_PER_LONG == 32 && defined(CONFIG_SMP)
-	spin_lock(&dst->i_lock);
-#endif
-	i_size_write(dst, i_size_read(src));
-	dst->i_blocks = src->i_blocks;
-#if BITS_PER_LONG == 32 && defined(CONFIG_SMP)
-	spin_unlock(&dst->i_lock);
-#endif
+	loff_t i_size;
+	blkcnt_t i_blocks;
+
+	/*
+	 * i_size_read() includes its own seqlocking and protection from
+	 * preemption (see include/linux/fs.h): we need nothing extra for
+	 * that here, and prefer to avoid nesting locks than attempt to
+	 * keep i_size and i_blocks in synch together.
+	 */
+	i_size = i_size_read(src);
+
+	/*
+	 * But if CONFIG_LSF (on 32-bit), we ought to make an effort to keep
+	 * the two halves of i_blocks in synch despite SMP or PREEMPT - though
+	 * stat's generic_fillattr() doesn't bother, and we won't be applying
+	 * quotas (where i_blocks does become important) at the upper level.
+	 *
+	 * We don't actually know what locking is used at the lower level; but
+	 * if it's a filesystem that supports quotas, it will be using i_lock
+	 * as in inode_add_bytes().  tmpfs uses other locking, and its 32-bit
+	 * is (just) able to exceed 2TB i_size with the aid of holes; but its
+	 * i_blocks cannot carry into the upper long without almost 2TB swap -
+	 * let's ignore that case.
+	 */
+	if (sizeof(i_blocks) > sizeof(long))
+		spin_lock(&src->i_lock);
+	i_blocks = src->i_blocks;
+	if (sizeof(i_blocks) > sizeof(long))
+		spin_unlock(&src->i_lock);
+
+	/*
+	 * If CONFIG_SMP on 32-bit, it's vital for fsstack_copy_inode_size()
+	 * to hold some lock around i_size_write(), otherwise i_size_read()
+	 * may spin forever (see include/linux/fs.h).  We don't necessarily
+	 * hold i_mutex when this is called, so take i_lock for that case.
+	 *
+	 * And if CONFIG_LSF (on 32-bit), continue our effort to keep the
+	 * two halves of i_blocks in synch despite SMP or PREEMPT: use i_lock
+	 * for that case too, and do both at once by combining the tests.
+	 *
+	 * There is none of this locking overhead in the 64-bit case.
+	 */
+	if (sizeof(i_size) > sizeof(long) || sizeof(i_blocks) > sizeof(long))
+		spin_lock(&dst->i_lock);
+	i_size_write(dst, i_size);
+	dst->i_blocks = i_blocks;
+	if (sizeof(i_size) > sizeof(long) || sizeof(i_blocks) > sizeof(long))
+		spin_unlock(&dst->i_lock);
 }
 EXPORT_SYMBOL_GPL(fsstack_copy_inode_size);
 
diff --git a/include/linux/fs_stack.h b/include/linux/fs_stack.h
index 6b52faf..6615a52 100644
--- a/include/linux/fs_stack.h
+++ b/include/linux/fs_stack.h
@@ -21,8 +21,7 @@
 
 /* externs for fs/stack.c */
 extern void fsstack_copy_attr_all(struct inode *dest, const struct inode *src);
-extern void fsstack_copy_inode_size(struct inode *dst,
-				    const struct inode *src);
+extern void fsstack_copy_inode_size(struct inode *dst, struct inode *src);
 
 /* inlines */
 static inline void fsstack_copy_attr_atime(struct inode *dest,
-- 
1.5.2.2

  reply	other threads:[~2008-07-30  2:43 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-30  2:43 [GIT PULL -mm] 00/19 fsstack+Unionfs updates/fixes/cleanups Erez Zadok
2008-07-30  2:43 ` Erez Zadok [this message]
2008-07-30  2:43 ` [PATCH 02/19] Unionfs: simplify the macros used to get/set the dentry start/end branches Erez Zadok
2008-07-30  2:43 ` [PATCH 03/19] Unionfs: move a rename helper closer to rename code Erez Zadok
2008-07-30  2:43 ` [PATCH 04/19] Unionfs: create and consolidate helpers to iput lower objects Erez Zadok
2008-07-30  2:43 ` [PATCH 05/19] Unionfs: create and consolidate helpers to path-put " Erez Zadok
2008-07-30  2:43 ` [PATCH 06/19] Unionfs: simplify stale-inode detection code Erez Zadok
2008-07-30  2:43 ` [PATCH 07/19] Unionfs: overhaul whiteout code Erez Zadok
2008-07-30  2:43 ` [PATCH 08/19] Unionfs: lookup overhaul using vfs_path_lookup Erez Zadok
2008-07-30  2:43 ` [PATCH 09/19] Unionfs: free lower paths array when destroying dentry's private data Erez Zadok
2008-07-30  2:43 ` [PATCH 10/19] Unionfs: cache coherency fixes Erez Zadok
2008-07-30  2:43 ` [PATCH 11/19] Unionfs: remove old lookup code Erez Zadok
2008-07-30  2:43 ` [PATCH 12/19] Unionfs: update maintainers Erez Zadok
2008-07-30  2:43 ` [PATCH 13/19] Unionfs: update copyrights Erez Zadok
2008-07-30  2:43 ` [PATCH 14/19] Unionfs: minor checkpatch fixes Erez Zadok
2008-07-30  2:43 ` [PATCH 15/19] Unionfs: properly hash newly created inodes Erez Zadok
2008-07-30  2:43 ` [PATCH 16/19] Unionfs: symlink no longer takes a mode parameter Erez Zadok
2008-07-30  2:43 ` [PATCH 17/19] Unionfs: permission no longer takes a nameidata parameter Erez Zadok
2008-07-30  2:43 ` [PATCH 18/19] Unionfs: LOOKUP_ACCESS intent no longer exists Erez Zadok
2008-07-30  2:43 ` [PATCH 19/19] Unionfs: use new kmem_cache_create constructor prototype Erez Zadok

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=12173858301951-git-send-email-ezk@cs.sunysb.edu \
    --to=ezk@cs.sunysb.edu \
    --cc=akpm@linux-foundation.org \
    --cc=hch@infradead.org \
    --cc=hch@lst.de \
    --cc=hooanon05@yahoo.co.jp \
    --cc=hugh@veritas.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhalcrow@us.ibm.com \
    --cc=miklos@szeredi.hu \
    --cc=viro@zeniv.linux.org.uk \
    /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).