Question on set_page_dirty()
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: [email protected] 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 [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/
Quoted 6 lines · Martin Maletinsky
Hello,
Looking at the function
set_page_dirty()(in linux 2.4.18-3 - see below) I noticed, that it not only sets the pagesPG_dirtybit (as theSetPageDirty()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).
Quoted 4 lines
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 theSetPageDirty()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 <[email protected]>
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/
Hi,
Quoted 8 lines · Jan Hudec
Quoted 4 lines
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 theSetPageDirty()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
Signature · 5 lines
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 [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/
Hi,
Quoted 2 lines · Ingo Oeser
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 [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/
Quoted 4 lines · Stephen C. Tweedie
Hi,
On Thu, 2002-12-12 at 09:29, Ingo Oeser wrote:
Quoted 9 lines
Quoted 2 lines
set_page_dirty()can be used in all cases, IMHO, since it:
- will not sleep...
Unfortunately, it can take both the
inode_lockandpagecache_lockspinlocks, 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 [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/