[Devel] [PATCH RHEL7 COMMIT] fuse kio: Allocate pcs_map from kmem_cache with SLAB_RECLAIM_ACCOUNT flag

Konstantin Khorenko khorenko at virtuozzo.com
Mon Aug 13 14:56:24 MSK 2018


The commit is pushed to "branch-rh7-3.10.0-862.9.1.vz7.70.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-862.9.1.vz7.70.2
------>
commit 4d9a5422532798e46477b5d08645e1b48e0a96d9
Author: Kirill Tkhai <ktkhai at virtuozzo.com>
Date:   Mon Aug 13 14:56:23 2018 +0300

    fuse kio: Allocate pcs_map from kmem_cache with SLAB_RECLAIM_ACCOUNT flag
    
    Andrey noticed, that reclaimer may give up to do shrinking,
    when there are too many unreclaimable memory in the system.
    
    Let's allocate pcs_map from kmem_cache, and mark pcs_map
    as reclaimable, since maps (the most probably) are truncated
    on inode truncating and destroying. This prevents the situation,
    when there are too many unreclaimable maps are allocated,
    and reclaimer gives up to do the shrink.
    
    v2: Also add SLAB_ACCOUNT
    
    Suggested-by: Andrey Ryabinin <aryabinin at virtuozzo.com>
    Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 fs/fuse/kio/pcs/pcs_fuse_kdirect.c | 14 ++++++++++++--
 fs/fuse/kio/pcs/pcs_map.c          |  4 +++-
 fs/fuse/kio/pcs/pcs_map.h          |  2 ++
 3 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/fs/fuse/kio/pcs/pcs_fuse_kdirect.c b/fs/fuse/kio/pcs/pcs_fuse_kdirect.c
index a3d6ca99b49a..abcd315c7474 100644
--- a/fs/fuse/kio/pcs/pcs_fuse_kdirect.c
+++ b/fs/fuse/kio/pcs/pcs_fuse_kdirect.c
@@ -1422,11 +1422,18 @@ static int __init kpcs_mod_init(void)
 					    0, SLAB_MEM_SPREAD, NULL);
 	if (!pcs_ireq_cachep)
 		goto free_fuse_cache;
+
+	pcs_map_cachep = kmem_cache_create("pcs_map",
+					    sizeof(struct pcs_map_entry),
+					    0, SLAB_RECLAIM_ACCOUNT|SLAB_ACCOUNT, NULL);
+	if (!pcs_map_cachep)
+		goto free_ireq_cache;
+
 	pcs_wq = alloc_workqueue("pcs_cluster", WQ_MEM_RECLAIM, 0);
 	if (!pcs_wq)
-		goto free_ireq_cache;
+		goto free_map_cache;
 
-	if(fuse_register_kio(&kio_pcs_ops))
+	if (fuse_register_kio(&kio_pcs_ops))
 		goto free_wq;
 
 	fuse_trace_root = debugfs_create_dir("fuse", NULL);
@@ -1437,6 +1444,8 @@ static int __init kpcs_mod_init(void)
 	return 0;
 free_wq:
 	destroy_workqueue(pcs_wq);
+free_map_cache:
+	kmem_cache_destroy(pcs_map_cachep);
 free_ireq_cache:
 	kmem_cache_destroy(pcs_ireq_cachep);
 free_fuse_cache:
@@ -1451,6 +1460,7 @@ static void __exit kpcs_mod_exit(void)
 
 	fuse_unregister_kio(&kio_pcs_ops);
 	destroy_workqueue(pcs_wq);
+	kmem_cache_destroy(pcs_map_cachep);
 	kmem_cache_destroy(pcs_ireq_cachep);
 	kmem_cache_destroy(pcs_fuse_req_cachep);
 }
diff --git a/fs/fuse/kio/pcs/pcs_map.c b/fs/fuse/kio/pcs/pcs_map.c
index bd6a5a077d86..f5b74b202105 100644
--- a/fs/fuse/kio/pcs/pcs_map.c
+++ b/fs/fuse/kio/pcs/pcs_map.c
@@ -28,6 +28,8 @@
 */
 #define MAP_BATCH 16
 
+struct kmem_cache *pcs_map_cachep;
+
 static struct pcs_cs_list *cs_link_to_cs_list(struct pcs_cs_link *csl)
 {
 	struct pcs_cs_record *cs_rec;
@@ -557,7 +559,7 @@ struct pcs_map_entry * pcs_find_get_map(struct pcs_dentry_info *di, u64 offset)
 		/* No direct throttler here */
 		break;
 	}
-	m = kzalloc(sizeof(struct pcs_map_entry), GFP_NOIO);
+	m = kmem_cache_zalloc(pcs_map_cachep, GFP_NOIO);
 	if (!m)
 		return NULL;
 
diff --git a/fs/fuse/kio/pcs/pcs_map.h b/fs/fuse/kio/pcs/pcs_map.h
index 6a7535d8cbdb..ef8d56de0b30 100644
--- a/fs/fuse/kio/pcs/pcs_map.h
+++ b/fs/fuse/kio/pcs/pcs_map.h
@@ -133,6 +133,8 @@ struct pcs_map_entry
 	struct list_head	queue;
 };
 
+extern struct kmem_cache *pcs_map_cachep;
+
 static inline u64 map_chunk_start(struct pcs_map_entry *m)
 {
 	return m->index << m->mapping->chunk_size_bits;


More information about the Devel mailing list