Received: by 2002:ac0:aa62:0:0:0:0:0 with SMTP id w31-v6csp1915801ima; Thu, 25 Oct 2018 07:01:26 -0700 (PDT) X-Google-Smtp-Source: AJdET5fy16VVwjvP6xL2wtccwbR2PUEzX1RKr1Z/pLJVTL1KPbL/OzbG8Q0p+/00/gYKGkgYYMq4 X-Received: by 2002:a62:1b45:: with SMTP id b66-v6mr1697760pfb.94.1540476086360; Thu, 25 Oct 2018 07:01:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540476086; cv=none; d=google.com; s=arc-20160816; b=gGAsxyAGCes/lrFTJFrfGBHo4WNTS6zITPvp3kdI7Lt01w6TLlU7cuGpkvbZCQECVX 6D6NCScXtZQYdSVKY5cUPYHllAd0xKSZtDuu/g8EVMGc060I8AJ6EAR/35nrKKCNgvC3 03Dc0zqbwN53nidHZ6584zqpbUg7AHwGX5Zgs7+ht99xogwvAlKlv7uVJzw2o12EI6Go KU3Mg/zAnhNohnJLt3fThZNMCZQqaeQS97ZP6Lx7aVrWmU3FNzx8LToGY5MbkiN9/CUP Mjtx7VYOhKn+lnjk0LLLZPNtNOTsxfLnqgUbNJkWLrSAIE3PXhUtjcONuBEA9BSD0rba M3lA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=F5Br1vFFX8kn4xvNIYzxt6g31sDP9kyeqhPTuCAWwfE=; b=U8h2b4h67zoqAYJQ60cGx9VtWZF4rrmtx8fsF8VX6Poku4hacR/agS7nfSw8/m3VJR 6uDPUemtIfT7mL2rZupx2KelROgJ5au10BdgaotbZl2YyvqCukZhWrF4umrRQF0XoGlI c5tnL2GiOhW7X5y89CyMRM5Dz8vLMlPT1H+66021TVqfgVq7DX1E9//Dh5o4h7cI45BE fEOOOxyB0XHxQbuTMxxP4JgD+gUIDkvfoz8iHPhXB4UFYjSBZxIzUl4gJrkfChrbuWDK lGArFnO0d4xiOutIdM2L04j94l2rY2Ky4YWzokTH9MAgFsr+rT1mUGBGxFeNXWTfEIRr g3ig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@toxicpanda-com.20150623.gappssmtp.com header.s=20150623 header.b=CMWZbZcU; 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 o1-v6si8190853pgh.193.2018.10.25.07.01.07; Thu, 25 Oct 2018 07:01:26 -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=CMWZbZcU; 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 S1727433AbeJYWbq (ORCPT + 99 others); Thu, 25 Oct 2018 18:31:46 -0400 Received: from mail-yb1-f195.google.com ([209.85.219.195]:35608 "EHLO mail-yb1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727401AbeJYWbq (ORCPT ); Thu, 25 Oct 2018 18:31:46 -0400 Received: by mail-yb1-f195.google.com with SMTP id k132-v6so3713584ybc.2 for ; Thu, 25 Oct 2018 06:58:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=F5Br1vFFX8kn4xvNIYzxt6g31sDP9kyeqhPTuCAWwfE=; b=CMWZbZcUk26TWxuvlEVVEnWf/u+ZmEzy51bIT2e+ufjWLux/wi3X4ip78tUOjrxqkR LJ9RAHfY3Mb9f6A20FZ7p0DCVC5j83fuNU6Gj5Is/EgA4ageQy7XplwryVzzjKHitIPh FHDUcmQQ2YwSpuMVMROlMuqhsprJ3hO7p0/MMTj8DYDAmqSwX573JqdT/rW3tgPpsIpZ G9OA49wUsptxkeRhopoiR26uPmd62dcaoDxCKVkQsK3wV8iMvYav1yAHavVLMYvJvlNV vkx2XMjov2dWaz+SkSkQlx3JKwRMamy1UZRQ6WvJshKnhxOF+SzPK+dfsIBBGK5SxaIG Xj0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=F5Br1vFFX8kn4xvNIYzxt6g31sDP9kyeqhPTuCAWwfE=; b=oT4S1gFhq5hvL0uHYhq/shiP7sM4fOaac+/lSxXzcfBT1XuevXWvLzovJ/bvKowNAK upA397/KMfgGW3IMiJnRaiApPETxrihzqhXhCUpeEUmu3axwVmYsg9GWrjTQfy5SKw0c 9+TRvWW2ewk+W/M+Em9lcKyC3hAtPWUS9BKHVXTCWVE2a2DHcFi3StIf78Jeb40fdytz NDNcIgZ3m4TrXqvkdEmnxTLCC9hoNXo99TC7S3AXAOJu6ZFSkeJ1DKfreB68rWwu4Sf5 YFVLiJl5MpCttB5rEtkvc37aaLpCdGIdsSH/pdj2FwRoLxegrn7oOCRoDHzzK89IYgE9 +IZA== X-Gm-Message-State: AGRZ1gI3KyD9mTWPYE21WQN+InCwu6PrnkgKCIKGommbRbitOnCPsZLK Lpr1LD4o55Gets2TELSWXE0N9Q== X-Received: by 2002:a25:c1c5:: with SMTP id r188-v6mr1518174ybf.260.1540475933459; Thu, 25 Oct 2018 06:58:53 -0700 (PDT) Received: from localhost ([2620:10d:c091:180::1:600d]) by smtp.gmail.com with ESMTPSA id 123-v6sm1994695ywx.15.2018.10.25.06.58.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 25 Oct 2018 06:58:52 -0700 (PDT) Date: Thu, 25 Oct 2018 09:58:51 -0400 From: Josef Bacik To: Jan Kara Cc: Josef Bacik , 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: Re: [PATCH 7/7] btrfs: drop mmap_sem in mkwrite for btrfs Message-ID: <20181025135849.bu3cmjnrvz5yysye@macbook-pro-91.dhcp.thefacebook.com> References: <20181018202318.9131-1-josef@toxicpanda.com> <20181018202318.9131-8-josef@toxicpanda.com> <20181025132230.GD7711@quack2.suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181025132230.GD7711@quack2.suse.cz> User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Oct 25, 2018 at 03:22:30PM +0200, Jan Kara wrote: > On Thu 18-10-18 16:23:18, Josef Bacik wrote: > > ->page_mkwrite is extremely expensive in btrfs. We have to reserve > > space, which can take 6 lifetimes, and we could possibly have to wait on > > writeback on the page, another several lifetimes. To avoid this simply > > drop the mmap_sem if we didn't have the cached page and do all of our > > work and return the appropriate retry error. If we have the cached page > > we know we did all the right things to set this page up and we can just > > carry on. > > > > Signed-off-by: Josef Bacik > ... > > @@ -8828,6 +8830,29 @@ vm_fault_t btrfs_page_mkwrite(struct vm_fault *vmf) > > > > reserved_space = PAGE_SIZE; > > > > + /* > > + * We have our cached page from a previous mkwrite, check it to make > > + * sure it's still dirty and our file size matches when we ran mkwrite > > + * the last time. If everything is OK then return VM_FAULT_LOCKED, > > + * otherwise do the mkwrite again. > > + */ > > + if (vmf->flags & FAULT_FLAG_USED_CACHED) { > > + lock_page(page); > > + if (vmf->cached_size == i_size_read(inode) && > > + PageDirty(page)) > > + return VM_FAULT_LOCKED; > > + unlock_page(page); > > + } > > I guess this is similar to Dave's comment: Why is i_size so special? What > makes sure that file didn't get modified between time you've prepared > cached_page and now such that you need to do the preparation again? > And if indeed metadata prepared for a page cannot change, what's so special > about it being that particular cached_page? > > Maybe to phrase my objections differently: Your preparations in > btrfs_page_mkwrite() are obviously related to your filesystem metadata. So > why cannot you infer from that metadata (extent tree, whatever - I'd use > extent status tree in ext4) whether that particular file+offset is already > prepared for writing and just bail out with success in that case? > I was just being overly paranoid, I was afraid of the case where we would truncate and then extend in between, but now that I actually think about it that would end up with the page not being on the mapping anymore so we would catch that case. I've dropped this part from my current version. I'm getting some testing on these patches in production and I'll post them sometime next week once I'm happy with them. Thanks, Josef