* [PATCHv2 0/2] zram: IDLE flag handling fixes @ 2024-10-28 15:36 Sergey Senozhatsky 2024-10-28 15:36 ` [PATCHv2 1/2] zram: clear IDLE flag after recompression Sergey Senozhatsky 2024-10-28 15:36 ` [PATCHv2 2/2] zram: clear IDLE flag in mark_idle() Sergey Senozhatsky 0 siblings, 2 replies; 6+ messages in thread From: Sergey Senozhatsky @ 2024-10-28 15:36 UTC (permalink / raw) To: Andrew Morton; +Cc: Minchan Kim, linux-kernel, Sergey Senozhatsky zram can wrongly preserve ZRAM_IDLE flag on its entries which can result in premature post-processing (writeback and recompression) of such entries. v1->v2: -- fixed typos and comments styles -- added Fixes tags Sergey Senozhatsky (2): zram: clear IDLE flag after recompression zram: clear IDLE flag in mark_idle() drivers/block/zram/zram_drv.c | 9 +++++++++ 1 file changed, 9 insertions(+) -- 2.47.0.163.g1226f6d8fa-goog ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCHv2 1/2] zram: clear IDLE flag after recompression 2024-10-28 15:36 [PATCHv2 0/2] zram: IDLE flag handling fixes Sergey Senozhatsky @ 2024-10-28 15:36 ` Sergey Senozhatsky 2024-10-28 17:56 ` Brian Geffon 2024-10-28 15:36 ` [PATCHv2 2/2] zram: clear IDLE flag in mark_idle() Sergey Senozhatsky 1 sibling, 1 reply; 6+ messages in thread From: Sergey Senozhatsky @ 2024-10-28 15:36 UTC (permalink / raw) To: Andrew Morton; +Cc: Minchan Kim, linux-kernel, Sergey Senozhatsky Recompression should clear ZRAM_IDLE flag on the entries it has accessed, because otherwise some entries, specifically those for which recompression has failed, become immediate candidate entries for another post-processing (e.g. writeback). Consider the following case: - recompression marks entries IDLE every 4 hours and attempts to recompress them - some entries are incompressible, so we keep them intact and hence preserve IDLE flag - writeback marks entries IDLE every 8 hours and writebacks IDLE entries, however we have IDLE entries left from recompression, so writeback prematurely writebacks those entries. The bug was reported by Shin Kawamura. Fixes: 84b33bf78889 ("zram: introduce recompress sysfs knob") Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org> --- drivers/block/zram/zram_drv.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index e6d12e81241d..a16dbffcdca3 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -1864,6 +1864,13 @@ static int recompress_slot(struct zram *zram, u32 index, struct page *page, if (ret) return ret; + /* + * We touched this entry so mark it as non-IDLE. This makes sure that + * we don't preserve IDLE flag and don't incorrectly pick this entry + * for different post-processing type (e.g. writeback). + */ + zram_clear_flag(zram, index, ZRAM_IDLE); + class_index_old = zs_lookup_class_index(zram->mem_pool, comp_len_old); /* * Iterate the secondary comp algorithms list (in order of priority) -- 2.47.0.163.g1226f6d8fa-goog ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCHv2 1/2] zram: clear IDLE flag after recompression 2024-10-28 15:36 ` [PATCHv2 1/2] zram: clear IDLE flag after recompression Sergey Senozhatsky @ 2024-10-28 17:56 ` Brian Geffon 0 siblings, 0 replies; 6+ messages in thread From: Brian Geffon @ 2024-10-28 17:56 UTC (permalink / raw) To: Sergey Senozhatsky; +Cc: Andrew Morton, Minchan Kim, linux-kernel On Tue, Oct 29, 2024 at 12:36:14AM +0900, Sergey Senozhatsky wrote: > Recompression should clear ZRAM_IDLE flag on the entries > it has accessed, because otherwise some entries, specifically > those for which recompression has failed, become immediate > candidate entries for another post-processing (e.g. writeback). > > Consider the following case: > - recompression marks entries IDLE every 4 hours and attempts > to recompress them > - some entries are incompressible, so we keep them intact and > hence preserve IDLE flag > - writeback marks entries IDLE every 8 hours and writebacks > IDLE entries, however we have IDLE entries left from > recompression, so writeback prematurely writebacks those > entries. > > The bug was reported by Shin Kawamura. Reported-by: Shin Kawamura <kawasin@google.com> > > Fixes: 84b33bf78889 ("zram: introduce recompress sysfs knob") > Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org> Acked-by: Brian Geffon <bgeffon@google.com> > --- > drivers/block/zram/zram_drv.c | 7 +++++++ > 1 file changed, 7 insertions(+) > > diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c > index e6d12e81241d..a16dbffcdca3 100644 > --- a/drivers/block/zram/zram_drv.c > +++ b/drivers/block/zram/zram_drv.c > @@ -1864,6 +1864,13 @@ static int recompress_slot(struct zram *zram, u32 index, struct page *page, > if (ret) > return ret; > > + /* > + * We touched this entry so mark it as non-IDLE. This makes sure that > + * we don't preserve IDLE flag and don't incorrectly pick this entry > + * for different post-processing type (e.g. writeback). > + */ > + zram_clear_flag(zram, index, ZRAM_IDLE); > + > class_index_old = zs_lookup_class_index(zram->mem_pool, comp_len_old); > /* > * Iterate the secondary comp algorithms list (in order of priority) > -- > 2.47.0.163.g1226f6d8fa-goog > ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCHv2 2/2] zram: clear IDLE flag in mark_idle() 2024-10-28 15:36 [PATCHv2 0/2] zram: IDLE flag handling fixes Sergey Senozhatsky 2024-10-28 15:36 ` [PATCHv2 1/2] zram: clear IDLE flag after recompression Sergey Senozhatsky @ 2024-10-28 15:36 ` Sergey Senozhatsky 2024-10-28 17:57 ` Brian Geffon 1 sibling, 1 reply; 6+ messages in thread From: Sergey Senozhatsky @ 2024-10-28 15:36 UTC (permalink / raw) To: Andrew Morton; +Cc: Minchan Kim, linux-kernel, Sergey Senozhatsky If entry does not fulfill current mark_idle() parameters, e.g. cutoff time, then we should clear its ZRAM_IDLE from previous mark_idle() invocations. Consider the following case: - mark_idle() cutoff time 8h - mark_idle() cutoff time 4h - writeback() idle - will writeback entries with cutoff time 8h, while it should only pick entries with cutoff time 4h The bug was reported by Shin Kawamura. Fixes: 755804d16965 ("zram: introduce an aged idle interface") Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org> --- drivers/block/zram/zram_drv.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index a16dbffcdca3..cee49bb0126d 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -410,6 +410,8 @@ static void mark_idle(struct zram *zram, ktime_t cutoff) #endif if (is_idle) zram_set_flag(zram, index, ZRAM_IDLE); + else + zram_clear_flag(zram, index, ZRAM_IDLE); zram_slot_unlock(zram, index); } } -- 2.47.0.163.g1226f6d8fa-goog ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCHv2 2/2] zram: clear IDLE flag in mark_idle() 2024-10-28 15:36 ` [PATCHv2 2/2] zram: clear IDLE flag in mark_idle() Sergey Senozhatsky @ 2024-10-28 17:57 ` Brian Geffon 2024-10-29 0:09 ` Sergey Senozhatsky 0 siblings, 1 reply; 6+ messages in thread From: Brian Geffon @ 2024-10-28 17:57 UTC (permalink / raw) To: Sergey Senozhatsky; +Cc: Andrew Morton, Minchan Kim, linux-kernel On Tue, Oct 29, 2024 at 12:36:15AM +0900, Sergey Senozhatsky wrote: > If entry does not fulfill current mark_idle() parameters, e.g. > cutoff time, then we should clear its ZRAM_IDLE from previous > mark_idle() invocations. > > Consider the following case: > - mark_idle() cutoff time 8h > - mark_idle() cutoff time 4h > - writeback() idle - will writeback entries with cutoff time 8h, > while it should only pick entries with cutoff time 4h > > The bug was reported by Shin Kawamura. Reported-by: Shin Kawamura <kawasin@google.com> > > Fixes: 755804d16965 ("zram: introduce an aged idle interface") > Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org> Acked-by: Brian Geffon <bgeffon@google.com> > --- > drivers/block/zram/zram_drv.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c > index a16dbffcdca3..cee49bb0126d 100644 > --- a/drivers/block/zram/zram_drv.c > +++ b/drivers/block/zram/zram_drv.c > @@ -410,6 +410,8 @@ static void mark_idle(struct zram *zram, ktime_t cutoff) > #endif > if (is_idle) > zram_set_flag(zram, index, ZRAM_IDLE); > + else > + zram_clear_flag(zram, index, ZRAM_IDLE); > zram_slot_unlock(zram, index); > } > } > -- > 2.47.0.163.g1226f6d8fa-goog > ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCHv2 2/2] zram: clear IDLE flag in mark_idle() 2024-10-28 17:57 ` Brian Geffon @ 2024-10-29 0:09 ` Sergey Senozhatsky 0 siblings, 0 replies; 6+ messages in thread From: Sergey Senozhatsky @ 2024-10-29 0:09 UTC (permalink / raw) To: Brian Geffon; +Cc: Sergey Senozhatsky, Andrew Morton, Minchan Kim, linux-kernel On (24/10/28 13:57), Brian Geffon wrote: > On Tue, Oct 29, 2024 at 12:36:15AM +0900, Sergey Senozhatsky wrote: > > If entry does not fulfill current mark_idle() parameters, e.g. > > cutoff time, then we should clear its ZRAM_IDLE from previous > > mark_idle() invocations. > > > > Consider the following case: > > - mark_idle() cutoff time 8h > > - mark_idle() cutoff time 4h > > - writeback() idle - will writeback entries with cutoff time 8h, > > while it should only pick entries with cutoff time 4h > > > > The bug was reported by Shin Kawamura. > Reported-by: Shin Kawamura <kawasin@google.com> This is how it was in v1, but that triggered a warn WARNING: Reported-by: should be immediately followed by Closes: with a URL to the report #16: Reported-by: Shin Kawamura <kawasin@google.com> Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org> so I switched to less "formal" reported-by tag in v2. ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2024-10-29 0:09 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2024-10-28 15:36 [PATCHv2 0/2] zram: IDLE flag handling fixes Sergey Senozhatsky 2024-10-28 15:36 ` [PATCHv2 1/2] zram: clear IDLE flag after recompression Sergey Senozhatsky 2024-10-28 17:56 ` Brian Geffon 2024-10-28 15:36 ` [PATCHv2 2/2] zram: clear IDLE flag in mark_idle() Sergey Senozhatsky 2024-10-28 17:57 ` Brian Geffon 2024-10-29 0:09 ` Sergey Senozhatsky
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox