Received: by 2002:ac0:aa62:0:0:0:0:0 with SMTP id w31-v6csp1874735ima; Thu, 25 Oct 2018 06:24:19 -0700 (PDT) X-Google-Smtp-Source: AJdET5ct0UPDIPY5MfJsrGJkLKTKukzJ3s/JqxOL9X0kV4lCkew9xLypkAQ/DXuWclxo0ybG25d9 X-Received: by 2002:a63:5022:: with SMTP id e34-v6mr1471037pgb.306.1540473859344; Thu, 25 Oct 2018 06:24:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540473859; cv=none; d=google.com; s=arc-20160816; b=mx6f6uWnz22G8UFGYvBdVe6qkms149/wj06mJM8tg6zNpKoJoPFTqGYhHJ21r6dtkv KFi0b9v7eW7GtJ755BLCwbvAzAmL2uLoBlRl5Vo2Zgyhd28c2GGuG+kPbXtKF3S1iZrJ 4UC14AXVvlHkw+wxgjjkfxAE3QxdTSrLdHsrDSEZsWCNq1Um4nFeWqmbywOSD0cfujjQ Zscp7sdBQPrjngmz4ngv0xvlq2BUkLLEbOM5xrlkC8SvQajhFYzKHaamgegDcB0vEieC kPFjXSq8cOJXEZe51Tsf0XqNh97anjwuk55wn/8LxD1Q/M64MuQ82k01Uh5AnsQHPz6Y L28w== 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=lG+m4o7ZY/CelBzxdsUuc18jZIC6jG9q8FEha/RAC2w=; b=lmU5A/yitWzfXgaDqgBHZKpg15n0WGlnJJjhrD1c/WMC03lHZdY1puEeWOsnv/kN0s MmapdYsfGnIF37eAkLjku/ld91KcSF+1v10Sj2Z2LS3bnEIvQ+fjOtXJbGNt+lqBOH7R IkeeGFwrDAiR8M7+tsG5x6XU2Ic9nUrWO8HkEj7j15UnF4ClYbERRRvdcehrAHBpAvEa zr8F7wx12x4gZ37NLKdTkPzErGVTdcwPpXycZWwz0esdO1e1UE+eRtCxtkxOwnaoU5GU o69QQJw6aMtvFIdsfLjErK4xOA0V68kYcH+WynZns7kr4Cq5SCNEtS+/5+nuQXm7B8nb bY4Q== 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 cf10-v6si8237129plb.278.2018.10.25.06.23.48; Thu, 25 Oct 2018 06:24:19 -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 S1727570AbeJYVzR (ORCPT + 99 others); Thu, 25 Oct 2018 17:55:17 -0400 Received: from mx2.suse.de ([195.135.220.15]:32878 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727234AbeJYVzQ (ORCPT ); Thu, 25 Oct 2018 17:55:16 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 97CEDAFC3; Thu, 25 Oct 2018 13:22:31 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 7FB581E06C6; Thu, 25 Oct 2018 15:22:30 +0200 (CEST) Date: Thu, 25 Oct 2018 15:22:30 +0200 From: Jan Kara To: Josef Bacik Cc: 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: <20181025132230.GD7711@quack2.suse.cz> References: <20181018202318.9131-1-josef@toxicpanda.com> <20181018202318.9131-8-josef@toxicpanda.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181018202318.9131-8-josef@toxicpanda.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 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? Honza -- Jan Kara SUSE Labs, CR