 fs/reiser4/as_ops.c                      |   29 +++++++++---------------
 fs/reiser4/context.h                     |    7 +++++
 fs/reiser4/entd.c                        |   10 --------
 fs/reiser4/flush.c                       |   14 ++---------
 fs/reiser4/flush.h                       |    2 -
 fs/reiser4/plugin/cryptcompress.c        |   10 --------
 fs/reiser4/plugin/file/file.c            |   37 ++-----------------------------
 fs/reiser4/plugin/file/tail_conversion.c |    2 -
 fs/reiser4/plugin/item/tail.c            |    5 ----
 fs/reiser4/txnmgr.c                      |   18 ++++++---------
 fs/reiser4/txnmgr.h                      |    2 -
 fs/reiser4/vfs_ops.c                     |   23 +++++++++----------
 fs/reiser4/vfs_ops.h                     |    5 +++-
 13 files changed, 51 insertions(+), 113 deletions(-)

diff -puN fs/reiser4/vfs_ops.c~reiser4-update-3 fs/reiser4/vfs_ops.c
--- linux-2.6.12-rc3-mm3/fs/reiser4/vfs_ops.c~reiser4-update-3	2005-05-11 18:04:31.419719298 +0400
+++ linux-2.6.12-rc3-mm3-vs/fs/reiser4/vfs_ops.c	2005-05-11 18:04:31.480723729 +0400
@@ -559,7 +559,7 @@ reiser4_put_inode(struct inode *inode)
  * Called by reiser4_sync_inodes(), during speculative write-back (through
  * pdflush, or balance_dirty_pages()).
  */
