From patchwork Mon Feb 15 00:15:23 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 8307301 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 653F69F38B for ; Mon, 15 Feb 2016 00:16:06 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 689932042B for ; Mon, 15 Feb 2016 00:16:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6C4952041B for ; Mon, 15 Feb 2016 00:16:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754154AbcBOAPe (ORCPT ); Sun, 14 Feb 2016 19:15:34 -0500 Received: from mail-yk0-f195.google.com ([209.85.160.195]:35319 "EHLO mail-yk0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753248AbcBOAPb (ORCPT ); Sun, 14 Feb 2016 19:15:31 -0500 Received: by mail-yk0-f195.google.com with SMTP id u9so3832420ykd.2 for ; Sun, 14 Feb 2016 16:15:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=poochiereds-net.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=HPchscEm54oR0GnQNbBkW1MLAfCI+DSdEV1jIKoj1QQ=; b=f3rod0mQIyjZwgADt3Gt8LKxQyG9eZz64L811ltfZNVDyESbqo+OmNqp2OYi08d8Ti o/gOgt5pg/EI1ImdaaMPyChgZ+Rt1vFwUlaUvB8ghjiTbh57RB3FD209ylowFDhPee2Z lmC55KIsi/KMfFYFbegK1OVYAVxRZF81j/v9AaxIOfDGpk8QBNPKqTNC6kKGMG5EoT8k /0LWbSlfuxaGwuJ7rBcQu1gZSbB5cdZv64+fGURtXNzA1ZTwXabyRtYJ5+Tx9ZkzAEvS TNdlaq3i+pZ2mRoEqDNHktgQa+MidbBSio5pFR0hHGQTxH++e2tu6P8ACmZFjU59+2ou xQSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=HPchscEm54oR0GnQNbBkW1MLAfCI+DSdEV1jIKoj1QQ=; b=ZqX0QS5iaJLp7Dx2ckM/T0o58zxzgJshyZ3C5uELJ4T1XOGgUJVRKA4wXcf7Q45Lr+ Urtil4OABE3kKFxZt3AUHP/by3GqkFdElxLvBcedwcLklW5AjEpDA18nQ3WKMf5HAThF egjC76nNws1sSW02GCLa4UQ7XQ2qlymyZYs7kZguKAM+xKIrGmgztvk63FdGAOojKpWA 7fDS/rnETIjjUyXFB2jsL8ckNWlL23mvAPWBuZJmqJnk2HJV/QV9SdHz9+HGs+NPWiX3 gkWI8rWzk1SbLRW/tg2t+UhIKMq42rtz4ncQUo2KIl/cUWWnkUjoqEGHQcK2x3KyOyiD 98Hw== X-Gm-Message-State: AG10YOT24/JcM3wE/5I0CPyQ3SVIm5gTZXkjZoTlmPJyDEbCSzwe07p6+zLaJH5fAz5I1w== X-Received: by 10.37.231.81 with SMTP id e78mr7954945ybh.57.1455495330368; Sun, 14 Feb 2016 16:15:30 -0800 (PST) Received: from tlielax.poochiereds.net ([2606:a000:1125:4074:3a60:77ff:fe93:a95d]) by smtp.googlemail.com with ESMTPSA id y4sm18820131ywa.28.2016.02.14.16.15.29 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 14 Feb 2016 16:15:29 -0800 (PST) From: Jeff Layton X-Google-Original-From: Jeff Layton To: Andrew Morton Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, "Paul E. McKenney" , Jan Kara , Eric Paris , Eryu Guan Subject: [PATCH 2/2] fsnotify: turn fsnotify reaper thread into a workqueue job Date: Sun, 14 Feb 2016 19:15:23 -0500 Message-Id: <1455495323-29605-2-git-send-email-jeff.layton@primarydata.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1455495323-29605-1-git-send-email-jeff.layton@primarydata.com> References: <1455495323-29605-1-git-send-email-jeff.layton@primarydata.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP We don't require a dedicated thread for fsnotify cleanup. Switch it over to a workqueue job instead that runs on the system_unbound_wq. In the interest of not thrashing the queued job too often when there are a lot of marks being removed, we delay the reaper job slightly when queueing it, to allow several to gather on the list. Cc: Jan Kara Cc: Eric Paris Cc: Andrew Morton Cc: Eryu Guan Signed-off-by: Jeff Layton Reviewed-by: Jan Kara --- fs/notify/mark.c | 49 ++++++++++++++++++------------------------------- 1 file changed, 18 insertions(+), 31 deletions(-) diff --git a/fs/notify/mark.c b/fs/notify/mark.c index fc0df4442f7b..7115c5d7d373 100644 --- a/fs/notify/mark.c +++ b/fs/notify/mark.c @@ -91,10 +91,14 @@ #include #include "fsnotify.h" +#define FSNOTIFY_REAPER_DELAY (1) /* 1 jiffy */ + struct srcu_struct fsnotify_mark_srcu; static DEFINE_SPINLOCK(destroy_lock); static LIST_HEAD(destroy_list); -static DECLARE_WAIT_QUEUE_HEAD(destroy_waitq); + +static void fsnotify_mark_destroy(struct work_struct *work); +static DECLARE_DELAYED_WORK(reaper_work, fsnotify_mark_destroy); void fsnotify_get_mark(struct fsnotify_mark *mark) { @@ -189,7 +193,8 @@ void fsnotify_free_mark(struct fsnotify_mark *mark) spin_lock(&destroy_lock); list_add(&mark->g_list, &destroy_list); spin_unlock(&destroy_lock); - wake_up(&destroy_waitq); + queue_delayed_work(system_unbound_wq, &reaper_work, + FSNOTIFY_REAPER_DELAY); /* * Some groups like to know that marks are being freed. This is a @@ -388,7 +393,8 @@ err: spin_lock(&destroy_lock); list_add(&mark->g_list, &destroy_list); spin_unlock(&destroy_lock); - wake_up(&destroy_waitq); + queue_delayed_work(system_unbound_wq, &reaper_work, + FSNOTIFY_REAPER_DELAY); return ret; } @@ -493,39 +499,20 @@ void fsnotify_init_mark(struct fsnotify_mark *mark, mark->free_mark = free_mark; } -static int fsnotify_mark_destroy(void *ignored) +static void fsnotify_mark_destroy(struct work_struct *work) { struct fsnotify_mark *mark, *next; struct list_head private_destroy_list; - for (;;) { - spin_lock(&destroy_lock); - /* exchange the list head */ - list_replace_init(&destroy_list, &private_destroy_list); - spin_unlock(&destroy_lock); - - synchronize_srcu(&fsnotify_mark_srcu); + spin_lock(&destroy_lock); + /* exchange the list head */ + list_replace_init(&destroy_list, &private_destroy_list); + spin_unlock(&destroy_lock); - list_for_each_entry_safe(mark, next, &private_destroy_list, g_list) { - list_del_init(&mark->g_list); - fsnotify_put_mark(mark); - } + synchronize_srcu(&fsnotify_mark_srcu); - wait_event_interruptible(destroy_waitq, !list_empty(&destroy_list)); + list_for_each_entry_safe(mark, next, &private_destroy_list, g_list) { + list_del_init(&mark->g_list); + fsnotify_put_mark(mark); } - - return 0; -} - -static int __init fsnotify_mark_init(void) -{ - struct task_struct *thread; - - thread = kthread_run(fsnotify_mark_destroy, NULL, - "fsnotify_mark"); - if (IS_ERR(thread)) - panic("unable to start fsnotify mark destruction thread."); - - return 0; } -device_initcall(fsnotify_mark_init);