Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp4466906img; Tue, 26 Mar 2019 09:56:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqyW7rZsZtLZuhfgNDvMj/30Clr+gzZVetaGh6D7Gmy/GR1jNFGtbEG4e5ahd4XYnkyg+Vvd X-Received: by 2002:a17:902:e002:: with SMTP id ca2mr19342249plb.131.1553619412995; Tue, 26 Mar 2019 09:56:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553619412; cv=none; d=google.com; s=arc-20160816; b=Vn+hiFHjpQH0f92T92+QGpYKd9wdVsCyeXjUVKjd5K+6sHEo3gwyooByWUP8ja1oWc DFEyzuMEoq2VJwTbm2E1e9zKlA2i/Z6Vrz87IUGev4HqDYwXTLJhZGkNUiJbs7W95UUP FzRYzu6Xk0mKTk3Mtr9E07JOXa+21sLkr8fv0y42IQA155GfkU4EURKDMcUPutfI28ny J2dI7HLmnolXAFJGNjfcDBcO/rFCJe+ontJfRcg3NSD9Bjjg/gIZs8sqC+J0wXjUoZ6r 7BKaEc60yEs8BXnQb1HEL1d4rFVoRfkoS1iYtBCddNb/X/Epm3k/YZlDt+xTlZq85j6j bHXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:organization:from:references:cc:to:subject; bh=oEX6dMKGVIXPkQRbV3Ym9LamMhWZ4S1/fFcZKRdic2U=; b=at3lyhg1VKUMYkqGi/o27ThfH3Mv3rFc0/kOL6QLz2YwiifxxNOCno5ESMSqLHKywC S1d0foH/9TlySD2gLh8ZG7uOJy5Ai2clV1GcwmS0gSZX1HM9ZhtfIq+z7IN4FHptpzq5 kzKcBRmtujmq0Ud6xH8oGcUnbQgADIOJjtSuha+CP0vo7/JLIyC+2G94EHaw7TIn6JEK dittRg3rj+V23y2z4xiFX9NVVmNDjG9JpcoDodP+bT/YWLXO3O4KRWjF8f+dB6QMDJQK O71dnXFRgGnXHaxp6+MKDRK0u9GaPMYOWi/j7uofW888KUhQqEMxHaBx2QIy4vhweOHg nMNQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f3si16630389pfc.158.2019.03.26.09.56.37; Tue, 26 Mar 2019 09:56:52 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731573AbfCZQzU (ORCPT + 99 others); Tue, 26 Mar 2019 12:55:20 -0400 Received: from mail02.iobjects.de ([188.40.134.68]:35334 "EHLO mail02.iobjects.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726207AbfCZQzU (ORCPT ); Tue, 26 Mar 2019 12:55:20 -0400 Received: from tux.wizards.de (pD9EBF050.dip0.t-ipconnect.de [217.235.240.80]) by mail02.iobjects.de (Postfix) with ESMTPSA id C41A241696A3; Tue, 26 Mar 2019 17:55:17 +0100 (CET) Received: from [192.168.100.223] (ragnarok.applied-asynchrony.com [192.168.100.223]) by tux.wizards.de (Postfix) with ESMTP id 4873EF01601; Tue, 26 Mar 2019 17:55:17 +0100 (CET) Subject: Re: [PATCH] loop: properly observe rotational flag of underlying device To: LKML , linux-block@vger.kernel.org Cc: Gwendal Grignou , Guenter Roeck , Benjamin Gordon References: <20190212225424.139232-1-bmgordon@chromium.org> From: =?UTF-8?Q?Holger_Hoffst=c3=a4tte?= Organization: Applied Asynchrony, Inc. Message-ID: <52a9cb46-5863-834c-3378-5b0ec87814e6@applied-asynchrony.com> Date: Tue, 26 Mar 2019 17:55:17 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: <20190212225424.139232-1-bmgordon@chromium.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Ping! Jens, can we please let this finally land in 5.2? thanks, Holger On 2/12/19 11:54 PM, Benjamin Gordon wrote: > From: Holger Hoffstätte > > The loop driver always declares the rotational flag of its device as > rotational, even when the device of the mapped file is nonrotational, > as is the case with SSDs or on tmpfs. This can confuse filesystem tools > which are SSD-aware; in my case I frequently forget to tell mkfs.btrfs > that my loop device on tmpfs is nonrotational, and that I really don't > need any automatic metadata redundancy. > > The attached patch fixes this by introspecting the rotational flag of the > mapped file's underlying block device, if it exists. If the mapped file's > filesystem has no associated block device - as is the case on e.g. tmpfs - > we assume nonrotational storage. If there is a better way to identify such > non-devices I'd love to hear them. > > Cc: Jens Axboe > Cc: linux-block@vger.kernel.org > Cc: holger@applied-asynchrony.com > Signed-off-by: Holger Hoffstätte > Signed-off-by: Gwendal Grignou > Signed-off-by: Benjamin Gordon > Reviewed-by: Guenter Roeck > --- > This is a resend of Holger's original patch from > https://lkml.org/lkml/2015/11/11/288 with the _unlocked functions > updated. We keep running into the same problem on Chrome OS that this > originally solved; any chance it can go in? > > drivers/block/loop.c | 19 +++++++++++++++++++ > 1 file changed, 19 insertions(+) > > diff --git a/drivers/block/loop.c b/drivers/block/loop.c > index cf5538942834..6c0fc0d49dc0 100644 > --- a/drivers/block/loop.c > +++ b/drivers/block/loop.c > @@ -900,6 +900,24 @@ static int loop_prepare_queue(struct loop_device *lo) > return 0; > } > > +static void loop_update_rotational(struct loop_device *lo) > +{ > + struct file *file = lo->lo_backing_file; > + struct inode *file_inode = file->f_mapping->host; > + struct block_device *file_bdev = file_inode->i_sb->s_bdev; > + struct request_queue *q = lo->lo_queue; > + bool nonrot = true; > + > + /* not all filesystems (e.g. tmpfs) have a sb->s_bdev */ > + if (file_bdev) > + nonrot = blk_queue_nonrot(bdev_get_queue(file_bdev)); > + > + if (nonrot) > + blk_queue_flag_set(QUEUE_FLAG_NONROT, q); > + else > + blk_queue_flag_clear(QUEUE_FLAG_NONROT, q); > +} > + > static int loop_set_fd(struct loop_device *lo, fmode_t mode, > struct block_device *bdev, unsigned int arg) > { > @@ -963,6 +981,7 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode, > if (!(lo_flags & LO_FLAGS_READ_ONLY) && file->f_op->fsync) > blk_queue_write_cache(lo->lo_queue, true, false); > > + loop_update_rotational(lo); > loop_update_dio(lo); > set_capacity(lo->lo_disk, size); > bd_set_size(bdev, size << 9); >