erofs: fix setting up pcluster for temporary pages
Subsystems (2)
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH 1/4 erofs: fix setting up pcluster for temporary pages
From: Gao Xiang <[email protected]>
pcluster should be only set up for all managed pages instead of temporary pages. Since it currently uses page->mapping to identify, the impact is minor for now.
--- fs/erofs/zdata.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
fs/erofs/zdata.c +5 -2
@@ -1078,8 +1078,11 @@ static struct page *pickup_page_for_submission(struct z_erofs_pcluster *pcl,cond_resched (); goto repeat; } -set_page_private (page, (unsigned long )pcl); -SetPagePrivate (page); + +if (tocache) { +set_page_private (page, (unsigned long )pcl); +SetPagePrivate (page); + } out:/* the only exit (for tracing and debugging) */ return page; }
Signature · 1 line
2.24.0
PATCH 2/4 erofs: get rid of magical Z_EROFS_MAPPING_STAGING
From: Gao Xiang <[email protected]>
Previously, we played around with magical page->mapping for short-lived temporary pages since we need to identify different types of pages in the same pcluster but both invalidated and short-lived temporary pages can have page->mapping == NULL. It was considered as safe because temporary pages are all non-LRU / non-movable pages.
This patch tends to use specific page->private to identify short-lived pages instead so it won't rely on page->mapping anymore. Details are described in "compress.h" as well.
---
prelimitary test is done. will do stress test then.
fs/erofs/compress.h | 50 ++++++++++++++++++++++++++++++----------- fs/erofs/decompressor.c | 2 +- fs/erofs/zdata.c | 42 +++++++++++++++++++++------------- fs/erofs/zdata.h | 1 + 4 files changed, 65 insertions(+), 30 deletions(-)
fs/erofs/compress.h +37 -13
@@ -26,30 +26,54 @@ struct z_erofs_decompress_req {bool inplace_io, partial_decoding; }; +#define Z_EROFS_SHORTLIVED_PAGE (-1UL << 2) +/* -* - 0x5A110C8D ('sallocated', Z_EROFS_MAPPING_STAGING) - -* used to mark temporary allocated pages from other -* file/cached pages and NULL mapping pages. +* For all pages in a pcluster, page->private should be one of +* Type Last 2bits page->private +* short-lived page 00 Z_EROFS_SHORTLIVED_PAGE +* cached/managed page 00 pointer to z_erofs_pcluster +* online page (file-backed, 01/10/11 sub-index << 2 | count +* some pages can be used for inplace I/O) +* +* page->mapping should be one of +* Type page->mapping +* short-lived page NULL +* cached/managed page non-NULL or NULL (invalidated/truncated page) +* online page non-NULL +* +* For all managed pages, PG_private should be set with 1 extra refcount, +* which is used for page reclaim / migration. */ -#define Z_EROFS_MAPPING_STAGING ((void *)0x5A110C8D) -/* check if a page is marked as staging */ -static inline bool z_erofs_page_is_staging (struct page *page) +/* +* short-lived pages are pages directly from buddy system with specific +* page->private (no need to set PagePrivate since these are non-LRU / +* non-movable pages and bypass reclaim / migration code). +*/ +static inline bool z_erofs_is_shortlived_page (struct page *page) { -return page->mapping ==Z_EROFS_MAPPING_STAGING ; +if (page->private !=Z_EROFS_SHORTLIVED_PAGE ) +return false; + +DBG_BUGON (page->mapping); +return true; } -static inline bool z_erofs_put_stagingpage (struct list_head *pagepool, -struct page *page) +static inline bool z_erofs_put_shortlivedpage (struct list_head *pagepool, +struct page *page) { -if (!z_erofs_page_is_staging (page)) +if (!z_erofs_is_shortlived_page (page))return false; -/* staging pages should not be used by others at the same time */ -if (page_ref_count (page) >1 ) +/* short-lived pages should not be used by others at the same time */ +if (page_ref_count (page) >1 ) {put_page (page); -else + }else { +/* follow the pcluster rule above. */ +set_page_private (page,0 );list_add (&page->lru, pagepool); + }return true; }
fs/erofs/decompressor.c +1 -1
@@ -76,7 +76,7 @@ static int z_erofs_lz4_prepare_destpages(struct z_erofs_decompress_req *rq, victim =erofs_allocpage (pagepool,GFP_KERNEL );if (!victim)return -ENOMEM ; - victim->mapping =Z_EROFS_MAPPING_STAGING ; +set_page_private (victim,Z_EROFS_SHORTLIVED_PAGE ); } rq->out[i] = victim; }
fs/erofs/zdata.c +26 -16
121 lines not on this page · raw message
fs/erofs/zdata.h +1 -0
@@ -173,6 +173,7 @@ static inline void z_erofs_onlinepage_endio(struct page *page) v =atomic_dec_return (u.o);if (!(v &Z_EROFS_ONLINEPAGE_COUNT_MASK )) { +set_page_private (page,0 );ClearPagePrivate (page);if (!PageError (page))SetPageUptodate (page);
Signature · 1 line
2.24.0
PATCH 3/4 erofs: insert to managed cache after adding to pcl
In reply to Gao XiangFrom: Gao Xiang <[email protected]>
Previously, it could be some concern to call add_to_page_cache_lru() with page->mapping == Z_EROFS_MAPPING_STAGING (!= NULL).
In contrast, page->private is used instead now, so partially revert commit 5ddcee1f3a1c ("erofs: get rid of __stagingpage_alloc helper") with some adaption for simplicity.
--- fs/erofs/zdata.c | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-)
fs/erofs/zdata.c +7 -16
@@ -1071,28 +1071,19 @@ static struct page *pickup_page_for_submission(struct z_erofs_pcluster *pcl,put_page (page); out_allocpage: page =erofs_allocpage (pagepool, gfp | __GFP_NOFAIL); -if (!tocache ||add_to_page_cache_lru (page, mc, index + nr, gfp)) { -/* turn into temporary page if fails */ -set_page_private (page,Z_EROFS_SHORTLIVED_PAGE ); - tocache = false; - } -if (oldpage !=cmpxchg (&pcl->compressed_pages[nr], oldpage, page)) { -if (tocache) { -/* since it added to managed cache successfully */ -unlock_page (page); -put_page (page); - }else { -list_add (&page->lru, pagepool); - } +list_add (&page->lru, pagepool);cond_resched (); goto repeat; } -if (tocache) { -set_page_private (page, (unsigned long )pcl); -SetPagePrivate (page); +if (!tocache ||add_to_page_cache_lru (page, mc, index + nr, gfp)) { +/* turn into temporary page if fails */ +set_page_private (page,Z_EROFS_SHORTLIVED_PAGE ); + goto out; } +set_page_private (page, (unsigned long )pcl); +SetPagePrivate (page); out:/* the only exit (for tracing and debugging) */ return page; }
Signature · 1 line
2.24.0
PATCH 4/4 erofs: complete a missing case for inplace I/O
In reply to Gao XiangFrom: Gao Xiang <[email protected]>
Add a missing case which could cause unnecessary page allocation but not directly use inplace I/O instead, which increases runtime extra memory footprint.
The detail is, considering a file-backed page, the right half of the page is chosen to be cached (e.g. the end page) and some of its data doesn't exist in managed cache, so the pcluster will be kept in the submission chain. (In other words, it cannot be decompressed in advance, for example, due to the bypass chain).
Currently, the pcluster for this case is downgraded as NOINPLACE, and stop the left half of the page from doing inplace I/O (so an extra page allocation is needed then.)
Let's avoid such unnecessary downgrade instead.
--- fs/erofs/zdata.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-)
fs/erofs/zdata.c +17 -5
@@ -160,7 +160,8 @@ static void preload_compressed_pages(struct z_erofs_collector *clt,const unsigned int clusterpages =BIT (pcl->clusterbits);struct page **pages = clt->compressedpages;pgoff_t index = pcl->obj.index + (pages - pcl->compressed_pages); -bool standalone = true; +bool io_cant_bypass = false; +bool updated = false;if (clt->mode <COLLECT_PRIMARY_FOLLOWED )return ;
@@ -180,20 +181,31 @@ static void preload_compressed_pages(struct z_erofs_collector *clt, }else if (type ==DELAYEDALLOC ) { t =tagptr_init (compressed_page_t,PAGE_UNALLOCATED ); }else {/* DONTALLOC */ -if (standalone) +/* update to first inplace I/O page */ +if (!updated) { clt->compressedpages = pages; - standalone = false; + updated = true; + } + io_cant_bypass = true;continue ; } -if (!cmpxchg_relaxed (pages,NULL ,tagptr_cast_ptr (t))) +if (!cmpxchg_relaxed (pages,NULL ,tagptr_cast_ptr (t))) { +if (type ==DELAYEDALLOC ) + io_cant_bypass = true;continue ; + }if (page)put_page (page); } -if (standalone)/* downgrade to PRIMARY_FOLLOWED_NOINPLACE */ +/* +* for COLLECT_PRIMARY_FOLLOWED pcluster, if all managed pages have +* been found (which means it can be handled without submittng I/O) +* it's unsafe to do inplace I/O. let's downgrade to NOINPLACE instead. +*/ +if (!io_cant_bypass) clt->mode =COLLECT_PRIMARY_FOLLOWED_NOINPLACE ; }
Signature · 1 line
2.24.0
Hello Gao Xiang,
Quoted 9 lines · Gao Xiang via Linux-erofs
From: Gao Xiang <[email protected]>
pcluster should be only set up for all managed pages instead of temporary pages. Since it currently uses
page->mappingto identify, the impact is minor for now.Fixes 5ddcee1f3a1c ("erofs: get rid of __stagingpage_alloc helper")Cc <[email protected]> # 5.5+Signed-off-by Gao Xiang <[email protected]>
I was looking exactly at this problem recently, my change is one-to-one to your fix, thus I can provide a tag:
The fixed problem is minor, but the kernel log becomes polluted, if a page allocation debug option is enabled:
% md5sum ~/erofs/testfile
BUG: Bad page state in process kworker/u9:0 pfn:687de
page:0000000057b8bcb4 refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x687de
flags: 0x4000000000002000(private)
raw: 4000000000002000 dead000000000100 dead000000000122 0000000000000000
raw: 0000000000000000 ffff888066758690 00000000ffffffff 0000000000000000
page dumped because: PAGE_FLAGS_CHECK_AT_FREE flag(s) set
Modules linked in:
CPU: 1 PID: 602 Comm: kworker/u9:0 Not tainted 5.9.1 #2
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.13.0-1 04/01/2014
Workqueue: erofs_unzipd z_erofs_decompressqueue_work
Call Trace:
dump_stack+0x84/0xba
bad_page.cold+0xac/0xb1
check_free_page_bad+0xb0/0xc0
free_pcp_prepare+0x2c8/0x2d0
free_unref_page+0x18/0xf0
put_pages_list+0x11a/0x120
z_erofs_decompressqueue_work+0xc9/0x110
? z_erofs_decompress_pcluster.isra.0+0xf10/0xf10
? read_word_at_a_time+0x12/0x20
? strscpy+0xc7/0x1a0
process_one_work+0x30c/0x730
worker_thread+0x91/0x640
? __kasan_check_read+0x11/0x20
? rescuer_thread+0x8a0/0x8a0
kthread+0x1dd/0x200
? kthread_unpark+0xa0/0xa0
ret_from_fork+0x1f/0x30
Disabling lock debugging due to kernel taint--
Best wishes,
Vladimir
Hi Vladimir,
Quoted 9 lines · Vladimir Zapolskiy
Hello Gao Xiang,
Quoted 6 lines · Gao Xiang via Linux-erofs
From: Gao Xiang <[email protected]>
pcluster should be only set up for all managed pages instead of temporary pages. Since it currently uses
page->mappingto identify, the impact is minor for now.
Quoted 8 lines
Quoted 3 lines
Fixes 5ddcee1f3a1c ("erofs: get rid of __stagingpage_alloc helper")Cc <[email protected]> # 5.5+Signed-off-by Gao Xiang <[email protected]>I was looking exactly at this problem recently, my change is one-to-one to your fix, thus I can provide a tag:
Tested-by Vladimir Zapolskiy <[email protected]>
Many thanks for confirming this!
I found this when I was killing magical stagingpage page->mapping, it's somewhat late :-)
Quoted 27 lines
The fixed problem is minor, but the kernel log becomes polluted, if a page allocation debug option is enabled:
% md5sum ~/erofs/testfile BUG: Bad page state in process kworker/u9:0 pfn:687de page:0000000057b8bcb4 refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x687de flags: 0x4000000000002000(private) raw: 4000000000002000 dead000000000100 dead000000000122 0000000000000000 raw: 0000000000000000 ffff888066758690 00000000ffffffff 0000000000000000 page dumped because: PAGE_FLAGS_CHECK_AT_FREE flag(s) set Modules linked in: CPU: 1 PID: 602 Comm: kworker/u9:0 Not tainted 5.9.1 #2 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.13.0-1 04/01/2014 Workqueue: erofs_unzipd z_erofs_decompressqueue_work Call Trace: dump_stack+0x84/0xba bad_page.cold+0xac/0xb1 check_free_page_bad+0xb0/0xc0 free_pcp_prepare+0x2c8/0x2d0 free_unref_page+0x18/0xf0 put_pages_list+0x11a/0x120 z_erofs_decompressqueue_work+0xc9/0x110 ? z_erofs_decompress_pcluster.isra.0+0xf10/0xf10 ? read_word_at_a_time+0x12/0x20 ? strscpy+0xc7/0x1a0
Quoted 8 lines
process_one_work+0x30c/0x730
worker_thread+0x91/0x640
? __kasan_check_read+0x11/0x20
? rescuer_thread+0x8a0/0x8a0
kthread+0x1dd/0x200
? kthread_unpark+0xa0/0xa0
ret_from_fork+0x1f/0x30
Disabling lock debugging due to kernel taintYeah, I can make a pull-request to Linus if you need this to be in master now, or I can post it for v5.11-rc1 since 5.4 LTS isn't effected (and it would be only a print problem with debugging option.)
Thanks,
Gao Xiang
Quoted 5 lines
--
Best wishes,
Vladimir
Hi Gao Xiang,
Quoted 16 lines · Gao Xiang
Hi Vladimir,
Quoted 13 lines · Vladimir Zapolskiy
Hello Gao Xiang,
Quoted 9 lines · Gao Xiang via Linux-erofs
From: Gao Xiang <[email protected]>
pcluster should be only set up for all managed pages instead of temporary pages. Since it currently uses
page->mappingto identify, the impact is minor for now.Fixes 5ddcee1f3a1c ("erofs: get rid of __stagingpage_alloc helper")Cc <[email protected]> # 5.5+Signed-off-by Gao Xiang <[email protected]>
Quoted 9 lines
Quoted 4 lines
I was looking exactly at this problem recently, my change is one-to-one to your fix, thus I can provide a tag:
Tested-by Vladimir Zapolskiy <[email protected]>Many thanks for confirming this!
I found this when I was killing magical stagingpagepage->mapping, it's somewhat late :-)
sure, for me it was an exciting immersion into the filesystem code :)
Quoted 36 lines
Quoted 27 lines
The fixed problem is minor, but the kernel log becomes polluted, if a page allocation debug option is enabled:
% md5sum ~/erofs/testfile BUG: Bad page state in process kworker/u9:0 pfn:687de page:0000000057b8bcb4 refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x687de flags: 0x4000000000002000(private) raw: 4000000000002000 dead000000000100 dead000000000122 0000000000000000 raw: 0000000000000000 ffff888066758690 00000000ffffffff 0000000000000000 page dumped because: PAGE_FLAGS_CHECK_AT_FREE flag(s) set Modules linked in: CPU: 1 PID: 602 Comm: kworker/u9:0 Not tainted 5.9.1 #2 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.13.0-1 04/01/2014 Workqueue: erofs_unzipd z_erofs_decompressqueue_work Call Trace: dump_stack+0x84/0xba bad_page.cold+0xac/0xb1 check_free_page_bad+0xb0/0xc0 free_pcp_prepare+0x2c8/0x2d0 free_unref_page+0x18/0xf0 put_pages_list+0x11a/0x120 z_erofs_decompressqueue_work+0xc9/0x110 ? z_erofs_decompress_pcluster.isra.0+0xf10/0xf10 ? read_word_at_a_time+0x12/0x20 ? strscpy+0xc7/0x1a0Quoted 8 lines
process_one_work+0x30c/0x730 worker_thread+0x91/0x640 ? __kasan_check_read+0x11/0x20 ? rescuer_thread+0x8a0/0x8a0 kthread+0x1dd/0x200 ? kthread_unpark+0xa0/0xa0 ret_from_fork+0x1f/0x30 Disabling lock debugging due to kernel taint
Quoted 4 lines
Yeah, I can make a pull-request to Linus if you need this to be in master now, or I can post it for v5.11-rc1 since 5.4 LTS isn't effected (and it would be only a print problem with debugging option.)
As for myself I don't utterly need this fix on the master branch ASAP, however it might be reasonable to get it included right into the next v5.10 release, because I believe it'll be an LTS. Eventually it's up to you to make a decision, from my side I won't urge you, the fixed issue is obviously a non-critical one.
Thank you for the original fix and taking my opinion into consideration :)
--
Best wishes,
Vladimir
Quoted 22 lines · Vladimir Zapolskiy
Hi Gao Xiang,
Quoted 19 lines · Gao Xiang
Hi Vladimir,
Quoted 16 lines · Vladimir Zapolskiy
Hello Gao Xiang,
Quoted 9 lines · Gao Xiang via Linux-erofs
From: Gao Xiang <[email protected]>
pcluster should be only set up for all managed pages instead of temporary pages. Since it currently uses
page->mappingto identify, the impact is minor for now.Fixes 5ddcee1f3a1c ("erofs: get rid of __stagingpage_alloc helper")Cc <[email protected]> # 5.5+Signed-off-by Gao Xiang <[email protected]>I was looking exactly at this problem recently, my change is one-to-one to your fix, thus I can provide a tag:
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
Tested-by Vladimir Zapolskiy <[email protected]>Many thanks for confirming this!
I found this when I was killing magical stagingpagepage->mapping, it's somewhat late :-)sure, for me it was an exciting immersion into the filesystem code :)
Thanks for your effort on this!
You could also post related kernel message in advance and I will definitly look into that as well. :)
Quoted 42 lines
Quoted 37 lines
Quoted 28 lines
The fixed problem is minor, but the kernel log becomes polluted, if a page allocation debug option is enabled:
% md5sum ~/erofs/testfile BUG: Bad page state in process kworker/u9:0 pfn:687de page:0000000057b8bcb4 refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x687de flags: 0x4000000000002000(private) raw: 4000000000002000 dead000000000100 dead000000000122 0000000000000000 raw: 0000000000000000 ffff888066758690 00000000ffffffff 0000000000000000 page dumped because: PAGE_FLAGS_CHECK_AT_FREE flag(s) set Modules linked in: CPU: 1 PID: 602 Comm: kworker/u9:0 Not tainted 5.9.1 #2 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.13.0-1 04/01/2014 Workqueue: erofs_unzipd z_erofs_decompressqueue_work Call Trace: dump_stack+0x84/0xba bad_page.cold+0xac/0xb1 check_free_page_bad+0xb0/0xc0 free_pcp_prepare+0x2c8/0x2d0 free_unref_page+0x18/0xf0 put_pages_list+0x11a/0x120 z_erofs_decompressqueue_work+0xc9/0x110 ? z_erofs_decompress_pcluster.isra.0+0xf10/0xf10 ? read_word_at_a_time+0x12/0x20 ? strscpy+0xc7/0x1a0Quoted 8 lines
process_one_work+0x30c/0x730 worker_thread+0x91/0x640 ? __kasan_check_read+0x11/0x20 ? rescuer_thread+0x8a0/0x8a0 kthread+0x1dd/0x200 ? kthread_unpark+0xa0/0xa0 ret_from_fork+0x1f/0x30 Disabling lock debugging due to kernel taintQuoted 4 lines
Yeah, I can make a pull-request to Linus if you need this to be in master now, or I can post it for v5.11-rc1 since 5.4 LTS isn't effected (and it would be only a print problem with debugging option.)
Quoted 6 lines
As for myself I don't utterly need this fix on the master branch ASAP, however it might be reasonable to get it included right into the next v5.10 release, because I believe it'll be an LTS. Eventually it's up to you to make a decision, from my side I won't urge you, the fixed issue is obviously a non-critical one.
Thank you for the original fix and taking my opinion into consideration :)
Yeah, v5.10 is a LTS version, and you are right, I will try to make a pull-request after I get Chao's RVB.
Thanks,
Gao Xiang
Quoted 5 lines
--
Best wishes,
Vladimir
Quoted 9 lines · Gao Xiang
From: Gao Xiang <[email protected]>
pcluster should be only set up for all managed pages instead of temporary pages. Since it currently uses
page->mappingto identify, the impact is minor for now.Fixes 5ddcee1f3a1c ("erofs: get rid of __stagingpage_alloc helper")Cc <[email protected]> # 5.5+Signed-off-by Gao Xiang <[email protected]>
Thanks,
Quoted 7 lines · Chao Yu
Quoted 6 lines · Gao Xiang
From: Gao Xiang <[email protected]>
pcluster should be only set up for all managed pages instead of temporary pages. Since it currently uses
page->mappingto identify, the impact is minor for now.
Quoted 5 lines
Quoted 3 lines
Fixes 5ddcee1f3a1c ("erofs: get rid of __stagingpage_alloc helper")Cc <[email protected]> # 5.5+Signed-off-by Gao Xiang <[email protected]>Reviewed-by Chao Yu <[email protected]>
Thanks, I've also added a note to the commit message like this, "
[ Update: Vladimir reported the kernel log becomes polluted
because PAGE_FLAGS_CHECK_AT_FREE flag(s) set if the page allocation debug option is enabled. ]
"
Will apply all of this to -fixes branch.
Thanks,
Gao Xiang
Quoted 3 lines
Thanks,
Quoted 14 lines · Gao Xiang
Quoted 7 lines · Chao Yu
Quoted 6 lines · Gao Xiang
From: Gao Xiang <[email protected]>
pcluster should be only set up for all managed pages instead of temporary pages. Since it currently uses
page->mappingto identify, the impact is minor for now.Quoted 5 lines
Quoted 3 lines
Fixes 5ddcee1f3a1c ("erofs: get rid of __stagingpage_alloc helper")Cc <[email protected]> # 5.5+Signed-off-by Gao Xiang <[email protected]>Reviewed-by Chao Yu <[email protected]>
Quoted 7 lines
Thanks, I've also added a note to the commit message like this, "
[ Update: Vladimir reported the kernel log becomes polluted
becausePAGE_FLAGS_CHECK_AT_FREEflag(s) set if the page allocation debug option is enabled. ]
"
Will apply all of this to -fixes branch.
Thanks for noticing that, looks fine to me.
Thanks,
Quoted 10 lines
Thanks,
Gao XiangQuoted 3 lines
Thanks,
.