* Re: [PATCH 1/2] block: fix leaks associated with discard request payload [not found] ` <20100627185927K.fujita.tomonori@lab.ntt.co.jp> @ 2010-06-27 10:35 ` FUJITA Tomonori 2010-06-27 11:07 ` Christoph Hellwig 0 siblings, 1 reply; 28+ messages in thread From: FUJITA Tomonori @ 2010-06-27 10:35 UTC (permalink / raw) To: hch Cc: snitzer, axboe, dm-devel, James.Bottomley, linux-kernel, martin.petersen, akpm, linux-scsi On Sun, 27 Jun 2010 19:01:33 +0900 FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> wrote: > On Sun, 27 Jun 2010 11:26:52 +0200 > Christoph Hellwig <hch@lst.de> wrote: > > > On Sun, Jun 27, 2010 at 05:49:29PM +0900, FUJITA Tomonori wrote: > > > On Sat, 26 Jun 2010 15:56:50 -0400 > > > Mike Snitzer <snitzer@redhat.com> wrote: > > > > > > > Fix leaks introduced via "block: don't allocate a payload for discard > > > > request" commit a1d949f5f44. > > > > > > > > sd_done() is not called for REQ_TYPE_BLOCK_PC commands so cleanup > > > > discard request's payload directly in scsi_finish_command(). > > > > > > Instead of adding another discard hack to scsi_finish_command(), how > > > about converting discard to REQ_TYPE_FS request? discard is FS request > > > from the perspective of the block layer. It also fixes a problem that > > > discard isn't retried in the case of UNIT ATTENTION. > > > > > > I think that we can get more cleaner code if we handle discard as > > > normal (fs) request in the block layer (and scsi-ml). We need more > > > changes but this patch is the first step. > > > > Making discard a REQ_TYPE_FS inside scsi (it already is before entering > > sd_prep_fn) means we'll need to special case it all over the I/O > > submission and completion path. Having the payload length not matching > > Hmm, my patch doesn't add any special case in scsi submission and > completion. sd_prep_fn already has a hack for discard to set > bi->bi_size to rq->__data_size so scsi can tell the block layer to > finish discard requests. > > Adding another special case for discard to scsi_io_completion() > doesn't look good. > > About the block layer, we already have special case for discard > everywhere (rq->cmd_flags & REQ_DISCARD). > > > > the transfer length is something we don't expect for FS requests. > > Yeah, that's tricky. I'm not sure yet which is better; change how the > block layer handles the transfer length or let the lower layer to add > pages (as we do now). > > > > > index e16185b..9e15c46 100644 > > > --- a/block/blk-lib.c > > > +++ b/block/blk-lib.c > > > @@ -20,6 +20,10 @@ static void blkdev_discard_end_io(struct bio *bio, int err) > > > if (bio->bi_private) > > > complete(bio->bi_private); > > > > > > + /* free the page that the lower layer allocated */ > > > + if (bio_page(bio)) > > > + __free_page(bio_page(bio)); > > > + > > > > This is exactly what this patchkit gets rid off. Having a payload > > page that the caller tracks (previously fully, with this patch only for > > freeing) makes DM's life a lot harder. Remember we don't actually store > > any payload in there before entering sd_prep_fn - it's just that the > > scsi commands implementing discards need some payload - either a sector > > sizes zero filled buffer for WRITE SAME, or an LBA/len encoding inside > > the payload for UNMAP. > > It's so bad if the block layer frees pages that the lower layer > allocates? I thought it's ok if the block layer doesn't allocate. > > It's better if sd_done() frees a page? As my patch does, if we handle > discard as FS in scsi-ml, sd_done() is called. How about this? = From: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> Subject: [PATCH] convert discard to REQ_TYPE_FS instead of REQ_TYPE_BLOCK_PC Fixes the two issues: - leak of pages that scsi_setup_discard_cmnd() allocates (because we don't call sd_done for pc requets). - discard requests aren't retried when possible (e.g. UNIT ATTENTION). Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> --- drivers/scsi/sd.c | 1 - 1 files changed, 0 insertions(+), 1 deletions(-) diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index d447726..056c8e1 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -432,7 +432,6 @@ static int scsi_setup_discard_cmnd(struct scsi_device *sdp, struct request *rq) nr_sectors >>= 3; } - rq->cmd_type = REQ_TYPE_BLOCK_PC; rq->timeout = SD_TIMEOUT; memset(rq->cmd, 0, rq->cmd_len); -- 1.6.5 ^ permalink raw reply related [flat|nested] 28+ messages in thread
* Re: [PATCH 1/2] block: fix leaks associated with discard request payload 2010-06-27 10:35 ` [PATCH 1/2] block: fix leaks associated with discard request payload FUJITA Tomonori @ 2010-06-27 11:07 ` Christoph Hellwig 2010-06-27 12:32 ` FUJITA Tomonori 0 siblings, 1 reply; 28+ messages in thread From: Christoph Hellwig @ 2010-06-27 11:07 UTC (permalink / raw) To: FUJITA Tomonori Cc: hch, snitzer, axboe, dm-devel, James.Bottomley, linux-kernel, martin.petersen, akpm, linux-scsi > How about this? As I tried to explain before this utterly confuses the I/O completion path. With the patch applied even a simple mkfs.xfs that issues discard just hangs. ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 1/2] block: fix leaks associated with discard request payload 2010-06-27 11:07 ` Christoph Hellwig @ 2010-06-27 12:32 ` FUJITA Tomonori 2010-06-27 14:16 ` Mike Snitzer ` (2 more replies) 0 siblings, 3 replies; 28+ messages in thread From: FUJITA Tomonori @ 2010-06-27 12:32 UTC (permalink / raw) To: hch Cc: fujita.tomonori, snitzer, axboe, dm-devel, James.Bottomley, linux-kernel, martin.petersen, akpm, linux-scsi On Sun, 27 Jun 2010 13:07:12 +0200 Christoph Hellwig <hch@lst.de> wrote: > > How about this? > > As I tried to explain before this utterly confuses the I/O completion > path. With the patch applied even a simple mkfs.xfs that issues discard > just hangs. Wired. I just tried mkfs.xfs against scsi_debug with my block patches (I saw one discard command). Seemed that it worked fine. ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 1/2] block: fix leaks associated with discard request payload 2010-06-27 12:32 ` FUJITA Tomonori @ 2010-06-27 14:16 ` Mike Snitzer 2010-06-27 15:35 ` Christoph Hellwig 2010-06-27 15:33 ` Christoph Hellwig 2010-06-28 7:57 ` Christoph Hellwig 2 siblings, 1 reply; 28+ messages in thread From: Mike Snitzer @ 2010-06-27 14:16 UTC (permalink / raw) To: FUJITA Tomonori Cc: hch, axboe, dm-devel, James.Bottomley, linux-kernel, martin.petersen, akpm, linux-scsi On Sun, Jun 27 2010 at 8:32am -0400, FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> wrote: > On Sun, 27 Jun 2010 13:07:12 +0200 > Christoph Hellwig <hch@lst.de> wrote: > > > > How about this? > > > > As I tried to explain before this utterly confuses the I/O completion > > path. With the patch applied even a simple mkfs.xfs that issues discard > > just hangs. > > Wired. I just tried mkfs.xfs against scsi_debug with my block patches > (I saw one discard command). Seemed that it worked fine. My leak fixes have been tested extensively against all permuations of devices with discards (ATA trim, SCSI UNMAP, SCSI WRTIE SAME w/ unmap=1). I think we need to get Christoph's discard payload transformation complete by fixing the leaks _without_ trying to rework how discard commands are tagged, etc. E.g. fix what Jens already has staged in linux-2.6-block's 'for-next' and 'for-2.6.36'. With that sorted out we can then look at longer term changes to cleanup discard request processing. Regards, Mike ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 1/2] block: fix leaks associated with discard request payload 2010-06-27 14:16 ` Mike Snitzer @ 2010-06-27 15:35 ` Christoph Hellwig 2010-06-27 16:23 ` FUJITA Tomonori 0 siblings, 1 reply; 28+ messages in thread From: Christoph Hellwig @ 2010-06-27 15:35 UTC (permalink / raw) To: Mike Snitzer Cc: FUJITA Tomonori, hch, axboe, dm-devel, James.Bottomley, linux-kernel, martin.petersen, akpm, linux-scsi On Sun, Jun 27, 2010 at 10:16:40AM -0400, Mike Snitzer wrote: > My leak fixes have been tested extensively against all permuations of > devices with discards (ATA trim, SCSI UNMAP, SCSI WRTIE SAME w/ unmap=1). > > I think we need to get Christoph's discard payload transformation > complete by fixing the leaks _without_ trying to rework how discard > commands are tagged, etc. E.g. fix what Jens already has staged in > linux-2.6-block's 'for-next' and 'for-2.6.36'. > > With that sorted out we can then look at longer term changes to cleanup > discard request processing. I tend to agree. I'll look into getting rid of treating discards as BLOCK_PC commands ontop of you patchset. ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 1/2] block: fix leaks associated with discard request payload 2010-06-27 15:35 ` Christoph Hellwig @ 2010-06-27 16:23 ` FUJITA Tomonori 0 siblings, 0 replies; 28+ messages in thread From: FUJITA Tomonori @ 2010-06-27 16:23 UTC (permalink / raw) To: hch Cc: snitzer, fujita.tomonori, axboe, dm-devel, James.Bottomley, linux-kernel, martin.petersen, akpm, linux-scsi On Sun, 27 Jun 2010 17:35:45 +0200 Christoph Hellwig <hch@lst.de> wrote: > On Sun, Jun 27, 2010 at 10:16:40AM -0400, Mike Snitzer wrote: > > My leak fixes have been tested extensively against all permuations of > > devices with discards (ATA trim, SCSI UNMAP, SCSI WRTIE SAME w/ unmap=1). > > > > I think we need to get Christoph's discard payload transformation > > complete by fixing the leaks _without_ trying to rework how discard > > commands are tagged, etc. E.g. fix what Jens already has staged in > > linux-2.6-block's 'for-next' and 'for-2.6.36'. > > > > With that sorted out we can then look at longer term changes to cleanup > > discard request processing. > > I tend to agree. I'll look into getting rid of treating discards as > BLOCK_PC commands ontop of you patchset. Let's start from jens' 2.6.36 tree (or it would be better if Jens can drop Christoph's patch). We don't need to start on the top of new discard hacks (specially, the hack in scsi_finish_command looks terrible). We should not merge them into mainline. We are still in rc3. I'll see how things work with other configurations. ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 1/2] block: fix leaks associated with discard request payload 2010-06-27 12:32 ` FUJITA Tomonori 2010-06-27 14:16 ` Mike Snitzer @ 2010-06-27 15:33 ` Christoph Hellwig 2010-06-28 7:57 ` Christoph Hellwig 2 siblings, 0 replies; 28+ messages in thread From: Christoph Hellwig @ 2010-06-27 15:33 UTC (permalink / raw) To: FUJITA Tomonori Cc: hch, snitzer, axboe, dm-devel, James.Bottomley, linux-kernel, martin.petersen, akpm, linux-scsi On Sun, Jun 27, 2010 at 09:32:07PM +0900, FUJITA Tomonori wrote: > On Sun, 27 Jun 2010 13:07:12 +0200 > Christoph Hellwig <hch@lst.de> wrote: > > > > How about this? > > > > As I tried to explain before this utterly confuses the I/O completion > > path. With the patch applied even a simple mkfs.xfs that issues discard > > just hangs. > > Wired. I just tried mkfs.xfs against scsi_debug with my block patches > (I saw one discard command). Seemed that it worked fine. Doesn't work for me against either a real SSD or WRITE SAME support in qemu. But I think I didn't actually have your barrier patches applied, so I'll try again with a clean tree. ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 1/2] block: fix leaks associated with discard request payload 2010-06-27 12:32 ` FUJITA Tomonori 2010-06-27 14:16 ` Mike Snitzer 2010-06-27 15:33 ` Christoph Hellwig @ 2010-06-28 7:57 ` Christoph Hellwig 2010-06-28 8:14 ` FUJITA Tomonori 2 siblings, 1 reply; 28+ messages in thread From: Christoph Hellwig @ 2010-06-28 7:57 UTC (permalink / raw) To: FUJITA Tomonori Cc: hch, snitzer, axboe, dm-devel, James.Bottomley, linux-kernel, martin.petersen, akpm, linux-scsi On Sun, Jun 27, 2010 at 09:32:07PM +0900, FUJITA Tomonori wrote: > On Sun, 27 Jun 2010 13:07:12 +0200 > Christoph Hellwig <hch@lst.de> wrote: > > > > How about this? > > > > As I tried to explain before this utterly confuses the I/O completion > > path. With the patch applied even a simple mkfs.xfs that issues discard > > just hangs. > > Wired. I just tried mkfs.xfs against scsi_debug with my block patches > (I saw one discard command). Seemed that it worked fine. I've tracked it down to the call to scsi_requeue_command in scsi_end_request. When the command is marked BLOCK_PC we'll just get it back as such in ->prep_fn next time, but now it's reverting to the previous state. While I see the problems with leaking ressources in that case I still can't quite explain the hang I see. ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 1/2] block: fix leaks associated with discard request payload 2010-06-28 7:57 ` Christoph Hellwig @ 2010-06-28 8:14 ` FUJITA Tomonori 2010-06-28 8:18 ` Jens Axboe 2010-06-28 15:25 ` Christoph Hellwig 0 siblings, 2 replies; 28+ messages in thread From: FUJITA Tomonori @ 2010-06-28 8:14 UTC (permalink / raw) To: hch Cc: fujita.tomonori, snitzer, axboe, dm-devel, James.Bottomley, linux-kernel, martin.petersen, akpm, linux-scsi On Mon, 28 Jun 2010 09:57:38 +0200 Christoph Hellwig <hch@lst.de> wrote: > On Sun, Jun 27, 2010 at 09:32:07PM +0900, FUJITA Tomonori wrote: > > On Sun, 27 Jun 2010 13:07:12 +0200 > > Christoph Hellwig <hch@lst.de> wrote: > > > > > > How about this? > > > > > > As I tried to explain before this utterly confuses the I/O completion > > > path. With the patch applied even a simple mkfs.xfs that issues discard > > > just hangs. > > > > Wired. I just tried mkfs.xfs against scsi_debug with my block patches > > (I saw one discard command). Seemed that it worked fine. > > I've tracked it down to the call to scsi_requeue_command in scsi_end_request. > When the command is marked BLOCK_PC we'll just get it back as such in > ->prep_fn next time, but now it's reverting to the previous state. If scsi_end_request() calls scsi_requeue_command(), the command has a left over (i.e. hasn't finished all the data), right? You hit such condition with discard commands? BLOCK_PC requests don't hit this case since blk_end_request() always return false for PC. > While I see the problems with leaking ressources in that case I still > can't quite explain the hang I see. Any way to reproduce the hang without ssd drives? ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 1/2] block: fix leaks associated with discard request payload 2010-06-28 8:14 ` FUJITA Tomonori @ 2010-06-28 8:18 ` Jens Axboe 2010-06-28 8:45 ` FUJITA Tomonori 2010-06-28 15:25 ` Christoph Hellwig 1 sibling, 1 reply; 28+ messages in thread From: Jens Axboe @ 2010-06-28 8:18 UTC (permalink / raw) To: FUJITA Tomonori Cc: hch, snitzer, dm-devel, James.Bottomley, linux-kernel, martin.petersen, akpm, linux-scsi On 2010-06-28 10:14, FUJITA Tomonori wrote: > On Mon, 28 Jun 2010 09:57:38 +0200 > Christoph Hellwig <hch@lst.de> wrote: > >> On Sun, Jun 27, 2010 at 09:32:07PM +0900, FUJITA Tomonori wrote: >>> On Sun, 27 Jun 2010 13:07:12 +0200 >>> Christoph Hellwig <hch@lst.de> wrote: >>> >>>>> How about this? >>>> >>>> As I tried to explain before this utterly confuses the I/O completion >>>> path. With the patch applied even a simple mkfs.xfs that issues discard >>>> just hangs. >>> >>> Wired. I just tried mkfs.xfs against scsi_debug with my block patches >>> (I saw one discard command). Seemed that it worked fine. >> >> I've tracked it down to the call to scsi_requeue_command in scsi_end_request. >> When the command is marked BLOCK_PC we'll just get it back as such in >> ->prep_fn next time, but now it's reverting to the previous state. > > If scsi_end_request() calls scsi_requeue_command(), the command has a > left over (i.e. hasn't finished all the data), right? You hit such > condition with discard commands? > > BLOCK_PC requests don't hit this case since blk_end_request() always > return false for PC. You can get requeues on the ->queuecommand() path as well, for a variety of reasons, and that would be what Christoph is hitting. -- Jens Axboe ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 1/2] block: fix leaks associated with discard request payload 2010-06-28 8:18 ` Jens Axboe @ 2010-06-28 8:45 ` FUJITA Tomonori 0 siblings, 0 replies; 28+ messages in thread From: FUJITA Tomonori @ 2010-06-28 8:45 UTC (permalink / raw) To: axboe Cc: fujita.tomonori, hch, snitzer, dm-devel, James.Bottomley, linux-kernel, martin.petersen, akpm, linux-scsi On Mon, 28 Jun 2010 10:18:48 +0200 Jens Axboe <axboe@kernel.dk> wrote: > On 2010-06-28 10:14, FUJITA Tomonori wrote: > > On Mon, 28 Jun 2010 09:57:38 +0200 > > Christoph Hellwig <hch@lst.de> wrote: > > > >> On Sun, Jun 27, 2010 at 09:32:07PM +0900, FUJITA Tomonori wrote: > >>> On Sun, 27 Jun 2010 13:07:12 +0200 > >>> Christoph Hellwig <hch@lst.de> wrote: > >>> > >>>>> How about this? > >>>> > >>>> As I tried to explain before this utterly confuses the I/O completion > >>>> path. With the patch applied even a simple mkfs.xfs that issues discard > >>>> just hangs. > >>> > >>> Wired. I just tried mkfs.xfs against scsi_debug with my block patches > >>> (I saw one discard command). Seemed that it worked fine. > >> > >> I've tracked it down to the call to scsi_requeue_command in scsi_end_request. > >> When the command is marked BLOCK_PC we'll just get it back as such in > >> ->prep_fn next time, but now it's reverting to the previous state. > > > > If scsi_end_request() calls scsi_requeue_command(), the command has a > > left over (i.e. hasn't finished all the data), right? You hit such > > condition with discard commands? > > > > BLOCK_PC requests don't hit this case since blk_end_request() always > > return false for PC. > > You can get requeues on the ->queuecommand() path as well, for a > variety of reasons, and that would be what Christoph is hitting. Probably, that's would be fine (we need to fix memory leak in that path). I guess that requeue with the partial completion commands might cause problems. ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 1/2] block: fix leaks associated with discard request payload 2010-06-28 8:14 ` FUJITA Tomonori 2010-06-28 8:18 ` Jens Axboe @ 2010-06-28 15:25 ` Christoph Hellwig 2010-06-30 11:55 ` FUJITA Tomonori 1 sibling, 1 reply; 28+ messages in thread From: Christoph Hellwig @ 2010-06-28 15:25 UTC (permalink / raw) To: FUJITA Tomonori Cc: hch, snitzer, axboe, dm-devel, James.Bottomley, linux-kernel, martin.petersen, akpm, linux-scsi On Mon, Jun 28, 2010 at 05:14:28PM +0900, FUJITA Tomonori wrote: > > While I see the problems with leaking ressources in that case I still > > can't quite explain the hang I see. > > Any way to reproduce the hang without ssd drives? Actually the SSDs don't fully hang, they just causes lots of I/O errors and hit the error handler hard. The hard hang is when running under qemu. Apply the patch below, then create an if=scsi drive that resides on an XFS filesystem, and you'll have scsi TP support in the guest: Index: qemu/hw/scsi-disk.c =================================================================== --- qemu.orig/hw/scsi-disk.c 2010-06-26 14:40:42.580004436 +0200 +++ qemu/hw/scsi-disk.c 2010-06-26 14:59:20.338020011 +0200 @@ -397,6 +397,7 @@ static int scsi_disk_emulate_inquiry(SCS } case 0xb0: /* block device characteristics */ { + static const int trim_sectors = (2 * 1024 * 1024) / 512; unsigned int min_io_size = s->qdev.conf.min_io_size / s->qdev.blocksize; unsigned int opt_io_size = @@ -416,6 +417,12 @@ static int scsi_disk_emulate_inquiry(SCS outbuf[13] = (opt_io_size >> 16) & 0xff; outbuf[14] = (opt_io_size >> 8) & 0xff; outbuf[15] = opt_io_size & 0xff; + + /* optimal unmap granularity */ + outbuf[28] = (trim_sectors >> 24) & 0xff; + outbuf[29] = (trim_sectors >> 16) & 0xff; + outbuf[30] = (trim_sectors >> 8) & 0xff; + outbuf[31] = trim_sectors & 0xff; break; } default: @@ -824,6 +831,11 @@ static int scsi_disk_emulate_command(SCS outbuf[11] = 0; outbuf[12] = 0; outbuf[13] = get_physical_block_exp(&s->qdev.conf); + + /* set TPE and TPRZ bits if the format supports discard */ + if (bdrv_is_discardable(s->bs)) + outbuf[14] = 0x80 | 0x40; + /* Protection, exponent and lowest lba field left blank. */ buflen = req->cmd.xfer; break; @@ -988,6 +1000,28 @@ static int32_t scsi_send_command(SCSIDev r->sector_count = len * s->cluster_size; is_write = 1; break; + case WRITE_SAME_16: +// printf("WRITE SAME(16) (sector %" PRId64 ", count %d)\n", lba, len); + +// if (lba + len > s->max_lba) + if (lba > s->max_lba) + goto illegal_lba; // check the condition code + /* + * We only support WRITE SAME with the unmap bit set for now. + */ + if (!(buf[1] & 0x8)) + goto fail; + + rc = bdrv_discard(s->bs, lba * s->cluster_size, len * s->cluster_size); + if (rc < 0) { + /* XXX: better error code ?*/ + goto fail; + } + + scsi_req_set_status(&r->req, GOOD, NO_SENSE); + scsi_req_complete(&r->req); + scsi_remove_request(r); + return 0; default: DPRINTF("Unknown SCSI command (%2.2x)\n", buf[0]); fail: Index: qemu/hw/scsi-defs.h =================================================================== --- qemu.orig/hw/scsi-defs.h 2010-06-26 14:40:42.589025947 +0200 +++ qemu/hw/scsi-defs.h 2010-06-26 14:40:43.820253983 +0200 @@ -84,6 +84,7 @@ #define MODE_SENSE_10 0x5a #define PERSISTENT_RESERVE_IN 0x5e #define PERSISTENT_RESERVE_OUT 0x5f +#define WRITE_SAME_16 0x93 #define MAINTENANCE_IN 0xa3 #define MAINTENANCE_OUT 0xa4 #define MOVE_MEDIUM 0xa5 Index: qemu/block.c =================================================================== --- qemu.orig/block.c 2010-06-26 14:40:42.597004296 +0200 +++ qemu/block.c 2010-06-26 14:40:43.824253703 +0200 @@ -1286,6 +1286,11 @@ int bdrv_is_sg(BlockDriverState *bs) return bs->sg; } +int bdrv_is_discardable(BlockDriverState *bs) +{ + return bs->discardable; +} + int bdrv_enable_write_cache(BlockDriverState *bs) { return bs->enable_write_cache; @@ -1431,6 +1436,13 @@ int bdrv_has_zero_init(BlockDriverState return 1; } +int bdrv_discard(BlockDriverState *bs, int64_t sector_num, int nb_sectors) +{ + if (!bs->drv || !bs->drv->bdrv_discard) + return -ENOTSUP; + return bs->drv->bdrv_discard(bs, sector_num, nb_sectors); +} + /* * Returns true iff the specified sector is present in the disk image. Drivers * not implementing the functionality are assumed to not support backing files, Index: qemu/block.h =================================================================== --- qemu.orig/block.h 2010-06-26 14:40:42.606004157 +0200 +++ qemu/block.h 2010-06-26 14:40:43.831254122 +0200 @@ -135,6 +135,7 @@ void bdrv_flush(BlockDriverState *bs); void bdrv_flush_all(void); void bdrv_close_all(void); +int bdrv_discard(BlockDriverState *bs, int64_t sector_num, int nb_sectors); int bdrv_has_zero_init(BlockDriverState *bs); int bdrv_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sectors, int *pnum); @@ -162,6 +163,7 @@ BlockErrorAction bdrv_get_on_error(Block int bdrv_is_removable(BlockDriverState *bs); int bdrv_is_read_only(BlockDriverState *bs); int bdrv_is_sg(BlockDriverState *bs); +int bdrv_is_discardable(BlockDriverState *bs); int bdrv_enable_write_cache(BlockDriverState *bs); int bdrv_is_inserted(BlockDriverState *bs); int bdrv_media_changed(BlockDriverState *bs); Index: qemu/block/raw-posix.c =================================================================== --- qemu.orig/block/raw-posix.c 2010-06-26 14:40:42.614025947 +0200 +++ qemu/block/raw-posix.c 2010-06-26 14:42:33.449255585 +0200 @@ -68,6 +68,10 @@ #include <sys/diskslice.h> #endif +#ifdef CONFIG_XFS +#include <xfs/xfs.h> +#endif + //#define DEBUG_FLOPPY //#define DEBUG_BLOCK @@ -117,6 +121,9 @@ typedef struct BDRVRawState { int use_aio; void *aio_ctx; #endif +#ifdef CONFIG_XFS + int is_xfs : 1; +#endif uint8_t* aligned_buf; } BDRVRawState; @@ -189,6 +196,13 @@ static int raw_open_common(BlockDriverSt #endif } +#ifdef CONFIG_XFS + if (platform_test_xfs_fd(s->fd)) { + s->is_xfs = 1; + bs->discardable = 1; + } +#endif + return 0; out_free_buf: @@ -731,6 +745,36 @@ static void raw_flush(BlockDriverState * qemu_fdatasync(s->fd); } +#ifdef CONFIG_XFS +static int xfs_discard(BDRVRawState *s, int64_t sector_num, int nb_sectors) +{ + struct xfs_flock64 fl; + + memset(&fl, 0, sizeof(fl)); + fl.l_whence = SEEK_SET; + fl.l_start = sector_num << 9; + fl.l_len = (int64_t)nb_sectors << 9; + + if (xfsctl(NULL, s->fd, XFS_IOC_UNRESVSP64, &fl) < 0) { + printf("cannot punch hole (%s)\n", strerror(errno)); + return -errno; + } + + return 0; +} +#endif + +static int raw_discard(BlockDriverState *bs, int64_t sector_num, int nb_sectors) +{ + BDRVRawState *s = bs->opaque; + +#ifdef CONFIG_XFS + if (s->is_xfs) + return xfs_discard(s, sector_num, nb_sectors); +#endif + + return -EOPNOTSUPP; +} static QEMUOptionParameter raw_create_options[] = { { @@ -752,6 +796,7 @@ static BlockDriver bdrv_file = { .bdrv_close = raw_close, .bdrv_create = raw_create, .bdrv_flush = raw_flush, + .bdrv_discard = raw_discard, .bdrv_aio_readv = raw_aio_readv, .bdrv_aio_writev = raw_aio_writev, Index: qemu/block_int.h =================================================================== --- qemu.orig/block_int.h 2010-06-26 14:40:42.636003738 +0200 +++ qemu/block_int.h 2010-06-26 14:40:43.843033002 +0200 @@ -73,6 +73,8 @@ struct BlockDriver { BlockDriverCompletionFunc *cb, void *opaque); BlockDriverAIOCB *(*bdrv_aio_flush)(BlockDriverState *bs, BlockDriverCompletionFunc *cb, void *opaque); + int (*bdrv_discard)(BlockDriverState *bs, int64_t sector_num, + int nb_sectors); int (*bdrv_aio_multiwrite)(BlockDriverState *bs, BlockRequest *reqs, int num_reqs); @@ -141,6 +143,7 @@ struct BlockDriverState { int encrypted; /* if true, the media is encrypted */ int valid_key; /* if true, a valid encryption key has been set */ int sg; /* if true, the device is a /dev/sg* */ + int discardable;/* if true the device supports TRIM/UNMAP */ /* event callback when inserting/removing */ void (*change_cb)(void *opaque); void *change_opaque; Index: qemu/configure =================================================================== --- qemu.orig/configure 2010-06-26 14:40:42.644003947 +0200 +++ qemu/configure 2010-06-26 14:40:43.850005973 +0200 @@ -272,6 +272,7 @@ xen="" linux_aio="" attr="" vhost_net="" +xfs="" gprof="no" debug_tcg="no" @@ -1284,6 +1285,27 @@ EOF fi ########################################## +# xfsctl() probe, used for raw-posix +if test "$xfs" != "no" ; then + cat > $TMPC << EOF +#include <xfs/xfs.h> +int main(void) +{ + xfsctl(NULL, 0, 0, NULL); + return 0; +} +EOF + if compile_prog "" "" ; then + xfs="yes" + else + if test "$xfs" = "yes" ; then + feature_not_found "uuid" + fi + xfs=no + fi +fi + +########################################## # vde libraries probe if test "$vde" != "no" ; then vde_libs="-lvdeplug" @@ -2115,6 +2137,7 @@ echo "preadv support $preadv" echo "fdatasync $fdatasync" echo "uuid support $uuid" echo "vhost-net support $vhost_net" +echo "xfsctl support $xfs" if test $sdl_too_old = "yes"; then echo "-> Your SDL version is too old - please upgrade to have SDL support" @@ -2235,6 +2258,9 @@ fi if test "$uuid" = "yes" ; then echo "CONFIG_UUID=y" >> $config_host_mak fi +if test "$xfs" = "yes" ; then + echo "CONFIG_XFS=y" >> $config_host_mak +fi qemu_version=`head $source_path/VERSION` echo "VERSION=$qemu_version" >>$config_host_mak echo "PKGVERSION=$pkgversion" >>$config_host_mak Index: qemu/block/raw.c =================================================================== --- qemu.orig/block/raw.c 2010-06-26 14:40:42.628004296 +0200 +++ qemu/block/raw.c 2010-06-26 14:40:43.852014913 +0200 @@ -6,6 +6,7 @@ static int raw_open(BlockDriverState *bs, int flags) { bs->sg = bs->file->sg; + bs->discardable = bs->file->discardable; return 0; } @@ -65,6 +66,11 @@ static int raw_probe(const uint8_t *buf, return 1; /* everything can be opened as raw image */ } +static int raw_discard(BlockDriverState *bs, int64_t sector_num, int nb_sectors) +{ + return bdrv_discard(bs->file, sector_num, nb_sectors); +} + static int raw_is_inserted(BlockDriverState *bs) { return bdrv_is_inserted(bs->file); @@ -125,6 +131,7 @@ static BlockDriver bdrv_raw = { .bdrv_aio_readv = raw_aio_readv, .bdrv_aio_writev = raw_aio_writev, .bdrv_aio_flush = raw_aio_flush, + .bdrv_discard = raw_discard, .bdrv_is_inserted = raw_is_inserted, .bdrv_eject = raw_eject, ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 1/2] block: fix leaks associated with discard request payload 2010-06-28 15:25 ` Christoph Hellwig @ 2010-06-30 11:55 ` FUJITA Tomonori 2010-07-01 4:21 ` FUJITA Tomonori 0 siblings, 1 reply; 28+ messages in thread From: FUJITA Tomonori @ 2010-06-30 11:55 UTC (permalink / raw) To: hch Cc: fujita.tomonori, snitzer, axboe, dm-devel, James.Bottomley, linux-kernel, martin.petersen, akpm, linux-scsi On Mon, 28 Jun 2010 17:25:36 +0200 Christoph Hellwig <hch@lst.de> wrote: > On Mon, Jun 28, 2010 at 05:14:28PM +0900, FUJITA Tomonori wrote: > > > While I see the problems with leaking ressources in that case I still > > > can't quite explain the hang I see. > > > > Any way to reproduce the hang without ssd drives? > > Actually the SSDs don't fully hang, they just causes lots of I/O errors > and hit the error handler hard. The hard hang is when running under > qemu. Apply the patch below, then create an if=scsi drive that resides > on an XFS filesystem, and you'll have scsi TP support in the guest: Ok, I figured out what's wrong. As I suspected, it's due to the partial completion. qemu scsi driver tells that the WRITE_SAME command was successful but somehow the command has resid. So we retry it again and again (and leak some memory). I don't know yet why qemu scsi driver is broken. Maybe there is a bug in it or converting discard to FS sends broken commands to the driver. I'll try to figure out it tomorrow. I've put a patch to complete discard command in the all-or-nothing manner: git://git.kernel.org/pub/scm/linux/kernel/git/tomo/linux-2.6-misc.git discard At least, the guest kernel doesn't hang for me. ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 1/2] block: fix leaks associated with discard request payload 2010-06-30 11:55 ` FUJITA Tomonori @ 2010-07-01 4:21 ` FUJITA Tomonori 0 siblings, 0 replies; 28+ messages in thread From: FUJITA Tomonori @ 2010-07-01 4:21 UTC (permalink / raw) To: hch Cc: snitzer, axboe, dm-devel, James.Bottomley, linux-kernel, martin.petersen, akpm, linux-scsi On Wed, 30 Jun 2010 20:55:09 +0900 FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> wrote: > On Mon, 28 Jun 2010 17:25:36 +0200 > Christoph Hellwig <hch@lst.de> wrote: > > > On Mon, Jun 28, 2010 at 05:14:28PM +0900, FUJITA Tomonori wrote: > > > > While I see the problems with leaking ressources in that case I still > > > > can't quite explain the hang I see. > > > > > > Any way to reproduce the hang without ssd drives? > > > > Actually the SSDs don't fully hang, they just causes lots of I/O errors > > and hit the error handler hard. The hard hang is when running under > > qemu. Apply the patch below, then create an if=scsi drive that resides > > on an XFS filesystem, and you'll have scsi TP support in the guest: > > Ok, I figured out what's wrong. > > As I suspected, it's due to the partial completion. > > qemu scsi driver tells that the WRITE_SAME command was successful but > somehow the command has resid. So we retry it again and again (and > leak some memory). > > I don't know yet why qemu scsi driver is broken. Maybe there is a bug > in it or converting discard to FS sends broken commands to the driver. looks like your qemu WRITE_SAME patch isn't completed :) You implement WRITE_SAME as if it doesn't do any data transfer. So qemu scsi driver gets resid. The reason why WRITE_SAME works now is that scsi-ml doesn't care about resid with PC commands but it cares with FS commands. I confirmed that qemu scsi driver gets the identical command with both PC and FS commands and qemu calls xfsctl. > I've put a patch to complete discard command in the all-or-nothing > manner: > > git://git.kernel.org/pub/scm/linux/kernel/git/tomo/linux-2.6-misc.git discard Seems that I finished discard FS conversion. I'll update it on the top of James' uprep patchset soon. ^ permalink raw reply [flat|nested] 28+ messages in thread
[parent not found: <20100622180029.GA15950@redhat.com>]
[parent not found: <1277582211-10725-1-git-send-email-snitzer@redhat.com>]
* Re: [PATCH 1/2] block: fix leaks associated with discard request payload [not found] ` <1277582211-10725-1-git-send-email-snitzer@redhat.com> @ 2010-06-27 15:29 ` James Bottomley 2010-06-28 17:16 ` Martin K. Petersen ` (2 more replies) 0 siblings, 3 replies; 28+ messages in thread From: James Bottomley @ 2010-06-27 15:29 UTC (permalink / raw) To: Mike Snitzer Cc: Christoph Hellwig, axboe, dm-devel, linux-kernel, martin.petersen, akpm, linux-scsi, FUJITA Tomonori linux-scsi cc added, since it's a SCSI patch. On Sat, 2010-06-26 at 15:56 -0400, Mike Snitzer wrote: > Fix leaks introduced via "block: don't allocate a payload for discard > request" commit a1d949f5f44. > > sd_done() is not called for REQ_TYPE_BLOCK_PC commands so cleanup > discard request's payload directly in scsi_finish_command(). > > Also cleanup page allocated for discard payload in > scsi_setup_discard_cmnd's scsi_setup_blk_pc_cmnd error path. > > Signed-off-by: Mike Snitzer <snitzer@redhat.com> > --- > block/blk-core.c | 23 +++++++++++++++++++++++ > drivers/scsi/scsi.c | 8 ++++++++ > drivers/scsi/sd.c | 18 ++++++++---------- > include/linux/blkdev.h | 1 + > 4 files changed, 40 insertions(+), 10 deletions(-) > > diff --git a/block/blk-core.c b/block/blk-core.c > index 98b4cee..07925aa 100644 > --- a/block/blk-core.c > +++ b/block/blk-core.c > @@ -1167,6 +1167,29 @@ void blk_add_request_payload(struct request *rq, struct page *page, > } > EXPORT_SYMBOL_GPL(blk_add_request_payload); > > +/** > + * blk_clear_request_payload - clear a request's payload > + * @rq: request to update > + * > + * The driver needs to take care of freeing the payload itself. > + */ > +void blk_clear_request_payload(struct request *rq) > +{ > + struct bio *bio = rq->bio; > + > + rq->__data_len = rq->resid_len = 0; > + rq->nr_phys_segments = 0; > + rq->buffer = NULL; > + > + bio->bi_size = 0; > + bio->bi_vcnt = 0; > + bio->bi_phys_segments = 0; > + > + bio->bi_io_vec->bv_page = NULL; > + bio->bi_io_vec->bv_len = 0; > +} > +EXPORT_SYMBOL_GPL(blk_clear_request_payload); > + > void init_request_from_bio(struct request *req, struct bio *bio) > { > req->cpu = bio->bi_comp_cpu; > diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c > index ad0ed21..69c7ea4 100644 > --- a/drivers/scsi/scsi.c > +++ b/drivers/scsi/scsi.c > @@ -851,6 +851,14 @@ void scsi_finish_command(struct scsi_cmnd *cmd) > */ > if (good_bytes == old_good_bytes) > good_bytes -= scsi_get_resid(cmd); > + } else if (cmd->request->cmd_flags & REQ_DISCARD) { > + /* > + * If this is a discard request that originated from the kernel > + * we need to free our payload here. Note that we need to check > + * the request flag as the normal payload rules apply for > + * pass-through UNMAP / WRITE SAME requests. > + */ > + __free_page(bio_page(cmd->request->bio)); This is another layering violation: the page is allocated in the Upper layer and freed in the mid-layer. I really hate these growing contortions for discard. They're a clear signal that we haven't implemented it right. So let's first work out how it should be done. I really like Tomo's idea of doing discard through the normal REQ_TYPE_FS route, which means we can control the setup in prep and the tear down in done, all confined to the ULD. Where I think I'm at is partially what Christoph says: The command transformation belongs in the ULD so that's where the allocation and deallocation should be, and partly what Tomo says in that we should eliminate the special case paths. The payload vs actual request size should be a red herring if we've got everything correct: only the ULD cares about the request parameters. Once we've got everything set up, the mid layer and LLD should only care about the parameters in the command, so we can confine the size changing part to the ULD doing the discard. Could someone take a stab at this and see if it works without layering violations or any other problematic signals? Thanks, James ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 1/2] block: fix leaks associated with discard request payload 2010-06-27 15:29 ` James Bottomley @ 2010-06-28 17:16 ` Martin K. Petersen 2010-06-29 8:00 ` Boaz Harrosh 2010-06-29 22:28 ` [dm-devel] " Mikulas Patocka 2010-06-30 8:32 ` Boaz Harrosh 2 siblings, 1 reply; 28+ messages in thread From: Martin K. Petersen @ 2010-06-28 17:16 UTC (permalink / raw) To: James Bottomley Cc: Mike Snitzer, Christoph Hellwig, axboe, dm-devel, linux-kernel, martin.petersen, akpm, linux-scsi, FUJITA Tomonori >>>>> "James" == James Bottomley <James.Bottomley@suse.de> writes: James> I really hate these growing contortions for discard. They're a James> clear signal that we haven't implemented it right. James> So let's first work out how it should be done. I really like James> Tomo's idea of doing discard through the normal REQ_TYPE_FS James> route, which means we can control the setup in prep and the tear James> down in done, all confined to the ULD. Yeah, this is what I was trying to do a couple of months ago. Trying to make discard and write same filesystem class requests so we can split, merge, etc. like READs and WRITEs. I still think this is how we should do it but it's a lot of work. There are several challenges involved. I was doing the "payload" allocation at request allocation time by permitting a buffer trailing struct request (size defined by ULD depending on req type). However, we have a few places in the stack where we memcpy requests and assume them to be the same size. That needs to be fixed. That's also the roadblock I ran into wrt. 32-byte CDB allocation so for that I ended up allocating the command in sd. Also, another major headache of mine is WRITE SAME/UNMAP to DSM TRIM conversion. Because of the limitations of the TRIM command format a single WRITE SAME can turn into effectively hundreds of TRIM commands to be issued. I tried to limit this by using UNMAP translation instead. But we can still get into cases where we need to either loop or allocate a bunch of TRIMs in the translation layer. That leaves two options: Either pass really conservative limits up the stack and loop up there. Or deal with the allocation/translation stuff at the bottom of the pile. None of my attempts in these departments turned out to be very nice. I'm still dreaming of the day where libata moves out from under SCSI so we don't have to translate square pegs into round holes... -- Martin K. Petersen Oracle Linux Engineering ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 1/2] block: fix leaks associated with discard request payload 2010-06-28 17:16 ` Martin K. Petersen @ 2010-06-29 8:00 ` Boaz Harrosh 0 siblings, 0 replies; 28+ messages in thread From: Boaz Harrosh @ 2010-06-29 8:00 UTC (permalink / raw) To: Martin K. Petersen Cc: James Bottomley, Mike Snitzer, Christoph Hellwig, axboe, dm-devel, linux-kernel, akpm, linux-scsi, FUJITA Tomonori On 06/28/2010 08:16 PM, Martin K. Petersen wrote: > I'm still dreaming of the day where libata moves out from under SCSI so > we don't have to translate square pegs into round holes... > Hi Martin. Is that on the Radar still? what would you say are the major issues holding it back? * Is it just the missing new ULD, Will we be using a new ULD? * Is it the ata midlayer that would duplicate some of scsi-midlayer. (Not so much these days, lots of good code went into blk_rq_) * Is it the distro's setup procedures changing yet again back to the hd vs sd times. Thanks Boaz ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [dm-devel] [PATCH 1/2] block: fix leaks associated with discard request payload 2010-06-27 15:29 ` James Bottomley 2010-06-28 17:16 ` Martin K. Petersen @ 2010-06-29 22:28 ` Mikulas Patocka 2010-06-29 23:03 ` James Bottomley 2010-06-30 8:32 ` Boaz Harrosh 2 siblings, 1 reply; 28+ messages in thread From: Mikulas Patocka @ 2010-06-29 22:28 UTC (permalink / raw) To: device-mapper development Cc: Mike Snitzer, axboe, linux-scsi, martin.petersen, linux-kernel, akpm, Christoph Hellwig On Sun, 27 Jun 2010, James Bottomley wrote: > linux-scsi cc added, since it's a SCSI patch. > > On Sat, 2010-06-26 at 15:56 -0400, Mike Snitzer wrote: > > Fix leaks introduced via "block: don't allocate a payload for discard > > request" commit a1d949f5f44. > > > > sd_done() is not called for REQ_TYPE_BLOCK_PC commands so cleanup > > discard request's payload directly in scsi_finish_command(). > > > > Also cleanup page allocated for discard payload in > > scsi_setup_discard_cmnd's scsi_setup_blk_pc_cmnd error path. > > > > Signed-off-by: Mike Snitzer <snitzer@redhat.com> > > --- > > block/blk-core.c | 23 +++++++++++++++++++++++ > > drivers/scsi/scsi.c | 8 ++++++++ > > drivers/scsi/sd.c | 18 ++++++++---------- > > include/linux/blkdev.h | 1 + > > 4 files changed, 40 insertions(+), 10 deletions(-) > > > > diff --git a/block/blk-core.c b/block/blk-core.c > > index 98b4cee..07925aa 100644 > > --- a/block/blk-core.c > > +++ b/block/blk-core.c > > @@ -1167,6 +1167,29 @@ void blk_add_request_payload(struct request *rq, struct page *page, > > } > > EXPORT_SYMBOL_GPL(blk_add_request_payload); > > > > +/** > > + * blk_clear_request_payload - clear a request's payload > > + * @rq: request to update > > + * > > + * The driver needs to take care of freeing the payload itself. > > + */ > > +void blk_clear_request_payload(struct request *rq) > > +{ > > + struct bio *bio = rq->bio; > > + > > + rq->__data_len = rq->resid_len = 0; > > + rq->nr_phys_segments = 0; > > + rq->buffer = NULL; > > + > > + bio->bi_size = 0; > > + bio->bi_vcnt = 0; > > + bio->bi_phys_segments = 0; > > + > > + bio->bi_io_vec->bv_page = NULL; > > + bio->bi_io_vec->bv_len = 0; > > +} > > +EXPORT_SYMBOL_GPL(blk_clear_request_payload); > > + > > void init_request_from_bio(struct request *req, struct bio *bio) > > { > > req->cpu = bio->bi_comp_cpu; > > diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c > > index ad0ed21..69c7ea4 100644 > > --- a/drivers/scsi/scsi.c > > +++ b/drivers/scsi/scsi.c > > @@ -851,6 +851,14 @@ void scsi_finish_command(struct scsi_cmnd *cmd) > > */ > > if (good_bytes == old_good_bytes) > > good_bytes -= scsi_get_resid(cmd); > > + } else if (cmd->request->cmd_flags & REQ_DISCARD) { > > + /* > > + * If this is a discard request that originated from the kernel > > + * we need to free our payload here. Note that we need to check > > + * the request flag as the normal payload rules apply for > > + * pass-through UNMAP / WRITE SAME requests. > > + */ > > + __free_page(bio_page(cmd->request->bio)); > > This is another layering violation: the page is allocated in the Upper > layer and freed in the mid-layer. > > I really hate these growing contortions for discard. They're a clear > signal that we haven't implemented it right. > > So let's first work out how it should be done. I really like Tomo's > idea of doing discard through the normal REQ_TYPE_FS route, which means > we can control the setup in prep and the tear down in done, all confined > to the ULD. > > Where I think I'm at is partially what Christoph says: The command > transformation belongs in the ULD so that's where the allocation and > deallocation should be, and partly what Tomo says in that we should > eliminate the special case paths. > > The payload vs actual request size should be a red herring if we've got > everything correct: only the ULD cares about the request parameters. > Once we've got everything set up, the mid layer and LLD should only care > about the parameters in the command, so we can confine the size changing > part to the ULD doing the discard. > > Could someone take a stab at this and see if it works without layering > violations or any other problematic signals? > > Thanks, > > James Well, I think that you overestimate the importance of scsi code too much. There is a layering violation in the code. So what --- you either fix the layering violation or let it be there and grind your teeth on it. But in either case, that layering violation won't affect anyone except scsi developers. On the other hand, if you say "because we want to avoid layering violation in SCSI, every issuer of discard request must supply an empty page", you create havoc all over the Linux codebase. md, dm, drbd, xvd, virtio --- whatever you think of, will be allocating a dummy page when constructing a discard request. If the layering violation spans only scsi code, it can be eventually fixed, but this, much worse "layering violation" that will be spanning all block device midlayers, won't ever be fixed. Imagine for example --- a discard request arrivers at a dm-snapshot device. The driver splits it into chunks, remaps each chunk to the physical chunk, submits the requests, the elevator merges adjacent requests and submits fewer bigger requests to the device. Now, if you had to allocate a zeroed page each time you are splitting the request, that would exhaust memory and burn cpu needlessly. You delete a 100MB file? --- fine, allocate a 100MB of zeroed pages. So I say --- let there be a layering violation in the scsi code, but don't put this problem with a page allocation to all the other bio midlayer developers. Mikulas ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [dm-devel] [PATCH 1/2] block: fix leaks associated with discard request payload 2010-06-29 22:28 ` [dm-devel] " Mikulas Patocka @ 2010-06-29 23:03 ` James Bottomley 2010-06-29 23:51 ` Mike Snitzer 2010-06-30 0:11 ` [dm-devel] " Mikulas Patocka 0 siblings, 2 replies; 28+ messages in thread From: James Bottomley @ 2010-06-29 23:03 UTC (permalink / raw) To: Mikulas Patocka Cc: device-mapper development, Mike Snitzer, axboe, linux-scsi, martin.petersen, linux-kernel, akpm, Christoph Hellwig On Tue, 2010-06-29 at 18:28 -0400, Mikulas Patocka wrote: > > On Sun, 27 Jun 2010, James Bottomley wrote: > > > linux-scsi cc added, since it's a SCSI patch. > > > > On Sat, 2010-06-26 at 15:56 -0400, Mike Snitzer wrote: > > > Fix leaks introduced via "block: don't allocate a payload for discard > > > request" commit a1d949f5f44. > > > > > > sd_done() is not called for REQ_TYPE_BLOCK_PC commands so cleanup > > > discard request's payload directly in scsi_finish_command(). > > > > > > Also cleanup page allocated for discard payload in > > > scsi_setup_discard_cmnd's scsi_setup_blk_pc_cmnd error path. > > > > > > Signed-off-by: Mike Snitzer <snitzer@redhat.com> > > > --- > > > block/blk-core.c | 23 +++++++++++++++++++++++ > > > drivers/scsi/scsi.c | 8 ++++++++ > > > drivers/scsi/sd.c | 18 ++++++++---------- > > > include/linux/blkdev.h | 1 + > > > 4 files changed, 40 insertions(+), 10 deletions(-) > > > > > > diff --git a/block/blk-core.c b/block/blk-core.c > > > index 98b4cee..07925aa 100644 > > > --- a/block/blk-core.c > > > +++ b/block/blk-core.c > > > @@ -1167,6 +1167,29 @@ void blk_add_request_payload(struct request *rq, struct page *page, > > > } > > > EXPORT_SYMBOL_GPL(blk_add_request_payload); > > > > > > +/** > > > + * blk_clear_request_payload - clear a request's payload > > > + * @rq: request to update > > > + * > > > + * The driver needs to take care of freeing the payload itself. > > > + */ > > > +void blk_clear_request_payload(struct request *rq) > > > +{ > > > + struct bio *bio = rq->bio; > > > + > > > + rq->__data_len = rq->resid_len = 0; > > > + rq->nr_phys_segments = 0; > > > + rq->buffer = NULL; > > > + > > > + bio->bi_size = 0; > > > + bio->bi_vcnt = 0; > > > + bio->bi_phys_segments = 0; > > > + > > > + bio->bi_io_vec->bv_page = NULL; > > > + bio->bi_io_vec->bv_len = 0; > > > +} > > > +EXPORT_SYMBOL_GPL(blk_clear_request_payload); > > > + > > > void init_request_from_bio(struct request *req, struct bio *bio) > > > { > > > req->cpu = bio->bi_comp_cpu; > > > diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c > > > index ad0ed21..69c7ea4 100644 > > > --- a/drivers/scsi/scsi.c > > > +++ b/drivers/scsi/scsi.c > > > @@ -851,6 +851,14 @@ void scsi_finish_command(struct scsi_cmnd *cmd) > > > */ > > > if (good_bytes == old_good_bytes) > > > good_bytes -= scsi_get_resid(cmd); > > > + } else if (cmd->request->cmd_flags & REQ_DISCARD) { > > > + /* > > > + * If this is a discard request that originated from the kernel > > > + * we need to free our payload here. Note that we need to check > > > + * the request flag as the normal payload rules apply for > > > + * pass-through UNMAP / WRITE SAME requests. > > > + */ > > > + __free_page(bio_page(cmd->request->bio)); > > > > This is another layering violation: the page is allocated in the Upper > > layer and freed in the mid-layer. > > > > I really hate these growing contortions for discard. They're a clear > > signal that we haven't implemented it right. > > > > So let's first work out how it should be done. I really like Tomo's > > idea of doing discard through the normal REQ_TYPE_FS route, which means > > we can control the setup in prep and the tear down in done, all confined > > to the ULD. > > > > Where I think I'm at is partially what Christoph says: The command > > transformation belongs in the ULD so that's where the allocation and > > deallocation should be, and partly what Tomo says in that we should > > eliminate the special case paths. > > > > The payload vs actual request size should be a red herring if we've got > > everything correct: only the ULD cares about the request parameters. > > Once we've got everything set up, the mid layer and LLD should only care > > about the parameters in the command, so we can confine the size changing > > part to the ULD doing the discard. > > > > Could someone take a stab at this and see if it works without layering > > violations or any other problematic signals? > > > > Thanks, > > > > James > > Well, I think that you overestimate the importance of scsi code too much. Not, I think, a deadly sin for a SCSI maintainer. > There is a layering violation in the code. So what --- you either fix the > layering violation or let it be there and grind your teeth on it. But in > either case, that layering violation won't affect anyone except scsi > developers. A layering violation is a signal of bad design wherever it occurs, so that wasn't a SCSI centric argument. > On the other hand, if you say "because we want to avoid layering violation > in SCSI, every issuer of discard request must supply an empty page", you > create havoc all over the Linux codebase. md, dm, drbd, xvd, virtio --- > whatever you think of, will be allocating a dummy page when constructing > a discard request. Since I didn't actually say any of that, I suggest you re-read text you quoted above. The phrase "The command transformation belongs in the ULD so that's where the allocation and deallocation should be" might be a relevant one to concentrate on. > If the layering violation spans only scsi code, it can be eventually > fixed, but this, much worse "layering violation" that will be spanning all > block device midlayers, won't ever be fixed. > > Imagine for example --- a discard request arrivers at a dm-snapshot > device. The driver splits it into chunks, remaps each chunk to the > physical chunk, submits the requests, the elevator merges adjacent > requests and submits fewer bigger requests to the device. Now, if you had > to allocate a zeroed page each time you are splitting the request, that > would exhaust memory and burn cpu needlessly. You delete a 100MB file? --- > fine, allocate a 100MB of zeroed pages. This is a straw man: You've tried to portray a position I've never taken as mine then attack it ... with what is effectively another bogus argument. It's not an either/or choice. I've asked the relevant parties to combine the approaches and see if a REQ_TYPE_FS path that does the allocations in the appropriate place, likely the ULD, produces a good design. > So I say --- let there be a layering violation in the scsi code, but don't > put this problem with a page allocation to all the other bio midlayer > developers. Thanks for explaining that you have nothing to contribute, I'll make sure you're not on my list of relevant parties. James ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 1/2] block: fix leaks associated with discard request payload 2010-06-29 23:03 ` James Bottomley @ 2010-06-29 23:51 ` Mike Snitzer 2010-06-30 0:11 ` [dm-devel] " Mikulas Patocka 1 sibling, 0 replies; 28+ messages in thread From: Mike Snitzer @ 2010-06-29 23:51 UTC (permalink / raw) To: James Bottomley Cc: axboe, linux-scsi, martin.petersen, linux-kernel, device-mapper development, Mikulas Patocka, akpm, Christoph Hellwig On Tue, Jun 29 2010 at 7:03pm -0400, James Bottomley <James.Bottomley@suse.de> wrote: > On Tue, 2010-06-29 at 18:28 -0400, Mikulas Patocka wrote: > > > > On Sun, 27 Jun 2010, James Bottomley wrote: > > > > > linux-scsi cc added, since it's a SCSI patch. > > > > > > On Sat, 2010-06-26 at 15:56 -0400, Mike Snitzer wrote: > > > > Fix leaks introduced via "block: don't allocate a payload for discard > > > > request" commit a1d949f5f44. > > > > > > > > sd_done() is not called for REQ_TYPE_BLOCK_PC commands so cleanup > > > > discard request's payload directly in scsi_finish_command(). > > > > > > > > Also cleanup page allocated for discard payload in > > > > scsi_setup_discard_cmnd's scsi_setup_blk_pc_cmnd error path. > > > > > > > > Signed-off-by: Mike Snitzer <snitzer@redhat.com> > > > > --- > > > > block/blk-core.c | 23 +++++++++++++++++++++++ > > > > drivers/scsi/scsi.c | 8 ++++++++ > > > > drivers/scsi/sd.c | 18 ++++++++---------- > > > > include/linux/blkdev.h | 1 + > > > > 4 files changed, 40 insertions(+), 10 deletions(-) > > > > > > > > diff --git a/block/blk-core.c b/block/blk-core.c > > > > index 98b4cee..07925aa 100644 > > > > --- a/block/blk-core.c > > > > +++ b/block/blk-core.c > > > > @@ -1167,6 +1167,29 @@ void blk_add_request_payload(struct request *rq, struct page *page, > > > > } > > > > EXPORT_SYMBOL_GPL(blk_add_request_payload); > > > > > > > > +/** > > > > + * blk_clear_request_payload - clear a request's payload > > > > + * @rq: request to update > > > > + * > > > > + * The driver needs to take care of freeing the payload itself. > > > > + */ > > > > +void blk_clear_request_payload(struct request *rq) > > > > +{ > > > > + struct bio *bio = rq->bio; > > > > + > > > > + rq->__data_len = rq->resid_len = 0; > > > > + rq->nr_phys_segments = 0; > > > > + rq->buffer = NULL; > > > > + > > > > + bio->bi_size = 0; > > > > + bio->bi_vcnt = 0; > > > > + bio->bi_phys_segments = 0; > > > > + > > > > + bio->bi_io_vec->bv_page = NULL; > > > > + bio->bi_io_vec->bv_len = 0; > > > > +} > > > > +EXPORT_SYMBOL_GPL(blk_clear_request_payload); > > > > + > > > > void init_request_from_bio(struct request *req, struct bio *bio) > > > > { > > > > req->cpu = bio->bi_comp_cpu; > > > > diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c > > > > index ad0ed21..69c7ea4 100644 > > > > --- a/drivers/scsi/scsi.c > > > > +++ b/drivers/scsi/scsi.c > > > > @@ -851,6 +851,14 @@ void scsi_finish_command(struct scsi_cmnd *cmd) > > > > */ > > > > if (good_bytes == old_good_bytes) > > > > good_bytes -= scsi_get_resid(cmd); > > > > + } else if (cmd->request->cmd_flags & REQ_DISCARD) { > > > > + /* > > > > + * If this is a discard request that originated from the kernel > > > > + * we need to free our payload here. Note that we need to check > > > > + * the request flag as the normal payload rules apply for > > > > + * pass-through UNMAP / WRITE SAME requests. > > > > + */ > > > > + __free_page(bio_page(cmd->request->bio)); > > > > > > This is another layering violation: the page is allocated in the Upper > > > layer and freed in the mid-layer. > > > > > > I really hate these growing contortions for discard. They're a clear > > > signal that we haven't implemented it right. > > > > > > So let's first work out how it should be done. I really like Tomo's > > > idea of doing discard through the normal REQ_TYPE_FS route, which means > > > we can control the setup in prep and the tear down in done, all confined > > > to the ULD. > > > > > > Where I think I'm at is partially what Christoph says: The command > > > transformation belongs in the ULD so that's where the allocation and > > > deallocation should be, and partly what Tomo says in that we should > > > eliminate the special case paths. > > > > > > The payload vs actual request size should be a red herring if we've got > > > everything correct: only the ULD cares about the request parameters. > > > Once we've got everything set up, the mid layer and LLD should only care > > > about the parameters in the command, so we can confine the size changing > > > part to the ULD doing the discard. > > > > > > Could someone take a stab at this and see if it works without layering > > > violations or any other problematic signals? > > > > > > Thanks, > > > > > > James > > > > Well, I think that you overestimate the importance of scsi code too much. > > Not, I think, a deadly sin for a SCSI maintainer. Indeed ;) > > There is a layering violation in the code. So what --- you either fix the > > layering violation or let it be there and grind your teeth on it. But in > > either case, that layering violation won't affect anyone except scsi > > developers. > > A layering violation is a signal of bad design wherever it occurs, so > that wasn't a SCSI centric argument. > > > On the other hand, if you say "because we want to avoid layering violation > > in SCSI, every issuer of discard request must supply an empty page", you > > create havoc all over the Linux codebase. md, dm, drbd, xvd, virtio --- > > whatever you think of, will be allocating a dummy page when constructing > > a discard request. > > Since I didn't actually say any of that, I suggest you re-read text you > quoted above. The phrase "The command transformation belongs in the ULD > so that's where the allocation and deallocation should be" might be a > relevant one to concentrate on. Right, freeing the page, that was allocated in SCSI's ULD, from the SCSI midlayer is a SCSI layering violation. I think Mikulas was reacting to the desire to maintain the existing, arguably more problematic, layering violation that spans the block and SCSI layers. > > If the layering violation spans only scsi code, it can be eventually > > fixed, but this, much worse "layering violation" that will be spanning all > > block device midlayers, won't ever be fixed. > > > > Imagine for example --- a discard request arrivers at a dm-snapshot > > device. The driver splits it into chunks, remaps each chunk to the > > physical chunk, submits the requests, the elevator merges adjacent > > requests and submits fewer bigger requests to the device. Now, if you had > > to allocate a zeroed page each time you are splitting the request, that > > would exhaust memory and burn cpu needlessly. You delete a 100MB file? --- > > fine, allocate a 100MB of zeroed pages. > > This is a straw man: You've tried to portray a position I've never > taken as mine then attack it ... with what is effectively another bogus > argument. > > It's not an either/or choice. I've asked the relevant parties to > combine the approaches and see if a REQ_TYPE_FS path that does the > allocations in the appropriate place, likely the ULD, produces a good > design. If in the end we can fix up SCSI properly then everyone is happy. So lets just keep working toward that. The various attempts to convert discard over to REQ_TYPE_FS have fallen short. Hopefully we'll have a break through shortly. Thanks for your guidance James, Mike ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [dm-devel] [PATCH 1/2] block: fix leaks associated with discard request payload 2010-06-29 23:03 ` James Bottomley 2010-06-29 23:51 ` Mike Snitzer @ 2010-06-30 0:11 ` Mikulas Patocka 2010-06-30 14:22 ` James Bottomley 1 sibling, 1 reply; 28+ messages in thread From: Mikulas Patocka @ 2010-06-30 0:11 UTC (permalink / raw) To: James Bottomley Cc: device-mapper development, Mike Snitzer, axboe, linux-scsi, martin.petersen, linux-kernel, akpm, Christoph Hellwig > > If the layering violation spans only scsi code, it can be eventually > > fixed, but this, much worse "layering violation" that will be spanning all > > block device midlayers, won't ever be fixed. > > > > Imagine for example --- a discard request arrivers at a dm-snapshot > > device. The driver splits it into chunks, remaps each chunk to the > > physical chunk, submits the requests, the elevator merges adjacent > > requests and submits fewer bigger requests to the device. Now, if you had > > to allocate a zeroed page each time you are splitting the request, that > > would exhaust memory and burn cpu needlessly. You delete a 100MB file? --- > > fine, allocate a 100MB of zeroed pages. > > This is a straw man: You've tried to portray a position I've never > taken as mine then attack it ... with what is effectively another bogus > argument. > > It's not an either/or choice. It is either/or choice. If the interface isn't fixed NOW, the existing flawed zeroed-page-allocation interface gets into RHEL and I and others will have to support it for 7 years. > I've asked the relevant parties to > combine the approaches and see if a REQ_TYPE_FS path that does the > allocations in the appropriate place, likely the ULD, produces a good > design. OK, but before you do this research, fix the interface. > > So I say --- let there be a layering violation in the scsi code, but don't > > put this problem with a page allocation to all the other bio midlayer > > developers. > > Thanks for explaining that you have nothing to contribute, I'll make > sure you're not on my list of relevant parties. You misunderstand what I meant. You admit that there are design problems in SCSI. So don't burden other developers with these problems. Don't force the others to allocate dummy pages just because you want a cleaner scsi code. You intend to fix the design of SCSI and then remove the dummy pages. But by the time you finish it, it will be already late and there will be midlayer drivers allocating these dummy pages. What I mean is that "layering violation" inside one driver is smaller problem than misdesigned interface between drivers. So accept the patch that creates "layering violation" but cleans up the interface. Mikulas ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [dm-devel] [PATCH 1/2] block: fix leaks associated with discard request payload 2010-06-30 0:11 ` [dm-devel] " Mikulas Patocka @ 2010-06-30 14:22 ` James Bottomley 2010-06-30 15:36 ` Mike Snitzer 2010-07-01 12:28 ` [dm-devel] " Mikulas Patocka 0 siblings, 2 replies; 28+ messages in thread From: James Bottomley @ 2010-06-30 14:22 UTC (permalink / raw) To: Mikulas Patocka Cc: device-mapper development, Mike Snitzer, axboe, linux-scsi, martin.petersen, linux-kernel, akpm, Christoph Hellwig On Tue, 2010-06-29 at 20:11 -0400, Mikulas Patocka wrote: > > > If the layering violation spans only scsi code, it can be eventually > > > fixed, but this, much worse "layering violation" that will be spanning all > > > block device midlayers, won't ever be fixed. > > > > > > Imagine for example --- a discard request arrivers at a dm-snapshot > > > device. The driver splits it into chunks, remaps each chunk to the > > > physical chunk, submits the requests, the elevator merges adjacent > > > requests and submits fewer bigger requests to the device. Now, if you had > > > to allocate a zeroed page each time you are splitting the request, that > > > would exhaust memory and burn cpu needlessly. You delete a 100MB file? --- > > > fine, allocate a 100MB of zeroed pages. > > > > This is a straw man: You've tried to portray a position I've never > > taken as mine then attack it ... with what is effectively another bogus > > argument. > > > > It's not an either/or choice. > > It is either/or choice. If the interface isn't fixed NOW, the existing > flawed zeroed-page-allocation interface gets into RHEL That's a false dichotomy. You might see an either apply this hack now or support the interface choice with RHEL, but upstream has the option to fix stuff correctly. RHEL has never needed my blessing to apply random crap to their kernel before ... why is this patch any different? > and I and others will have to support it for 7 years. It's called a business model ... I believe it's what they pay you for. > > I've asked the relevant parties to > > combine the approaches and see if a REQ_TYPE_FS path that does the > > allocations in the appropriate place, likely the ULD, produces a good > > design. > > OK, but before you do this research, fix the interface. So even in the RHEL world, I think you'd find that analysing the problem *before* comping up with a fix is a good way of doing things. > > > So I say --- let there be a layering violation in the scsi code, but don't > > > put this problem with a page allocation to all the other bio midlayer > > > developers. > > > > Thanks for explaining that you have nothing to contribute, I'll make > > sure you're not on my list of relevant parties. > > You misunderstand what I meant. You admit that there are design problems > in SCSI. No I didn't. And the rest of this rubbish is based on that false premise. It might help you to take off your SCSI antipathy and see this as a system problem: it actually originates in block and spills out from there. Thus it requires a system solution. James > So don't burden other developers with these problems. Don't force > the others to allocate dummy pages just because you want a cleaner scsi > code. > > You intend to fix the design of SCSI and then remove the dummy pages. But > by the time you finish it, it will be already late and there will be > midlayer drivers allocating these dummy pages. > > What I mean is that "layering violation" inside one driver is smaller > problem than misdesigned interface between drivers. So accept the patch > that creates "layering violation" but cleans up the interface. > > Mikulas ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 1/2] block: fix leaks associated with discard request payload 2010-06-30 14:22 ` James Bottomley @ 2010-06-30 15:36 ` Mike Snitzer 2010-06-30 16:26 ` James Bottomley 2010-07-01 12:28 ` [dm-devel] " Mikulas Patocka 1 sibling, 1 reply; 28+ messages in thread From: Mike Snitzer @ 2010-06-30 15:36 UTC (permalink / raw) To: James Bottomley Cc: Mikulas Patocka, device-mapper development, axboe, linux-scsi, martin.petersen, linux-kernel, akpm, Christoph Hellwig On Wed, Jun 30 2010 at 10:22am -0400, James Bottomley <James.Bottomley@suse.de> wrote: > On Tue, 2010-06-29 at 20:11 -0400, Mikulas Patocka wrote: > > > > If the layering violation spans only scsi code, it can be eventually > > > > fixed, but this, much worse "layering violation" that will be spanning all > > > > block device midlayers, won't ever be fixed. > > > > > > > > Imagine for example --- a discard request arrivers at a dm-snapshot > > > > device. The driver splits it into chunks, remaps each chunk to the > > > > physical chunk, submits the requests, the elevator merges adjacent > > > > requests and submits fewer bigger requests to the device. Now, if you had > > > > to allocate a zeroed page each time you are splitting the request, that > > > > would exhaust memory and burn cpu needlessly. You delete a 100MB file? --- > > > > fine, allocate a 100MB of zeroed pages. > > > > > > This is a straw man: You've tried to portray a position I've never > > > taken as mine then attack it ... with what is effectively another bogus > > > argument. > > > > > > It's not an either/or choice. > > > > It is either/or choice. If the interface isn't fixed NOW, the existing > > flawed zeroed-page-allocation interface gets into RHEL > > That's a false dichotomy. You might see an either apply this hack now > or support the interface choice with RHEL, but upstream has the option > to fix stuff correctly. RHEL has never needed my blessing to apply > random crap to their kernel before ... why is this patch any different? > > > and I and others will have to support it for 7 years. > > It's called a business model ... I believe it's what they pay you for. > > > > I've asked the relevant parties to > > > combine the approaches and see if a REQ_TYPE_FS path that does the > > > allocations in the appropriate place, likely the ULD, produces a good > > > design. > > > > OK, but before you do this research, fix the interface. > > So even in the RHEL world, I think you'd find that analysing the problem > *before* comping up with a fix is a good way of doing things. > > > > > So I say --- let there be a layering violation in the scsi code, but don't > > > > put this problem with a page allocation to all the other bio midlayer > > > > developers. > > > > > > Thanks for explaining that you have nothing to contribute, I'll make > > > sure you're not on my list of relevant parties. > > > > You misunderstand what I meant. You admit that there are design problems > > in SCSI. > > No I didn't. > > And the rest of this rubbish is based on that false premise. It might > help you to take off your SCSI antipathy and see this as a system > problem: it actually originates in block and spills out from there. > Thus it requires a system solution. As fun as it is for the others monitoring these lists to see redhat.com vs suse.de banter I think framing this discussion like you (and Mikulas) continue to do is a complete distraction. I tried to elevate (and defuse) the discussion yesterday. But simply put: patches speak volumes. I look forward to working with Tomo, hch and anyone else who has something to contribute that moves us toward a real fix for discards. Mike ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 1/2] block: fix leaks associated with discard request payload 2010-06-30 15:36 ` Mike Snitzer @ 2010-06-30 16:26 ` James Bottomley 0 siblings, 0 replies; 28+ messages in thread From: James Bottomley @ 2010-06-30 16:26 UTC (permalink / raw) To: Mike Snitzer Cc: Mikulas Patocka, device-mapper development, axboe, linux-scsi, martin.petersen, linux-kernel, akpm, Christoph Hellwig On Wed, 2010-06-30 at 11:36 -0400, Mike Snitzer wrote: > On Wed, Jun 30 2010 at 10:22am -0400, > James Bottomley <James.Bottomley@suse.de> wrote: > > > On Tue, 2010-06-29 at 20:11 -0400, Mikulas Patocka wrote: > > > > > If the layering violation spans only scsi code, it can be eventually > > > > > fixed, but this, much worse "layering violation" that will be spanning all > > > > > block device midlayers, won't ever be fixed. > > > > > > > > > > Imagine for example --- a discard request arrivers at a dm-snapshot > > > > > device. The driver splits it into chunks, remaps each chunk to the > > > > > physical chunk, submits the requests, the elevator merges adjacent > > > > > requests and submits fewer bigger requests to the device. Now, if you had > > > > > to allocate a zeroed page each time you are splitting the request, that > > > > > would exhaust memory and burn cpu needlessly. You delete a 100MB file? --- > > > > > fine, allocate a 100MB of zeroed pages. > > > > > > > > This is a straw man: You've tried to portray a position I've never > > > > taken as mine then attack it ... with what is effectively another bogus > > > > argument. > > > > > > > > It's not an either/or choice. > > > > > > It is either/or choice. If the interface isn't fixed NOW, the existing > > > flawed zeroed-page-allocation interface gets into RHEL > > > > That's a false dichotomy. You might see an either apply this hack now > > or support the interface choice with RHEL, but upstream has the option > > to fix stuff correctly. RHEL has never needed my blessing to apply > > random crap to their kernel before ... why is this patch any different? > > > > > and I and others will have to support it for 7 years. > > > > It's called a business model ... I believe it's what they pay you for. > > > > > > I've asked the relevant parties to > > > > combine the approaches and see if a REQ_TYPE_FS path that does the > > > > allocations in the appropriate place, likely the ULD, produces a good > > > > design. > > > > > > OK, but before you do this research, fix the interface. > > > > So even in the RHEL world, I think you'd find that analysing the problem > > *before* comping up with a fix is a good way of doing things. > > > > > > > So I say --- let there be a layering violation in the scsi code, but don't > > > > > put this problem with a page allocation to all the other bio midlayer > > > > > developers. > > > > > > > > Thanks for explaining that you have nothing to contribute, I'll make > > > > sure you're not on my list of relevant parties. > > > > > > You misunderstand what I meant. You admit that there are design problems > > > in SCSI. > > > > No I didn't. > > > > And the rest of this rubbish is based on that false premise. It might > > help you to take off your SCSI antipathy and see this as a system > > problem: it actually originates in block and spills out from there. > > Thus it requires a system solution. > > As fun as it is for the others monitoring these lists to see redhat.com > vs suse.de banter I think framing this discussion like you (and Mikulas) > continue to do is a complete distraction. Well, it's not SUSE v Red Hat, it's upstream v Enterprise ... and it's partly my job to explain why upstream does correct fixes not enterprise workarounds (whether the enterprise is RHEL or SLES). But I agree it's becoming a pointless distraction. > I tried to elevate (and defuse) the discussion yesterday. But simply > put: patches speak volumes. I look forward to working with Tomo, hch > and anyone else who has something to contribute that moves us toward a > real fix for discards. Right, so thanks for that. Most of our problem is tied up in the fact that we need to allocate in the prepare path, but we don't have a corresponding clear unprepare path to do the deallocation in. Introducing that into block might sort out this tangle better ... error handling on the backend is very convoluted and we can't really free the page until after it's complete (and the ->done function doesn't mark completion of error handling terms). I think the bones of a solution to this might be that scsi_unprep_request() needs to call into block (instead of setting the flags itself), say blk_unprep_request. Block also needs to call blk_unprep_request based on the REQ_DONTPREP status in its completion path. This would then give us a hook to hang the deallocation correctly on. James ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [dm-devel] [PATCH 1/2] block: fix leaks associated with discard request payload 2010-06-30 14:22 ` James Bottomley 2010-06-30 15:36 ` Mike Snitzer @ 2010-07-01 12:28 ` Mikulas Patocka 2010-07-01 12:46 ` Mike Snitzer 1 sibling, 1 reply; 28+ messages in thread From: Mikulas Patocka @ 2010-07-01 12:28 UTC (permalink / raw) To: James Bottomley Cc: device-mapper development, Mike Snitzer, axboe, linux-scsi, martin.petersen, linux-kernel, akpm, Christoph Hellwig > > It is either/or choice. If the interface isn't fixed NOW, the existing > > flawed zeroed-page-allocation interface gets into RHEL > > That's a false dichotomy. You might see an either apply this hack now > or support the interface choice with RHEL, but upstream has the option > to fix stuff correctly. RHEL has never needed my blessing to apply > random crap to their kernel before ... why is this patch any different? We can't apply non-upstream patches (except few exceptions such as dm-raid45). It makes sense, non-upstream patches have smaller test coverage. > And the rest of this rubbish is based on that false premise. It might > help you to take off your SCSI antipathy and see this as a system > problem: it actually originates in block and spills out from there. > Thus it requires a system solution. > > James Imagine this: I take a FPGA PCI board, I design a storage controller on it and this controller will need 3 pages to process a discard request. Now I say: I refuse to allocate these 3 pages in the driver because the driver would look ugly --- instead, I demand that everyone in the Linux kernel who creates a discard request must attach 3 pages to the request for my driver. Do you think it is correct behavior? Would you accept such a driver? I guess you wouldn't! But this is the same thing that you are doing with SCSI. Now lets take it a bit further and I say "I may clean up the driver for my controller one day, when I do it, I remove that 3-page requirement --- and then, everyone who allocated those pages will have to change his code and remove the allocations". And this is what you are intending to do with SCSI. Mikulas ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 1/2] block: fix leaks associated with discard request payload 2010-07-01 12:28 ` [dm-devel] " Mikulas Patocka @ 2010-07-01 12:46 ` Mike Snitzer 2010-07-01 14:03 ` Mikulas Patocka 0 siblings, 1 reply; 28+ messages in thread From: Mike Snitzer @ 2010-07-01 12:46 UTC (permalink / raw) To: Mikulas Patocka Cc: James Bottomley, device-mapper development, axboe, linux-scsi, martin.petersen, linux-kernel, akpm, Christoph Hellwig On Thu, Jul 01 2010 at 8:28am -0400, Mikulas Patocka <mpatocka@redhat.com> wrote: > > > It is either/or choice. If the interface isn't fixed NOW, the existing > > > flawed zeroed-page-allocation interface gets into RHEL > > > > That's a false dichotomy. You might see an either apply this hack now > > or support the interface choice with RHEL, but upstream has the option > > to fix stuff correctly. RHEL has never needed my blessing to apply > > random crap to their kernel before ... why is this patch any different? > > We can't apply non-upstream patches (except few exceptions such as > dm-raid45). It makes sense, non-upstream patches have smaller test > coverage. > > > And the rest of this rubbish is based on that false premise. It might > > help you to take off your SCSI antipathy and see this as a system > > problem: it actually originates in block and spills out from there. > > Thus it requires a system solution. > > > > James > > Imagine this: I take a FPGA PCI board, I design a storage controller on it > and this controller will need 3 pages to process a discard request. Now I > say: I refuse to allocate these 3 pages in the driver because the driver > would look ugly --- instead, I demand that everyone in the Linux kernel > who creates a discard request must attach 3 pages to the request for my > driver. > > Do you think it is correct behavior? Would you accept such a driver? I > guess you wouldn't! But this is the same thing that you are doing with > SCSI. > > Now lets take it a bit further and I say "I may clean up the driver for my > controller one day, when I do it, I remove that 3-page requirement --- and > then, everyone who allocated those pages will have to change his code and > remove the allocations". > > And this is what you are intending to do with SCSI. Mikulas, Jens has already queued up a comprehensive fix (3 patches) that James and Tomo developed. Please stop the hostility.. it has no place. Others, I'd encourage you to not respond to this thread further ;) Regards, Mike ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 1/2] block: fix leaks associated with discard request payload 2010-07-01 12:46 ` Mike Snitzer @ 2010-07-01 14:03 ` Mikulas Patocka 0 siblings, 0 replies; 28+ messages in thread From: Mikulas Patocka @ 2010-07-01 14:03 UTC (permalink / raw) To: Mike Snitzer Cc: axboe, linux-scsi, martin.petersen, linux-kernel, device-mapper development, James Bottomley, akpm, Christoph Hellwig > Mikulas, > > Jens has already queued up a comprehensive fix (3 patches) that James > and Tomo developed. Please stop the hostility.. it has no place. > > Others, > I'd encourage you to not respond to this thread further ;) > > Regards, > Mike I read mailing lists at longer intervals than my mailbox, so I read the James' message I responded to but missed the patches on the list. It's good that it's fixed and there is no need to argue about it anymore. Mikulas ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 1/2] block: fix leaks associated with discard request payload 2010-06-27 15:29 ` James Bottomley 2010-06-28 17:16 ` Martin K. Petersen 2010-06-29 22:28 ` [dm-devel] " Mikulas Patocka @ 2010-06-30 8:32 ` Boaz Harrosh 2010-06-30 8:42 ` Christoph Hellwig 2 siblings, 1 reply; 28+ messages in thread From: Boaz Harrosh @ 2010-06-30 8:32 UTC (permalink / raw) To: James Bottomley Cc: Mike Snitzer, Christoph Hellwig, axboe, dm-devel, linux-kernel, martin.petersen, akpm, linux-scsi, FUJITA Tomonori On 06/27/2010 06:29 PM, James Bottomley wrote: <snip> >> + /* >> + * If this is a discard request that originated from the kernel >> + * we need to free our payload here. Note that we need to check >> + * the request flag as the normal payload rules apply for >> + * pass-through UNMAP / WRITE SAME requests. >> + */ >> + __free_page(bio_page(cmd->request->bio)); > > This is another layering violation: the page is allocated in the Upper > layer and freed in the mid-layer. > May I ask a silly question? Why the dynamic allocation? Why not have a const-static single global page at the block-layer somewhere that will be used for all discard-type operations and be done with it once and for all. A single page can be used for any size bio , any number of concurrent discards, any ZERO needed operation. It can also be used by other operations like padding and others. In fact isn't there one for the libsata padding? (It could be dynamical allocated on first use for embedded system) just my $0.017 Boaz ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 1/2] block: fix leaks associated with discard request payload 2010-06-30 8:32 ` Boaz Harrosh @ 2010-06-30 8:42 ` Christoph Hellwig 2010-06-30 10:25 ` Boaz Harrosh 0 siblings, 1 reply; 28+ messages in thread From: Christoph Hellwig @ 2010-06-30 8:42 UTC (permalink / raw) To: Boaz Harrosh Cc: James Bottomley, Mike Snitzer, Christoph Hellwig, axboe, dm-devel, linux-kernel, martin.petersen, akpm, linux-scsi, FUJITA Tomonori On Wed, Jun 30, 2010 at 11:32:43AM +0300, Boaz Harrosh wrote: > May I ask a silly question? Why the dynamic allocation? > > Why not have a const-static single global page at the block-layer somewhere > that will be used for all discard-type operations and be done with it once and > for all. A single page can be used for any size bio , any number of concurrent > discards, any ZERO needed operation. It can also be used by other operations > like padding and others. In fact isn't there one for the libsata padding? for UNMAP we need to write into the payload. And for ATA TRIM we need to write into the WRITE SAME payload. That's another layering violation for those looking for them, btw.. ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 1/2] block: fix leaks associated with discard request payload 2010-06-30 8:42 ` Christoph Hellwig @ 2010-06-30 10:25 ` Boaz Harrosh 2010-06-30 10:41 ` Christoph Hellwig 0 siblings, 1 reply; 28+ messages in thread From: Boaz Harrosh @ 2010-06-30 10:25 UTC (permalink / raw) To: Christoph Hellwig Cc: James Bottomley, Mike Snitzer, axboe, dm-devel, linux-kernel, martin.petersen, akpm, linux-scsi, FUJITA Tomonori On 06/30/2010 11:42 AM, Christoph Hellwig wrote: > On Wed, Jun 30, 2010 at 11:32:43AM +0300, Boaz Harrosh wrote: >> May I ask a silly question? Why the dynamic allocation? >> >> Why not have a const-static single global page at the block-layer somewhere >> that will be used for all discard-type operations and be done with it once and >> for all. A single page can be used for any size bio , any number of concurrent >> discards, any ZERO needed operation. It can also be used by other operations >> like padding and others. In fact isn't there one for the libsata padding? > > for UNMAP we need to write into the payload. And for ATA TRIM we need > to write into the WRITE SAME payload. OK, Thanks, I see. Is it one of these operations, (like we have in OSD) where the CDB information spills into the payload? like the scatter-gather and extent lists and such. Do we actually use a WRITE_SAME which is not zero? for what use? > That's another layering violation > for those looking for them, btw.. > Agreed ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 1/2] block: fix leaks associated with discard request payload 2010-06-30 10:25 ` Boaz Harrosh @ 2010-06-30 10:41 ` Christoph Hellwig 2010-06-30 10:57 ` Boaz Harrosh 0 siblings, 1 reply; 28+ messages in thread From: Christoph Hellwig @ 2010-06-30 10:41 UTC (permalink / raw) To: Boaz Harrosh Cc: Christoph Hellwig, James Bottomley, Mike Snitzer, axboe, dm-devel, linux-kernel, martin.petersen, akpm, linux-scsi, FUJITA Tomonori On Wed, Jun 30, 2010 at 01:25:01PM +0300, Boaz Harrosh wrote: > OK, Thanks, I see. Is it one of these operations, (like we have in OSD) where > the CDB information spills into the payload? like the scatter-gather and extent > lists and such. For UNMAP the payload is a list of block number / length pairs, while the CDB itself doesn't contain any information like that. It's a rather awkward command. > Do we actually use a WRITE_SAME which is not zero? for what use? The kernel doesn't issue any WRITE SAME without the unmap bit set. ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 1/2] block: fix leaks associated with discard request payload 2010-06-30 10:41 ` Christoph Hellwig @ 2010-06-30 10:57 ` Boaz Harrosh 2010-06-30 12:18 ` Mike Snitzer 0 siblings, 1 reply; 28+ messages in thread From: Boaz Harrosh @ 2010-06-30 10:57 UTC (permalink / raw) To: Christoph Hellwig Cc: James Bottomley, Mike Snitzer, axboe, dm-devel, linux-kernel, martin.petersen, akpm, linux-scsi, FUJITA Tomonori On 06/30/2010 01:41 PM, Christoph Hellwig wrote: > On Wed, Jun 30, 2010 at 01:25:01PM +0300, Boaz Harrosh wrote: >> OK, Thanks, I see. Is it one of these operations, (like we have in OSD) where >> the CDB information spills into the payload? like the scatter-gather and extent >> lists and such. > > For UNMAP the payload is a list of block number / length pairs, while > the CDB itself doesn't contain any information like that. It's a rather > awkward command. > How big can that be? could we, maybe, use the sense_buffer, properly allocated already? >> Do we actually use a WRITE_SAME which is not zero? for what use? > > The kernel doesn't issue any WRITE SAME without the unmap bit set. So if the unmap bit is set then the page can just be zero, right? I still think a static zero-page is a worth while optimization. And block-drivers can take care with special needs with a private mem_pool or something. For the discard-type user and generic block layer the page is just an implementation specific residue, No? But don't mind me, I'm just babbling. Not that I'll do anything about it. Boaz ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 1/2] block: fix leaks associated with discard request payload 2010-06-30 10:57 ` Boaz Harrosh @ 2010-06-30 12:18 ` Mike Snitzer 0 siblings, 0 replies; 28+ messages in thread From: Mike Snitzer @ 2010-06-30 12:18 UTC (permalink / raw) To: Boaz Harrosh Cc: Christoph Hellwig, James Bottomley, axboe, dm-devel, linux-kernel, martin.petersen, akpm, linux-scsi, FUJITA Tomonori On Wed, Jun 30 2010 at 6:57am -0400, Boaz Harrosh <bharrosh@panasas.com> wrote: > On 06/30/2010 01:41 PM, Christoph Hellwig wrote: > > On Wed, Jun 30, 2010 at 01:25:01PM +0300, Boaz Harrosh wrote: > >> OK, Thanks, I see. Is it one of these operations, (like we have in OSD) where > >> the CDB information spills into the payload? like the scatter-gather and extent > >> lists and such. > > > > For UNMAP the payload is a list of block number / length pairs, while > > the CDB itself doesn't contain any information like that. It's a rather > > awkward command. > > > > How big can that be? could we, maybe, use the sense_buffer, properly allocated > already? > > >> Do we actually use a WRITE_SAME which is not zero? for what use? > > > > The kernel doesn't issue any WRITE SAME without the unmap bit set. > > So if the unmap bit is set then the page can just be zero, right? > > I still think a static zero-page is a worth while optimization. And > block-drivers can take care with special needs with a private mem_pool > or something. For the discard-type user and generic block layer the > page is just an implementation specific residue, No? Why should the block layer have any role in managing this page? Block layer doesn't care about it, SCSI does. Mike ^ permalink raw reply [flat|nested] 28+ messages in thread
end of thread, other threads:[~2010-07-01 14:03 UTC | newest]
Thread overview: 28+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20100627174721D.fujita.tomonori@lab.ntt.co.jp>
[not found] ` <20100627092652.GA11625@lst.de>
[not found] ` <20100627185927K.fujita.tomonori@lab.ntt.co.jp>
2010-06-27 10:35 ` [PATCH 1/2] block: fix leaks associated with discard request payload FUJITA Tomonori
2010-06-27 11:07 ` Christoph Hellwig
2010-06-27 12:32 ` FUJITA Tomonori
2010-06-27 14:16 ` Mike Snitzer
2010-06-27 15:35 ` Christoph Hellwig
2010-06-27 16:23 ` FUJITA Tomonori
2010-06-27 15:33 ` Christoph Hellwig
2010-06-28 7:57 ` Christoph Hellwig
2010-06-28 8:14 ` FUJITA Tomonori
2010-06-28 8:18 ` Jens Axboe
2010-06-28 8:45 ` FUJITA Tomonori
2010-06-28 15:25 ` Christoph Hellwig
2010-06-30 11:55 ` FUJITA Tomonori
2010-07-01 4:21 ` FUJITA Tomonori
[not found] <20100622180029.GA15950@redhat.com>
[not found] ` <1277582211-10725-1-git-send-email-snitzer@redhat.com>
2010-06-27 15:29 ` James Bottomley
2010-06-28 17:16 ` Martin K. Petersen
2010-06-29 8:00 ` Boaz Harrosh
2010-06-29 22:28 ` [dm-devel] " Mikulas Patocka
2010-06-29 23:03 ` James Bottomley
2010-06-29 23:51 ` Mike Snitzer
2010-06-30 0:11 ` [dm-devel] " Mikulas Patocka
2010-06-30 14:22 ` James Bottomley
2010-06-30 15:36 ` Mike Snitzer
2010-06-30 16:26 ` James Bottomley
2010-07-01 12:28 ` [dm-devel] " Mikulas Patocka
2010-07-01 12:46 ` Mike Snitzer
2010-07-01 14:03 ` Mikulas Patocka
2010-06-30 8:32 ` Boaz Harrosh
2010-06-30 8:42 ` Christoph Hellwig
2010-06-30 10:25 ` Boaz Harrosh
2010-06-30 10:41 ` Christoph Hellwig
2010-06-30 10:57 ` Boaz Harrosh
2010-06-30 12:18 ` Mike Snitzer
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox