Commit 97eb6b69 authored by David Sterba's avatar David Sterba

btrfs: use slab for end_io_wq structures

The structure is frequently reused.  Rename it according to the slab
name.
Signed-off-by: default avatarDavid Sterba <dsterba@suse.cz>
parent af13b492
...@@ -72,11 +72,11 @@ static int btrfs_cleanup_transaction(struct btrfs_root *root); ...@@ -72,11 +72,11 @@ static int btrfs_cleanup_transaction(struct btrfs_root *root);
static void btrfs_error_commit_super(struct btrfs_root *root); static void btrfs_error_commit_super(struct btrfs_root *root);
/* /*
* end_io_wq structs are used to do processing in task context when an IO is * btrfs_end_io_wq structs are used to do processing in task context when an IO
* complete. This is used during reads to verify checksums, and it is used * is complete. This is used during reads to verify checksums, and it is used
* by writes to insert metadata for new file extents after IO is complete. * by writes to insert metadata for new file extents after IO is complete.
*/ */
struct end_io_wq { struct btrfs_end_io_wq {
struct bio *bio; struct bio *bio;
bio_end_io_t *end_io; bio_end_io_t *end_io;
void *private; void *private;
...@@ -87,6 +87,26 @@ struct end_io_wq { ...@@ -87,6 +87,26 @@ struct end_io_wq {
struct btrfs_work work; struct btrfs_work work;
}; };
static struct kmem_cache *btrfs_end_io_wq_cache;
int __init btrfs_end_io_wq_init(void)
{
btrfs_end_io_wq_cache = kmem_cache_create("btrfs_end_io_wq",
sizeof(struct btrfs_end_io_wq),
0,
SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD,
NULL);
if (!btrfs_end_io_wq_cache)
return -ENOMEM;
return 0;
}
void btrfs_end_io_wq_exit(void)
{
if (btrfs_end_io_wq_cache)
kmem_cache_destroy(btrfs_end_io_wq_cache);
}
/* /*
* async submit bios are used to offload expensive checksumming * async submit bios are used to offload expensive checksumming
* onto the worker threads. They checksum file and metadata bios * onto the worker threads. They checksum file and metadata bios
...@@ -690,7 +710,7 @@ static int btree_io_failed_hook(struct page *page, int failed_mirror) ...@@ -690,7 +710,7 @@ static int btree_io_failed_hook(struct page *page, int failed_mirror)
static void end_workqueue_bio(struct bio *bio, int err) static void end_workqueue_bio(struct bio *bio, int err)
{ {
struct end_io_wq *end_io_wq = bio->bi_private; struct btrfs_end_io_wq *end_io_wq = bio->bi_private;
struct btrfs_fs_info *fs_info; struct btrfs_fs_info *fs_info;
struct btrfs_workqueue *wq; struct btrfs_workqueue *wq;
btrfs_work_func_t func; btrfs_work_func_t func;
...@@ -736,9 +756,9 @@ static void end_workqueue_bio(struct bio *bio, int err) ...@@ -736,9 +756,9 @@ static void end_workqueue_bio(struct bio *bio, int err)
int btrfs_bio_wq_end_io(struct btrfs_fs_info *info, struct bio *bio, int btrfs_bio_wq_end_io(struct btrfs_fs_info *info, struct bio *bio,
enum btrfs_wq_endio_type metadata) enum btrfs_wq_endio_type metadata)
{ {
struct end_io_wq *end_io_wq; struct btrfs_end_io_wq *end_io_wq;
end_io_wq = kmalloc(sizeof(*end_io_wq), GFP_NOFS); end_io_wq = kmem_cache_alloc(btrfs_end_io_wq_cache, GFP_NOFS);
if (!end_io_wq) if (!end_io_wq)
return -ENOMEM; return -ENOMEM;
...@@ -1723,16 +1743,16 @@ static int setup_bdi(struct btrfs_fs_info *info, struct backing_dev_info *bdi) ...@@ -1723,16 +1743,16 @@ static int setup_bdi(struct btrfs_fs_info *info, struct backing_dev_info *bdi)
static void end_workqueue_fn(struct btrfs_work *work) static void end_workqueue_fn(struct btrfs_work *work)
{ {
struct bio *bio; struct bio *bio;
struct end_io_wq *end_io_wq; struct btrfs_end_io_wq *end_io_wq;
int error; int error;
end_io_wq = container_of(work, struct end_io_wq, work); end_io_wq = container_of(work, struct btrfs_end_io_wq, work);
bio = end_io_wq->bio; bio = end_io_wq->bio;
error = end_io_wq->error; error = end_io_wq->error;
bio->bi_private = end_io_wq->private; bio->bi_private = end_io_wq->private;
bio->bi_end_io = end_io_wq->end_io; bio->bi_end_io = end_io_wq->end_io;
kfree(end_io_wq); kmem_cache_free(btrfs_end_io_wq_cache, end_io_wq);
bio_endio_nodec(bio, error); bio_endio_nodec(bio, error);
} }
......
...@@ -142,6 +142,8 @@ int btree_lock_page_hook(struct page *page, void *data, ...@@ -142,6 +142,8 @@ int btree_lock_page_hook(struct page *page, void *data,
void (*flush_fn)(void *)); void (*flush_fn)(void *));
int btrfs_calc_num_tolerated_disk_barrier_failures( int btrfs_calc_num_tolerated_disk_barrier_failures(
struct btrfs_fs_info *fs_info); struct btrfs_fs_info *fs_info);
int __init btrfs_end_io_wq_init(void);
void btrfs_end_io_wq_exit(void);
#ifdef CONFIG_DEBUG_LOCK_ALLOC #ifdef CONFIG_DEBUG_LOCK_ALLOC
void btrfs_init_lockdep(void); void btrfs_init_lockdep(void);
......
...@@ -2001,10 +2001,14 @@ static int __init init_btrfs_fs(void) ...@@ -2001,10 +2001,14 @@ static int __init init_btrfs_fs(void)
if (err) if (err)
goto free_delayed_ref; goto free_delayed_ref;
err = btrfs_interface_init(); err = btrfs_end_io_wq_init();
if (err) if (err)
goto free_prelim_ref; goto free_prelim_ref;
err = btrfs_interface_init();
if (err)
goto free_end_io_wq;
btrfs_init_lockdep(); btrfs_init_lockdep();
btrfs_print_info(); btrfs_print_info();
...@@ -2021,6 +2025,8 @@ static int __init init_btrfs_fs(void) ...@@ -2021,6 +2025,8 @@ static int __init init_btrfs_fs(void)
unregister_ioctl: unregister_ioctl:
btrfs_interface_exit(); btrfs_interface_exit();
free_end_io_wq:
btrfs_end_io_wq_exit();
free_prelim_ref: free_prelim_ref:
btrfs_prelim_ref_exit(); btrfs_prelim_ref_exit();
free_delayed_ref: free_delayed_ref:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment