Date: Fri, 24 May 2013 11:53:20 +0300 From: Konstantin Belousov <kostikbel@gmail.com> To: Lawrence Stewart <lstewart@freebsd.org> Cc: Nigel Williams <njwilliams@swin.edu.au>, freebsd-current@freebsd.org Subject: Re: Read-triggered corruption of swap backed MD devices Message-ID: <20130524085320.GB3047@kib.kiev.ua> In-Reply-To: <519ECE40.5020901@freebsd.org> References: <519ECE40.5020901@freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
--gK+LRxvpqA0rHHYe Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, May 24, 2013 at 12:19:44PM +1000, Lawrence Stewart wrote: > Hi all, >=20 > I tracked the cause of a colleague's nanobsd image creation problem to > what appears to be some nasty behaviour with swap-backed MD devices. > I've verified the behaviour exists on three separate systems running > 10-CURRENT r250260, 9-STABLE r250824 and 9-STABLE r250925. >=20 > The following minimal reproduction recipe (run as root) > deterministically triggers the behaviour for me on the 3 systems I've > tested: >=20 > env MD_DEV=3D`mdconfig -an -t swap -s 1m -x 63 -y 16` sh -c '(fdisk -I > md${MD_DEV} ; bsdlabel -w -B md${MD_DEV}s1 ; bsdlabel md${MD_DEV}s1 ; dd > if=3D/dev/md${MD_DEV} of=3D/dev/null bs=3D64k ; bsdlabel md${MD_DEV}s1 ; > mdconfig -d -u ${MD_DEV})' >=20 > By changing the mdconfig "-t swap" argument to "-t malloc", the bsdlabel > remains intact after the dd command completes. >=20 > I've included command line recipe runs from my 10-CURRENT r250260 laptop > with both "-t swap" and "-t malloc" at the end of this email for referenc= e. >=20 > Smells like a VM related problem to me, but ENOCLUE so I would > appreciate some help. Confirmed, and the following patch fixed the issue for me. diff --git a/sys/dev/md/md.c b/sys/dev/md/md.c index e871d8f..57c5b57 100644 --- a/sys/dev/md/md.c +++ b/sys/dev/md/md.c @@ -829,7 +829,9 @@ mdstart_swap(struct md_s *sc, struct bio *bp) m =3D vm_page_grab(sc->object, i, VM_ALLOC_NORMAL | VM_ALLOC_RETRY); if (bp->bio_cmd =3D=3D BIO_READ) { - if (m->valid !=3D VM_PAGE_BITS_ALL) + if (m->valid =3D=3D VM_PAGE_BITS_ALL) + rv =3D VM_PAGER_OK; + else rv =3D vm_pager_get_pages(sc->object, &m, 1, 0); if (rv =3D=3D VM_PAGER_ERROR) { vm_page_wakeup(m); @@ -854,6 +856,8 @@ mdstart_swap(struct md_s *sc, struct bio *bp) } else if (bp->bio_cmd =3D=3D BIO_WRITE) { if (len !=3D PAGE_SIZE && m->valid !=3D VM_PAGE_BITS_ALL) rv =3D vm_pager_get_pages(sc->object, &m, 1, 0); + else + rv =3D VM_PAGER_OK; if (rv =3D=3D VM_PAGER_ERROR) { vm_page_wakeup(m); break; @@ -868,6 +872,8 @@ mdstart_swap(struct md_s *sc, struct bio *bp) } else if (bp->bio_cmd =3D=3D BIO_DELETE) { if (len !=3D PAGE_SIZE && m->valid !=3D VM_PAGE_BITS_ALL) rv =3D vm_pager_get_pages(sc->object, &m, 1, 0); + else + rv =3D VM_PAGER_OK; if (rv =3D=3D VM_PAGER_ERROR) { vm_page_wakeup(m); break; --gK+LRxvpqA0rHHYe Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.20 (FreeBSD) iQIcBAEBAgAGBQJRnyqAAAoJEJDCuSvBvK1BtywP/izoF5Qcqhug8rzIn+DvuXgz 3Z6P9Nk5c9jldSjU05qpGxgLZR5vsvrlPGoUopWLFQdHMuErHaVJot40HgvAf5B+ dCxJWH46LYwtnvMbABscLkkaHYhNUoQQDLLMAZIgw6SjL7R/2NoHqlBy2fbtEOD5 xsielpftWMQKcpW94ClQNjY9cSdEWKGUFXhDNyNpWSM+FqxiF4Ax2p9X8KXlFDAa Izr6Edc2nHCn5Z/yx4CovcQaPiQGYXkaLCesKhBs+MS/ztIS4fIp0ljgMUUE8Bsd ua6UwGHXeaYypgtw+29fgyVH9qHc/uQEa/TVxaaq5A+6wc1XMd6v6QTAVYxVIcZf QnOwL/okppm/21V7N/43KyLdiPzRru9elmJQBaLSlUZCiBO2TVmylZQtteNaqUgN ozSehdN25p1XTzWZkHe62orpxcZzH8+oqqexyVfeC6VrFH3vrJVNJwSs+Sr+InSe msRzfWlh9jz3PDeJhFP33MMYxVWIZFGcLkC8X3oKDdD18VYkIJj+8U7AUsdR1lkl nfIZgtH9O7zVqevRKPJhKolLnVUiwE5pCsuWU0D/JuII7kturU41ok2eOtrndj0B Y3Y5i/YngZ7e+zrIK5qYtmLkfBhqTM1Iawjk7judUykfbef2BA/G4PUYlNazjI9l KvnMq0alqJ95eNjsGigw =EGN0 -----END PGP SIGNATURE----- --gK+LRxvpqA0rHHYe--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20130524085320.GB3047>