Skip to contentSkip to conversation

New device mapper target ZDM

PATCH In review Shaun Tancheff 3 participants 5 messages Nov 21, 2016 – Nov 22, 2016

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

PATCH 1/1 New device mapper target ZDM

ZDM presents a traditional block device for ZBC/ZAC zoned devices.

User space utilities in zdm-tools for creating, repairing and restore DM instances at: https://github.com/Seagate

Primary advantages of using a zoned translation layer (ZTL) over a zone-caching model include:
Low memory usage less than 25 MiB per instance based on cache aging. Consistent first fill performance.
Good random write performance.
User configurable to match different workloads and QoS.

Disadvantages
A small amount of disk is used for ZTL data and over-provisioning. Lower random read performance.
Greater code complexity.

---
 Documentation/device-mapper/zdm.txt |   152 +
 MAINTAINERS                         |     7 +
 drivers/md/Kconfig                  |    20 +
 drivers/md/Makefile                 |     1 +
 drivers/md/dm-zdm.c                 |  2826 ++++++++++
 drivers/md/dm-zdm.h                 |   945 ++++
 drivers/md/libzdm.c                 | 10043 ++++++++++++++++++++++++++++++++++
 7 files changed, 13994 insertions(+)
 create mode 100644 Documentation/device-mapper/zdm.txt
 create mode 100644 drivers/md/dm-zdm.c
 create mode 100644 drivers/md/dm-zdm.h
 create mode 100644 drivers/md/libzdm.c
