question on page-migration code
Hirokazu (and Marcelo),
In testing my manual page migration code, I've run up against a situation where the migrations are occasionally very slow. They work ok, but they can take minutes to migrate a few megabytes of memory.
Dropping into kdb shows that the migration code is waiting in msleep() in migrate_page_common() due to an -EAGAIN return from page_migratable(). A little further digging shows that the specific return in page_migratable() is the very last one there at the bottom of the routine.
I'm puzzled as to why the page is still busy in this case. Previous code in page_migratable() has unmapped the page, its not in PageWriteback() because we would have taken a different return statement in that case.
According to /proc/meminfo, there are no pages in either SwapCache or Dirty state, and the system has been sync'd before the migrate_pages() call was issued.
Signature · 14 lines
Best Regards,
Ray
-----------------------------------------------
Ray Bryant
512-453-9679 (work) 512-507-7807 (cell)
[email protected] [email protected]
The box said: "Requires Windows 98 or better",
so I installed Linux.
-----------------------------------------------
--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>Quoted 11 lines · Ray Bryant
Hirokazu (and Marcelo),
In testing my manual page migration code, I've run up against a situation where the migrations are occasionally very slow. They work ok, but they can take minutes to migrate a few megabytes of memory.
Dropping into kdb shows that the migration code is waiting in
msleep()inmigrate_page_common()due to an-EAGAINreturn frompage_migratable(). A little further digging shows that the specific return inpage_migratable()is the very last one there at the bottom of the routine.
Quoted 7 lines
I'm puzzled as to why the page is still busy in this case. Previous code in
page_migratable()has unmapped the page, its not inPageWriteback()because we would have taken a different return statement in that case.According to
/proc/meminfo, there are no pages in either SwapCache or Dirty state, and the system has been sync'd before themigrate_pages()call was issued.
Who is using the page?
A little debugging might help similar to what bad_page does can help:
printk(KERN_EMERG "flags:0x%0*lx mapping:%p mapcount:%d count:%d\n",
(int)(2*sizeof(page_flags_t)), (unsigned long)page->flags,
page->mapping, page_mapcount(page), page_count(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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 22 lines · Marcelo Tosatti
Quoted 11 lines · Ray Bryant
Hirokazu (and Marcelo),
In testing my manual page migration code, I've run up against a situation where the migrations are occasionally very slow. They work ok, but they can take minutes to migrate a few megabytes of memory.
Dropping into kdb shows that the migration code is waiting in
msleep()inmigrate_page_common()due to an-EAGAINreturn frompage_migratable(). A little further digging shows that the specific return inpage_migratable()is the very last one there at the bottom of the routine.Quoted 7 lines
I'm puzzled as to why the page is still busy in this case. Previous code in
page_migratable()has unmapped the page, its not inPageWriteback()because we would have taken a different return statement in that case.According to
/proc/meminfo, there are no pages in either SwapCache or Dirty state, and the system has been sync'd before themigrate_pages()call was issued.
Quoted 8 lines
Who is using the page?
A little debugging might help similar to what
bad_pagedoes can help:printk(KERN_EMERG "flags:0x%0*lx mapping:%p mapcount:%d count:%d\n", (int)(2*sizeof(page_flags_t)), (unsigned long)page->flags, page->mapping, page_mapcount(page), page_count(page));--
The suspect pages all have flags field of 105d and mapcount of 0, pagecount of 3. If I'm decoding the bits correctly, we've got the following bits set:
Locked
Referenced
Uptodate
Dirty
ActivePG_arch_1
Doesn't tell me much. Anything spring to mind when you look at these bits, Marcelo?
Signature · 14 lines
Best Regards,
Ray
-----------------------------------------------
Ray Bryant
512-453-9679 (work) 512-507-7807 (cell)
[email protected] [email protected]
The box said: "Requires Windows 98 or better",
so I installed Linux.
-----------------------------------------------
--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>Quoted 26 lines · Marcelo Tosatti
Quoted 11 lines · Ray Bryant
Hirokazu (and Marcelo),
In testing my manual page migration code, I've run up against a situation where the migrations are occasionally very slow. They work ok, but they can take minutes to migrate a few megabytes of memory.
Dropping into kdb shows that the migration code is waiting in
msleep()inmigrate_page_common()due to an-EAGAINreturn frompage_migratable(). A little further digging shows that the specific return inpage_migratable()is the very last one there at the bottom of the routine.Quoted 7 lines
I'm puzzled as to why the page is still busy in this case. Previous code in
page_migratable()has unmapped the page, its not inPageWriteback()because we would have taken a different return statement in that case.According to
/proc/meminfo, there are no pages in either SwapCache or Dirty state, and the system has been sync'd before themigrate_pages()call was issued.Who is using the page?
A little debugging might help similar to what
bad_pagedoes can help:
Quoted 9 lines
printk(KERN_EMERG "flags:0x%0*lx mapping:%p mapcount:%d count:%d\n", (int)(2*sizeof(page_flags_t)), (unsigned long)page->flags, page->mapping, page_mapcount(page), page_count(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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
A little further digging shows that when we go into -EAGAIN case in migrate_page_common(), we have flag bits 0x104D set, and when we finally exit the routine, we have flags bits 0x004D set. The 1 bit there is PG_private, as near as I can tell (not PG_arch_1, I guess I can't count).
PagePrivate() is cleared by truncation specific code in migrate_onepage(), but it doesn't appear to be cleared (directly) by code on the generic_migrate_page() patch. I wonder if this has something to do with the problem I am seeing.
Signature · 14 lines
Best Regards,
Ray
-----------------------------------------------
Ray Bryant
512-453-9679 (work) 512-507-7807 (cell)
[email protected] [email protected]
The box said: "Requires Windows 98 or better",
so I installed Linux.
-----------------------------------------------
--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>Hi Ray,
Quoted 38 lines
Quoted 24 lines
Quoted 11 lines
Hirokazu (and Marcelo),
In testing my manual page migration code, I've run up against a situation where the migrations are occasionally very slow. They work ok, but they can take minutes to migrate a few megabytes of memory.
Dropping into kdb shows that the migration code is waiting in
msleep()inmigrate_page_common()due to an-EAGAINreturn frompage_migratable(). A little further digging shows that the specific return inpage_migratable()is the very last one there at the bottom of the routine.Quoted 7 lines
I'm puzzled as to why the page is still busy in this case. Previous code in
page_migratable()has unmapped the page, its not inPageWriteback()because we would have taken a different return statement in that case.According to
/proc/meminfo, there are no pages in either SwapCache or Dirty state, and the system has been sync'd before themigrate_pages()call was issued.Who is using the page?
A little debugging might help similar to what
bad_pagedoes can help:Quoted 9 lines
printk(KERN_EMERG "flags:0x%0*lx mapping:%p mapcount:%d count:%d\n", (int)(2*sizeof(page_flags_t)), (unsigned long)page->flags, page->mapping, page_mapcount(page), page_count(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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>A little further digging shows that when we go into
-EAGAINcase inmigrate_page_common(), we have flag bits0x104Dset, and when we finally exit the routine, we have flags bits0x004Dset. The 1 bit there isPG_private, as near as I can tell (notPG_arch_1, I guess I can't count).
Quoted 4 lines
PagePrivate()is cleared by truncation specific code inmigrate_onepage(), but it doesn't appear to be cleared (directly) by code on thegeneric_migrate_page()patch. I wonder if this has something to do with the problem I am seeing.
I understand what happened on your machine.
PG_private is a filesystem specific flag, setting some filesystem depending data in page->private. When the flag is set on a page, only the local filesystem on which the page depends can handle it.
Most of the filesystems uses page->private to manage buffers while others may use it for different purposes. Each filesystem can implement migrate_page method to handles page->private. At this moment, only ext2 and ext3 have this method, which migrates buffers without any I/Os.
If the method isn't implemented for the page, the migration code calls pageout() and try_to_release_page() to release page->private instead.
Which filesystem are you using? I guess it might be XFS which doesn't have the method yet.
Thank you,
Hirokazu Takahashi.
--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 4 lines · Hirokazu Takahashi
Hi Ray,
<snip>
Quoted 17 lines
I understand what happened on your machine.
PG_privateis a filesystem specific flag, setting some filesystem depending data inpage->private. When the flag is set on a page, only the local filesystem on which the page depends can handle it.Most of the filesystems uses
page->privateto manage buffers while others may use it for different purposes. Each filesystem can implementmigrate_pagemethod to handlespage->private. At this moment, only ext2 and ext3 have this method, which migrates buffers without any I/Os.If the method isn't implemented for the page, the migration code calls
pageout()andtry_to_release_page()to releasepage->privateinstead.
Quoted 6 lines
Which filesystem are you using? I guess it might be XFS which doesn't have the method yet.
Thank you,
Hirokazu Takahashi.
Yes, I am using XFS. However, the thing I still don't understand why the migration is fast the first time I use it, but then the next time it is slow? It is the case that swap I/O is apparently happening for the pages when I see the slowdown, so I agree that you've probably diagnosed that part of the problem. (Well, I would wonder why pageout() followed by try_to_release_page() is soooo slow. But hey perhaps we are doing I/O in one page units or such and that could explain why the I/O takes so long.)
But why does the first migration happen so quickly? I'm wondering if the migration process doesn't leave the page in a state that requires cleaning, whereas the pages as originally found didn't need to be cleaned. It would seem to me we would want the page state after migration to be effectively the same as the page state before migration.
Signature · 14 lines
Best Regards,
Ray
-----------------------------------------------
Ray Bryant
512-453-9679 (work) 512-507-7807 (cell)
[email protected] [email protected]
The box said: "Requires Windows 98 or better",
so I installed Linux.
-----------------------------------------------
--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>Hi Hirokazu,
What appears to be happening is the following:
dirty pte bits are being swept into the page dirty bit as a side effect of migration. That is, if a page had pte_dirty(pte) set, then after migration, it will have PageDirty(page) = true.
Only pages with PageDirty() set will be written to swap as part of the process of trying to clear PG_private. So, when I do the first migration, the PG_dirty bit is not set on the page, but the dirty bit is set in the pte. Because PG_dirty is not set, the page does not get written to swap, and the migration is fast. However, at the end of the migration process, the pages all have PG_dirty set and the pte dirty bits are cleared.
The second time I do the migration, the PG_dirty bits are still set (left over from the first migration), so they have to be written to swap and the migration is slow. As part of the pageout(), try_to_release_page() process, the PG_dirty is cleared, along with the pte dirty bits, as before.
When the program is resumed, it will cause the pte dirty bits to be set, and then we will be back in the situation we started with before the first migration.
Hence the third migration will be fast, and the 4th migration will be slow, etc. This is a stable, repeatable process.
I guess it seems to me that if a page has pte dirty set, but doesn't have PG_dirty set, then that state should be carried over to the newpage after a migration, rather than sweeping the pte dirty bit into the PG_dirty bit.
Another way to do this would be to implement the migrate dirty buffers without swap I/O trick of ext2/3 in XFS, but that is somewhat far afield for me to try. :-) I'll discuss this with Nathan Scott et al and see if that is something that would be straightforward to do.
But I have a nagging suspicion that this covers up, rather than fixes the state transition from oldpage to newpage that really shouldn't be happening, as near as I can tell.
BTW, the program that I am testing creates a relatively large mapped file, and, as you guessed, this file is backed by XFS. Programs that just use large amounts of anonymous storage are not effected by this problem, I would imagine.
Signature · 14 lines
Best Regards,
Ray
-----------------------------------------------
Ray Bryant
512-453-9679 (work) 512-507-7807 (cell)
[email protected] [email protected]
The box said: "Requires Windows 98 or better",
so I installed Linux.
-----------------------------------------------
--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>At Tue, 12 Apr 2005 00:43:42 -0500,
Quoted 6 lines · Ray Bryant
What appears to be happening is the following:
dirty pte bits are being swept into the page dirty bit as a side effect of migration. That is, if a page had
pte_dirty(pte)set, then after migration, it will have PageDirty(page) = true.
Quoted 6 lines
Only pages with
PageDirty()set will be written to swap as part of the process of trying to clearPG_private. So, when I do the first migration, thePG_dirtybit is not set on the page, but the dirty bit is set in the pte. BecausePG_dirtyis not set, the page does not get written to swap, and the migration is fast. However, at the end of the migration process, the pages all havePG_dirtyset and the pte dirty bits are cleared.
When I wrote the migration code long ago, I didn't think about such side effects and just followed the kswapd operation.
Quoted 3 lines
I guess it seems to me that if a page has pte dirty set, but doesn't have
PG_dirtyset, then that state should be carried over to the newpage after a migration, rather than sweeping the pte dirty bit into thePG_dirtybit.
I think this is the correct solution.
--
IWAMOTO Toshihiro
--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Hi Ray,
Quoted 15 lines
Hi Hirokazu,
What appears to be happening is the following:
dirty pte bits are being swept into the page dirty bit as a side effect of migration. That is, if a page had
pte_dirty(pte)set, then after migration, it will have PageDirty(page) = true.Only pages with
PageDirty()set will be written to swap as part of the process of trying to clearPG_private. So, when I do the first migration, thePG_dirtybit is not set on the page, but the dirty bit is set in the pte. BecausePG_dirtyis not set, the page does not get written to swap, and the migration is fast. However, at the end of the migration process, the pages all havePG_dirtyset and the pte dirty bits are cleared.
Quoted 8 lines
The second time I do the migration, the
PG_dirtybits are still set (left over from the first migration), so they have to be written to swap and the migration is slow. As part of thepageout(),try_to_release_page()process, thePG_dirtyis cleared, along with the pte dirty bits, as before.When the program is resumed, it will cause the pte dirty bits to be set, and then we will be back in the situation we started with before the first migration.
In both cases, the PG_dirty flag are always set before writeback_and_free_buffers() is called, as try_to_unmap() moves the pte dirty bits to the PG_dirty on the page prior to starting the migration.
In my guess, the difference may be the PG_private flag. In the first migration, the pages may not have the PG_private flag while it may have the flag in the second time.
If the PG_dirty flag is set, Linux VM tends to make the pages have their own private data, preparing the write-back I/Os.
The scenario might be like this:
At the first time, the pages can be migrated without any I/Os as the PG_private isn't set even though the PG_dirty is set. Linux VM may set the PG_private on the pages since they have the PG_dirty.
At the second time, the write-back is required as both the PG_private and the PG_dirty are set, clearing both of the flags. At the third time, the pages don't have the PG_private and can be migrated easily.
But, this is not what we expected;(
Quoted 12 lines
Hence the third migration will be fast, and the 4th migration will be slow, etc. This is a stable, repeatable process.
I guess it seems to me that if a page has pte dirty set, but doesn't have
PG_dirtyset, then that state should be carried over to the newpage after a migration, rather than sweeping the pte dirty bit into thePG_dirtybit.Another way to do this would be to implement the migrate dirty buffers without swap I/O trick of ext2/3 in XFS, but that is somewhat far afield for me to try. :-) I'll discuss this with Nathan Scott et al and see if that is something that would be straightforward to do.
Quoted 24 lines
But I have a nagging suspicion that this covers up, rather than fixes the state transition from oldpage to newpage that really shouldn't be happening, as near as I can tell.
BTW, the program that I am testing creates a relatively large mapped file, and, as you guessed, this file is backed by XFS. Programs that just use large amounts of anonymous storage are not effected by this problem, I would imagine.
Signature · 14 lines
Best Regards, Ray ----------------------------------------------- Ray Bryant 512-453-9679 (work) 512-507-7807 (cell) [email protected] [email protected] The box said: "Requires Windows 98 or better", so I installed Linux. ----------------------------------------------- -- 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/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 6 lines · Hirokazu Takahashi
If the method isn't implemented for the page, the migration code calls
pageout()andtry_to_release_page()to releasepage->privateinstead.Which filesystem are you using? I guess it might be XFS which doesn't have the method yet.
Can we more easily detect and work around this in the code, so that this won't happen for more filesystems?
-- Dave
--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Hi,
Quoted 9 lines
Quoted 6 lines
If the method isn't implemented for the page, the migration code calls
pageout()andtry_to_release_page()to releasepage->privateinstead.Which filesystem are you using? I guess it might be XFS which doesn't have the method yet.
Can we more easily detect and work around this in the code, so that this won't happen for more filesystems?
As Ray said, the following seems to be a straight approach. I haven't had any other ideas to work around it.
ray> I guess it seems to me that if a page has pte dirty set, but doesn't have ray> PG_dirty set, then that state should be carried over to the newpage after ray> a migration, rather than sweeping the pte dirty bit into the PG_dirty bit.
The implementation might be as follows:
- to make try_to_unmap_one() record dirty bit in anywhere instead of calling set_page_dirty().
- to make touch_unmapped_address() call get_user_pages() with the record of the dirty bit.
However, we have to remember that there must exit some race conditions. For example, it may fail to restore the dirty bit since the process address spaces might be deleted during the memory migration. This may occur as the process isn't suspended during the migration.
Thanks,
Hirokazu Takahashi.
--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 9 lines · Hirokazu Takahashi
Hi,
Quoted 7 lines
Quoted 6 lines
If the method isn't implemented for the page, the migration code calls
pageout()andtry_to_release_page()to releasepage->privateinstead.Which filesystem are you using? I guess it might be XFS which doesn't have the method yet.
Quoted 7 lines
Quoted 2 lines
Can we more easily detect and work around this in the code, so that this won't happen for more filesystems?
As Ray said, the following seems to be a straight approach. I haven't had any other ideas to work around it.
From my understanding there are two problems:
1) PG_private set on file pages whose filesystems do not implement ->migrate_page() method.
Not much can be done about it, except implementing migrate_page() for all filesystems using page->private for uses other than buffer_head's.
BTW: only ext2/3 are implementing migrate_page(), all buffer_head based filesystems should do the same on a final version. Have you guys tried fs'es other than ext2/3?
Dave, I dont understand what you mean with "workaround". The page is not migratable, thus the memory area which contains it can't be migrated either.
2) PG_dirty bit set on anonymous pages which have been migrated.
Quoted 3 lines
ray> I guess it seems to me that if a page has pte dirty set, but doesn't have ray>
PG_dirtyset, then that state should be carried over to the newpage after ray> a migration, rather than sweeping the pte dirty bit into thePG_dirtybit.
The dirty bit is set by swap allocation and freeing code.
Quoted 5 lines
The implementation might be as follows:
- to maketry_to_unmap_one()record dirty bit in anywhere instead of callingset_page_dirty().
- to maketouch_unmapped_address()callget_user_pages()with the record of the dirty bit.
Quoting Ray:
"Checking /proc/vmstat/pgpgout appears to indicate that the pages I am migrating are being swapped out when I see the migration slow down, although something is fishy with pgpgout."
Anonymous pages seem to the problem Ray is seeing, except (1) which vanishes with ext2/ext3 as he reports.
Anon pages _should_ be removed from the swapcache at the end of generic_migrate_page (__remove_exclusive_swap_page()).
So, it does not matter if they have PG_dirty bit set, as long as they are not swap-allocated (PageSwapCache).
Ray, please confirm that anon pages are removed from the swapcache after being migrated (watching /proc/meminfo should do it).
One point is that if free memory is below the safe watermarks, the system will vmscan, allocating swap & writing out, which is expected.
How much memory is free during said tests?
Quoted 4 lines
However, we have to remember that there must exit some race conditions. For example, it may fail to restore the dirty bit since the process address spaces might be deleted during the memory migration. This may occur as the process isn't suspended during the migration.
The PG_dirty bit is set, by the migration code, for anonymous pages only.
That said, I see no need to reset PG_dirty in case it was not set before migration, as you propose.
--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
At Thu, 14 Apr 2005 12:57:34 -0300,
Quoted 17 lines · Marcelo Tosatti
On Wed, Apr 13, 2005 at 07:48:00PM +0900, Hirokazu Takahashi wrote:
2)
PG_dirtybit set on anonymous pages which have been migrated.Quoted 3 lines
ray> I guess it seems to me that if a page has pte dirty set, but doesn't have ray>
PG_dirtyset, then that state should be carried over to the newpage after ray> a migration, rather than sweeping the pte dirty bit into thePG_dirtybit.The dirty bit is set by swap allocation and freeing code.
Quoted 5 lines
The implementation might be as follows:
- to maketry_to_unmap_one()record dirty bit in anywhere instead of callingset_page_dirty().
- to maketouch_unmapped_address()callget_user_pages()with the record of the dirty bit.
Quoted 7 lines
Quoting Ray:
"Checking/proc/vmstat/pgpgoutappears to indicate that the pages I am migrating are being swapped out when I see the migration slow down, although something is fishy with pgpgout."Anonymous pages seem to the problem Ray is seeing, except (1) which vanishes with ext2/ext3 as he reports.
I think Ray is using the word "swap" to mean "page out" and anonymous pages are irrelevant here, judging from his another mail (quoted below).
At Tue, 12 Apr 2005 00:43:42 -0500,
Ray Bryant wrote:
: BTW, the program that I am testing creates a relatively large mapped file, : and, as you guessed, this file is backed by XFS. Programs that just use : large amounts of anonymous storage are not effected by this problem, I : would imagine.
Quoted 2 lines
One point is that if free memory is below the safe watermarks, the system will vmscan, allocating swap & writing out, which is expected.
If there are enough RAM, mmaped dirty pages shouldn't be written back. However, memory migration triggers writebacks.
Quoted 6 lines
Quoted 4 lines
However, we have to remember that there must exit some race conditions. For example, it may fail to restore the dirty bit since the process address spaces might be deleted during the memory migration. This may occur as the process isn't suspended during the migration.
The
PG_dirtybit is set, by the migration code, for anonymous pages only.
If a file page is mmaped and its PTE is dirty, the page gets PG_dirty bit when it is unmapped.
Quoted 2 lines
That said, I see no need to reset
PG_dirtyin case it was not set before migration, as you propose.
I think PG_dirty should be reset, as the side effect is probably unacceptable for Ray's application. It would be a bit more complicated than just changing page and PTE bits, but I think it's doable.
--
IWAMOTO Toshihiro
--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Hi Toshihiro,
Quoted 24 lines · IWAMOTO Toshihiro
At Thu, 14 Apr 2005 12:57:34 -0300,
Quoted 22 lines · Marcelo Tosatti
On Wed, Apr 13, 2005 at 07:48:00PM +0900, Hirokazu Takahashi wrote:
2)
PG_dirtybit set on anonymous pages which have been migrated.Quoted 3 lines
ray> I guess it seems to me that if a page has pte dirty set, but doesn't have ray>
PG_dirtyset, then that state should be carried over to the newpage after ray> a migration, rather than sweeping the pte dirty bit into thePG_dirtybit.The dirty bit is set by swap allocation and freeing code.
Quoted 5 lines
The implementation might be as follows:
- to maketry_to_unmap_one()record dirty bit in anywhere instead of callingset_page_dirty().
- to maketouch_unmapped_address()callget_user_pages()with the record of the dirty bit.Quoting Ray:
"Checking/proc/vmstat/pgpgoutappears to indicate that the pages I am migrating are being swapped out when I see the migration slow down, although something is fishy with pgpgout."
Quoted 5 lines
Quoted 2 lines
Anonymous pages seem to the problem Ray is seeing, except (1) which vanishes with ext2/ext3 as he reports.
I think Ray is using the word "swap" to mean "page out" and anonymous pages are irrelevant here, judging from his another mail (quoted below).
Ah, OK.
Quoted 18 lines
At Tue, 12 Apr 2005 00:43:42 -0500,
Ray Bryant wrote:
: BTW, the program that I am testing creates a relatively large mapped file, : and, as you guessed, this file is backed by XFS. Programs that just use : large amounts of anonymous storage are not effected by this problem, I : would imagine.Quoted 2 lines
One point is that if free memory is below the safe watermarks, the system will vmscan, allocating swap & writing out, which is expected.
If there are enough RAM, mmaped dirty pages shouldn't be written back. However, memory migration triggers writebacks.
Quoted 5 lines
Quoted 4 lines
However, we have to remember that there must exit some race conditions. For example, it may fail to restore the dirty bit since the process address spaces might be deleted during the memory migration. This may occur as the process isn't suspended during the migration.
Quoted 4 lines
Quoted 1 line
The
PG_dirtybit is set, by the migration code, for anonymous pages only.If a file page is mmaped and its PTE is dirty, the page gets
PG_dirtybit when it is unmapped.
Right.
Quoted 7 lines
Quoted 2 lines
That said, I see no need to reset
PG_dirtyin case it was not set before migration, as you propose.I think
PG_dirtyshould be reset, as the side effect is probably unacceptable for Ray's application. It would be a bit more complicated than just changing page and PTE bits, but I think it's doable.
Yes, makes sense.
Question: Who is causing the writeouts here?
Is there memory pressure or is it pdflush?
Its not the migration code? (that would be a problem I think). --
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Hi,
At Fri, 15 Apr 2005 09:53:55 -0300,
Quoted 12 lines · Marcelo Tosatti
Quoted 10 lines · IWAMOTO Toshihiro
At Thu, 14 Apr 2005 12:57:34 -0300,
Quoted 2 lines · Marcelo Tosatti
That said, I see no need to reset
PG_dirtyin case it was not set before migration, as you propose.I think
PG_dirtyshould be reset, as the side effect is probably unacceptable for Ray's application. It would be a bit more complicated than just changing page and PTE bits, but I think it's doable.
Quoted 7 lines
Yes, makes sense.
Question: Who is causing the writeouts here?
Is there memory pressure or is it pdflush?
Its not the migration code? (that would be a problem I think).
If I understand correctly, writebacks happen in the following way.
1. The migration code unmaps dirty PTEs.
2. try_to_unmap() calls set_page_dirty() for such pages, setting PG_dirty and the dirty radix tree tag.
3. When pdflush is woken, it calls do_writepages().
4. At least for ext2 (I assume it is true for most file systems), do_writepage() calls result in mpage_writepages() calls, which scan radix trees for dirty tags.
--
IWAMOTO Toshihiro
--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Hirokazu et al,
I'm sorry, I've been kind of out of the loop here since last Wenesday (that's the day I left Austin to fly to Melbourne, Australia which is where I am now, visiting the SGI lab in Melbourne).
Nathan Scott (who works at SGI Melbourne) looked at the ext2/ext3 migrate_page code and realized that basically the same implementation would work for xfs. So I now have a kernel that implements that function for xfs and, as you predicted, the "slow down" in the 2nd migration that I was seeing before has gone away. I'll add Nathan's patch to my manual page migration stuff in the next version (later this week, I hope).
So I guess it doesn't matter to me at the moment whether or not the PG_dirty bit is set on the pages, except that I philosphically dislike the fact that migration changes the state of the page. I'm not sure it matters, but I would prefer it if this didn't happen. However, I'm not adamant about this, since what I really want to happen is to have a functioning manual page migration system call. It does seem to be a bother to have to add that migrate_page method to each file system, since in most cases the addition is going to look somewhat like it does for ext2/3. For xfs, Nathan did add an additional bit to make sure that xfs metadata pages were not considered migratable.
WRT, Marcelo's question as to who is causing the page out I/O to occur during migration, let me go back and verify this is actually what is happening.
Otherwise, is there a consensus about what to do about the PG_dirty bits being set on the migrated pages? As I read things Marcelo says it is not worth it, but others think that it should be fixed?
Signature · 12 lines
----------------------------------------------- Ray Bryant 512-453-9679 (work) 512-507-7807 (cell) [email protected] [email protected] The box said: "Requires Windows 98 or better", so I installed Linux. ----------------------------------------------- -- 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/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Ray,
Quoted 14 lines · Ray Bryant
Hirokazu et al,
I'm sorry, I've been kind of out of the loop here since last Wenesday (that's the day I left Austin to fly to Melbourne, Australia which is where I am now, visiting the SGI lab in Melbourne).
Nathan Scott (who works at SGI Melbourne) looked at the ext2/ext3
migrate_pagecode and realized that basically the same implementation would work for xfs. So I now have a kernel that implements that function for xfs and, as you predicted, the "slow down" in the 2nd migration that I was seeing before has gone away. I'll add Nathan's patch to my manual page migration stuff in the next version (later this week, I hope).
Quoted 9 lines
So I guess it doesn't matter to me at the moment whether or not the
PG_dirtybit is set on the pages, except that I philosphically dislike the fact that migration changes the state of the page. I'm not sure it matters, but I would prefer it if this didn't happen. However, I'm not adamant about this, since what I really want to happen is to have a functioning manual page migration system call. It does seem to be a bother to have to add thatmigrate_pagemethod to each file system, since in most cases the addition is going to look somewhat like it does for ext2/3.
One could create "block_migrate_page()" in fs/buffer.c so to void migrate_page definition on each filesystem which uses buffer_head's.
But all address_space_operations need to be updated anyway.
Quoted 11 lines
For xfs, Nathan did add an additional bit to make sure that xfs metadata pages were not considered migratable.
WRT, Marcelo's question as to who is causing the page out I/O to occur during migration, let me go back and verify this is actually what is happening.
Otherwise, is there a consensus about what to do about the
PG_dirtybits being set on the migrated pages? As I read things Marcelo says it is not worth it, but others think that it should be fixed?
Dirty mmaped file pages will have their dirty tag migrated from ptes to pages via unmapping (try_to_unmap), which causes pdflush to sync these pages when their inodes get aged, as Toshihiro notices.
I dislike the idea of "saving the dirty state to reinstantiate it later", but, it seems its the only way of avoiding the dirty mmaped file writeouts.
--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 17 lines · Hirokazu Takahashi
I understand what happened on your machine.
PG_privateis a filesystem specific flag, setting some filesystem depending data inpage->private. When the flag is set on a page, only the local filesystem on which the page depends can handle it.Most of the filesystems uses
page->privateto manage buffers while others may use it for different purposes. Each filesystem can implementmigrate_pagemethod to handlespage->private. At this moment, only ext2 and ext3 have this method, which migrates buffers without any I/Os.If the method isn't implemented for the page, the migration code calls
pageout()andtry_to_release_page()to releasepage->privateinstead.
Quoted 6 lines
Which filesystem are you using? I guess it might be XFS which doesn't have the method yet.
Thank you,
Hirokazu Takahashi.
Hi Hirakazu,
Just to make sure, I re-ran my test case with the test program's home directory (and hence where its mapped files reside) on an ext3 file system instead of on XFS. In this case, the migrations are all fast; however, there are still significant number of page I/O's occuring (135 MB worth, I am migrating 138 MB). So it doesn't appear that an I/O-less migration is going on here either.
Signature · 14 lines
Best Regards,
Ray
-----------------------------------------------
Ray Bryant
512-453-9679 (work) 512-507-7807 (cell)
[email protected] [email protected]
The box said: "Requires Windows 98 or better",
so I installed Linux.
-----------------------------------------------
--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>Quoted 8 lines · Marcelo Tosatti
Who is using the page?
A little debugging might help similar to what
bad_pagedoes can help:printk(KERN_EMERG "flags:0x%0*lx mapping:%p mapcount:%d count:%d\n", (int)(2*sizeof(page_flags_t)), (unsigned long)page->flags, page->mapping, page_mapcount(page), page_count(page));--
Marcello,
I wrote:
"PagePrivate() is cleared by truncation specific code in migrate_onepage(), but it doesn't appear to be cleared (directly) by code on the generic_migrate_page() patch. I wonder if this has something to do with the problem I am seeing. "
Ooops. I didn't look deep enough. migrate_page_common() calls writeback_and_free_buffers(), which in turn calls try_to_release_page() which will eventually call down to __clear_page_buffers() which will clear PagePrivate().
So it looks like the following is perhaps what is happening:
(1) We come into migrate_one_page() with the pages dirty. (The first time we enter the -EAGAIN section of migate_page_common() we have flags = 105d, the last time through before succeeding, flags are 104d, and when we do return flags=004d.
(2) We have to wait around until the pages get paged out before we can
migrated them. (flags=004d).
I'll have to check and see if I believe it might take 3 minutes to page out all of the pages of my application. If so, then this explains what is happening.
Does that make sense?
Signature · 14 lines
Best Regards,
Ray
-----------------------------------------------
Ray Bryant
512-453-9679 (work) 512-507-7807 (cell)
[email protected] [email protected]
The box said: "Requires Windows 98 or better",
so I installed Linux.
-----------------------------------------------
--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>Marcello,
Checking /proc/vmstat/pgpgout appears to indicate that the pages I am migrating are being swapped out when I see the migration slow down, although something is fishy with pgpgout. pgpgout is supposed to be KB of page I/O, but I know that I am migrating 8685 pages, at 16KB/page, or 138960 KB. pgpgout gets incremented by roughly twice this. So it looks like either:
(1) pgpgout is really sectors written, or
(2) pages are being paged out twice as part of memory migration.
I still don't understand why this pageout process doesn't happen every time I do a migration (e. g. never on the first time), and why it is taking 210 s to page out 138960 K. That's around 600 KB/s of I/O to the paging disk.
Signature · 14 lines
Best Regards,
Ray
-----------------------------------------------
Ray Bryant
512-453-9679 (work) 512-507-7807 (cell)
[email protected] [email protected]
The box said: "Requires Windows 98 or better",
so I installed Linux.
-----------------------------------------------
--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>Hirokazu (and Marcelo),
A little more information on this. The first time I migrate the test process, the migration is quite rapid. The next time I migrate the same process (to a new set of nodes, or back to the old set of nodes where it came from), it is quite slow, and the migration remains this way, albeit with widely varying times (e. g. 40s to 220 s), from that point forward.
I'm wondering if the page state is not being set quite correctly in the migrated pages, thus causing needless waiting in migrate_page_common() when the pages are migrated for a second time.
Signature · 14 lines
Best Regards,
Ray
-----------------------------------------------
Ray Bryant
512-453-9679 (work) 512-507-7807 (cell)
[email protected] [email protected]
The box said: "Requires Windows 98 or better",
so I installed Linux.
-----------------------------------------------
--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>