-static void
+void
 writeout(struct super_block *sb, struct writeback_control *wbc)
 {
 	long written = 0;
@@ -570,10 +570,6 @@ writeout(struct super_block *sb, struct 
 	 * nothing to flush, commits some atoms.
 	 */
 
-	/* reiser4 has its own means of periodical write-out */
-	if (wbc->for_kupdate)
-		return;
-
 	/* Commit all atoms if reiser4_writepages() is called from sys_sync() or
 	   sys_fsync(). */
 	if (wbc->sync_mode != WB_SYNC_NONE) {
@@ -593,9 +589,7 @@ writeout(struct super_block *sb, struct 
 			/* do not put more requests to overload write queue */
 			if (wbc->nonblocking &&
 			    bdi_write_congested(mapping->backing_dev_info)) {
-
 				blk_run_address_space(mapping);
-				/*blk_run_queues();*/
 				wbc->encountered_congestion = 1;
 				break;
 			}
@@ -620,21 +614,26 @@ reiser4_sync_inodes(struct super_block *
 {
 	reiser4_context ctx;
 
+	/* reiser4 has its own means of periodical write-out */
+	if (wbc->for_kupdate)
+		return;
+
+	assert("", wbc->older_than_this == NULL);
+
 	init_context(&ctx, sb);
-	wbc->older_than_this = NULL;
 
 	/*
-	 * What we are trying to do here is to capture all "anonymous" pages.
+	 * call reiser4_writepages for each of dirty inodes to turn dirty pages
+	 * into transactions if they were not yet.
 	 */
 	generic_sync_sb_inodes(sb, wbc);
-	/*capture_reiser4_inodes(sb, wbc);*/
-	spin_unlock(&inode_lock);
+
+	/* flush goes here */
 	writeout(sb, wbc);
 
 	/* avoid recursive calls to ->sync_inodes */
 	context_set_commit_async(&ctx);
 	reiser4_exit_context(&ctx);
-	spin_lock(&inode_lock);
 }
 
 void reiser4_throttle_write(struct inode * inode)
diff -puN fs/reiser4/as_ops.c~reiser4-update-3 fs/reiser4/as_ops.c
--- linux-2.6.12-rc3-mm3/fs/reiser4/as_ops.c~reiser4-update-3	2005-05-11 18:04:31.426719807 +0400
+++ linux-2.6.12-rc3-mm3-vs/fs/reiser4/as_ops.c	2005-05-12 18:23:18.743354004 +0400
@@ -492,7 +492,6 @@ reiser4_internal int
 reiser4_releasepage(struct page *page, int gfp UNUSED_ARG)
 {
 	jnode *node;
-	void *oid;
 
 	assert("nikita-2257", PagePrivate(page));
 	assert("nikita-2259", PageLocked(page));
@@ -508,8 +507,6 @@ reiser4_releasepage(struct page *page, i
 	assert("reiser4-4", page->mapping != NULL);
 	assert("reiser4-5", page->mapping->host != NULL);
 
-	oid = (void *)(unsigned long)get_inode_oid(page->mapping->host);
-
 	/* is_page_cache_freeable() check
 	   (mapping + private + page_cache_get() by shrink_cache()) */
 	if (page_count(page) > 3)
@@ -557,19 +554,6 @@ reiser4_releasepage(struct page *page, i
 #undef INC_NSTAT
 #undef INC_STAT
 
-reiser4_internal void
-move_inode_out_from_sync_inodes_loop(struct address_space * mapping)
-{
-	/* work around infinite loop in pdflush->sync_sb_inodes. */
-	/* Problem: ->writepages() is supposed to submit io for the pages from
-	 * ->io_pages list and to clean this list. */
-	mapping->host->dirtied_when = jiffies;
-	spin_lock(&inode_lock);
-	list_move(&mapping->host->i_list, &mapping->host->i_sb->s_dirty);
-	spin_unlock(&inode_lock);
-
-}
-
 /* reiser4 writepages() address space operation this captures anonymous pages
    and anonymous jnodes. Anonymous pages are pages which are dirtied via
    mmapping. Anonymous jnodes are ones which were created by reiser4_writepage
@@ -584,12 +568,21 @@ reiser4_writepages(struct address_space 
 
 	inode = mapping->host;
 	fplug = inode_file_plugin(inode);
-	if (fplug != NULL && fplug->capture != NULL)
+	if (fplug != NULL && fplug->capture != NULL) {
 		/* call file plugin method to capture anonymous pages and
 		   anonymous jnodes */
 		ret = fplug->capture(inode, wbc);
+		if (is_in_reiser4_context()) {
+			if (get_current_context()->nr_captured >= CAPTURE_APAGE_BURST) {
+				/* there are already pages to flush, flush them
+				   out, do not delay until end of
+				   reiser4_sync_inodes */
+				writeout(inode->i_sb, wbc);
+				get_current_context()->nr_captured = 0;
+			}
+		}
+	}
 
-	move_inode_out_from_sync_inodes_loop(mapping);
 	return ret;
 }
 
diff -puN fs/reiser4/plugin/file/file.c~reiser4-update-3 fs/reiser4/plugin/file/file.c
--- linux-2.6.12-rc3-mm3/fs/reiser4/plugin/file/file.c~reiser4-update-3	2005-05-11 18:04:31.434720388 +0400
+++ linux-2.6.12-rc3-mm3-vs/fs/reiser4/plugin/file/file.c	2005-05-12 11:34:22.710261107 +0400
@@ -935,14 +935,6 @@ capturepage_unix_file(struct page * page
 	return result;
 }
 
-static void
-redirty_inode(struct inode *inode)
-{
-	spin_lock(&inode_lock);
-	inode->i_state |= I_DIRTY;
-	spin_unlock(&inode_lock);
-}
-
 /*
  * Support for "anonymous" pages and jnodes.
  *
@@ -1015,9 +1007,6 @@ capture_anonymous_page(struct page *pg, 
 	return result;
 }
 
-
-#define CAPTURE_APAGE_BURST      (1024l)
-
 /* look for pages tagged REISER4_MOVED starting from the index-th page, return
    number of captured pages, update index to next page after the last found
    one */
@@ -1349,23 +1338,7 @@ capture_unix_file(struct inode *inode, s
 		 */
 		assert("", LOCK_CNT_NIL(inode_sem_w));
 		assert("", LOCK_CNT_NIL(inode_sem_r));
-#if 0
-		if (is_in_reiser4_context()) {
-			if (down_read_trylock(&uf_info->latch) == 0) {
-/* ZAM-FIXME-HANS: please explain this error handling here, grep for
- * all instances of returning EBUSY, and tell me whether any of them
- * represent busy loops that we should recode.  Also tell me whether
- * any of them fail to return EBUSY to user space, and if yes, then
- * recode them to not use the EBUSY macro.*/
-				warning("", "does this ever happen?");
-				result = RETERR(-EBUSY);
-				reiser4_exit_context(&ctx);
-				break;
-			}
-		} else
-			down_read(&uf_info->latch);
-		LOCK_CNT_INC(inode_sem_r);
-#endif
+
 		txn_restart_current();
 		get_nonexclusive_access(uf_info, 0);
 		while (to_capture > 0) {
@@ -1391,7 +1364,7 @@ capture_unix_file(struct inode *inode, s
 			if (result < 0)
 				break;
 			to_capture -= result;
-			wbc->nr_to_write -= result;
+			get_current_context()->nr_captured -= result;
 
 			if (jindex == (pgoff_t)-1) {
 				assert("vs-1728", pindex == (pgoff_t)-1);
@@ -1400,13 +1373,9 @@ capture_unix_file(struct inode *inode, s
 		}
 		if (to_capture <= 0)
 			/* there may be left more pages */
-			redirty_inode(inode);
+			__mark_inode_dirty(inode, I_DIRTY_PAGES);
 
 		drop_nonexclusive_access(uf_info);
-/*
-		up_read(&uf_info->latch);
-		LOCK_CNT_DEC(inode_sem_r);
-*/
 		if (result < 0) {
 			/* error happened */
 			reiser4_exit_context(&ctx);
diff -puN fs/reiser4/context.h~reiser4-update-3 fs/reiser4/context.h
--- linux-2.6.12-rc3-mm3/fs/reiser4/context.h~reiser4-update-3	2005-05-11 18:04:31.442720969 +0400
+++ linux-2.6.12-rc3-mm3-vs/fs/reiser4/context.h	2005-05-11 18:04:31.489724383 +0400
@@ -121,6 +121,13 @@ struct reiser4_context {
 
 	/* count non-trivial jnode_set_dirty() calls */
 	unsigned long nr_marked_dirty;
+
+	/* reiser4_sync_inodes calls (via generic_sync_sb_inodes)
+	 * reiser4_writepages for each of dirty inodes. Reiser4_writepages
+	 * captures pages. When number of pages captured in one
+	 * reiser4_sync_inodes reaches some threshold - some atoms get
+	 * flushed */
+	int nr_captured;
 #if REISER4_DEBUG
 	/* A link of all active contexts. */
 	context_list_link contexts_link;
diff -puN fs/reiser4/flush.c~reiser4-update-3 fs/reiser4/flush.c
--- linux-2.6.12-rc3-mm3/fs/reiser4/flush.c~reiser4-update-3	2005-05-11 18:04:31.452721695 +0400
+++ linux-2.6.12-rc3-mm3-vs/fs/reiser4/flush.c	2005-05-11 18:04:31.494724746 +0400
@@ -631,7 +631,8 @@ static int prepare_flush_pos(flush_pos_t
    audit.
 */
 
-static int jnode_flush(jnode * node, long *nr_to_flush, long * nr_written, flush_queue_t * fq, int flags)
+static int
+jnode_flush(jnode *node, long *nr_written, flush_queue_t *fq, int flags)
 {
 	long ret = 0;
 	flush_scan right_scan;
@@ -665,7 +666,6 @@ static int jnode_flush(jnode * node, lon
 	/* Initialize a flush position. */
 	pos_init(&flush_pos);
 
-	flush_pos.nr_to_flush = nr_to_flush;
 	flush_pos.nr_written = nr_written;
 	flush_pos.fq = fq;
 	flush_pos.flags = flags;
@@ -829,14 +829,6 @@ static int jnode_flush(jnode * node, lon
 	/* Any failure reaches this point. */
 failed:
 
-	if (nr_to_flush != NULL) {
-		if (ret >= 0) {
-			(*nr_to_flush) = flush_pos.prep_or_free_cnt;
-		} else {
-			(*nr_to_flush) = 0;
-		}
-	}
-
 	switch (ret) {
 	    case -E_REPEAT:
 	    case -EINVAL:
@@ -985,7 +977,7 @@ flush_current_atom (int flags, long *nr_
 		jref(node);
 		UNLOCK_ATOM(*atom);
 		UNLOCK_JNODE(node);
-		ret = jnode_flush(node, NULL, nr_submitted, fq, flags);
+		ret = jnode_flush(node, nr_submitted, fq, flags);
 		jput(node);
 	}
 
diff -puN fs/reiser4/flush.h~reiser4-update-3 fs/reiser4/flush.h
--- linux-2.6.12-rc3-mm3/fs/reiser4/flush.h~reiser4-update-3	2005-05-11 18:04:31.459722204 +0400
+++ linux-2.6.12-rc3-mm3-vs/fs/reiser4/flush.h	2005-05-11 18:04:31.497724964 +0400
@@ -103,8 +103,6 @@ struct flush_position {
 	reiser4_blocknr_hint preceder;	/* The flush 'hint' state. */
 	int leaf_relocate;	/* True if enough leaf-level nodes were
 				 * found to suggest a relocate policy. */
-	long *nr_to_flush;	/* If called under memory pressure,
-				 * indicates how many nodes the VM asked to flush. */
 	int alloc_cnt;		/* The number of nodes allocated during squeeze and allococate. */
 	int prep_or_free_cnt;	/* The number of nodes prepared for write (allocate) or squeezed and freed. */
 	flush_queue_t *fq;
diff -puN fs/reiser4/vfs_ops.h~reiser4-update-3 fs/reiser4/vfs_ops.h
--- linux-2.6.12-rc3-mm3/fs/reiser4/vfs_ops.h~reiser4-update-3	2005-05-11 18:04:31.466722712 +0400
+++ linux-2.6.12-rc3-mm3-vs/fs/reiser4/vfs_ops.h	2005-05-11 18:04:31.498725036 +0400
@@ -38,9 +38,12 @@ extern int reiser4_invalidatepage(struct
 extern int reiser4_releasepage(struct page *page, int gfp);
 extern int reiser4_writepages(struct address_space *, struct writeback_control *wbc);
 extern int reiser4_start_up_io(struct page *page);
-extern void move_inode_out_from_sync_inodes_loop(struct address_space * mapping);
 extern void reiser4_clear_page_dirty(struct page *);
 extern void reiser4_throttle_write(struct inode*);
+
+#define CAPTURE_APAGE_BURST (1024l)
+void writeout(struct super_block *, struct writeback_control *);
+
 /*
  * this is used to speed up lookups for directory entry: on initial call to
  * ->lookup() seal and coord of directory entry (if found, that is) are stored
diff -puN fs/reiser4/plugin/item/tail.c~reiser4-update-3 fs/reiser4/plugin/item/tail.c
--- linux-2.6.12-rc3-mm3/fs/reiser4/plugin/item/tail.c~reiser4-update-3	2005-05-11 18:04:31.473723221 +0400
+++ linux-2.6.12-rc3-mm3-vs/fs/reiser4/plugin/item/tail.c	2005-05-11 18:04:31.500725182 +0400
@@ -478,11 +478,6 @@ tail_balance_dirty_pages(struct address_
 	}
 
 	if (!reiser4_is_set(inode->i_sb, REISER4_ATOMIC_WRITE)) {
-		/* FIXME-VS: this is temporary: the problem is that bdp takes
-		   inodes from sb's dirty list and it looks like nobody puts
-		   there inodes of files which are built of tails */
-		move_inode_out_from_sync_inodes_loop(mapping);
-
 		uf_info = unix_file_inode_data(inode);
 		excl = unix_file_inode_data(inode)->exclusive_use;
 		if (excl)
diff -puN fs/reiser4/entd.c~reiser4-update-3 fs/reiser4/entd.c
--- linux-2.6.12-rc3-mm3/fs/reiser4/entd.c~reiser4-update-3	2005-05-11 18:04:42.609532006 +0400
+++ linux-2.6.12-rc3-mm3-vs/fs/reiser4/entd.c	2005-05-11 18:25:36.920631675 +0400
@@ -242,14 +242,6 @@ static void kick_entd(entd_context * ent
 	kcond_signal(&ent->wait);
 }
 
-static void entd_capture_anonymous_pages(
-	struct super_block * super, struct writeback_control * wbc)
-{
-	spin_lock(&inode_lock);
-	generic_sync_sb_inodes(super, wbc);
-	spin_unlock(&inode_lock);
-}
-
 static void entd_flush(struct super_block *super)
 {
 	long            nr_submitted = 0;
@@ -267,7 +259,7 @@ static void entd_flush(struct super_bloc
 
 	ctx.entd = 1;
 
-	entd_capture_anonymous_pages(super, &wbc);
+	generic_sync_sb_inodes(super, &wbc);
 	result = flush_some_atom(&nr_submitted, &wbc, JNODE_FLUSH_WRITE_BLOCKS);
 	if (result != 0)
 		warning("nikita-3100", "Flush failed: %i", result);
diff -puN fs/reiser4/txnmgr.c~reiser4-update-3 fs/reiser4/txnmgr.c
--- linux-2.6.12-rc3-mm3/fs/reiser4/txnmgr.c~reiser4-update-3	2005-05-11 18:08:26.580798870 +0400
+++ linux-2.6.12-rc3-mm3-vs/fs/reiser4/txnmgr.c	2005-05-12 18:40:07.287549634 +0400
@@ -245,7 +245,7 @@ year old --- define all technical terms 
 
 static void atom_free(txn_atom * atom);
 
-static long commit_txnh(txn_handle * txnh);
+static int commit_txnh(txn_handle * txnh);
 
 static void wakeup_atom_waitfor_list(txn_atom * atom);
 static void wakeup_atom_waiting_list(txn_atom * atom);
@@ -487,7 +487,7 @@ txn_begin(reiser4_context * context)
 }
 
 /* Finish a transaction handle context. */
-reiser4_internal long
+reiser4_internal int
 txn_end(reiser4_context * context)
 {
 	long ret = 0;
@@ -1446,7 +1446,6 @@ flush_some_atom(long *nr_submitted, cons
 	txn_handle *txnh = ctx->trans;
 	txn_atom *atom;
 	int ret;
-	int ret1;
 
 	assert("zam-1042", txnh != NULL);
  repeat:
@@ -1528,12 +1527,11 @@ flush_some_atom(long *nr_submitted, cons
 			goto repeat;
 		ret = 0;
 	}
-
-	ret1 = txn_end(ctx);
-	assert("vs-1692", ret1 == 0);
-	if (ret1 > 0)
-		*nr_submitted += ret1;
-	txn_begin(ctx);
+/*
+	if (*nr_submitted > wbc->nr_to_write)
+		warning("", "asked for %ld, written %ld\n", wbc->nr_to_write, *nr_submitted);
+*/
+	txn_restart(ctx);
 
 	return ret;
 }
@@ -1787,7 +1785,7 @@ try_commit_txnh(commit_data *cd)
 /* Called to commit a transaction handle.  This decrements the atom's number of open
    handles and if it is the last handle to commit and the atom should commit, initiates
    atom commit. if commit does not fail, return number of written blocks */
-static long
+static int
 commit_txnh(txn_handle * txnh)
 {
 	commit_data cd;
diff -puN fs/reiser4/txnmgr.h~reiser4-update-3 fs/reiser4/txnmgr.h
--- linux-2.6.12-rc3-mm3/fs/reiser4/txnmgr.h~reiser4-update-3	2005-05-11 18:21:01.254610260 +0400
+++ linux-2.6.12-rc3-mm3-vs/fs/reiser4/txnmgr.h	2005-05-11 18:21:35.080066978 +0400
@@ -459,7 +459,7 @@ extern int txnmgr_done(txn_mgr * mgr);
 extern int txn_reserve(int reserved);
 
 extern void txn_begin(reiser4_context * context);
-extern long txn_end(reiser4_context * context);
+extern int txn_end(reiser4_context * context);
 
 extern void txn_restart(reiser4_context * context);
 extern void txn_restart_current(void);
diff -puN fs/reiser4/plugin/cryptcompress.c~reiser4-update-3 fs/reiser4/plugin/cryptcompress.c
--- linux-2.6.12-rc3-mm3/fs/reiser4/plugin/cryptcompress.c~reiser4-update-3	2005-05-12 11:33:47.453987848 +0400
+++ linux-2.6.12-rc3-mm3-vs/fs/reiser4/plugin/cryptcompress.c	2005-05-12 11:35:17.652996363 +0400
@@ -3219,14 +3219,6 @@ capture_anonymous_cluster(reiser4_cluste
 	return result;
 }
 
-static void
-redirty_inode(struct inode *inode)
-{
-	spin_lock(&inode_lock);
-	inode->i_state |= I_DIRTY;
-	spin_unlock(&inode_lock);
-}
-
 #define MAX_CLUSTERS_TO_CAPTURE(inode)      (1024 >> inode_cluster_shift(inode))
 
 /* read lock should be acquired */
@@ -3278,7 +3270,7 @@ capture_anonymous_clusters(struct addres
 		assert("edward-1078", to_capture <= MAX_CLUSTERS_TO_CAPTURE(mapping->host));
 		if (to_capture <= 0)
 			/* there may be left more pages */
-			redirty_inode(mapping->host);
+			__mark_inode_dirty(mapping->host, I_DIRTY_PAGES);
 	}
  out:
 	done_lh(&lh);
diff -puN fs/reiser4/plugin/file/tail_conversion.c~reiser4-update-3 fs/reiser4/plugin/file/tail_conversion.c
--- linux-2.6.12-rc3-mm3/fs/reiser4/plugin/file/tail_conversion.c~reiser4-update-3	2005-05-12 11:42:55.693513834 +0400
+++ linux-2.6.12-rc3-mm3-vs/fs/reiser4/plugin/file/tail_conversion.c	2005-05-12 11:43:00.688795044 +0400
@@ -336,7 +336,7 @@ tail2extent(unix_file_info_t *uf_info)
 			   not risk deadlock appearance
 			*/
 			assert("vs-983", !PagePrivate(page));
-
+			reiser4_invalidate_pages(inode->i_mapping, page->index, 1, 0);
 			for (page_off = 0; page_off < PAGE_CACHE_SIZE;) {
 				coord_t coord;
 				lock_handle lh;

_