Documentation/device-mapper/zdm.txt new file +152 -0
new file mode 100644
index 0000000..3384d7d
@@ -0,0 +1,152 @@
+Overview of Host Aware ZBC/ZAC Device Mapper
+  - Zone size (256MiB)
+  - v4.10 ZBC support or later ...
+
+ZDM presents a traditional block device for ZBC/ZAC zoned devices.
+
+User space utilities in zdm-tools for creating, repairing and restore
+DM instances at: https://github.com/stancheff and https://github.com/Seagate
+
+ZDM uses a zoned translation layer [ZTL] which shares similarities with
+an FTL. Sometimes referred to as an STL [Shingled translation layer] as
+the physical media restricts differ the core principles remain.
+
+Primary advantages of using a zoned translation layer (ZTL) over a
+zone-caching model include:
+    Low memory usage less than 25 MiB per instance based on cache aging.
+    Consistent first fill performance.
+    Good random write performance.
+    User configurable to match different workloads and QoS.
+
+Disadvantages
+    A small amount of disk is used for ZTL data and over-provisioning.
+    Lower random read performance.
+    Greater code complexity.
+
+
+        Initial Setup (Reported size / addressable space)
+                
+On initial setup ZDM and the zdmadm tool calculate the mount of space
+needed for ZDM internal metadata (lookup tables, superblocks, crcs, etc)
+as well as a percentage of over provisioned space needed for garbage
+collection.
+
+This effectively reduces the amount of addressable space reported by
+the constructed target block device.
+
+Garbage collection by default is a transparent background activity. To
+facilitate the this ZDM reports 'trim' or 'discard' support as well as
+
+The current ZTL I/O model is to request a contiguous block large enough to
+hold the current request and map request to the allocated space and update
+the mapping into the ZTL. The initial update of ZTL is held in an extent
+table that is periodically migrated to the on-disc format and persisted.
+Extent table blocks that are not migrated are incorporated in the superblock
+stream during flush/fua operations. Read operations consult this hierarchy to
+determine the current location of requested blocks.
+
+
+        De-dupe Write Optimization
+
+On write I/Os which are all zeroed are mapped into the discard extent
+tables. The zeroed I/O is not written to disc, on read the empty block
+is generated.
+
+
+        Delayed Writeback Optimization
+
+An optional 1ms delay can be enabled to allow contiguous I/Os to be
+merged. This is mainly used for RAID 4/5/6 as the MD-RAID layer
+presents a 4K block mixed read/write workload which is far from
+optimal for ZDM.
+
+
+        Garbage Collection
+
+Background garbage collection operations are initiated on a periodic trigger
+and on allocation failures (unable to allocate free blocks for writing).
+The zone selected for cleaning is done by estimated the amount of stale
+blocks in the zone, either determined directly by remapped blocks, or estimated
+from discard requests. A zone stale ratio is assigned based on the estimated
+number of stale blocks in the zone. This is the number of free blocks that
+will be recovered once the active blocks in the zone are relocated and the zone
+is reset.
+There are several knobs presented via zdmadm to determine how aggressively
+garbage collection operate as well as the ability to halt automatic garbage
+collection entirely for critical operations. The primary knobs are how stale
+a zone must be and the number of empty zones which are available. The defaults
+are to initiate GC on a fully stale zone all the time and on to start
+considering lesser ratios as the disc when less than 25% of all zones are
+not in use.
+                
+
+        Implementation Overview
+
+-> .map(): DM target map handler
+When a target has I/O to process this handler is called
+
+ - Map incoming bio (bi_iter.bi_sector) onto ZDM exposed address space.
+ - Flag queue as no merge to avoid I/O being re-ordered by any io
+   elevator that may be enabled.
+ - Determine if I/O is a discard, read, or write. If it is a write determine
+   if the I/O is also flagged with FLUSH/FUA. Note: REQ_OP_FLUSH is a write op.
+    - Record the discard via the trim extent cache.
+    - Handle the read
+    - Handle the write. See .end_io() for completion handling.
+ - If flush is in effect queue the metadata worker and wait for completion.
+
+-> .end_io(): DM target endio handler
+When a bio completes this endio handler is notified.
+
+ - If completed operation is a write, update the appropriate zone wp to
+   indicate the wp has actually advanced. If the zone is full update the
+   stale ratio calculation of the zone and it's containing bin.
+
+Metadata worker:
+ - If initialize load previous state from disc
+ - Migrate extent cache entries to ZTL table entries
+ - on flush/fua, push all dirty ZLT blocks, extent cache, superblock et al.
+   to disc and perform a explicit media flush.
+
+Periodic activity (background worker):
+ - If last flush > 30s, queue a flush operation.
+ - If last I/O > DISCARD_IDLE_MSECS process some trim extent cache
+ - Scan for GC candidates and issue GC if found
+ - If cache memory usage is high try to release old blocks of ZLT
+
+GC worker:
+ - Load reverse map for zone and locate forward map ZLT entries.
+ - Build the current zone valid block map (tLBA -> bLBA).
+ - Loop until all valid data is moved out of zone: 
+   - Read valid tLBA entries
+   - Write (relocate) tLBA entries to new zone.
+ - Update map information for all moved (still valid) blocks.
+ - Reset WP on newly cleared zone and add zone to the free pool.
+
+Notable code [struct map_pool]:
+ - array merge sort and insert over non-contiguous pages
+ - binary search over non-contiguous pages
+
+
+        Data Layout
+
+See: z_mapped_sync / z_mapped_init
+
+Zone #0: 
+   Block 0 - Reserved for zdmadm
+   Superblock layout:
+    - 512 blocks (1-512, 513-1024, 1025-1536)
+   WP use/free cache
+    - 2048-~2200 [acutal limit: (2 x <zone count>) / (PAGE_SIZE / sizeof(u32))]
+
+ZLT layout:
+   Zone #1 - z:   Forward map
+   Zone #z+1 - y: Reverse map
+   Zone #y+1:     CRC-16 over forward/reverse map.
+
+Data zones #y+2 to end.
+
+Future plans:
+  Enable 3 generations of WP use/free similar to current superblock scheme.
+  Pack ZLT layout (currently zone aligned) for better CMR utilization.
+  Restore/Expand stream id support when feature is merged.
MAINTAINERS +7 -0
index f593300..67962182 100644
@@ -13036,6 +13036,13 @@ L:	[email protected] (subscribers-only)
 S:	Maintained
 F:	drivers/net/wireless/zydas/zd1211rw/
 
+ZDM ZONED DEVICE MAPPER TARGET
+M:	Shaun Tancheff <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	drivers/md/dm-zdm.*
+F:	drivers/md/libzdm.c
+
 ZPOOL COMPRESSED PAGE STORAGE API
 M:	Dan Streetman <[email protected]>
 L:	[email protected]
drivers/md/Kconfig +20 -0
index 02a5345..d0cdb8a 100644
@@ -336,6 +336,26 @@ config DM_ERA
          over time.  Useful for maintaining cache coherency when using
          vendor snapshots.
 
+config DM_ZDM
+       tristate "ZDM: Zoned based device target (EXPERIMENTAL)"
+       depends on BLK_DEV_DM
+       default n
+       select LIBCRC32C
+       ---help---
+         This device-mapper target implements a translation layer
+         for zoned block devices (ZBC/ZAC)
+         ZDM performs write serialization and copy-on-write data to
+         ensure forward writing within zones. ZDM also includes a
+         garbage collection model to reclaim stale blocks and remap
+         in use blocks.
+
+         Use zdmadm to create, repair and/or restore ZDM instances.
+
+         To compile this code as a module, choose M here: the module will
+         be called dm-zoned.
+
+         If unsure, say N.
+
 config DM_MIRROR
        tristate "Mirror target"
        depends on BLK_DEV_DM
