Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1690229ybz; Thu, 16 Apr 2020 13:46:04 -0700 (PDT) X-Google-Smtp-Source: APiQypLnYpYABm7TjtCEg02U4jivEZ4vSyutbHJ+oC3TF+FlaYpP1IcksjXFk9IcGxQGYSwE2mw7 X-Received: by 2002:a17:906:6987:: with SMTP id i7mr11521522ejr.12.1587069964013; Thu, 16 Apr 2020 13:46:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587069964; cv=none; d=google.com; s=arc-20160816; b=W8WsJdEKMjKnC3lkA03F4Q1pGtHYyVf6KD8pYKGS3BiEjH1+7VzYwMbCcFx6ntU4q1 WZoJbXNMzAVHTs7JchXj+hsdZ3ynhiAkdkP1lWFeMRXDbuKzIw6eQcxOG7u73Y8V2s4q eWskrnQbSpu7UNLE9BYY3LrRCthCRJX6qeTgeXrRumgDtqf84LMbZ4TW44HsV68FS7SD PwjpnXMPzWdFKVMP9A7iB14/1aMQb20h6CG91FxUpswBn31mc65mySHFfiyt5Ew2A8SY hoFmF9wKV9nF83r3LJHwbt90LZ+VMk+sMMFKzdhkbWSz3kZzvE1gf+jR2hqffJo+siZX UUXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=LcO8LGSRLpNBRQkWwHdMf9RGdRa86XKrk2exP8zF5vE=; b=jEJNmHefYSVTRCR4x4o3+rjI3a7OWFutWeFNwwQ1W6H5hdZC/U2mv4iiLNg/G00fWP 2B1bk6wBW/0oWYHXzv+8ANNsoARg/rmjnHMMFepvuXHY5k4dOx5/J4y4TBFlDb2Zsaiw oz4XGAQ3aS1bKBHhnGNH2e5Ul38BrR/v7c4UYEM3B/K3qo0Xobg28DqP3l155DWBv3DD tX4tKlR5Sp7oYGVZY6vOuChV1rdNLJCJUoGCCMH0fxwiBTCNu53/k24LhcOwz8QvYDOg h/jSAvzqx0ihGkeySttEVZ6J86VhfDXCVcIe+BNZwS6/P3DDg07oFUZvG4bVsK8V7bUP 2Gjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Uyos0jNd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e4si6545714edm.570.2020.04.16.13.45.41; Thu, 16 Apr 2020 13:46:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Uyos0jNd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730295AbgDPTFY (ORCPT + 99 others); Thu, 16 Apr 2020 15:05:24 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:52926 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728611AbgDPTFX (ORCPT ); Thu, 16 Apr 2020 15:05:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587063921; h=from:from:reply-to:subject:subject: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=LcO8LGSRLpNBRQkWwHdMf9RGdRa86XKrk2exP8zF5vE=; b=Uyos0jNd0X1zkATsvQc8EhD1tog5pjW0fQQC56zwBlVIDFcsRlLNzYMsgaazNtsmsKJcGX s/sBkSfVYMyRgqsf0SDY8t4NGI4XunKEsGjoJUWiO1NzLm14buna42m8i2un6nPWg3Cc9F 41+Pdclg7aA1M5ww9MWGg4V5+15HHz8= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-73-6Ukn1W4mMRGW_C6M9lssZQ-1; Thu, 16 Apr 2020 15:05:17 -0400 X-MC-Unique: 6Ukn1W4mMRGW_C6M9lssZQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2B336107ACCC; Thu, 16 Apr 2020 19:05:16 +0000 (UTC) Received: from horse.redhat.com (ovpn-116-15.rdu2.redhat.com [10.10.116.15]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1B10E10027C3; Thu, 16 Apr 2020 19:05:07 +0000 (UTC) Received: by horse.redhat.com (Postfix, from userid 10451) id 4C979220537; Thu, 16 Apr 2020 15:05:07 -0400 (EDT) Date: Thu, 16 Apr 2020 15:05:07 -0400 From: Vivek Goyal To: Liu Bo Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvdimm@lists.01.org, virtio-fs@redhat.com, miklos@szeredi.hu, stefanha@redhat.com, dgilbert@redhat.com, mst@redhat.com Subject: Re: [PATCH 20/20] fuse,virtiofs: Add logic to free up a memory range Message-ID: <20200416190507.GC276932@redhat.com> References: <20200304165845.3081-1-vgoyal@redhat.com> <20200304165845.3081-21-vgoyal@redhat.com> <20200326000904.GA34937@rsjd01523.et2sqa> <20200327140114.GB32717@redhat.com> <20200327220606.GA119028@rsjd01523.et2sqa> <20200414193045.GB210453@redhat.com> <20200415172229.GA121484@rsjd01523.et2sqa> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200415172229.GA121484@rsjd01523.et2sqa> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 16, 2020 at 01:22:29AM +0800, Liu Bo wrote: > On Tue, Apr 14, 2020 at 03:30:45PM -0400, Vivek Goyal wrote: > > On Sat, Mar 28, 2020 at 06:06:06AM +0800, Liu Bo wrote: > > > On Fri, Mar 27, 2020 at 10:01:14AM -0400, Vivek Goyal wrote: > > > > On Thu, Mar 26, 2020 at 08:09:05AM +0800, Liu Bo wrote: > > > > > > > > [..] > > > > > > +/* > > > > > > + * Find first mapping in the tree and free it and return it. Do not add > > > > > > + * it back to free pool. If fault == true, this function should be called > > > > > > + * with fi->i_mmap_sem held. > > > > > > + */ > > > > > > +static struct fuse_dax_mapping *inode_reclaim_one_dmap(struct fuse_conn *fc, > > > > > > + struct inode *inode, > > > > > > + bool fault) > > > > > > +{ > > > > > > + struct fuse_inode *fi = get_fuse_inode(inode); > > > > > > + struct fuse_dax_mapping *dmap; > > > > > > + int ret; > > > > > > + > > > > > > + if (!fault) > > > > > > + down_write(&fi->i_mmap_sem); > > > > > > + > > > > > > + /* > > > > > > + * Make sure there are no references to inode pages using > > > > > > + * get_user_pages() > > > > > > + */ > > > > > > + ret = fuse_break_dax_layouts(inode, 0, 0); > > > > > > > > > > Hi Vivek, > > > > > > > > > > This patch is enabling inline reclaim for fault path, but fault path > > > > > has already holds a locked exceptional entry which I believe the above > > > > > fuse_break_dax_layouts() needs to wait for, can you please elaborate > > > > > on how this can be avoided? > > > > > > > > > > > > > Hi Liubo, > > > > > > > > Can you please point to the exact lock you are referring to. I will > > > > check it out. Once we got rid of needing to take inode lock in > > > > reclaim path, that opended the door to do inline reclaim in fault > > > > path as well. But I was not aware of this exceptional entry lock. > > > > > > Hi Vivek, > > > > > > dax_iomap_{pte,pmd}_fault has called grab_mapping_entry to get a > > > locked entry, when this fault gets into inline reclaim, would > > > fuse_break_dax_layouts wait for the locked exceptional entry which is > > > locked in dax_iomap_{pte,pmd}_fault? > > > > Hi Liu Bo, > > > > This is a good point. Indeed it can deadlock the way code is written > > currently. > > > > It's 100% reproducible on 4.19, but not on 5.x which has xarray for > dax_layout_busy_page. > > It was weird that on 5.x kernel the deadlock is gone, it turned out > that xarray search in dax_layout_busy_page simply skips the empty > locked exceptional entry, I didn't get deeper to find out whether it's > reasonable, but with that 5.x doesn't run to deadlock. I found more problems with enabling inline reclaim in fault path. I am holding fi->i_mmap_sem, shared and fuse_break_dax_layouts() can drop fi->i_mmap_sem if page is busy. I don't think we can drop and reacquire fi->i_mmap_sem while in fault path. Also fuse_break_dax_layouts() does not know if we are holding it shared or exclusive. So I will probably have to go back to disable inline reclaim in fault path. If memory range is not available go back up in fuse_dax_fault(), drop fi->i_mmap_sem lock and wait on wait queue for a range to become free and retry. I can retain the changes I did to break layout for a 2MB range only and not the whole file. I think that's a good optimization to retain anyway. Vivek