summaryrefslogtreecommitdiff
path: root/fs/fuse
diff options
context:
space:
mode:
authorVivek Goyal <vgoyal@redhat.com>2020-08-20 01:19:55 +0300
committerMiklos Szeredi <mszeredi@redhat.com>2020-09-10 12:39:23 +0300
commitd0cfb9dcbca6ebd21ec78ea719b451ea4c22cecf (patch)
treeee066b2bf7124a7c58d06880ed132b8d10b752e8 /fs/fuse
parent6ae330cad6ef22ab8347ea9e0707dc56a7c7363f (diff)
downloadlinux-d0cfb9dcbca6ebd21ec78ea719b451ea4c22cecf.tar.xz
virtiofs: maintain a list of busy elements
This list will be used selecting fuse_dax_mapping to free when number of free mappings drops below a threshold. Signed-off-by: Vivek Goyal <vgoyal@redhat.com> Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
Diffstat (limited to 'fs/fuse')
-rw-r--r--fs/fuse/dax.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/fs/fuse/dax.c b/fs/fuse/dax.c
index efc1a8ef5639..e6407839c538 100644
--- a/fs/fuse/dax.c
+++ b/fs/fuse/dax.c
@@ -28,6 +28,9 @@ struct fuse_dax_mapping {
/* For interval tree in file/inode */
struct interval_tree_node itn;
+ /* Will connect in fc->busy_ranges to keep track busy memory */
+ struct list_head busy_list;
+
/** Position in DAX window */
u64 window_offset;
@@ -55,6 +58,10 @@ struct fuse_conn_dax {
/* Lock protecting accessess to members of this structure */
spinlock_t lock;
+ /* List of memory ranges which are busy */
+ unsigned long nr_busy_ranges;
+ struct list_head busy_ranges;
+
/* DAX Window Free Ranges */
long nr_free_ranges;
struct list_head free_ranges;
@@ -86,6 +93,15 @@ static struct fuse_dax_mapping *alloc_dax_mapping(struct fuse_conn_dax *fcd)
}
/* This assumes fcd->lock is held */
+static void __dmap_remove_busy_list(struct fuse_conn_dax *fcd,
+ struct fuse_dax_mapping *dmap)
+{
+ list_del_init(&dmap->busy_list);
+ WARN_ON(fcd->nr_busy_ranges == 0);
+ fcd->nr_busy_ranges--;
+}
+
+/* This assumes fcd->lock is held */
static void __dmap_add_to_free_pool(struct fuse_conn_dax *fcd,
struct fuse_dax_mapping *dmap)
{
@@ -139,6 +155,10 @@ static int fuse_setup_one_mapping(struct inode *inode, unsigned long start_idx,
/* Protected by fi->dax->sem */
interval_tree_insert(&dmap->itn, &fi->dax->tree);
fi->dax->nr++;
+ spin_lock(&fcd->lock);
+ list_add_tail(&dmap->busy_list, &fcd->busy_ranges);
+ fcd->nr_busy_ranges++;
+ spin_unlock(&fcd->lock);
}
return 0;
}
@@ -207,6 +227,7 @@ static void dmap_reinit_add_to_free_pool(struct fuse_conn_dax *fcd,
pr_debug("fuse: freeing memory range start_idx=0x%lx end_idx=0x%lx window_offset=0x%llx length=0x%llx\n",
dmap->itn.start, dmap->itn.last, dmap->window_offset,
dmap->length);
+ __dmap_remove_busy_list(fcd, dmap);
dmap->itn.start = dmap->itn.last = 0;
__dmap_add_to_free_pool(fcd, dmap);
}
@@ -700,6 +721,8 @@ static void fuse_free_dax_mem_ranges(struct list_head *mem_list)
/* Free All allocated elements */
list_for_each_entry_safe(range, temp, mem_list, list) {
list_del(&range->list);
+ if (!list_empty(&range->busy_list))
+ list_del(&range->busy_list);
kfree(range);
}
}
@@ -723,6 +746,7 @@ static int fuse_dax_mem_range_init(struct fuse_conn_dax *fcd)
unsigned long i;
INIT_LIST_HEAD(&fcd->free_ranges);
+ INIT_LIST_HEAD(&fcd->busy_ranges);
id = dax_read_lock();
nr_pages = dax_direct_access(fcd->dev, 0, PHYS_PFN(dax_size), &kaddr,
&pfn);
@@ -748,6 +772,7 @@ static int fuse_dax_mem_range_init(struct fuse_conn_dax *fcd)
*/
range->window_offset = i * FUSE_DAX_SZ;
range->length = FUSE_DAX_SZ;
+ INIT_LIST_HEAD(&range->busy_list);
list_add_tail(&range->list, &fcd->free_ranges);
}