From patchwork Wed Jan 17 20:21:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Matthew Wilcox (Oracle)" X-Patchwork-Id: 10170895 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 2243560386 for ; Wed, 17 Jan 2018 20:28:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1413120163 for ; Wed, 17 Jan 2018 20:28:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0849320602; Wed, 17 Jan 2018 20:28:54 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 907BC20163 for ; Wed, 17 Jan 2018 20:28:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754013AbeAQU1s (ORCPT ); Wed, 17 Jan 2018 15:27:48 -0500 Received: from bombadil.infradead.org ([65.50.211.133]:57673 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754009AbeAQUXF (ORCPT ); Wed, 17 Jan 2018 15:23:05 -0500 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=nDbSNQtY3I32d6R0AQMGtIlXjATZUM/TBTgCd5AKpiA=; b=MN4v26tzHiZB6R+Hk3zmusuUY +pu9Srd/sL/BJ9P7ObG+bnphV3pKEOIN5kdRFQlqAMn6h8C4nraM0Y9PCd84Co2v/5IERdFERb+S3 a7dgBBcUZleKdvb3DgUQIePAyqtpKqAiz2S1jgRnnWJJbJXlNc1z/9p3paUVBPJQs4bDnTFTOjBpD hN4nQ+zEPxMchcDMWHSobhw92MeC9ynbdhCLVaAE3PRRMQ5N02pdpG5be+cCnAq4sKrZcOKCh3hUZ Gxde4v9fSJE3ufVQErRwh1nKfNHo5TkBV0OqpqArJ7/eQLnPaJMGAkxeyarYWWZ37kQUD0YSBIiZk zRa7DnlrA==; Received: from willy by bombadil.infradead.org with local (Exim 4.89 #1 (Red Hat Linux)) id 1ebuEi-0006KT-5U; Wed, 17 Jan 2018 20:23:04 +0000 From: Matthew Wilcox To: linux-kernel@vger.kernel.org Cc: Matthew Wilcox , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-nilfs@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-xfs@vger.kernel.org, linux-usb@vger.kernel.org, Bjorn Andersson , Stefano Stabellini , iommu@lists.linux-foundation.org, linux-remoteproc@vger.kernel.org, linux-s390@vger.kernel.org, intel-gfx@lists.freedesktop.org, cgroups@vger.kernel.org, linux-sh@vger.kernel.org, David Howells Subject: [PATCH v6 92/99] f2fs: Convert pids radix tree to XArray Date: Wed, 17 Jan 2018 12:21:56 -0800 Message-Id: <20180117202203.19756-93-willy@infradead.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180117202203.19756-1-willy@infradead.org> References: <20180117202203.19756-1-willy@infradead.org> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Matthew Wilcox The XArray API works out rather well for this user. Signed-off-by: Matthew Wilcox --- fs/f2fs/super.c | 2 -- fs/f2fs/trace.c | 60 ++++----------------------------------------------------- fs/f2fs/trace.h | 2 -- 3 files changed, 4 insertions(+), 60 deletions(-) diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 708155d9c2e4..d608edffe69e 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -2831,8 +2831,6 @@ static int __init init_f2fs_fs(void) { int err; - f2fs_build_trace_ios(); - err = init_inodecache(); if (err) goto fail; diff --git a/fs/f2fs/trace.c b/fs/f2fs/trace.c index bccbbf2616d2..f316a42c547f 100644 --- a/fs/f2fs/trace.c +++ b/fs/f2fs/trace.c @@ -16,8 +16,7 @@ #include "f2fs.h" #include "trace.h" -static RADIX_TREE(pids, GFP_ATOMIC); -static spinlock_t pids_lock; +static DEFINE_XARRAY(pids); static struct last_io_info last_io; static inline void __print_last_io(void) @@ -57,28 +56,13 @@ void f2fs_trace_pid(struct page *page) { struct inode *inode = page->mapping->host; pid_t pid = task_pid_nr(current); - void *p; set_page_private(page, (unsigned long)pid); - if (radix_tree_preload(GFP_NOFS)) - return; - - spin_lock(&pids_lock); - p = radix_tree_lookup(&pids, pid); - if (p == current) - goto out; - if (p) - radix_tree_delete(&pids, pid); - - f2fs_radix_tree_insert(&pids, pid, current); - - trace_printk("%3x:%3x %4x %-16s\n", + if (xa_store(&pids, pid, current, GFP_NOFS) != current) + trace_printk("%3x:%3x %4x %-16s\n", MAJOR(inode->i_sb->s_dev), MINOR(inode->i_sb->s_dev), pid, current->comm); -out: - spin_unlock(&pids_lock); - radix_tree_preload_end(); } void f2fs_trace_ios(struct f2fs_io_info *fio, int flush) @@ -120,43 +104,7 @@ void f2fs_trace_ios(struct f2fs_io_info *fio, int flush) return; } -void f2fs_build_trace_ios(void) -{ - spin_lock_init(&pids_lock); -} - -#define PIDVEC_SIZE 128 -static unsigned int gang_lookup_pids(pid_t *results, unsigned long first_index, - unsigned int max_items) -{ - struct radix_tree_iter iter; - void **slot; - unsigned int ret = 0; - - if (unlikely(!max_items)) - return 0; - - radix_tree_for_each_slot(slot, &pids, &iter, first_index) { - results[ret] = iter.index; - if (++ret == max_items) - break; - } - return ret; -} - void f2fs_destroy_trace_ios(void) { - pid_t pid[PIDVEC_SIZE]; - pid_t next_pid = 0; - unsigned int found; - - spin_lock(&pids_lock); - while ((found = gang_lookup_pids(pid, next_pid, PIDVEC_SIZE))) { - unsigned idx; - - next_pid = pid[found - 1] + 1; - for (idx = 0; idx < found; idx++) - radix_tree_delete(&pids, pid[idx]); - } - spin_unlock(&pids_lock); + xa_destroy(&pids); } diff --git a/fs/f2fs/trace.h b/fs/f2fs/trace.h index 67db24ac1e85..157e4564e48b 100644 --- a/fs/f2fs/trace.h +++ b/fs/f2fs/trace.h @@ -34,12 +34,10 @@ struct last_io_info { extern void f2fs_trace_pid(struct page *); extern void f2fs_trace_ios(struct f2fs_io_info *, int); -extern void f2fs_build_trace_ios(void); extern void f2fs_destroy_trace_ios(void); #else #define f2fs_trace_pid(p) #define f2fs_trace_ios(i, n) -#define f2fs_build_trace_ios() #define f2fs_destroy_trace_ios() #endif