From owner-svn-src-head@freebsd.org Wed Aug 31 15:38:39 2016 Return-Path: Delivered-To: svn-src-head@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 ECAF9BCAB85; Wed, 31 Aug 2016 15:38:39 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from mail110.syd.optusnet.com.au (mail110.syd.optusnet.com.au [211.29.132.97]) by mx1.freebsd.org (Postfix) with ESMTP id B7D64805; Wed, 31 Aug 2016 15:38:39 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from c122-106-149-109.carlnfd1.nsw.optusnet.com.au (c122-106-149-109.carlnfd1.nsw.optusnet.com.au [122.106.149.109]) by mail110.syd.optusnet.com.au (Postfix) with ESMTPS id E3C907883A8; Thu, 1 Sep 2016 01:38:31 +1000 (AEST) Date: Thu, 1 Sep 2016 01:38:31 +1000 (EST) From: Bruce Evans X-X-Sender: bde@besplex.bde.org To: Konstantin Belousov cc: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r305129 - head/sys/vm In-Reply-To: <201608311449.u7VEnwlq064219@repo.freebsd.org> Message-ID: <20160901011048.T45881@besplex.bde.org> References: <201608311449.u7VEnwlq064219@repo.freebsd.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Optus-CM-Score: 0 X-Optus-CM-Analysis: v=2.1 cv=VIkg5I7X c=1 sm=1 tr=0 a=R/f3m204ZbWUO/0rwPSMPw==:117 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=kj9zAlcOel0A:10 a=WAYQV6Fnp0Brtd7ixUAA:9 a=CjuIK1q_8ugA:10 X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 31 Aug 2016 15:38:40 -0000 On Wed, 31 Aug 2016, Konstantin Belousov wrote: > Log: > Make swapoff reliable. > > The swap_pager_swapoff() function uses trylock for the object lock > before pagein, which means that either i/o to md(4) over swap, or > intensive page faults over swap pager objects might prevent swapoff() > from making any progress. Then the retry < 100 check fails and machine > panics. > > If trylock fails, acquire the object lock in the blockable way and > restart the hash bucket walk. Keep retries logic for now. Trylock is difficult to use. When it fails, there is no way for the caller to tell how long it should wait before retrying (much like EAGAIN errors for userland). Sometimes there is deadlock so retrying is worse than useless. Sometimes trylock can detect deadlock, but callers never can (otherwise they wouldn't try). My version of mtx_trylock_spin_flags() has a timeout in usec. It returns immediately if deadlock is detected. The timeout is just for convenience in simple cases where the caller want to aquire the lock normally but doesn't want the unbounded timeout or panic given by mtx_trylock_spin(). The important thing is to return error codes like: - EDEADLK for deadlock detected (e.g., when the CPU running the thread holding the lock is stopped) - EMAYBEDEADLK when deadlock is almost detected (e.g., when CPUs are being stopped) - EAGAIN when no problem is detected but the lock is held - ERECURSE when the lock is held but acquiring it recursively would work if the caller asked for that - ELOR if acquiring the lock would work but give a LOR, and the caller didn't ask for LORs. The current return value is positive logic for success and doesn't allow returning error codes. In my applications in console drivers, the caller doesn't want the lock if it would give a LOR. Without WITNESS, it is too hard to tell if the lock would give a LOR, but some errors are easy to detect. E.g., acquiring sleep lock in a critical section. Bruce