Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp2271868ybc; Wed, 20 Nov 2019 11:28:23 -0800 (PST) X-Google-Smtp-Source: APXvYqxj1FGYbUGMTHl+V+CYBF2rbBoXH5I+r1hgHD47VqKMzwXUy02k8T34eRuPuw7AQnA+79SC X-Received: by 2002:a7b:ca51:: with SMTP id m17mr5091136wml.110.1574278103809; Wed, 20 Nov 2019 11:28:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574278103; cv=none; d=google.com; s=arc-20160816; b=w3H7iOG1vyrbtFPV98DfLb2rleebQ+kNvTsZDPOG6TlcpplJbnBmvTVgF5Z7gz5KJY gQOyV4a7B9euv9oRALykcRT0U+c4KbHPUlFCc4HxJ+TgSxfV8tLmngSX3XqQVR597uR1 xStAuVxpZoJsjaGjMw9mwx4bQAc1O2Y9f2xaJogXh1zpzQtab0IOawx8T1lYo+GBLBLX HKVtzpsjP9FWxF1E11m9PoUp5MC6cdWggtBjH+7tunaPfURgsivLD2M1KDeM9POS1rla NizRBSOj7mlaAymq2rDk52vfxp2Y44dgojLgbf3Knm4ExMn1E7Znz9NZxAB3cSAlihFR Gjkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=Mw+/fineosuPJvDOnBDBPMogHWUzz9jTmRi29Rw+s8o=; b=IOyrlrMdKHeyi/JGhj4Q52akAutQ0WIr1FwtMrp1QbvnvW1gCYcwWvoffx1YA0CAkc Yq+lGeDJTxH+XFobYhEqd2hYsyTl9yKtpAD6i06ck9hB+RkY9WUcL5F89/ZJEx0wJid5 GaScxsuA8ZCo7zCkNhuoeyVMNKT5ZFT35hOI40NUlsVzj4M8+ERd/RhhPyKs/DkR6WD4 sq/odnwuN1Rk8mkPCaCAGRUbhu1uGYFuA8Y3ssOd9T2HX1Vh+B1ADcBEUuto3HdlWHuH qbc7q+u5MOBz/8/LiBgyVit8Hnw6T+L+613W5g7sq04QpVSVEYTNWLYQnFkbhvLCvHZT knlg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=mPCKWx7D; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t27si281864edd.304.2019.11.20.11.28.00; Wed, 20 Nov 2019 11:28:23 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=mPCKWx7D; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727637AbfKTT02 (ORCPT + 99 others); Wed, 20 Nov 2019 14:26:28 -0500 Received: from mail-lj1-f194.google.com ([209.85.208.194]:39125 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727474AbfKTT02 (ORCPT ); Wed, 20 Nov 2019 14:26:28 -0500 Received: by mail-lj1-f194.google.com with SMTP id p18so411232ljc.6 for ; Wed, 20 Nov 2019 11:26:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Mw+/fineosuPJvDOnBDBPMogHWUzz9jTmRi29Rw+s8o=; b=mPCKWx7DB8WKiRCILkF/Vp93HtGJYEdHFGc3esVg4bfwz+9ufxMwG7XDtyzMmczsj9 onbNWqBPFjCQ12S7lrtRI6fL0ibOD1rJ31/migziZy+08Jx8f3F53jnVZocTReJC6bD8 2KZOIOhJBwNhU/+M1IuCWG2kr6yfT4oi5iN10= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Mw+/fineosuPJvDOnBDBPMogHWUzz9jTmRi29Rw+s8o=; b=mEcc72zTDm8IJ0ENky0VafaCtx8L1JB2ZHDO93uxXc/oMrtsGTBuZ6RiX0IxtjhOJD +qmCcZSQJp0Ou4SKWSwwzh4lON+fHnu3x6nE5tfnnkUXdGJqUxlDSJWuBwXcpljIB06c 8umrvDVogOtzOPYOF8KXaLWeXSlN6ncNyD1uEDMI3T+HR6LEMWsOP9E7cvO0d4hOlCLB NVgROmSLpT7+JOPgFRLP+mbiJ3ZT3qs5ruhjeQBusJTa90aqi2joiHGJ1C2eeMZse/JH YEanvgD31sIDd0ULOUHGKMSSIJr+bYS4whVWE2zbgvZnlOUGfwLAGh9OVYUIKLzNVBcj af8w== X-Gm-Message-State: APjAAAW6uHW2F4We8Gab1uyycNmUszKD309h1yVRezhjbqSNoNLyivYH 2cM6RT/ifJwN2zb/KOxAKNA9R7Lkb7w= X-Received: by 2002:a2e:8613:: with SMTP id a19mr4192719lji.138.1574277986077; Wed, 20 Nov 2019 11:26:26 -0800 (PST) Received: from mail-lj1-f169.google.com (mail-lj1-f169.google.com. [209.85.208.169]) by smtp.gmail.com with ESMTPSA id x1sm16260543lff.90.2019.11.20.11.26.25 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 20 Nov 2019 11:26:25 -0800 (PST) Received: by mail-lj1-f169.google.com with SMTP id p18so411159ljc.6 for ; Wed, 20 Nov 2019 11:26:25 -0800 (PST) X-Received: by 2002:a2e:9208:: with SMTP id k8mr4368991ljg.14.1574277984775; Wed, 20 Nov 2019 11:26:24 -0800 (PST) MIME-Version: 1.0 References: <20191114235008.185111-1-evgreen@chromium.org> <20191114154903.v7.2.I4d476bddbf41a61422ad51502f4361e237d60ad4@changeid> <20191120022518.GU6235@magnolia> <20191120191302.GV6235@magnolia> In-Reply-To: <20191120191302.GV6235@magnolia> From: Evan Green Date: Wed, 20 Nov 2019 11:25:48 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v7 2/2] loop: Better discard support for block devices To: "Darrick J. Wong" Cc: Jens Axboe , Martin K Petersen , Gwendal Grignou , Christoph Hellwig , Ming Lei , Alexis Savery , Douglas Anderson , Bart Van Assche , Chaitanya Kulkarni , linux-block , LKML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Nov 20, 2019 at 11:13 AM Darrick J. Wong wrote: > > On Wed, Nov 20, 2019 at 10:56:30AM -0800, Evan Green wrote: > > On Tue, Nov 19, 2019 at 6:25 PM Darrick J. Wong wrote: > > > > > > On Thu, Nov 14, 2019 at 03:50:08PM -0800, Evan Green wrote: > > > > If the backing device for a loop device is itself a block device, > > > > then mirror the "write zeroes" capabilities of the underlying > > > > block device into the loop device. Copy this capability into both > > > > max_write_zeroes_sectors and max_discard_sectors of the loop device. > > > > > > > > The reason for this is that REQ_OP_DISCARD on a loop device translates > > > > into blkdev_issue_zeroout(), rather than blkdev_issue_discard(). This > > > > presents a consistent interface for loop devices (that discarded data > > > > is zeroed), regardless of the backing device type of the loop device. > > > > There should be no behavior change for loop devices backed by regular > > > > files. (marking this spot for below) > > > > > > > > This change fixes blktest block/003, and removes an extraneous > > > > error print in block/013 when testing on a loop device backed > > > > by a block device that does not support discard. > > > > > > > > Signed-off-by: Evan Green > > > > Reviewed-by: Gwendal Grignou > > > > Reviewed-by: Chaitanya Kulkarni > > > > --- > > > > > > > > Changes in v7: > > > > - Rebase on top of Darrick's patch > > > > - Tweak opening line of commit description (Darrick) > > > > > > > > Changes in v6: None > > > > Changes in v5: > > > > - Don't mirror discard if lo_encrypt_key_size is non-zero (Gwendal) > > > > > > > > Changes in v4: > > > > - Mirror blkdev's write_zeroes into loopdev's discard_sectors. > > > > > > > > Changes in v3: > > > > - Updated commit description > > > > > > > > Changes in v2: None > > > > > > > > drivers/block/loop.c | 40 +++++++++++++++++++++++++++++----------- > > > > 1 file changed, 29 insertions(+), 11 deletions(-) > > > > > > > > diff --git a/drivers/block/loop.c b/drivers/block/loop.c > > > > index 6a9fe1f9fe84..e8f23e4b78f7 100644 > > > > --- a/drivers/block/loop.c > > > > +++ b/drivers/block/loop.c > > > > @@ -427,11 +427,12 @@ static int lo_fallocate(struct loop_device *lo, struct request *rq, loff_t pos, > > > > * information. > > > > */ > > > > struct file *file = lo->lo_backing_file; > > > > + struct request_queue *q = lo->lo_queue; > > > > int ret; > > > > > > > > mode |= FALLOC_FL_KEEP_SIZE; > > > > > > > > - if ((!file->f_op->fallocate) || lo->lo_encrypt_key_size) { > > > > + if (!blk_queue_discard(q)) { > > > > ret = -EOPNOTSUPP; > > > > goto out; > > > > } > > > > @@ -862,6 +863,21 @@ static void loop_config_discard(struct loop_device *lo) > > > > struct file *file = lo->lo_backing_file; > > > > struct inode *inode = file->f_mapping->host; > > > > struct request_queue *q = lo->lo_queue; > > > > + struct request_queue *backingq; > > > > + > > > > + /* > > > > + * If the backing device is a block device, mirror its zeroing > > > > + * capability. REQ_OP_DISCARD translates to a zero-out even when backed > > > > + * by block devices to keep consistent behavior with file-backed loop > > > > + * devices. > > > > + */ > > > > + if (S_ISBLK(inode->i_mode) && !lo->lo_encrypt_key_size) { > > > > + backingq = bdev_get_queue(inode->i_bdev); > > > > + blk_queue_max_discard_sectors(q, > > > > + backingq->limits.max_write_zeroes_sectors); > > > > > > max_discard_sectors? > > > > I didn't plumb max_discard_sectors because for my scenario it never > > ends up hitting the block device that way. > > > > The loop device either uses FL_ZERO_RANGE or FL_PUNCH_HOLE. When > > backed by a block device, that ends up in blkdev_fallocate(), which > > always translates both of those into blkdev_issue_zeroout(), not > > blkdev_issue_discard(). So it's really the zeroing capabilities of the > > block device that matters, even for loop discard operations. It seems > > weird, but I think this is the right thing because it presents a > > consistent interface to loop device users whether backed by a file > > system file, or directly by a block device. That is, a previously > > discarded range will read back as zeroes. > > Ah, right. Could you add this paragraph as a comment explaining why > we're setting max_discard_sectors from max_write_zeroes_sectors? Sure. I put an explanation in the commit description (see spot I marked above), but I agree a comment is probably also worthwhile. > > --D > > > -Evan