public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
To: Christoph Hellwig <hch@infradead.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Andi Kleen <andi@firstfloor.org>,
	linux-kernel@vger.kernel.org, rusty@rustcorp.com.au,
	wfg@ustc.edu
Subject: Re: 2.6.22 -mm merge plans
Date: Thu, 10 May 2007 15:39:36 -0400	[thread overview]
Message-ID: <20070510193936.GA6320@Krystal> (raw)
In-Reply-To: <20070503172546.GA13392@infradead.org>

* Christoph Hellwig (hch@infradead.org) wrote:
> On Thu, May 03, 2007 at 01:16:46PM -0400, Mathieu Desnoyers wrote:
> > > kprobes does this kind of synchronization internally, so the marker
> > > wrapper should probabl aswell.
> > > 
> > 
> > The problem appears on heavily loaded systems. Doing 50
> > synchronize_sched() calls in a row can take up to a few seconds on a
> > 4-way machine. This is why I prefer to do it in the module to which
> > the callbacks belong.
> 
> We recently had a discussion on batch unreistration interface for
> kprobes.  I'm not very happy with having so different interfaces for
> different kind of probe registrations.
> 

Ok, I've had a look at the kprobes batch registration mechanisms and..
well, it does not look well suited for the markers. Adding
supplementary data structures such as linked lists of probes does not
look like a good match.

However, I agree with you that providing a similar API is good.

Therefore, here is my proposal :

The goal is to do the synchronize just after we unregister the last
probe handler provided by a given module. Since the unregistration
functions iterate on every marker present in the kernel, we can keep a
count of how many probes provided by the same module are still present.
If we see that we unregistered the last probe pointing to this module,
we issue a synchronize_sched().

It adds no data structure and keeps the same order of complexity as what
is already there, we only have to do 2 passes in the marker structures :
the first one finds the module associated with the callback and the
second disables the callbacks and keep a count of the number of
callbacks associated with the module.

Mathieu

P.S.: here is the code.


Linux Kernel Markers - Architecture Independant code Provide internal
synchronize_sched() in batch.

The goal is to do the synchronize just after we unregister the last
probe handler provided by a given module. Since the unregistration
functions iterate on every marker present in the kernel, we can keep a
count of how many probes provided by the same module are still present.
If we see that we unregistered the last probe pointing to this module,
we issue a synchronize_sched().

It adds no data structure and keeps the same order of complexity as what
is already there, we only have to do 2 passes in the marker structures : 
the first one finds the module associated with the callback and the 
second disables the callbacks and keep a count of the number of
callbacks associated with the module.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
---
 kernel/module.c |   62 ++++++++++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 52 insertions(+), 10 deletions(-)

Index: linux-2.6-lttng/kernel/module.c
===================================================================
--- linux-2.6-lttng.orig/kernel/module.c	2007-05-10 14:48:28.000000000 -0400
+++ linux-2.6-lttng/kernel/module.c	2007-05-10 15:38:27.000000000 -0400
@@ -404,8 +404,12 @@
 }
 
 /* Sets a range of markers to a disabled state : unset the enable bit and
- * provide the empty callback. */
+ * provide the empty callback.
+ * Keep a count of other markers connected to the same module as the one
+ * provided as parameter. */
 static int marker_remove_probe_range(const char *name,
+	struct module *probe_module,
+	int *ref_count,
 	const struct __mark_marker *begin,
 	const struct __mark_marker *end)
 {
@@ -413,12 +417,17 @@
 	int found = 0;
 
 	for (iter = begin; iter < end; iter++) {
-		if (strcmp(name, iter->mdata->name) == 0) {
-			marker_set_enable(iter->enable, 0,
-				iter->mdata->flags);
-			iter->mdata->call = __mark_empty_function;
-			found++;
+		if (strcmp(name, iter->mdata->name) != 0) {
+			if (probe_module)
+				if (__module_text_address(
+					(unsigned long)iter->mdata->call)
+						== probe_module)
+					(*ref_count)++;
+			continue;
 		}
+		marker_set_enable(iter->enable, 0, iter->mdata->flags);
+		iter->mdata->call = __mark_empty_function;
+		found++;
 	}
 	return found;
 }
@@ -450,6 +459,29 @@
 	return found;
 }
 
