From: levin li <[email protected]>

Signed-off-by: levin li <[email protected]>
---
 sheep/object_cache.c |   28 ++++++++++++++++++++--------
 sheep/ops.c          |    2 ++
 sheep/sheep_priv.h   |    1 +
 3 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/sheep/object_cache.c b/sheep/object_cache.c
index 1febea9..2e48f2e 100644
--- a/sheep/object_cache.c
+++ b/sheep/object_cache.c
@@ -622,6 +622,25 @@ static void update_cache_entry(struct object_cache *oc, 
uint32_t idx,
        pthread_rwlock_unlock(&oc->lock);
 }
 
+void object_cache_try_to_reclaim(void)
+{
+       struct work *work;
+
+       if (!sys->cache_size)
+               return;
+
+       if (uatomic_read(&sys_cache.cache_size) < sys->cache_size)
+               return;
+
+       if (cache_in_reclaim(1))
+               return;
+
+       work = xzalloc(sizeof(struct work));
+       work->fn = reclaim_work;
+       work->done = reclaim_done;
+       queue_work(sys->reclaim_wqueue, work);
+}
+
 static void add_to_object_cache(struct object_cache *oc, uint32_t idx)
 {
        struct object_cache_entry *entry, *old;
@@ -653,14 +672,7 @@ static void add_to_object_cache(struct object_cache *oc, 
uint32_t idx)
        }
        pthread_rwlock_unlock(&oc->lock);
 
-       if (sys->cache_size &&
-           uatomic_read(&sys_cache.cache_size) > sys->cache_size &&
-           !cache_in_reclaim(1)) {
-               struct work *work = xzalloc(sizeof(struct work));
-               work->fn = reclaim_work;
-               work->done = reclaim_done;
-               queue_work(sys->reclaim_wqueue, work);
-       }
+       object_cache_try_to_reclaim();
 }
 
 static int object_cache_lookup(struct object_cache *oc, uint32_t idx,
diff --git a/sheep/ops.c b/sheep/ops.c
index 2869504..6c92575 100644
--- a/sheep/ops.c
+++ b/sheep/ops.c
@@ -509,6 +509,8 @@ static int local_set_cache_size(const struct sd_req *req, 
struct sd_rsp *rsp,
        uatomic_set(&sys->cache_size, cache_size);
        dprintf("Max cache size set to %dM\n", cache_size);
 
+       object_cache_try_to_reclaim();
+
        return SD_RES_SUCCESS;
 }
 
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index 2090d67..c4225ea 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -335,6 +335,7 @@ int peer_remove_obj(struct request *req);
 int bypass_object_cache(struct request *req);
 int object_is_cached(uint64_t oid);
 
+void object_cache_try_to_reclaim(void);
 int object_cache_handle_request(struct request *req);
 int object_cache_write(uint64_t oid, char *data, unsigned int datalen,
                       uint64_t offset, uint16_t flags, int create);
-- 
1.7.1

-- 
sheepdog mailing list
[email protected]
http://lists.wpkg.org/mailman/listinfo/sheepdog

Reply via email to