* Question on set_page_dirty()
@ 2002-12-10 9:59 Martin Maletinsky
2002-12-11 8:01 ` Jan Hudec
0 siblings, 1 reply; 5+ messages in thread
From: Martin Maletinsky @ 2002-12-10 9:59 UTC (permalink / raw)
To: linux-mm, kernelnewbies
Hello,
Looking at the function set_page_dirty() (in linux 2.4.18-3 - see below) I noticed, that it not only sets the pages PG_dirty bit (as the SetPageDirty() macro does), but
additionnally may link the page onto a queue (more precisely the dirty queue of it's 'mapping').
What is the meaning of this dirty queue, what is the effect of linking a page onto that queue, and when should the set_page_dirty() function be used rather than the
SetPageDirty() macro?
Thanks in advance for any help
with best regards
Martin Maletinsky
P.S. Please put me on CC: in your reply, since I am not in the mailing list.
*
153 * Add a page to the dirty page list.
154 */
155 void set_page_dirty(struct page *page)
156 {
157 if (!test_and_set_bit(PG_dirty, &page->flags)) {
158 struct address_space *mapping = page->mapping;
159
160 if (mapping) {
161 spin_lock(&pagecache_lock);
162 list_del(&page->list);
163 list_add(&page->list, &mapping->dirty_pages);
164 spin_unlock(&pagecache_lock);
165
166 if (mapping->host)
167 mark_inode_dirty_pages(mapping->host);
168 }
169 }
170 }
--
Supercomputing System AG email: maletinsky@scs.ch
Martin Maletinsky phone: +41 (0)1 445 16 05
Technoparkstrasse 1 fax: +41 (0)1 445 16 10
CH-8005 Zurich
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Question on set_page_dirty()
2002-12-10 9:59 Question on set_page_dirty() Martin Maletinsky
@ 2002-12-11 8:01 ` Jan Hudec
2002-12-12 9:29 ` Ingo Oeser
0 siblings, 1 reply; 5+ messages in thread
From: Jan Hudec @ 2002-12-11 8:01 UTC (permalink / raw)
To: Martin Maletinsky; +Cc: linux-mm, kernelnewbies
On Tue, Dec 10, 2002 at 10:59:34AM +0100, Martin Maletinsky wrote:
> Hello,
>
> Looking at the function set_page_dirty() (in linux 2.4.18-3 - see
> below) I noticed, that it not only sets the pages PG_dirty bit (as the
> SetPageDirty() macro does), but additionnally may link the page onto
> a queue (more precisely the dirty queue of it's 'mapping').
That's the most important bit of it all. All dirty pages must at some
point be cleaned. The list keeps track of which pages need to be
cleaned, so kernel can do it quickly either when it needs to free the
mapping (close the file, terminate process, exec) or when it's just time
to flush some pages (in kflushd).
> What is the meaning of this dirty queue, what is the effect of linking
> a page onto that queue, and when should the set_page_dirty() function
> be used rather than the
> SetPageDirty() macro?
If you use the SetPageDirty macro, then the page is marked dirty, but
kernel can't find it when it should clean it. Thus it eventualy won't
flush the data (it won't call writepage on it).
-------------------------------------------------------------------------------
Jan 'Bulb' Hudec <bulb@ucw.cz>
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Question on set_page_dirty()
2002-12-11 8:01 ` Jan Hudec
@ 2002-12-12 9:29 ` Ingo Oeser
2002-12-12 12:42 ` Stephen C. Tweedie
0 siblings, 1 reply; 5+ messages in thread
From: Ingo Oeser @ 2002-12-12 9:29 UTC (permalink / raw)
To: Jan Hudec, Martin Maletinsky, linux-mm, kernelnewbies
Hi,
On Wed, Dec 11, 2002 at 09:01:02AM +0100, Jan Hudec wrote:
> > What is the meaning of this dirty queue, what is the effect of linking
> > a page onto that queue, and when should the set_page_dirty() function
> > be used rather than the
> > SetPageDirty() macro?
>
> If you use the SetPageDirty macro, then the page is marked dirty, but
> kernel can't find it when it should clean it. Thus it eventualy won't
> flush the data (it won't call writepage on it).
set_page_dirty() can be used in all cases, IMHO, since it:
- will not sleep
- will not call the set_page_dirty() method, if page has been dirty
before (test_and_set_XXX is atomic an guarantees to trigger
once only)
- will not do anything besides settingt the PG_Dirty bit,
if the page contains no mapping, or does not contain a
set_page_dirty_method
So if set_page_dirty() exists on a certain kernel you want to
support, it should be used in all cases. Accounting code can also
be hooked into this, if it is used properly.
Regards
Ingo Oeser
--
Science is what we can tell a computer. Art is everything else. --- D.E.Knuth
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Question on set_page_dirty()
2002-12-12 9:29 ` Ingo Oeser
@ 2002-12-12 12:42 ` Stephen C. Tweedie
2002-12-12 18:20 ` Andrew Morton
0 siblings, 1 reply; 5+ messages in thread
From: Stephen C. Tweedie @ 2002-12-12 12:42 UTC (permalink / raw)
To: Ingo Oeser; +Cc: Jan Hudec, Martin Maletinsky, linux-mm, kernelnewbies
Hi,
On Thu, 2002-12-12 at 09:29, Ingo Oeser wrote:
> set_page_dirty() can be used in all cases, IMHO, since it:
> - will not sleep
...
Unfortunately, it can take both the inode_lock and pagecache_lock
spinlocks, so if you use it in the wrong place, with other locks already
held, you can cause a deadlock. So you _do_ need to be a bit careful,
and you can't just use it with abandon.
Cheers,
Stephen
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Question on set_page_dirty()
2002-12-12 12:42 ` Stephen C. Tweedie
@ 2002-12-12 18:20 ` Andrew Morton
0 siblings, 0 replies; 5+ messages in thread
From: Andrew Morton @ 2002-12-12 18:20 UTC (permalink / raw)
To: Stephen C. Tweedie
Cc: Ingo Oeser, Jan Hudec, Martin Maletinsky, linux-mm, kernelnewbies
"Stephen C. Tweedie" wrote:
>
> Hi,
>
> On Thu, 2002-12-12 at 09:29, Ingo Oeser wrote:
> > set_page_dirty() can be used in all cases, IMHO, since it:
> > - will not sleep
> ...
>
> Unfortunately, it can take both the inode_lock and pagecache_lock
> spinlocks, so if you use it in the wrong place, with other locks already
> held, you can cause a deadlock. So you _do_ need to be a bit careful,
> and you can't just use it with abandon.
>
And in 2.5 the pagecache_lock is per-inode. This ends up meaning that
it is not legal to run set_page_dirty(page) unless the caller has
done something to prevent the thing at page->mapping from being freed.
If that has not been done, it is conceivable (but hugely unlikely) that
the page could be truncated from its mapping and that mapping could be
thrown away while set_page_dirty() is trying to claim its ->page_lock.
So in 2.5, set_page_dirty() is only legal if the caller has a ref against
page->mapping->host, or if the page is locked.
It's currently wrong in a couple of places. I have local fixes for
the VM, and direct-IO still needs to be done. It will just be:
lock_page(page); /* pins page->mapping */
set_page_dirty(page);
unlock_page(page);
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2002-12-12 18:20 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-12-10 9:59 Question on set_page_dirty() Martin Maletinsky
2002-12-11 8:01 ` Jan Hudec
2002-12-12 9:29 ` Ingo Oeser
2002-12-12 12:42 ` Stephen C. Tweedie
2002-12-12 18:20 ` Andrew Morton
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox