struct inode *inode = container_of(page->mapping,
                                           struct inode, i_data);
        struct super_block *sb = inode->i_sb;
+       struct the_nilfs *nilfs = NILFS_MDT(inode)->mi_nilfs;
        struct nilfs_sb_info *writer = NULL;
        int err = 0;
 
        if (page->mapping->assoc_mapping)
                return 0; /* Do not request flush for shadow page cache */
        if (!sb) {
-               writer = nilfs_get_writer(NILFS_MDT(inode)->mi_nilfs);
+               down_read(&nilfs->ns_writer_sem);
+               writer = nilfs->ns_writer;
                if (!writer) {
-                       nilfs_put_writer(NILFS_MDT(inode)->mi_nilfs);
+                       up_read(&nilfs->ns_writer_sem);
                        return -EROFS;
                }
                sb = writer->s_super;
                nilfs_flush_segment(sb, inode->i_ino);
 
        if (writer)
-               nilfs_put_writer(NILFS_MDT(inode)->mi_nilfs);
+               up_read(&nilfs->ns_writer_sem);
        return err;
 }
 
 
 
        nilfs->ns_bdev = bdev;
        atomic_set(&nilfs->ns_count, 1);
-       atomic_set(&nilfs->ns_writer_refcount, -1);
        atomic_set(&nilfs->ns_ndirtyblks, 0);
        init_rwsem(&nilfs->ns_sem);
        init_rwsem(&nilfs->ns_super_sem);
        mutex_init(&nilfs->ns_mount_mutex);
-       mutex_init(&nilfs->ns_writer_mutex);
+       init_rwsem(&nilfs->ns_writer_sem);
        INIT_LIST_HEAD(&nilfs->ns_list);
        INIT_LIST_HEAD(&nilfs->ns_supers);
        spin_lock_init(&nilfs->ns_last_segment_lock);
 
  * @ns_sem: semaphore for shared states
  * @ns_super_sem: semaphore for global operations across super block instances
  * @ns_mount_mutex: mutex protecting mount process of nilfs
- * @ns_writer_mutex: mutex protecting ns_writer attach/detach
- * @ns_writer_refcount: number of referrers on ns_writer
+ * @ns_writer_sem: semaphore protecting ns_writer attach/detach
  * @ns_current: back pointer to current mount
  * @ns_sbh: buffer heads of on-disk super blocks
  * @ns_sbp: pointers to super block data
        struct rw_semaphore     ns_sem;
        struct rw_semaphore     ns_super_sem;
        struct mutex            ns_mount_mutex;
-       struct mutex            ns_writer_mutex;
-       atomic_t                ns_writer_refcount;
+       struct rw_semaphore     ns_writer_sem;
 
        /*
         * components protected by ns_super_sem
        atomic_inc(&nilfs->ns_count);
 }
 
-static inline struct nilfs_sb_info *nilfs_get_writer(struct the_nilfs *nilfs)
-{
-       if (atomic_inc_and_test(&nilfs->ns_writer_refcount))
-               mutex_lock(&nilfs->ns_writer_mutex);
-       return nilfs->ns_writer;
-}
-
-static inline void nilfs_put_writer(struct the_nilfs *nilfs)
-{
-       if (atomic_add_negative(-1, &nilfs->ns_writer_refcount))
-               mutex_unlock(&nilfs->ns_writer_mutex);
-}
-
 static inline void
 nilfs_attach_writer(struct the_nilfs *nilfs, struct nilfs_sb_info *sbi)
 {
-       mutex_lock(&nilfs->ns_writer_mutex);
+       down_write(&nilfs->ns_writer_sem);
        nilfs->ns_writer = sbi;
-       mutex_unlock(&nilfs->ns_writer_mutex);
+       up_write(&nilfs->ns_writer_sem);
 }
 
 static inline void
 nilfs_detach_writer(struct the_nilfs *nilfs, struct nilfs_sb_info *sbi)
 {
-       mutex_lock(&nilfs->ns_writer_mutex);
+       down_write(&nilfs->ns_writer_sem);
        if (sbi == nilfs->ns_writer)
                nilfs->ns_writer = NULL;
-       mutex_unlock(&nilfs->ns_writer_mutex);
+       up_write(&nilfs->ns_writer_sem);
 }
 
 static inline void nilfs_put_sbinfo(struct nilfs_sb_info *sbi)