Next set of LVM cache patches
cover Next set of LVM cache patches
These patches add the ability to create and remove cache pools and cache LVs. Yet to be addressed is reporting code (i.e. 'lvs'), man page updates, arguments for cache pool tunables (i.e. changing policies, cache mode, etc), profiles, and converting.
I'd still like to work on patch 5 a bit yet, but comments are welcome on these patches while I do that.
Jonathan Brassow (6):
pool: Make another thin pool fn generic for cache usage also
cache: Add functions that create/remove cache LVs
cache: Code changes to allow creation of cache pools
cache: Code changes to allow removal of cachepool LVs
cache: Code to allow the creation of cache LVs
cache: Code that allows removal of cache LVs
conf/example.conf.in | 11 ++ lib/Makefile.in | 1 + lib/activate/dev_manager.c | 11 ++- lib/config/config_settings.h | 3 + lib/config/defaults.h | 3 +- lib/format_text/flags.c | 4 + lib/metadata/cache_manip.c | 219 +++++++++++++++++++++++++++++ lib/metadata/lv_manip.c | 284 +++++++++++++++++++++++++++++++------ lib/metadata/merge.c | 60 +++++++-- lib/metadata/metadata-exported.h | 12 ++- libdm/libdevmapper.h | 5 + tools/args.h | 1 + tools/commands.h | 7 +- tools/lvcreate.c | 196 ++++++++++++++++++++++++-- 14 files changed, 738 insertions(+), 79 deletions(-) create mode 100644 lib/metadata/cache_manip.c
Signature · 1 line
1.7.7.6
PATCH 1/6 pool: Make another thin pool fn generic for cache usage also
Make '_recalculate_thin_pool_chunk_size_with_dev_hints' so it can be used for cache and thin pools.
--- conf/example.conf.in | 11 +++++++++ lib/config/config_settings.h | 3 ++ lib/metadata/lv_manip.c | 52 +++++++++++++++++++++++++++++------------- 3 files changed, 50 insertions(+), 16 deletions(-)
conf/example.conf.in +11 -0
@@ -305,6 +305,17 @@ allocation { # placed on different PVs from the cache_pool data. cache_pool_metadata_require_separate_pvs = 0 + # Specify the minimal chunk size (in kiB) for cache pool volumes. + # Using a chunk_size that is too large can result in wasteful use of + # the cache, where small reads and writes can cause large sections of + # an LV to be mapped into the cache. However, choosing a chunk_size + # that is too small can result in more overhead trying to manage the + # numerous chunks that become mapped into the cache. The former is + # more of a problem than the latter in most cases, so we default to + # a value that is on the smaller end of the spectrum. Supported values + # range from 32(kiB) to 1048576 in multiples of 32. + # cache_pool_chunk_size = 64 + # Set to 1 to guarantee that thin pool metadata will always # be placed on different PVs from the pool data. thin_pool_metadata_require_separate_pvs = 0
lib/config/config_settings.h +3 -0
@@ -107,7 +107,10 @@ cfg(allocation_maximise_cling_CFG, "maximise_cling", allocation_CFG_SECTION, 0, cfg(allocation_use_blkid_wiping_CFG, "use_blkid_wiping", allocation_CFG_SECTION, 0, CFG_TYPE_BOOL, 1, vsn(2, 2, 105), NULL) cfg(allocation_wipe_signatures_when_zeroing_new_lvs_CFG, "wipe_signatures_when_zeroing_new_lvs", allocation_CFG_SECTION, 0, CFG_TYPE_BOOL, 1, vsn(2, 2, 105), NULL) cfg(allocation_mirror_logs_require_separate_pvs_CFG, "mirror_logs_require_separate_pvs", allocation_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_MIRROR_LOGS_REQUIRE_SEPARATE_PVS, vsn(2, 2, 85), NULL) + cfg(allocation_cache_pool_metadata_require_separate_pvs_CFG, "cache_pool_metadata_require_separate_pvs", allocation_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_CACHE_POOL_METADATA_REQUIRE_SEPARATE_PVS, vsn(2, 2, 106), NULL) +cfg(allocation_cache_pool_chunk_size_CFG, "cache_pool_chunk_size", allocation_CFG_SECTION, 0, CFG_TYPE_INT, 0, vsn(2, 2, 106), NULL) + cfg(allocation_thin_pool_metadata_require_separate_pvs_CFG, "thin_pool_metadata_require_separate_pvs", allocation_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_THIN_POOL_METADATA_REQUIRE_SEPARATE_PVS, vsn(2, 2, 89), NULL) cfg(allocation_thin_pool_zero_CFG, "thin_pool_zero", allocation_CFG_SECTION, CFG_PROFILABLE, CFG_TYPE_BOOL, DEFAULT_THIN_POOL_ZERO, vsn(2, 2, 99), NULL)cfg (allocation_thin_pool_discards_CFG,"thin_pool_discards" , allocation_CFG_SECTION,CFG_PROFILABLE ,CFG_TYPE_STRING ,DEFAULT_THIN_POOL_DISCARDS ,vsn (2 ,2 ,99 ),NULL )
lib/metadata/lv_manip.c +36 -16
83 lines not on this page · raw message
Signature · 1 line
1.7.7.6
PATCH 2/6 cache: Add functions that create/remove cache LVs
In reply to Jonathan BrassowA cache LV - from LVM's perpective - is a user accessible device that links the cachepool LV and the origin LV. The following functions were added to facilitate the creation and removal of this top-level LV:
1) 'lv_cache_create' - takes a cachepool and an origin device and links them into a new top-level LV of 'cache' segment type. No allocation is necessary in this function, as the sub-LVs contain all of the necessary allocated space. Only the top-level layer needs to be created.
2) 'lv_cache_remove' - this function removes the top-level LV of a cache LV - promoting the cachepool and origin sub-LVs to top-level devices and leaving them exposed to the user. That is, the cachepool is unlinked and free to be used with another origin to form a new cache LV; and the origin is no longer cached.
--- lib/Makefile.in | 1 + lib/metadata/cache_manip.c | 219 ++++++++++++++++++++++++++++++++++++++ lib/metadata/metadata-exported.h | 9 ++- 3 files changed, 227 insertions(+), 2 deletions(-) create mode 100644 lib/metadata/cache_manip.c
lib/Makefile.in +1 -0
@@ -87,6 +87,7 @@ SOURCES =\ locking/locking.c \ locking/no_locking.c \ log/log.c \ + metadata/cache_manip.c \ metadata/lv.c \ metadata/lv_manip.c \ metadata/merge.c \
lib/metadata/cache_manip.c new file +219 -0
219 lines not on this page · raw message
lib/metadata/metadata-exported.h +7 -2
@@ -1,6 +1,6 @@/* * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved. -* Copyright (C) 2004-2013 Red Hat, Inc. All rights reserved. +* Copyright (C) 2004-2014 Red Hat, Inc. All rights reserved. * * This file is part of LVM2. *
@@ -1016,9 +1016,14 @@ int lv_raid_reshape(struct logical_volume *lv,int lv_raid_replace (struct logical_volume *lv,struct dm_list *remove_pvs,struct dm_list *allocate_pvs);int lv_raid_remove_missing (struct logical_volume *lv); -/* -- metadata/raid_manip.c */ +/* ++ metadata/cache_manip.c */ +struct logical_volume *lv_cache_create (struct logical_volume *pool, +struct logical_volume *origin); +int lv_cache_remove (struct logical_volume *cache_lv); +/* -- metadata/cache_manip.c */ +struct cmd_vg *cmd_vg_add (struct dm_pool *mem,struct dm_list *cmd_vgs,const char *vg_name,const char *vgid,uint32_t flags);
Signature · 1 line
1.7.7.6
PATCH 3/6 cache: Code changes to allow creation of cache pools
In reply to Jonathan BrassowThis patch allows the creation of cache pools. Users are not yet able to create cache LV. They are only able to define the space used for the cache and its characteristics (chunk_size and cache mode ATM) by creating the cache pool.
I would still like to see the following generalized:
- update_pool_params
--- lib/config/defaults.h | 3 +- lib/format_text/flags.c | 4 ++ lib/metadata/lv_manip.c | 46 ++++++++++------ lib/metadata/merge.c | 49 ++++++++++++----- lib/metadata/metadata-exported.h | 2 + libdm/libdevmapper.h | 5 ++ tools/args.h | 1 + tools/commands.h | 7 ++- tools/lvcreate.c | 109 ++++++++++++++++++++++++++++++++++---- 9 files changed, 182 insertions(+), 44 deletions(-)
lib/config/defaults.h +2 -1
@@ -77,9 +77,10 @@#define DEFAULT_THIN_POOL_CHUNK_SIZE_PERFORMANCE 512/* KB */ #define DEFAULT_THIN_POOL_DISCARDS "passdown"#define DEFAULT_THIN_POOL_ZERO 1 -#define DEFAULT_POOL_METADATA_SPARE 1 +#define DEFAULT_POOL_METADATA_SPARE 1/* thin + cache */ #define DEFAULT_CACHE_POOL_METADATA_REQUIRE_SEPARATE_PVS 0 +#define DEFAULT_CACHE_POOL_CHUNK_SIZE DEFAULT_THIN_POOL_CHUNK_SIZE#define DEFAULT_UMASK 0077
lib/format_text/flags.c +4 -0
@@ -83,6 +83,10 @@ static const struct flag _lv_flags[] = { {THIN_POOL, NULL, 0}, {THIN_POOL_DATA, NULL, 0}, {THIN_POOL_METADATA, NULL, 0}, + {CACHE, NULL, 0}, + {CACHE_POOL, NULL, 0}, + {CACHE_POOL_DATA, NULL, 0}, + {CACHE_POOL_METADATA, NULL, 0}, {0, NULL, 0} };
lib/metadata/lv_manip.c +29 -17
106 lines not on this page · raw message
lib/metadata/merge.c +36 -13
67 lines not on this page · raw message
lib/metadata/metadata-exported.h +2 -0
@@ -793,6 +793,8 @@ struct lvcreate_params {uint32_t min_recovery_rate;/* RAID */ uint32_t max_recovery_rate;/* RAID */ +uint32_t feature_flags;/* cache */ +const struct segment_type *segtype;/* all */ unsigned target_attr;/* all */
libdm/libdevmapper.h +5 -0
@@ -820,6 +820,11 @@ int dm_tree_node_add_replicator_dev_target(struct dm_tree_node *node,*/ #define DM_THIN_MAX_METADATA_SIZE (UINT64_C(255) * (1 << 14) * (4096 / (1 << 9)) - 256 * 1024) +/* Right now, cache parameters are the same as thin */ +#define DM_CACHE_MIN_DATA_BLOCK_SIZE DM_THIN_MIN_DATA_BLOCK_SIZE +#define DM_CACHE_MAX_DATA_BLOCK_SIZE DM_THIN_MAX_DATA_BLOCK_SIZE +#define DM_CACHE_MAX_METADATA_SIZE DM_THIN_MAX_METADATA_SIZE + int dm_tree_node_add_thin_pool_target(struct dm_tree_node *node, uint64_t size, uint64_t transaction_id,
tools/args.h +1 -0
@@ -62,6 +62,7 @@ arg(monitor_ARG, '\0', "monitor", yes_no_arg, 0) arg(config_ARG, '\0', "config", string_arg, 0) arg(trustcache_ARG, '\0', "trustcache", NULL, 0) arg(cache_ARG, '\0', "cache", NULL, 0) +arg(cachemode_ARG, '\0', "cachemode", string_arg, 0) arg(ignoremonitoring_ARG, '\0', "ignoremonitoring", NULL, 0) arg(nameprefixes_ARG, '\0', "nameprefixes", NULL, 0)arg (unquoted_ARG,'\0' ,"unquoted" ,NULL ,0 )
tools/commands.h +4 -3
@@ -230,6 +230,7 @@ xx(lvcreate,"\t[-a|--activate [a|e|l]{y|n}]\n" "\t[--addtag Tag]\n" "\t[--alloc AllocationPolicy]\n" +"\t[--cachemode CacheMode]\n" "\t[-C|--contiguous {y|n}]\n" "\t[-d|--debug]\n" "\t[-h|-?|--help]\n"
@@ -296,9 +297,9 @@ xx(lvcreate,"\t[PhysicalVolumePath...]\n\n" , addtag_ARG, alloc_ARG, autobackup_ARG, activate_ARG, available_ARG, - chunksize_ARG, contiguous_ARG, corelog_ARG, discards_ARG, extents_ARG, - ignoreactivationskip_ARG, ignoremonitoring_ARG, major_ARG, minor_ARG, - mirrorlog_ARG, mirrors_ARG, monitor_ARG, minrecoveryrate_ARG, + cachemode_ARG, chunksize_ARG, contiguous_ARG, corelog_ARG, discards_ARG, + extents_ARG, ignoreactivationskip_ARG, ignoremonitoring_ARG, major_ARG, + minor_ARG, mirrorlog_ARG, mirrors_ARG, monitor_ARG, minrecoveryrate_ARG, maxrecoveryrate_ARG, name_ARG, nosync_ARG, noudevsync_ARG, permission_ARG, persistent_ARG, poolmetadatasize_ARG, poolmetadataspare_ARG, raidminrecoveryrate_ARG, raidmaxrecoveryrate_ARG, readahead_ARG,
tools/lvcreate.c +99 -10
144 lines not on this page · raw message
Signature · 1 line
1.7.7.6
PATCH 4/6 cache: Code changes to allow removal of cachepool LVs
In reply to Jonathan Brassow--- lib/metadata/lv_manip.c | 27 +++++++++++++++++++-------- 1 files changed, 19 insertions(+), 8 deletions(-)
lib/metadata/lv_manip.c +19 -8
@@ -559,7 +559,8 @@ static int _release_and_discard_lv_segment_area(struct lv_segment *seg, uint32_t }if ((seg_lv (seg, s)->status &MIRROR_IMAGE ) || - (seg_lv (seg, s)->status &THIN_POOL_DATA )) { + (seg_lv (seg, s)->status &THIN_POOL_DATA ) || + (seg_lv (seg, s)->status &CACHE_POOL_DATA )) {if (!lv_reduce (seg_lv (seg, s), area_reduction)) return_0;/* FIXME: any upper level reporting */ return 1 ;
@@ -4552,6 +4553,7 @@ int lv_remove_single(struct cmd_context *cmd, struct logical_volume *lv,int format1_reload_required =0 ;int visible;struct logical_volume *pool_lv =NULL ; +struct lv_segment *cache_seg =NULL ;int ask_discard; vg = lv->vg;
@@ -4596,6 +4598,12 @@ int lv_remove_single(struct cmd_context *cmd, struct logical_volume *lv, }else if (lv_is_thin_volume (lv)) pool_lv =first_seg (lv)->pool_lv; +if (lv_is_cache_pool_data (lv) ||lv_is_cache_pool_metadata (lv)) { +log_error ("Can't remove logical volume %s used by a cache_pool." , + lv->name); +return 0 ; + } +if (lv->status &LOCKED ) {log_error ("Can't remove locked LV %s" , lv->name);return 0 ;
@@ -4824,12 +4832,14 @@ int lv_remove_with_dependencies(struct cmd_context *cmd, struct logical_volume *if (lv_is_used_thin_pool (lv) && !_lv_remove_segs_using_this_lv (cmd, lv, force, level,"pool" )) return_0; - -if (lv_is_thin_pool (lv) && lv->vg->pool_metadata_spare_lv) { -/* When removing last thin pool, remove also spare */ +if ((lv_is_thin_pool (lv) ||lv_is_cache_pool (lv)) && + lv->vg->pool_metadata_spare_lv) { +/* When removing last pool, also remove the spare */ is_last_pool =1 ; dm_list_iterate_items(lvl, &lv->vg->lvs) -if (lv_is_thin_pool (lvl->lv) && lvl->lv != lv) { +if ((lv_is_thin_pool (lvl->lv) || +lv_is_cache_pool (lvl->lv)) && + lvl->lv != lv) { is_last_pool =0 ;break ; }
@@ -4842,9 +4852,10 @@ int lv_remove_with_dependencies(struct cmd_context *cmd, struct logical_volume *if (lv_is_pool_metadata_spare (lv) && (force ==PROMPT ) && - (yes_no_prompt ("Removal of pool metadata spare logical volume \"%s\" " -"disables automatic recovery attempts after damage " -"to a thin pool. Proceed? [y/n]: " , lv->name) =='n' )) + (yes_no_prompt ("Removal of pool metadata spare logical volume" +" \"%s\" disables automatic recovery attempts" +" after damage to a thin or cache pool." +" Proceed? [y/n]: " , lv->name) =='n' )) goto no_remove;return lv_remove_single (cmd, lv, force,0 );
Signature · 1 line
1.7.7.6
PATCH 5/6 cache: Code to allow the creation of cache LVs
In reply to Jonathan BrassowThis patch allows users to create cache LVs with 'lvcreate'. An origin or a cache pool LV must be created first. Then, while supplying the origin or cache pool to the lvcreate command, the cache can be created.
Ex1:
Here the cache pool is created first, followed by the origin which will be cached.
# Create a cache pool first
~> lvcreate --type cache_pool -L 500M -n cachepool vg /dev/small_n_fast # Then create an origin + cache LV
~> lvcreate --type cache -L 1G -n lv vg/cachepool /dev/large_n_slow
Ex2:
Here the origin is created first, followed by the cache pool - allowing a cache LV to be created covering the origin.
# Create origin first
~> lvcreate -L 1G -n lv vg /dev/large_n_slow
# Then create the cache pool + cache LV
~> lvcreate --type cache -L 500M -n cachepool vg/lv /dev/small_n_fast
The code determines which type of LV was supplied (cache pool or origin) by checking its type. It ensures the right argument was given by ensuring that the origin is larger than the cache pool.
--- lib/activate/dev_manager.c | 11 +++- lib/metadata/lv_manip.c | 130 ++++++++++++++++++++++++++++++++++++-- lib/metadata/merge.c | 11 +++ lib/metadata/metadata-exported.h | 1 + tools/lvcreate.c | 87 +++++++++++++++++++++++++- 5 files changed, 231 insertions(+), 9 deletions(-)
lib/activate/dev_manager.c +9 -2
@@ -1912,6 +1912,10 @@ static int _add_lv_to_dtree(struct dev_manager *dm, struct dm_tree *dtree, !_add_lv_to_dtree(dm, dtree, seg->pool_lv, 1)) /* stack */ return_0; +if (seg->pool_lv &&lv_is_cache_pool (seg->pool_lv) && + !_add_lv_to_dtree (dm, dtree, seg->pool_lv,0 )) + return_0; +for (s =0 ; s < seg->area_count; s++) {if (seg_type (seg, s) ==AREA_LV &&seg_lv (seg, s) && !_add_lv_to_dtree (dm, dtree,seg_lv (seg, s),0 ))
@@ -2376,15 +2380,18 @@ static int _add_segment_to_dtree(struct dev_manager *dm,if (seg->external_lv && !_add_new_external_lv_to_dtree (dm, dtree, seg->external_lv, laopts)) return_0; +/* Add mirror log */ if (seg->log_lv && !_add_new_lv_to_dtree (dm, dtree, seg->log_lv, laopts,NULL )) return_0; -/* Add thin pool metadata */ + +/* Add pool metadata */ if (seg->metadata_lv && !_add_new_lv_to_dtree (dm, dtree, seg->metadata_lv, laopts,NULL )) return_0; -/* Add thin pool layer */ + +/* Add pool layer */ if (seg->pool_lv && !_add_new_lv_to_dtree (dm, dtree, seg->pool_lv, laopts,lv_layer (seg->pool_lv)))
lib/metadata/lv_manip.c +125 -5
154 lines not on this page · raw message
lib/metadata/merge.c +11 -0
@@ -294,6 +294,17 @@ int check_lv_segments(struct logical_volume *lv, int complete_vg) inc_error_count; } } + }else if (seg_is_cache (seg)) { +if (!lv_is_cache (lv)) { +log_error ("LV %s is missing cache flag for segment %u" , + lv->name, seg_count); + inc_error_count; + } +if (!seg->pool_lv) { +log_error ("LV %s: segment %u is missing cache_pool LV" , + lv->name, seg_count); + inc_error_count; + } }else {if (seg->pool_lv) { log_error("LV %s: segment %u must not have thin pool LV set",
lib/metadata/metadata-exported.h +1 -0
@@ -749,6 +749,7 @@ static inline int is_change_activating(activation_change_t change)/* FIXME: refactor and reduce the size of this struct! */ struct lvcreate_params {/* flags */ +int cache;int snapshot;/* snap */ int thin;/* thin */ int create_pool;/* thin */
tools/lvcreate.c +85 -2
105 lines not on this page · raw message
Signature · 1 line
1.7.7.6
PATCH 6/6 cache: Code that allows removal of cache LVs
In reply to Jonathan BrassowThis patch makes the changes necessary to be able to remove cache LVs.
If the user wants to remove just the cache for an LV. They specify the LV's associated cache pool when removing:
# Removes the cache pool - leaving the origin un-cached ~> lvremove vg/cachepool
If the user wishes to remove the origin, but leave the cachepool to be used for another LV, they specify the cache LV.
# Removes the origin - leaving the cache pool
~> lvremove vg/origin
In order to remove it all, specify both LVs.
--- lib/metadata/lv_manip.c | 31 ++++++++++++++++++++++++++++++- 1 files changed, 30 insertions(+), 1 deletions(-)
lib/metadata/lv_manip.c +30 -1
@@ -542,6 +542,8 @@ struct lv_segment *alloc_snapshot_seg(struct logical_volume *lv,static int _release_and_discard_lv_segment_area (struct lv_segment *seg,uint32_t s,uint32_t area_reduction,int with_discard) { +struct lv_segment *cache_seg; +if (seg_type (seg, s) ==AREA_UNASSIGNED )return 1 ;
@@ -558,7 +560,8 @@ static int _release_and_discard_lv_segment_area(struct lv_segment *seg, uint32_treturn 1 ; } -if ((seg_lv (seg, s)->status &MIRROR_IMAGE ) || +if (seg_is_cache (seg) || + (seg_lv (seg, s)->status &MIRROR_IMAGE ) || (seg_lv (seg, s)->status &THIN_POOL_DATA ) || (seg_lv (seg, s)->status &CACHE_POOL_DATA )) {if (!lv_reduce (seg_lv (seg, s), area_reduction))
@@ -566,6 +569,15 @@ static int _release_and_discard_lv_segment_area(struct lv_segment *seg, uint32_treturn 1 ; } +if (seg_is_cache_pool (seg) && + !dm_list_empty (&seg->lv->segs_using_this_lv)) { +if (!(cache_seg =get_only_segment_using_this_lv (seg->lv))) + return_0; + +if (!lv_cache_remove (cache_seg->lv)) + return_0; + } +if (seg_lv (seg, s)->status &RAID_IMAGE ) {/* * FIXME: Use lv_reduce not lv_remove
@@ -4598,6 +4610,21 @@ int lv_remove_single(struct cmd_context *cmd, struct logical_volume *lv, }else if (lv_is_thin_volume (lv)) pool_lv =first_seg (lv)->pool_lv; +/* +* If we are removing a cache_pool, we must first unlink +* it from any origins (i.e. remove the cache layer). +* +* If the cache_pool is not linked, we can simply proceed +* to remove it. +*/ +if (lv_is_cache_pool (lv) && !dm_list_empty (&lv->segs_using_this_lv)) { +if (!(cache_seg =get_only_segment_using_this_lv (lv))) + return_0; + +if (!lv_cache_remove (cache_seg->lv)) + return_0; + } +if (lv_is_cache_pool_data (lv) ||lv_is_cache_pool_metadata (lv)) {log_error ("Can't remove logical volume %s used by a cache_pool." , lv->name);
@@ -5122,6 +5149,8 @@ int remove_layer_from_lv(struct logical_volume *lv, parent->le_count != layer_lv->le_count) return_0; +//FIXME: why do we empty the parent? It removes everything below. +//This makes the function unusable for 'lv_cache_remove' if (!lv_empty (parent)) return_0;
Signature · 1 line
1.7.7.6