+/* Get the module to which the probe handler's text belongs.
+ * Called with module_mutex taken.
+ * Returns NULL if the probe handler is not in a module. */
+static struct module *__marker_get_probe_module(const char *name)
+{
+	struct module *mod;
+	const struct __mark_marker *iter;
+
+	list_for_each_entry(mod, &modules, list) {
+		if (mod->taints)
+			continue;
+		for (iter = mod->markers;
+			iter < mod->markers+mod->num_markers; iter++) {
+			if (strcmp(name, iter->mdata->name) != 0)
+				continue;
+			if (iter->mdata->call)
+				return __module_text_address(
+					(unsigned long)iter->mdata->call);
+		}
+	}
+	return NULL;
+}
+
 /* Calls _marker_set_probe_range for the core markers and modules markers.
  * Marker enabling/disabling use the modlist_lock to synchronise. */
 int _marker_set_probe(int flags, const char *name, const char *format,
@@ -477,23 +509,33 @@
 EXPORT_SYMBOL_GPL(_marker_set_probe);
 
 /* Calls _marker_remove_probe_range for the core markers and modules markers.
- * Marker enabling/disabling use the modlist_lock to synchronise. */
+ * Marker enabling/disabling use the modlist_lock to synchronise.
+ * ref_count is the number of markers still connected to the same module
+ * as the one in which sits the probe handler currently removed, excluding the
+ * one currently removed. If the count is 0, we issue a synchronize_sched() to
+ * make sure the module can safely unload. */
 int marker_remove_probe(const char *name)
 {
-	struct module *mod;
+	struct module *mod, *probe_module;
 	int found = 0;
+	int ref_count = 0;
 
 	mutex_lock(&module_mutex);
+	/* In what module is the probe handler ? */
+	probe_module = __marker_get_probe_module(name);
 	/* Core kernel markers */
-	found += marker_remove_probe_range(name,
+	found += marker_remove_probe_range(name, probe_module, &ref_count,
 			__start___markers, __stop___markers);
 	/* Markers in modules. */
 	list_for_each_entry(mod, &modules, list) {
 		if (!mod->taints)
-			found += marker_remove_probe_range(name,
+			found += marker_remove_probe_range(name, probe_module,
+				&ref_count,
 				mod->markers, mod->markers+mod->num_markers);
 	}
 	mutex_unlock(&module_mutex);
+	if (!ref_count)
+		synchronize_sched();
 	return found;
 }
 EXPORT_SYMBOL_GPL(marker_remove_probe);

-- 
Mathieu Desnoyers
Computer Engineering Ph.D. Student, Ecole Polytechnique de Montreal
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68

  reply	other threads:[~2007-05-10 19:39 UTC|newest]

Thread overview: 233+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-04-30 23:20 2.6.22 -mm merge plans Andrew Morton
2007-04-30 23:48 ` to something appropriate (was Re: 2.6.22 -mm merge plans) Jeff Garzik
2007-05-01  0:07   ` Dave Jones
2007-05-01  0:09   ` Andrew Morton
2007-05-01  0:24     ` Jeff Garzik
2007-05-01  0:40       ` [stable] " Chris Wright
2007-05-01  0:45         ` Jeff Garzik
2007-05-01  4:58           ` Greg KH
2007-05-01 16:14             ` Chuck Ebbert
2007-05-01 16:40               ` Alan Cox
2007-05-01 23:34                 ` Greg KH
2007-05-02  0:52                   ` Chris Wright
2007-05-02 14:10                     ` Chuck Ebbert
2007-05-01  9:49   ` Alan Cox
2007-04-30 23:59 ` 2.6.22 -mm merge plans Bill Irwin
2007-05-01  0:09 ` nfsd/md patches " Neil Brown
2007-05-01  9:08   ` Christoph Hellwig
2007-05-01  9:15     ` Andrew Morton
2007-05-01  9:21       ` Christoph Hellwig
2007-05-01  9:52     ` Neil Brown
2007-05-01 10:15       ` Christoph Hellwig
2007-05-01 14:34         ` Trond Myklebust
2007-05-01  0:54 ` MADV_FREE functionality Rik van Riel
2007-05-01  1:18   ` Andrew Morton
2007-05-01  1:23     ` Rik van Riel
2007-05-01  7:13     ` Jakub Jelinek
2007-05-01  1:23   ` Ulrich Drepper
2007-05-01  1:39 ` 2.6.22 -mm merge plans Stefan Richter
2007-05-01  2:30 ` 2.6.22 -mm merge plans (RE: input) Dmitry Torokhov
2007-05-01  8:14   ` Jiri Slaby
2007-05-01 12:05     ` Dmitry Torokhov
2007-05-01  8:11 ` 2.6.22 -mm merge plans -- pfn_valid_within Andy Whitcroft
2007-05-01  8:19   ` Andrew Morton
2007-05-01  8:42 ` "partical" kthread conversion Christoph Hellwig
2007-05-01  8:51   ` Andrew Morton
2007-05-02 14:01     ` Dean Nelson
2007-05-02 14:45       ` Eric W. Biederman
2007-05-02 15:37         ` Dean Nelson
2007-05-02 15:49           ` Eric W. Biederman
2007-05-02 19:33         ` Andrew Morton
2007-05-02 20:38           ` Eric W. Biederman
2007-05-01  8:44 ` 2.6.22 -mm merge plans -- vm bugfixes Nick Piggin
2007-05-01  8:54   ` Andrew Morton
2007-05-01 19:31   ` Hugh Dickins
2007-05-02  3:08     ` Nick Piggin
2007-05-02  9:15       ` Nick Piggin
2007-05-02 14:00       ` Hugh Dickins
2007-05-03  1:32         ` Nick Piggin
2007-05-03 10:37           ` Christoph Hellwig
2007-05-03 12:56             ` Nick Piggin
2007-05-04  9:23               ` Nick Piggin
2007-05-04  9:43                 ` Nick Piggin
2007-05-08  3:03                 ` Benjamin Herrenschmidt
2007-05-03 12:24           ` Hugh Dickins
2007-05-03 12:43             ` Nick Piggin
2007-05-03 12:58               ` Hugh Dickins
2007-05-03 13:08                 ` Nick Piggin
2007-05-03 16:52           ` Andrew Morton
2007-05-04  4:16             ` Nick Piggin
2007-05-09 12:34         ` Nick Piggin
2007-05-09 14:28           ` Hugh Dickins
2007-05-09 14:45             ` Nick Piggin
2007-05-09 15:38               ` Hugh Dickins
2007-05-09 22:24                 ` Nick Piggin
2007-05-01  8:46 ` pcmcia ioctl removal Christoph Hellwig
2007-05-01  8:56   ` Russell King
2007-05-01  8:57   ` Willy Tarreau
2007-05-01  9:08     ` Andrew Morton
2007-05-01 14:46       ` Adrian Bunk
2007-05-01  9:16   ` Robert P. J. Day
2007-05-01  9:44     ` Willy Tarreau
2007-05-01 10:16       ` Robert P. J. Day
2007-05-01 10:26       ` Gabriel C
2007-05-01 10:52         ` Willy Tarreau
2007-05-01 10:12     ` Jan Engelhardt
2007-05-01 11:00       ` Willy Tarreau
2007-05-01 12:06         ` Konstantin Münning
2007-05-01 13:56         ` Rogan Dawes
2007-05-01 19:10       ` Russell King
2007-05-01 20:41         ` Jan Engelhardt
2007-05-09 12:54   ` Pavel Machek
2007-05-09 13:00     ` Robert P. J. Day
2007-05-09 13:03     ` Adrian Bunk
2007-05-09 19:11       ` Romano Giannetti
2007-05-10 12:40         ` Adrian Bunk
2007-05-01  8:48 ` pci hotplug patches Christoph Hellwig
2007-05-02  3:57   ` Greg KH
2007-05-13 20:59     ` Christoph Hellwig
2007-05-14 11:48       ` Greg KH
2007-05-01  8:54 ` cache-pipe-buf-page-address-for-non-highmem-arch.patch Christoph Hellwig
     [not found]   ` <20070501020441.10b6a003.akpm@linux-foundation.org>
2007-05-03  3:48     ` cache-pipe-buf-page-address-for-non-highmem-arch.patch Ken Chen
2007-05-01  8:55 ` consolidate-generic_writepages-and-mpage_writepages.patch Christoph Hellwig
2007-05-01  9:17 ` 2.6.22 -mm merge plans Pekka Enberg
2007-05-01  9:24   ` Christoph Hellwig
2007-05-01  9:37   ` Peter Zijlstra
2007-05-01 12:19   ` Andi Kleen
2007-05-01 17:12     ` Pekka Enberg
2007-05-01 10:16 ` fragmentation avoidance " Mel Gorman
2007-05-01 13:02   ` 2.6.22 -mm merge plans -- lumpy reclaim Andy Whitcroft
2007-05-01 18:03     ` Peter Zijlstra
2007-05-01 19:00     ` Andrew Morton
2007-05-01 14:54   ` fragmentation avoidance Re: 2.6.22 -mm merge plans Christoph Lameter
2007-05-01 19:00     ` Mel Gorman
2007-05-01 18:57   ` Andrew Morton
2007-05-07 13:07   ` Yasunori Goto
2007-05-01 12:17 ` Andi Kleen
2007-05-01 22:08   ` Mathieu Desnoyers
2007-05-02 10:44     ` Andi Kleen
2007-05-02 16:37       ` Frank Ch. Eigler
2007-05-02 16:47       ` Andrew Morton
2007-05-02 17:29         ` Christoph Hellwig
2007-05-02 20:36           ` Mathieu Desnoyers
2007-05-02 20:53             ` Andrew Morton
2007-05-02 23:11               ` Mathieu Desnoyers
2007-05-02 23:21                 ` Andrew Morton
2007-05-03 15:04                   ` Mathieu Desnoyers
2007-05-03 15:12                     ` Christoph Hellwig
2007-05-03 17:16                       ` Mathieu Desnoyers
2007-05-03 17:25                         ` Christoph Hellwig
2007-05-10 19:39                           ` Mathieu Desnoyers [this message]
2007-05-13 21:04                             ` Christoph Hellwig
2007-05-03  8:06                 ` Christoph Hellwig
2007-05-03 14:43                   ` Mathieu Desnoyers
2007-05-03 10:31                 ` Andi Kleen
2007-05-03 14:49                   ` Mathieu Desnoyers
2007-05-03  8:09               ` Christoph Hellwig
2007-05-03  8:08             ` Christoph Hellwig
2007-05-02 17:49         ` Andi Kleen
2007-05-02 21:46           ` Tilman Schmidt
2007-05-03 10:12             ` Andi Kleen
2007-05-02 17:19       ` Mathieu Desnoyers
2007-05-02  0:31   ` Rusty Russell
2007-05-02 10:30     ` Andi Kleen
2007-05-01 13:06 ` file capabilities and security_task_wait failure " Stephen Smalley
2007-05-01 14:31 ` 2.6.22 -mm merge plans: mm-more-rmap-checking Hugh Dickins
2007-05-02  1:42   ` Nick Piggin
2007-05-02 13:17     ` Hugh Dickins
2007-05-03  0:18       ` Nick Piggin
2007-05-01 16:56 ` 2.6.22 -mm merge plans Zan Lynx
2007-05-01 17:06 ` 2.6.22 -mm merge plans: mm-detach_vmas_to_be_unmapped-fix Hugh Dickins
2007-05-01 18:10 ` 2.6.22 -mm merge plans: slub Hugh Dickins
2007-05-01 19:25   ` Christoph Lameter
2007-05-01 19:55   ` Andrew Morton
2007-05-01 20:19     ` Hugh Dickins
2007-05-01 20:36       ` Andrew Morton
2007-05-01 20:46         ` Christoph Lameter
2007-05-01 21:09           ` Andrew Morton
2007-05-02 12:54         ` Hugh Dickins
2007-05-02 17:03           ` Christoph Lameter
2007-05-02 19:11             ` Andrew Morton
2007-05-02 19:42               ` Christoph Lameter
2007-05-02 19:54                 ` Sam Ravnborg
2007-05-02 20:14                   ` Christoph Lameter
2007-05-02 18:52           ` Siddha, Suresh B
2007-05-02 18:58             ` Christoph Lameter
2007-05-01 21:08       ` Christoph Lameter
2007-05-02 12:45         ` Hugh Dickins
2007-05-02 17:01           ` Christoph Lameter
2007-05-02 18:08             ` Hugh Dickins
2007-05-02 18:28               ` Christoph Lameter
2007-05-02 18:42                 ` Andrew Morton
2007-05-02 18:53                   ` Christoph Lameter
2007-05-02 17:25           ` Christoph Lameter
2007-05-02 18:36             ` Hugh Dickins
2007-05-02 18:39               ` Christoph Lameter
2007-05-02 18:57                 ` Andrew Morton
2007-05-02 19:01                   ` Christoph Lameter
2007-05-02 19:18                     ` Pekka Enberg
2007-05-02 19:34                       ` Christoph Lameter
2007-05-02 19:43                       ` Christoph Lameter
2007-05-03  8:15             ` Andrew Morton
2007-05-03  8:27               ` William Lee Irwin III
2007-05-03 16:30                 ` Christoph Lameter
2007-05-03  8:46               ` Hugh Dickins
2007-05-03  8:57                 ` Andrew Morton
2007-05-03  9:15                   ` Hugh Dickins
2007-05-03 21:04                     ` 2.6.22 -mm merge plans: slub on PowerPC Hugh Dickins
2007-05-03 21:15                       ` Christoph Lameter
2007-05-03 22:41                         ` Hugh Dickins
2007-05-04  0:25                       ` Benjamin Herrenschmidt
2007-05-04  0:54                         ` Christoph Lameter
2007-05-03 16:45                   ` 2.6.22 -mm merge plans: slub Christoph Lameter
2007-05-03 15:54 ` swap-prefetch: 2.6.22 -mm merge plans Ingo Molnar
2007-05-03 16:15   ` Michal Piotrowski
2007-05-03 16:23     ` Michal Piotrowski
2007-05-03 22:14   ` Con Kolivas
2007-05-04  7:34   ` Nick Piggin
2007-05-04  8:52     ` Ingo Molnar
2007-05-04  9:09       ` Nick Piggin
2007-05-04 12:10       ` Con Kolivas
2007-05-05  8:42         ` Con Kolivas
2007-05-06 10:13           ` [ck] " Antonino Ingargiola
2007-05-06 18:22           ` Jory A. Pratt
2007-05-09 23:28           ` Con Kolivas
2007-05-10  0:05             ` Nick Piggin
2007-05-10  1:34               ` Con Kolivas
2007-05-10  1:56                 ` Nick Piggin
2007-05-10  3:48                   ` Ray Lee
2007-05-10  3:56                     ` Nick Piggin
2007-05-10  5:52                       ` Ray Lee
2007-05-10  7:04                         ` Nick Piggin
2007-05-10  7:20                           ` William Lee Irwin III
2007-05-10 12:34                           ` Ray Lee
2007-05-12  4:46                           ` [PATCH] mm: swap prefetch improvements Con Kolivas
2007-05-12  5:03                             ` Paul Jackson
2007-05-12  5:15                               ` Con Kolivas
2007-05-12  5:51                                 ` Paul Jackson
2007-05-12  7:28                                   ` Con Kolivas
2007-05-12  8:14                                     ` Paul Jackson
2007-05-12  8:21                                       ` Con Kolivas
2007-05-12  8:37                                         ` Paul Jackson
2007-05-12  8:57                                           ` [PATCH respin] " Con Kolivas
2007-05-21 10:03                             ` [PATCH] " Ingo Molnar
2007-05-21 13:44                               ` Con Kolivas
2007-05-21 16:00                                 ` Ingo Molnar
2007-05-22 10:15                                   ` Antonino Ingargiola
2007-05-22 10:20                                     ` Con Kolivas
2007-05-22 10:25                                       ` Ingo Molnar
2007-05-22 10:37                                         ` Con Kolivas
2007-05-22 10:46                                           ` Ingo Molnar
2007-05-22 10:54                                             ` Con Kolivas
2007-05-22 10:57                                               ` Ingo Molnar
2007-05-22 11:04                                                 ` Con Kolivas
     [not found]                                                   ` <20070522111104.GA14950@elte.hu>
2007-05-22 11:12                                                     ` Ingo Molnar
2007-05-22 20:18                                             ` [ck] " Michael Chang
2007-05-22 20:31                                               ` Ingo Molnar
2007-05-22 20:42                                           ` Ash Milsted
2007-05-22 22:50                                             ` Con Kolivas
2007-05-23  7:57                                               ` Ash Milsted
2007-05-10  3:58                     ` swap-prefetch: 2.6.22 -mm merge plans Con Kolivas
2007-05-07 14:28         ` Bill Davidsen
2007-05-07 14:18       ` Bill Davidsen
2007-05-07 17:47 ` Josef Sipek

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=20070510193936.GA6320@Krystal \
    --to=mathieu.desnoyers@polymtl.ca \
    --cc=akpm@linux-foundation.org \
    --cc=andi@firstfloor.org \
    --cc=hch@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rusty@rustcorp.com.au \
    --cc=wfg@ustc.edu \
    /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