From owner-freebsd-current@FreeBSD.ORG Fri May 24 15:40:46 2013 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 3F89C6D1; Fri, 24 May 2013 15:40:46 +0000 (UTC) (envelope-from asomers@gmail.com) Received: from mail-qa0-x231.google.com (mail-qa0-x231.google.com [IPv6:2607:f8b0:400d:c00::231]) by mx1.freebsd.org (Postfix) with ESMTP id 851F59C1; Fri, 24 May 2013 15:40:45 +0000 (UTC) Received: by mail-qa0-f49.google.com with SMTP id j11so2319256qag.8 for ; Fri, 24 May 2013 08:40:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=qz6GjQ0iYWRKLglhteQS1aczSMv0Ghu3jX2bygkep8A=; b=yDw+Lm/Z4InMLPxF9CnwGALa7X7VEBsBeEeW/g0+nTeCvral0HPwgeQJMqgcruXBeT 1zZw1lAe6KK2JpahjThUxTqKOmLxWR8IgWImV7vS/u+0U/BF3ZKdSBoifeONIX/D3HLB nUpg5LSc/vILKGuK2HohO62u6JOstIx2I7RC6RtoB1wahHt7AxPUYZkA+60H+l1G0ixE NR3gOmT5sywbiCWDmiJ5zvQfl1BJaffogTxYiOc6ZWGb5bnoxoJ3aIwo3hK3/mbadWP0 6AWv+W6wqRK4VIVfnwyvqkNyRWxKJUvZDuUfUgiga8Z67zwrEBVckVZM6uLVt5x3JdnE 1zDA== MIME-Version: 1.0 X-Received: by 10.224.57.82 with SMTP id b18mr17001237qah.36.1369410045070; Fri, 24 May 2013 08:40:45 -0700 (PDT) Received: by 10.49.133.137 with HTTP; Fri, 24 May 2013 08:40:44 -0700 (PDT) In-Reply-To: <20130524085320.GB3047@kib.kiev.ua> References: <519ECE40.5020901@freebsd.org> <20130524085320.GB3047@kib.kiev.ua> Date: Fri, 24 May 2013 09:40:44 -0600 Message-ID: Subject: Re: Read-triggered corruption of swap backed MD devices From: asomers@gmail.com To: Konstantin Belousov Content-Type: text/plain; charset=ISO-8859-1 X-Mailman-Approved-At: Fri, 24 May 2013 16:36:18 +0000 Cc: Lawrence Stewart , Nigel Williams , freebsd-current@freebsd.org X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 24 May 2013 15:40:46 -0000 Fast work, Konstantin! This looks like it may be the solution to an intermittent and inexplicable bug we've been seeing that we feared may be data corruption in ZFS. On Fri, May 24, 2013 at 2:53 AM, Konstantin Belousov wrote: > On Fri, May 24, 2013 at 12:19:44PM +1000, Lawrence Stewart wrote: >> Hi all, >> >> 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. >> >> The following minimal reproduction recipe (run as root) >> deterministically triggers the behaviour for me on the 3 systems I've >> tested: >> >> env MD_DEV=`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=/dev/md${MD_DEV} of=/dev/null bs=64k ; bsdlabel md${MD_DEV}s1 ; >> mdconfig -d -u ${MD_DEV})' >> >> By changing the mdconfig "-t swap" argument to "-t malloc", the bsdlabel >> remains intact after the dd command completes. >> >> 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 reference. >> >> 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 = vm_page_grab(sc->object, i, VM_ALLOC_NORMAL | > VM_ALLOC_RETRY); > if (bp->bio_cmd == BIO_READ) { > - if (m->valid != VM_PAGE_BITS_ALL) > + if (m->valid == VM_PAGE_BITS_ALL) > + rv = VM_PAGER_OK; > + else > rv = vm_pager_get_pages(sc->object, &m, 1, 0); > if (rv == 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 == BIO_WRITE) { > if (len != PAGE_SIZE && m->valid != VM_PAGE_BITS_ALL) > rv = vm_pager_get_pages(sc->object, &m, 1, 0); > + else > + rv = VM_PAGER_OK; > if (rv == 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 == BIO_DELETE) { > if (len != PAGE_SIZE && m->valid != VM_PAGE_BITS_ALL) > rv = vm_pager_get_pages(sc->object, &m, 1, 0); > + else > + rv = VM_PAGER_OK; > if (rv == VM_PAGER_ERROR) { > vm_page_wakeup(m); > break;