From owner-svn-src-all@freebsd.org Wed Sep 14 10:51:07 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 87380BD9A26; Wed, 14 Sep 2016 10:51:07 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 3081E10EA; Wed, 14 Sep 2016 10:51:07 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u8EAp6qb072649; Wed, 14 Sep 2016 10:51:06 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u8EAp6oW072648; Wed, 14 Sep 2016 10:51:06 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201609141051.u8EAp6oW072648@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Wed, 14 Sep 2016 10:51:06 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r305803 - stable/10/sys/vm X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 14 Sep 2016 10:51:07 -0000 Author: kib Date: Wed Sep 14 10:51:06 2016 New Revision: 305803 URL: https://svnweb.freebsd.org/changeset/base/305803 Log: MFC r305129: Make swapoff reliable. Modified: stable/10/sys/vm/swap_pager.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/vm/swap_pager.c ============================================================================== --- stable/10/sys/vm/swap_pager.c Wed Sep 14 10:36:44 2016 (r305802) +++ stable/10/sys/vm/swap_pager.c Wed Sep 14 10:51:06 2016 (r305803) @@ -1764,36 +1764,49 @@ static void swap_pager_swapoff(struct swdevt *sp) { struct swblock *swap; + vm_object_t locked_obj, object; + vm_pindex_t pindex; int i, j, retries; GIANT_REQUIRED; retries = 0; + locked_obj = NULL; full_rescan: mtx_lock(&swhash_mtx); for (i = 0; i <= swhash_mask; i++) { /* '<=' is correct here */ restart: for (swap = swhash[i]; swap != NULL; swap = swap->swb_hnext) { - vm_object_t object = swap->swb_object; - vm_pindex_t pindex = swap->swb_index; + object = swap->swb_object; + pindex = swap->swb_index; for (j = 0; j < SWAP_META_PAGES; ++j) { - if (swp_pager_isondev(swap->swb_pages[j], sp)) { - /* avoid deadlock */ + if (!swp_pager_isondev(swap->swb_pages[j], sp)) + continue; + if (locked_obj != object) { + if (locked_obj != NULL) + VM_OBJECT_WUNLOCK(locked_obj); + locked_obj = object; if (!VM_OBJECT_TRYWLOCK(object)) { - break; - } else { mtx_unlock(&swhash_mtx); - swp_pager_force_pagein(object, - pindex + j); - VM_OBJECT_WUNLOCK(object); + /* Depends on type-stability. */ + VM_OBJECT_WLOCK(object); mtx_lock(&swhash_mtx); goto restart; } } + MPASS(locked_obj == object); + mtx_unlock(&swhash_mtx); + swp_pager_force_pagein(object, pindex + j); + mtx_lock(&swhash_mtx); + goto restart; } } } mtx_unlock(&swhash_mtx); + if (locked_obj != NULL) { + VM_OBJECT_WUNLOCK(locked_obj); + locked_obj = NULL; + } if (sp->sw_used) { /* * Objects may be locked or paging to the device being