* [PATCH 0/8] Introduce sgl_alloc() and sgl_free()
@ 2017-10-12 22:45 Bart Van Assche
2017-10-12 22:45 ` [PATCH 1/8] lib: " Bart Van Assche
` (7 more replies)
0 siblings, 8 replies; 20+ messages in thread
From: Bart Van Assche @ 2017-10-12 22:45 UTC (permalink / raw)
To: Jens Axboe; +Cc: linux-block, linux-scsi, linux-nvme, Bart Van Assche
Hello Jens,
As you probably know there are multiple drivers that both allocate a
scatter/gather list and populate that list with pages. This patch series moves
the code for allocating and freeing such scatterlists from these drivers into
a new source file, namely lib/sgl_alloc. Please consider this patch series for
kernel v4.15.
Notes:
- Only the ib_srpt driver changes have been tested but none of the other
drivers have been retested.
- The next step is to introduce a caching mechanism for these scatterlists
and make the nvmet/rdma and SCSI target drivers use that caching mechanism
since for these drivers sgl allocation occurs in the hot path.
Thanks,
Bart.
Bart Van Assche (8):
lib: Introduce sgl_alloc() and sgl_free()
crypto: scompress - use sgl_alloc() and sgl_free()
nvmet/fc: Use sgl_alloc() and sgl_free()
nvmet/rdma: Use sgl_alloc() and sgl_free()
target: Use sgl_alloc_order() and sgl_free()
scsi/ipr: Use sgl_alloc_order() and sgl_free_order()
scsi/pmcraid: Remove an unused structure member
scsi/pmcraid: Use sgl_alloc_order() and sgl_free_order()
crypto/Kconfig | 1 +
crypto/scompress.c | 52 +----------------
drivers/nvme/target/Kconfig | 2 +
drivers/nvme/target/fc.c | 37 +-----------
drivers/nvme/target/rdma.c | 64 ++-------------------
drivers/scsi/Kconfig | 2 +
drivers/scsi/ipr.c | 50 +++-------------
drivers/scsi/ipr.h | 2 +-
drivers/scsi/pmcraid.c | 44 ++------------
drivers/scsi/pmcraid.h | 3 +-
drivers/target/Kconfig | 1 +
drivers/target/target_core_transport.c | 47 ++-------------
include/linux/sgl_alloc.h | 16 ++++++
lib/Kconfig | 4 ++
lib/Makefile | 1 +
lib/sgl_alloc.c | 102 +++++++++++++++++++++++++++++++++
16 files changed, 161 insertions(+), 267 deletions(-)
create mode 100644 include/linux/sgl_alloc.h
create mode 100644 lib/sgl_alloc.c
--
2.14.2
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH 1/8] lib: Introduce sgl_alloc() and sgl_free()
2017-10-12 22:45 [PATCH 0/8] Introduce sgl_alloc() and sgl_free() Bart Van Assche
@ 2017-10-12 22:45 ` Bart Van Assche
2017-10-12 22:52 ` Jens Axboe
2017-10-13 17:43 ` Randy Dunlap
2017-10-12 22:45 ` [PATCH 2/8] crypto: scompress - use " Bart Van Assche
` (6 subsequent siblings)
7 siblings, 2 replies; 20+ messages in thread
From: Bart Van Assche @ 2017-10-12 22:45 UTC (permalink / raw)
To: Jens Axboe; +Cc: linux-block, linux-scsi, linux-nvme, Bart Van Assche
Many kernel drivers contain code that allocate and free both a
scatterlist and the pages that populate that scatterlist.
Introduce functions under lib/ that perform these tasks instead
of duplicating this functionality in multiple drivers.
Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
---
include/linux/sgl_alloc.h | 16 ++++++++
lib/Kconfig | 4 ++
lib/Makefile | 1 +
lib/sgl_alloc.c | 102 ++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 123 insertions(+)
create mode 100644 include/linux/sgl_alloc.h
create mode 100644 lib/sgl_alloc.c
diff --git a/include/linux/sgl_alloc.h b/include/linux/sgl_alloc.h
new file mode 100644
index 000000000000..a0f719690c9e
--- /dev/null
+++ b/include/linux/sgl_alloc.h
@@ -0,0 +1,16 @@
+#ifndef _SGL_ALLOC_H_
+#define _SGL_ALLOC_H_
+
+#include <linux/types.h> /* bool, gfp_t */
+
+struct scatterlist;
+
+struct scatterlist *sgl_alloc_order(unsigned long long length,
+ unsigned int order, unsigned int *nent_p,
+ gfp_t gfp, bool chainable);
+struct scatterlist *sgl_alloc(unsigned long long length, unsigned int *nent_p,
+ gfp_t gfp);
+void sgl_free_order(struct scatterlist *sgl, int order);
+void sgl_free(struct scatterlist *sgl);
+
+#endif /* _SGL_ALLOC_H_ */
diff --git a/lib/Kconfig b/lib/Kconfig
index b1445b22a6de..8396c4cfa1ab 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -413,6 +413,10 @@ config HAS_DMA
depends on !NO_DMA
default y
+config SGL_ALLOC
+ bool
+ default n
+
config DMA_NOOP_OPS
bool
depends on HAS_DMA && (!64BIT || ARCH_DMA_ADDR_T_64BIT)
diff --git a/lib/Makefile b/lib/Makefile
index dafa79613fb4..4a0e9caf3c0e 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -27,6 +27,7 @@ lib-y := ctype.o string.o vsprintf.o cmdline.o \
lib-$(CONFIG_MMU) += ioremap.o
lib-$(CONFIG_SMP) += cpumask.o
+lib-$(CONFIG_SGL_ALLOC) += sgl_alloc.o
lib-$(CONFIG_DMA_NOOP_OPS) += dma-noop.o
lib-$(CONFIG_DMA_VIRT_OPS) += dma-virt.o
diff --git a/lib/sgl_alloc.c b/lib/sgl_alloc.c
new file mode 100644
index 000000000000..d96b395dd5c8
--- /dev/null
+++ b/lib/sgl_alloc.c
@@ -0,0 +1,102 @@
+#include <linux/kernel.h>
+#include <linux/scatterlist.h>
+#include <linux/sgl_alloc.h>
+#include <linux/slab.h>
+#include <linux/types.h>
+#include <asm/page.h>
+
+/**
+ * sgl_alloc_order - allocate a scatterlist and its pages
+ * @length: Length in bytes of the scatterlist. Must be at least one
+ * @order: Second argument for alloc_pages()
+ * @nent_p: [out] Number of entries in the scatterlist that have pages
+ * @gfp: Memory allocation flags
+ * @chainable: Whether or not to allocate an extra element in the scatterlist
+ * for scatterlist chaining purposes
+ *
+ * Returns: %NULL upon failure or a pointer to an initialized scatterlist.
+ */
+struct scatterlist *sgl_alloc_order(unsigned long long length,
+ unsigned int order, unsigned int *nent_p,
+ gfp_t gfp, bool chainable)
+{
+ struct scatterlist *sgl, *sg;
+ struct page *page;
+ unsigned int nent, nalloc;
+ u32 elem_len;
+
+ nent = round_up(length, PAGE_SIZE << order) >> (PAGE_SHIFT + order);
+ nalloc = nent;
+ if (chainable) {
+ /* Check for integer overflow */
+ if (nalloc + 1 < nalloc)
+ return NULL;
+ nalloc++;
+ }
+ sgl = kmalloc_array(nalloc, sizeof(struct scatterlist),
+ (gfp & ~GFP_DMA) | __GFP_ZERO);
+ if (!sgl)
+ return NULL;
+
+ sg_init_table(sgl, nent);
+ sg = sgl;
+ while (length) {
+ elem_len = min_t(u64, length, PAGE_SIZE << order);
+ page = alloc_pages(gfp, order);
+ if (!page) {
+ sgl_free(sgl);
+ return NULL;
+ }
+
+ sg_set_page(sg, page, elem_len, 0);
+ length -= elem_len;
+ sg = sg_next(sg);
+ }
+ WARN_ON_ONCE(sg);
+ if (nent_p)
+ *nent_p = nent;
+ return sgl;
+}
+EXPORT_SYMBOL(sgl_alloc_order);
+
+/**
+ * sgl_alloc - allocate a scatterlist and its pages
+ * @length: Length in bytes of the scatterlist
+ * @nent_p: [out] Number of entries in the scatterlist
+ * @gfp: Memory allocation flags
+ */
+struct scatterlist *sgl_alloc(unsigned long long length, unsigned int *nent_p,
+ gfp_t gfp)
+{
+ return sgl_alloc_order(length, 0, nent_p, gfp, false);
+}
+EXPORT_SYMBOL(sgl_alloc);
+
+/**
+ * sgl_free_order - free a scatterlist and its pages
+ * @sg: Scatterlist with one or more elements
+ * @order: Second argument for __free_pages()
+ */
+void sgl_free_order(struct scatterlist *sgl, int order)
+{
+ struct scatterlist *sg;
+ struct page *page;
+
+ for (sg = sgl; sg; sg = sg_next(sg)) {
+ page = sg_page(sg);
+ if (page)
+ __free_pages(page, order);
+ }
+ kfree(sgl);
+}
+EXPORT_SYMBOL(sgl_free_order);
+
+/**
+ * sgl_free - free a scatterlist and its pages
+ * @sg: Scatterlist with one or more elements
+ */
+void sgl_free(struct scatterlist *sgl)
+{
+ sgl_free_order(sgl, 0);
+}
+EXPORT_SYMBOL(sgl_free);
--
2.14.2
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH 2/8] crypto: scompress - use sgl_alloc() and sgl_free()
2017-10-12 22:45 [PATCH 0/8] Introduce sgl_alloc() and sgl_free() Bart Van Assche
2017-10-12 22:45 ` [PATCH 1/8] lib: " Bart Van Assche
@ 2017-10-12 22:45 ` Bart Van Assche
2017-10-12 22:45 ` [PATCH 3/8] nvmet/fc: Use " Bart Van Assche
` (5 subsequent siblings)
7 siblings, 0 replies; 20+ messages in thread
From: Bart Van Assche @ 2017-10-12 22:45 UTC (permalink / raw)
To: Jens Axboe
Cc: linux-block, linux-scsi, linux-nvme, Bart Van Assche,
Ard Biesheuvel, Herbert Xu
Use the sgl_alloc() and sgl_free() functions instead of open coding
these functions.
Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Herbert Xu <herbert@gondor.apana.org.au>
---
crypto/Kconfig | 1 +
crypto/scompress.c | 52 +++-------------------------------------------------
2 files changed, 4 insertions(+), 49 deletions(-)
diff --git a/crypto/Kconfig b/crypto/Kconfig
index 0a121f9ddf8e..a0667dd284ff 100644
--- a/crypto/Kconfig
+++ b/crypto/Kconfig
@@ -105,6 +105,7 @@ config CRYPTO_KPP
config CRYPTO_ACOMP2
tristate
select CRYPTO_ALGAPI2
+ select SGL_ALLOC
config CRYPTO_ACOMP
tristate
diff --git a/crypto/scompress.c b/crypto/scompress.c
index 2075e2c4e7df..ea4d5a3e01d1 100644
--- a/crypto/scompress.c
+++ b/crypto/scompress.c
@@ -24,6 +24,7 @@
#include <linux/cryptouser.h>
#include <net/netlink.h>
#include <linux/scatterlist.h>
+#include <linux/sgl_alloc.h>
#include <crypto/scatterwalk.h>
#include <crypto/internal/acompress.h>
#include <crypto/internal/scompress.h>
@@ -140,53 +141,6 @@ static int crypto_scomp_init_tfm(struct crypto_tfm *tfm)
return ret;
}
-static void crypto_scomp_sg_free(struct scatterlist *sgl)
-{
- int i, n;
- struct page *page;
-
- if (!sgl)
- return;
-
- n = sg_nents(sgl);
- for_each_sg(sgl, sgl, n, i) {
- page = sg_page(sgl);
- if (page)
- __free_page(page);
- }
-
- kfree(sgl);
-}
-
-static struct scatterlist *crypto_scomp_sg_alloc(size_t size, gfp_t gfp)
-{
- struct scatterlist *sgl;
- struct page *page;
- int i, n;
-
- n = ((size - 1) >> PAGE_SHIFT) + 1;
-
- sgl = kmalloc_array(n, sizeof(struct scatterlist), gfp);
- if (!sgl)
- return NULL;
-
- sg_init_table(sgl, n);
-
- for (i = 0; i < n; i++) {
- page = alloc_page(gfp);
- if (!page)
- goto err;
- sg_set_page(sgl + i, page, PAGE_SIZE, 0);
- }
-
- return sgl;
-
-err:
- sg_mark_end(sgl + i);
- crypto_scomp_sg_free(sgl);
- return NULL;
-}
-
static int scomp_acomp_comp_decomp(struct acomp_req *req, int dir)
{
struct crypto_acomp *tfm = crypto_acomp_reqtfm(req);
@@ -220,7 +174,7 @@ static int scomp_acomp_comp_decomp(struct acomp_req *req, int dir)
scratch_dst, &req->dlen, *ctx);
if (!ret) {
if (!req->dst) {
- req->dst = crypto_scomp_sg_alloc(req->dlen, GFP_ATOMIC);
+ req->dst = sgl_alloc(req->dlen, NULL, GFP_ATOMIC);
if (!req->dst)
goto out;
}
@@ -274,7 +228,7 @@ int crypto_init_scomp_ops_async(struct crypto_tfm *tfm)
crt->compress = scomp_acomp_compress;
crt->decompress = scomp_acomp_decompress;
- crt->dst_free = crypto_scomp_sg_free;
+ crt->dst_free = sgl_free;
crt->reqsize = sizeof(void *);
return 0;
--
2.14.2
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH 3/8] nvmet/fc: Use sgl_alloc() and sgl_free()
2017-10-12 22:45 [PATCH 0/8] Introduce sgl_alloc() and sgl_free() Bart Van Assche
2017-10-12 22:45 ` [PATCH 1/8] lib: " Bart Van Assche
2017-10-12 22:45 ` [PATCH 2/8] crypto: scompress - use " Bart Van Assche
@ 2017-10-12 22:45 ` Bart Van Assche
2017-10-13 8:41 ` Johannes Thumshirn
2017-10-12 22:45 ` [PATCH 4/8] nvmet/rdma: " Bart Van Assche
` (4 subsequent siblings)
7 siblings, 1 reply; 20+ messages in thread
From: Bart Van Assche @ 2017-10-12 22:45 UTC (permalink / raw)
To: Jens Axboe
Cc: linux-block, linux-scsi, linux-nvme, Bart Van Assche, Keith Busch,
Christoph Hellwig, James Smart, Johannes Thumshirn, Sagi Grimberg
Use the sgl_alloc() and sgl_free() functions instead of open coding
these functions.
Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
Cc: Keith Busch <keith.busch@intel.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: James Smart <james.smart@broadcom.com>
Cc: Johannes Thumshirn <jthumshirn@suse.de>
Cc: Sagi Grimberg <sagi@grimberg.me>
---
drivers/nvme/target/Kconfig | 1 +
drivers/nvme/target/fc.c | 37 +++----------------------------------
2 files changed, 4 insertions(+), 34 deletions(-)
diff --git a/drivers/nvme/target/Kconfig b/drivers/nvme/target/Kconfig
index 03e4ab65fe77..4d9715630e21 100644
--- a/drivers/nvme/target/Kconfig
+++ b/drivers/nvme/target/Kconfig
@@ -39,6 +39,7 @@ config NVME_TARGET_FC
tristate "NVMe over Fabrics FC target driver"
depends on NVME_TARGET
depends on HAS_DMA
+ select SGL_ALLOC
help
This enables the NVMe FC target support, which allows exporting NVMe
devices over FC.
diff --git a/drivers/nvme/target/fc.c b/drivers/nvme/target/fc.c
index 58e010bdda3e..02084539de5b 100644
--- a/drivers/nvme/target/fc.c
+++ b/drivers/nvme/target/fc.c
@@ -16,6 +16,7 @@
*/
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/module.h>
+#include <linux/sgl_alloc.h>
#include <linux/slab.h>
#include <linux/blk-mq.h>
#include <linux/parser.h>
@@ -1683,31 +1684,12 @@ static int
nvmet_fc_alloc_tgt_pgs(struct nvmet_fc_fcp_iod *fod)
{
struct scatterlist *sg;
- struct page *page;
unsigned int nent;
- u32 page_len, length;
- int i = 0;
- length = fod->total_length;
- nent = DIV_ROUND_UP(length, PAGE_SIZE);
- sg = kmalloc_array(nent, sizeof(struct scatterlist), GFP_KERNEL);
+ sg = sgl_alloc(fod->total_length, &nent, GFP_KERNEL);
if (!sg)
goto out;
- sg_init_table(sg, nent);
-
- while (length) {
- page_len = min_t(u32, length, PAGE_SIZE);
-
- page = alloc_page(GFP_KERNEL);
- if (!page)
- goto out_free_pages;
-
- sg_set_page(&sg[i], page, page_len, 0);
- length -= page_len;
- i++;
- }
-
fod->data_sg = sg;
fod->data_sg_cnt = nent;
fod->data_sg_cnt = fc_dma_map_sg(fod->tgtport->dev, sg, nent,
@@ -1717,14 +1699,6 @@ nvmet_fc_alloc_tgt_pgs(struct nvmet_fc_fcp_iod *fod)
return 0;
-out_free_pages:
- while (i > 0) {
- i--;
- __free_page(sg_page(&sg[i]));
- }
- kfree(sg);
- fod->data_sg = NULL;
- fod->data_sg_cnt = 0;
out:
return NVME_SC_INTERNAL;
}
@@ -1732,18 +1706,13 @@ nvmet_fc_alloc_tgt_pgs(struct nvmet_fc_fcp_iod *fod)
static void
nvmet_fc_free_tgt_pgs(struct nvmet_fc_fcp_iod *fod)
{
- struct scatterlist *sg;
- int count;
-
if (!fod->data_sg || !fod->data_sg_cnt)
return;
fc_dma_unmap_sg(fod->tgtport->dev, fod->data_sg, fod->data_sg_cnt,
((fod->io_dir == NVMET_FCP_WRITE) ?
DMA_FROM_DEVICE : DMA_TO_DEVICE));
- for_each_sg(fod->data_sg, sg, fod->data_sg_cnt, count)
- __free_page(sg_page(sg));
- kfree(fod->data_sg);
+ sgl_free(fod->data_sg);
fod->data_sg = NULL;
fod->data_sg_cnt = 0;
}
--
2.14.2
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH 4/8] nvmet/rdma: Use sgl_alloc() and sgl_free()
2017-10-12 22:45 [PATCH 0/8] Introduce sgl_alloc() and sgl_free() Bart Van Assche
` (2 preceding siblings ...)
2017-10-12 22:45 ` [PATCH 3/8] nvmet/fc: Use " Bart Van Assche
@ 2017-10-12 22:45 ` Bart Van Assche
2017-10-13 8:42 ` Johannes Thumshirn
2017-10-12 22:45 ` [PATCH 5/8] target: Use sgl_alloc_order() " Bart Van Assche
` (3 subsequent siblings)
7 siblings, 1 reply; 20+ messages in thread
From: Bart Van Assche @ 2017-10-12 22:45 UTC (permalink / raw)
To: Jens Axboe
Cc: linux-block, linux-scsi, linux-nvme, Bart Van Assche, Keith Busch,
Christoph Hellwig, Sagi Grimberg
Use the sgl_alloc() and sgl_free() functions instead of open coding
these functions.
Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
Cc: Keith Busch <keith.busch@intel.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Sagi Grimberg <sagi@grimberg.me>
---
drivers/nvme/target/Kconfig | 1 +
drivers/nvme/target/rdma.c | 64 ++++-----------------------------------------
2 files changed, 6 insertions(+), 59 deletions(-)
diff --git a/drivers/nvme/target/Kconfig b/drivers/nvme/target/Kconfig
index 4d9715630e21..5f4f8b16685f 100644
--- a/drivers/nvme/target/Kconfig
+++ b/drivers/nvme/target/Kconfig
@@ -29,6 +29,7 @@ config NVME_TARGET_RDMA
tristate "NVMe over Fabrics RDMA target support"
depends on INFINIBAND
depends on NVME_TARGET
+ select SGL_ALLOC
help
This enables the NVMe RDMA target support, which allows exporting NVMe
devices over RDMA.
diff --git a/drivers/nvme/target/rdma.c b/drivers/nvme/target/rdma.c
index 76d2bb793afe..bec0c8421b69 100644
--- a/drivers/nvme/target/rdma.c
+++ b/drivers/nvme/target/rdma.c
@@ -23,6 +23,7 @@
#include <linux/string.h>
#include <linux/wait.h>
#include <linux/inet.h>
+#include <linux/sgl_alloc.h>
#include <asm/unaligned.h>
#include <rdma/ib_verbs.h>
@@ -185,59 +186,6 @@ nvmet_rdma_put_rsp(struct nvmet_rdma_rsp *rsp)
spin_unlock_irqrestore(&rsp->queue->rsps_lock, flags);
}
-static void nvmet_rdma_free_sgl(struct scatterlist *sgl, unsigned int nents)
-{
- struct scatterlist *sg;
- int count;
-
- if (!sgl || !nents)
- return;
-
- for_each_sg(sgl, sg, nents, count)
- __free_page(sg_page(sg));
- kfree(sgl);
-}
-
-static int nvmet_rdma_alloc_sgl(struct scatterlist **sgl, unsigned int *nents,
- u32 length)
-{
- struct scatterlist *sg;
- struct page *page;
- unsigned int nent;
- int i = 0;
-
- nent = DIV_ROUND_UP(length, PAGE_SIZE);
- sg = kmalloc_array(nent, sizeof(struct scatterlist), GFP_KERNEL);
- if (!sg)
- goto out;
-
- sg_init_table(sg, nent);
-
- while (length) {
- u32 page_len = min_t(u32, length, PAGE_SIZE);
-
- page = alloc_page(GFP_KERNEL);
- if (!page)
- goto out_free_pages;
-
- sg_set_page(&sg[i], page, page_len, 0);
- length -= page_len;
- i++;
- }
- *sgl = sg;
- *nents = nent;
- return 0;
-
-out_free_pages:
- while (i > 0) {
- i--;
- __free_page(sg_page(&sg[i]));
- }
- kfree(sg);
-out:
- return NVME_SC_INTERNAL;
-}
-
static int nvmet_rdma_alloc_cmd(struct nvmet_rdma_device *ndev,
struct nvmet_rdma_cmd *c, bool admin)
{
@@ -484,7 +432,7 @@ static void nvmet_rdma_release_rsp(struct nvmet_rdma_rsp *rsp)
}
if (rsp->req.sg != &rsp->cmd->inline_sg)
- nvmet_rdma_free_sgl(rsp->req.sg, rsp->req.sg_cnt);
+ sgl_free(rsp->req.sg);
if (unlikely(!list_empty_careful(&queue->rsp_wr_wait_list)))
nvmet_rdma_process_wr_wait_list(queue);
@@ -620,16 +568,14 @@ static u16 nvmet_rdma_map_sgl_keyed(struct nvmet_rdma_rsp *rsp,
u32 len = get_unaligned_le24(sgl->length);
u32 key = get_unaligned_le32(sgl->key);
int ret;
- u16 status;
/* no data command? */
if (!len)
return 0;
- status = nvmet_rdma_alloc_sgl(&rsp->req.sg, &rsp->req.sg_cnt,
- len);
- if (status)
- return status;
+ rsp->req.sg = sgl_alloc(len, &rsp->req.sg_cnt, GFP_KERNEL);
+ if (!rsp->req.sg)
+ return NVME_SC_INTERNAL;
ret = rdma_rw_ctx_init(&rsp->rw, cm_id->qp, cm_id->port_num,
rsp->req.sg, rsp->req.sg_cnt, 0, addr, key,
--
2.14.2
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH 5/8] target: Use sgl_alloc_order() and sgl_free()
2017-10-12 22:45 [PATCH 0/8] Introduce sgl_alloc() and sgl_free() Bart Van Assche
` (3 preceding siblings ...)
2017-10-12 22:45 ` [PATCH 4/8] nvmet/rdma: " Bart Van Assche
@ 2017-10-12 22:45 ` Bart Van Assche
2017-10-12 22:45 ` [PATCH 6/8] scsi/ipr: Use sgl_alloc_order() and sgl_free_order() Bart Van Assche
` (2 subsequent siblings)
7 siblings, 0 replies; 20+ messages in thread
From: Bart Van Assche @ 2017-10-12 22:45 UTC (permalink / raw)
To: Jens Axboe
Cc: linux-block, linux-scsi, linux-nvme, Bart Van Assche,
Nicholas A . Bellinger, Christoph Hellwig, Hannes Reinecke,
Sagi Grimberg
Use the sgl_alloc_order() and sgl_free() functions instead of open
coding these functions.
Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
Cc: Nicholas A. Bellinger <nab@linux-iscsi.org>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Hannes Reinecke <hare@suse.com>
Cc: Sagi Grimberg <sagi@grimberg.me>
---
drivers/target/Kconfig | 1 +
drivers/target/target_core_transport.c | 47 ++++------------------------------
2 files changed, 6 insertions(+), 42 deletions(-)
diff --git a/drivers/target/Kconfig b/drivers/target/Kconfig
index e2bc99980f75..4c44d7bed01a 100644
--- a/drivers/target/Kconfig
+++ b/drivers/target/Kconfig
@@ -5,6 +5,7 @@ menuconfig TARGET_CORE
select CONFIGFS_FS
select CRC_T10DIF
select BLK_SCSI_REQUEST # only for scsi_command_size_tbl..
+ select SGL_ALLOC
default n
help
Say Y or M here to enable the TCM Storage Engine and ConfigFS enabled
diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
index 836d552b0385..e8f0eabd25ab 100644
--- a/drivers/target/target_core_transport.c
+++ b/drivers/target/target_core_transport.c
@@ -34,6 +34,7 @@
#include <linux/cdrom.h>
#include <linux/module.h>
#include <linux/ratelimit.h>
+#include <linux/sgl_alloc.h>
#include <linux/vmalloc.h>
#include <asm/unaligned.h>
#include <net/sock.h>
@@ -2293,13 +2294,7 @@ static void target_complete_ok_work(struct work_struct *work)
void target_free_sgl(struct scatterlist *sgl, int nents)
{
- struct scatterlist *sg;
- int count;
-
- for_each_sg(sgl, sg, nents, count)
- __free_page(sg_page(sg));
-
- kfree(sgl);
+ sgl_free(sgl);
}
EXPORT_SYMBOL(target_free_sgl);
@@ -2423,42 +2418,10 @@ int
target_alloc_sgl(struct scatterlist **sgl, unsigned int *nents, u32 length,
bool zero_page, bool chainable)
{
- struct scatterlist *sg;
- struct page *page;
- gfp_t zero_flag = (zero_page) ? __GFP_ZERO : 0;
- unsigned int nalloc, nent;
- int i = 0;
-
- nalloc = nent = DIV_ROUND_UP(length, PAGE_SIZE);
- if (chainable)
- nalloc++;
- sg = kmalloc_array(nalloc, sizeof(struct scatterlist), GFP_KERNEL);
- if (!sg)
- return -ENOMEM;
+ gfp_t gfp = GFP_KERNEL | (zero_page ? __GFP_ZERO : 0);
- sg_init_table(sg, nalloc);
-
- while (length) {
- u32 page_len = min_t(u32, length, PAGE_SIZE);
- page = alloc_page(GFP_KERNEL | zero_flag);
- if (!page)
- goto out;
-
- sg_set_page(&sg[i], page, page_len, 0);
- length -= page_len;
- i++;
- }
- *sgl = sg;
- *nents = nent;
- return 0;
-
-out:
- while (i > 0) {
- i--;
- __free_page(sg_page(&sg[i]));
- }
- kfree(sg);
- return -ENOMEM;
+ *sgl = sgl_alloc_order(length, 0, nents, gfp, chainable);
+ return *sgl ? 0 : -ENOMEM;
}
EXPORT_SYMBOL(target_alloc_sgl);
--
2.14.2
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH 6/8] scsi/ipr: Use sgl_alloc_order() and sgl_free_order()
2017-10-12 22:45 [PATCH 0/8] Introduce sgl_alloc() and sgl_free() Bart Van Assche
` (4 preceding siblings ...)
2017-10-12 22:45 ` [PATCH 5/8] target: Use sgl_alloc_order() " Bart Van Assche
@ 2017-10-12 22:45 ` Bart Van Assche
2017-10-13 8:45 ` Johannes Thumshirn
2017-10-12 22:45 ` [PATCH 7/8] scsi/pmcraid: Remove an unused structure member Bart Van Assche
2017-10-12 22:45 ` [PATCH 8/8] scsi/pmcraid: Use sgl_alloc_order() and sgl_free_order() Bart Van Assche
7 siblings, 1 reply; 20+ messages in thread
From: Bart Van Assche @ 2017-10-12 22:45 UTC (permalink / raw)
To: Jens Axboe
Cc: linux-block, linux-scsi, linux-nvme, Bart Van Assche,
Martin K . Petersen, Brian King
Use the sgl_alloc_order() and sgl_free_order() functions instead
of open coding these functions.
Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
Cc: linux-scsi@vger.kernel.org
Cc: Martin K. Petersen <martin.petersen@oracle.com>
Cc: Brian King <brking@linux.vnet.ibm.com>
---
drivers/scsi/Kconfig | 1 +
drivers/scsi/ipr.c | 50 +++++++++-----------------------------------------
drivers/scsi/ipr.h | 2 +-
3 files changed, 11 insertions(+), 42 deletions(-)
diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig
index 41366339b950..d11e75e76195 100644
--- a/drivers/scsi/Kconfig
+++ b/drivers/scsi/Kconfig
@@ -1058,6 +1058,7 @@ config SCSI_IPR
depends on PCI && SCSI && ATA
select FW_LOADER
select IRQ_POLL
+ select SGL_ALLOC
---help---
This driver supports the IBM Power Linux family RAID adapters.
This includes IBM pSeries 5712, 5703, 5709, and 570A, as well
diff --git a/drivers/scsi/ipr.c b/drivers/scsi/ipr.c
index f838bd73befa..b197995a6f34 100644
--- a/drivers/scsi/ipr.c
+++ b/drivers/scsi/ipr.c
@@ -76,6 +76,7 @@
#include <linux/hdreg.h>
#include <linux/reboot.h>
#include <linux/stringify.h>
+#include <linux/sgl_alloc.h>
#include <asm/io.h>
#include <asm/irq.h>
#include <asm/processor.h>
@@ -3815,10 +3816,8 @@ static struct device_attribute ipr_iopoll_weight_attr = {
**/
static struct ipr_sglist *ipr_alloc_ucode_buffer(int buf_len)
{
- int sg_size, order, bsize_elem, num_elem, i, j;
+ int sg_size, order;
struct ipr_sglist *sglist;
- struct scatterlist *scatterlist;
- struct page *page;
/* Get the minimum size per scatter/gather element */
sg_size = buf_len / (IPR_MAX_SGLIST - 1);
@@ -3826,45 +3825,18 @@ static struct ipr_sglist *ipr_alloc_ucode_buffer(int buf_len)
/* Get the actual size per element */
order = get_order(sg_size);
- /* Determine the actual number of bytes per element */
- bsize_elem = PAGE_SIZE * (1 << order);
-
- /* Determine the actual number of sg entries needed */
- if (buf_len % bsize_elem)
- num_elem = (buf_len / bsize_elem) + 1;
- else
- num_elem = buf_len / bsize_elem;
-
/* Allocate a scatter/gather list for the DMA */
- sglist = kzalloc(sizeof(struct ipr_sglist) +
- (sizeof(struct scatterlist) * (num_elem - 1)),
- GFP_KERNEL);
-
+ sglist = kzalloc(sizeof(struct ipr_sglist), GFP_KERNEL);
if (sglist == NULL) {
ipr_trace;
return NULL;
}
-
- scatterlist = sglist->scatterlist;
- sg_init_table(scatterlist, num_elem);
-
sglist->order = order;
- sglist->num_sg = num_elem;
-
- /* Allocate a bunch of sg elements */
- for (i = 0; i < num_elem; i++) {
- page = alloc_pages(GFP_KERNEL, order);
- if (!page) {
- ipr_trace;
-
- /* Free up what we already allocated */
- for (j = i - 1; j >= 0; j--)
- __free_pages(sg_page(&scatterlist[j]), order);
- kfree(sglist);
- return NULL;
- }
-
- sg_set_page(&scatterlist[i], page, 0, 0);
+ sglist->scatterlist = sgl_alloc_order(buf_len, order, &sglist->num_sg,
+ GFP_KERNEL, false);
+ if (!sglist->scatterlist) {
+ kfree(sglist);
+ return NULL;
}
return sglist;
@@ -3882,11 +3854,7 @@ static struct ipr_sglist *ipr_alloc_ucode_buffer(int buf_len)
**/
static void ipr_free_ucode_buffer(struct ipr_sglist *sglist)
{
- int i;
-
- for (i = 0; i < sglist->num_sg; i++)
- __free_pages(sg_page(&sglist->scatterlist[i]), sglist->order);
-
+ sgl_free_order(sglist->scatterlist, sglist->order);
kfree(sglist);
}
diff --git a/drivers/scsi/ipr.h b/drivers/scsi/ipr.h
index c7f0e9e3cd7d..93570734cbfb 100644
--- a/drivers/scsi/ipr.h
+++ b/drivers/scsi/ipr.h
@@ -1454,7 +1454,7 @@ struct ipr_sglist {
u32 num_sg;
u32 num_dma_sg;
u32 buffer_len;
- struct scatterlist scatterlist[1];
+ struct scatterlist *scatterlist;
};
enum ipr_sdt_state {
--
2.14.2
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH 7/8] scsi/pmcraid: Remove an unused structure member
2017-10-12 22:45 [PATCH 0/8] Introduce sgl_alloc() and sgl_free() Bart Van Assche
` (5 preceding siblings ...)
2017-10-12 22:45 ` [PATCH 6/8] scsi/ipr: Use sgl_alloc_order() and sgl_free_order() Bart Van Assche
@ 2017-10-12 22:45 ` Bart Van Assche
2017-10-13 8:45 ` Johannes Thumshirn
2017-10-12 22:45 ` [PATCH 8/8] scsi/pmcraid: Use sgl_alloc_order() and sgl_free_order() Bart Van Assche
7 siblings, 1 reply; 20+ messages in thread
From: Bart Van Assche @ 2017-10-12 22:45 UTC (permalink / raw)
To: Jens Axboe
Cc: linux-block, linux-scsi, linux-nvme, Bart Van Assche,
Martin K . Petersen, Anil Ravindranath
Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
Cc: linux-scsi@vger.kernel.org
Cc: Martin K. Petersen <martin.petersen@oracle.com>
Cc: Anil Ravindranath <anil_ravindranath@pmc-sierra.com>
---
drivers/scsi/pmcraid.h | 1 -
1 file changed, 1 deletion(-)
diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
index 8bfac72a242b..44da91712115 100644
--- a/drivers/scsi/pmcraid.h
+++ b/drivers/scsi/pmcraid.h
@@ -542,7 +542,6 @@ struct pmcraid_sglist {
u32 order;
u32 num_sg;
u32 num_dma_sg;
- u32 buffer_len;
struct scatterlist scatterlist[1];
};
--
2.14.2
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH 8/8] scsi/pmcraid: Use sgl_alloc_order() and sgl_free_order()
2017-10-12 22:45 [PATCH 0/8] Introduce sgl_alloc() and sgl_free() Bart Van Assche
` (6 preceding siblings ...)
2017-10-12 22:45 ` [PATCH 7/8] scsi/pmcraid: Remove an unused structure member Bart Van Assche
@ 2017-10-12 22:45 ` Bart Van Assche
2017-10-13 8:47 ` Johannes Thumshirn
7 siblings, 1 reply; 20+ messages in thread
From: Bart Van Assche @ 2017-10-12 22:45 UTC (permalink / raw)
To: Jens Axboe
Cc: linux-block, linux-scsi, linux-nvme, Bart Van Assche,
Martin K . Petersen, Anil Ravindranath
Use the sgl_alloc_order() and sgl_free_order() functions instead
of open coding these functions.
Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
Cc: linux-scsi@vger.kernel.org
Cc: Martin K. Petersen <martin.petersen@oracle.com>
Cc: Anil Ravindranath <anil_ravindranath@pmc-sierra.com>
---
drivers/scsi/Kconfig | 1 +
drivers/scsi/pmcraid.c | 44 +++++---------------------------------------
drivers/scsi/pmcraid.h | 2 +-
3 files changed, 7 insertions(+), 40 deletions(-)
diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig
index d11e75e76195..632200ec36a6 100644
--- a/drivers/scsi/Kconfig
+++ b/drivers/scsi/Kconfig
@@ -1576,6 +1576,7 @@ config ZFCP
config SCSI_PMCRAID
tristate "PMC SIERRA Linux MaxRAID adapter support"
depends on PCI && SCSI && NET
+ select SGL_ALLOC
---help---
This driver supports the PMC SIERRA MaxRAID adapters.
diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
index b4d6cd8cd1ad..5f3ea3f3dc64 100644
--- a/drivers/scsi/pmcraid.c
+++ b/drivers/scsi/pmcraid.c
@@ -46,6 +46,7 @@
#include <linux/libata.h>
#include <linux/mutex.h>
#include <linux/ktime.h>
+#include <linux/sgl_alloc.h>
#include <scsi/scsi.h>
#include <scsi/scsi_host.h>
#include <scsi/scsi_device.h>
@@ -3232,12 +3233,7 @@ static int pmcraid_build_ioadl(
*/
static void pmcraid_free_sglist(struct pmcraid_sglist *sglist)
{
- int i;
-
- for (i = 0; i < sglist->num_sg; i++)
- __free_pages(sg_page(&(sglist->scatterlist[i])),
- sglist->order);
-
+ sgl_free_order(sglist->scatterlist, sglist->order);
kfree(sglist);
}
@@ -3254,50 +3250,20 @@ static void pmcraid_free_sglist(struct pmcraid_sglist *sglist)
static struct pmcraid_sglist *pmcraid_alloc_sglist(int buflen)
{
struct pmcraid_sglist *sglist;
- struct scatterlist *scatterlist;
- struct page *page;
- int num_elem, i, j;
int sg_size;
int order;
- int bsize_elem;
sg_size = buflen / (PMCRAID_MAX_IOADLS - 1);
order = (sg_size > 0) ? get_order(sg_size) : 0;
- bsize_elem = PAGE_SIZE * (1 << order);
-
- /* Determine the actual number of sg entries needed */
- if (buflen % bsize_elem)
- num_elem = (buflen / bsize_elem) + 1;
- else
- num_elem = buflen / bsize_elem;
/* Allocate a scatter/gather list for the DMA */
- sglist = kzalloc(sizeof(struct pmcraid_sglist) +
- (sizeof(struct scatterlist) * (num_elem - 1)),
- GFP_KERNEL);
-
+ sglist = kzalloc(sizeof(struct pmcraid_sglist), GFP_KERNEL);
if (sglist == NULL)
return NULL;
- scatterlist = sglist->scatterlist;
- sg_init_table(scatterlist, num_elem);
sglist->order = order;
- sglist->num_sg = num_elem;
- sg_size = buflen;
-
- for (i = 0; i < num_elem; i++) {
- page = alloc_pages(GFP_KERNEL|GFP_DMA|__GFP_ZERO, order);
- if (!page) {
- for (j = i - 1; j >= 0; j--)
- __free_pages(sg_page(&scatterlist[j]), order);
- kfree(sglist);
- return NULL;
- }
-
- sg_set_page(&scatterlist[i], page,
- sg_size < bsize_elem ? sg_size : bsize_elem, 0);
- sg_size -= bsize_elem;
- }
+ sgl_alloc_order(buflen, order, &sglist->num_sg,
+ GFP_KERNEL | GFP_DMA | __GFP_ZERO, false);
return sglist;
}
diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
index 44da91712115..754ef30927e2 100644
--- a/drivers/scsi/pmcraid.h
+++ b/drivers/scsi/pmcraid.h
@@ -542,7 +542,7 @@ struct pmcraid_sglist {
u32 order;
u32 num_sg;
u32 num_dma_sg;
- struct scatterlist scatterlist[1];
+ struct scatterlist *scatterlist;
};
/* page D0 inquiry data of focal point resource */
--
2.14.2
^ permalink raw reply related [flat|nested] 20+ messages in thread
* Re: [PATCH 1/8] lib: Introduce sgl_alloc() and sgl_free()
2017-10-12 22:45 ` [PATCH 1/8] lib: " Bart Van Assche
@ 2017-10-12 22:52 ` Jens Axboe
2017-10-12 23:00 ` Bart Van Assche
2017-10-13 17:43 ` Randy Dunlap
1 sibling, 1 reply; 20+ messages in thread
From: Jens Axboe @ 2017-10-12 22:52 UTC (permalink / raw)
To: Bart Van Assche; +Cc: linux-block, linux-scsi, linux-nvme
On 10/12/2017 04:45 PM, Bart Van Assche wrote:
> Many kernel drivers contain code that allocate and free both a
> scatterlist and the pages that populate that scatterlist.
> Introduce functions under lib/ that perform these tasks instead
> of duplicating this functionality in multiple drivers.
>
> Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
> ---
> include/linux/sgl_alloc.h | 16 ++++++++
> lib/Kconfig | 4 ++
> lib/Makefile | 1 +
> lib/sgl_alloc.c | 102 ++++++++++++++++++++++++++++++++++++++++++++++
> 4 files changed, 123 insertions(+)
> create mode 100644 include/linux/sgl_alloc.h
> create mode 100644 lib/sgl_alloc.c
>
> diff --git a/include/linux/sgl_alloc.h b/include/linux/sgl_alloc.h
> new file mode 100644
> index 000000000000..a0f719690c9e
> --- /dev/null
> +++ b/include/linux/sgl_alloc.h
> @@ -0,0 +1,16 @@
> +#ifndef _SGL_ALLOC_H_
> +#define _SGL_ALLOC_H_
> +
> +#include <linux/types.h> /* bool, gfp_t */
> +
> +struct scatterlist;
> +
> +struct scatterlist *sgl_alloc_order(unsigned long long length,
> + unsigned int order, unsigned int *nent_p,
> + gfp_t gfp, bool chainable);
> +struct scatterlist *sgl_alloc(unsigned long long length, unsigned int *nent_p,
> + gfp_t gfp);
> +void sgl_free_order(struct scatterlist *sgl, int order);
> +void sgl_free(struct scatterlist *sgl);
> +
> +#endif /* _SGL_ALLOC_H_ */
Should this just go into linux/scatterlist.h instead of creating a new header
file?
--
Jens Axboe
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH 1/8] lib: Introduce sgl_alloc() and sgl_free()
2017-10-12 22:52 ` Jens Axboe
@ 2017-10-12 23:00 ` Bart Van Assche
2017-10-13 8:44 ` Johannes Thumshirn
2017-10-13 14:20 ` Jens Axboe
0 siblings, 2 replies; 20+ messages in thread
From: Bart Van Assche @ 2017-10-12 23:00 UTC (permalink / raw)
To: axboe@kernel.dk
Cc: linux-scsi@vger.kernel.org, linux-block@vger.kernel.org,
linux-nvme@lists.infradead.org
On Thu, 2017-10-12 at 16:52 -0600, Jens Axboe wrote:
> On 10/12/2017 04:45 PM, Bart Van Assche wrote:
> > +++ b/include/linux/sgl_alloc.h
> > @@ -0,0 +1,16 @@
> > +#ifndef _SGL_ALLOC_H_
> > +#define _SGL_ALLOC_H_
> > +
> > +#include <linux/types.h> /* bool, gfp_t */
> > +
> > +struct scatterlist;
> > +
> > +struct scatterlist *sgl_alloc_order(unsigned long long length,
> > + unsigned int order, unsigned int *nent_p,
> > + gfp_t gfp, bool chainable);
> > +struct scatterlist *sgl_alloc(unsigned long long length, unsigned int *nent_p,
> > + gfp_t gfp);
> > +void sgl_free_order(struct scatterlist *sgl, int order);
> > +void sgl_free(struct scatterlist *sgl);
> > +
> > +#endif /* _SGL_ALLOC_H_ */
>
> Should this just go into linux/scatterlist.h instead of creating a new header
> file?
That's something I can change. I don't have a strong opinion about whether
these declarations should go into a new header file or into linux/scatterlist.h.
Bart.
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH 3/8] nvmet/fc: Use sgl_alloc() and sgl_free()
2017-10-12 22:45 ` [PATCH 3/8] nvmet/fc: Use " Bart Van Assche
@ 2017-10-13 8:41 ` Johannes Thumshirn
0 siblings, 0 replies; 20+ messages in thread
From: Johannes Thumshirn @ 2017-10-13 8:41 UTC (permalink / raw)
To: Bart Van Assche
Cc: Jens Axboe, linux-block, linux-scsi, linux-nvme, Keith Busch,
Christoph Hellwig, James Smart, Sagi Grimberg
Looks good,
Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>
--
Johannes Thumshirn Storage
jthumshirn@suse.de +49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH 4/8] nvmet/rdma: Use sgl_alloc() and sgl_free()
2017-10-12 22:45 ` [PATCH 4/8] nvmet/rdma: " Bart Van Assche
@ 2017-10-13 8:42 ` Johannes Thumshirn
0 siblings, 0 replies; 20+ messages in thread
From: Johannes Thumshirn @ 2017-10-13 8:42 UTC (permalink / raw)
To: Bart Van Assche
Cc: Jens Axboe, linux-block, linux-scsi, linux-nvme, Keith Busch,
Christoph Hellwig, Sagi Grimberg
Looks good,
Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>
--
Johannes Thumshirn Storage
jthumshirn@suse.de +49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH 1/8] lib: Introduce sgl_alloc() and sgl_free()
2017-10-12 23:00 ` Bart Van Assche
@ 2017-10-13 8:44 ` Johannes Thumshirn
2017-10-13 14:20 ` Jens Axboe
1 sibling, 0 replies; 20+ messages in thread
From: Johannes Thumshirn @ 2017-10-13 8:44 UTC (permalink / raw)
To: Bart Van Assche
Cc: axboe@kernel.dk, linux-scsi@vger.kernel.org,
linux-block@vger.kernel.org, linux-nvme@lists.infradead.org
On Thu, Oct 12, 2017 at 11:00:10PM +0000, Bart Van Assche wrote:
> On Thu, 2017-10-12 at 16:52 -0600, Jens Axboe wrote:
> > On 10/12/2017 04:45 PM, Bart Van Assche wrote:
> > > +++ b/include/linux/sgl_alloc.h
> > > @@ -0,0 +1,16 @@
> > > +#ifndef _SGL_ALLOC_H_
> > > +#define _SGL_ALLOC_H_
> > > +
> > > +#include <linux/types.h> /* bool, gfp_t */
> > > +
> > > +struct scatterlist;
> > > +
> > > +struct scatterlist *sgl_alloc_order(unsigned long long length,
> > > + unsigned int order, unsigned int *nent_p,
> > > + gfp_t gfp, bool chainable);
> > > +struct scatterlist *sgl_alloc(unsigned long long length, unsigned int *nent_p,
> > > + gfp_t gfp);
> > > +void sgl_free_order(struct scatterlist *sgl, int order);
> > > +void sgl_free(struct scatterlist *sgl);
> > > +
> > > +#endif /* _SGL_ALLOC_H_ */
> >
> > Should this just go into linux/scatterlist.h instead of creating a new header
> > file?
>
> That's something I can change. I don't have a strong opinion about whether
> these declarations should go into a new header file or into linux/scatterlist.h.
Yes please do (and the implementaion should go into lib/scatterlist.c).
Additionally please get rid of the new CONFIG_SGL_ALLOC as well.
Thanks,
Johannes
--
Johannes Thumshirn Storage
jthumshirn@suse.de +49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH 6/8] scsi/ipr: Use sgl_alloc_order() and sgl_free_order()
2017-10-12 22:45 ` [PATCH 6/8] scsi/ipr: Use sgl_alloc_order() and sgl_free_order() Bart Van Assche
@ 2017-10-13 8:45 ` Johannes Thumshirn
0 siblings, 0 replies; 20+ messages in thread
From: Johannes Thumshirn @ 2017-10-13 8:45 UTC (permalink / raw)
To: Bart Van Assche
Cc: Jens Axboe, linux-block, linux-scsi, linux-nvme,
Martin K . Petersen, Brian King
Looks good,
Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>
--
Johannes Thumshirn Storage
jthumshirn@suse.de +49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH 7/8] scsi/pmcraid: Remove an unused structure member
2017-10-12 22:45 ` [PATCH 7/8] scsi/pmcraid: Remove an unused structure member Bart Van Assche
@ 2017-10-13 8:45 ` Johannes Thumshirn
0 siblings, 0 replies; 20+ messages in thread
From: Johannes Thumshirn @ 2017-10-13 8:45 UTC (permalink / raw)
To: Bart Van Assche
Cc: Jens Axboe, linux-block, linux-scsi, linux-nvme,
Martin K . Petersen, Anil Ravindranath
Fair enough,
Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>
--
Johannes Thumshirn Storage
jthumshirn@suse.de +49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH 8/8] scsi/pmcraid: Use sgl_alloc_order() and sgl_free_order()
2017-10-12 22:45 ` [PATCH 8/8] scsi/pmcraid: Use sgl_alloc_order() and sgl_free_order() Bart Van Assche
@ 2017-10-13 8:47 ` Johannes Thumshirn
0 siblings, 0 replies; 20+ messages in thread
From: Johannes Thumshirn @ 2017-10-13 8:47 UTC (permalink / raw)
To: Bart Van Assche
Cc: Jens Axboe, linux-block, linux-scsi, linux-nvme,
Martin K . Petersen, Anil Ravindranath
Looks good,
Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>
--
Johannes Thumshirn Storage
jthumshirn@suse.de +49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH 1/8] lib: Introduce sgl_alloc() and sgl_free()
2017-10-12 23:00 ` Bart Van Assche
2017-10-13 8:44 ` Johannes Thumshirn
@ 2017-10-13 14:20 ` Jens Axboe
1 sibling, 0 replies; 20+ messages in thread
From: Jens Axboe @ 2017-10-13 14:20 UTC (permalink / raw)
To: Bart Van Assche
Cc: linux-scsi@vger.kernel.org, linux-block@vger.kernel.org,
linux-nvme@lists.infradead.org
On 10/12/2017 05:00 PM, Bart Van Assche wrote:
> On Thu, 2017-10-12 at 16:52 -0600, Jens Axboe wrote:
>> On 10/12/2017 04:45 PM, Bart Van Assche wrote:
>>> +++ b/include/linux/sgl_alloc.h
>>> @@ -0,0 +1,16 @@
>>> +#ifndef _SGL_ALLOC_H_
>>> +#define _SGL_ALLOC_H_
>>> +
>>> +#include <linux/types.h> /* bool, gfp_t */
>>> +
>>> +struct scatterlist;
>>> +
>>> +struct scatterlist *sgl_alloc_order(unsigned long long length,
>>> + unsigned int order, unsigned int *nent_p,
>>> + gfp_t gfp, bool chainable);
>>> +struct scatterlist *sgl_alloc(unsigned long long length, unsigned int *nent_p,
>>> + gfp_t gfp);
>>> +void sgl_free_order(struct scatterlist *sgl, int order);
>>> +void sgl_free(struct scatterlist *sgl);
>>> +
>>> +#endif /* _SGL_ALLOC_H_ */
>>
>> Should this just go into linux/scatterlist.h instead of creating a new header
>> file?
>
> That's something I can change. I don't have a strong opinion about whether
> these declarations should go into a new header file or into linux/scatterlist.h.
I think you should make that change, keep things simpler. As Johannes
suggested, you could move the code to lib/scatterlist.c as well. I would
recommend keeping the kconfig option to only build it when needed, though.
--
Jens Axboe
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH 1/8] lib: Introduce sgl_alloc() and sgl_free()
2017-10-12 22:45 ` [PATCH 1/8] lib: " Bart Van Assche
2017-10-12 22:52 ` Jens Axboe
@ 2017-10-13 17:43 ` Randy Dunlap
2017-10-13 17:56 ` Bart Van Assche
1 sibling, 1 reply; 20+ messages in thread
From: Randy Dunlap @ 2017-10-13 17:43 UTC (permalink / raw)
To: Bart Van Assche, Jens Axboe; +Cc: linux-block, linux-scsi, linux-nvme
On 10/12/17 15:45, Bart Van Assche wrote:
> diff --git a/lib/sgl_alloc.c b/lib/sgl_alloc.c
> new file mode 100644
> index 000000000000..d96b395dd5c8
> --- /dev/null
> +++ b/lib/sgl_alloc.c
> @@ -0,0 +1,102 @@
> +/**
> + * sgl_free_order - free a scatterlist and its pages
> + * @sg: Scatterlist with one or more elements
@sgl:
> + * @order: Second argument for __free_pages()
> + */
> +void sgl_free_order(struct scatterlist *sgl, int order)
> +{
> + struct scatterlist *sg;
> + struct page *page;
> +
> + for (sg = sgl; sg; sg = sg_next(sg)) {
> + page = sg_page(sg);
> + if (page)
> + __free_pages(page, order);
> + }
> + kfree(sgl);
> +}
> +EXPORT_SYMBOL(sgl_free_order);
> +
> +/**
> + * sgl_free - free a scatterlist and its pages
> + * @sg: Scatterlist with one or more elements
@sgl:
> + */
> +void sgl_free(struct scatterlist *sgl)
> +{
> + sgl_free_order(sgl, 0);
> +}
> +EXPORT_SYMBOL(sgl_free);
>
ta.
--
~Randy
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH 1/8] lib: Introduce sgl_alloc() and sgl_free()
2017-10-13 17:43 ` Randy Dunlap
@ 2017-10-13 17:56 ` Bart Van Assche
0 siblings, 0 replies; 20+ messages in thread
From: Bart Van Assche @ 2017-10-13 17:56 UTC (permalink / raw)
To: rdunlap@infradead.org, axboe@kernel.dk
Cc: linux-scsi@vger.kernel.org, linux-block@vger.kernel.org,
linux-nvme@lists.infradead.org
On Fri, 2017-10-13 at 10:43 -0700, Randy Dunlap wrote:
> On 10/12/17 15:45, Bart Van Assche wrote:
> > + * @sg: Scatterlist with one or more elements
>
> @sgl:
Thanks Randy. I will fix this before I repost this series.
Bart.
^ permalink raw reply [flat|nested] 20+ messages in thread
end of thread, other threads:[~2017-10-13 17:56 UTC | newest]
Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-10-12 22:45 [PATCH 0/8] Introduce sgl_alloc() and sgl_free() Bart Van Assche
2017-10-12 22:45 ` [PATCH 1/8] lib: " Bart Van Assche
2017-10-12 22:52 ` Jens Axboe
2017-10-12 23:00 ` Bart Van Assche
2017-10-13 8:44 ` Johannes Thumshirn
2017-10-13 14:20 ` Jens Axboe
2017-10-13 17:43 ` Randy Dunlap
2017-10-13 17:56 ` Bart Van Assche
2017-10-12 22:45 ` [PATCH 2/8] crypto: scompress - use " Bart Van Assche
2017-10-12 22:45 ` [PATCH 3/8] nvmet/fc: Use " Bart Van Assche
2017-10-13 8:41 ` Johannes Thumshirn
2017-10-12 22:45 ` [PATCH 4/8] nvmet/rdma: " Bart Van Assche
2017-10-13 8:42 ` Johannes Thumshirn
2017-10-12 22:45 ` [PATCH 5/8] target: Use sgl_alloc_order() " Bart Van Assche
2017-10-12 22:45 ` [PATCH 6/8] scsi/ipr: Use sgl_alloc_order() and sgl_free_order() Bart Van Assche
2017-10-13 8:45 ` Johannes Thumshirn
2017-10-12 22:45 ` [PATCH 7/8] scsi/pmcraid: Remove an unused structure member Bart Van Assche
2017-10-13 8:45 ` Johannes Thumshirn
2017-10-12 22:45 ` [PATCH 8/8] scsi/pmcraid: Use sgl_alloc_order() and sgl_free_order() Bart Van Assche
2017-10-13 8:47 ` Johannes Thumshirn
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).