Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 20 Jun 2017 17:03:06 +0000 (UTC)
From:      Mark Johnston <markj@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject:   svn commit: r320154 - stable/10/sys/dev/md
Message-ID:  <201706201703.v5KH36Z1038866@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: markj
Date: Tue Jun 20 17:03:06 2017
New Revision: 320154
URL: https://svnweb.freebsd.org/changeset/base/320154

Log:
  MFC r319932:
  Fix handling of subpage BIO_WRITE and BIO_DELETE requests on swap MDs.

Modified:
  stable/10/sys/dev/md/md.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/dev/md/md.c
==============================================================================
--- stable/10/sys/dev/md/md.c	Tue Jun 20 16:55:30 2017	(r320153)
+++ stable/10/sys/dev/md/md.c	Tue Jun 20 17:03:06 2017	(r320154)
@@ -963,6 +963,16 @@ unmapped_step:
 	return (error);
 }
 
+static void
+md_swap_page_free(vm_page_t m)
+{
+
+	vm_page_xunbusy(m);
+	vm_page_lock(m);
+	vm_page_free(m);
+	vm_page_unlock(m);
+}
+
 static int
 mdstart_swap(struct md_s *sc, struct bio *bp)
 {
@@ -1034,14 +1044,16 @@ mdstart_swap(struct md_s *sc, struct bio *bp)
 				cpu_flush_dcache(p, len);
 			}
 		} 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
+			if (len == PAGE_SIZE || 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_xunbusy(m);
 				break;
-			}
+			} else if (rv == VM_PAGER_FAIL)
+				pmap_zero_page(m);
+
 			if ((bp->bio_flags & BIO_UNMAPPED) != 0) {
 				pmap_copy_pages(bp->bio_ma, ma_offs, &m,
 				    offs, len);
@@ -1051,33 +1063,39 @@ mdstart_swap(struct md_s *sc, struct bio *bp)
 			} else {
 				physcopyin(p, VM_PAGE_TO_PHYS(m) + offs, len);
 			}
+
 			m->valid = VM_PAGE_BITS_ALL;
+			vm_page_dirty(m);
+			vm_pager_page_unswapped(m);
 		} 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
+			if (len == PAGE_SIZE || 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_xunbusy(m);
 				break;
-			}
-			if (len != PAGE_SIZE) {
-				pmap_zero_page_area(m, offs, len);
-				vm_page_clear_dirty(m, offs, len);
-				m->valid = VM_PAGE_BITS_ALL;
-			} else
+			} else if (rv == VM_PAGER_FAIL) {
+				md_swap_page_free(m);
+				m = NULL;
+			} else {
+				/* Page is valid. */
+				if (len != PAGE_SIZE) {
+					pmap_zero_page_area(m, offs, len);
+					vm_page_dirty(m);
+				}
 				vm_pager_page_unswapped(m);
+				if (len == PAGE_SIZE) {
+					md_swap_page_free(m);
+					m = NULL;
+				}
+			}
 		}
-		vm_page_xunbusy(m);
-		vm_page_lock(m);
-		if (bp->bio_cmd == BIO_DELETE && len == PAGE_SIZE)
-			vm_page_free(m);
-		else
+		if (m != NULL) {
+			vm_page_xunbusy(m);
+			vm_page_lock(m);
 			vm_page_activate(m);
-		vm_page_unlock(m);
-		if (bp->bio_cmd == BIO_WRITE) {
-			vm_page_dirty(m);
-			vm_pager_page_unswapped(m);
+			vm_page_unlock(m);
 		}
 
 		/* Actions on further pages start at offset 0 */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201706201703.v5KH36Z1038866>