linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ingo Franzki <ifranzki@linux.ibm.com>
To: Jens Axboe <axboe@kernel.dk>,
	linux-block@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Juergen Christ <jchrist@linux.ibm.com>
Subject: loop_set_block_size: loop0 () has still dirty pages (nrpages=2)
Date: Tue, 8 Jun 2021 14:01:29 +0200	[thread overview]
Message-ID: <8bed44f2-273c-856e-0018-69f127ea4258@linux.ibm.com> (raw)

Hi all,

we occasionally encounter a problem when setting up a loop device in one of our automated testcases.

We set up a loop device as follows:

    # dd if=/dev/zero of=/var/tmp/loopbackfile1.img bs=1M count=2500 status=none
    # losetup --sector-size 4096 -fP --show /var/tmp/loopbackfile1.img

This works fine most of the times, but in the seldom case of the error, we get 'losetup: /var/tmp/loopbackfile1.img: failed to set up loop device: Resource temporarily unavailable'.

I am sure that no other loop device is currently defined, so we don't run out of loop devices.

We also see the following message in the syslog when the error occurs:

     loop_set_block_size: loop0 () has still dirty pages (nrpages=2)

The nrpages number varies from time to time. 

"Resource temporarily unavailable" is EAGAIN, and function loop_set_block_size() in drivers/block/loop.c returns this after printing the syslog message via pr_warn:

static int loop_set_block_size(struct loop_device *lo, unsigned long arg)
{
	int err = 0;

	if (lo->lo_state != Lo_bound)
		return -ENXIO;

	err = loop_validate_block_size(arg);
	if (err)
		return err;

	if (lo->lo_queue->limits.logical_block_size == arg)
		return 0;

	sync_blockdev(lo->lo_device);
	invalidate_bdev(lo->lo_device);

	blk_mq_freeze_queue(lo->lo_queue);

	/* invalidate_bdev should have truncated all the pages */
	if (lo->lo_device->bd_inode->i_mapping->nrpages) {
		err = -EAGAIN;
		pr_warn("%s: loop%d (%s) has still dirty pages (nrpages=%lu)\n",
			__func__, lo->lo_number, lo->lo_file_name,
			lo->lo_device->bd_inode->i_mapping->nrpages);
		goto out_unfreeze;
	}

	blk_queue_logical_block_size(lo->lo_queue, arg);
	blk_queue_physical_block_size(lo->lo_queue, arg);
	blk_queue_io_min(lo->lo_queue, arg);
	loop_update_dio(lo);
out_unfreeze:
	blk_mq_unfreeze_queue(lo->lo_queue);

	return err;
}

So looks like invalidate_bdev() did actually not truncate all the pages under some circumstances....

The problem only happens when '--sector-size 4096' is specified, with the default sector size is always works. It does not call loop_set_block_size() in the default case I guess.

The loop0 device has certainly be used by other testcases before, most likely with the default block size. But at the time of this run, no loop device is currently active (losetup shows nothing). 

Anyone have an idea what goes wrong here? 

This happens on upstream kernels on the s390x platform, but I can't tell if is related to the platform or a specific kernel version. 
The failing use case is not that old, so I can't tell if it would have happened on earlier kernels or not, or since when it happens. 

Any help is appreciated!

-- 
Ingo Franzki
ifranzki@linux.ibm.com  
Linux on IBM Z Development, Schoenaicher Str. 220, 71032 Boeblingen, Germany

IBM Deutschland Research & Development GmbH / Vorsitzender des Aufsichtsrats: Matthias Hartmann
Geschäftsführung: Dirk Wittkopp
Sitz der Gesellschaft: Böblingen / Registergericht: Amtsgericht Stuttgart, HRB 243294
IBM DATA Privacy Statement: https://www.ibm.com/privacy/us/en/

             reply	other threads:[~2021-06-08 12:01 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-08 12:01 Ingo Franzki [this message]
2021-06-10 14:45 ` Ming Lei
2021-06-14  7:35   ` Ingo Franzki
2021-06-14 22:37     ` Ming Lei
2021-06-15  8:06       ` Jan Kara
2021-06-15  8:42     ` Karel Zak
2021-06-16  7:22       ` Ingo Franzki
2021-06-16  7:44         ` Karel Zak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8bed44f2-273c-856e-0018-69f127ea4258@linux.ibm.com \
    --to=ifranzki@linux.ibm.com \
    --cc=axboe@kernel.dk \
    --cc=jchrist@linux.ibm.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --subject='Re: loop_set_block_size: loop0 () has still dirty pages (nrpages=2)' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).