cachefiles: make on-demand request distribution fairer
PATCH 1/1 cachefiles: make on-demand request distribution fairer
For now, enqueuing and dequeuing on-demand requests all start from idx 0, this makes request distribution unfair. In the weighty concurrent I/O scenario, the request stored in higher idx will starve.
Searching requests cyclically in cachefiles_ondemand_daemon_read, makes distribution fairer.
--- fs/cachefiles/internal.h | 1 + fs/cachefiles/ondemand.c | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-)
fs/cachefiles/internal.h +1 -0
@@ -111,6 +111,7 @@ struct cachefiles_cache {char *tag;/* cache binding tag */ refcount_t unbind_pincount;/* refcount to do daemon unbind */ struct xarray reqs;/* xarray of pending on-demand requests */ +unsigned long req_id_next;struct xarray ondemand_ids;/* xarray for ondemand_id allocation */ u32 ondemand_id_next; };
fs/cachefiles/ondemand.c +9 -3
@@ -238,14 +238,19 @@ ssize_t cachefiles_ondemand_daemon_read(struct cachefiles_cache *cache,unsigned long id =0 ;size_t n;int ret =0 ; -XA_STATE (xas, &cache->reqs,0 ); +XA_STATE (xas, &cache->reqs, cache->req_id_next);/* -* Search for a request that has not ever been processed, to prevent -* requests from being processed repeatedly. +* Cyclically search for a request that has not ever been processed, +* to prevent requests from being processed repeatedly, and make +* request distribution fair. */ xa_lock (&cache->reqs); req =xas_find_marked (&xas,UINT_MAX ,CACHEFILES_REQ_NEW ); +if (!req && cache->req_id_next >0 ) { +xas_set (&xas,0 ); + req =xas_find_marked (&xas, cache->req_id_next -1 ,CACHEFILES_REQ_NEW ); + }if (!req) {xa_unlock (&cache->reqs);return 0 ;
@@ -260,6 +265,7 @@ ssize_t cachefiles_ondemand_daemon_read(struct cachefiles_cache *cache, }xas_clear_mark (&xas,CACHEFILES_REQ_NEW ); + cache->req_id_next = xas.xa_index +1 ;xa_unlock (&cache->reqs); id = xas.xa_index;
Signature · 1 line
2.25.1
Hi Yin,
Quoted 6 lines · Xin Yin
For now, enqueuing and dequeuing on-demand requests all start from idx 0, this makes request distribution unfair. In the weighty concurrent I/O scenario, the request stored in higher idx will starve.
Searching requests cyclically in
cachefiles_ondemand_daemon_read, makes distribution fairer.
Yeah, thanks for the catch. The previous approach could cause somewhat unfairness and make some requests starving... But we don't need strict FIFO here.
Quoted 13 lines
Reported-by Yongqing Li <[email protected]>Signed-off-by Xin Yin <[email protected]>--- fs/cachefiles/internal.h | 1 + fs/cachefiles/ondemand.c | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-)fs/cachefiles/internal.h +0
-0
fs/cachefiles/internal.h struct cachefiles_cache { · line 114
Quoted 4 lines
fs/cachefiles/internal.h +1
-0@@ -111,6 +111,7 @@ struct cachefiles_cache {char *tag;/* cache binding tag */ refcount_t unbind_pincount;/* refcount to do daemon unbind */ struct xarray reqs;/* xarray of pending on-demand requests */ +unsigned long req_id_next;
unsigned long ondemand_req_id_next; ?
Otherwise it looks good to me,
Thanks,
Gao Xiang
Quoted 45 lines
fs/cachefiles/internal.h +0
-0struct xarray ondemand_ids;/* xarray for ondemand_id allocation */ u32 ondemand_id_next; };fs/cachefiles/ondemand.c +9
-3@@ -238,14 +238,19 @@ ssize_t cachefiles_ondemand_daemon_read(struct cachefiles_cache *cache,unsigned long id =0 ;size_t n;int ret =0 ; -XA_STATE (xas, &cache->reqs,0 ); +XA_STATE (xas, &cache->reqs, cache->req_id_next);/* -* Search for a request that has not ever been processed, to prevent -* requests from being processed repeatedly. +* Cyclically search for a request that has not ever been processed, +* to prevent requests from being processed repeatedly, and make +* request distribution fair. */ xa_lock (&cache->reqs); req =xas_find_marked (&xas,UINT_MAX ,CACHEFILES_REQ_NEW ); +if (!req && cache->req_id_next >0 ) { +xas_set (&xas,0 ); + req =xas_find_marked (&xas, cache->req_id_next -1 ,CACHEFILES_REQ_NEW ); + }if (!req) {xa_unlock (&cache->reqs);return 0 ;@@ -260,6 +265,7 @@ ssize_t cachefiles_ondemand_daemon_read(struct cachefiles_cache *cache, }xas_clear_mark (&xas,CACHEFILES_REQ_NEW ); + cache->req_id_next = xas.xa_index +1 ;xa_unlock (&cache->reqs); id = xas.xa_index;Signature · 6 lines
2.25.1 -- Linux-cachefs mailing list [email protected] https://listman.redhat.com/mailman/listinfo/linux-cachefs
Quoted 23 lines · Gao Xiang
Hi Yin,
Quoted 6 lines · Xin Yin
For now, enqueuing and dequeuing on-demand requests all start from idx 0, this makes request distribution unfair. In the weighty concurrent I/O scenario, the request stored in higher idx will starve.
Searching requests cyclically in
cachefiles_ondemand_daemon_read, makes distribution fairer.Yeah, thanks for the catch. The previous approach could cause somewhat unfairness and make some requests starving... But we don't need strict FIFO here.
Quoted 8 lines
Reported-by Yongqing Li <[email protected]>Signed-off-by Xin Yin <[email protected]>--- fs/cachefiles/internal.h | 1 + fs/cachefiles/ondemand.c | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-)
Quoted 11 lines
fs/cachefiles/internal.h struct cachefiles_cache { · line 114
Quoted 9 lines
fs/cachefiles/internal.h +1
-0@@ -111,6 +111,7 @@ struct cachefiles_cache {char *tag;/* cache binding tag */ refcount_t unbind_pincount;/* refcount to do daemon unbind */ struct xarray reqs;/* xarray of pending on-demand requests */ +unsigned long req_id_next;unsigned long
ondemand_req_id_next; ?
Hi Xiang,
Thanks for the detailed review , whether "ondemand_req_id_next" is a little long ? struct cachefiles_cache only holds on-demand requests , so I think "req_id_next" will not cause ambiguity. Does this make sense?
Thanks,
Xin Yin
Quoted 51 lines
Otherwise it looks good to me,
Thanks,
Gao XiangQuoted 45 lines
fs/cachefiles/internal.h +0
-0struct xarray ondemand_ids;/* xarray for ondemand_id allocation */ u32 ondemand_id_next; };fs/cachefiles/ondemand.c +9
-4@@ -238,14 +238,19 @@ ssize_t cachefiles_ondemand_daemon_read(struct cachefiles_cache *cache,unsigned long id =0 ;size_t n;int ret =0 ; -XA_STATE (xas, &cache->reqs,0 ); +XA_STATE (xas, &cache->reqs, cache->req_id_next);/* -* Search for a request that has not ever been processed, to prevent -* requests from being processed repeatedly. +* Cyclically search for a request that has not ever been processed, +* to prevent requests from being processed repeatedly, and make +* request distribution fair. */ xa_lock (&cache->reqs); req =xas_find_marked (&xas,UINT_MAX ,CACHEFILES_REQ_NEW ); +if (!req && cache->req_id_next >0 ) { +xas_set (&xas,0 ); + req =xas_find_marked (&xas, cache->req_id_next -1 ,CACHEFILES_REQ_NEW ); + }if (!req) {xa_unlock (&cache->reqs);return 0 ;@@ -260,6 +265,7 @@ ssize_t cachefiles_ondemand_daemon_read(struct cachefiles_cache *cache, }xas_clear_mark (&xas,CACHEFILES_REQ_NEW ); + cache->req_id_next = xas.xa_index +1 ;xa_unlock (&cache->reqs); id = xas.xa_index; --2.25.1
--
Linux-cachefs mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/linux-cachefs
Quoted 35 lines · Xin Yin
Quoted 23 lines · Gao Xiang
Hi Yin,
Quoted 6 lines · Xin Yin
For now, enqueuing and dequeuing on-demand requests all start from idx 0, this makes request distribution unfair. In the weighty concurrent I/O scenario, the request stored in higher idx will starve.
Searching requests cyclically in
cachefiles_ondemand_daemon_read, makes distribution fairer.Yeah, thanks for the catch. The previous approach could cause somewhat unfairness and make some requests starving... But we don't need strict FIFO here.
Quoted 8 lines
Reported-by Yongqing Li <[email protected]>Signed-off-by Xin Yin <[email protected]>--- fs/cachefiles/internal.h | 1 + fs/cachefiles/ondemand.c | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-)Quoted 11 lines
fs/cachefiles/internal.h struct cachefiles_cache { · line 114
Quoted 9 lines
fs/cachefiles/internal.h +1
-0@@ -111,6 +111,7 @@ struct cachefiles_cache {char *tag;/* cache binding tag */ refcount_t unbind_pincount;/* refcount to do daemon unbind */ struct xarray reqs;/* xarray of pending on-demand requests */ +unsigned long req_id_next;unsigned long
ondemand_req_id_next; ?
Quoted 6 lines
Hi Xiang,
Thanks for the detailed review , whether "
ondemand_req_id_next" is a little long ? structcachefiles_cacheonly holds on-demand requests , so I think "req_id_next" will not cause ambiguity. Does this make sense?
If David is fine with "req_id_next", I'm okay with that as well.
Thanks,
Gao Xiang
Quoted 59 lines
Thanks,
Xin YinQuoted 43 lines
Otherwise it looks good to me,
Thanks,
Gao XiangQuoted 37 lines
fs/cachefiles/internal.h +0
-0struct xarray ondemand_ids;/* xarray for ondemand_id allocation */ u32 ondemand_id_next; };fs/cachefiles/ondemand.c +9
-3@@ -238,14 +238,19 @@ ssize_t cachefiles_ondemand_daemon_read(struct cachefiles_cache *cache,unsigned long id =0 ;size_t n;int ret =0 ; -XA_STATE (xas, &cache->reqs,0 ); +XA_STATE (xas, &cache->reqs, cache->req_id_next);/* -* Search for a request that has not ever been processed, to prevent -* requests from being processed repeatedly. +* Cyclically search for a request that has not ever been processed, +* to prevent requests from being processed repeatedly, and make +* request distribution fair. */ xa_lock (&cache->reqs); req =xas_find_marked (&xas,UINT_MAX ,CACHEFILES_REQ_NEW ); +if (!req && cache->req_id_next >0 ) { +xas_set (&xas,0 ); + req =xas_find_marked (&xas, cache->req_id_next -1 ,CACHEFILES_REQ_NEW ); + }if (!req) {xa_unlock (&cache->reqs);return 0 ;@@ -260,6 +265,7 @@ ssize_t cachefiles_ondemand_daemon_read(struct cachefiles_cache *cache, }xas_clear_mark (&xas,CACHEFILES_REQ_NEW ); + cache->req_id_next = xas.xa_index +1 ;xa_unlock (&cache->reqs);Quoted 8 lines
Quoted 8 lines
fs/cachefiles/ondemand.c +0
-1id = xas.xa_index; --2.25.1
--
Linux-cachefs mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/linux-cachefs--
Linux-cachefs mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/linux-cachefs
David Howells
maintainerQuoted 1 line · Gao Xiang
If David is fine with "
req_id_next", I'm okay with that as well.
I can live with it.
Did you want to give me an R-b line?
David
Hi David,
Quoted 7 lines · David Howells
Quoted 1 line · Gao Xiang
If David is fine with "
req_id_next", I'm okay with that as well.I can live with it.
Did you want to give me an R-b line?
Yeah, thanks, much appreciated! As far as I know, such unfairness can cause starvation in Bytedance's test environment, it would be better to fix it as above.
Thanks,
Gao Xiang
Quoted 2 lines
David
Quoted 38 lines · Xin Yin
For now, enqueuing and dequeuing on-demand requests all start from idx 0, this makes request distribution unfair. In the weighty concurrent I/O scenario, the request stored in higher idx will starve.
Searching requests cyclically in
cachefiles_ondemand_daemon_read, makes distribution fairer.Reported-by Yongqing Li <[email protected]>Signed-off-by Xin Yin <[email protected]>--- fs/cachefiles/internal.h | 1 + fs/cachefiles/ondemand.c | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-)fs/cachefiles/internal.h +1
-0@@ -111,6 +111,7 @@ struct cachefiles_cache {char *tag;/* cache binding tag */ refcount_t unbind_pincount;/* refcount to do daemon unbind */ struct xarray reqs;/* xarray of pending on-demand requests */ +unsigned long req_id_next;struct xarray ondemand_ids;/* xarray for ondemand_id allocation */ u32 ondemand_id_next; };fs/cachefiles/ondemand.c +1
-1@@ -238,14 +238,19 @@ ssize_t cachefiles_ondemand_daemon_read(struct cachefiles_cache *cache,unsigned long id =0 ;size_t n;int ret =0 ; -XA_STATE (xas, &cache->reqs,0 ); +XA_STATE (xas, &cache->reqs, cache->req_id_next);/*
fs/cachefiles/ondemand.c ssize_t cachefiles_ondemand_daemon_read(struct cachefiles_cache *cache, · line 251
Quoted 10 lines
fs/cachefiles/ondemand.c +5
-2-* Search for a request that has not ever been processed, to prevent -* requests from being processed repeatedly. +* Cyclically search for a request that has not ever been processed, +* to prevent requests from being processed repeatedly, and make +* request distribution fair. */ xa_lock (&cache->reqs); req =xas_find_marked (&xas,UINT_MAX ,CACHEFILES_REQ_NEW ); +if (!req && cache->req_id_next >0 ) { + xas_set(&xas, 0);> + req = xas_find_marked(&xas, cache->req_id_next - 1,
CACHEFILES_REQ_NEW);
LGTM.
Quoted 12 lines
fs/cachefiles/ondemand.c +2
-0+ }if (!req) {xa_unlock (&cache->reqs);return 0 ;@@ -260,6 +265,7 @@ ssize_t cachefiles_ondemand_daemon_read(struct cachefiles_cache *cache, }xas_clear_mark (&xas,CACHEFILES_REQ_NEW ); + cache->req_id_next = xas.xa_index +1 ;xa_unlock (&cache->reqs); id = xas.xa_index;
Signature · 2 lines
Thanks, Jingbo
David Howells
maintainerQuoted 2 lines · Xin Yin
Reported-by Yongqing Li <[email protected]>Signed-off-by Xin Yin <[email protected]>
Can you give me a Fixes: line please?
David
Quoted 8 lines · David Howells
Quoted 2 lines · Xin Yin
Reported-by Yongqing Li <[email protected]>Signed-off-by Xin Yin <[email protected]>Can you give me a Fixes: line please?
Sure , I will send a V2 patch and add the Fixes line.
Thanks
Xin Yin
Quoted 2 lines
David
David Howells
maintainerQuoted 3 lines · Xin Yin
Quoted 2 lines
Can you give me a Fixes: line please?
Sure , I will send a V2 patch and add the Fixes line.
Just giving me a Fixes line would do. I can insert it.
David
Quoted 9 lines · David Howells
Quoted 3 lines · Xin Yin
Quoted 2 lines
Can you give me a Fixes: line please?
Sure , I will send a V2 patch and add the Fixes line.
Just giving me a Fixes line would do. I can insert it.
Yeah, many thanks , the fixes line would be:
up cookie")
Thanks,
Xin Yin
Quoted 2 lines
David