mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@suse.de>
To: linux-kernel@vger.kernel.org
Cc: Matthew Wilcox <matthew@wil.cx>,
	Matthew Wilcox <willy@linux.intel.com>,
	Greg Kroah-Hartman <gregkh@suse.de>
Subject: [PATCH 04/60] driver core: Remove completion from struct klist_node
Date: Tue,  6 Jan 2009 14:11:23 -0800	[thread overview]
Message-ID: <1231279939-32728-4-git-send-email-gregkh@suse.de> (raw)
In-Reply-To: <20090106221123.GA32689@kroah.com>

From: Matthew Wilcox <matthew@wil.cx>

Removing the completion from klist_node reduces its size from 64 bytes
to 28 on x86-64.  To maintain the semantics of klist_remove(), we add
a single list of klist nodes which are pending deletion and scan them.

Signed-off-by: Matthew Wilcox <willy@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 include/linux/klist.h |    2 --
 lib/klist.c           |   43 ++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 40 insertions(+), 5 deletions(-)

diff --git a/include/linux/klist.h b/include/linux/klist.h
index 8ea98db..d5a27af 100644
--- a/include/linux/klist.h
+++ b/include/linux/klist.h
@@ -13,7 +13,6 @@
 #define _LINUX_KLIST_H
 
 #include <linux/spinlock.h>
-#include <linux/completion.h>
 #include <linux/kref.h>
 #include <linux/list.h>
 
@@ -41,7 +40,6 @@ struct klist_node {
 	void			*n_klist;	/* never access directly */
 	struct list_head	n_node;
 	struct kref		n_ref;
-	struct completion	n_removed;
 };
 
 extern void klist_add_tail(struct klist_node *n, struct klist *k);
diff --git a/lib/klist.c b/lib/klist.c
index bbdd301..573d606 100644
--- a/lib/klist.c
+++ b/lib/klist.c
@@ -36,6 +36,7 @@
 
 #include <linux/klist.h>
 #include <linux/module.h>
+#include <linux/sched.h>
 
 /*
  * Use the lowest bit of n_klist to mark deleted nodes and exclude
@@ -108,7 +109,6 @@ static void add_tail(struct klist *k, struct klist_node *n)
 static void klist_node_init(struct klist *k, struct klist_node *n)
 {
 	INIT_LIST_HEAD(&n->n_node);
-	init_completion(&n->n_removed);
 	kref_init(&n->n_ref);
 	knode_set_klist(n, k);
 	if (k->get)
@@ -171,13 +171,34 @@ void klist_add_before(struct klist_node *n, struct klist_node *pos)
 }
 EXPORT_SYMBOL_GPL(klist_add_before);
 
+struct klist_waiter {
+	struct list_head list;
+	struct klist_node *node;
+	struct task_struct *process;
+	int woken;
+};
+
+static DEFINE_SPINLOCK(klist_remove_lock);
+static LIST_HEAD(klist_remove_waiters);
+
 static void klist_release(struct kref *kref)
 {
+	struct klist_waiter *waiter, *tmp;
 	struct klist_node *n = container_of(kref, struct klist_node, n_ref);
 
 	WARN_ON(!knode_dead(n));
 	list_del(&n->n_node);
-	complete(&n->n_removed);
+	spin_lock(&klist_remove_lock);
+	list_for_each_entry_safe(waiter, tmp, &klist_remove_waiters, list) {
+		if (waiter->node != n)
+			continue;
+
+		waiter->woken = 1;
+		mb();
+		wake_up_process(waiter->process);
+		list_del(&waiter->list);
+	}
+	spin_unlock(&klist_remove_lock);
 	knode_set_klist(n, NULL);
 }
 
@@ -217,8 +238,24 @@ EXPORT_SYMBOL_GPL(klist_del);
  */
 void klist_remove(struct klist_node *n)
 {
+	struct klist_waiter waiter;
+
+	waiter.node = n;
+	waiter.process = current;
+	waiter.woken = 0;
+	spin_lock(&klist_remove_lock);
+	list_add(&waiter.list, &klist_remove_waiters);
+	spin_unlock(&klist_remove_lock);
+
 	klist_del(n);
-	wait_for_completion(&n->n_removed);
+
+	for (;;) {
+		set_current_state(TASK_UNINTERRUPTIBLE);
+		if (waiter.woken)
+			break;
+		schedule();
+	}
+	__set_current_state(TASK_RUNNING);
 }
 EXPORT_SYMBOL_GPL(klist_remove);
 
