Received: by 2002:ac0:aa62:0:0:0:0:0 with SMTP id w31-v6csp623421ima; Fri, 26 Oct 2018 04:06:39 -0700 (PDT) X-Google-Smtp-Source: AJdET5fCgOQcsskNq7i9Lbbb1lk9c4oWvs0wgWiqf95qIQ5OazoRFWGUPhIbaUbImJ8XzPVsROAY X-Received: by 2002:a65:594b:: with SMTP id g11-v6mr1366634pgu.229.1540551999229; Fri, 26 Oct 2018 04:06:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540551999; cv=none; d=google.com; s=arc-20160816; b=u6cCeafEPAR/Uq567HlEeD4l2cXN/qQnUYpeQDEkLpJgvW0mXnmEaKDafeoJM3Naac ipxlmdxpxdQWuBLIVno3oCCAV084lGKdHazAyBUtJA2nSdUo3lKlwCkxbpCX7KoFlClT zXOGAZfwJrKHIi1YzGC4S7GiCQdbwSu+fTF/eqYhWew6siwR99JkFSvcYX6WBWmeLCeF SFp1edMKbMm6FufV7OvFgRymBx/Z97QAq4Hj7gXBc+tExpePgF96aMO8PXoju/lTzgDR zXDULvjoIBwRp/oTUuXZRORVmqDOGHomUOywJfGKRvE1F8kDaxU6Y53ZuN8RvMyL8WYy xTqg== 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; bh=ea8p3HKg0CWuw4FP7JcPEPD+0XyFRH6vkPV60twmic8=; b=RZu14Y2zZMDBEUhCDUPOPOxODTGhQNhBFuU5QKxn69pIDIk7Y8jI9IzyLjsDaXztEU 5v4AYAk6S5VDUNSUsFUzD9p9CkSWKgcGisE1kgmvaHwwJDjuqJUV96ZOEe6HuwcyTX8k V7s+KE4L5FS45G5q65lRzaPdSWKol0BJmVgRKhzavBaLck7eKsH6VLvPVPRtj5m6R6hs puVY6+rU3fELk4tI/PvyNt1ZHcFMmti3ShP2UjkhdePg/gc1ZsFSZocx3OH7X8fs1r3G WXJN+K5gj239F81PdzU3lgCqiYCIQIUxtWxXu1x218cniQ5yaTos0bx21PZzHCK0mywF eeng== ARC-Authentication-Results: i=1; mx.google.com; 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 a4-v6si3480337pls.416.2018.10.26.04.06.23; Fri, 26 Oct 2018 04:06:39 -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; 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 S1727590AbeJZTmX (ORCPT + 99 others); Fri, 26 Oct 2018 15:42:23 -0400 Received: from mx2.suse.de ([195.135.220.15]:49402 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726612AbeJZTmX (ORCPT ); Fri, 26 Oct 2018 15:42:23 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id DB5BBAF63; Fri, 26 Oct 2018 11:05:42 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id ABA851E06DB; Fri, 26 Oct 2018 11:47:33 +0200 (CEST) Date: Fri, 26 Oct 2018 11:47:33 +0200 From: Jan Kara To: Josef Bacik Cc: Jan Kara , 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: <20181026094733.GB25227@quack2.suse.cz> References: <20181018202318.9131-1-josef@toxicpanda.com> <20181018202318.9131-8-josef@toxicpanda.com> <20181025132230.GD7711@quack2.suse.cz> <20181025135849.bu3cmjnrvz5yysye@macbook-pro-91.dhcp.thefacebook.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181025135849.bu3cmjnrvz5yysye@macbook-pro-91.dhcp.thefacebook.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu 25-10-18 09:58:51, Josef Bacik wrote: > 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, OK, but do you still need the vmf->cached_page stuff? Because I don't see why even that is necessary... Honza -- Jan Kara SUSE Labs, CR