* reusing bios @ 2011-03-12 9:29 Arne Jansen 2011-03-12 10:08 ` Jens Axboe 0 siblings, 1 reply; 6+ messages in thread From: Arne Jansen @ 2011-03-12 9:29 UTC (permalink / raw) To: linux-scsi; +Cc: axboe Hi, I'm trying to re-use struct bio after completion, including the allocated pages. Normally I re-initialize the fields bi_sector, bi_size, bi_next, bi_flags, bi_comp_cpu and bi_bdev. This works perfectly well, as long as no media errors are encountered. After a media error, all subsequent reads with this bio fail. Are there any more fields that need to get re-initialized? Or, better, is there a function to reset the bio? Thanks, Arne ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: reusing bios 2011-03-12 9:29 reusing bios Arne Jansen @ 2011-03-12 10:08 ` Jens Axboe 2011-03-12 13:33 ` Arne Jansen 0 siblings, 1 reply; 6+ messages in thread From: Jens Axboe @ 2011-03-12 10:08 UTC (permalink / raw) To: Arne Jansen; +Cc: linux-scsi On 2011-03-12 10:29, Arne Jansen wrote: > Hi, > > I'm trying to re-use struct bio after completion, including the > allocated pages. Normally I re-initialize the fields bi_sector, > bi_size, bi_next, bi_flags, bi_comp_cpu and bi_bdev. > This works perfectly well, as long as no media errors are encountered. > After a media error, all subsequent reads with this bio fail. Are > there any more fields that need to get re-initialized? Or, better, > is there a function to reset the bio? bio_init()? Sounds like you are not setting BIO_UPTODATE when resetting it. -- Jens Axboe ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: reusing bios 2011-03-12 10:08 ` Jens Axboe @ 2011-03-12 13:33 ` Arne Jansen 2011-03-12 13:48 ` Jens Axboe 0 siblings, 1 reply; 6+ messages in thread From: Arne Jansen @ 2011-03-12 13:33 UTC (permalink / raw) To: Jens Axboe; +Cc: linux-scsi Jens Axboe wrote: > On 2011-03-12 10:29, Arne Jansen wrote: >> Hi, >> >> I'm trying to re-use struct bio after completion, including the >> allocated pages. Normally I re-initialize the fields bi_sector, >> bi_size, bi_next, bi_flags, bi_comp_cpu and bi_bdev. >> This works perfectly well, as long as no media errors are encountered. >> After a media error, all subsequent reads with this bio fail. Are >> there any more fields that need to get re-initialized? Or, better, >> is there a function to reset the bio? > > bio_init()? Sounds like you are not setting BIO_UPTODATE when resetting > it. > bio_init does way too much, as it discards the io_vec, refcnt, destructor, private etc. I set the flags to 1 << BIO_UPTODATE, but that proved to be fatal, too, as it clobbers the POOL_FLAGS, which leads to an oops when the last reference drops. These bio-beasts are just not made to be reused. One needs way too much internal knowledge to reinitialize them properly. Therefore, I'd really like to have a call like bio_reinit, which keeps the io_vec and all the owners private information, but resets the parts that get used by the stack like bi_next. Would that make sense? ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: reusing bios 2011-03-12 13:33 ` Arne Jansen @ 2011-03-12 13:48 ` Jens Axboe 2011-03-12 13:58 ` Arne Jansen 0 siblings, 1 reply; 6+ messages in thread From: Jens Axboe @ 2011-03-12 13:48 UTC (permalink / raw) To: Arne Jansen; +Cc: linux-scsi On 2011-03-12 14:33, Arne Jansen wrote: > Jens Axboe wrote: >> On 2011-03-12 10:29, Arne Jansen wrote: >>> Hi, >>> >>> I'm trying to re-use struct bio after completion, including the >>> allocated pages. Normally I re-initialize the fields bi_sector, >>> bi_size, bi_next, bi_flags, bi_comp_cpu and bi_bdev. >>> This works perfectly well, as long as no media errors are encountered. >>> After a media error, all subsequent reads with this bio fail. Are >>> there any more fields that need to get re-initialized? Or, better, >>> is there a function to reset the bio? >> >> bio_init()? Sounds like you are not setting BIO_UPTODATE when resetting >> it. >> > > bio_init does way too much, as it discards the io_vec, refcnt, destructor, > private etc. > I set the flags to 1 << BIO_UPTODATE, but that proved to be fatal, too, as > it clobbers the POOL_FLAGS, which leads to an oops when the last reference > drops. These bio-beasts are just not made to be reused. One needs way too > much internal knowledge to reinitialize them properly. > Therefore, I'd really like to have a call like bio_reinit, which keeps the > io_vec and all the owners private information, but resets the parts that > get used by the stack like bi_next. Would that make sense? The thing is, you can't really reuse without violating the allocator principle of finite life times. Otherwise you risk hanging the system. If you want to reuse, the bio should come out of your own pool or through the bio_kmalloc() interface, not from bio_alloc() with the default pool. So there is no reinit, as there hasn't been a good use case for that. The fact that flags has pool information in the top bits is a sure sign you are violating that. -- Jens Axboe ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: reusing bios 2011-03-12 13:48 ` Jens Axboe @ 2011-03-12 13:58 ` Arne Jansen 2011-03-14 22:10 ` Dan Williams 0 siblings, 1 reply; 6+ messages in thread From: Arne Jansen @ 2011-03-12 13:58 UTC (permalink / raw) To: Jens Axboe; +Cc: linux-scsi Jens Axboe wrote: > On 2011-03-12 14:33, Arne Jansen wrote: >> Jens Axboe wrote: >>> On 2011-03-12 10:29, Arne Jansen wrote: >>>> Hi, >>>> >>>> I'm trying to re-use struct bio after completion, including the >>>> allocated pages. Normally I re-initialize the fields bi_sector, >>>> bi_size, bi_next, bi_flags, bi_comp_cpu and bi_bdev. >>>> This works perfectly well, as long as no media errors are encountered. >>>> After a media error, all subsequent reads with this bio fail. Are >>>> there any more fields that need to get re-initialized? Or, better, >>>> is there a function to reset the bio? >>> bio_init()? Sounds like you are not setting BIO_UPTODATE when resetting >>> it. >>> >> bio_init does way too much, as it discards the io_vec, refcnt, destructor, >> private etc. >> I set the flags to 1 << BIO_UPTODATE, but that proved to be fatal, too, as >> it clobbers the POOL_FLAGS, which leads to an oops when the last reference >> drops. These bio-beasts are just not made to be reused. One needs way too >> much internal knowledge to reinitialize them properly. >> Therefore, I'd really like to have a call like bio_reinit, which keeps the >> io_vec and all the owners private information, but resets the parts that >> get used by the stack like bi_next. Would that make sense? > > The thing is, you can't really reuse without violating the allocator > principle of finite life times. Otherwise you risk hanging the system. > If you want to reuse, the bio should come out of your own pool or > through the bio_kmalloc() interface, not from bio_alloc() with the > default pool. > > So there is no reinit, as there hasn't been a good use case for that. > The fact that flags has pool information in the top bits is a sure sign > you are violating that. > ok, assuming I allocate them with bio_kmalloc, the problem of reinit would remain. Now that I own them, I can't reuse them. This particular use case here is a scrub for btrfs. I have a limited set of bios and pages, that I reuse as long as the scrub runs. Of course I could just free up and reallocate everything after each read, but as I know how much work there is ahead, I can just as well keep them. ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: reusing bios 2011-03-12 13:58 ` Arne Jansen @ 2011-03-14 22:10 ` Dan Williams 0 siblings, 0 replies; 6+ messages in thread From: Dan Williams @ 2011-03-14 22:10 UTC (permalink / raw) To: Arne Jansen; +Cc: Jens Axboe, linux-scsi On Sat, Mar 12, 2011 at 5:58 AM, Arne Jansen <lists@die-jansens.de> wrote: > Jens Axboe wrote: >> >> On 2011-03-12 14:33, Arne Jansen wrote: >>> >>> Jens Axboe wrote: >>>> >>>> On 2011-03-12 10:29, Arne Jansen wrote: >>>>> >>>>> Hi, >>>>> >>>>> I'm trying to re-use struct bio after completion, including the >>>>> allocated pages. Normally I re-initialize the fields bi_sector, >>>>> bi_size, bi_next, bi_flags, bi_comp_cpu and bi_bdev. >>>>> This works perfectly well, as long as no media errors are encountered. >>>>> After a media error, all subsequent reads with this bio fail. Are >>>>> there any more fields that need to get re-initialized? Or, better, >>>>> is there a function to reset the bio? >>>> >>>> bio_init()? Sounds like you are not setting BIO_UPTODATE when resetting >>>> it. >>>> >>> bio_init does way too much, as it discards the io_vec, refcnt, >>> destructor, >>> private etc. >>> I set the flags to 1 << BIO_UPTODATE, but that proved to be fatal, too, >>> as >>> it clobbers the POOL_FLAGS, which leads to an oops when the last >>> reference >>> drops. These bio-beasts are just not made to be reused. One needs way too >>> much internal knowledge to reinitialize them properly. >>> Therefore, I'd really like to have a call like bio_reinit, which keeps >>> the >>> io_vec and all the owners private information, but resets the parts that >>> get used by the stack like bi_next. Would that make sense? >> >> The thing is, you can't really reuse without violating the allocator >> principle of finite life times. Otherwise you risk hanging the system. >> If you want to reuse, the bio should come out of your own pool or >> through the bio_kmalloc() interface, not from bio_alloc() with the >> default pool. >> >> So there is no reinit, as there hasn't been a good use case for that. >> The fact that flags has pool information in the top bits is a sure sign >> you are violating that. >> > > ok, assuming I allocate them with bio_kmalloc, the problem of reinit would > remain. Now that I own them, I can't reuse them. > This particular use case here is a scrub for btrfs. I have a limited set of > bios and pages, that I reuse as long as the scrub runs. Of course I could > just free up and reallocate everything after each read, but as I know how > much work there is ahead, I can just as well keep them. Have a look at drivers/md/raid5.c::ops_run_io() the stripe_head bios are allocated once at initialization and reused for the life of the array. -- Dan ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2011-03-14 22:10 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2011-03-12 9:29 reusing bios Arne Jansen 2011-03-12 10:08 ` Jens Axboe 2011-03-12 13:33 ` Arne Jansen 2011-03-12 13:48 ` Jens Axboe 2011-03-12 13:58 ` Arne Jansen 2011-03-14 22:10 ` Dan Williams
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox