From 3e9fedfa7ea52a03a1975572ab37cc1ae9344a8a Mon Sep 17 00:00:00 2001 From: Wang Shilong Date: Mon, 29 Apr 2019 21:13:59 +0800 Subject: [PATCH] LU-12225 obdclass: improve jobid memory reclaim policy 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 Reviewed-on: https://review.whamcloud.com/34775 Tested-by: Jenkins Reviewed-by: Ben Evans Tested-by: Maloo Reviewed-by: Gu Zheng Reviewed-by: Oleg Drokin --- lustre/obdclass/jobid.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lustre/obdclass/jobid.c b/lustre/obdclass/jobid.c index 07a6c57..7aba58e 100644 --- a/lustre/obdclass/jobid.c +++ b/lustre/obdclass/jobid.c @@ -126,10 +126,14 @@ static int jobid_should_free_item(void *obj, void *data) if (obj == NULL) return 0; + if (jobid == NULL) { + WARN_ON_ONCE(atomic_read(&pidmap->jp_refcount) != 1); + return 1; + } + 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; -- 1.8.3.1