Skip to contentSkip to conversation

Make the mq policy an alias for smq

PATCH In review Joe Thornber 5 participants 10 messages Feb 10, 2016 – Feb 27, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Make the mq policy an alias for smq

smq seems to be performing better than the old mq policy in all situations, as well as using a quarter of the memory.

This patch makes 'mq' and alias for 'smq' when choosing a cache policy. The tunables that were present for the old mq are faked, and have no effect. mq should be considered deprecated now.

---
 drivers/md/Kconfig               |   11 +-
 drivers/md/Makefile              |    2 -
 drivers/md/dm-cache-policy-mq.c  | 1472 --------------------------------------
 drivers/md/dm-cache-policy-smq.c |   93 ++-
 drivers/md/dm-cache-policy.c     |    6 +-
 5 files changed, 97 insertions(+), 1487 deletions(-)
 delete mode 100644 drivers/md/dm-cache-policy-mq.c
drivers/md/Kconfig +4 -7
index b871928..9ea570b 100644
@@ -295,14 +295,11 @@ config DM_CACHE
          cleaned etc.  It supports writeback and writethrough modes.
 
 config DM_CACHE_MQ
-       tristate "MQ Cache Policy (EXPERIMENTAL)"
-       depends on DM_CACHE
-       default y
+       tristate "MQ Cache Policy (DEPRECATED)"
+       depends on DM_CACHE_SMQ
+       default n
        ---help---
-         A cache policy that uses a multiqueue ordered by recent hit
-         count to select which blocks should be promoted and demoted.
-         This is meant to be a general purpose policy.  It prioritises
-         reads over writes.
+         This policy is now an alias for the SMQ policy.
 
 config DM_CACHE_SMQ
        tristate "Stochastic MQ Cache Policy (EXPERIMENTAL)"
drivers/md/Makefile +0 -2
index 4ac5360..45d04ca 100644
@@ -12,7 +12,6 @@ dm-log-userspace-y \
 		+= dm-log-userspace-base.o dm-log-userspace-transfer.o
 dm-thin-pool-y	+= dm-thin.o dm-thin-metadata.o
 dm-cache-y	+= dm-cache-target.o dm-cache-metadata.o dm-cache-policy.o
-dm-cache-mq-y   += dm-cache-policy-mq.o
 dm-cache-smq-y   += dm-cache-policy-smq.o
 dm-cache-cleaner-y += dm-cache-policy-cleaner.o
 dm-era-y	+= dm-era-target.o
@@ -54,7 +53,6 @@ obj-$(CONFIG_DM_RAID)	+= dm-raid.o
 obj-$(CONFIG_DM_THIN_PROVISIONING)	+= dm-thin-pool.o
 obj-$(CONFIG_DM_VERITY)		+= dm-verity.o
 obj-$(CONFIG_DM_CACHE)		+= dm-cache.o
-obj-$(CONFIG_DM_CACHE_MQ)	+= dm-cache-mq.o
 obj-$(CONFIG_DM_CACHE_SMQ)	+= dm-cache-smq.o
 obj-$(CONFIG_DM_CACHE_CLEANER)	+= dm-cache-cleaner.o
 obj-$(CONFIG_DM_ERA)		+= dm-era.o
drivers/md/dm-cache-policy-mq.c deleted +0 -1472

1,472 lines not on this page · raw message

drivers/md/dm-cache-policy-smq.c +88 -5

151 lines not on this page · raw message

drivers/md/dm-cache-policy.c +5 -1
index c1a3cee..829f3af 100644
@@ -62,7 +62,11 @@ static struct dm_cache_policy_type *get_policy(const char *name)
 	if (t)
 		return t;
 
-	request_module("dm-cache-%s", name);
+	/* hack; mq is in the smq module */
+	if (!strcmp(name, "mq"))
+		request_module("dm-cache-smq");
+	else
+		request_module("dm-cache-%s", name);
 
 	t = get_policy_once(name);
 	if (IS_ERR(t))
Signature · 1 line
2.5.0
#1 lore raw

Can you add in some documentation on how you tell which dm_cache policy is actually being used, and how to measure it, etc? It's a black box and some info would be nice.

John

#2 lore raw
Quoted 4 lines · John Stoffel

Can you add in some documentation on how you tell which dm_cache policy is actually being used, and how to measure it, etc? It's a black box and some info would be nice.

You can get some stats on the cache performance via the status ioctl (eg, dmsetup status ...). This will tell you about promotions/demotion to the cache, write hits, read hits etc.

There is documentation on cache policies in Documentation/device-mapper/cache-policies.txt

https://github.com/jthornber/linux-2.6/blob/2016-02-10-thin-dev-on-4.4/Documentation/device-mapper/cache-policies.txt

