From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1FA94C2B9F7 for ; Wed, 26 May 2021 10:21:05 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9B43C61440 for ; Wed, 26 May 2021 10:21:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9B43C61440 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 25CE96B0070; Wed, 26 May 2021 06:21:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1E5DC6B0071; Wed, 26 May 2021 06:21:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0103A6B0072; Wed, 26 May 2021 06:21:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0238.hostedemail.com [216.40.44.238]) by kanga.kvack.org (Postfix) with ESMTP id BF1B06B0070 for ; Wed, 26 May 2021 06:21:03 -0400 (EDT) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 5F959180AD820 for ; Wed, 26 May 2021 10:21:03 +0000 (UTC) X-FDA: 78182989206.05.E198829 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf17.hostedemail.com (Postfix) with ESMTP id 7618240B8CFF for ; Wed, 26 May 2021 10:20:58 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1622024462; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=KNXtYbX9PoD7HWobCfGe506uRcOdWxiA8Gr7nrDFogA=; b=2urB98NmE/jP6mSICb3YhJoU3CNmVA3jsTPkDf7uho1D8U4aLvX/lEIJbpI3lzu6DI90cx 2tW3Ki9mRLc2S7rBmkdiGaAABLeduUVN5U6+vxKaHtuTRR9ubsJronVXiVU/Mr1KlGAcCl 37efE24YmVwNASTk4LKCY08gWwFykkk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1622024462; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=KNXtYbX9PoD7HWobCfGe506uRcOdWxiA8Gr7nrDFogA=; b=7FeQ1oYTjy3dESOA3v95EZt/vKI8f9cxYKZTi5iS4eZ6729GTgdeaYfZCfXLAK5U9i4RIo 5mD2xUxmmobGLpAg== Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 57F18B25F; Wed, 26 May 2021 10:21:01 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id DE7451F2CAC; Wed, 26 May 2021 12:20:59 +0200 (CEST) Date: Wed, 26 May 2021 12:20:59 +0200 From: Jan Kara To: Dave Chinner Cc: Jan Kara , linux-fsdevel@vger.kernel.org, Christoph Hellwig , ceph-devel@vger.kernel.org, Chao Yu , Damien Le Moal , "Darrick J. Wong" , Jaegeuk Kim , Jeff Layton , Johannes Thumshirn , linux-cifs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-mm@kvack.org, linux-xfs@vger.kernel.org, Miklos Szeredi , Steve French , Ted Tso , Matthew Wilcox , Christoph Hellwig Subject: Re: [PATCH 07/13] xfs: Convert to use invalidate_lock Message-ID: <20210526102059.GD30369@quack2.suse.cz> References: <20210525125652.20457-1-jack@suse.cz> <20210525135100.11221-7-jack@suse.cz> <20210525214041.GJ664593@dread.disaster.area> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210525214041.GJ664593@dread.disaster.area> User-Agent: Mutt/1.10.1 (2018-07-13) X-Rspamd-Queue-Id: 7618240B8CFF Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=2urB98Nm; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=7FeQ1oYT; dmarc=none; spf=pass (imf17.hostedemail.com: domain of jack@suse.cz designates 195.135.220.15 as permitted sender) smtp.mailfrom=jack@suse.cz X-Rspamd-Server: rspam03 X-Stat-Signature: z7eyzjgeb16e8kp51gzheu8qwd5gpmbn X-HE-Tag: 1622024458-332848 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Wed 26-05-21 07:40:41, Dave Chinner wrote: > On Tue, May 25, 2021 at 03:50:44PM +0200, Jan Kara wrote: > > Use invalidate_lock instead of XFS internal i_mmap_lock. The intended > > purpose of invalidate_lock is exactly the same. Note that the locking in > > __xfs_filemap_fault() slightly changes as filemap_fault() already takes > > invalidate_lock. > > > > Reviewed-by: Christoph Hellwig > > CC: > > CC: "Darrick J. Wong" > > Signed-off-by: Jan Kara > > --- > > fs/xfs/xfs_file.c | 12 ++++++----- > > fs/xfs/xfs_inode.c | 52 ++++++++++++++++++++++++++-------------------- > > fs/xfs/xfs_inode.h | 1 - > > fs/xfs/xfs_super.c | 2 -- > > 4 files changed, 36 insertions(+), 31 deletions(-) > > > > diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c > > index 396ef36dcd0a..dc9cb5c20549 100644 > > --- a/fs/xfs/xfs_file.c > > +++ b/fs/xfs/xfs_file.c > > @@ -1282,7 +1282,7 @@ xfs_file_llseek( > > * > > * mmap_lock (MM) > > * sb_start_pagefault(vfs, freeze) > > - * i_mmaplock (XFS - truncate serialisation) > > + * invalidate_lock (vfs/XFS_MMAPLOCK - truncate serialisation) > > * page_lock (MM) > > * i_lock (XFS - extent map serialisation) > > */ > > @@ -1303,24 +1303,26 @@ __xfs_filemap_fault( > > file_update_time(vmf->vma->vm_file); > > } > > > > - xfs_ilock(XFS_I(inode), XFS_MMAPLOCK_SHARED); > > if (IS_DAX(inode)) { > > pfn_t pfn; > > > > + xfs_ilock(XFS_I(inode), XFS_MMAPLOCK_SHARED); > > ret = dax_iomap_fault(vmf, pe_size, &pfn, NULL, > > (write_fault && !vmf->cow_page) ? > > &xfs_direct_write_iomap_ops : > > &xfs_read_iomap_ops); > > if (ret & VM_FAULT_NEEDDSYNC) > > ret = dax_finish_sync_fault(vmf, pe_size, pfn); > > + xfs_iunlock(XFS_I(inode), XFS_MMAPLOCK_SHARED); > > } else { > > - if (write_fault) > > + if (write_fault) { > > + xfs_ilock(XFS_I(inode), XFS_MMAPLOCK_SHARED); > > ret = iomap_page_mkwrite(vmf, > > &xfs_buffered_write_iomap_ops); > > - else > > + xfs_iunlock(XFS_I(inode), XFS_MMAPLOCK_SHARED); > > + } else > > ret = filemap_fault(vmf); > > } > > - xfs_iunlock(XFS_I(inode), XFS_MMAPLOCK_SHARED); > > This seems kinda messy. filemap_fault() basically takes the > invalidate lock around the entire operation, it runs, so maybe it > would be cleaner to implement it as: > > filemap_fault_locked(vmf) > { > /* does the filemap fault work */ > } > > filemap_fault(vmf) > { > filemap_invalidate_down_read(...) > ret = filemap_fault_locked(vmf) > filemap_invalidate_up_read(...) > return ret; > } > > And that means XFS could just call filemap_fault_locked() and not > have to do all this messy locking just to avoid holding the lock > that filemap_fault has now internalised. Sure, I can do that. > > @@ -355,8 +358,11 @@ xfs_isilocked( > > > > if (lock_flags & (XFS_MMAPLOCK_EXCL|XFS_MMAPLOCK_SHARED)) { > > if (!(lock_flags & XFS_MMAPLOCK_SHARED)) > > - return !!ip->i_mmaplock.mr_writer; > > - return rwsem_is_locked(&ip->i_mmaplock.mr_lock); > > + return !debug_locks || > > + lockdep_is_held_type( > > + &VFS_I(ip)->i_mapping->invalidate_lock, > > + 0); > > + return rwsem_is_locked(&VFS_I(ip)->i_mapping->invalidate_lock); > > } > > > > And so here we are again, losing more of our read vs write debug > checks on debug kernels when lockdep is not enabled.... > > Can we please add rwsem_is_locked_read() and rwsem_is_locked_write() > wrappers that just look at the rwsem counter value to determine how > the lock is held? Then the mrlock_t can go away entirely.... Apparently someone already did that for XFS as Darrick pointed out. So we just have to sort out how to merge it. Honza -- Jan Kara SUSE Labs, CR