From: OGAWA Hirofumi Subject: Re: [PATCH 1/5] [BLOCK] Add 'discard' request handling Date: Thu, 07 Aug 2008 01:19:48 +0900 Message-ID: <877iauqfob.fsf@devron.myhome.or.jp> References: <488B7281.4020007@gmail.com> <20080726130200.f541e604.akpm@linux-foundation.org> <1217900716.3454.667.camel@pmac.infradead.org> <20080805114210.GW20055@kernel.dk> <1217953741.3454.784.camel@pmac.infradead.org> <1217957140.3454.800.camel@pmac.infradead.org> <1218014703.5111.35.camel@pmac.infradead.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: Jens Axboe , Andrew Morton , Ric Wheeler , linux-fsdevel@vger.kernel.org, gilad@codefidence.com To: David Woodhouse Return-path: Received: from mail.parknet.ad.jp ([210.171.162.6]:43355 "EHLO mail.officemail.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751591AbYHFQT4 (ORCPT ); Wed, 6 Aug 2008 12:19:56 -0400 In-Reply-To: <1218014703.5111.35.camel@pmac.infradead.org> (David Woodhouse's message of "Wed, 06 Aug 2008 10:25:03 +0100") Sender: linux-fsdevel-owner@vger.kernel.org List-ID: David Woodhouse writes: > Some block devices benefit from a hint that they can forget the contents > of certain sectors. Add basic support for this to the block core, along > with a 'blkdev_issue_discard()' helper function which issues such > requests. > > Although blkdev_issue_discard() can take an end_io function, it's > acceptable to leave that as NULL and in that case the allocated bio will > be automatically freed. Most of the time, it's expected that callers > won't care about when, or even _if_, the request completes. It's only a > hint to the device anyway. By definition, the file system doesn't _care_ > about these sectors any more. Looks like good start. Thanks. Although I'm not quite sure it helps, is there any plan to merge bios? > +int blkdev_issue_discard(struct block_device *bdev, sector_t sector, > + unsigned nr_sects, bio_end_io_t end_io) > +{ > + struct request_queue *q; [...] > + > + bio->bi_end_io = end_io; > + bio->bi_bdev = bdev; > + bio->bi_sector = sector; > + bio->bi_size = nr_sects << 9; > + submit_bio(1 << BIO_RW_DISCARD, bio); > + return 0; > +} If fs merges contiguous blocks to one bio, bi_size will overflow. Will we have to limit (of the device?) and separate for the device? Or how about to have #define for discard bio for BIO_RW_DISCARD users? > @@ -185,10 +188,16 @@ struct bio { > #define bio_failfast(bio) ((bio)->bi_rw & (1 << BIO_RW_FAILFAST)) > #define bio_rw_ahead(bio) ((bio)->bi_rw & (1 << BIO_RW_AHEAD)) > #define bio_rw_meta(bio) ((bio)->bi_rw & (1 << BIO_RW_META)) > +#define bio_discard(bio) ((bio)->bi_rw & (1 << BIO_RW_DISCARD)) > #define bio_empty_barrier(bio) (bio_barrier(bio) && !(bio)->bi_size) > > +#define bio_dataless(bio) (!(bio)->bi_io_vec) The following seems good to convert to bio_dataless? Signed-off-by: OGAWA Hirofumi --- mm/bounce.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff -puN mm/bounce.c~test mm/bounce.c --- linux-2.6/mm/bounce.c~test 2008-08-07 00:04:26.000000000 +0900 +++ linux-2.6-hirofumi/mm/bounce.c 2008-08-07 00:04:57.000000000 +0900 @@ -267,7 +267,7 @@ void blk_queue_bounce(struct request_que /* * Data-less bio, nothing to bounce */ - if (bio_empty_barrier(*bio_orig)) + if (bio_dataless(*bio_orig)) { return; /* _ -- OGAWA Hirofumi