As for knowing which policy is running; I'm not sure what to say. It'll be the one you ask for. If the above patch goes in, then there'll be a kernel version where mq becomes the same as smq. I'll bump the policy version number to make it clear that mq has undergone a big change.

- Joe

#3 lore raw
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Joe" == Joe Thornber <[email protected]> writes:

Quoted 4 lines · John Stoffel
Quoted 4 lines

Can you add in some documentation on how you tell which dm_cache policy is actually being used, and how to measure it, etc? It's a black box and some info would be nice.

Joe> You can get some stats on the cache performance via the status Joe> ioctl (eg, dmsetup status ...). This will tell you about Joe> promotions/demotion to the cache, write hits, read hits etc.

I've looked at this output, but I can't make heads nor tail of it, nor does the docs (v4.4-rc7) seem to provide any useful headings.

    # dmsetup --manglename none status --target cache
    data-home: 0 1153433600 cache 8 2443/32768 128 819200/819200 379170
    190334 1010554 121237 232 232 0 1 writeback 2 migration_threshold 2048
    smq 0 rw -
    data-local: 0 702545920 cache 8 2443/32768 128 804148/819200 574195
    28503 81586 19118 0 85798 0 1 writeback 2 migration_threshold 2048 smq
    0 rw -

But at least I see that I'm using smq for my cache policy.

Joe> There is documentation on cache policies in Joe> Documentation/device-mapper/cache-policies.txt

Joe> https://github.com/jthornber/linux-2.6/blob/2016-02-10-thin-dev-on-4.4/Documentation/device-mapper/cache-policies.txt

Joe> As for knowing which policy is running; I'm not sure what to say. Joe> It'll be the one you ask for. If the above patch goes in, then Joe> there'll be a kernel version where mq becomes the same as smq. Joe> I'll bump the policy version number to make it clear that mq has Joe> undergone a big change.

I never explicitly asked for any policy when using lvcache, so that's why I was asking. *grin*

Using the -c or -C options doesn't really change things. I see there's a --noheadings option, but that's not useful without the inverse --headings option so I can figure out what the results mean without looking into the kernel source code.

Should I pull down the source and try to make up a patch for this case?

John

#4 lore raw
In reply to Joe Thornber
Quoted 38 lines · Joe Thornber

smq seems to be performing better than the old mq policy in all situations, as well as using a quarter of the memory.

This patch makes 'mq' and alias for 'smq' when choosing a cache policy. The tunables that were present for the old mq are faked, and have no effect. mq should be considered deprecated now.

---
 drivers/md/Kconfig               |   11 +-
 drivers/md/Makefile              |    2 -
 drivers/md/dm-cache-policy-mq.c  | 1472 --------------------------------------
 drivers/md/dm-cache-policy-smq.c |   93 ++-
 drivers/md/dm-cache-policy.c     |    6 +-
 5 files changed, 97 insertions(+), 1487 deletions(-)
 delete mode 100644 drivers/md/dm-cache-policy-mq.c
drivers/md/Kconfig +4 -7
index b871928..9ea570b 100644
@@ -295,14 +295,11 @@ config DM_CACHE
          cleaned etc.  It supports writeback and writethrough modes.
 
 config DM_CACHE_MQ
-       tristate "MQ Cache Policy (EXPERIMENTAL)"
-       depends on DM_CACHE
-       default y
+       tristate "MQ Cache Policy (DEPRECATED)"
+       depends on DM_CACHE_SMQ
+       default n
        ---help---
-         A cache policy that uses a multiqueue ordered by recent hit
-         count to select which blocks should be promoted and demoted.
-         This is meant to be a general purpose policy.  It prioritises
-         reads over writes.
+         This policy is now an alias for the SMQ policy.
 
 config DM_CACHE_SMQ
        tristate "Stochastic MQ Cache Policy (EXPERIMENTAL)"

...

drivers/md/dm-cache-policy-mq.c

Quoted 5 lines
drivers/md/dm-cache-policy-mq.c deleted +0 -0
deleted file mode 100644
index dbdabdf..0000000

<snip delete of dm-cache-policy-mq.c>

Quoted 4 lines
drivers/md/dm-cache-policy-smq.c +0 -0
index 1ffbeb1..8ad6b22 100644

...

Quoted 61 lines
drivers/md/dm-cache-policy-smq.c +18 -0
@@ -1716,6 +1781,15 @@ static struct dm_cache_policy_type smq_policy_type = {
 	.create = smq_create
 };
 
+static struct dm_cache_policy_type mq_policy_type = {
+	.name = "mq",
+	.version = {1, 4, 0},
+	.hint_size = 4,
+	.owner = THIS_MODULE,
+	.create = mq_create,
+	.real = &mq_policy_type
+};
+
 static struct dm_cache_policy_type default_policy_type = {
 	.name = "default",
 	.version = {1, 4, 0},
@@ -1735,9 +1809,17 @@ static int __init smq_init(void)
 		return -ENOMEM;
 	}
 
