Partial Parity Log for MD RAID 5
Subsystems (3)
v5 cover Partial Parity Log for MD RAID 5
This series of patches implements the Partial Parity Log for RAID5 arrays. The purpose of this feature is closing the RAID 5 Write Hole. It is a solution alternative to the existing raid5-cache, but the logging workflow and much of the implementation is based on it.
The main differences compared to raid5-cache is that PPL is a distributed log - it is stored on array member drives in the metadata area and does not require a dedicated journaling drive. Write performance is reduced by up to 30%-40% but it scales with the number of drives in the array and the journaling drive does not become a bottleneck or a single point of failure. PPL does not protect from losing in-flight data, only from silent data corruption. More details about how the log works can be found in patches 3 and 5.
This feature originated from Intel RSTe, which uses IMSM metadata. PPL for IMSM is going to be included in RSTe implementations starting with upcoming Xeon platforms and Intel will continue supporting and maintaining it. This patchset implements PPL for external metadata (specifically IMSM) as well as native MD v1.x metadata.
Changes in mdadm are also required to make this fully usable. Patches for mdadm will be sent later.
v5:
- Added a common raid5-cache and ppl interface in raid5-log.h.
- Moved ops_run_partial_parity() to raid5-ppl.c.
- Use an inline bio in struct ppl_io_unit, simplify ppl_submit_iounit() and fix a potential bio allocation issue.
- Simplified condition for appending a stripe_head to ppl entry in ppl_log_stripe().
- Flush disk cache after ppl recovery, write with FUA in ppl_write_empty_header().
- Removed order > 0 page allocation in ppl_recover_entry().
- Put r5l_io_unit and ppl_io_unit in a union in struct stripe_head.
- struct ppl_conf *ppl in struct r5conf replaced with void *log_private.
- Improved comments and descriptions.
v4:
- Separated raid5-cache and ppl structures.
- Removed the policy logic from raid5-cache, ppl calls moved to raid5 core.
- Checking wrong configuration when validating superblock.
- Moved documentation to separate file.
- More checks for ppl sector/size.
- Some small fixes and improvements.
v3:
- Fixed alignment issues in the metadata structures.
- Removed reading IMSM signature from superblock.
- Removed 'rwh_policy' and per-device JournalPpl flags, added 'consistency_policy', 'ppl_sector' and 'ppl_size' sysfs attributes.
- Reworked and simplified disk removal logic.
- Debug messages in raid5-ppl.c converted to pr_debug().
- Fixed some bugs in logging and recovery code.
- Improved descriptions and documentation.
v2:
- Fixed wrong PPL size calculation for IMSM.
- Simplified full stripe write case.
- Removed direct access to bi_io_vec.
- Handle failed bio_add_page().
Artur Paszkiewicz (7):
md: superblock changes for PPL
raid5: separate header for log functions
raid5-ppl: Partial Parity Log write logging implementation
md: add sysfs entries for PPL
raid5-ppl: load and recover the log
raid5-ppl: support disk hot add/remove with PPL
raid5-ppl: runtime PPL enabling or disabling
Documentation/admin-guide/md.rst | 32 +- Documentation/md/raid5-ppl.txt | 44 ++ drivers/md/Makefile | 2 +- drivers/md/md.c | 140 +++++ drivers/md/md.h | 10 + drivers/md/raid0.c | 3 +- drivers/md/raid1.c | 3 +- drivers/md/raid5-cache.c | 22 +- drivers/md/raid5-log.h | 114 ++++ drivers/md/raid5-ppl.c | 1247 ++++++++++++++++++++++++++++++++++++++ drivers/md/raid5.c | 182 ++++-- drivers/md/raid5.h | 40 +- include/uapi/linux/raid/md_p.h | 45 +- 13 files changed, 1799 insertions(+), 85 deletions(-) create mode 100644 Documentation/md/raid5-ppl.txt create mode 100644 drivers/md/raid5-log.h create mode 100644 drivers/md/raid5-ppl.c
Signature · 1 line
2.11.0
PATCH v5 1/7 md: superblock changes for PPL
Include information about PPL location and size into mdp_superblock_1 and copy it to/from rdev. Because PPL is mutually exclusive with bitmap, put it in place of 'bitmap_offset'. Add a new flag MD_FEATURE_PPL for 'feature_map', analogically to MD_FEATURE_BITMAP_OFFSET. Add MD_HAS_PPL to mddev->flags to indicate that PPL is enabled on an array.
--- drivers/md/md.c | 19 +++++++++++++++++++ drivers/md/md.h | 8 ++++++++ drivers/md/raid0.c | 3 ++- drivers/md/raid1.c | 3 ++- include/uapi/linux/raid/md_p.h | 18 ++++++++++++++---- 5 files changed, 45 insertions(+), 6 deletions(-)
drivers/md/md.c +19 -0
@@ -1506,6 +1506,12 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_ }else if (sb->bblog_offset !=0 ) rdev->badblocks.shift =0 ; +if (le32_to_cpu (sb->feature_map) &MD_FEATURE_PPL ) { + rdev->ppl.offset = (__s16 )le16_to_cpu (sb->ppl.offset); + rdev->ppl.size =le16_to_cpu (sb->ppl.size); + rdev->ppl.sector = rdev->sb_start + rdev->ppl.offset; + } +if (!refdev) { ret =1 ; }else {
@@ -1618,6 +1624,13 @@ static int super_1_validate(struct mddev *mddev, struct md_rdev *rdev)if (le32_to_cpu (sb->feature_map) &MD_FEATURE_JOURNAL )set_bit (MD_HAS_JOURNAL , &mddev->flags); + +if (le32_to_cpu (sb->feature_map) &MD_FEATURE_PPL ) { +if (le32_to_cpu (sb->feature_map) & + (MD_FEATURE_BITMAP_OFFSET |MD_FEATURE_JOURNAL )) +return -EINVAL ; +set_bit (MD_HAS_PPL , &mddev->flags); + } }else if (mddev->pers ==NULL ) {/* Insist of good event counter while assembling, except for * spares (which don't need an event count) */
@@ -1831,6 +1844,12 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)if (test_bit (MD_HAS_JOURNAL , &mddev->flags)) sb->feature_map |=cpu_to_le32 (MD_FEATURE_JOURNAL ); +if (test_bit (MD_HAS_PPL , &mddev->flags)) { + sb->feature_map |=cpu_to_le32 (MD_FEATURE_PPL ); + sb->ppl.offset =cpu_to_le16 (rdev->ppl.offset); + sb->ppl.size =cpu_to_le16 (rdev->ppl.size); + } +rdev_for_each (rdev2, mddev) { i = rdev2->desc_nr;if (test_bit (Faulty, &rdev2->flags))
drivers/md/md.h +8 -0
@@ -122,6 +122,13 @@ struct md_rdev {* sysfs entry */ struct badblocks badblocks; + +struct { +short offset;/* Offset from superblock to start of PPL. +* Not used by external metadata. */ +unsigned int size;/* Size in sectors of the PPL space */ +sector_t sector;/* First sector of the PPL space */ + } ppl; };enum flag_bits { Faulty,/* device is known to have a fault */
@@ -226,6 +233,7 @@ enum mddev_flags {* supported as calls to md_error() will * never cause the array to become failed. */ + MD_HAS_PPL, /* The raid array has PPL feature set */ };enum mddev_sb_flags {
drivers/md/raid0.c +2 -1
@@ -29,7 +29,8 @@#define UNSUPPORTED_MDDEV_FLAGS \ ((1L << MD_HAS_JOURNAL) | \ (1L << MD_JOURNAL_CLEAN) | \ - (1L << MD_FAILFAST_SUPPORTED)) + (1L << MD_FAILFAST_SUPPORTED) |\ + (1L << MD_HAS_PPL))static int raid0_congested (struct mddev *mddev,int bits) {
drivers/md/raid1.c +2 -1
@@ -44,7 +44,8 @@#define UNSUPPORTED_MDDEV_FLAGS \ ((1L << MD_HAS_JOURNAL) | \ - (1L << MD_JOURNAL_CLEAN)) + (1L << MD_JOURNAL_CLEAN) | \ + (1L << MD_HAS_PPL))/* * Number of guaranteed r1bios in case of extreme VM load:
include/uapi/linux/raid/md_p.h +14 -4
@@ -242,10 +242,18 @@ struct mdp_superblock_1 {__le32 chunksize;/* in 512byte sectors */ __le32 raid_disks; -__le32 bitmap_offset;/* sectors after start of superblock that bitmap starts -* NOTE: signed, so bitmap can be before superblock -* only meaningful of feature_map[0] is set. -*/ +union { +__le32 bitmap_offset;/* sectors after start of superblock that bitmap starts +* NOTE: signed, so bitmap can be before superblock +* only meaningful of feature_map[0] is set. +*/ + +/* only meaningful when feature_map[MD_FEATURE_PPL] is set */ +struct { +__le16 offset;/* sectors from start of superblock that ppl starts (signed) */ +__le16 size;/* ppl size in sectors */ + } ppl; + };/* These are only valid with feature bit '4' */ __le32 new_level;/* new level we are reshaping to */
@@ -318,6 +326,7 @@ struct mdp_superblock_1 {*/ #define MD_FEATURE_CLUSTERED 256/* clustered MD */ #define MD_FEATURE_JOURNAL 512/* support write cache */ +#define MD_FEATURE_PPL 1024/* support PPL */ #define MD_FEATURE_ALL (MD_FEATURE_BITMAP_OFFSET \ |MD_FEATURE_RECOVERY_OFFSET \ |MD_FEATURE_RESHAPE_ACTIVE \
@@ -328,6 +337,7 @@ struct mdp_superblock_1 { |MD_FEATURE_RECOVERY_BITMAP \ |MD_FEATURE_CLUSTERED \ |MD_FEATURE_JOURNAL \ + |MD_FEATURE_PPL \ ) struct r5l_payload_header {
Signature · 1 line
2.11.0
PATCH v5 2/7 raid5: separate header for log functions
In reply to Artur PaszkiewiczMove raid5-cache declarations from raid5.h to raid5-log.h, add inline wrappers for functions which will be shared with ppl and use them in raid5 core instead of direct calls to raid5-cache.
Remove unused parameter from r5c_cache_data(), move two duplicated pr_debug() calls to r5l_init_log().
--- drivers/md/raid5-cache.c | 22 ++++++++++--- drivers/md/raid5-log.h | 81 ++++++++++++++++++++++++++++++++++++++++++++++++ drivers/md/raid5.c | 48 ++++++++-------------------- drivers/md/raid5.h | 30 ------------------ 4 files changed, 112 insertions(+), 69 deletions(-) create mode 100644 drivers/md/raid5-log.h
drivers/md/raid5-cache.c +18 -4
@@ -343,6 +343,8 @@ void r5c_handle_cached_data_endio(struct r5conf *conf, } } +void r5l_wake_reclaim (struct r5l_log *log,sector_t space); +/* Check whether we should flush some stripes to free up stripe cache */ void r5c_check_stripe_cache_usage (struct r5conf *conf) {
@@ -2620,9 +2622,7 @@ void r5c_finish_stripe_write_out(struct r5conf *conf, } } -int -r5c_cache_data (struct r5l_log *log,struct stripe_head *sh, -struct stripe_head_state *s) +int r5c_cache_data (struct r5l_log *log,struct stripe_head *sh) {struct r5conf *conf = sh->raid_conf;int pages =0 ;
@@ -2785,6 +2785,10 @@ int r5l_init_log(struct r5conf *conf, struct md_rdev *rdev) {struct request_queue *q =bdev_get_queue (rdev->bdev);struct r5l_log *log; +char b[BDEVNAME_SIZE ]; + +pr_debug ("md/raid:%s: using device %s as journal\n" , +mdname (conf->mddev),bdevname (rdev->bdev, b));if (PAGE_SIZE !=4096 )return -EINVAL ;
@@ -2887,7 +2891,7 @@ int r5l_init_log(struct r5conf *conf, struct md_rdev *rdev)return -EINVAL ; } -void r5l_exit_log (struct r5l_log *log) +static void __r5l_exit_log (struct r5l_log *log) {flush_work (&log->disable_writeback_work);md_unregister_thread (&log->reclaim_thread);
@@ -2897,3 +2901,13 @@ void r5l_exit_log(struct r5l_log *log)kmem_cache_destroy (log->io_kc);kfree (log); } + +void r5l_exit_log (struct r5conf *conf) +{ +struct r5l_log *log = conf->log; + + conf->log =NULL ; +synchronize_rcu (); + +__r5l_exit_log (log); +}
drivers/md/raid5-log.h new file +81 -0
81 lines not on this page · raw message
drivers/md/raid5.c +13 -35
120 lines not on this page · raw message
drivers/md/raid5.h +0 -30
@@ -765,34 +765,4 @@ extern struct stripe_head * raid5_get_active_stripe(struct r5conf *conf, sector_t sector, int previous, int noblock, int noquiesce);extern int raid5_calc_degraded (struct r5conf *conf); -extern int r5l_init_log (struct r5conf *conf,struct md_rdev *rdev); -extern void r5l_exit_log (struct r5l_log *log); -extern int r5l_write_stripe (struct r5l_log *log,struct stripe_head *head_sh); -extern void r5l_write_stripe_run (struct r5l_log *log); -extern void r5l_flush_stripe_to_raid (struct r5l_log *log); -extern void r5l_stripe_write_finished (struct stripe_head *sh); -extern int r5l_handle_flush_request (struct r5l_log *log,struct bio *bio); -extern void r5l_quiesce (struct r5l_log *log,int state); -extern bool r5l_log_disk_error (struct r5conf *conf); -extern bool r5c_is_writeback (struct r5l_log *log); -extern int -r5c_try_caching_write (struct r5conf *conf,struct stripe_head *sh, -struct stripe_head_state *s,int disks); -extern void -r5c_finish_stripe_write_out (struct r5conf *conf,struct stripe_head *sh, -struct stripe_head_state *s); -extern void r5c_release_extra_page (struct stripe_head *sh); -extern void r5c_use_extra_page (struct stripe_head *sh); -extern void r5l_wake_reclaim (struct r5l_log *log,sector_t space); -extern void r5c_handle_cached_data_endio (struct r5conf *conf, -struct stripe_head *sh,int disks,struct bio_list *return_bi); -extern int r5c_cache_data (struct r5l_log *log,struct stripe_head *sh, -struct stripe_head_state *s); -extern void r5c_make_stripe_write_out (struct stripe_head *sh); -extern void r5c_flush_cache (struct r5conf *conf,int num); -extern void r5c_check_stripe_cache_usage (struct r5conf *conf); -extern void r5c_check_cached_full_stripe (struct r5conf *conf); -extern struct md_sysfs_entry r5c_journal_mode; -extern void r5c_update_on_rdev_error (struct mddev *mddev); -extern bool r5c_big_stripe_cached (struct r5conf *conf,sector_t sect);#endif
Signature · 1 line
2.11.0
PATCH v5 3/7 raid5-ppl: Partial Parity Log write logging implementation
In reply to Artur PaszkiewiczImplement the calculation of partial parity for a stripe and PPL write logging functionality. The description of PPL is added to the documentation. More details can be found in the comments in raid5-ppl.c.
Attach a page for holding the partial parity data to stripe_head. Allocate it only if mddev has the MD_HAS_PPL flag set.
Partial parity is the xor of not modified data chunks of a stripe and is calculated as follows:
- reconstruct-write case:
xor data from all not updated disks in a stripe
- read-modify-write case:
xor old data and parity from all updated disks in a stripe
Implement it using the async_tx API and integrate into raid_run_ops(). It must be called when we still have access to old data, so do it when STRIPE_OP_BIODRAIN is set, but before ops_run_prexor5(). The result is stored into sh->ppl_page.
Partial parity is not meaningful for full stripe write and is not stored in the log or used for recovery, so don't attempt to calculate it when stripe has STRIPE_FULL_WRITE.
Put the PPL metadata structures to md_p.h because userspace tools (mdadm) will also need to read/write PPL.
Warn about using PPL with enabled disk volatile write-back cache for now. It can be removed once disk cache flushing before writing PPL is implemented.
--- Documentation/md/raid5-ppl.txt | 44 +++ drivers/md/Makefile | 2 +- drivers/md/raid5-log.h | 24 ++ drivers/md/raid5-ppl.c | 703 +++++++++++++++++++++++++++++++++++++++++ drivers/md/raid5.c | 64 +++- drivers/md/raid5.h | 10 +- include/uapi/linux/raid/md_p.h | 27 ++ 7 files changed, 869 insertions(+), 5 deletions(-) create mode 100644 Documentation/md/raid5-ppl.txt create mode 100644 drivers/md/raid5-ppl.c
Documentation/md/raid5-ppl.txt new file +44 -0
@@ -0,0 +1,44 @@ +Partial Parity Log + +Partial Parity Log (PPL) is a feature available for RAID5 arrays. The issue +addressed by PPL is that after a dirty shutdown, parity of a particular stripe +may become inconsistent with data on other member disks. If the array is also +in degraded state, there is no way to recalculate parity, because one of the +disks is missing. This can lead to silent data corruption when rebuilding the +array or using it is as degraded - data calculated from parity for array blocks +that have not been touched by a write request during the unclean shutdown can +be incorrect. Such condition is known as the RAID5 Write Hole. Because of +this, md by default does not allow starting a dirty degraded array. + +Partial parity for a write operation is the XOR of stripe data chunks not +modified by this write. It is just enough data needed for recovering from the +write hole. XORing partial parity with the modified chunks produces parity for +the stripe, consistent with its state before the write operation, regardless of +which chunk writes have completed. If one of the not modified data disks of +this stripe is missing, this updated parity can be used to recover its +contents. PPL recovery is also performed when starting an array after an +unclean shutdown and all disks are available, eliminating the need to resync +the array. Because of this, using write-intent bitmap and PPL together is not +supported. + +When handling a write request PPL writes partial parity before new data and +parity are dispatched to disks. PPL is a distributed log - it is stored on +array member drives in the metadata area, on the parity drive of a particular +stripe. It does not require a dedicated journaling drive. Write performance is +reduced by up to 30%-40% but it scales with the number of drives in the array +and the journaling drive does not become a bottleneck or a single point of +failure. + +Unlike raid5-cache, the other solution in md for closing the write hole, PPL is +not a true journal. It does not protect from losing in-flight data, only from +silent data corruption. If a dirty disk of a stripe is lost, no PPL recovery is +performed for this stripe (parity is not updated). So it is possible to have +arbitrary data in the written part of a stripe if that disk is lost. In such +case the behavior is the same as in plain raid5. + +PPL is available for md version-1 metadata and external (specifically IMSM) +metadata arrays. It can be enabled using mdadm option --consistency-policy=ppl. + +Currently, volatile write-back cache should be disabled on all member drives +when using PPL. Otherwise it cannot guarantee consistency in case of power +failure.
drivers/md/Makefile +1 -1
@@ -18,7 +18,7 @@ dm-cache-cleaner-y += dm-cache-policy-cleaner.o dm-era-y += dm-era-target.o dm-verity-y += dm-verity-target.o md-mod-y += md.o bitmap.o -raid456-y += raid5.o raid5-cache.o +raid456-y += raid5.o raid5-cache.o raid5-ppl.o # Note: link order is important. All raid personalities # and must come before md.o, as they each initialise
drivers/md/raid5-log.h +24 -0
@@ -31,6 +31,20 @@ extern struct md_sysfs_entry r5c_journal_mode;extern void r5c_update_on_rdev_error (struct mddev *mddev);extern bool r5c_big_stripe_cached (struct r5conf *conf,sector_t sect); +extern struct dma_async_tx_descriptor * +ops_run_partial_parity (struct stripe_head *sh,struct raid5_percpu *percpu, +struct dma_async_tx_descriptor *tx); +extern int ppl_init_log (struct r5conf *conf); +extern void ppl_exit_log (struct r5conf *conf); +extern int ppl_write_stripe (struct r5conf *conf,struct stripe_head *sh); +extern void ppl_write_stripe_run (struct r5conf *conf); +extern void ppl_stripe_write_finished (struct stripe_head *sh); + +static inline bool raid5_has_ppl (struct r5conf *conf) +{ +return test_bit (MD_HAS_PPL , &conf->mddev->flags); +} +static inline int log_stripe (struct stripe_head *sh,struct stripe_head_state *s) {struct r5conf *conf = sh->raid_conf;
@@ -45,6 +59,8 @@ static inline int log_stripe(struct stripe_head *sh, struct stripe_head_state *s/* caching phase */ return r5c_cache_data (conf->log, sh); } + }else if (raid5_has_ppl (conf)) { +return ppl_write_stripe (conf, sh); }return -EAGAIN ;
@@ -56,24 +72,32 @@ static inline void log_stripe_write_finished(struct stripe_head *sh)if (conf->log)r5l_stripe_write_finished (sh); +else if (raid5_has_ppl (conf)) +ppl_stripe_write_finished (sh); }static inline void log_write_stripe_run (struct r5conf *conf) {if (conf->log)r5l_write_stripe_run (conf->log); +else if (raid5_has_ppl (conf)) +ppl_write_stripe_run (conf); }static inline void log_exit (struct r5conf *conf) {if (conf->log)r5l_exit_log (conf); +else if (raid5_has_ppl (conf)) +ppl_exit_log (conf); }static inline int log_init (struct r5conf *conf,struct md_rdev *journal_dev) {if (journal_dev)return r5l_init_log (conf, journal_dev); +else if (raid5_has_ppl (conf)) +return ppl_init_log (conf);return 0 ; }
drivers/md/raid5-ppl.c new file +703 -0
703 lines not on this page · raw message
drivers/md/raid5.c +61 -3
118 lines not on this page · raw message
drivers/md/raid5.h +9 -1
@@ -224,10 +224,16 @@ struct stripe_head {spinlock_t batch_lock;/* only header's lock is useful */ struct list_head batch_list;/* protected by head's batch lock*/ -struct r5l_io_unit *log_io; +union { +struct r5l_io_unit *log_io; +struct ppl_io_unit *ppl_io; + }; +struct list_head log_list;sector_t log_start;/* first meta block on the journal */ struct list_head r5c;/* for r5c_cache->stripe_in_journal */ + +struct page *ppl_page;/* partial parity of this stripe */ /** * struct stripe_operations * @target - STRIPE_OP_COMPUTE_BLK target
@@ -400,6 +406,7 @@ enum {STRIPE_OP_BIODRAIN ,STRIPE_OP_RECONSTRUCT ,STRIPE_OP_CHECK , + STRIPE_OP_PARTIAL_PARITY, };/*
@@ -686,6 +693,7 @@ struct r5conf {int group_cnt;int worker_cnt_per_group;struct r5l_log *log; +void *log_private;struct bio_list pending_bios;spinlock_t pending_bios_lock;
include/uapi/linux/raid/md_p.h +27 -0
@@ -398,4 +398,31 @@ struct r5l_meta_block {#define R5LOG_VERSION 0x1#define R5LOG_MAGIC 0x6433c509 + +struct ppl_header_entry { +__le64 data_sector;/* raid sector of the new data */ +__le32 pp_size;/* length of partial parity */ +__le32 data_size;/* length of data */ +__le32 parity_disk;/* member disk containing parity */ +__le32 checksum;/* checksum of partial parity data for this +* entry (~crc32c) */ +} __attribute__ ((__packed__ )); + +#define PPL_HEADER_SIZE 4096 +#define PPL_HDR_RESERVED 512 +#define PPL_HDR_ENTRY_SPACE \ + (PPL_HEADER_SIZE - PPL_HDR_RESERVED - 4 * sizeof(u32) - sizeof(u64)) +#define PPL_HDR_MAX_ENTRIES \ + (PPL_HDR_ENTRY_SPACE / sizeof(struct ppl_header_entry)) + +struct ppl_header { +__u8 reserved[PPL_HDR_RESERVED ];/* reserved space, fill with 0xff */ +__le32 signature;/* signature (family number of volume) */ +__le32 padding;/* zero pad */ +__le64 generation;/* generation number of the header */ +__le32 entries_count;/* number of entries in entry array */ +__le32 checksum;/* checksum of the header (~crc32c) */ +struct ppl_header_entry entries[PPL_HDR_MAX_ENTRIES ]; +} __attribute__ ((__packed__ )); +#endif
Signature · 1 line
2.11.0
Re: [PATCH v5 3/7] raid5-ppl: Partial Parity Log write logging implementation
Quoted 33 lines · Artur Paszkiewicz
Implement the calculation of partial parity for a stripe and PPL write logging functionality. The description of PPL is added to the documentation. More details can be found in the comments in
raid5-ppl.c.Attach a page for holding the partial parity data to
stripe_head. Allocate it only if mddev has theMD_HAS_PPLflag set.Partial parity is the xor of not modified data chunks of a stripe and is calculated as follows:
- reconstruct-write case:
xor data from all not updated disks in a stripe- read-modify-write case:
xor old data and parity from all updated disks in a stripeImplement it using the
async_txAPI and integrate intoraid_run_ops(). It must be called when we still have access to old data, so do it whenSTRIPE_OP_BIODRAINis set, but beforeops_run_prexor5(). The result is stored intosh->ppl_page.Partial parity is not meaningful for full stripe write and is not stored in the log or used for recovery, so don't attempt to calculate it when stripe has
STRIPE_FULL_WRITE.Put the PPL metadata structures to
md_p.hbecause userspace tools (mdadm) will also need to read/write PPL.Warn about using PPL with enabled disk volatile write-back cache for now. It can be removed once disk cache flushing before writing PPL is implemented.
Signed-off-by Artur Paszkiewicz <[email protected]>
... snip ...
Quoted 28 lines
drivers/md/raid5-ppl.c new file +28
-0+struct dma_async_tx_descriptor * +ops_run_partial_parity (struct stripe_head *sh,struct raid5_percpu *percpu, +struct dma_async_tx_descriptor *tx) +{ +int disks = sh->disks; +struct page **xor_srcs =flex_array_get (percpu->scribble,0 ); +int count =0 , pd_idx = sh->pd_idx, i; +struct async_submit_ctl submit; + +pr_debug ("%s: stripe %llu\n" , __func__, (unsigned long long )sh->sector); + +/* +* Partial parity is the XOR of stripe data chunks that are not changed +* during the write request. Depending on available data +* (read-modify-write vs. reconstruct-write case) we calculate it +* differently. +*/ +if (sh->reconstruct_state == reconstruct_state_prexor_drain_run) { +/* rmw: xor old data and parity from updated disks */ +for (i = disks; i--;) { +struct r5dev *dev = &sh->dev[i]; +if (test_bit (R5_Wantdrain, &dev->flags) || i == pd_idx) + xor_srcs[count++] = dev->page; + } + }else if (sh->reconstruct_state == reconstruct_state_drain_run) { +/* rcw: xor data from all not updated disks */ +for (i = disks; i--;) { +struct r5dev *dev = &sh->dev[i];
drivers/md/raid5-ppl.c line 182
Quoted 10 lines
drivers/md/raid5-ppl.c new file +10
-0+if (test_bit (R5_UPTODATE , &dev->flags)) + xor_srcs[count++] = dev->page; + } + }else { +return tx; + } + +init_async_submit (&submit,ASYNC_TX_XOR_ZERO_DST , tx,NULL , sh, +flex_array_get (percpu->scribble,0 ) + +sizeof (struct page *) * (sh->disks +2 ));
Since this should be done before biodrain, should this add ASYNC_TX_FENCE flag?
Thanks,
Shaohua
Re: [PATCH v5 3/7] raid5-ppl: Partial Parity Log write logging implementation
Quoted 69 lines · Shaohua Li
Quoted 33 lines · Artur Paszkiewicz
Implement the calculation of partial parity for a stripe and PPL write logging functionality. The description of PPL is added to the documentation. More details can be found in the comments in
raid5-ppl.c.Attach a page for holding the partial parity data to
stripe_head. Allocate it only if mddev has theMD_HAS_PPLflag set.Partial parity is the xor of not modified data chunks of a stripe and is calculated as follows:
- reconstruct-write case:
xor data from all not updated disks in a stripe- read-modify-write case:
xor old data and parity from all updated disks in a stripeImplement it using the
async_txAPI and integrate intoraid_run_ops(). It must be called when we still have access to old data, so do it whenSTRIPE_OP_BIODRAINis set, but beforeops_run_prexor5(). The result is stored intosh->ppl_page.Partial parity is not meaningful for full stripe write and is not stored in the log or used for recovery, so don't attempt to calculate it when stripe has
STRIPE_FULL_WRITE.Put the PPL metadata structures to
md_p.hbecause userspace tools (mdadm) will also need to read/write PPL.Warn about using PPL with enabled disk volatile write-back cache for now. It can be removed once disk cache flushing before writing PPL is implemented.
Signed-off-by Artur Paszkiewicz <[email protected]>... snip ...
Quoted 32 lines
drivers/md/raid5-ppl.c new file +32
-0+struct dma_async_tx_descriptor * +ops_run_partial_parity (struct stripe_head *sh,struct raid5_percpu *percpu, +struct dma_async_tx_descriptor *tx) +{ +int disks = sh->disks; +struct page **xor_srcs =flex_array_get (percpu->scribble,0 ); +int count =0 , pd_idx = sh->pd_idx, i; +struct async_submit_ctl submit; + +pr_debug ("%s: stripe %llu\n" , __func__, (unsigned long long )sh->sector); + +/* +* Partial parity is the XOR of stripe data chunks that are not changed +* during the write request. Depending on available data +* (read-modify-write vs. reconstruct-write case) we calculate it +* differently. +*/ +if (sh->reconstruct_state == reconstruct_state_prexor_drain_run) { +/* rmw: xor old data and parity from updated disks */ +for (i = disks; i--;) { +struct r5dev *dev = &sh->dev[i]; +if (test_bit (R5_Wantdrain, &dev->flags) || i == pd_idx) + xor_srcs[count++] = dev->page; + } + }else if (sh->reconstruct_state == reconstruct_state_drain_run) { +/* rcw: xor data from all not updated disks */ +for (i = disks; i--;) { +struct r5dev *dev = &sh->dev[i]; +if (test_bit (R5_UPTODATE , &dev->flags)) + xor_srcs[count++] = dev->page; + } + }else {
Quoted 8 lines
drivers/md/raid5-ppl.c line 182
Quoted 6 lines
drivers/md/raid5-ppl.c new file +6
-0+return tx; + } + +init_async_submit (&submit,ASYNC_TX_XOR_ZERO_DST , tx,NULL , sh, +flex_array_get (percpu->scribble,0 ) + +sizeof (struct page *) * (sh->disks +2 ));Since this should be done before biodrain, should this add
ASYNC_TX_FENCEflag?
The result of this calculation isn't used later by other async_tx operations, so it's not needed here, if I understand this correctly. But maybe later we could optimize and use partial parity to calculate full parity, then it will be necessary.
Thanks,
Artur
Re: [PATCH v5 3/7] raid5-ppl: Partial Parity Log write logging implementation
Quoted 79 lines · Artur Paszkiewicz
Quoted 69 lines · Shaohua Li
Quoted 33 lines · Artur Paszkiewicz
Implement the calculation of partial parity for a stripe and PPL write logging functionality. The description of PPL is added to the documentation. More details can be found in the comments in
raid5-ppl.c.Attach a page for holding the partial parity data to
stripe_head. Allocate it only if mddev has theMD_HAS_PPLflag set.Partial parity is the xor of not modified data chunks of a stripe and is calculated as follows:
- reconstruct-write case:
xor data from all not updated disks in a stripe- read-modify-write case:
xor old data and parity from all updated disks in a stripeImplement it using the
async_txAPI and integrate intoraid_run_ops(). It must be called when we still have access to old data, so do it whenSTRIPE_OP_BIODRAINis set, but beforeops_run_prexor5(). The result is stored intosh->ppl_page.Partial parity is not meaningful for full stripe write and is not stored in the log or used for recovery, so don't attempt to calculate it when stripe has
STRIPE_FULL_WRITE.Put the PPL metadata structures to
md_p.hbecause userspace tools (mdadm) will also need to read/write PPL.Warn about using PPL with enabled disk volatile write-back cache for now. It can be removed once disk cache flushing before writing PPL is implemented.
Signed-off-by Artur Paszkiewicz <[email protected]>... snip ...
Quoted 32 lines
drivers/md/raid5-ppl.c new file +32
-0+struct dma_async_tx_descriptor * +ops_run_partial_parity (struct stripe_head *sh,struct raid5_percpu *percpu, +struct dma_async_tx_descriptor *tx) +{ +int disks = sh->disks; +struct page **xor_srcs =flex_array_get (percpu->scribble,0 ); +int count =0 , pd_idx = sh->pd_idx, i; +struct async_submit_ctl submit; + +pr_debug ("%s: stripe %llu\n" , __func__, (unsigned long long )sh->sector); + +/* +* Partial parity is the XOR of stripe data chunks that are not changed +* during the write request. Depending on available data +* (read-modify-write vs. reconstruct-write case) we calculate it +* differently. +*/ +if (sh->reconstruct_state == reconstruct_state_prexor_drain_run) { +/* rmw: xor old data and parity from updated disks */ +for (i = disks; i--;) { +struct r5dev *dev = &sh->dev[i]; +if (test_bit (R5_Wantdrain, &dev->flags) || i == pd_idx) + xor_srcs[count++] = dev->page; + } + }else if (sh->reconstruct_state == reconstruct_state_drain_run) { +/* rcw: xor data from all not updated disks */ +for (i = disks; i--;) { +struct r5dev *dev = &sh->dev[i]; +if (test_bit (R5_UPTODATE , &dev->flags)) + xor_srcs[count++] = dev->page; + } + }else {Quoted 8 lines
drivers/md/raid5-ppl.c line 182
Quoted 6 lines
drivers/md/raid5-ppl.c new file +6
-0+return tx; + } + +init_async_submit (&submit,ASYNC_TX_XOR_ZERO_DST , tx,NULL , sh, +flex_array_get (percpu->scribble,0 ) + +sizeof (struct page *) * (sh->disks +2 ));Since this should be done before biodrain, should this add
ASYNC_TX_FENCEflag?
Quoted 4 lines
The result of this calculation isn't used later by other
async_txoperations, so it's not needed here, if I understand this correctly. But maybe later we could optimize and use partial parity to calculate full parity, then it will be necessary.
But the source pages will be overwritten soon, if no fence, I think this is a problem. Anyway, I'll let Dan to clarify.
Dan,
We are using async API for below operations:
1. xor several source pages to a dest page
2. memcpy other data to the source pages
The two operations will be in an async chain. Should the first operation include ASYNC_TX_FENCE flag? The API comment declares the flag is required if the destination page is used by subsequent operations, but I suspect it should be used too if the subsequent operations could change the source pages.
Thanks,
Shaohua
Re: [PATCH v5 3/7] raid5-ppl: Partial Parity Log write logging implementation
Quoted 93 lines · Shaohua Li
Quoted 79 lines · Artur Paszkiewicz
Quoted 69 lines · Shaohua Li
Quoted 33 lines · Artur Paszkiewicz
Implement the calculation of partial parity for a stripe and PPL write logging functionality. The description of PPL is added to the documentation. More details can be found in the comments in
raid5-ppl.c.Attach a page for holding the partial parity data to
stripe_head. Allocate it only if mddev has theMD_HAS_PPLflag set.Partial parity is the xor of not modified data chunks of a stripe and is calculated as follows:
- reconstruct-write case:
xor data from all not updated disks in a stripe- read-modify-write case:
xor old data and parity from all updated disks in a stripeImplement it using the
async_txAPI and integrate intoraid_run_ops(). It must be called when we still have access to old data, so do it whenSTRIPE_OP_BIODRAINis set, but beforeops_run_prexor5(). The result is stored intosh->ppl_page.Partial parity is not meaningful for full stripe write and is not stored in the log or used for recovery, so don't attempt to calculate it when stripe has
STRIPE_FULL_WRITE.Put the PPL metadata structures to
md_p.hbecause userspace tools (mdadm) will also need to read/write PPL.Warn about using PPL with enabled disk volatile write-back cache for now. It can be removed once disk cache flushing before writing PPL is implemented.
Signed-off-by Artur Paszkiewicz <[email protected]>... snip ...
Quoted 32 lines
drivers/md/raid5-ppl.c new file +32
-0+struct dma_async_tx_descriptor * +ops_run_partial_parity (struct stripe_head *sh,struct raid5_percpu *percpu, +struct dma_async_tx_descriptor *tx) +{ +int disks = sh->disks; +struct page **xor_srcs =flex_array_get (percpu->scribble,0 ); +int count =0 , pd_idx = sh->pd_idx, i; +struct async_submit_ctl submit; + +pr_debug ("%s: stripe %llu\n" , __func__, (unsigned long long )sh->sector); + +/* +* Partial parity is the XOR of stripe data chunks that are not changed +* during the write request. Depending on available data +* (read-modify-write vs. reconstruct-write case) we calculate it +* differently. +*/ +if (sh->reconstruct_state == reconstruct_state_prexor_drain_run) { +/* rmw: xor old data and parity from updated disks */ +for (i = disks; i--;) { +struct r5dev *dev = &sh->dev[i]; +if (test_bit (R5_Wantdrain, &dev->flags) || i == pd_idx) + xor_srcs[count++] = dev->page; + } + }else if (sh->reconstruct_state == reconstruct_state_drain_run) { +/* rcw: xor data from all not updated disks */ +for (i = disks; i--;) { +struct r5dev *dev = &sh->dev[i]; +if (test_bit (R5_UPTODATE , &dev->flags)) + xor_srcs[count++] = dev->page; + } + }else {Quoted 8 lines
drivers/md/raid5-ppl.c line 182
Quoted 6 lines
drivers/md/raid5-ppl.c new file +6
-0+return tx; + } + +init_async_submit (&submit,ASYNC_TX_XOR_ZERO_DST , tx,NULL , sh, +flex_array_get (percpu->scribble,0 ) + +sizeof (struct page *) * (sh->disks +2 ));Since this should be done before biodrain, should this add
ASYNC_TX_FENCEflag?Quoted 4 lines
The result of this calculation isn't used later by other
async_txoperations, so it's not needed here, if I understand this correctly. But maybe later we could optimize and use partial parity to calculate full parity, then it will be necessary.But the source pages will be overwritten soon, if no fence, I think this is a problem. Anyway, I'll let Dan to clarify.
Dan,
We are using async API for below operations:
1. xor several source pages to a dest page
2. memcpy other data to the source pages
Quoted 4 lines
The two operations will be in an async chain. Should the first operation include
ASYNC_TX_FENCEflag? The API comment declares the flag is required if the destination page is used by subsequent operations, but I suspect it should be used too if the subsequent operations could change the source pages.
I think you're right. If operation2 could change operation1 source data we should include the fence.
Re: [PATCH v5 3/7] raid5-ppl: Partial Parity Log write logging implementation
In reply to Artur PaszkiewiczQuoted 25 lines · Artur Paszkiewicz
Implement the calculation of partial parity for a stripe and PPL write logging functionality. The description of PPL is added to the documentation. More details can be found in the comments in
raid5-ppl.c.Attach a page for holding the partial parity data to
stripe_head. Allocate it only if mddev has theMD_HAS_PPLflag set.Partial parity is the xor of not modified data chunks of a stripe and is calculated as follows:
- reconstruct-write case:
xor data from all not updated disks in a stripe- read-modify-write case:
xor old data and parity from all updated disks in a stripeImplement it using the
async_txAPI and integrate intoraid_run_ops(). It must be called when we still have access to old data, so do it whenSTRIPE_OP_BIODRAINis set, but beforeops_run_prexor5(). The result is stored intosh->ppl_page.Partial parity is not meaningful for full stripe write and is not stored in the log or used for recovery, so don't attempt to calculate it when stripe has
STRIPE_FULL_WRITE.
Quoted 8 lines
Put the PPL metadata structures to
md_p.hbecause userspace tools (mdadm) will also need to read/write PPL.Warn about using PPL with enabled disk volatile write-back cache for now. It can be removed once disk cache flushing before writing PPL is implemented.
Signed-off-by Artur Paszkiewicz <[email protected]>
Sorry for the delay in getting to this for review...
Quoted 9 lines
drivers/md/raid5-ppl.c new file +9
-0+static struct ppl_io_unit *ppl_new_iounit (struct ppl_log *log, +struct stripe_head *sh) +{ +struct ppl_conf *ppl_conf = log->ppl_conf; +struct ppl_io_unit *io; +struct ppl_header *pplhdr; + + io =mempool_alloc (ppl_conf->io_pool,GFP_ATOMIC ); +if (!io)
drivers/md/raid5-ppl.c line 212
Quoted 10 lines
drivers/md/raid5-ppl.c new file +10
-0+return NULL ; + +memset (io,0 ,sizeof (*io)); + io->log = log; +INIT_LIST_HEAD (&io->log_sibling); +INIT_LIST_HEAD (&io->stripe_list); +atomic_set (&io->pending_stripes,0 ); +bio_init (&io->bio, io->biovec,PPL_IO_INLINE_BVECS ); + + io->header_page =mempool_alloc (ppl_conf->meta_pool,GFP_NOIO );
I'm trying to understand how these two mempool_alloc()s relate, and particularly why the first one needs to be GFP_ATOMIC, while the second one can safely be GFP_NOIO.
I see that the allocated memory is freed in different places:header_page is called from the bi_endio function as soon as the write completes, while 'io' is freed later. But I'm not sure that is enough to make it safe.
When working with mempools, you need to assume that the pool only contains one element, and that every time you call mempool_alloc(), it waits for that one element to be available. While that doesn't usually happen, it is possible and if that case isn't handled correctly, the system can deadlock.
If no memory is available when this mempool_alloc() is called, it will block. As it is called from the raid5d thread, the whole array will block. So this can only complete safely is the write request has already been submitted - or if there is some other workqueue which submit requests after a timeout or similar.
I don't see that in the code. These ppl_io_unit structures can queue up and are only submitted later by raid5d (I think). So if raid5d waits for one to become free, it will wait forever.
One easy way around this problem (assuming my understanding is correct) is to just have a single mempool which allocates both a struct ppl_io_unit and a page. You would need to define you own alloc/free routines for the pool but that is easy enough.
Then you only need a single mempool_alloc(), which can sensibly be GFP_ATOMIC.
If that fails, you queue for later handling as you do now. If it succeeds, then you continue to use the memory without any risk of deadlocking.
Thanks,
NeilBrown
Quoted 10 lines
drivers/md/raid5-ppl.c new file +10
-0+ pplhdr =page_address (io->header_page); +clear_page (pplhdr); +memset (pplhdr->reserved,0xff ,PPL_HDR_RESERVED ); + pplhdr->signature =cpu_to_le32 (ppl_conf->signature); + + io->seq =atomic64_add_return (1 , &ppl_conf->seq); + pplhdr->generation =cpu_to_le64 (io->seq); + +return io; +}
Re: [PATCH v5 3/7] raid5-ppl: Partial Parity Log write logging implementation
Quoted 86 lines · Neil Brown
Quoted 25 lines · Artur Paszkiewicz
Implement the calculation of partial parity for a stripe and PPL write logging functionality. The description of PPL is added to the documentation. More details can be found in the comments in
raid5-ppl.c.Attach a page for holding the partial parity data to
stripe_head. Allocate it only if mddev has theMD_HAS_PPLflag set.Partial parity is the xor of not modified data chunks of a stripe and is calculated as follows:
- reconstruct-write case:
xor data from all not updated disks in a stripe- read-modify-write case:
xor old data and parity from all updated disks in a stripeImplement it using the
async_txAPI and integrate intoraid_run_ops(). It must be called when we still have access to old data, so do it whenSTRIPE_OP_BIODRAINis set, but beforeops_run_prexor5(). The result is stored intosh->ppl_page.Partial parity is not meaningful for full stripe write and is not stored in the log or used for recovery, so don't attempt to calculate it when stripe has
STRIPE_FULL_WRITE.Quoted 8 lines
Put the PPL metadata structures to
md_p.hbecause userspace tools (mdadm) will also need to read/write PPL.Warn about using PPL with enabled disk volatile write-back cache for now. It can be removed once disk cache flushing before writing PPL is implemented.
Signed-off-by Artur Paszkiewicz <[email protected]>Sorry for the delay in getting to this for review...
Quoted 9 lines
drivers/md/raid5-ppl.c new file +9
-0+static struct ppl_io_unit *ppl_new_iounit (struct ppl_log *log, +struct stripe_head *sh) +{ +struct ppl_conf *ppl_conf = log->ppl_conf; +struct ppl_io_unit *io; +struct ppl_header *pplhdr; + + io =mempool_alloc (ppl_conf->io_pool,GFP_ATOMIC ); +if (!io)drivers/md/raid5-ppl.c line 212
Quoted 10 lines
drivers/md/raid5-ppl.c new file +10
-0+return NULL ; + +memset (io,0 ,sizeof (*io)); + io->log = log; +INIT_LIST_HEAD (&io->log_sibling); +INIT_LIST_HEAD (&io->stripe_list); +atomic_set (&io->pending_stripes,0 ); +bio_init (&io->bio, io->biovec,PPL_IO_INLINE_BVECS ); + + io->header_page =mempool_alloc (ppl_conf->meta_pool,GFP_NOIO );I'm trying to understand how these two mempool_alloc()s relate, and particularly why the first one needs to be
GFP_ATOMIC, while the second one can safely beGFP_NOIO.
I see that the allocated memory is freed in different places:header_pageis called from thebi_endiofunction as soon as the write completes, while 'io' is freed later. But I'm not sure that is enough to make it safe.When working with mempools, you need to assume that the pool only contains one element, and that every time you call
mempool_alloc(), it waits for that one element to be available. While that doesn't usually happen, it is possible and if that case isn't handled correctly, the system can deadlock.If no memory is available when this
mempool_alloc()is called, it will block. As it is called from the raid5d thread, the whole array will block. So this can only complete safely is the write request has already been submitted - or if there is some other workqueue which submit requests after a timeout or similar.
I don't see that in the code. Theseppl_io_unitstructures can queue up and are only submitted later by raid5d (I think). So if raid5d waits for one to become free, it will wait forever.One easy way around this problem (assuming my understanding is correct) is to just have a single mempool which allocates both a struct
ppl_io_unitand a page. You would need to define you own alloc/free routines for the pool but that is easy enough.
Quoted 5 lines
Then you only need a single
mempool_alloc(), which can sensibly beGFP_ATOMIC.
If that fails, you queue for later handling as you do now. If it succeeds, then you continue to use the memory without any risk of deadlocking.
Maybe Artur is following the raid5-cache code, which uses GFP_ATOMIC with
commit: 5036c39(raid5: allow r5l_io_unit allocations to fail). A single pool does make sense.
Thanks,
Shaohua
Re: [PATCH v5 3/7] raid5-ppl: Partial Parity Log write logging implementation
Quoted 93 lines · Shaohua Li
Quoted 86 lines · Neil Brown
Quoted 25 lines · Artur Paszkiewicz
Implement the calculation of partial parity for a stripe and PPL write logging functionality. The description of PPL is added to the documentation. More details can be found in the comments in
raid5-ppl.c.Attach a page for holding the partial parity data to
stripe_head. Allocate it only if mddev has theMD_HAS_PPLflag set.Partial parity is the xor of not modified data chunks of a stripe and is calculated as follows:
- reconstruct-write case:
xor data from all not updated disks in a stripe- read-modify-write case:
xor old data and parity from all updated disks in a stripeImplement it using the
async_txAPI and integrate intoraid_run_ops(). It must be called when we still have access to old data, so do it whenSTRIPE_OP_BIODRAINis set, but beforeops_run_prexor5(). The result is stored intosh->ppl_page.Partial parity is not meaningful for full stripe write and is not stored in the log or used for recovery, so don't attempt to calculate it when stripe has
STRIPE_FULL_WRITE.Quoted 8 lines
Put the PPL metadata structures to
md_p.hbecause userspace tools (mdadm) will also need to read/write PPL.Warn about using PPL with enabled disk volatile write-back cache for now. It can be removed once disk cache flushing before writing PPL is implemented.
Signed-off-by Artur Paszkiewicz <[email protected]>Sorry for the delay in getting to this for review...
Quoted 9 lines
drivers/md/raid5-ppl.c new file +9
-0+static struct ppl_io_unit *ppl_new_iounit (struct ppl_log *log, +struct stripe_head *sh) +{ +struct ppl_conf *ppl_conf = log->ppl_conf; +struct ppl_io_unit *io; +struct ppl_header *pplhdr; + + io =mempool_alloc (ppl_conf->io_pool,GFP_ATOMIC ); +if (!io)drivers/md/raid5-ppl.c line 212
Quoted 10 lines
drivers/md/raid5-ppl.c new file +10
-0+return NULL ; + +memset (io,0 ,sizeof (*io)); + io->log = log; +INIT_LIST_HEAD (&io->log_sibling); +INIT_LIST_HEAD (&io->stripe_list); +atomic_set (&io->pending_stripes,0 ); +bio_init (&io->bio, io->biovec,PPL_IO_INLINE_BVECS ); + + io->header_page =mempool_alloc (ppl_conf->meta_pool,GFP_NOIO );I'm trying to understand how these two mempool_alloc()s relate, and particularly why the first one needs to be
GFP_ATOMIC, while the second one can safely beGFP_NOIO.
I see that the allocated memory is freed in different places:header_pageis called from thebi_endiofunction as soon as the write completes, while 'io' is freed later. But I'm not sure that is enough to make it safe.When working with mempools, you need to assume that the pool only contains one element, and that every time you call
mempool_alloc(), it waits for that one element to be available. While that doesn't usually happen, it is possible and if that case isn't handled correctly, the system can deadlock.If no memory is available when this
mempool_alloc()is called, it will block. As it is called from the raid5d thread, the whole array will block. So this can only complete safely is the write request has already been submitted - or if there is some other workqueue which submit requests after a timeout or similar.
I don't see that in the code. Theseppl_io_unitstructures can queue up and are only submitted later by raid5d (I think). So if raid5d waits for one to become free, it will wait forever.One easy way around this problem (assuming my understanding is correct) is to just have a single mempool which allocates both a struct
ppl_io_unitand a page. You would need to define you own alloc/free routines for the pool but that is easy enough.Quoted 5 lines
Then you only need a single
mempool_alloc(), which can sensibly beGFP_ATOMIC.
If that fails, you queue for later handling as you do now. If it succeeds, then you continue to use the memory without any risk of deadlocking.
Quoted 3 lines
Maybe Artur is following the raid5-cache code, which uses
GFP_ATOMICwith
commit: 5036c39(raid5: allowr5l_io_unitallocations to fail). A single pool does make sense.
That's right, I based this on raid5-cache code. I like the approach that Neil proposed, I'll test it some more and probably send a patch soon. Do you think GFP_ATOMIC is necessary here or would GFP_NOWAIT be enough?
Thanks,
Artur
Re: [PATCH v5 3/7] raid5-ppl: Partial Parity Log write logging implementation
Quoted 94 lines · Artur Paszkiewicz
Quoted 93 lines · Shaohua Li
Quoted 91 lines · Neil Brown
Quoted 25 lines · Artur Paszkiewicz
Implement the calculation of partial parity for a stripe and PPL write logging functionality. The description of PPL is added to the documentation. More details can be found in the comments in
raid5-ppl.c.Attach a page for holding the partial parity data to
stripe_head. Allocate it only if mddev has theMD_HAS_PPLflag set.Partial parity is the xor of not modified data chunks of a stripe and is calculated as follows:
- reconstruct-write case:
xor data from all not updated disks in a stripe- read-modify-write case:
xor old data and parity from all updated disks in a stripeImplement it using the
async_txAPI and integrate intoraid_run_ops(). It must be called when we still have access to old data, so do it whenSTRIPE_OP_BIODRAINis set, but beforeops_run_prexor5(). The result is stored intosh->ppl_page.Partial parity is not meaningful for full stripe write and is not stored in the log or used for recovery, so don't attempt to calculate it when stripe has
STRIPE_FULL_WRITE.Quoted 8 lines
Put the PPL metadata structures to
md_p.hbecause userspace tools (mdadm) will also need to read/write PPL.Warn about using PPL with enabled disk volatile write-back cache for now. It can be removed once disk cache flushing before writing PPL is implemented.
Signed-off-by Artur Paszkiewicz <[email protected]>Sorry for the delay in getting to this for review...
Quoted 9 lines
drivers/md/raid5-ppl.c new file +9
-0+static struct ppl_io_unit *ppl_new_iounit (struct ppl_log *log, +struct stripe_head *sh) +{ +struct ppl_conf *ppl_conf = log->ppl_conf; +struct ppl_io_unit *io; +struct ppl_header *pplhdr; + + io =mempool_alloc (ppl_conf->io_pool,GFP_ATOMIC ); +if (!io)drivers/md/raid5-ppl.c line 212
Quoted 10 lines
drivers/md/raid5-ppl.c new file +10
-0+return NULL ; + +memset (io,0 ,sizeof (*io)); + io->log = log; +INIT_LIST_HEAD (&io->log_sibling); +INIT_LIST_HEAD (&io->stripe_list); +atomic_set (&io->pending_stripes,0 ); +bio_init (&io->bio, io->biovec,PPL_IO_INLINE_BVECS ); + + io->header_page =mempool_alloc (ppl_conf->meta_pool,GFP_NOIO );I'm trying to understand how these two mempool_alloc()s relate, and particularly why the first one needs to be
GFP_ATOMIC, while the second one can safely beGFP_NOIO.
I see that the allocated memory is freed in different places:header_pageis called from thebi_endiofunction as soon as the write completes, while 'io' is freed later. But I'm not sure that is enough to make it safe.When working with mempools, you need to assume that the pool only contains one element, and that every time you call
mempool_alloc(), it waits for that one element to be available. While that doesn't usually happen, it is possible and if that case isn't handled correctly, the system can deadlock.If no memory is available when this
mempool_alloc()is called, it will block. As it is called from the raid5d thread, the whole array will block. So this can only complete safely is the write request has already been submitted - or if there is some other workqueue which submit requests after a timeout or similar.
I don't see that in the code. Theseppl_io_unitstructures can queue up and are only submitted later by raid5d (I think). So if raid5d waits for one to become free, it will wait forever.One easy way around this problem (assuming my understanding is correct) is to just have a single mempool which allocates both a struct
ppl_io_unitand a page. You would need to define you own alloc/free routines for the pool but that is easy enough.Then you only need a single
mempool_alloc(), which can sensibly beGFP_ATOMIC.
If that fails, you queue for later handling as you do now. If it succeeds, then you continue to use the memory without any risk of deadlocking.
Quoted 7 lines
Quoted 3 lines
Maybe Artur is following the raid5-cache code, which uses
GFP_ATOMICwith
commit: 5036c39(raid5: allowr5l_io_unitallocations to fail). A single pool does make sense.That's right, I based this on raid5-cache code. I like the approach that Neil proposed, I'll test it some more and probably send a patch soon. Do you think
GFP_ATOMICis necessary here or wouldGFP_NOWAITbe enough?
Since we can handle error, I don't see the reason why we should use GFP_ATOMIC, GFP_NOWAIT is good to me.
Thanks,
Shaohua
Re: [PATCH v5 3/7] raid5-ppl: Partial Parity Log write logging implementation
In reply to Artur PaszkiewiczQuoted 27 lines · Artur Paszkiewicz
Implement the calculation of partial parity for a stripe and PPL write logging functionality. The description of PPL is added to the documentation. More details can be found in the comments in
raid5-ppl.c.Attach a page for holding the partial parity data to
stripe_head. Allocate it only if mddev has theMD_HAS_PPLflag set.Partial parity is the xor of not modified data chunks of a stripe and is calculated as follows:
- reconstruct-write case:
xor data from all not updated disks in a stripe- read-modify-write case:
xor old data and parity from all updated disks in a stripeImplement it using the
async_txAPI and integrate intoraid_run_ops(). It must be called when we still have access to old data, so do it whenSTRIPE_OP_BIODRAINis set, but beforeops_run_prexor5(). The result is stored intosh->ppl_page.Partial parity is not meaningful for full stripe write and is not stored in the log or used for recovery, so don't attempt to calculate it when stripe has
STRIPE_FULL_WRITE.Put the PPL metadata structures to
md_p.hbecause userspace tools (mdadm) will also need to read/write PPL.
...
Quoted 12 lines
include/uapi/linux/raid/md_p.h +4
-0@@ -398,4 +398,31 @@ struct r5l_meta_block {#define R5LOG_VERSION 0x1#define R5LOG_MAGIC 0x6433c509 + +struct ppl_header_entry { +__le64 data_sector;/* raid sector of the new data */ +__le32 pp_size;/* length of partial parity */
include/uapi/linux/raid/md_p.h struct r5l_meta_block { · line 414
Quoted 10 lines
include/uapi/linux/raid/md_p.h +10
-0+__le32 data_size;/* length of data */ +__le32 parity_disk;/* member disk containing parity */ +__le32 checksum;/* checksum of partial parity data for this +* entry (~crc32c) */ +} __attribute__ ((__packed__)); + +#define PPL_HEADER_SIZE 4096 +#define PPL_HDR_RESERVED 512 +#define PPL_HDR_ENTRY_SPACE \ + (PPL_HEADER_SIZE - PPL_HDR_RESERVED - 4 * sizeof(u32) - sizeof(u64))
PPL_HDR_ENTRY_SPACE is ostensibly a function of the ppl_header structure fields. Can we use its field types: e.g. __le32 rather than u32.
This fixes klibc build error:
In file included from /klibc/usr/klibc/../include/sys/md.h:30:0,
from /klibc/usr/kinit/do_mounts_md.c:19:
/linux-next/usr/include/linux/raid/md_p.h:414:51: error: 'u32' undeclared here (not in a function)
(PPL_HEADER_SIZE - PPL_HDR_RESERVED - 4 * sizeof(u32) - sizeof(u64)) #define PPL_HDR_ENTRY_SPACE \
- (PPL_HEADER_SIZE - PPL_HDR_RESERVED - 4 * sizeof(u32) - sizeof(u64))
+ (PPL_HEADER_SIZE - PPL_HDR_RESERVED - 4 * sizeof(__le32) - sizeof(__le64))
Quoted 14 lines
include/uapi/linux/raid/md_p.h +13
-0+#define PPL_HDR_MAX_ENTRIES \ + (PPL_HDR_ENTRY_SPACE / sizeof(struct ppl_header_entry)) + +struct ppl_header { +__u8 reserved[PPL_HDR_RESERVED ];/* reserved space, fill with 0xff */ +__le32 signature;/* signature (family number of volume) */ +__le32 padding;/* zero pad */ +__le64 generation;/* generation number of the header */ +__le32 entries_count;/* number of entries in entry array */ +__le32 checksum;/* checksum of the header (~crc32c) */ +struct ppl_header_entry entries[PPL_HDR_MAX_ENTRIES ]; +} __attribute__ ((__packed__ )); +#endif
PATCH 1/1 uapi: fix linux/raid/md_p.h userspace compilation error
Use __le32 and __le64 instead of u32 and u64.
This fixes klibc build error:
In file included from /klibc/usr/klibc/../include/sys/md.h:30:0,
from /klibc/usr/kinit/do_mounts_md.c:19:
/linux-next/usr/include/linux/raid/md_p.h:414:51: error: 'u32' undeclared here (not in a function)
(PPL_HEADER_SIZE - PPL_HDR_RESERVED - 4 * sizeof(u32) - sizeof(u64))--- include/uapi/linux/raid/md_p.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/uapi/linux/raid/md_p.h +1 -1
@@ -411,7 +411,7 @@ struct ppl_header_entry {#define PPL_HEADER_SIZE 4096#define PPL_HDR_RESERVED 512#define PPL_HDR_ENTRY_SPACE \ - (PPL_HEADER_SIZE - PPL_HDR_RESERVED - 4 * sizeof(u32) - sizeof(u64)) + (PPL_HEADER_SIZE - PPL_HDR_RESERVED - 4 * sizeof(__le32) - sizeof(__le64))#define PPL_HDR_MAX_ENTRIES \ (PPL_HDR_ENTRY_SPACE / sizeof(struct ppl_header_entry))
Signature · 1 line
2.11.0
Re: [PATCH] uapi: fix linux/raid/md_p.h userspace compilation error
Quoted 11 lines · Artur Paszkiewicz
Use
__le32and__le64instead of u32 and u64.This fixes klibc build error:
In file included from /klibc/usr/klibc/../include/sys/md.h:30:0,from /klibc/usr/kinit/do_mounts_md.c:19: /linux-next/usr/include/linux/raid/md_p.h:414:51: error: 'u32' undeclared here (not in a function) (PPL_HEADER_SIZE - PPL_HDR_RESERVED - 4 * sizeof(u32) - sizeof(u64))Reported-by Greg Thelen <[email protected]>Reported-by Nigel Croxon <[email protected]>Signed-off-by Artur Paszkiewicz <[email protected]>
My klibc builds are working again. Thanks.
Shaohua Li
AppliedRe: [PATCH] uapi: fix linux/raid/md_p.h userspace compilation error
In reply to Artur PaszkiewiczQuoted 7 lines · Artur Paszkiewicz
Use
__le32and__le64instead of u32 and u64.This fixes klibc build error:
In file included from /klibc/usr/klibc/../include/sys/md.h:30:0,from /klibc/usr/kinit/do_mounts_md.c:19: /linux-next/usr/include/linux/raid/md_p.h:414:51: error: 'u32' undeclared here (not in a function) (PPL_HEADER_SIZE - PPL_HDR_RESERVED - 4 * sizeof(u32) - sizeof(u64))
applied, thanks!
Quoted 27 lines
Reported-by Greg Thelen <[email protected]>Reported-by Nigel Croxon <[email protected]>Signed-off-by Artur Paszkiewicz <[email protected]>--- include/uapi/linux/raid/md_p.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/uapi/linux/raid/md_p.h +1
-1@@ -411,7 +411,7 @@ struct ppl_header_entry {#define PPL_HEADER_SIZE 4096#define PPL_HDR_RESERVED 512#define PPL_HDR_ENTRY_SPACE \ - (PPL_HEADER_SIZE - PPL_HDR_RESERVED - 4 * sizeof(u32) - sizeof(u64)) + (PPL_HEADER_SIZE - PPL_HDR_RESERVED - 4 * sizeof(__le32) - sizeof(__le64))#define PPL_HDR_MAX_ENTRIES \ (PPL_HDR_ENTRY_SPACE / sizeof(struct ppl_header_entry))Signature · 6 lines
2.11.0 -- To unsubscribe from this list: send the line "unsubscribe linux-raid" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v5 4/7 md: add sysfs entries for PPL
In reply to Artur PaszkiewiczAdd 'consistency_policy' attribute for array. It indicates how the array maintains consistency in case of unexpected shutdown.
Add 'ppl_sector' and 'ppl_size' for rdev, which describe the location and size of the PPL space on the device. They can't be changed for active members if the array is started and PPL is enabled, so in the setter functions only basic checks are performed. More checks are done in ppl_validate_rdev() when starting the log.
These attributes are writable to allow enabling PPL for external metadata arrays and (later) to enable/disable PPL for a running array.
--- Documentation/admin-guide/md.rst | 32 ++++++++++- drivers/md/md.c | 115 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 144 insertions(+), 3 deletions(-)
Documentation/admin-guide/md.rst +29 -3
@@ -276,14 +276,14 @@ All md devices contain: array creation it will default to 0, though starting the array as ``clean`` will set it much larger. - new_dev + new_dev This file can be written but not read. The value written should be a block device number as major:minor. e.g. 8:0 This will cause that device to be attached to the array, if it is available. It will then appear at md/dev-XXX (depending on the name of the device) and further configuration is then possible. - safe_mode_delay + safe_mode_delay When an md array has seen no write requests for a certain period of time, it will be marked as ``clean``. When another write request arrives, the array is marked as ``dirty`` before the write
@@ -292,7 +292,7 @@ All md devices contain: period as a number of seconds. The default is 200msec (0.200). Writing a value of 0 disables safemode. - array_state + array_state This file contains a single word which describes the current state of the array. In many cases, the state can be set by writing the word for the desired state, however some states
@@ -401,7 +401,30 @@ All md devices contain: once the array becomes non-degraded, and this fact has been recorded in the metadata. + consistency_policy + This indicates how the array maintains consistency in case of unexpected + shutdown. It can be: + none + Array has no redundancy information, e.g. raid0, linear. + + resync + Full resync is performed and all redundancy is regenerated when the + array is started after unclean shutdown. + + bitmap + Resync assisted by a write-intent bitmap. + + journal + For raid4/5/6, journal device is used to log transactions and replay + after unclean shutdown. + + ppl + For raid5 only, Partial Parity Log is used to close the write hole and + eliminate resync. + + The accepted values when writing to this file are ``ppl`` and ``resync``, + used to enable and disable PPL. As component devices are added to an md array, they appear in the ``md``
@@ -563,6 +586,9 @@ Each directory contains: adds bad blocks without acknowledging them. This is largely for testing. + ppl_sector, ppl_size + Location and size (in sectors) of the space used for Partial Parity Log + on this device. An active md device will also contain an entry for each active device
drivers/md/md.c +115 -0
139 lines not on this page · raw message
Signature · 1 line
2.11.0
PATCH v5 5/7 raid5-ppl: load and recover the log
In reply to Artur PaszkiewiczLoad the log from each disk when starting the array and recover if the array is dirty.
The initial empty PPL is written by mdadm. When loading the log we verify the header checksum and signature. For external metadata arrays the signature is verified in userspace, so here we read it from the header, verifying only if it matches on all disks, and use it later when writing PPL.
In addition to the header checksum, each header entry also contains a checksum of its partial parity data. If the header is valid, recovery is performed for each entry until an invalid entry is found. If the array is not degraded and recovery using PPL fully succeeds, there is no need to resync the array because data and parity will be consistent, so in this case resync will be disabled.
Due to compatibility with IMSM implementations on other systems, we can't assume that the recovery data block size is always 4K. Writes generated by MD raid5 don't have this issue, but when recovering PPL written in other environments it is possible to have entries with 512-byte sector granularity. The recovery code takes this into account and also the logical sector size of the underlying drives.
--- drivers/md/raid5-ppl.c | 497 +++++++++++++++++++++++++++++++++++++++++++++++++ drivers/md/raid5.c | 5 +- 2 files changed, 501 insertions(+), 1 deletion(-)
drivers/md/raid5-ppl.c +497 -0
@@ -103,6 +103,10 @@ struct ppl_conf {mempool_t *io_pool;struct bio_set *bs;mempool_t *meta_pool; + +/* used only for recovery */ +int recovered_entries; +int mismatch_count; };struct ppl_log {
@@ -514,6 +518,482 @@ void ppl_stripe_write_finished(struct stripe_head *sh)ppl_io_unit_finished (io); } +static void ppl_xor (int size,struct page *page1,struct page *page2, +struct page *page_result) +{ +struct async_submit_ctl submit; +struct dma_async_tx_descriptor *tx; +struct page *xor_srcs[] = { page1, page2 }; + +init_async_submit (&submit,ASYNC_TX_ACK |ASYNC_TX_XOR_DROP_DST , +NULL ,NULL ,NULL ,NULL ); + tx =async_xor (page_result, xor_srcs,0 ,2 , size, &submit); + +async_tx_quiesce (&tx); +} + +/* +* PPL recovery strategy: xor partial parity and data from all modified data +* disks within a stripe and write the result as the new stripe parity. If all +* stripe data disks are modified (full stripe write), no partial parity is +* available, so just xor the data disks. +* +* Recovery of a PPL entry shall occur only if all modified data disks are +* available and read from all of them succeeds. +* +* A PPL entry applies to a stripe, partial parity size for an entry is at most +* the size of the chunk. Examples of possible cases for a single entry: +* +* case 0: single data disk write: +* data0 data1 data2 ppl parity +* +--------+--------+--------+ +--------------------+ +* | ------ | ------ | ------ | +----+ | (no change) | +* | ------ | -data- | ------ | | pp | -> | data1 ^ pp | +* | ------ | -data- | ------ | | pp | -> | data1 ^ pp | +* | ------ | ------ | ------ | +----+ | (no change) | +* +--------+--------+--------+ +--------------------+ +* pp_size = data_size +* +* case 1: more than one data disk write: +* data0 data1 data2 ppl parity +* +--------+--------+--------+ +--------------------+ +* | ------ | ------ | ------ | +----+ | (no change) | +* | -data- | -data- | ------ | | pp | -> | data0 ^ data1 ^ pp | +* | -data- | -data- | ------ | | pp | -> | data0 ^ data1 ^ pp | +* | ------ | ------ | ------ | +----+ | (no change) | +* +--------+--------+--------+ +--------------------+ +* pp_size = data_size / modified_data_disks +* +* case 2: write to all data disks (also full stripe write): +* data0 data1 data2 parity +* +--------+--------+--------+ +--------------------+ +* | ------ | ------ | ------ | | (no change) | +* | -data- | -data- | -data- | --------> | xor all data | +* | ------ | ------ | ------ | --------> | (no change) | +* | ------ | ------ | ------ | | (no change) | +* +--------+--------+--------+ +--------------------+ +* pp_size = 0 +* +* The following cases are possible only in other implementations. The recovery +* code can handle them, but they are not generated at runtime because they can +* be reduced to cases 0, 1 and 2: +* +* case 3: +* data0 data1 data2 ppl parity +* +--------+--------+--------+ +----+ +--------------------+ +* | ------ | -data- | -data- | | pp | | data1 ^ data2 ^ pp | +* | ------ | -data- | -data- | | pp | -> | data1 ^ data2 ^ pp | +* | -data- | -data- | -data- | | -- | -> | xor all data | +* | -data- | -data- | ------ | | pp | | data0 ^ data1 ^ pp | +* +--------+--------+--------+ +----+ +--------------------+ +* pp_size = chunk_size +* +* case 4: +* data0 data1 data2 ppl parity +* +--------+--------+--------+ +----+ +--------------------+ +* | ------ | -data- | ------ | | pp | | data1 ^ pp | +* | ------ | ------ | ------ | | -- | -> | (no change) | +* | ------ | ------ | ------ | | -- | -> | (no change) | +* | -data- | ------ | ------ | | pp | | data0 ^ pp | +* +--------+--------+--------+ +----+ +--------------------+ +* pp_size = chunk_size +*/ +static int ppl_recover_entry (struct ppl_log *log,struct ppl_header_entry *e, +sector_t ppl_sector) +{ +struct ppl_conf *ppl_conf = log->ppl_conf; +struct mddev *mddev = ppl_conf->mddev; +struct r5conf *conf = mddev->private; +int block_size = ppl_conf->block_size; +struct page *page1; +struct page *page2; +sector_t r_sector_first; +sector_t r_sector_last; +int strip_sectors; +int data_disks; +int i; +int ret =0 ; +char b[BDEVNAME_SIZE ]; +unsigned int pp_size =le32_to_cpu (e->pp_size); +unsigned int data_size =le32_to_cpu (e->data_size); + + page1 =alloc_page (GFP_KERNEL ); + page2 =alloc_page (GFP_KERNEL ); + +if (!page1 || !page2) { + ret = -ENOMEM ; + goto out; + } + + r_sector_first =le64_to_cpu (e->data_sector) * (block_size >>9 ); + +if ((pp_size >>9 ) < conf->chunk_sectors) { +if (pp_size >0 ) { + data_disks = data_size / pp_size; + strip_sectors = pp_size >>9 ; + }else { + data_disks = conf->raid_disks - conf->max_degraded; + strip_sectors = (data_size >>9 ) / data_disks; + } + r_sector_last = r_sector_first + + (data_disks -1 ) * conf->chunk_sectors + + strip_sectors; + }else { + data_disks = conf->raid_disks - conf->max_degraded; + strip_sectors = conf->chunk_sectors; + r_sector_last = r_sector_first + (data_size >>9 ); + } + +pr_debug ("%s: array sector first: %llu last: %llu\n" , __func__, + (unsigned long long )r_sector_first, + (unsigned long long )r_sector_last); + +/* if start and end is 4k aligned, use a 4k block */ +if (block_size ==512 && + (r_sector_first & (STRIPE_SECTORS -1 )) ==0 && + (r_sector_last & (STRIPE_SECTORS -1 )) ==0 ) + block_size =STRIPE_SIZE ; + +/* iterate through blocks in strip */ +for (i =0 ; i < strip_sectors; i += (block_size >>9 )) { +bool update_parity = false; +sector_t parity_sector; +struct md_rdev *parity_rdev; +struct stripe_head sh; +int disk; +int indent =0 ; + +pr_debug ("%s:%*s iter %d start\n" , __func__, indent,"" , i); + indent +=2 ; + +memset (page_address (page1),0 ,PAGE_SIZE ); + +/* iterate through data member disks */ +for (disk =0 ; disk < data_disks; disk++) { +int dd_idx; +struct md_rdev *rdev; +sector_t sector; +sector_t r_sector = r_sector_first + i + + (disk * conf->chunk_sectors); + +pr_debug ("%s:%*s data member disk %d start\n" , + __func__, indent,"" , disk); + indent +=2 ; + +if (r_sector >= r_sector_last) { +pr_debug ("%s:%*s array sector %llu doesn't need parity update\n" , + __func__, indent,"" , + (unsigned long long )r_sector); + indent -=2 ; +continue ; + } + + update_parity = true; + +/* map raid sector to member disk */ + sector =raid5_compute_sector (conf, r_sector,0 , + &dd_idx,NULL ); +pr_debug ("%s:%*s processing array sector %llu => data member disk %d, sector %llu\n" , + __func__, indent,"" , + (unsigned long long )r_sector, dd_idx, + (unsigned long long )sector); + + rdev = conf->disks[dd_idx].rdev; +if (!rdev) { +pr_debug ("%s:%*s data member disk %d missing\n" , + __func__, indent,"" , dd_idx); + update_parity = false; +break ; + } + +pr_debug ("%s:%*s reading data member disk %s sector %llu\n" , + __func__, indent,"" ,bdevname (rdev->bdev, b), + (unsigned long long )sector); +if (!sync_page_io (rdev, sector, block_size, page2, +REQ_OP_READ ,0 , false)) { +md_error (mddev, rdev); +pr_debug ("%s:%*s read failed!\n" , __func__, + indent,"" ); + ret = -EIO ; + goto out; + } + +ppl_xor (block_size, page1, page2, page1); + + indent -=2 ; + } + +if (!update_parity) +continue ; + +if (pp_size >0 ) { +pr_debug ("%s:%*s reading pp disk sector %llu\n" , + __func__, indent,"" , + (unsigned long long )(ppl_sector + i)); +if (!sync_page_io (log->rdev, + ppl_sector - log->rdev->data_offset + i, + block_size, page2,REQ_OP_READ ,0 , + false)) { +pr_debug ("%s:%*s read failed!\n" , __func__, + indent,"" ); +md_error (mddev, log->rdev); + ret = -EIO ; + goto out; + } + +ppl_xor (block_size, page1, page2, page1); + } + +/* map raid sector to parity disk */ + parity_sector =raid5_compute_sector (conf, r_sector_first + i, +0 , &disk, &sh); +BUG_ON (sh.pd_idx !=le32_to_cpu (e->parity_disk)); + parity_rdev = conf->disks[sh.pd_idx].rdev; + +BUG_ON (parity_rdev->bdev->bd_dev != log->rdev->bdev->bd_dev); +pr_debug ("%s:%*s write parity at sector %llu, disk %s\n" , + __func__, indent,"" , + (unsigned long long )parity_sector, +bdevname (parity_rdev->bdev, b)); +if (!sync_page_io (parity_rdev, parity_sector, block_size, + page1,REQ_OP_WRITE ,0 , false)) { +pr_debug ("%s:%*s parity write error!\n" , __func__, + indent,"" ); +md_error (mddev, parity_rdev); + ret = -EIO ; + goto out; + } + } +out: +if (page1) +__free_page (page1); +if (page2) +__free_page (page2); +return ret; +} + +static int ppl_recover (struct ppl_log *log,struct ppl_header *pplhdr) +{ +struct ppl_conf *ppl_conf = log->ppl_conf; +struct md_rdev *rdev = log->rdev; +struct mddev *mddev = rdev->mddev; +sector_t ppl_sector = rdev->ppl.sector + (PPL_HEADER_SIZE >>9 ); +struct page *page; +int i; +int ret =0 ; + + page =alloc_page (GFP_KERNEL ); +if (!page) +return -ENOMEM ; + +/* iterate through all PPL entries saved */ +for (i =0 ; i <le32_to_cpu (pplhdr->entries_count); i++) { +struct ppl_header_entry *e = &pplhdr->entries[i]; +u32 pp_size =le32_to_cpu (e->pp_size); +sector_t sector = ppl_sector; +int ppl_entry_sectors = pp_size >>9 ; +u32 crc, crc_stored; + +pr_debug ("%s: disk: %d entry: %d ppl_sector: %llu pp_size: %u\n" , + __func__, rdev->raid_disk, i, + (unsigned long long )ppl_sector, pp_size); + + crc = ~0 ; + crc_stored =le32_to_cpu (e->checksum); + +/* read parial parity for this entry and calculate its checksum */ +while (pp_size) { +int s = pp_size >PAGE_SIZE ?PAGE_SIZE : pp_size; + +if (!sync_page_io (rdev, sector - rdev->data_offset, + s, page,REQ_OP_READ ,0 , false)) { +md_error (mddev, rdev); + ret = -EIO ; + goto out; + } + + crc =crc32c_le (crc,page_address (page), s); + + pp_size -= s; + sector += s >>9 ; + } + + crc = ~crc; + +if (crc != crc_stored) { +/* +* Don't recover this entry if the checksum does not +* match, but keep going and try to recover other +* entries. +*/ +pr_debug ("%s: ppl entry crc does not match: stored: 0x%x calculated: 0x%x\n" , + __func__, crc_stored, crc); + ppl_conf->mismatch_count++; + }else { + ret =ppl_recover_entry (log, e, ppl_sector); +if (ret) + goto out; + ppl_conf->recovered_entries++; + } + + ppl_sector += ppl_entry_sectors; + } + +/* flush the disk cache after recovery if necessary */ +if (test_bit (QUEUE_FLAG_WC , &bdev_get_queue (rdev->bdev)->queue_flags)) { +struct bio *bio =bio_alloc_bioset (GFP_KERNEL ,0 , ppl_conf->bs); + + bio->bi_bdev = rdev->bdev; + bio->bi_opf =REQ_OP_WRITE |REQ_PREFLUSH ; + ret =submit_bio_wait (bio); +bio_put (bio); + } +out: +__free_page (page); +return ret; +} + +static int ppl_write_empty_header (struct ppl_log *log) +{ +struct page *page; +struct ppl_header *pplhdr; +struct md_rdev *rdev = log->rdev; +int ret =0 ; + +pr_debug ("%s: disk: %d ppl_sector: %llu\n" , __func__, + rdev->raid_disk, (unsigned long long )rdev->ppl.sector); + + page =alloc_page (GFP_NOIO | __GFP_ZERO); +if (!page) +return -ENOMEM ; + + pplhdr =page_address (page); +memset (pplhdr->reserved,0xff ,PPL_HDR_RESERVED ); + pplhdr->signature =cpu_to_le32 (log->ppl_conf->signature); + pplhdr->checksum =cpu_to_le32 (~crc32c_le (~0 , pplhdr,PAGE_SIZE )); + +if (!sync_page_io (rdev, rdev->ppl.sector - rdev->data_offset, +PPL_HEADER_SIZE , page,REQ_OP_WRITE |REQ_FUA ,0 , + false)) { +md_error (rdev->mddev, rdev); + ret = -EIO ; + } + +__free_page (page); +return ret; +} + +static int ppl_load_distributed (struct ppl_log *log) +{ +struct ppl_conf *ppl_conf = log->ppl_conf; +struct md_rdev *rdev = log->rdev; +struct mddev *mddev = rdev->mddev; +struct page *page; +struct ppl_header *pplhdr; +u32 crc, crc_stored; +u32 signature; +int ret =0 ; + +pr_debug ("%s: disk: %d\n" , __func__, rdev->raid_disk); + +/* read PPL header */ + page =alloc_page (GFP_KERNEL ); +if (!page) +return -ENOMEM ; + +if (!sync_page_io (rdev, rdev->ppl.sector - rdev->data_offset, +PAGE_SIZE , page,REQ_OP_READ ,0 , false)) { +md_error (mddev, rdev); + ret = -EIO ; + goto out; + } + pplhdr =page_address (page); + +/* check header validity */ + crc_stored =le32_to_cpu (pplhdr->checksum); + pplhdr->checksum =0 ; + crc = ~crc32c_le (~0 , pplhdr,PAGE_SIZE ); + +if (crc_stored != crc) { +pr_debug ("%s: ppl header crc does not match: stored: 0x%x calculated: 0x%x\n" , + __func__, crc_stored, crc); + ppl_conf->mismatch_count++; + goto out; + } + + signature =le32_to_cpu (pplhdr->signature); + +if (mddev->external) { +/* +* For external metadata the header signature is set and +* validated in userspace. +*/ + ppl_conf->signature = signature; + }else if (ppl_conf->signature != signature) { +pr_debug ("%s: ppl header signature does not match: stored: 0x%x configured: 0x%x\n" , + __func__, signature, ppl_conf->signature); + ppl_conf->mismatch_count++; + goto out; + } + +/* attempt to recover from log if we are starting a dirty array */ +if (!mddev->pers && mddev->recovery_cp != MaxSector) + ret =ppl_recover (log, pplhdr); +out: +/* write empty header if we are starting the array */ +if (!ret && !mddev->pers) + ret =ppl_write_empty_header (log); + +__free_page (page); + +pr_debug ("%s: return: %d mismatch_count: %d recovered_entries: %d\n" , + __func__, ret, ppl_conf->mismatch_count, + ppl_conf->recovered_entries); +return ret; +} + +static int ppl_load (struct ppl_conf *ppl_conf) +{ +int ret =0 ; +u32 signature =0 ; +bool signature_set = false; +int i; + +for (i =0 ; i < ppl_conf->count; i++) { +struct ppl_log *log = &ppl_conf->child_logs[i]; + +/* skip missing drive */ +if (!log->rdev) +continue ; + + ret =ppl_load_distributed (log); +if (ret) +break ; + +/* +* For external metadata we can't check if the signature is +* correct on a single drive, but we can check if it is the same +* on all drives. +*/ +if (ppl_conf->mddev->external) { +if (!signature_set) { + signature = ppl_conf->signature; + signature_set = true; + }else if (signature != ppl_conf->signature) { +pr_warn ("md/raid:%s: PPL header signature does not match on all member drives\n" , +mdname (ppl_conf->mddev)); + ret = -EINVAL ; +break ; + } + } + } + +pr_debug ("%s: return: %d mismatch_count: %d recovered_entries: %d\n" , + __func__, ret, ppl_conf->mismatch_count, + ppl_conf->recovered_entries); +return ret; +} +static void __ppl_exit_log (struct ppl_conf *ppl_conf) {clear_bit (MD_HAS_PPL , &ppl_conf->mddev->flags);
@@ -694,6 +1174,23 @@ int ppl_init_log(struct r5conf *conf)pr_warn ("md/raid:%s: Volatile write-back cache should be disabled on all member drives when using PPL!\n" ,mdname (mddev)); +/* load and possibly recover the logs from the member disks */ + ret =ppl_load (ppl_conf); + +if (ret) { + goto err; + }else if (!mddev->pers && + mddev->recovery_cp ==0 && !mddev->degraded && + ppl_conf->recovered_entries >0 && + ppl_conf->mismatch_count ==0 ) { +/* +* If we are starting a dirty array and the recovery succeeds +* without any issues, set the array as clean. +*/ + mddev->recovery_cp = MaxSector; +set_bit (MD_SB_CHANGE_CLEAN , &mddev->sb_flags); + } + conf->log_private = ppl_conf;return 0 ;
drivers/md/raid5.c +4 -1
@@ -7236,7 +7236,10 @@ static int raid5_run(struct mddev *mddev)if (mddev->degraded > dirty_parity_disks && mddev->recovery_cp != MaxSector) { -if (mddev->ok_start_degraded) +if (test_bit (MD_HAS_PPL , &mddev->flags)) +pr_crit ("md/raid:%s: starting dirty degraded array with PPL.\n" , +mdname (mddev)); +else if (mddev->ok_start_degraded)pr_crit ("md/raid:%s: starting dirty degraded array - data corruption possible.\n" ,mdname (mddev));else {
Signature · 1 line
2.11.0
Re: [PATCH v5 5/7] raid5-ppl: load and recover the log
Quoted 45 lines · Artur Paszkiewicz
Load the log from each disk when starting the array and recover if the array is dirty.
The initial empty PPL is written by mdadm. When loading the log we verify the header checksum and signature. For external metadata arrays the signature is verified in userspace, so here we read it from the header, verifying only if it matches on all disks, and use it later when writing PPL.
In addition to the header checksum, each header entry also contains a checksum of its partial parity data. If the header is valid, recovery is performed for each entry until an invalid entry is found. If the array is not degraded and recovery using PPL fully succeeds, there is no need to resync the array because data and parity will be consistent, so in this case resync will be disabled.
Due to compatibility with IMSM implementations on other systems, we can't assume that the recovery data block size is always 4K. Writes generated by MD raid5 don't have this issue, but when recovering PPL written in other environments it is possible to have entries with 512-byte sector granularity. The recovery code takes this into account and also the logical sector size of the underlying drives.
Signed-off-by Artur Paszkiewicz <[email protected]>--- drivers/md/raid5-ppl.c | 497 +++++++++++++++++++++++++++++++++++++++++++++++++ drivers/md/raid5.c | 5 +- 2 files changed, 501 insertions(+), 1 deletion(-)drivers/md/raid5-ppl.c +4
-0@@ -103,6 +103,10 @@ struct ppl_conf {mempool_t *io_pool;struct bio_set *bs;mempool_t *meta_pool; + +/* used only for recovery */ +int recovered_entries; +int mismatch_count; };struct ppl_log {
drivers/md/raid5-ppl.c void ppl_stripe_write_finished(struct stripe_head *sh) · line 523
Quoted 6 lines
drivers/md/raid5-ppl.c +3
-0@@ -514,6 +518,482 @@ void ppl_stripe_write_finished(struct stripe_head *sh)ppl_io_unit_finished (io); } +static void ppl_xor (int size,struct page *page1,struct page *page2, +struct page *page_result) +{
I'd remove the page_result parameter, it should always be page1. And this will make it clear why we need ASYNC_TX_XOR_DROP_DST.
Quoted 10 lines
drivers/md/raid5-ppl.c +10
-0+struct async_submit_ctl submit; +struct dma_async_tx_descriptor *tx; +struct page *xor_srcs[] = { page1, page2 }; + +init_async_submit (&submit,ASYNC_TX_ACK |ASYNC_TX_XOR_DROP_DST , +NULL ,NULL ,NULL ,NULL ); + tx =async_xor (page_result, xor_srcs,0 ,2 , size, &submit); + +async_tx_quiesce (&tx); +}
...
drivers/md/raid5-ppl.c void ppl_stripe_write_finished(struct stripe_head *sh) · line 843
Quoted 11 lines
drivers/md/raid5-ppl.c +11
-0+ ret =ppl_recover_entry (log, e, ppl_sector); +if (ret) + goto out; + ppl_conf->recovered_entries++; + } + + ppl_sector += ppl_entry_sectors; + } + +/* flush the disk cache after recovery if necessary */ +if (test_bit (QUEUE_FLAG_WC , &bdev_get_queue (rdev->bdev)->queue_flags)) {
The block layer will handle this, so you don't need to check
drivers/md/raid5-ppl.c void ppl_stripe_write_finished(struct stripe_head *sh) · line 849
Quoted 6 lines
drivers/md/raid5-ppl.c +6
-0+struct bio *bio =bio_alloc_bioset (GFP_KERNEL ,0 , ppl_conf->bs); + + bio->bi_bdev = rdev->bdev; + bio->bi_opf =REQ_OP_WRITE |REQ_PREFLUSH ; + ret =submit_bio_wait (bio); +bio_put (bio);
please use blkdev_issue_flush() instead.
Quoted 6 lines
drivers/md/raid5-ppl.c +6
-0+ } +out: +__free_page (page); +return ret; +} +
...
Quoted 7 lines
drivers/md/raid5-ppl.c +7
-0+static int ppl_load (struct ppl_conf *ppl_conf) +{ +int ret =0 ; +u32 signature =0 ; +bool signature_set = false; +int i; +
drivers/md/raid5-ppl.c void ppl_stripe_write_finished(struct stripe_head *sh) · line 971
Quoted 10 lines
drivers/md/raid5-ppl.c +10
-0+for (i =0 ; i < ppl_conf->count; i++) { +struct ppl_log *log = &ppl_conf->child_logs[i]; + +/* skip missing drive */ +if (!log->rdev) +continue ; + + ret =ppl_load_distributed (log); +if (ret) +break ;
Not sure about the strategy here. But if one disk fails, why don't we continue do the recovery from other disks? This way we can at least recovery more data.
Thanks,
Shaohua
Re: [PATCH v5 5/7] raid5-ppl: load and recover the log
Quoted 110 lines · Shaohua Li
Quoted 45 lines · Artur Paszkiewicz
Load the log from each disk when starting the array and recover if the array is dirty.
The initial empty PPL is written by mdadm. When loading the log we verify the header checksum and signature. For external metadata arrays the signature is verified in userspace, so here we read it from the header, verifying only if it matches on all disks, and use it later when writing PPL.
In addition to the header checksum, each header entry also contains a checksum of its partial parity data. If the header is valid, recovery is performed for each entry until an invalid entry is found. If the array is not degraded and recovery using PPL fully succeeds, there is no need to resync the array because data and parity will be consistent, so in this case resync will be disabled.
Due to compatibility with IMSM implementations on other systems, we can't assume that the recovery data block size is always 4K. Writes generated by MD raid5 don't have this issue, but when recovering PPL written in other environments it is possible to have entries with 512-byte sector granularity. The recovery code takes this into account and also the logical sector size of the underlying drives.
Signed-off-by Artur Paszkiewicz <[email protected]>--- drivers/md/raid5-ppl.c | 497 +++++++++++++++++++++++++++++++++++++++++++++++++ drivers/md/raid5.c | 5 +- 2 files changed, 501 insertions(+), 1 deletion(-)drivers/md/raid5-ppl.c +4
-0@@ -103,6 +103,10 @@ struct ppl_conf {mempool_t *io_pool;struct bio_set *bs;mempool_t *meta_pool; + +/* used only for recovery */ +int recovered_entries; +int mismatch_count; };struct ppl_log {drivers/md/raid5-ppl.c void ppl_stripe_write_finished(struct stripe_head *sh) · line 523
Quoted 6 lines
drivers/md/raid5-ppl.c +3
-0@@ -514,6 +518,482 @@ void ppl_stripe_write_finished(struct stripe_head *sh)ppl_io_unit_finished (io); } +static void ppl_xor (int size,struct page *page1,struct page *page2, +struct page *page_result) +{I'd remove the
page_resultparameter, it should always be page1. And this will make it clear why we needASYNC_TX_XOR_DROP_DST.Quoted 10 lines
drivers/md/raid5-ppl.c +10
-0+struct async_submit_ctl submit; +struct dma_async_tx_descriptor *tx; +struct page *xor_srcs[] = { page1, page2 }; + +init_async_submit (&submit,ASYNC_TX_ACK |ASYNC_TX_XOR_DROP_DST , +NULL ,NULL ,NULL ,NULL ); + tx =async_xor (page_result, xor_srcs,0 ,2 , size, &submit); + +async_tx_quiesce (&tx); +}...
drivers/md/raid5-ppl.c void ppl_stripe_write_finished(struct stripe_head *sh) · line 843
Quoted 11 lines
drivers/md/raid5-ppl.c +11
-0+ ret =ppl_recover_entry (log, e, ppl_sector); +if (ret) + goto out; + ppl_conf->recovered_entries++; + } + + ppl_sector += ppl_entry_sectors; + } + +/* flush the disk cache after recovery if necessary */ +if (test_bit (QUEUE_FLAG_WC , &bdev_get_queue (rdev->bdev)->queue_flags)) {The block layer will handle this, so you don't need to check
drivers/md/raid5-ppl.c void ppl_stripe_write_finished(struct stripe_head *sh) · line 849
Quoted 6 lines
drivers/md/raid5-ppl.c +6
-0+struct bio *bio =bio_alloc_bioset (GFP_KERNEL ,0 , ppl_conf->bs); + + bio->bi_bdev = rdev->bdev; + bio->bi_opf =REQ_OP_WRITE |REQ_PREFLUSH ; + ret =submit_bio_wait (bio); +bio_put (bio);please use
blkdev_issue_flush()instead.Quoted 6 lines
drivers/md/raid5-ppl.c +6
-0+ } +out: +__free_page (page); +return ret; +} +...
Quoted 12 lines
drivers/md/raid5-ppl.c +12
-0+static int ppl_load (struct ppl_conf *ppl_conf) +{ +int ret =0 ; +u32 signature =0 ; +bool signature_set = false; +int i; + +for (i =0 ; i < ppl_conf->count; i++) { +struct ppl_log *log = &ppl_conf->child_logs[i]; + +/* skip missing drive */ +if (!log->rdev)
Quoted 8 lines
drivers/md/raid5-ppl.c void ppl_stripe_write_finished(struct stripe_head *sh) · line 971
Quoted 5 lines
drivers/md/raid5-ppl.c +5
-0+continue ; + + ret =ppl_load_distributed (log); +if (ret) +break ;Not sure about the strategy here. But if one disk fails, why don't we continue do the recovery from other disks? This way we can at least recovery more data.
I thought it would be safer to abort early. Then we can for example remove the failed drive try again or disable ppl. And if the array is already degraded and another disk fails, the recovery won't be meaningful anyway.
Thanks,
Artur
PATCH v5 6/7 raid5-ppl: support disk hot add/remove with PPL
In reply to Artur PaszkiewiczAdd a function to modify the log by removing an rdev when a drive fails or adding when a spare/replacement is activated as a raid member.
Removing a disk just clears the child log rdev pointer. No new stripes will be accepted for this child log in ppl_write_stripe() and running io units will be processed without writing PPL to the device.
Adding a disk sets the child log rdev pointer and writes an empty PPL header.
--- drivers/md/raid5-log.h | 9 +++++++++ drivers/md/raid5-ppl.c | 45 ++++++++++++++++++++++++++++++++++++++++++++- drivers/md/raid5.c | 12 +++++++++++- 3 files changed, 64 insertions(+), 2 deletions(-)
drivers/md/raid5-log.h +9 -0
@@ -39,6 +39,7 @@ extern void ppl_exit_log(struct r5conf *conf);extern int ppl_write_stripe (struct r5conf *conf,struct stripe_head *sh);extern void ppl_write_stripe_run (struct r5conf *conf);extern void ppl_stripe_write_finished (struct stripe_head *sh); +extern int ppl_modify_log (struct r5conf *conf,struct md_rdev *rdev,bool add);static inline bool raid5_has_ppl (struct r5conf *conf) {
@@ -102,4 +103,12 @@ static inline int log_init(struct r5conf *conf, struct md_rdev *journal_dev) return 0; } +static inline int log_modify (struct r5conf *conf,struct md_rdev *rdev,bool add) +{ +if (raid5_has_ppl (conf)) +return ppl_modify_log (conf, rdev, add); + +return 0 ; +} +#endif
drivers/md/raid5-ppl.c +44 -1
60 lines not on this page · raw message
drivers/md/raid5.c +11 -1
@@ -7527,6 +7527,11 @@ static int raid5_remove_disk(struct mddev *mddev, struct md_rdev *rdev) *rdevp = rdev; } } +if (!err) { + err =log_modify (conf, rdev, false); +if (err) + goto abort; + }if (p->replacement) {/* We must have just cleared 'rdev' */ p->rdev = p->replacement;
@@ -7536,6 +7541,9 @@ static int raid5_remove_disk(struct mddev *mddev, struct md_rdev *rdev)*/ p->replacement =NULL ;clear_bit (WantReplacement, &rdev->flags); + +if (!err) + err =log_modify (conf, p->rdev, true); }else /* We might have just removed the Replacement as faulty- * clear the bit just in case
@@ -7592,10 +7600,12 @@ static int raid5_add_disk(struct mddev *mddev, struct md_rdev *rdev)if (p->rdev ==NULL ) {clear_bit (In_sync, &rdev->flags); rdev->raid_disk = disk; - err =0 ;if (rdev->saved_raid_disk != disk) conf->fullsync =1 ;rcu_assign_pointer (p->rdev, rdev); + + err =log_modify (conf, rdev, true); + goto out; } }
Signature · 1 line
2.11.0
PATCH v5 7/7 raid5-ppl: runtime PPL enabling or disabling
In reply to Artur PaszkiewiczAllow writing to 'consistency_policy' attribute when the array is active. Add a new function 'change_consistency_policy' to the md_personality operations structure to handle the change in the personality code. Values "ppl" and "resync" are accepted and turn PPL on and off respectively.
When enabling PPL its location and size should first be set using 'ppl_sector' and 'ppl_size' attributes and a valid PPL header should be written at this location on each member device.
Enabling or disabling PPL is performed under a suspended array. The raid5_reset_stripe_cache function frees the stripe cache and allocates it again in order to allocate or free the ppl_pages for the stripes in the stripe cache.
--- drivers/md/md.c | 12 +++++++++--- drivers/md/md.h | 2 ++ drivers/md/raid5-ppl.c | 4 ++++ drivers/md/raid5.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 68 insertions(+), 3 deletions(-)
drivers/md/md.c +9 -3
@@ -4995,14 +4995,20 @@ consistency_policy_show(struct mddev *mddev, char *page)static ssize_t consistency_policy_store (struct mddev *mddev,const char *buf,size_t len) { +int err =0 ; +if (mddev->pers) { -return -EBUSY ; +if (mddev->pers->change_consistency_policy) + err = mddev->pers->change_consistency_policy (mddev, buf); +else + err = -EBUSY ; }else if (mddev->external &&strncmp (buf,"ppl" ,3 ) ==0 ) {set_bit (MD_HAS_PPL , &mddev->flags); -return len; }else { -return -EINVAL ; + err = -EINVAL ; } + +return err ? err : len; } static struct md_sysfs_entry md_consistency_policy =
drivers/md/md.h +2 -0
@@ -545,6 +545,8 @@ struct md_personality/* congested implements bdi.congested_fn(). * Will not be called while array is 'suspended' */ int (*congested)(struct mddev *mddev,int bits); +/* Changes the consistency policy of an active array. */ +int (*change_consistency_policy)(struct mddev *mddev,const char *buf); };struct md_sysfs_entry {
drivers/md/raid5-ppl.c +4 -0
@@ -1195,6 +1195,10 @@ int ppl_init_log(struct r5conf *conf)*/ mddev->recovery_cp = MaxSector;set_bit (MD_SB_CHANGE_CLEAN , &mddev->sb_flags); + }else if (mddev->pers && ppl_conf->mismatch_count >0 ) { +/* no mismatch allowed when enabling PPL for a running array */ + ret = -EINVAL ; + goto err; } conf->log_private = ppl_conf;
drivers/md/raid5.c +53 -0
65 lines not on this page · raw message
Signature · 1 line
2.11.0
Quoted 13 lines · Artur Paszkiewicz
This series of patches implements the Partial Parity Log for RAID5 arrays. The purpose of this feature is closing the RAID 5 Write Hole. It is a solution alternative to the existing raid5-cache, but the logging workflow and much of the implementation is based on it.
The main differences compared to raid5-cache is that PPL is a distributed log - it is stored on array member drives in the metadata area and does not require a dedicated journaling drive. Write performance is reduced by up to 30%-40% but it scales with the number of drives in the array and the journaling drive does not become a bottleneck or a single point of failure. PPL does not protect from losing in-flight data, only from silent data corruption. More details about how the log works can be found in patches 3 and 5.
Quoted 8 lines
This feature originated from Intel RSTe, which uses IMSM metadata. PPL for IMSM is going to be included in RSTe implementations starting with upcoming Xeon platforms and Intel will continue supporting and maintaining it. This patchset implements PPL for external metadata (specifically IMSM) as well as native MD v1.x metadata.
Changes in mdadm are also required to make this fully usable. Patches for mdadm will be sent later.
Looks good, I'll apply this series into next. There are some small issues I replied separately. Please send a separate patch to fix them if they make sense, I'll integrate them locally.
Thanks,
Shaohua
PATCH 1/1 raid5-ppl: two minor improvements
- Remove 'page_result' parameter from ppl_xor() and always write result to 'page1'.
- Use blkdev_issue_flush() instead of open coding the flush bio submission.
--- drivers/md/raid5-ppl.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-)
drivers/md/raid5-ppl.c +5 -13
@@ -524,8 +524,7 @@ void ppl_stripe_write_finished(struct stripe_head *sh)ppl_io_unit_finished (io); } -static void ppl_xor (int size,struct page *page1,struct page *page2, -struct page *page_result) +static void ppl_xor (int size,struct page *page1,struct page *page2) {struct async_submit_ctl submit;struct dma_async_tx_descriptor *tx;
@@ -533,7 +532,7 @@ static void ppl_xor(int size, struct page *page1, struct page *page2,init_async_submit (&submit,ASYNC_TX_ACK |ASYNC_TX_XOR_DROP_DST ,NULL ,NULL ,NULL ,NULL ); - tx =async_xor (page_result, xor_srcs,0 ,2 , size, &submit); + tx =async_xor (page1, xor_srcs,0 ,2 , size, &submit);async_tx_quiesce (&tx); }
@@ -724,7 +723,7 @@ static int ppl_recover_entry(struct ppl_log *log, struct ppl_header_entry *e, goto out; } -ppl_xor (block_size, page1, page2, page1); +ppl_xor (block_size, page1, page2); indent -=2 ; }
@@ -747,7 +746,7 @@ static int ppl_recover_entry(struct ppl_log *log, struct ppl_header_entry *e, goto out; } -ppl_xor (block_size, page1, page2, page1); +ppl_xor (block_size, page1, page2); }/* map raid sector to parity disk */
@@ -846,14 +845,7 @@ static int ppl_recover(struct ppl_log *log, struct ppl_header *pplhdr) }/* flush the disk cache after recovery if necessary */ -if (test_bit (QUEUE_FLAG_WC , &bdev_get_queue (rdev->bdev)->queue_flags)) { -struct bio *bio =bio_alloc_bioset (GFP_KERNEL ,0 , ppl_conf->bs); - - bio->bi_bdev = rdev->bdev; - bio->bi_opf =REQ_OP_WRITE |REQ_PREFLUSH ; - ret =submit_bio_wait (bio); -bio_put (bio); - } + ret =blkdev_issue_flush (rdev->bdev,GFP_KERNEL ,NULL ); out:__free_page (page);return ret;
Signature · 1 line
2.11.0
Shaohua Li
AppliedRe: [PATCH] raid5-ppl: two minor improvements
Quoted 4 lines · Artur Paszkiewicz
- Remove '
page_result' parameter fromppl_xor()and always write result to 'page1'.
- Useblkdev_issue_flush()instead of open coding the flush bio submission.
merged to original patch
Quoted 69 lines
Signed-off-by Artur Paszkiewicz <[email protected]>--- drivers/md/raid5-ppl.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-)drivers/md/raid5-ppl.c +5
-13@@ -524,8 +524,7 @@ void ppl_stripe_write_finished(struct stripe_head *sh)ppl_io_unit_finished (io); } -static void ppl_xor (int size,struct page *page1,struct page *page2, -struct page *page_result) +static void ppl_xor (int size,struct page *page1,struct page *page2) {struct async_submit_ctl submit;struct dma_async_tx_descriptor *tx;@@ -533,7 +532,7 @@ static void ppl_xor(int size, struct page *page1, struct page *page2,init_async_submit (&submit,ASYNC_TX_ACK |ASYNC_TX_XOR_DROP_DST ,NULL ,NULL ,NULL ,NULL ); - tx =async_xor (page_result, xor_srcs,0 ,2 , size, &submit); + tx =async_xor (page1, xor_srcs,0 ,2 , size, &submit);async_tx_quiesce (&tx); }@@ -724,7 +723,7 @@ static int ppl_recover_entry(struct ppl_log *log, struct ppl_header_entry *e, goto out; } -ppl_xor (block_size, page1, page2, page1); +ppl_xor (block_size, page1, page2); indent -=2 ; }@@ -747,7 +746,7 @@ static int ppl_recover_entry(struct ppl_log *log, struct ppl_header_entry *e, goto out; } -ppl_xor (block_size, page1, page2, page1); +ppl_xor (block_size, page1, page2); }/* map raid sector to parity disk */ @@ -846,14 +845,7 @@ static int ppl_recover(struct ppl_log *log, struct ppl_header *pplhdr) }/* flush the disk cache after recovery if necessary */ -if (test_bit (QUEUE_FLAG_WC , &bdev_get_queue (rdev->bdev)->queue_flags)) { -struct bio *bio =bio_alloc_bioset (GFP_KERNEL ,0 , ppl_conf->bs); - - bio->bi_bdev = rdev->bdev; - bio->bi_opf =REQ_OP_WRITE |REQ_PREFLUSH ; - ret =submit_bio_wait (bio); -bio_put (bio); - } + ret =blkdev_issue_flush (rdev->bdev,GFP_KERNEL ,NULL ); out:__free_page (page);return ret;Signature · 6 lines
2.11.0 -- To unsubscribe from this list: send the line "unsubscribe linux-raid" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html