Message ID | 20240221052624.573287-1-zhaoyang.huang@unisoc.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [Resend,PATCHv9,1/1] block: introduce content activity based ioprio | expand |
On Wed, Feb 21, 2024 at 01:26:24PM +0800, zhaoyang.huang wrote: > +/* > + * bio_set_active_ioprio_folio is helper function to count the bio's > + * content's activities which measured by MGLRU. > + * The file system should call this function after bio_add_page/folio for > + * the buffered read/write/sync. > + */ > +#ifdef CONFIG_BLK_CONT_ACT_BASED_IOPRIO > +void bio_set_active_ioprio_folio(struct bio *bio, struct folio *folio) How did you test this? Nothing calls this function, so this patch can't actually be doing anything. Are you planning to update any filesystems to use this? - Eric
On Wed, Feb 21, 2024 at 1:41 PM Eric Biggers <ebiggers@kernel.org> wrote: > > On Wed, Feb 21, 2024 at 01:26:24PM +0800, zhaoyang.huang wrote: > > +/* > > + * bio_set_active_ioprio_folio is helper function to count the bio's > > + * content's activities which measured by MGLRU. > > + * The file system should call this function after bio_add_page/folio for > > + * the buffered read/write/sync. > > + */ > > +#ifdef CONFIG_BLK_CONT_ACT_BASED_IOPRIO > > +void bio_set_active_ioprio_folio(struct bio *bio, struct folio *folio) > > How did you test this? Nothing calls this function, so this patch can't > actually be doing anything. Are you planning to update any filesystems to use > this? Thanks for asking. I verified this patch in an Android based 6GB RAM system by modifying EROFS/F2FS/EXT4's aops API which I didn't upstreaming yet. I would like to recommend this to the desired fs if this is accepted. > > - Eric
On Wed, Feb 21, 2024 at 01:50:55PM +0800, Zhaoyang Huang wrote: > On Wed, Feb 21, 2024 at 1:41 PM Eric Biggers <ebiggers@kernel.org> wrote: > > > > On Wed, Feb 21, 2024 at 01:26:24PM +0800, zhaoyang.huang wrote: > > > +/* > > > + * bio_set_active_ioprio_folio is helper function to count the bio's > > > + * content's activities which measured by MGLRU. > > > + * The file system should call this function after bio_add_page/folio for > > > + * the buffered read/write/sync. > > > + */ > > > +#ifdef CONFIG_BLK_CONT_ACT_BASED_IOPRIO > > > +void bio_set_active_ioprio_folio(struct bio *bio, struct folio *folio) > > > > How did you test this? Nothing calls this function, so this patch can't > > actually be doing anything. Are you planning to update any filesystems to use > > this? > Thanks for asking. I verified this patch in an Android based 6GB RAM > system by modifying EROFS/F2FS/EXT4's aops API which I didn't > upstreaming yet. I would like to recommend this to the desired fs if > this is accepted. This patch needs to come with a user. Unused code can't be accepted. - Eric
diff --git a/block/Kconfig b/block/Kconfig index f1364d1c0d93..fb3a888194c0 100644 --- a/block/Kconfig +++ b/block/Kconfig @@ -228,6 +228,21 @@ config BLOCK_HOLDER_DEPRECATED config BLK_MQ_STACKING bool +config BLK_CONT_ACT_BASED_IOPRIO + bool "Enable content activity based ioprio" + depends on LRU_GEN + default n + help + This item enable the feature of adjust bio's priority by + calculating its content's activity. + This feature works as a hint of original bio_set_ioprio + which means rt task get no change of its bio->bi_ioprio + while other tasks have the opportunity to raise the ioprio + if the bio take certain numbers of active pages. + The file system should use the API after bio_add_folio for + their buffered read/write/sync function to adjust the + bio->bi_ioprio. + source "block/Kconfig.iosched" endif # BLOCK diff --git a/block/bio.c b/block/bio.c index 816d412c06e9..2c0b8f2ae4d4 100644 --- a/block/bio.c +++ b/block/bio.c @@ -1476,6 +1476,39 @@ void bio_set_pages_dirty(struct bio *bio) } EXPORT_SYMBOL_GPL(bio_set_pages_dirty); +/* + * bio_set_active_ioprio_folio is helper function to count the bio's + * content's activities which measured by MGLRU. + * The file system should call this function after bio_add_page/folio for + * the buffered read/write/sync. + */ +#ifdef CONFIG_BLK_CONT_ACT_BASED_IOPRIO +void bio_set_active_ioprio_folio(struct bio *bio, struct folio *folio) +{ + int class, level, hint; + int activities; + + /* + * use bi_ioprio to record the activities, assume no one will set it + * before submit_bio + */ + bio->bi_ioprio += folio_test_workingset(folio) ? 1 : 0; + activities = IOPRIO_PRIO_DATA(bio->bi_ioprio); + level = IOPRIO_PRIO_LEVEL(bio->bi_ioprio); + hint = IOPRIO_PRIO_HINT(bio->bi_ioprio); + + if (activities > bio->bi_vcnt / 2) + class = IOPRIO_CLASS_RT; + else if (activities > bio->bi_vcnt / 4) + class = max(IOPRIO_PRIO_CLASS(get_current_ioprio()), IOPRIO_CLASS_BE); + + bio->bi_ioprio = IOPRIO_PRIO_VALUE_HINT(class, level, hint); +} +#else +void bio_set_active_ioprio_folio(struct bio *bio, struct folio *folio) {} +#endif +EXPORT_SYMBOL_GPL(bio_set_active_ioprio_folio); + /* * bio_check_pages_dirty() will check that all the BIO's pages are still dirty. * If they are, then fine. If, however, some pages are clean then they must diff --git a/include/linux/bio.h b/include/linux/bio.h index 41d417ee1349..6c36546f6b9b 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -487,6 +487,7 @@ void bio_iov_bvec_set(struct bio *bio, struct iov_iter *iter); void __bio_release_pages(struct bio *bio, bool mark_dirty); extern void bio_set_pages_dirty(struct bio *bio); extern void bio_check_pages_dirty(struct bio *bio); +void bio_set_active_ioprio_folio(struct bio *bio, struct folio *folio); extern void bio_copy_data_iter(struct bio *dst, struct bvec_iter *dst_iter, struct bio *src, struct bvec_iter *src_iter);