+	r = dm_cache_policy_register(&mq_policy_type);
+	if (r) {
+		DMERR("register failed %d", r);
+		dm_cache_policy_unregister(&smq_policy_type);
+		return -ENOMEM;
+	}
+
 	r = dm_cache_policy_register(&default_policy_type);
 	if (r) {
 		DMERR("register failed (as default) %d", r);
+		dm_cache_policy_unregister(&mq_policy_type);
 		dm_cache_policy_unregister(&smq_policy_type);
 		return -ENOMEM;
 	}
@@ -1748,6 +1830,7 @@ static int __init smq_init(void)
 static void __exit smq_exit(void)
 {
 	dm_cache_policy_unregister(&smq_policy_type);
+	dm_cache_policy_unregister(&mq_policy_type);
 	dm_cache_policy_unregister(&default_policy_type);
 }
 
drivers/md/dm-cache-policy.c +5 -1
index c1a3cee..829f3af 100644
@@ -62,7 +62,11 @@ static struct dm_cache_policy_type *get_policy(const char *name)
 	if (t)
 		return t;
 
-	request_module("dm-cache-%s", name);
+	/* hack; mq is in the smq module */
+	if (!strcmp(name, "mq"))
+		request_module("dm-cache-smq");
+	else
+		request_module("dm-cache-%s", name);
 
 	t = get_policy_once(name);
 	if (IS_ERR(t))
Signature · 1 line
2.5.0

I don't think we need this get_policy() hack. We just want "mq" to be an alias for "smq" no? Same as "default".

The new call to dm_cache_policy_register(&mq_policy_type) will add the mq_policy_type to dm-cache-policy.c:register_list

Shouldn't get_policy()'s call to get_policy_once() resolve "mq" to be "smq" if we just add this to the bottom of dm-cache-policy-smq?:

MODULE_ALIAS("dm-cache-mq");

I'm also missing why mq_policy_type's .real points to itself via &mq_policy_type -- shouldn't it be &smq_policy_type (like "default" does)?

Or is this some subtle compatability so that "mq" is always displayed in cache status output?

#5 lore raw
Quoted 2 lines · Mike Snitzer

Or is this some subtle compatability so that "mq" is always displayed in cache status output?

This is about auto loading the smq module if someone asks for mq.

#6 lore raw
In reply to Mike Snitzer
Quoted 4 lines · Mike Snitzer

Shouldn't get_policy()'s call to get_policy_once() resolve "mq" to be "smq" if we just add this to the bottom of dm-cache-policy-smq?:

MODULE_ALIAS("dm-cache-mq");

Yes, you're right. See my fixup patch.

#7 lore raw
Quoted 7 lines · Joe Thornber
Quoted 4 lines · Mike Snitzer

Shouldn't get_policy()'s call to get_policy_once() resolve "mq" to be "smq" if we just add this to the bottom of dm-cache-policy-smq?:

MODULE_ALIAS("dm-cache-mq");

Yes, you're right. See my fixup patch.

Hmm, not seeing what you consider to be the latest fixed up version.. (nothing that sets: MODULE_ALIAS("dm-cache-mq") in smq.c)

But I've staged this in linux-next for 4.6, see:
https://git.kernel.org/cgit/linux/kernel/git/device-mapper/linux-dm.git/commit/?h=for-next&id=8cbd0cb8cca67baa3e430fb6d636613fdc1cee1a

#8 lore raw

Branch 2016-02-10-thin-dev-on-4.4

https://github.com/jthornber/linux-2.6/commit/9b0d197c86371bc4de01dcb7d7b1a49664d5d15e
https://github.com/jthornber/linux-2.6/commit/04a082129113de7c495eb609cdfcbbedc6cab3a3

Quoted 18 lines · On Fri, 26 Feb 2016 at 22:03 Mike Snitzer <[email protected]> wrote:
Quoted 7 lines · Joe Thornber
Quoted 4 lines · Mike Snitzer

Shouldn't get_policy()'s call to get_policy_once() resolve "mq" to be "smq" if we just add this to the bottom of dm-cache-policy-smq?:

MODULE_ALIAS("dm-cache-mq");

Yes, you're right. See my fixup patch.

Hmm, not seeing what you consider to be the latest fixed up version.. (nothing that sets: MODULE_ALIAS("dm-cache-mq") in smq.c)

But I've staged this in linux-next for 4.6, see:

https://git.kernel.org/cgit/linux/kernel/git/device-mapper/linux-dm.git/commit/?h=for-next&id=8cbd0cb8cca67baa3e430fb6d636613fdc1cee1a