-- 
1.6.0.4


  parent reply	other threads:[~2009-01-06 22:14 UTC|newest]

Thread overview: 69+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-06 22:11 [GIT PATCH] driver core patches for your 2.6-git tree Greg KH
2009-01-06 22:11 ` [PATCH 01/60] PM: Simplify the new suspend/hibernation framework for devices Greg Kroah-Hartman
2009-01-06 22:11 ` [PATCH 02/60] Fix misspellings in pm.h macros Greg Kroah-Hartman
2009-01-06 22:11 ` [PATCH 03/60] driver core: Rearrange struct device for better packing Greg Kroah-Hartman
2009-01-06 22:11 ` Greg Kroah-Hartman [this message]
2009-01-06 22:11 ` [PATCH 05/60] driver core: struct device - replace bus_id with dev_name(), dev_set_name() Greg Kroah-Hartman
2009-01-06 22:11 ` [PATCH 06/60] sysfs: clarify SYSFS_DEPRECATED help text Greg Kroah-Hartman
2009-01-07  9:21   ` Mikael Pettersson
2009-01-07 19:38     ` Greg KH
2009-01-06 22:11 ` [PATCH 07/60] uevent: don't pass envp_ext[] as format string in kobject_uevent_env() Greg Kroah-Hartman
2009-01-06 22:11 ` [PATCH 08/60] kobject: return the result of uevent sending by netlink Greg Kroah-Hartman
2009-01-06 22:11 ` [PATCH 09/60] kernel/ksysfs.c:fix dependence on CONFIG_NET Greg Kroah-Hartman
2009-01-06 22:11 ` [PATCH 10/60] PCI: Rework default handling of suspend and resume Greg Kroah-Hartman
2009-01-06 22:11 ` [PATCH 11/60] kobject: Make Documentation/kobject.txt a little more coherent Greg Kroah-Hartman
2009-01-06 22:11 ` [PATCH 12/60] dynamic_printk: reduce one level of indentation Greg Kroah-Hartman
2009-01-06 22:11 ` [PATCH 13/60] driver core: create a private portion of struct device Greg Kroah-Hartman
2009-01-06 22:11 ` [PATCH 14/60] driver core: move klist_children into private structure Greg Kroah-Hartman
2009-01-06 22:11 ` [PATCH 15/60] driver core: move knode_driver " Greg Kroah-Hartman
2009-01-06 22:11 ` [PATCH 16/60] driver core: move knode_bus " Greg Kroah-Hartman
2009-01-06 22:11 ` [PATCH 17/60] Make DEBUG take precedence over DYNAMIC_PRINTK_DEBUG Greg Kroah-Hartman
2009-01-06 22:11 ` [PATCH 18/60] Driver core: move the bus notifier call points Greg Kroah-Hartman
2009-01-06 22:11 ` [PATCH 19/60] driver core:fix duplicate removing driver link in __device_release_driver Greg Kroah-Hartman
2009-01-06 22:11 ` [PATCH 20/60] driver core: add root_device_register() Greg Kroah-Hartman
2009-01-06 22:11 ` [PATCH 21/60] virtio: do not statically allocate root device Greg Kroah-Hartman
2009-01-06 22:11 ` [PATCH 22/60] lguest: " Greg Kroah-Hartman
2009-01-06 22:11 ` [PATCH 23/60] s390: remove s390_root_dev_*() Greg Kroah-Hartman
2009-01-06 22:11 ` [PATCH 24/60] xen: struct device - replace bus_id with dev_name(), dev_set_name() Greg Kroah-Hartman
2009-01-06 22:11 ` [PATCH 25/60] w1: " Greg Kroah-Hartman
2009-01-06 22:11 ` [PATCH 26/60] video: " Greg Kroah-Hartman
2009-01-06 22:11 ` [PATCH 27/60] tifm: " Greg Kroah-Hartman
2009-01-06 22:11 ` [PATCH 28/60] thermal: " Greg Kroah-Hartman
2009-01-06 22:11 ` [PATCH 29/60] swiotlb: " Greg Kroah-Hartman
2009-01-06 22:11 ` [PATCH 30/60] spi: " Greg Kroah-Hartman
2009-01-06 22:11 ` [PATCH 31/60] SGI: " Greg Kroah-Hartman
2009-01-06 23:03   ` Jack Steiner
2009-01-06 22:11 ` [PATCH 32/60] serial: " Greg Kroah-Hartman
2009-01-06 22:11 ` [PATCH 33/60] power-supply: " Greg Kroah-Hartman
2009-01-06 22:11 ` [PATCH 34/60] pnp: " Greg Kroah-Hartman
2009-01-06 22:11 ` [PATCH 35/60] mwave: " Greg Kroah-Hartman
2009-01-06 22:11 ` [PATCH 36/60] mtd: " Greg Kroah-Hartman
2009-01-06 22:11 ` [PATCH 37/60] mips: " Greg Kroah-Hartman
2009-01-06 22:11 ` [PATCH 38/60] memstick: " Greg Kroah-Hartman
2009-01-06 22:11 ` [PATCH 39/60] macintosh: " Greg Kroah-Hartman
2009-01-06 22:11 ` [PATCH 40/60] pm: " Greg Kroah-Hartman
2009-01-06 22:12 ` [PATCH 41/60] ISDN: " Greg Kroah-Hartman
2009-01-06 22:12 ` [PATCH 42/60] infiniband: " Greg Kroah-Hartman
2009-01-06 22:12 ` [PATCH 43/60] i7300_idle: " Greg Kroah-Hartman
2009-01-06 22:12 ` [PATCH 44/60] IA64: " Greg Kroah-Hartman
2009-01-06 22:12 ` [PATCH 45/60] i2o: " Greg Kroah-Hartman
2009-01-06 22:12 ` [PATCH 46/60] hwmon: " Greg Kroah-Hartman
2009-01-06 22:12 ` [PATCH 47/60] gpu: " Greg Kroah-Hartman
2009-01-06 22:12 ` [PATCH 48/60] gpio: " Greg Kroah-Hartman
2009-01-06 22:12 ` [PATCH 49/60] gadget: " Greg Kroah-Hartman
2009-01-06 22:12 ` [PATCH 50/60] dmi: " Greg Kroah-Hartman
2009-01-06 22:12 ` [PATCH 51/60] chris: " Greg Kroah-Hartman
2009-01-06 22:12 ` [PATCH 52/60] block: " Greg Kroah-Hartman
2009-01-06 22:12 ` [PATCH 53/60] avr: " Greg Kroah-Hartman
2009-01-07  8:54   ` Haavard Skinnemoen
2009-01-07 19:36     ` Greg KH
2009-01-06 22:12 ` [PATCH 54/60] libata: " Greg Kroah-Hartman
2009-01-06 22:12 ` [PATCH 55/60] arm: " Greg Kroah-Hartman
2009-01-06 22:12 ` [PATCH 56/60] UIO: use pci_ioremap_bar() in drivers/uio Greg Kroah-Hartman
2009-01-06 22:12 ` [PATCH 57/60] UIO: uio_pdrv_genirq: allow custom irq_flags Greg Kroah-Hartman
2009-01-06 22:12 ` [PATCH 58/60] UIO: Pass information about ioports to userspace (V2) Greg Kroah-Hartman
2009-01-06 22:12 ` [PATCH 59/60] UIO: Documentation for UIO ioport info handling Greg Kroah-Hartman
2009-01-06 22:12 ` [PATCH 60/60] uio: make uio_info's name and version const Greg Kroah-Hartman
2009-01-06 23:23 ` [GIT PATCH] driver core patches for your 2.6-git tree Hans J. Koch
2009-01-07  0:36   ` Greg KH
2009-01-07 11:33 ` [PATCH 41/60] ISDN: struct device - replace bus_id with dev_name(), dev_set_name() Karsten Keil

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1231279939-32728-4-git-send-email-gregkh@suse.de \
    --to=gregkh@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matthew@wil.cx \
    --cc=willy@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome