Commit c68d6c88 authored by Chao Yu's avatar Chao Yu Committed by Jaegeuk Kim

f2fs: compress: introduce cic/dic slab cache

Add two slab caches: "f2fs_cic_entry" and "f2fs_dic_entry" for memory
allocation of compress_io_ctx and decompress_io_ctx structure.
Signed-off-by: default avatarChao Yu <yuchao0@huawei.com>
Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
parent 31083031
...@@ -17,6 +17,9 @@ ...@@ -17,6 +17,9 @@
#include "node.h" #include "node.h"
#include <trace/events/f2fs.h> #include <trace/events/f2fs.h>
static struct kmem_cache *cic_entry_slab;
static struct kmem_cache *dic_entry_slab;
static void *page_array_alloc(struct inode *inode, int nr) static void *page_array_alloc(struct inode *inode, int nr)
{ {
struct f2fs_sb_info *sbi = F2FS_I_SB(inode); struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
...@@ -1206,7 +1209,7 @@ static int f2fs_write_compressed_pages(struct compress_ctx *cc, ...@@ -1206,7 +1209,7 @@ static int f2fs_write_compressed_pages(struct compress_ctx *cc,
fio.version = ni.version; fio.version = ni.version;
cic = f2fs_kzalloc(sbi, sizeof(struct compress_io_ctx), GFP_NOFS); cic = kmem_cache_zalloc(cic_entry_slab, GFP_NOFS);
if (!cic) if (!cic)
goto out_put_dnode; goto out_put_dnode;
...@@ -1323,7 +1326,7 @@ static int f2fs_write_compressed_pages(struct compress_ctx *cc, ...@@ -1323,7 +1326,7 @@ static int f2fs_write_compressed_pages(struct compress_ctx *cc,
f2fs_put_page(cc->cpages[i], 1); f2fs_put_page(cc->cpages[i], 1);
} }
out_put_cic: out_put_cic:
kfree(cic); kmem_cache_free(cic_entry_slab, cic);
out_put_dnode: out_put_dnode:
f2fs_put_dnode(&dn); f2fs_put_dnode(&dn);
out_unlock_op: out_unlock_op:
...@@ -1361,7 +1364,7 @@ void f2fs_compress_write_end_io(struct bio *bio, struct page *page) ...@@ -1361,7 +1364,7 @@ void f2fs_compress_write_end_io(struct bio *bio, struct page *page)
} }
page_array_free(cic->inode, cic->rpages, cic->nr_rpages); page_array_free(cic->inode, cic->rpages, cic->nr_rpages);
kfree(cic); kmem_cache_free(cic_entry_slab, cic);
} }
static int f2fs_write_raw_pages(struct compress_ctx *cc, static int f2fs_write_raw_pages(struct compress_ctx *cc,
...@@ -1473,18 +1476,17 @@ int f2fs_write_multi_pages(struct compress_ctx *cc, ...@@ -1473,18 +1476,17 @@ int f2fs_write_multi_pages(struct compress_ctx *cc,
struct decompress_io_ctx *f2fs_alloc_dic(struct compress_ctx *cc) struct decompress_io_ctx *f2fs_alloc_dic(struct compress_ctx *cc)
{ {
struct f2fs_sb_info *sbi = F2FS_I_SB(cc->inode);
struct decompress_io_ctx *dic; struct decompress_io_ctx *dic;
pgoff_t start_idx = start_idx_of_cluster(cc); pgoff_t start_idx = start_idx_of_cluster(cc);
int i; int i;
dic = f2fs_kzalloc(sbi, sizeof(struct decompress_io_ctx), GFP_NOFS); dic = kmem_cache_zalloc(dic_entry_slab, GFP_NOFS);
if (!dic) if (!dic)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
dic->rpages = page_array_alloc(cc->inode, cc->cluster_size); dic->rpages = page_array_alloc(cc->inode, cc->cluster_size);
if (!dic->rpages) { if (!dic->rpages) {
kfree(dic); kmem_cache_free(dic_entry_slab, dic);
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
} }
...@@ -1549,7 +1551,7 @@ void f2fs_free_dic(struct decompress_io_ctx *dic) ...@@ -1549,7 +1551,7 @@ void f2fs_free_dic(struct decompress_io_ctx *dic)
} }
page_array_free(dic->inode, dic->rpages, dic->nr_rpages); page_array_free(dic->inode, dic->rpages, dic->nr_rpages);
kfree(dic); kmem_cache_free(dic_entry_slab, dic);
} }
void f2fs_decompress_end_io(struct page **rpages, void f2fs_decompress_end_io(struct page **rpages,
...@@ -1599,3 +1601,54 @@ void f2fs_destroy_page_array_cache(struct f2fs_sb_info *sbi) ...@@ -1599,3 +1601,54 @@ void f2fs_destroy_page_array_cache(struct f2fs_sb_info *sbi)
{ {
kmem_cache_destroy(sbi->page_array_slab); kmem_cache_destroy(sbi->page_array_slab);
} }
static int __init f2fs_init_cic_cache(void)
{
cic_entry_slab = f2fs_kmem_cache_create("f2fs_cic_entry",
sizeof(struct compress_io_ctx));
if (!cic_entry_slab)
return -ENOMEM;
return 0;
}
static void f2fs_destroy_cic_cache(void)
{
kmem_cache_destroy(cic_entry_slab);
}
static int __init f2fs_init_dic_cache(void)
{
dic_entry_slab = f2fs_kmem_cache_create("f2fs_dic_entry",
sizeof(struct decompress_io_ctx));
if (!dic_entry_slab)
return -ENOMEM;
return 0;
}
static void f2fs_destroy_dic_cache(void)
{
kmem_cache_destroy(dic_entry_slab);
}
int __init f2fs_init_compress_cache(void)
{
int err;
err = f2fs_init_cic_cache();
if (err)
goto out;
err = f2fs_init_dic_cache();
if (err)
goto free_cic;
return 0;
free_cic:
f2fs_destroy_cic_cache();
out:
return -ENOMEM;
}
void f2fs_destroy_compress_cache(void)
{
f2fs_destroy_dic_cache();
f2fs_destroy_cic_cache();
}
...@@ -3936,6 +3936,8 @@ void f2fs_destroy_compress_ctx(struct compress_ctx *cc); ...@@ -3936,6 +3936,8 @@ void f2fs_destroy_compress_ctx(struct compress_ctx *cc);
void f2fs_init_compress_info(struct f2fs_sb_info *sbi); void f2fs_init_compress_info(struct f2fs_sb_info *sbi);
int f2fs_init_page_array_cache(struct f2fs_sb_info *sbi); int f2fs_init_page_array_cache(struct f2fs_sb_info *sbi);
void f2fs_destroy_page_array_cache(struct f2fs_sb_info *sbi); void f2fs_destroy_page_array_cache(struct f2fs_sb_info *sbi);
int __init f2fs_init_compress_cache(void);
void f2fs_destroy_compress_cache(void);
#else #else
static inline bool f2fs_is_compressed_page(struct page *page) { return false; } static inline bool f2fs_is_compressed_page(struct page *page) { return false; }
static inline bool f2fs_is_compress_backend_ready(struct inode *inode) static inline bool f2fs_is_compress_backend_ready(struct inode *inode)
...@@ -3954,6 +3956,8 @@ static inline int f2fs_init_compress_mempool(void) { return 0; } ...@@ -3954,6 +3956,8 @@ static inline int f2fs_init_compress_mempool(void) { return 0; }
static inline void f2fs_destroy_compress_mempool(void) { } static inline void f2fs_destroy_compress_mempool(void) { }
static inline int f2fs_init_page_array_cache(struct f2fs_sb_info *sbi) { return 0; } static inline int f2fs_init_page_array_cache(struct f2fs_sb_info *sbi) { return 0; }
static inline void f2fs_destroy_page_array_cache(struct f2fs_sb_info *sbi) { } static inline void f2fs_destroy_page_array_cache(struct f2fs_sb_info *sbi) { }
static inline int __init f2fs_init_compress_cache(void) { return 0; }
static inline void f2fs_destroy_compress_cache(void) { }
#endif #endif
static inline void set_compress_context(struct inode *inode) static inline void set_compress_context(struct inode *inode)
......
...@@ -4054,7 +4054,12 @@ static int __init init_f2fs_fs(void) ...@@ -4054,7 +4054,12 @@ static int __init init_f2fs_fs(void)
err = f2fs_init_compress_mempool(); err = f2fs_init_compress_mempool();
if (err) if (err)
goto free_bioset; goto free_bioset;
err = f2fs_init_compress_cache();
if (err)
goto free_compress_mempool;
return 0; return 0;
free_compress_mempool:
f2fs_destroy_compress_mempool();
free_bioset: free_bioset:
f2fs_destroy_bioset(); f2fs_destroy_bioset();
free_bio_enrty_cache: free_bio_enrty_cache:
...@@ -4086,6 +4091,7 @@ static int __init init_f2fs_fs(void) ...@@ -4086,6 +4091,7 @@ static int __init init_f2fs_fs(void)
static void __exit exit_f2fs_fs(void) static void __exit exit_f2fs_fs(void)
{ {
f2fs_destroy_compress_cache();
f2fs_destroy_compress_mempool(); f2fs_destroy_compress_mempool();
f2fs_destroy_bioset(); f2fs_destroy_bioset();
f2fs_destroy_bio_entry_cache(); f2fs_destroy_bio_entry_cache();
......
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