linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@osdl.org>
To: Martin Jambor <jambormartin@gmail.com>
Cc: linux-fsdevel@vger.kernel.org
Subject: Re: Relocking page in writepage
Date: Sat, 25 Feb 2006 02:50:53 -0800	[thread overview]
Message-ID: <20060225025053.2b25a91d.akpm@osdl.org> (raw)
In-Reply-To: <9615ac9b0602150742v5b0911e2t1ee601716f4ed5dd@mail.gmail.com>

Martin Jambor <jambormartin@gmail.com> wrote:
>
> Hi,
> 
> is it ok to do something like the following in aops->writepage (or in
> writepages after calling clear_page_dirty_for_io(page) for that
> matter):
> 
>         struct address_space mapping = page->mapping;
> 	page_cache_get(page);
> 	unlock_page(page);
> 
>         /* do something that might deadlock if page was locked */
> 
> 	lock_page(page);
> 	page_cache_release(page);
> 
> 	if (page->mapping != mapping) { /* truncated while doing the above */
> 		unlock_page(page);
> 		return 0;
> 	}
> 
>         /* continue as usual  (i.e. initiate writing, set writeback
> and unlock) */
> 
> A few practical tests showed no problem but I thought it would be
> better to ask anyway...
> I know it isn't a nice thing to do but otherwise I would probably need
> to implement some mechanism to remember the page I have locked and
> never try to lock (or page_cache_grab) it again. Both are cumbersome
> but this is easier, what do you think about it?
> 

I can't immediately think of a problem with that.

I guess it would be nicer to do:

	lock_page();
	if (page->mapping != mapping) {
		unlock_page();
		page_cache_release();

so the page get freed immediately if the race happened, rather than having
it drift down the LRU.

umm, actually you do need to handle the case where someone came in and
redirtied the page and potentially stated writeback against it.

	lock_page();
	wait_on_page_writeback();
	if (page->mapping != mapping) {
		unlock_page();
		page_cache_release();
		return;
	}

	Now, we don't know whether to write the page.  Someone else might have
	redirtied it and written it while w dropped the lock.

So you have to go off and write it, occasionally unnecessarily.

umm, no.  If you leave PageWriteback() set throughout, nobody will try to
restart a write.  So after relocking the page you should run
clear_page_dirty() to cover that case, then write it.

Tricky.

  reply	other threads:[~2006-02-25 10:51 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-02-15 15:42 Relocking page in writepage Martin Jambor
2006-02-25 10:50 ` Andrew Morton [this message]
2006-02-26 15:32   ` Martin Jambor

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=20060225025053.2b25a91d.akpm@osdl.org \
    --to=akpm@osdl.org \
    --cc=jambormartin@gmail.com \
    --cc=linux-fsdevel@vger.kernel.org \
    /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).