Skip to contentSkip to conversation

2/5: Device-mapper: kcopyd

PATCH In review Alasdair G Kergon 5 participants 11 messages Jun 2, 2004 – Jul 3, 2004

Subsystems (2)
lore
Share & tools
lore

Alasdair G Kergon

author maintainer
#0 lore raw

PATCH 1/1 2/5: Device-mapper: kcopyd

kcopyd

drivers/md/Makefile +1 -1
@@ -3,7 +3,7 @@
 #
 
 dm-mod-objs	:= dm.o dm-table.o dm-target.o dm-linear.o dm-stripe.o \
-		   dm-ioctl.o dm-io.o
+		   dm-ioctl.o dm-io.o kcopyd.o
 raid6-objs	:= raid6main.o raid6algos.o raid6recov.o raid6tables.o \
 		   raid6int1.o raid6int2.o raid6int4.o \
 		   raid6int8.o raid6int16.o raid6int32.o \
drivers/md/dm.c +1 -0
@@ -153,6 +153,7 @@
 	xx(dm_target)
 	xx(dm_linear)
 	xx(dm_stripe)
+	xx(kcopyd)
 	xx(dm_interface)
 #undef xx
 };
drivers/md/dm.h +3 -0
@@ -177,6 +177,9 @@
 int dm_stripe_init(void);
 void dm_stripe_exit(void);
 
+int kcopyd_init(void);
+void kcopyd_exit(void);
+
 void *dm_vcalloc(unsigned long nmemb, unsigned long elem_size);
 
 #endif
drivers/md/kcopyd.c +667 -0

667 lines not on this page · raw message

drivers/md/kcopyd.h +41 -0

41 lines not on this page · raw message

#1 lore raw

drivers/md/kcopyd.c line 5

Quoted 10 lines · Alasdair G Kergon

kcopyd

drivers/md/kcopyd.c +5 -0
@@ -0,0 +1,667 @@
+/*
+ * Copyright (C) 2002 Sistina Software (UK) Limited.
+ *
+ * This file is released under the GPL.
+ */

It might be nice to have a brief comment here explaining what this is and how it is supposed to be used.

Cheers, Andreas

PS - It isn't really nice to exclude yourself from the reply-to list. --
Andreas Dilger
http://sourceforge.net/projects/ext2resize/
http://www-mddsp.enel.ucalgary.ca/People/adilger/

#2 lore raw
Quoted 14 lines · Andreas Dilger

drivers/md/kcopyd.c line 5

Quoted 10 lines · Alasdair G Kergon

kcopyd

drivers/md/kcopyd.c +5 -0
@@ -0,0 +1,667 @@
+/*
+ * Copyright (C) 2002 Sistina Software (UK) Limited.
+ *
+ * This file is released under the GPL.
+ */

It might be nice to have a brief comment here explaining what this is and how it is supposed to be used.

How's this?

We're also working on some general documentation which will go in Documentation/device-mapper and will include more detailed information about the core driver and the other sub-modules. We'll try to submit those patches in the near future.

Signature · 31 lines
Kevin Corry
[email protected]
http://evms.sourceforge.net/


--- diff/drivers/md/kcopyd.c	2004-06-02 11:44:53.000000000 -0500
+++ source/drivers/md/kcopyd.c	2004-06-02 11:44:33.000000000 -0500
@@ -2,6 +2,10 @@
  * Copyright (C) 2002 Sistina Software (UK) Limited.
  *
  * This file is released under the GPL.
+ *
+ * Kcopyd provides a simple interface for copying an area of one
+ * block-device to one or more other block-devices, with an asynchronous
+ * completion notification.
  */
 
 #include <asm/atomic.h>
--- diff/drivers/md/kcopyd.h	2004-06-02 11:44:53.000000000 -0500
+++ source/drivers/md/kcopyd.h	2004-06-02 11:44:47.000000000 -0500
@@ -2,6 +2,10 @@
  * Copyright (C) 2001 Sistina Software
  *
  * This file is released under the GPL.
+ *
+ * Kcopyd provides a simple interface for copying an area of one
+ * block-device to one or more other block-devices, with an asynchronous
+ * completion notification.
  */
 
 #ifndef DM_KCOPYD_H
#3 lore raw
Quoted 6 lines · Kevin Corry
Quoted 2 lines · Andreas Dilger

It might be nice to have a brief comment here explaining what this is and how it is supposed to be used.

How's this?

Quoted 8 lines

We're also working on some general documentation which will go in Documentation/device-mapper and will include more detailed information about the core driver and the other sub-modules. We'll try to submit those patches in the near future.

+ * Kcopyd provides a simple interface for copying an area of one
+ * block-device to one or more other block-devices, with an asynchronous
+ * completion notification.

Hi Kevin,

Once again, sorry for the lag.

Since not everybody knows the device-mapper code by heart, I'll add that kcopyd is used by the snapshot target to perform copyouts, that is, to preserve snapshotted data that would otherwise be overwritten.

Another potential use would be synching in the mirror target.

Regards,

Daniel

author maintainer
#4 lore raw
In reply to Andreas Dilger
Quoted 2 lines · Andreas Dilger

It might be nice to have a brief comment here explaining what this is and how it is supposed to be used.

A daemon for copying regions of block devices around in an efficient manner. Multiple destinations can be specified for a copy. Designed to perform well both with many small chunks or few large chunks.

Alasdair

Signature · 1 line
[email protected]
#5 lore raw
In reply to Alasdair G Kergon
Quoted 2 lines · Alasdair G Kergon

kcopyd

