Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 128147
b: refs/heads/master
c: 8a4c249
h: refs/heads/master
i:
  128145: ff22874
  128143: e55e2e8
v: v3
  • Loading branch information
Alexey Korolev authored and David Woodhouse committed Dec 10, 2008
1 parent c54c5d9 commit be93970
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: a9fc8991883cdf029bd373a82cbc2d12a10799dd
refs/heads/master: 8a4c2495b142fe612b291a810d9e695f269c26db
25 changes: 18 additions & 7 deletions trunk/drivers/mtd/nand/nandsim.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,9 @@ struct nandsim {
/* The simulated NAND flash pages array */
union ns_mem *pages;

/* Slab allocator for nand pages */
struct kmem_cache *nand_pages_slab;

/* Internal buffer of page + OOB size bytes */
union ns_mem buf;

Expand Down Expand Up @@ -435,8 +438,8 @@ static struct mtd_info *nsmtd;
static u_char ns_verify_buf[NS_LARGEST_PAGE_SIZE];

/*
* Allocate array of page pointers and initialize the array to NULL
* pointers.
* Allocate array of page pointers, create slab allocation for an array
* and initialize the array by NULL pointers.
*
* RETURNS: 0 if success, -ENOMEM if memory alloc fails.
*/
Expand Down Expand Up @@ -484,6 +487,12 @@ static int alloc_device(struct nandsim *ns)
for (i = 0; i < ns->geom.pgnum; i++) {
ns->pages[i].byte = NULL;
}
ns->nand_pages_slab = kmem_cache_create("nandsim",
ns->geom.pgszoob, 0, 0, NULL);
if (!ns->nand_pages_slab) {
NS_ERR("cache_create: unable to create kmem_cache\n");
return -ENOMEM;
}

return 0;

Expand Down Expand Up @@ -511,8 +520,10 @@ static void free_device(struct nandsim *ns)
if (ns->pages) {
for (i = 0; i < ns->geom.pgnum; i++) {
if (ns->pages[i].byte)
kfree(ns->pages[i].byte);
kmem_cache_free(ns->nand_pages_slab,
ns->pages[i].byte);
}
kmem_cache_destroy(ns->nand_pages_slab);
vfree(ns->pages);
}
}
Expand Down Expand Up @@ -1475,7 +1486,7 @@ static void erase_sector(struct nandsim *ns)
for (i = 0; i < ns->geom.pgsec; i++) {
if (mypage->byte != NULL) {
NS_DBG("erase_sector: freeing page %d\n", ns->regs.row+i);
kfree(mypage->byte);
kmem_cache_free(ns->nand_pages_slab, mypage->byte);
mypage->byte = NULL;
}
mypage++;
Expand Down Expand Up @@ -1538,10 +1549,10 @@ static int prog_page(struct nandsim *ns, int num)
/*
* We allocate memory with GFP_NOFS because a flash FS may
* utilize this. If it is holding an FS lock, then gets here,
* then kmalloc runs writeback which goes to the FS again
* and deadlocks. This was seen in practice.
* then kernel memory alloc runs writeback which goes to the FS
* again and deadlocks. This was seen in practice.
*/
mypage->byte = kmalloc(ns->geom.pgszoob, GFP_NOFS);
mypage->byte = kmem_cache_alloc(ns->nand_pages_slab, GFP_NOFS);
if (mypage->byte == NULL) {
NS_ERR("prog_page: error allocating memory for page %d\n", ns->regs.row);
return -1;
Expand Down

0 comments on commit be93970

Please sign in to comment.