dm-snap: Replace special round_down()
PATCH 1/11 dm-snap: Replace special round_down()
In reply to a message not in the archiveThis patch removes the special round_down() to next power of 2 implementation used only at one place in the snapshot target. It is replaced by an equivalent 1 << fls() which might use an architecture specific implementation.
--- drivers/md/dm-snap.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-)
drivers/md/dm-snap.c +1 -11
@@ -333,16 +333,6 @@ static int calc_max_buckets(void) }/* -* Rounds a number down to a power of 2. -*/ -static uint32_t round_down (uint32_t n) -{ -while (n & (n -1 )) - n &= (n -1 ); -return n; -} - -/* * Allocate room for a suitable hash table. */ static int init_hash_tables (struct dm_snapshot *s)
@@ -361,7 +351,7 @@ static int init_hash_tables(struct dm_sn hash_size =min (hash_size, max_buckets);/* Round it down to a power of 2 */ - hash_size =round_down (hash_size); + hash_size =1 <<fls (hash_size);if (init_exception_table (&s->complete, hash_size))return -ENOMEM ;
PATCH 2/11 dm-snap: Replace special round_up()
In reply to a message not in the archiveThis patch replaces the special round_up() implementation used in the snapshot target. The code is not very performance critical so I think it is not worth having a special variant here.
--- drivers/md/dm-snap.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-)
drivers/md/dm-snap.c +1 -11
@@ -371,16 +371,6 @@ static int init_hash_tables(struct dm_snreturn 0 ; } -/* -* Round a number up to the nearest 'size' boundary. size must -* be a power of 2. -*/ -static ulong round_up (ulong n,ulong size) -{ - size--; -return (n + size) & ~size; -} -static int set_chunk_size (struct dm_snapshot *s,const char *chunk_size_arg,char **error) {
@@ -402,7 +392,7 @@ static int set_chunk_size(struct dm_snap* Chunk size must be multiple of page size. Silently * round up if it's not. */ - chunk_size =round_up (chunk_size,PAGE_SIZE >>9 ); + chunk_size =roundup (chunk_size,PAGE_SIZE >>9 );/* Check chunk_size is a power of 2 */ if (chunk_size & (chunk_size -1 )) {
PATCH 3/11 dm-snap: Remove dead queued_bios code
In reply to a message not in the archiveThis patch removes the unused queued_bios handling code.
--- drivers/md/dm-snap.c | 33 --------------------------------- drivers/md/dm-snap.h | 4 ---- 2 files changed, 37 deletions(-)
drivers/md/dm-snap.c +0 -33
@@ -39,9 +39,6 @@*/ #define SNAPSHOT_PAGES 256 -static struct workqueue_struct *ksnapd; -static void flush_queued_bios (struct work_struct *work); -struct dm_snap_pending_exception {struct dm_snap_exception e;
@@ -511,9 +508,6 @@ static int snapshot_ctr(struct dm_targetDMWARN ("Snapshot is marked invalid." ); } -bio_list_init (&s->queued_bios); -INIT_WORK (&s->queued_bios_work, flush_queued_bios); -/* Add snapshot to the list of snapshots for this origin */ /* Exceptions aren't triggered till snapshot_resume() is called */ if (register_snapshot (s)) {
@@ -563,8 +557,6 @@ static void snapshot_dtr(struct dm_targe {struct dm_snapshot *s = ti->private; -flush_workqueue (ksnapd); -/* Prevent further origin writes from using this snapshot. */ /* After this returns there can be no new kcopyd jobs. */ unregister_snapshot (s);
@@ -592,20 +584,6 @@ static void flush_bios(struct bio *bio) } } -static void flush_queued_bios (struct work_struct *work) -{ -struct dm_snapshot *s = - container_of(work, struct dm_snapshot, queued_bios_work); -struct bio *queued_bios; -unsigned long flags; - -spin_lock_irqsave (&s->pe_lock, flags); - queued_bios =bio_list_get (&s->queued_bios); -spin_unlock_irqrestore (&s->pe_lock, flags); - -flush_bios (queued_bios); -} -/* * Error a list of buffers. */
@@ -1249,17 +1227,8 @@ static int __init dm_snapshot_init(void) goto bad5; } - ksnapd =create_singlethread_workqueue ("ksnapd" ); -if (!ksnapd) { -DMERR ("Failed to create ksnapd workqueue." ); - r = -ENOMEM ; - goto bad6; - } -return 0 ; - bad6: -mempool_destroy (pending_pool); bad5:kmem_cache_destroy (pending_cache); bad4:
@@ -1277,8 +1246,6 @@ static void __exit dm_snapshot_exit(void {int r; -destroy_workqueue (ksnapd); - r =dm_unregister_target (&snapshot_target);if (r)DMERR ("snapshot unregister failed %d" , r);
drivers/md/dm-snap.h +0 -4
@@ -124,10 +124,6 @@ struct dm_snapshot {struct exception_store store;struct kcopyd_client *kcopyd_client; - -/* Queue of snapshot writes for ksnapd to flush */ -struct bio_list queued_bios; -struct work_struct queued_bios_work; };/*
PATCH 4/11 dm-snap: Remove dead pe_lock spinlock
In reply to a message not in the archiveRemove the dead pe_lock spinlock.
--- drivers/md/dm-snap.c | 1 - drivers/md/dm-snap.h | 6 ------ 2 files changed, 7 deletions(-)
drivers/md/dm-snap.c +0 -1
@@ -469,7 +469,6 @@ static int snapshot_ctr(struct dm_target s->active =0 ; s->last_percent =0 ;init_rwsem (&s->lock); -spin_lock_init (&s->pe_lock); s->table = ti->table;/* Allocate hash table for COW data */
drivers/md/dm-snap.h +0 -6
@@ -114,12 +114,6 @@ struct dm_snapshot {struct exception_table pending;struct exception_table complete; -/* -* pe_lock protects all pending_exception operations and access -* as well as the snapshot_bios list. -*/ -spinlock_t pe_lock; -/* The on disk metadata handler */ struct exception_store store;
PATCH 5/11 dm-snap: remove SECTOR_SHIFT define
In reply to a message not in the archiveSector size on Linux is always 512 bytes. Don't even try to give the impression this is changeable.
--- drivers/md/dm-exception-store.c | 8 ++++---- drivers/md/dm-snap.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-)
drivers/md/dm-exception-store.c +4 -4
@@ -139,7 +139,7 @@ static int alloc_area(struct pstore *ps)int r = -ENOMEM ;size_t len; - len = ps->snap->chunk_size <<SECTOR_SHIFT ; + len = ps->snap->chunk_size <<9 ;/* * Allocate the chunk_size block of memory that will hold
@@ -230,7 +230,7 @@ static int area_io(struct pstore *ps, uistatic int zero_area (struct pstore *ps,uint32_t area) { -memset (ps->area,0 , ps->snap->chunk_size <<SECTOR_SHIFT ); +memset (ps->area,0 , ps->snap->chunk_size <<9 );return area_io (ps, area,WRITE ); }
@@ -315,7 +315,7 @@ static int write_header(struct pstore *p {struct disk_header *dh; -memset (ps->area,0 , ps->snap->chunk_size <<SECTOR_SHIFT ); +memset (ps->area,0 , ps->snap->chunk_size <<9 ); dh = (struct disk_header *) ps->area; dh->magic =cpu_to_le32 (SNAP_MAGIC );
@@ -462,7 +462,7 @@ static int persistent_read_metadata(stru/* * Now we know correct chunk_size, complete the initialisation. */ - ps->exceptions_per_area = (ps->snap->chunk_size <<SECTOR_SHIFT ) / + ps->exceptions_per_area = (ps->snap->chunk_size <<9 ) /sizeof (struct disk_exception ); ps->callbacks =dm_vcalloc (ps->exceptions_per_area,sizeof (*ps->callbacks));
drivers/md/dm-snap.h +1 -1
@@ -139,7 +139,7 @@ int dm_create_transient(struct exception*/ static inline sector_t get_dev_size (struct block_device *bdev) { -return bdev->bd_inode->i_size >>SECTOR_SHIFT ; +return bdev->bd_inode->i_size >>9 ; }static inline chunk_t sector_to_chunk (struct dm_snapshot *s,sector_t sector)
PATCH 6/11 dm-log: remove SECTOR_SHIFT define
In reply to a message not in the archiveSector size on Linux is always 512 bytes. Don't even try to give the impression this is changeable.
--- drivers/md/dm-log.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/md/dm-log.c +4 -5
@@ -330,9 +330,9 @@ static int create_log_context(struct dir/* * Buffer holds both header and bitset. */ - buf_size =dm_round_up ((LOG_OFFSET <<SECTOR_SHIFT ) + - bitset_size, ti->limits.hardsect_size); - lc->header_location.count = buf_size >>SECTOR_SHIFT ; + buf_size =dm_round_up ((LOG_OFFSET <<9 ) + bitset_size, + ti->limits.hardsect_size); + lc->header_location.count = buf_size >>9 ; lc->io_req.mem.type =DM_IO_VMA ; lc->io_req.client =dm_io_client_create (dm_div_up (buf_size,PAGE_SIZE ));
@@ -350,8 +350,7 @@ static int create_log_context(struct dirreturn -ENOMEM ; } - lc->clean_bits = (void *)lc->disk_header + - (LOG_OFFSET <<SECTOR_SHIFT ); + lc->clean_bits = (void *)lc->disk_header + (LOG_OFFSET <<9 ); }memset (lc->clean_bits,-1 , bitset_size);
PATCH 7/11 dm-crypt: remove SECTOR_SHIFT define
In reply to a message not in the archiveSector size on Linux is always 512 bytes. Don't even try to give the impression this is changeable.
--- drivers/md/dm-crypt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/md/dm-crypt.c +2 -2
@@ -350,12 +350,12 @@ static int crypt_convert(struct crypt_costruct scatterlist sg_in = { .page = bv_in->bv_page, .offset = bv_in->bv_offset + ctx->offset_in, - .length =1 <<SECTOR_SHIFT + .length =512 };struct scatterlist sg_out = { .page = bv_out->bv_page, .offset = bv_out->bv_offset + ctx->offset_out, - .length =1 <<SECTOR_SHIFT + .length =512 }; ctx->offset_in += sg_in.length;
PATCH 8/11 dm: remove SECTOR_SHIFT define
In reply to a message not in the archiveSector size on Linux is always 512 bytes. Don't even try to give the impression this is changeable.
--- drivers/md/dm-io.c | 3 +-- drivers/md/dm-stripe.c | 2 +- drivers/md/dm-table.c | 4 ++-- drivers/md/dm.c | 2 +- drivers/md/dm.h | 2 -- 5 files changed, 5 insertions(+), 8 deletions(-)
drivers/md/dm-io.c +1 -2
@@ -293,8 +293,7 @@ static void do_region(int rw, unsigned i* bvec for bio_get/set_region() and decrement bi_max_vecs * to hide it from bio_add_page(). */ - num_bvecs =dm_sector_div_up (remaining, - (PAGE_SIZE >>SECTOR_SHIFT )); + num_bvecs =dm_sector_div_up (remaining,PAGE_SIZE >>9 ); num_bvecs =1 +min_t (int,bio_get_nr_vecs (where->bdev), num_bvecs); bio =bio_alloc_bioset (GFP_NOIO , num_bvecs, io->client->bios);
drivers/md/dm-stripe.c +1 -1
@@ -100,7 +100,7 @@ static int stripe_ctr(struct dm_target ** chunk_size is a power of two */ if (!chunk_size || (chunk_size & (chunk_size -1 )) || - (chunk_size < (PAGE_SIZE >>SECTOR_SHIFT ))) { + (chunk_size < (PAGE_SIZE >>9 ))) { ti->error ="Invalid chunk size" ;return -EINVAL ; }
drivers/md/dm-table.c +2 -2
@@ -428,7 +428,7 @@ static void close_dev(struct dm_dev *d,*/ static int check_device_area (struct dm_dev *dd,sector_t start,sector_t len) { -sector_t dev_size = dd->bdev->bd_inode->i_size >>SECTOR_SHIFT ; +sector_t dev_size = dd->bdev->bd_inode->i_size >>9 ;if (!dev_size)return 1 ;
@@ -702,7 +702,7 @@ static void check_for_valid_limits(strucif (!rs->max_hw_segments) rs->max_hw_segments =MAX_HW_SEGMENTS ;if (!rs->hardsect_size) - rs->hardsect_size =1 <<SECTOR_SHIFT ; + rs->hardsect_size =512 ;if (!rs->max_segment_size) rs->max_segment_size =MAX_SEGMENT_SIZE ;if (!rs->seg_boundary_mask)
drivers/md/dm.c +1 -1
@@ -1104,7 +1104,7 @@ static void __set_size(struct mapped_devset_capacity (md->disk, size);mutex_lock (&md->suspended_bdev->bd_inode->i_mutex); -i_size_write (md->suspended_bdev->bd_inode, (loff_t )size <<SECTOR_SHIFT ); +i_size_write (md->suspended_bdev->bd_inode, (loff_t )size <<9 );mutex_unlock (&md->suspended_bdev->bd_inode->i_mutex); }
drivers/md/dm.h +0 -2
@@ -62,8 +62,6 @@ #define DMEMIT(x...) sz += ((sz >= maxlen) ? \ 0 : scnprintf(result + sz, maxlen - sz, x)) -#define SECTOR_SHIFT 9 -/* * Definitions of return values from target end_io function. */
PATCH 9/11 dm-snap: use is_power_of_2()
In reply to a message not in the archiveUse is_power_of_2().
--- drivers/md/dm-snap.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/md/dm-snap.c +1 -2
@@ -391,8 +391,7 @@ static int set_chunk_size(struct dm_snap*/ chunk_size =roundup (chunk_size,PAGE_SIZE >>9 ); -/* Check chunk_size is a power of 2 */ -if (chunk_size & (chunk_size -1 )) { +if (!is_power_of_2 (chunk_size)) { *error ="Chunk size is not a power of 2" ;return -EINVAL ; }
PATCH 10/11 dm: use is_power_of_2()
In reply to a message not in the archiveUse is_power_of_2().
--- drivers/md/dm-stripe.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/md/dm-stripe.c +7 -6
@@ -96,12 +96,13 @@ static int stripe_ctr(struct dm_target *return -EINVAL ; } -/* -* chunk_size is a power of two -*/ -if (!chunk_size || (chunk_size & (chunk_size -1 )) || - (chunk_size < (PAGE_SIZE >>9 ))) { - ti->error ="Invalid chunk size" ; +if (!is_power_of_2 (chunk_size)) { + ti->error ="Chunk size is not a power of 2" ; +return -EINVAL ; + } + +if (chunk_size < (PAGE_SIZE >>9 )) { + ti->error ="Chunk size is smaller than page size" ;return -EINVAL ; }
PATCH 11/11 dm-snap: Fix snapshot compilation with CONFIG_LBD
In reply to a message not in the archiveThe snapshot code validates the snapshot chunksize against the device block size. Since the block size is usually a power of 2 we don't need to use modulo here which would let the compiler emit a call to __umoddi3(). Therefore this patch changes to the test to use a bitmask instead.
--- drivers/md/dm-snap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/dm-snap.c +1 -1
@@ -397,7 +397,7 @@ static int set_chunk_size(struct dm_snap }/* Validate the chunk size against the device block size */ -if (chunk_size % (bdev_hardsect_size (s->cow->bdev) >>9 )) { +if (chunk_size & ((bdev_hardsect_size (s->cow->bdev) >>9 ) -1 )) { *error ="Chunk size is not a multiple of device blocksize" ;return -EINVAL ; }
Alasdair G Kergon
maintainerRe: [patch 05/11] dm-snap: remove SECTOR_SHIFT define
In reply to a message not in the archiveQuoted 2 lines · Jan Blunck
Sector size on Linux is always 512 bytes. Don't even try to give the impression this is changeable.
If that's what worries you, add a comment next to the definition, perhaps?
It's there so you can easily locate all the places within dm that perform these conversions by using a simple search. Searching for '9' wouldn't be as easy. (I don't know about other people, but I find the code easier to read the way it is.)
BTW When changing one thing across the whole of dm, you may combine the sub-component patches into a single patch.
Alasdair
Signature · 1 line
[email protected]
Alasdair G Kergon
maintainerRe: [patch 03/11] dm-snap: Remove dead queued_bios code
In reply to a message not in the archiveQuoted 1 line · Jan Blunck
This patch removes the unused
queued_bioshandling code.
Well I'm going to leave this in for now (as one existing unfinished patch series does build upon it). We can include its removal as part of your following patch series that no doubt replaces the functionality with something better.
Alasdair
Signature · 1 line
[email protected]
Quoted 30 lines · Jan Blunck
This patch removes the special
round_down()to next power of 2 implementation used only at one place in the snapshot target. It is replaced by an equivalent 1 <<fls()which might use an architecture specific implementation.Signed-off-by Jan Blunck <[email protected]>--- drivers/md/dm-snap.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-)drivers/md/dm-snap.c +0
-10@@ -333,16 +333,6 @@ static int calc_max_buckets(void) }/* -* Rounds a number down to a power of 2. -*/ -static uint32_t round_down (uint32_t n) -{ -while (n & (n -1 )) - n &= (n -1 ); -return n; -} - -/* * Allocate room for a suitable hash table. */ static int init_hash_tables (struct dm_snapshot *s)
drivers/md/dm-snap.c static int init_hash_tables(struct dm_sn · line 357
Quoted 8 lines
drivers/md/dm-snap.c +1
-1@@ -361,7 +351,7 @@ static int init_hash_tables(struct dm_sn hash_size =min (hash_size, max_buckets);/* Round it down to a power of 2 */ - hash_size =round_down (hash_size); + hash_size =1 <<fls (hash_size);if (init_exception_table (&s->complete, hash_size))return -ENOMEM ;
Err, this is sooo stupid. First, 1 << fls(n) isn't round down but roundup_pow_of_2(). Second, hash_size is of type sector_t which could be u64 with CONFIG_LBD.
Signature · 38 lines
Subject: dm-snap: Replace special round_down() This patch removes the special round_down() to next power of 2 implementation used only at one place in the snapshot target. It is replaced by an equivalent 1 << fls() which might use an architecture specific implementation. Signed-off-by: Jan Blunck <[email protected]> --- drivers/md/dm-snap.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) --- a/drivers/md/dm-snap.c +++ b/drivers/md/dm-snap.c @@ -333,16 +333,6 @@ static int calc_max_buckets(void) } /* - * Rounds a number down to a power of 2. - */ -static uint32_t round_down(uint32_t n) -{ - while (n & (n - 1)) - n &= (n - 1); - return n; -} - -/* * Allocate room for a suitable hash table. */ static int init_hash_tables(struct dm_snapshot *s) @@ -361,7 +351,7 @@ static int init_hash_tables(struct dm_sn hash_size = min(hash_size, max_buckets); /* Round it down to a power of 2 */ - hash_size = round_down(hash_size); + hash_size = 1 << (fls_long(hash_size) - 1); if (init_exception_table(&s->complete, hash_size)) return -ENOMEM;
Re: [patch 05/11] dm-snap: remove SECTOR_SHIFT define
In reply to Alasdair G KergonQuoted 6 lines · Alasdair G Kergon
Quoted 2 lines · Jan Blunck
Sector size on Linux is always 512 bytes. Don't even try to give the impression this is changeable.
If that's what worries you, add a comment next to the definition, perhaps?
That and that the code just looks more like the rest of the block layer code. Only a few users (UFS, MSDOS, HFS, IDE) use a predefined SECTOR_{SHIFT,SIZE}.
Quoted 4 lines
It's there so you can easily locate all the places within dm that perform these conversions by using a simple search. Searching for '9' wouldn't be as easy. (I don't know about other people, but I find the code easier to read the way it is.)
Hmm, so I guess this is more about dis/like of how the code looks. Maybe we should define a global SECTOR_{SIZE,SHIFT} into blkdev.h.
Regards,
Jan
Signature · 1 line
Jan Blunck <[email protected]>
Re: [patch 03/11] dm-snap: Remove dead queued_bios code
In reply to Alasdair G KergonQuoted 7 lines · Alasdair G Kergon
Quoted 1 line · Jan Blunck
This patch removes the unused
queued_bioshandling code.Well I'm going to leave this in for now (as one existing unfinished patch series does build upon it). We can include its removal as part of your following patch series that no doubt replaces the functionality with something better.
You mean the snapshot read tracking. Yes, I think I can fix this problem too.
Regards,
Jan
Signature · 1 line
Jan Blunck <[email protected]>
Quoted 3 lines · Jan Blunck
This patch removes the special
round_down()to next power of 2 implementation used only at one place in the snapshot target. It is replaced by an equivalent 1 <<fls()which might use an architecture specific implementation.
Err, ok this is the second fix for this patch. I hope it is the last. It doesn't make any sense to have hash_size be defined as sector_t. Same goes for max_buckets.
Regards,
Jan
Signature · 1 line
Jan Blunck <[email protected]>
Subject: dm-snap: Replace special round_down()
This patch removes the special round_down() to next power of 2 implementation used only at one place in the snapshot target. It is replaced by an equivalent 1 << fls() which might use an architecture specific implementation.
--- drivers/md/dm-snap.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-)
drivers/md/dm-snap.c +3 -12
@@ -333,21 +333,12 @@ static int calc_max_buckets(void) }/* -* Rounds a number down to a power of 2. -*/ -static uint32_t round_down (uint32_t n) -{ -while (n & (n -1 )) - n &= (n -1 ); -return n; -} - -/* * Allocate room for a suitable hash table. */ static int init_hash_tables (struct dm_snapshot *s) { -sector_t hash_size, cow_dev_size, origin_dev_size, max_buckets; +unsigned int hash_size, max_buckets; +sector_t cow_dev_size, origin_dev_size;/* * Calculate based on the size of the original volume or
@@ -361,7 +352,7 @@ static int init_hash_tables(struct dm_sn hash_size =min (hash_size, max_buckets);/* Round it down to a power of 2 */ - hash_size =round_down (hash_size); + hash_size =1 << (fls (hash_size) -1 );if (init_exception_table (&s->complete, hash_size))return -ENOMEM ;