I dunno about the rest of the people around here but I for one do not know what kcopyd does, nor why it is being added to the kernel. The changelog was your chance to enlighten us - it is a shame nobody took the five minutes to prepare a description.

drivers/md/kcopyd.c line 121

Quoted 10 lines
drivers/md/kcopyd.c +10 -0
+static void drop_pages(struct page_list *pl)
+{
+	struct page_list *next;
+
+	while (pl) {
+		next = pl->next;
+		free_pl(pl);
+		pl = next;
+	}
+}

What is the page pool for? It is unfortunate that there is no suitable library code for managing this - it is a fairly common pattern. Maybe we could massage mempools in some manner.

Why are the pooled pages locked?

drivers/md/kcopyd.c line 225

Quoted 9 lines
drivers/md/kcopyd.c +9 -0
+static LIST_HEAD(_complete_jobs);
+static LIST_HEAD(_io_jobs);
+static LIST_HEAD(_pages_jobs);
+
+static int __init jobs_init(void)
+{
+	INIT_LIST_HEAD(&_complete_jobs);
+	INIT_LIST_HEAD(&_io_jobs);
+	INIT_LIST_HEAD(&_pages_jobs);

Do these lists need to be initialised a second time?

drivers/md/kcopyd.c line 539

Quoted 2 lines
drivers/md/kcopyd.c +2 -0
+		memcpy(sub_job, job, sizeof(*job));
+	memcpy(&job->source, from, sizeof(*from));

Structure assignments are nice. If the struct is small the compiler will do an element-by-element copy. At some compiler-determined breakpoint it will do a memcpy. And it's typesafe.

author maintainer
#6 lore raw
Quoted 1 line · Andrew Morton

What is the page pool for?

On the I/O path it can't wait for pages to be allocated without risking deadlock. (cf. pvmove in 2.4)

Quoted 1 line

Why are the pooled pages locked?

I can't see that having any effect (i.e. unnecessary).

Quoted 6 lines

drivers/md/kcopyd.c line 225

Quoted 4 lines
drivers/md/kcopyd.c +4 -0
+static int __init jobs_init(void)
+	INIT_LIST_HEAD(&_complete_jobs);
+	INIT_LIST_HEAD(&_io_jobs);
+	INIT_LIST_HEAD(&_pages_jobs);

Do these lists need to be initialised a second time?

No:-)

Alasdair

Signature · 1 line
[email protected]
#7 lore raw
In reply to Alasdair G Kergon

drivers/md/kcopyd.c line 201

Quoted 6 lines · Alasdair G Kergon

kcopyd

...

drivers/md/kcopyd.c +2 -0
+/* FIXME: this should scale with the number of pages */
+#define MIN_JOBS 512

This pins at least 2MB of RAM up-front, even if devicemapper is not in use.

Have you any plans to fix that up?

#8 lore raw
Quoted 8 lines · Andrew Morton

drivers/md/kcopyd.c line 201

Quoted 5 lines · Alasdair G Kergon

kcopyd

...

drivers/md/kcopyd.c +2 -0
+/* FIXME: this should scale with the number of pages */
+#define MIN_JOBS 512

This pins at least 2MB of RAM up-front, even if devicemapper is not in use.

Is that really the case? The MIN_JOBS value is used to initialize the mempool of kcopyd_job structures (see kcopyd.c::jobs_init()). A kcopyd_job is (according to my calculations on i386) 272 bytes. If you assume they are nicely aligned, then we'll round that up to 512 bytes. This means you should be able to fit 8 of those structures in a page, and initializing to MIN_JOBS should only use 256kB of RAM. Granted, 256kB of RAM isn't all the great either, but it's about an order of magnitude less than 2MB.

Or am I not understanding how kmem_caches and mempools work?

The jobs_init() routine is run (and hence the kmem_cache and mempool are created) when kcopyd() is loaded, so the min-value has to be set to some static number. One possibility to cut down on the up-front memory usage would be to reduce the static MIN_JOBS value, and then use mempool_resize() when the kcopyd users call kcopyd_client_[create|destroy].

Another thing we could do would be to build kcopyd as its own kernel module. Right now it's built in the same module with the core DM driver, so it's loaded any time DM is loaded, regardless of whether any DM module is using it. It should be fairly easy to split it out in its own module, which means that mempool won't be created until some other module is loaded that depends on kcopyd.

Signature · 3 lines
Kevin Corry
[email protected]
http://evms.sourceforge.net/
#9 lore raw
Quoted 5 lines · Kevin Corry
Quoted 3 lines · Andrew Morton
Quoted 2 lines · Alasdair G Kergon

kcopyd

Quoted 7 lines
Quoted 5 lines

drivers/md/kcopyd.c line 201

Quoted 3 lines

...

drivers/md/kcopyd.c +2 -0
+/* FIXME: this should scale with the number of pages */
+#define MIN_JOBS 512

This pins at least 2MB of RAM up-front, even if devicemapper is not in use.

Is that really the case?

No, sorry, I had CONFIG_DEBUG_PAGEALLOC turned on...

130k is still quite a lot. Bear in mind that this memory is never used unless the page allocation attept fails. The mempool is there to prevent OOM deadlocks and it is usually the case that a single mempool item is sufficient for that.

author maintainer
#10 lore raw
In reply to Andrew Morton
Quoted 2 lines · Andrew Morton

This pins at least 2MB of RAM up-front, even if devicemapper is not in use. Have you any plans to fix that up?

kcopyd used to create/destroy itself so it was only present while it was being used. Nobody can remember why that got changed so we'll try reimplementing it.

Alasdair

Signature · 1 line
[email protected]