fix page_count in ->iomap_migrate_page()
Subsystems (2)
PATCH 1/1 fix page_count in ->iomap_migrate_page()
IOMAP uses PG_private a little different with buffer_head based filesystem.
It uses it as marker and when set, the page counter is not incremented, migrate_page_move_mapping() assumes that PG_private indicates a counter of +1.
so, we have to pass a extra count of -1 to migrate_page_move_mapping() if the flag is set.
--- fs/iomap.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
fs/iomap.c +10 -1
@@ -544,8 +544,17 @@ iomap_migrate_page(struct address_space *mapping, struct page *newpage, struct page *page, enum migrate_mode mode) { int ret; +int extra_count =0 ; - ret =migrate_page_move_mapping (mapping, newpage, page,NULL , mode,0 ); +/* +* IOMAP uses PG_private as marker and does not raise the page counter. +* migrate_page_move_mapping() expects a incremented counter if PG_private +* is set. Therefore pass -1 as extra_count for this case. +*/ +if (page_has_private (page)) + extra_count =-1 ; + ret =migrate_page_move_mapping (mapping, newpage, page, +NULL , mode, extra_count);if (ret !=MIGRATEPAGE_SUCCESS )return ret;
Signature · 1 line
2.7.4
[CC'ing authors of the code plus mm folks]
Am Freitag, 14. Dezember 2018, 06:56:01 CET schrieb zhangjun:
Quoted 25 lines
IOMAP uses
PG_privatea little different withbuffer_headbased filesystem.
It uses it as marker and when set, the page counter is not incremented,migrate_page_move_mapping()assumes thatPG_privateindicates a counter of +1.
so, we have to pass a extra count of -1 tomigrate_page_move_mapping()if the flag is set.Signed-off-by zhangjun <[email protected]>--- fs/iomap.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)fs/iomap.c +2
-1@@ -544,8 +544,17 @@ iomap_migrate_page(struct address_space *mapping, struct page *newpage, struct page *page, enum migrate_mode mode) {int ret; +int extra_count =0 ; - ret =migrate_page_move_mapping (mapping, newpage, page,NULL , mode,0 ); +/*
fs/iomap.c iomap_migrate_page(struct address_space *mapping, struct page *newpage, · line 559
Quoted 10 lines
fs/iomap.c +8
-0+* IOMAP uses PG_private as marker and does not raise the page counter. +* migrate_page_move_mapping() expects a incremented counter if PG_private +* is set. Therefore pass -1 as extra_count for this case. +*/ +if (page_has_private (page)) + extra_count =-1 ; + ret =migrate_page_move_mapping (mapping, newpage, page, +NULL , mode, extra_count);if (ret !=MIGRATEPAGE_SUCCESS )return ret;
This is the third place which needs this workaround. UBIFS, F2FS, and now iomap.
I agree with Dave that nobody can assume that PG_private implies an additional page reference.
But page migration does that. Including parts of the write back code.
Thanks,
//richard
Hi Richard,
Quoted 6 lines · Richard Weinberger
This is the third place which needs this workaround. UBIFS, F2FS, and now iomap.
I agree with Dave that nobody can assume that
PG_privateimplies an additional page reference.
But page migration does that. Including parts of the write back code.
It seems that it's clearly documented in
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/linux/mm.h#n780
* A pagecache page contains an opaque `private' member, which belongs to the
* page's address_space. Usually, this is the address of a circular list of
* the page's disk buffers. PG_private must be set to tell the VM to call
* into the filesystem to release these pages.
*
* A page may belong to an inode's memory mapping. In this case, page->mapping
* is the pointer to the inode, and page->index is the file offset of the page,
* in units of PAGE_SIZE.
*
* If pagecache pages are not associated with an inode, they are said to be
* anonymous pages. These may become associated with the swapcache, and in that
* case PG_swapcache is set, and page->private is an offset into the swapcache. *
* In either case (swapcache or inode backed), the pagecache itself holds one
* reference to the page. Setting PG_private should also increment the
* refcount. The each user mapping also has a reference to the page.
and when I looked into that, I found
https://lore.kernel.org/lkml/[email protected]/
Thanks,
Gao Xiang
Am Freitag, 14. Dezember 2018, 13:26:28 CET schrieb Gao Xiang:
Quoted 30 lines
Hi Richard,
Quoted 6 lines · Richard Weinberger
This is the third place which needs this workaround. UBIFS, F2FS, and now iomap.
I agree with Dave that nobody can assume that
PG_privateimplies an additional page reference.
But page migration does that. Including parts of the write back code.It seems that it's clearly documented in
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/linux/mm.h#n780* A pagecache page contains an opaque `private' member, which belongs to the
* page'saddress_space. Usually, this is the address of a circular list of
* the page's disk buffers.PG_privatemust be set to tell the VM to call
* into the filesystem to release these pages.
*
* A page may belong to an inode's memory mapping. In this case,page->mapping
* is the pointer to the inode, andpage->indexis the file offset of the page,
* in units ofPAGE_SIZE.
*
* If pagecache pages are not associated with an inode, they are said to be
* anonymous pages. These may become associated with the swapcache, and in that
* casePG_swapcacheis set, andpage->privateis an offset into the swapcache. *
* In either case (swapcache or inode backed), the pagecache itself holds one
* reference to the page. SettingPG_privateshould also increment the
* refcount. The each user mapping also has a reference to the page.
Quoted 2 lines
and when I looked into that, I found
https://lore.kernel.org/lkml/[email protected]/
Hmm, in case of UBIFS it seems easy. We can add a get/put_page() around setting/clearing the flag.
I did that now and so far none of my tests exploded.
Artem, do you remember why UBIFS never raised the page counter when setting PG_private?
Thanks,
//richard
Hi Richard,
Quoted 3 lines · Richard Weinberger
Hmm, in case of UBIFS it seems easy. We can add a get/put_page() around setting/clearing the flag.
I did that now and so far none of my tests exploded.
Yes, many existed codes are based on this restriction in order to be freeable race-free. and that's it since PG_Private was once introduced at first by Andrew Morton in 2002 for many Linux versions....and it's not bad I think... :)
Thanks,
Gao Xiang
Quoted 10 lines · zhangjun
IOMAP uses
PG_privatea little different withbuffer_headbased filesystem.
It uses it as marker and when set, the page counter is not incremented,migrate_page_move_mapping()assumes thatPG_privateindicates a counter of +1.
so, we have to pass a extra count of -1 tomigrate_page_move_mapping()if the flag is set.Signed-off-by zhangjun <[email protected]>---
I found that it fixed in
https://patchwork.kernel.org/patch/10684835/
and has been merged in
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=61c6de667263184125d5ca75e894fcad632b0dd3
It seems it has been corrected by Piotr.
Thanks,
Gao Xiang
FYI, for iomap we got a patch to just increment the page count when setting the private data, and it finally got merged into mainline after a while.
Not that it totally makes sense to me, but it is what it is. It would just be nice if set_page_private took care of it and we had a clear_page_private to undo it, making the whole scheme at lot more obvious.
Am Samstag, 15. Dezember 2018, 11:51:12 CET schrieb Christoph Hellwig:
Quoted 8 lines
FYI, for iomap we got a patch to just increment the page count when setting the private data, and it finally got merged into mainline after a while.
Not that it totally makes sense to me, but it is what it is. It would just be nice if
set_page_privatetook care of it and we had aclear_page_privateto undo it, making the whole scheme at lot more obvious.
Yeah, UBIFS will go the same route. I have already a patch prepared which increments the page count when UBIFS sets PG_private.
Thanks,
//richard