From mboxrd@z Thu Jan 1 00:00:00 1970 From: Matthew Wilcox Subject: [PATCH v6 57/99] dax: Convert dax_unlock_mapping_entry to XArray Date: Wed, 17 Jan 2018 12:21:21 -0800 Message-ID: <20180117202203.19756-58-willy@infradead.org> References: <20180117202203.19756-1-willy@infradead.org> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=References:In-Reply-To:Message-Id:Date:Subject:Cc: To:From:Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=Z+ajj2wD4YsebV2T4CDiyg/K740zitLZXJd3yaYAxYY=; b=nI27ZyO5zMPv/7PG2HgNdt/DAj ewIn5q/FbcVWp7fgqooFyd4k2mbnLqz7kU2e1KI6sNc/pRShdFXDeZ3xtXO2vD0j/44creXtnkmDj d5DOyHOAGjUHvP24Zy+8YBrr6K19SsVfTbZwZwVn15NwNBPrp37kqKyLQeK1JjpyEn54=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To :MIME-Version:Content-Type:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=Z+ajj2wD4YsebV2T4CDiyg/K740zitLZXJd3yaYAxYY=; b=jXFK1zxHmCImHUGqUdSS/pSZJH 7FeoTj9oOlgT5HnDxaygjXDwlx97c976wiNK5lh2dRDZcVX/LSHJupPc/EY1ury4ts0NbtRmD/cZr CF9nXprDI/z+mteWRq/nSQVek9Ko+vBIvRFpZ33/iKibLB15kr1Jv388CfPwyzoHxmZc=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=Z+ajj2wD4YsebV2T4CDiyg/K740zitLZXJd3yaYAxYY=; b=UMVqCZ4n3BWUCchehQooIWPkX ZCiiy2jJhqKy20/XNvSQscnRanbBFcaIukqaaKiFosQ9OQ6fMLDRoZ4vqSQ9rwe8qOXdnfT8RUX7J 6vRocjbGPfi2TPOxYT59fkk/V461FEeBtMJt4jejA3FGwgDVGe4NSNDJQeHeiWu22BVJKTXi5D7Gd aUGDbRvfBUU2riSNU62oM85fM4tj3iIDRN/f6I8nW9UQfxKSh6eL497AkcKZqMIZcIKQu9c6+4uhf GXulDCD184rM846aa+IMjb3t1hwA7cj8qPgvx1ZpKoZ/Y0X/EW80nSejmUWSDl7AkWgGU27en3xyq HkMlGTFCg==; In-Reply-To: <20180117202203.19756-1-willy@infradead.org> List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net To: linux-kernel@vger.kernel.org Cc: linux-s390@vger.kernel.org, David Howells , linux-nilfs@vger.kernel.org, Matthew Wilcox , linux-sh@vger.kernel.org, intel-gfx@lists.freedesktop.org, linux-usb@vger.kernel.org, linux-remoteproc@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-xfs@vger.kernel.org, linux-mm@kvack.org, iommu@lists.linux-foundation.org, Stefano Stabellini , linux-fsdevel@vger.kernel.org, cgroups@vger.kernel.org, Bjorn Andersson , linux-btrfs@vger.kernel.org From: Matthew Wilcox Replace slot_locked() with dax_locked() and inline unlock_slot() into its only caller. Signed-off-by: Matthew Wilcox --- fs/dax.c | 48 ++++++++++++++++-------------------------------- 1 file changed, 16 insertions(+), 32 deletions(-) diff --git a/fs/dax.c b/fs/dax.c index 5097a606da1a..f3463d93a6ce 100644 --- a/fs/dax.c +++ b/fs/dax.c @@ -73,6 +73,11 @@ fs_initcall(init_dax_wait_table); #define DAX_ZERO_PAGE (1UL << 2) #define DAX_EMPTY (1UL << 3) +static bool dax_locked(void *entry) +{ + return xa_to_value(entry) & DAX_ENTRY_LOCK; +} + static unsigned long dax_radix_sector(void *entry) { return xa_to_value(entry) >> DAX_SHIFT; @@ -180,16 +185,6 @@ static void dax_wake_mapping_entry_waiter(struct address_space *mapping, __wake_up(wq, TASK_NORMAL, wake_all ? 0 : 1, &key); } -/* - * Check whether the given slot is locked. Must be called with xa_lock held. - */ -static inline int slot_locked(struct address_space *mapping, void **slot) -{ - unsigned long entry = xa_to_value( - radix_tree_deref_slot_protected(slot, &mapping->pages.xa_lock)); - return entry & DAX_ENTRY_LOCK; -} - /* * Mark the given slot as locked. Must be called with xa_lock held. */ @@ -202,18 +197,6 @@ static inline void *lock_slot(struct address_space *mapping, void **slot) return entry; } -/* - * Mark the given slot as unlocked. Must be called with xa_lock held. - */ -static inline void *unlock_slot(struct address_space *mapping, void **slot) -{ - unsigned long v = xa_to_value( - radix_tree_deref_slot_protected(slot, &mapping->pages.xa_lock)); - void *entry = xa_mk_value(v & ~DAX_ENTRY_LOCK); - radix_tree_replace_slot(&mapping->pages, slot, entry); - return entry; -} - /* * Lookup entry in radix tree, wait for it to become unlocked if it is * a DAX entry and return it. The caller must call @@ -237,8 +220,7 @@ static void *get_unlocked_mapping_entry(struct address_space *mapping, entry = __radix_tree_lookup(&mapping->pages, index, NULL, &slot); if (!entry || - WARN_ON_ONCE(!xa_is_value(entry)) || - !slot_locked(mapping, slot)) { + WARN_ON_ONCE(!xa_is_value(entry)) || !dax_locked(entry)) { if (slotp) *slotp = slot; return entry; @@ -257,17 +239,19 @@ static void *get_unlocked_mapping_entry(struct address_space *mapping, static void dax_unlock_mapping_entry(struct address_space *mapping, pgoff_t index) { - void *entry, **slot; + XA_STATE(xas, &mapping->pages, index); + void *entry; - xa_lock_irq(&mapping->pages); - entry = __radix_tree_lookup(&mapping->pages, index, NULL, &slot); - if (WARN_ON_ONCE(!entry || !xa_is_value(entry) || - !slot_locked(mapping, slot))) { - xa_unlock_irq(&mapping->pages); + xas_lock_irq(&xas); + entry = xas_load(&xas); + if (WARN_ON_ONCE(!entry || !xa_is_value(entry) || !dax_locked(entry))) { + xas_unlock_irq(&xas); return; } - unlock_slot(mapping, slot); - xa_unlock_irq(&mapping->pages); + entry = xa_mk_value(xa_to_value(entry) & ~DAX_ENTRY_LOCK); + xas_store(&xas, entry); + /* Safe to not call xas_pause here -- we don't touch the array after */ + xas_unlock_irq(&xas); dax_wake_mapping_entry_waiter(mapping, index, entry, false); } -- 2.15.1 ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot