]> www.infradead.org Git - users/hch/nvme-cli.git/commitdiff
lightnvm: enable to set OP on target creation
authorJavier González <javier@cnexlabs.com>
Mon, 30 Oct 2017 13:01:07 +0000 (14:01 +0100)
committerJavier González <javier@cnexlabs.com>
Fri, 12 Jan 2018 10:04:05 +0000 (11:04 +0100)
On target creation, allow to define the over-provision (OP). Since OP
area has a direct impact on write amplification, users can optimize the
OCSSD behavior for their workloads.

Support in the kernel has been upstreamed in 4.16

Signed-off-by: Javier González <javier@cnexlabs.com>
linux/lightnvm.h
lnvm-nvme.c
nvme-lightnvm.c
nvme-lightnvm.h

index 84919e85805d9406fde87f38b077ab6c05e826be..f678ffbca265255ca98c5757f43cb4fd7c2b3d90 100644 (file)
@@ -74,14 +74,23 @@ struct nvm_ioctl_create_simple {
        __u32 lun_end;
 };
 
+struct nvm_ioctl_create_extended {
+       __u16 lun_begin;
+       __u16 lun_end;
+       __u16 over_prov;
+       __u16 rsv;
+};
+
 enum {
        NVM_CONFIG_TYPE_SIMPLE = 0,
+       NVM_CONFIG_TYPE_EXTENDED = 1,
 };
 
 struct nvm_ioctl_create_conf {
        __u32 type;
        union {
                struct nvm_ioctl_create_simple s;
+               struct nvm_ioctl_create_extended e;
        };
 };
 
index a9322b8d6950a9bba1647fb7955660eae84f078d..aabbe261bf90c852fdcd59ba81df30575831118b 100644 (file)
@@ -125,6 +125,7 @@ static int lnvm_create_tgt(int argc, char **argv, struct command *cmd, struct pl
        const char *tgttype = "identifier of target type. e.g. pblk.";
        const char *lun_begin = "Define begin of luns to use for target.";
        const char *lun_end = "Define set of luns to use for target.";
+       const char *over_prov = "Define over-provision percentage for target.";
        const char *flag_factory = "Create target in factory mode";
        int flags;
 
@@ -135,6 +136,8 @@ static int lnvm_create_tgt(int argc, char **argv, struct command *cmd, struct pl
                char *tgttype;
                __u32 lun_begin;
                __u32 lun_end;
+               __u32 over_prov;
+
                /* flags */
                __u32 factory;
        };
@@ -145,6 +148,7 @@ static int lnvm_create_tgt(int argc, char **argv, struct command *cmd, struct pl
                .tgttype = "",
                .lun_begin = -1,
                .lun_end = -1,
+               .over_prov = -1,
                .factory = 0,
        };
 
@@ -154,7 +158,8 @@ static int lnvm_create_tgt(int argc, char **argv, struct command *cmd, struct pl
                {"target-type",   't', "TARGETTYPE",  CFG_STRING,    &cfg.tgttype,   required_argument, tgttype},
                {"lun-begin",     'b', "NUM",    CFG_POSITIVE,  &cfg.lun_begin,      required_argument,       lun_begin},
                {"lun-end",       'e', "NUM",    CFG_POSITIVE,  &cfg.lun_end,   required_argument,       lun_end},
-               {"factory",      'f', "FLAG",   CFG_NONE,  &cfg.factory,   no_argument,  flag_factory},
+               {"over-prov",     'o', "NUM",    CFG_POSITIVE,  &cfg.over_prov, required_argument,  over_prov},
+               {"factory",       'f', "FLAG",   CFG_NONE,  &cfg.factory,   no_argument,  flag_factory},
                {NULL}
        };
 
@@ -177,7 +182,7 @@ static int lnvm_create_tgt(int argc, char **argv, struct command *cmd, struct pl
        if (cfg.factory)
                flags |= NVM_TARGET_FACTORY;
 
-       return lnvm_do_create_tgt(cfg.devname, cfg.tgtname, cfg.tgttype, cfg.lun_begin, cfg.lun_end, flags);
+       return lnvm_do_create_tgt(cfg.devname, cfg.tgtname, cfg.tgttype, cfg.lun_begin, cfg.lun_end, cfg.over_prov, flags);
 }
 
 static int lnvm_remove_tgt(int argc, char **argv, struct command *cmd, struct plugin *plugin)
index 488560753e924a2ac75c2e92623549eebbcca385..0fdc74d999120da5f4d08d8a7d34137566e781f5 100644 (file)
@@ -147,7 +147,8 @@ int lnvm_do_info(void)
 }
 
 int lnvm_do_create_tgt(char *devname, char *tgtname, char *tgttype,
-                                       int lun_begin, int lun_end, int flags)
+                                       int lun_begin, int lun_end,
+                                       int over_prov, int flags)
 {
        struct nvm_ioctl_create c;
        int fd, ret;
@@ -159,12 +160,20 @@ int lnvm_do_create_tgt(char *devname, char *tgtname, char *tgttype,
        strncpy(c.dev, devname, DISK_NAME_LEN);
        strncpy(c.tgtname, tgtname, DISK_NAME_LEN);
        strncpy(c.tgttype, tgttype, NVM_TTYPE_NAME_MAX);
-       c.flags = 0;
-       c.conf.type = 0;
-       c.conf.s.lun_begin = lun_begin;
-       c.conf.s.lun_end = lun_end;
        c.flags = flags;
 
+       /* Fall back into simple IOCTL version if no extended attributes used */
+       if (over_prov != -1) {
+               c.conf.type = NVM_CONFIG_TYPE_EXTENDED;
+               c.conf.e.lun_begin = lun_begin;
+               c.conf.e.lun_end = lun_end;
+               c.conf.e.over_prov = over_prov;
+       } else {
+               c.conf.type = NVM_CONFIG_TYPE_SIMPLE;
+               c.conf.s.lun_begin = lun_begin;
+               c.conf.s.lun_end = lun_end;
+       }
+
        ret = ioctl(fd, NVM_DEV_CREATE, &c);
        if (ret)
                fprintf(stderr, "Creation of target failed. Please see dmesg.\n");
index 0eb7f40ea7f545c7bb75d61cddb95af43907eaef..8faca80e2db61c8bfbcd26be59a5c09db170bc95 100644 (file)
@@ -244,7 +244,7 @@ static inline struct ppa_addr generic_to_dev_addr(
 int lnvm_do_init(char *, char *);
 int lnvm_do_list_devices(void);
 int lnvm_do_info(void);
-int lnvm_do_create_tgt(char *, char *, char *, int, int, int);
+int lnvm_do_create_tgt(char *, char *, char *, int, int, int, int);
 int lnvm_do_remove_tgt(char *);
 int lnvm_do_factory_init(char *, int, int, int);
 int lnvm_do_id_ns(int, int, unsigned int);