diff --git a/Assistant/Threads/TransferScanner.hs b/Assistant/Threads/TransferScanner.hs index 46695469ee..5a6871fdb7 100644 --- a/Assistant/Threads/TransferScanner.hs +++ b/Assistant/Threads/TransferScanner.hs @@ -24,6 +24,7 @@ import qualified Remote import qualified Types.Remote as Remote import Utility.ThreadScheduler import Utility.NotificationBroadcaster +import Utility.Batch import qualified Git.LsFiles as LsFiles import qualified Backend import Annex.Content @@ -114,7 +115,7 @@ failedTransferScan r = do - since we need to look at the locations of all keys anyway. -} expensiveScan :: UrlRenderer -> [Remote] -> Assistant () -expensiveScan urlrenderer rs = unless onlyweb $ do +expensiveScan urlrenderer rs = unless onlyweb $ batch <~> do debug ["starting scan of", show visiblers] unwantedrs <- liftAnnex $ S.fromList diff --git a/Utility/Batch.hs b/Utility/Batch.hs new file mode 100644 index 0000000000..38b588b343 --- /dev/null +++ b/Utility/Batch.hs @@ -0,0 +1,40 @@ +{- Running a long or expensive batch operation niced. + - + - Copyright 2013 Joey Hess + - + - Licensed under the GNU GPL version 3 or higher. + -} + +{-# LANGUAGE CPP #-} + +module Utility.Batch where + +#if defined(__LINUX__) || defined(__ANDROID__) +import Control.Concurrent.Async +import System.Posix.Process +#endif + +{- Runs an operation, at batch priority. + - + - This is done by running it in a bound thread, which on Linux can be set + - to have a different nice level than the rest of the program. Note that + - due to running in a bound thread, some operations may be more expensive + - to perform. Also note that if the action calls forkIO or forkOS itself, + - that will make a new thread that does not have the batch priority. + - + - POSIX threads do not support separate nice levels, so on other operating + - systems, the action is simply ran. + -} +batch :: IO a -> IO a +#if defined(__LINUX__) || defined(__ANDROID__) +batch a = wait =<< batchthread + where + batchthread = asyncBound $ do + setProcessPriority 0 maxNice + a +#else +batch a = a +#endif + +maxNice :: Int +maxNice = 19 diff --git a/debian/changelog b/debian/changelog index d907b6ed3e..81d28087c5 100644 --- a/debian/changelog +++ b/debian/changelog @@ -35,6 +35,7 @@ git-annex (4.20130602) UNRELEASED; urgency=low git-annex branch. * Windows: The test suite now passes on Windows (a few broken parts are disabled). + * assistant: On Linux, the expensive transfer scan is run niced. -- Joey Hess Mon, 10 Jun 2013 12:52:44 -0400 diff --git a/git-annex.cabal b/git-annex.cabal index 210b64b01a..5ac4d0f0b9 100644 --- a/git-annex.cabal +++ b/git-annex.cabal @@ -115,6 +115,9 @@ Executable git-annex Build-Depends: data-endian CPP-Options: -D__ANDROID__ + if os(linux) + CPP-Options: -D__LINUX__ + if os(linux) && flag(Inotify) Build-Depends: hinotify CPP-Options: -DWITH_INOTIFY