Re: Write-back from inside FS - need suggestions

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Andrew Morton <akpm@...>
Cc: Linux Kernel Mailing List <linux-kernel@...>
Date: Sunday, September 30, 2007 - 4:40 am

Andrew, thank you for this help.

Andrew Morton wrote:

Well, in my case I force write-back from prepare_write _only_ when the page
is clean, because if it is dirty, it was (pessimistically) accounted earlier
already and changing dirty page does not change anything on the media. So
I call writeback only for _new_ pages, which are always clean.

I use PagePrivate() flag to flag pages as dirty, and unflag them in
writepage(). I need to keep my own accounting of number of dirty pages at
any point of time. I found that I cannot use PageDirty() flag because
it is cleaned before my ->writepage is called, so I cannot decrement my
dirty_pg_counter, and I'd have to muck with radix tree's tags which I do
not really like to do, thus I just use the private flag.

So in writepage() i only call writeback if PagePrivate() is unset, which
guarantees me that the page is clean, I presume.

So for my purposes the patch below _looks_ ok. I'm saying "looks" because I
tested it just a little.


Ok, thank you! I (naively) thought i_mutex is locked in ->writepage. But now
I see that pdflush does not lock it, readahead calls ->readpage without
i_mutex too. They just lock the page.


I see, thanks. There is also i_size and i_size_write() and i_size_read().
My understanding is that i_size may be changed without something (i_mutex
or I_LOCK) locked, thus these helpers. i_size is read/written without them
in many places, though, so the relation of these i_size protection helpers
to i_mutex/I_LOCK is unclean for me.

Ideally, it would be nice to teach lockdep to monitor I_LOCK vs i_mutex.

Below it the patch which seems to give me what I need. Just for reference.

=========================
Subject: [PATCH] VFS: introduce writeback_inodes_sb()

Let file systems to writeback their pages and inodes when needed.

Note, it cannot be called if one of the dirty pages is locked by
the caller, otherwise it'll deadlock.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
---
 fs/fs-writeback.c         |    8 ++++++++
 include/linux/writeback.h |    1 +
 2 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c
index a4b142a..17c8aaa 100644
--- a/fs/fs-writeback.c
+++ b/fs/fs-writeback.c
@@ -486,6 +486,14 @@ void sync_inodes_sb(struct super_block *sb, int wait)
        spin_unlock(&inode_lock);
 }

+void writeback_inodes_sb(struct super_block *sb, struct writeback_control *wbc)
+{
+       spin_lock(&inode_lock);
+       sync_sb_inodes(sb, wbc);
+       spin_unlock(&inode_lock);
+}
+EXPORT_SYMBOL_GPL(writeback_inodes_sb);
+
 /*
  * Rather lame livelock avoidance.
  */
diff --git a/include/linux/writeback.h b/include/linux/writeback.h
index 4ef4d22..e20cd12 100644
--- a/include/linux/writeback.h
+++ b/include/linux/writeback.h
@@ -72,6 +72,7 @@ void writeback_inodes(struct writeback_control *wbc);
 void wake_up_inode(struct inode *inode);
 int inode_wait(void *);
 void sync_inodes_sb(struct super_block *, int wait);
+void writeback_inodes_sb(struct super_block *sb, struct writeback_control *wbc);
 void sync_inodes(int wait);

 /* writeback.h requires fs.h; it, too, is not included from here. */
--
1.5.0.6

-- 
Best Regards,
Artem Bityutskiy (Артём Битюцкий)
-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Write-back from inside FS - need suggestions, Artem Bityutskiy, (Fri Sep 28, 5:16 am)
Re: Write-back from inside FS - need suggestions, Artem Bityutskiy, (Sat Sep 29, 5:56 am)
Re: Write-back from inside FS - need suggestions, Andrew Morton, (Sat Sep 29, 6:39 am)
Re: Write-back from inside FS - need suggestions, Artem Bityutskiy, (Sat Sep 29, 3:10 pm)
Re: Write-back from inside FS - need suggestions, Andrew Morton, (Sat Sep 29, 4:00 pm)
Re: Write-back from inside FS - need suggestions, Artem Bityutskiy, (Sun Sep 30, 4:40 am)
Re: Write-back from inside FS - need suggestions, Artem Bityutskiy, (Sat Sep 29, 6:44 am)
Re: Write-back from inside FS - need suggestions, Andrew Morton, (Fri Sep 28, 6:29 am)