Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp2364120imm; Thu, 18 Oct 2018 13:24:17 -0700 (PDT) X-Google-Smtp-Source: ACcGV61i3/fvfcpwPhDio5KwqTYKqnhesBlZLQYY14VJQ+rAaQrwZBiIQTC/hlopch39H5aN2w3c X-Received: by 2002:a17:902:22a:: with SMTP id 39-v6mr31735867plc.267.1539894257148; Thu, 18 Oct 2018 13:24:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539894257; cv=none; d=google.com; s=arc-20160816; b=v5G0QSVWFtT0oo7HznLzNeEPCTYO7iFqDqHKw4Gm3vTOdtub/pp+zV0HHADsc73SQq HucXlNGyJ+KZlgI59JVsdiBTNPRZAO1pfV+YqhTkx+seJXCToHCog2F2ZmOCpqf6+0i2 P0LhtpsVMpAbTFIaELCc4mQHWTPmg6b5ZLhQqW6P9rh4AtGdRFHkduKcUBHFq0NgUcfK hiwelitNjWyhw8uHWNRFsmRaKQOFWgwkq39N7hc8Or74NOO5AVHVKsSSX1YgrQls1zyQ oqAq4skqnJkaiL/93JW5n+wzJs+ABKkpFLSTAMolJSr5LWyEYVUxpPm7f2H5Xn+TTp4Z gqhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:to:from :dkim-signature; bh=DWidnD6qko/sL4ed97MdEuO7mHJAyViTAX5kCV+6cyc=; b=ULZ2hWepPqmxKU5kcREtjKhfoc6ue1k2PndPQEMLUa9TEfQap8Tm7eAbrk0yLCoM4V CPBCfTH3et4J9ngapfuKLHPguHlNcCxUUWVkCxaINUUgdMH8ISfO3EZuK3wbF+Ke09zC 0kr8fvjFcjOd7c1MMnthBznjPjKYckbReKlhJsU0S+EFUn8EeRbD6PjfecKuSfklCCBk xDMfusGI1ThvBSToTjqQDJkIZIcJdyXvfv9lXb3HK1LZE19jaNAgzF0ydapSoWED1Ytk /3MEIh/27VfIH0mBf70pkkhtvfPqdqyYlEeYB/qwcNcdaZ6TDacGz5FOxTmpHMq/45gU 1Nsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@toxicpanda-com.20150623.gappssmtp.com header.s=20150623 header.b=AaEbPwvI; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y28-v6si21888409pfk.230.2018.10.18.13.24.00; Thu, 18 Oct 2018 13:24:17 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@toxicpanda-com.20150623.gappssmtp.com header.s=20150623 header.b=AaEbPwvI; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727397AbeJSE0I (ORCPT + 99 others); Fri, 19 Oct 2018 00:26:08 -0400 Received: from mail-qt1-f175.google.com ([209.85.160.175]:36019 "EHLO mail-qt1-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726916AbeJSE0I (ORCPT ); Fri, 19 Oct 2018 00:26:08 -0400 Received: by mail-qt1-f175.google.com with SMTP id u34-v6so35862760qth.3 for ; Thu, 18 Oct 2018 13:23:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id; bh=DWidnD6qko/sL4ed97MdEuO7mHJAyViTAX5kCV+6cyc=; b=AaEbPwvIQ2uGM6aHQ3euKHdNj9EWEgUN/aAWClr4BNjuZiV6sYn0RLHAKPODu9L+21 It7zKNOR8t4h8dy8WuSA8VLm8gdQgFnZZG8TCqZLHdJBcWGhh+HD7IJlaox4FetBBFL2 vH3mWAR5w+6QRzx3xgXDCUNFbz91FarZqclXCcOZYT+pPgNeuCR8osS0rJblLspEcig3 iSrMhaN7aNcVI6/blu1MxEbaNIUEYCiRt6EvB95nyXS9yHaxFALWO2EX8bx0EPgsFe/Q IZxe9iXQMiXWLbBsDkvwhbnnlEqaKPCsiVOENxGCJNMp0xwgu1Y36SrlsG1i+DbOnAi+ Z60Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=DWidnD6qko/sL4ed97MdEuO7mHJAyViTAX5kCV+6cyc=; b=Yy5uUUCJ8TdeQV4Q/yMszlOFQf11G97PgKs7nn2loI1UCP0oVwu7PU9sccpIRiGZan 4SnNvoeKjAZ+fuH7hoe90kyK9mqH8bpctW+3DsRkeUXJExkzKnXwO5fcCtd3k2fONxpW /6HqGMMX6A8UWCC/5nCRk9HBMMSL50diSVYMNshKpB68D9+rBQhNSOH4MxwPghMr2YIm tMri6AN4hkbLvjNIazj5GhGtSCioCI4zkpNyxn1vRaQhCr4eF7Fkf1+tmBkfVHqm5Zg+ WPrBMUeazcUCvCVxFov6CpDR8ijQ2MQVN669l3LO5JcCJ8gJy4LoXaorukLR23gPtqW4 avJQ== X-Gm-Message-State: ABuFfojNA63I3Wt3uIG9sGLCncU+tJuX4tMchmT9ELFsfDc1lHX83JJw BSmGnpamFiqtjTDJW4KHCUEHWA== X-Received: by 2002:a0c:95e6:: with SMTP id t35mr31999009qvt.163.1539894207297; Thu, 18 Oct 2018 13:23:27 -0700 (PDT) Received: from localhost ([107.15.81.208]) by smtp.gmail.com with ESMTPSA id q24-v6sm14344124qtb.26.2018.10.18.13.23.25 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 18 Oct 2018 13:23:26 -0700 (PDT) From: Josef Bacik To: kernel-team@fb.com, hannes@cmpxchg.org, linux-kernel@vger.kernel.org, tj@kernel.org, david@fromorbit.com, akpm@linux-foundation.org, linux-fsdevel@vger.kernel.org, linux-btrfs@vger.kernel.org, riel@fb.com, linux-mm@kvack.org Subject: [PATCH 0/7][V3] drop the mmap_sem when doing IO in the fault path Date: Thu, 18 Oct 2018 16:23:11 -0400 Message-Id: <20181018202318.9131-1-josef@toxicpanda.com> X-Mailer: git-send-email 2.14.3 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Getting some production testing running on these patches shortly to verify they are ready for primetime, but in the meantime they've had a bunch of xfstests runs on xfs, btrfs, and ext4 using kvm-xfstests. v2->v3: - dropped the RFC, ready for a real review. - fixed a kbuild error for !MMU configs. - dropped the swapcache patches since Johannes is still working on those parts. v1->v2: - reworked so it only affects x86, since its the only arch I can build and test. - fixed the fact that do_page_mkwrite wasn't actually sending ALLOW_RETRY down to ->page_mkwrite. - fixed error handling in do_page_mkwrite/callers to explicitly catch VM_FAULT_RETRY. - fixed btrfs to set ->cached_page properly. This time I've verified that the ->page_mkwrite retry path is actually getting used (apparently I only verified the read side last time). xfstests is still running but it passed the couple of mmap tests I ran directly. Again this is an RFC, I'm still doing a bunch of testing, but I'd appreciate comments on the overall strategy. -- Original message -- Now that we have proper isolation in place with cgroups2 we have started going through and fixing the various priority inversions. Most are all gone now, but this one is sort of weird since it's not necessarily a priority inversion that happens within the kernel, but rather because of something userspace does. We have giant applications that we want to protect, and parts of these giant applications do things like watch the system state to determine how healthy the box is for load balancing and such. This involves running 'ps' or other such utilities. These utilities will often walk /proc//whatever, and these files can sometimes need to down_read(&task->mmap_sem). Not usually a big deal, but we noticed when we are stress testing that sometimes our protected application has latency spikes trying to get the mmap_sem for tasks that are in lower priority cgroups. This is because any down_write() on a semaphore essentially turns it into a mutex, so even if we currently have it held for reading, any new readers will not be allowed on to keep from starving the writer. This is fine, except a lower priority task could be stuck doing IO because it has been throttled to the point that its IO is taking much longer than normal. But because a higher priority group depends on this completing it is now stuck behind lower priority work. In order to avoid this particular priority inversion we want to use the existing retry mechanism to stop from holding the mmap_sem at all if we are going to do IO. This already exists in the read case sort of, but needed to be extended for more than just grabbing the page lock. With io.latency we throttle at submit_bio() time, so the readahead stuff can block and even page_cache_read can block, so all these paths need to have the mmap_sem dropped. The other big thing is ->page_mkwrite. btrfs is particularly shitty here because we have to reserve space for the dirty page, which can be a very expensive operation. We use the same retry method as the read path, and simply cache the page and verify the page is still setup properly the next pass through ->page_mkwrite(). I've tested these patches with xfstests and there are no regressions. Let me know what you think. Thanks, Josef