From patchwork Sat May 19 01:35:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 10412491 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B712B60230 for ; Sat, 19 May 2018 01:45:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AFADC28926 for ; Sat, 19 May 2018 01:45:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A43CB28AF6; Sat, 19 May 2018 01:45:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2FCAD28926 for ; Sat, 19 May 2018 01:45:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D42946B06B5; Fri, 18 May 2018 21:45:28 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id CF1F06B06B6; Fri, 18 May 2018 21:45:28 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C08AE6B06B7; Fri, 18 May 2018 21:45:28 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl0-f72.google.com (mail-pl0-f72.google.com [209.85.160.72]) by kanga.kvack.org (Postfix) with ESMTP id 8098D6B06B5 for ; Fri, 18 May 2018 21:45:28 -0400 (EDT) Received: by mail-pl0-f72.google.com with SMTP id i1-v6so6098634pld.11 for ; Fri, 18 May 2018 18:45:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:subject:from :to:cc:date:message-id:in-reply-to:references:user-agent :mime-version:content-transfer-encoding; bh=6Fi5s3MPCnLM/nzYuf973545TFksOorJGStyHlBeBiE=; b=JuPIbzc7pZHGAGpSbQAMyiBdQ/i5awxlFTlOdxR7E9W7lUYOpcysmh/tyAh+vqcUnD V51eh0wki6J915fgt1x+JxA5T7TOo1e7mYN/M2iSff048Q2+dTAAZ1QmWKnjwhr/QAZf N7J+/vowe8xM9bv8ppWi/NYOylaz8H+brRxmC0Y18WhREE3f+8VjxHZs2E+jPiVr6XGz TyCMP6OS+ARs93Y3uH19MzMqt/fcb3vcRrm4iOy+934uqaw9w37Zf9spW6noErApG+4F L/qRDT+r+bnJduPIy15r+U/SUgW8lG30qC6vp09bLZxdnbLzaqUJElwBYj5RUSbaUwza LKog== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 192.55.52.93 as permitted sender) smtp.mailfrom=dan.j.williams@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Gm-Message-State: ALKqPwfXI+bV4ohq0M2e5oCC9S3OV1H/34FRfWCMwOb/uALsCvu/n7M0 T++ScRskfXn42YA24mYQh07J18BQYhkmeHu9MDvUdLkfskoWHlorpEg9thFTqG8hXEoHOPXeOFP ymPgT0EgG1oSwtCRpLKpfHt4urY+Bt6tA4dGds4q7hMXUMdy4OW0SoAdVGl8n70ZWDQ== X-Received: by 2002:a17:902:b681:: with SMTP id c1-v6mr11741845pls.286.1526694328223; Fri, 18 May 2018 18:45:28 -0700 (PDT) X-Google-Smtp-Source: AB8JxZokCAt/dpvxBFjlysdYb4Y+mcM77nVW/ZKOgoU4PNzFu1JDiUwxjM84wk0lvYKlmz0ZKRZS X-Received: by 2002:a17:902:b681:: with SMTP id c1-v6mr11741790pls.286.1526694327153; Fri, 18 May 2018 18:45:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526694327; cv=none; d=google.com; s=arc-20160816; b=lFGVNaxy8GTmmtvUSYw2QPXDVuVocWneVbdPfDrf9D58ZvmeIzYkcsIwx0CusHF413 RiAWYyoQAZzTYin1NSFMwrl9wV17apwSuy+Q+4/ABHMCH3QOoxYGDtoqWwF+dnWQD+/6 nb575MsrnVasObHR9Y+mgwlPCwUqPGP4luS5zUl6F27e21WFfaZbcrCg7JB4Tg1MxeMW 7QbH/9zFlXSRF65n+oao/xDl9fvxxCaJ7Ar7crFP11oPJa+RMSoLBly6MWQESAShzJ/I ePcw2sfJaP6crTJOuRSlI6JbL9JR88X0GmbiGmMRj/CNL1GzvYUHEKgCM7msyQ/9bFXz tPnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:message-id:date:cc:to:from:subject :arc-authentication-results; bh=6Fi5s3MPCnLM/nzYuf973545TFksOorJGStyHlBeBiE=; b=Cc7j6U+Ef+OTxsAUvjLuY/JgEJKYBb3b6v+rhnmKFzvst7InVLqwYiYIsZI0PIH6E3 CasfOG7OQd8+8tpF3fthmsYEzUdOEeMy8AouVZkgrD1ZnHq2Fj6ZHLoULuRrP86iYbi4 F17fpEvx0VqWs6ZRNUGVBvKNWtyYYOz5PUUQNSemR0cOIqmbJ7IF9Yw/Ik3mB4F4VQb2 OyrBaWv44oejJa1zd+yrryMeqePoTutZADx7sD12zp1ZBLfDV3eNqICX/Z8H7idH8TNy MinjdsdBGgE4dfQtfZ0/mWsOi9AIWbriLnN7a0JBG1dwCTSyKfzyy1WtmlU3tOY3Ekaf eCog== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 192.55.52.93 as permitted sender) smtp.mailfrom=dan.j.williams@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga11.intel.com (mga11.intel.com. [192.55.52.93]) by mx.google.com with ESMTPS id b19-v6si8696723pfh.358.2018.05.18.18.45.26 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 May 2018 18:45:27 -0700 (PDT) Received-SPF: pass (google.com: domain of dan.j.williams@intel.com designates 192.55.52.93 as permitted sender) client-ip=192.55.52.93; Authentication-Results: mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 192.55.52.93 as permitted sender) smtp.mailfrom=dan.j.williams@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 May 2018 18:45:26 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,417,1520924400"; d="scan'208";a="229917188" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by fmsmga006.fm.intel.com with ESMTP; 18 May 2018 18:45:25 -0700 Subject: [PATCH v11 7/7] xfs, dax: introduce xfs_break_dax_layouts() From: Dan Williams To: linux-nvdimm@lists.01.org Cc: Dave Chinner , Ross Zwisler , Jan Kara , Jan Kara , Christoph Hellwig , "Darrick J. Wong" , linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Date: Fri, 18 May 2018 18:35:29 -0700 Message-ID: <152669372916.34337.4066620800998291994.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <152669369110.34337.14271778212195820353.stgit@dwillia2-desk3.amr.corp.intel.com> References: <152669369110.34337.14271778212195820353.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.18-2-gc94f MIME-Version: 1.0 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: X-Virus-Scanned: ClamAV using ClamSMTP xfs_break_dax_layouts(), similar to xfs_break_leased_layouts(), scans for busy / pinned dax pages and waits for those pages to go idle before any potential extent unmap operation. dax_layout_busy_page() handles synchronizing against new page-busy events (get_user_pages). It invalidates all mappings to trigger the get_user_pages slow path which will eventually block on the xfs inode lock held in XFS_MMAPLOCK_EXCL mode. If dax_layout_busy_page() finds a busy page it returns it for xfs to wait for the page-idle event that will fire when the page reference count reaches 1 (recall ZONE_DEVICE pages are idle at count 1, see generic_dax_pagefree()). While waiting, the XFS_MMAPLOCK_EXCL lock is dropped in order to not deadlock the process that might be trying to elevate the page count of more pages before arranging for any of them to go idle. I.e. the typical case of submitting I/O is that iov_iter_get_pages() elevates the reference count of all pages in the I/O before starting I/O on the first page. The process of elevating the reference count of all pages involved in an I/O may cause faults that need to take XFS_MMAPLOCK_EXCL. Although XFS_MMAPLOCK_EXCL is dropped while waiting, XFS_IOLOCK_EXCL is held while sleeping. We need this to prevent starvation of the truncate path as continuous submission of direct-I/O could starve the truncate path indefinitely if the lock is dropped. Cc: Dave Chinner Cc: Ross Zwisler Reported-by: Jan Kara Reviewed-by: Jan Kara Cc: Christoph Hellwig Acked-by: Darrick J. Wong Signed-off-by: Dan Williams Reviewed-by: Christoph Hellwig --- fs/xfs/xfs_file.c | 61 ++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 51 insertions(+), 10 deletions(-) diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index 4774c7172ef4..f5695dc314f1 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -718,6 +718,38 @@ xfs_file_write_iter( return ret; } +static void +xfs_wait_dax_page( + struct inode *inode, + bool *did_unlock) +{ + struct xfs_inode *ip = XFS_I(inode); + + *did_unlock = true; + xfs_iunlock(ip, XFS_MMAPLOCK_EXCL); + schedule(); + xfs_ilock(ip, XFS_MMAPLOCK_EXCL); +} + +static int +xfs_break_dax_layouts( + struct inode *inode, + uint iolock, + bool *did_unlock) +{ + struct page *page; + + ASSERT(xfs_isilocked(XFS_I(inode), XFS_MMAPLOCK_EXCL)); + + page = dax_layout_busy_page(inode->i_mapping); + if (!page) + return 0; + + return ___wait_var_event(&page->_refcount, + atomic_read(&page->_refcount) == 1, TASK_INTERRUPTIBLE, + 0, 0, xfs_wait_dax_page(inode, did_unlock)); +} + int xfs_break_layouts( struct inode *inode, @@ -725,19 +757,28 @@ xfs_break_layouts( enum layout_break_reason reason) { bool retry; + int error; ASSERT(xfs_isilocked(XFS_I(inode), XFS_IOLOCK_SHARED|XFS_IOLOCK_EXCL)); - switch (reason) { - case BREAK_UNMAP: - ASSERT(xfs_isilocked(XFS_I(inode), XFS_MMAPLOCK_EXCL)); - /* fall through */ - case BREAK_WRITE: - return xfs_break_leased_layouts(inode, iolock, &retry); - default: - WARN_ON_ONCE(1); - return -EINVAL; - } + do { + retry = false; + switch (reason) { + case BREAK_UNMAP: + error = xfs_break_dax_layouts(inode, *iolock, &retry); + if (error || retry) + break; + /* fall through */ + case BREAK_WRITE: + error = xfs_break_leased_layouts(inode, iolock, &retry); + break; + default: + WARN_ON_ONCE(1); + error = -EINVAL; + } + } while (error == 0 && retry); + + return error; } #define XFS_FALLOC_FL_SUPPORTED \