From: Boaz Harrosh <boaz@plexistor.com>
To: Ross Zwisler <ross.zwisler@linux.intel.com>,
Jens Axboe <axboe@fb.com>,
Matthew Wilcox <matthew.r.wilcox@intel.com>,
linux-fsdevel <linux-fsdevel@vger.kernel.org>,
linux-nvdimm@lists.01.org
Cc: Andrew Morton <akpm@linux-foundation.org>
Subject: [PATCH 3/9] SQUASHME: pmem: Let each device manage private memory region
Date: Tue, 09 Sep 2014 18:43:04 +0300 [thread overview]
Message-ID: <540F2008.9050809@plexistor.com> (raw)
In-Reply-To: <540F1EC6.4000504@plexistor.com>
From: Boaz Harrosh <boaz@plexistor.com>
This patch removes any global memory information. And lets
each pmem-device manage it's own memory region.
pmem_alloc() Now receives phys_addr and disk_size and will
map that region, also pmem_free will do the unmaping.
This is so we can support multiple discontinuous memory regions
in the next patch
Signed-off-by: Boaz Harrosh <boaz@plexistor.com>
---
drivers/block/pmem.c | 122 +++++++++++++++++++++++++++++++--------------------
1 file changed, 75 insertions(+), 47 deletions(-)
diff --git a/drivers/block/pmem.c b/drivers/block/pmem.c
index 499536c..d5c5c52 100644
--- a/drivers/block/pmem.c
+++ b/drivers/block/pmem.c
@@ -27,19 +27,12 @@
#define PAGE_SECTORS_SHIFT (PAGE_SHIFT - SECTOR_SHIFT)
#define PAGE_SECTORS (1 << PAGE_SECTORS_SHIFT)
-/*
- * driver-wide physical address and total_size - one single, contiguous memory
- * region that we divide up in to same-sized devices
- */
-phys_addr_t phys_addr;
-void *virt_addr;
-size_t total_size;
-
struct pmem_device {
struct request_queue *pmem_queue;
struct gendisk *pmem_disk;
struct list_head pmem_list;
+ /* One contiguous memory region per device */
phys_addr_t phys_addr;
void *virt_addr;
size_t size;
@@ -234,26 +227,70 @@ MODULE_PARM_DESC(pmem_count, "Number of pmem devices to evenly split allocated s
static LIST_HEAD(pmem_devices);
static int pmem_major;
-/* FIXME: move phys_addr, virt_addr, size calls up to caller */
-static struct pmem_device *pmem_alloc(int i)
+/* pmem->phys_addr and pmem->size need to be set.
+ * Will then set virt_addr if successful.
+ */
+int pmem_mapmem(struct pmem_device *pmem)
+{
+ struct resource *res_mem;
+ int err;
+
+ res_mem = request_mem_region_exclusive(pmem->phys_addr, pmem->size,
+ "pmem");
+ if (!res_mem) {
+ pr_warn("pmem: request_mem_region_exclusive phys=0x%llx size=0x%zx failed\n",
+ pmem->phys_addr, pmem->size);
+ return -EINVAL;
+ }
+
+ pmem->virt_addr = ioremap_cache(pmem->phys_addr, pmem->size);
+ if (unlikely(!pmem->virt_addr)) {
+ err = -ENXIO;
+ goto out_release;
+ }
+ return 0;
+
+out_release:
+ release_mem_region(pmem->phys_addr, pmem->size);
+ return err;
+}
+
+void pmem_unmapmem(struct pmem_device *pmem)
+{
+ if (unlikely(!pmem->virt_addr))
+ return;
+
+ iounmap(pmem->virt_addr);
+ release_mem_region(pmem->phys_addr, pmem->size);
+ pmem->virt_addr = NULL;
+}
+
+static struct pmem_device *pmem_alloc(phys_addr_t phys_addr, size_t disk_size,
+ int i)
{
struct pmem_device *pmem;
struct gendisk *disk;
- size_t disk_size = total_size / pmem_count;
- size_t disk_sectors = disk_size / 512;
+ int err;
pmem = kzalloc(sizeof(*pmem), GFP_KERNEL);
- if (!pmem)
+ if (unlikely(!pmem)) {
+ err = -ENOMEM;
goto out;
+ }
- pmem->phys_addr = phys_addr + i * disk_size;
- pmem->virt_addr = virt_addr + i * disk_size;
+ pmem->phys_addr = phys_addr;
pmem->size = disk_size;
- pmem->pmem_queue = blk_alloc_queue(GFP_KERNEL);
- if (!pmem->pmem_queue)
+ err = pmem_mapmem(pmem);
+ if (unlikely(err))
goto out_free_dev;
+ pmem->pmem_queue = blk_alloc_queue(GFP_KERNEL);
+ if (unlikely(!pmem->pmem_queue)) {
+ err = -ENOMEM;
+ goto out_unmap;
+ }
+
blk_queue_make_request(pmem->pmem_queue, pmem_make_request);
blk_queue_max_hw_sectors(pmem->pmem_queue, 1024);
blk_queue_bounce_limit(pmem->pmem_queue, BLK_BOUNCE_ANY);
@@ -264,9 +301,12 @@ static struct pmem_device *pmem_alloc(int i)
blk_queue_physical_block_size(pmem->pmem_queue, PAGE_SIZE);
pmem->pmem_queue->limits.io_min = 512; /* Don't use the accessor */
- disk = pmem->pmem_disk = alloc_disk(0);
- if (!disk)
+ disk = alloc_disk(0);
+ if (unlikely(!disk)) {
+ err = -ENOMEM;
goto out_free_queue;
+ }
+
disk->major = pmem_major;
disk->first_minor = 0;
disk->fops = &pmem_fops;
@@ -274,22 +314,26 @@ static struct pmem_device *pmem_alloc(int i)
disk->queue = pmem->pmem_queue;
disk->flags = GENHD_FL_EXT_DEVT;
sprintf(disk->disk_name, "pmem%d", i);
- set_capacity(disk, disk_sectors);
+ set_capacity(disk, disk_size >> SECTOR_SHIFT);
+ pmem->pmem_disk = disk;
return pmem;
out_free_queue:
blk_cleanup_queue(pmem->pmem_queue);
+out_unmap:
+ pmem_unmapmem(pmem);
out_free_dev:
kfree(pmem);
out:
- return NULL;
+ return ERR_PTR(err);
}
static void pmem_free(struct pmem_device *pmem)
{
put_disk(pmem->pmem_disk);
blk_cleanup_queue(pmem->pmem_queue);
+ pmem_unmapmem(pmem);
kfree(pmem);
}
@@ -303,36 +347,28 @@ static void pmem_del_one(struct pmem_device *pmem)
static int __init pmem_init(void)
{
int result, i;
- struct resource *res_mem;
struct pmem_device *pmem, *next;
+ phys_addr_t phys_addr;
+ size_t total_size, disk_size;
phys_addr = (phys_addr_t) pmem_start_gb * 1024 * 1024 * 1024;
total_size = (size_t) pmem_size_gb * 1024 * 1024 * 1024;
-
- res_mem = request_mem_region_exclusive(phys_addr, total_size, "pmem");
- if (!res_mem)
- return -ENOMEM;
-
- virt_addr = ioremap_cache(phys_addr, total_size);
- if (!virt_addr) {
- result = -ENOMEM;
- goto out_release;
- }
+ disk_size = total_size / pmem_count;
result = register_blkdev(0, "pmem");
- if (result < 0) {
- result = -EIO;
- goto out_unmap;
- } else
+ if (result < 0)
+ return -EIO;
+ else
pmem_major = result;
for (i = 0; i < pmem_count; i++) {
- pmem = pmem_alloc(i);
- if (!pmem) {
- result = -ENOMEM;
+ pmem = pmem_alloc(phys_addr, disk_size, i);
+ if (IS_ERR(pmem)) {
+ result = PTR_ERR(pmem);
goto out_free;
}
list_add_tail(&pmem->pmem_list, &pmem_devices);
+ phys_addr += disk_size;
}
list_for_each_entry(pmem, &pmem_devices, pmem_list)
@@ -348,11 +384,6 @@ out_free:
}
unregister_blkdev(pmem_major, "pmem");
-out_unmap:
- iounmap(virt_addr);
-
-out_release:
- release_mem_region(phys_addr, total_size);
return result;
}
@@ -364,9 +395,6 @@ static void __exit pmem_exit(void)
pmem_del_one(pmem);
unregister_blkdev(pmem_major, "pmem");
- iounmap(virt_addr);
- release_mem_region(phys_addr, total_size);
-
pr_info("pmem: module unloaded\n");
}
--
1.9.3
next prev parent reply other threads:[~2014-09-09 15:43 UTC|newest]
Thread overview: 63+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-27 21:11 [PATCH 0/4] Add persistent memory driver Ross Zwisler
2014-08-27 21:11 ` [PATCH 1/4] pmem: Initial version of " Ross Zwisler
2014-09-09 16:23 ` [PATCH v2] " Boaz Harrosh
2014-09-09 16:53 ` [Linux-nvdimm] " Dan Williams
2014-09-10 13:23 ` Boaz Harrosh
2014-09-10 17:03 ` Dan Williams
2014-09-10 17:47 ` Boaz Harrosh
2014-09-10 23:01 ` Dan Williams
2014-09-11 10:45 ` Boaz Harrosh
2014-09-11 16:31 ` Dan Williams
2014-09-14 11:18 ` Boaz Harrosh
2014-09-16 13:54 ` Jeff Moyer
2014-09-16 16:24 ` Boaz Harrosh
2014-09-19 16:27 ` Dan Williams
2014-09-21 9:27 ` Boaz Harrosh
2014-11-02 3:22 ` [PATCH 1/4] " Elliott, Robert (Server Storage)
2014-11-03 15:50 ` Jeff Moyer
2014-11-03 16:19 ` Wilcox, Matthew R
2014-11-04 10:37 ` Boaz Harrosh
2014-11-04 16:26 ` Elliott, Robert (Server Storage)
2014-11-04 16:41 ` Ross Zwisler
2014-11-04 17:06 ` Boaz Harrosh
2014-08-27 21:12 ` [PATCH 2/4] pmem: Add support for getgeo() Ross Zwisler
2014-11-02 3:27 ` Elliott, Robert (Server Storage)
2014-11-03 16:36 ` Wilcox, Matthew R
2014-08-27 21:12 ` [PATCH 3/4] pmem: Add support for rw_page() Ross Zwisler
2014-08-27 21:12 ` [PATCH 4/4] pmem: Add support for direct_access() Ross Zwisler
2014-09-09 15:37 ` [PATCH 0/9] pmem: Fixes and farther development (mm: add_persistent_memory) Boaz Harrosh
2014-09-09 15:40 ` [PATCH 1/9] SQUASHME: pmem: Remove unused #include headers Boaz Harrosh
2014-09-09 22:29 ` Ross Zwisler
2014-09-10 11:36 ` Boaz Harrosh
2014-09-10 19:16 ` [Linux-nvdimm] " Matthew Wilcox
2014-09-11 11:35 ` Boaz Harrosh
2014-09-11 19:34 ` Matthew Wilcox
2014-09-09 15:41 ` [PATCH 2/9] SQUASHME: pmem: Request from fdisk 4k alignment Boaz Harrosh
2014-09-11 18:39 ` Ross Zwisler
2014-09-14 11:25 ` Boaz Harrosh
2014-09-09 15:43 ` Boaz Harrosh [this message]
2014-09-11 20:35 ` [PATCH 3/9] SQUASHME: pmem: Let each device manage private memory region Ross Zwisler
2014-09-09 15:44 ` [PATCH 4/9] SQUASHME: pmem: Support of multiple memory regions Boaz Harrosh
2014-09-09 15:45 ` [PATCH 5/9] mm: Let sparse_{add,remove}_one_section receive a node_id Boaz Harrosh
2014-09-09 18:36 ` Dave Hansen
2014-09-10 10:07 ` Boaz Harrosh
2014-09-10 16:10 ` Dave Hansen
2014-09-10 17:25 ` Boaz Harrosh
2014-09-10 18:28 ` Dave Hansen
2014-09-11 8:39 ` Boaz Harrosh
2014-09-11 17:07 ` Dave Hansen
2014-09-14 9:36 ` Boaz Harrosh
2014-09-09 15:47 ` [PATCH 6/9] mm: New add_persistent_memory/remove_persistent_memory Boaz Harrosh
2014-09-09 15:48 ` [PATCH 7/9] pmem: Add support for page structs Boaz Harrosh
2014-09-09 15:49 ` [PATCH 8/9] SQUASHME: pmem: Fixs to getgeo Boaz Harrosh
2014-09-09 15:51 ` [PATCH 9/9] pmem: KISS, remove register_blkdev Boaz Harrosh
2014-09-10 16:50 ` [PATCH] SQUASHME pmem: Micro optimization for pmem_direct_access Boaz Harrosh
2014-09-10 22:32 ` Ross Zwisler
2014-09-11 11:42 ` Boaz Harrosh
2014-09-14 14:58 ` [PATCH v2] SQUASHME pmem: Micro optimize the hotpath Boaz Harrosh
2014-09-14 16:02 ` [PATCH] SQUASHME: pmem: no need to copy a page at a time Boaz Harrosh
2014-09-15 0:23 ` Wilcox, Matthew R
2014-09-15 8:47 ` Boaz Harrosh
2014-09-10 17:50 ` [PATCH] SQUASHME: pmem: Add MODULE_ALIAS Boaz Harrosh
2014-09-10 19:22 ` Ross Zwisler
2014-09-11 11:44 ` Boaz Harrosh
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=540F2008.9050809@plexistor.com \
--to=boaz@plexistor.com \
--cc=akpm@linux-foundation.org \
--cc=axboe@fb.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-nvdimm@lists.01.org \
--cc=matthew.r.wilcox@intel.com \
--cc=ross.zwisler@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).