Whamcloud - gitweb
LU-12225 obdclass: improve jobid memory reclaim policy 75/34775/3
authorWang Shilong <wshilong@ddn.com>
Mon, 29 Apr 2019 13:13:59 +0000 (21:13 +0800)
committerOleg Drokin <green@whamcloud.com>
Sat, 25 May 2019 05:12:42 +0000 (05:12 +0000)
jobid_should_free_item() will be called in following three
cases to decide whether @pidmap should be deleted from hash list:

1) expire normal timeout and memory reclaimer called to
try free some items.

2) admin echo sys interface to free some jobid.

3) Umount client to free all memory.

For case 2 && 3, it makes sense we always return 1,
add a warn_on in case3 to make sure there isn't any
bug in the codes.

For the case1, we could change policy a bit to not
return 1 if reference count of @pidmap is larger than 1,
a common case is a newly added @pidmap is easily freed
from hash list with current policy.

Actually, even we delete @pidmap from hash list, memory
will be eventually freed with its references count reached
1, and it is very likely we deleted and inserted @pidmap
again since this could be a hot and long runtime job.

Change-Id: I61b894a900319953d5a3369bee69bda050102129
Signed-off-by: Wang Shilong <wshilong@ddn.com>
Reviewed-on: https://review.whamcloud.com/34775
Tested-by: Jenkins
Reviewed-by: Ben Evans <bevans@cray.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Gu Zheng <gzheng@ddn.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/obdclass/jobid.c

index 07a6c57..7aba58e 100644 (file)
@@ -126,10 +126,14 @@ static int jobid_should_free_item(void *obj, void *data)
        if (obj == NULL)
                return 0;
 
        if (obj == NULL)
                return 0;
 
+       if (jobid == NULL) {
+               WARN_ON_ONCE(atomic_read(&pidmap->jp_refcount) != 1);
+               return 1;
+       }
+
        spin_lock(&pidmap->jp_lock);
        spin_lock(&pidmap->jp_lock);
-       if (jobid == NULL)
-               rc = 1;
-       else if (jobid[0] == '\0')
+       /* prevent newly inserted items from deleting */
+       if (jobid[0] == '\0' && atomic_read(&pidmap->jp_refcount) == 1)
                rc = 1;
        else if (ktime_get_real_seconds() - pidmap->jp_time > DELETE_INTERVAL)
                rc = 1;
                rc = 1;
        else if (ktime_get_real_seconds() - pidmap->jp_time > DELETE_INTERVAL)
                rc = 1;