drivers/md/Makefile +1 -0
index 3cbda1a..1a35fc3 100644
@@ -59,6 +59,7 @@ obj-$(CONFIG_DM_CACHE_SMQ)	+= dm-cache-smq.o
 obj-$(CONFIG_DM_CACHE_CLEANER)	+= dm-cache-cleaner.o
 obj-$(CONFIG_DM_ERA)		+= dm-era.o
 obj-$(CONFIG_DM_LOG_WRITES)	+= dm-log-writes.o
+obj-$(CONFIG_DM_ZDM)		+= dm-zdm.o
 
 ifeq ($(CONFIG_DM_UEVENT),y)
 dm-mod-objs			+= dm-uevent.o
drivers/md/dm-zdm.c new file +2826 -0

2,802 lines not on this page · raw message

drivers/md/dm-zdm.h new file +945 -0

945 lines not on this page · raw message

drivers/md/libzdm.c new file +10043 -0

10,043 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.10.2

Part of the diff is not shown here. View the raw message.

#1 lore raw
Quoted 17 lines · Shaun Tancheff
drivers/md/dm-zdm.c new file +17 -0
+/* -------------------------------------------------------------------------- */
+/* --ProcFS Support Routines------------------------------------------------- */
+/* -------------------------------------------------------------------------- */
+
+#if defined(CONFIG_PROC_FS)
+
+/**
+ * struct zone_info_entry - Proc zone entry.
+ * @zone: Zone Index
+ * @info: Info (WP/Used).
+ */
+struct zone_info_entry {
+	u32 zone;
+	u32 info;
+};
+
+/**

drivers/md/dm-zdm.c line 2247

Quoted 10 lines
drivers/md/dm-zdm.c new file +10 -0
+ * Startup writing to our proc entry
+ */
+static void *proc_wp_start(struct seq_file *seqf, loff_t *pos)
+{
+	struct zdm *znd = seqf->private;
+
+	if (*pos == 0)
+		znd->wp_proc_at = *pos;
+	return &znd->wp_proc_at;
+}

Hello Shaun,

Does this mean that you are not aware that it is considered unacceptable for new drivers to create procfs entries?

Bart.

#2 lore raw
Quoted 31 lines · Bart Van Assche
Quoted 17 lines · Shaun Tancheff
drivers/md/dm-zdm.c new file +17 -0
+/* -------------------------------------------------------------------------- */
+/* --ProcFS Support Routines------------------------------------------------- */
+/* -------------------------------------------------------------------------- */
+
+#if defined(CONFIG_PROC_FS)
+
+/**
+ * struct zone_info_entry - Proc zone entry.
+ * @zone: Zone Index
+ * @info: Info (WP/Used).
+ */
+struct zone_info_entry {
+     u32 zone;
+     u32 info;
+};
+
+/**

drivers/md/dm-zdm.c line 2247

Quoted 10 lines
drivers/md/dm-zdm.c new file +10 -0
+ * Startup writing to our proc entry
+ */
+static void *proc_wp_start(struct seq_file *seqf, loff_t *pos)
+{
+     struct zdm *znd = seqf->private;
+
+     if (*pos == 0)
+             znd->wp_proc_at = *pos;
+     return &znd->wp_proc_at;
+}

Hello Shaun,

Quoted 2 lines

Does this mean that you are not aware that it is considered unacceptable for new drivers to create procfs entries?

I understood that it was frowned on.

I can move all but the 'status' to debugfs and move 'status' to sysfs and reformat
the output as appropriate.... would that suffice?

Quoted 1 line

Bart.

#3 lore raw
Quoted 3 lines · Shaun Tancheff

I can move all but the 'status' to debugfs and move 'status' to sysfs and reformat
the output as appropriate.... would that suffice?

First concentrate on working out how to shoe-horn the code into the standard device-mapper interface model, like the existing dm targets.

The right location for the assorted things you've placed in /proc will then drop out of that analysis.

Alasdair

#4 lore raw
In reply to Shaun Tancheff

Well to start with some device-mapper basics, looks at the newer files (e.g. thin-provisioning.txt, cache.txt) in the Documentation directory to see what format to use and how to document the interface. Constructor, status, examples using dmsetup only etc.

(BTW We don't use equals signs in our interfaces.)

But even before any of that, I'm puzzled by the basics of how this can have been fitted into a device-mapper interface where the "sine qua non" resume function is still TODO, 'dmsetup table' appears unimplemented, 'status' doesn't appear to provide the internal status, and 'load' has some keywords that also don't appear to fit.

Look at how the existing dm targets divide up the work between each of the functions and model your interface on those.

Alasdair