Buffer read will get starvation in case reading/writing the same file from different nodes concurrently
Hello Guys,
There is a issue from the customer, who is complaining that buffer reading sometimes lasts too much time ( 1 - 10 seconds) in case reading/writing the same file from different nodes concurrently.
According to the demo code from the customer, we also can reproduce this issue at home (run the test program under SLES11SP4 OCFS2 cluster), actually this issue can be reproduced in openSuSe 13.2 (more newer code), but in direct-io mode, this issue will disappear. Base on my investigation, the root cause is the buffer-io using cluster-lock is different from direct-io, I do not know why buffer-io use cluster-lock like this way.
the code details are as below,
in aops.c file,
281 static int ocfs2_readpage(struct file *file, struct page *page)
282 {
283 struct inode *inode = page->mapping->host; 284 struct ocfs2_inode_info *oi = OCFS2_I(inode); 285 loff_t start = (loff_t)page->index << PAGE_CACHE_SHIFT; 286 int ret, unlock = 1;
287
288 trace_ocfs2_readpage((unsigned long long)oi->ip_blkno,
289 (page ? page->index : 0));
290
291 ret = ocfs2_inode_lock_with_page(inode, NULL, 0, page); <<== this line
292 if (ret != 0) {
293 if (ret == AOP_TRUNCATED_PAGE)
294 unlock = 0;
295 mlog_errno(ret);
296 goto out;
297 }
in dlmglue.c file,
2 int ocfs2_inode_lock_with_page(struct inode *inode,
2443 struct buffer_head **ret_bh, 2444 int ex, 2445 struct page *page)
2446 {
2447 int ret;
2448
2449 ret = ocfs2_inode_lock_full(inode, ret_bh, ex, OCFS2_LOCK_NONBLOCK); <<== there, why using NONBLOCK mode to get the cluster lock? this way will let reading IO get starvation.
2450 if (ret == -EAGAIN) {
2451 unlock_page(page);
2452 if (ocfs2_inode_lock(inode, ret_bh, ex) == 0)
2453 ocfs2_inode_unlock(inode, ex);
2454 ret = AOP_TRUNCATED_PAGE;
2455 }
2456
2457 return ret;
2458 }
If you know the background behind the code, please tell us, why not use block way to get the lock in reading a page, then reading IO will get the page fairly when there is a concurrent writing IO from the other node.
Second, I tried to modify that line from OCFS2_LOCK_NONBLOCK to 0 (switch to blocking way), the reading IO will not be blocked too much time (can erase the customer's complaining), but a new problem arises, sometimes the reading IO and writing IO get a dead lock (why dead lock? I am looking at).
Thanks
Gang
Hi Gang,
Eric and I have discussed this case before.
Using NONBLOCK here is because there is a lock inversion between inode lock and page lock. You can refer to the comments of ocfs2_inode_lock_with_page for details.
Actually I have found that NONBLOCK mode is only used in lock inversion cases.
Thanks,
Joseph
Quoted 55 lines · Gang He
Hello Guys,
There is a issue from the customer, who is complaining that buffer reading sometimes lasts too much time ( 1 - 10 seconds) in case reading/writing the same file from different nodes concurrently.
According to the demo code from the customer, we also can reproduce this issue at home (run the test program under SLES11SP4 OCFS2 cluster), actually this issue can be reproduced in openSuSe 13.2 (more newer code), but in direct-io mode, this issue will disappear. Base on my investigation, the root cause is the buffer-io using cluster-lock is different from direct-io, I do not know why buffer-io use cluster-lock like this way.
the code details are as below,
inaops.cfile,
281 static intocfs2_readpage(struct file *file, struct page *page)
282 {283 struct inode *inode = page->mapping->host; 284 struct ocfs2_inode_info *oi = OCFS2_I(inode); 285 loff_t start = (loff_t)page->index << PAGE_CACHE_SHIFT; 286 int ret, unlock = 1;287
288 trace_ocfs2_readpage((unsigned long long)oi->ip_blkno,
289 (page ?page->index: 0));
290
291 ret =ocfs2_inode_lock_with_page(inode, NULL, 0, page); <<== this line
292 if (ret != 0) {
293 if (ret ==AOP_TRUNCATED_PAGE)
294 unlock = 0;
295mlog_errno(ret);
296 goto out;
297 }in
dlmglue.cfile,
2 int ocfs2_inode_lock_with_page(struct inode *inode,2443 struct buffer_head **ret_bh, 2444 int ex, 2445 struct page *page)2446 {
2447 int ret;
2448
2449 ret =ocfs2_inode_lock_full(inode, ret_bh, ex, OCFS2_LOCK_NONBLOCK); <<== there, why using NONBLOCK mode to get the cluster lock? this way will let reading IO get starvation.
2450 if (ret ==-EAGAIN) {
2451unlock_page(page);
2452 if (ocfs2_inode_lock(inode, ret_bh, ex)== 0)
2453ocfs2_inode_unlock(inode, ex);
2454 ret =AOP_TRUNCATED_PAGE;
2455 }
2456
2457 return ret;
2458 }If you know the background behind the code, please tell us, why not use block way to get the lock in reading a page, then reading IO will get the page fairly when there is a concurrent writing IO from the other node.
Second, I tried to modify that line fromOCFS2_LOCK_NONBLOCKto 0 (switch to blocking way), the reading IO will not be blocked too much time (can erase the customer's complaining), but a new problem arises, sometimes the reading IO and writing IO get a dead lock (why dead lock? I am looking at).Thanks
Gang.
Hello Jeseph,
Quoted 8 lines
Quoted 1 line
Quoted 1 line
Hi Gang,
Eric and I have discussed this case before.
Using NONBLOCK here is because there is a lock inversion between inode lock and page lock. You can refer to the comments ofocfs2_inode_lock_with_pagefor details.
Actually I have found that NONBLOCK mode is only used in lock inversion cases.
Could you tell more details? for a inode object, here are three type cluster locks,ip_open_lockres is used to protect open/delete posix semantic,ip_rw_lockres looks to be used to protect write in direct-io case, just feel the words "rw" let people be confused,ip_inode_lockres to be used more widely, could you tell more, why there needs a lock inversion, not use block-way to get lock in read/write code path? second, when the read path can not get the lock with the NONBLOCK mode, why need to call ocfs2_inode_lock(inode, ret_bh, ex) with a block way in the next code? actually, two lock wrappers use the same cluster lock (ip_inode_lockres), you know, the next block-way locking will cost too much time.
Thanks a lot.
Gang
Quoted 75 lines
Thanks,
JosephQuoted 3 lines · Gang He
Hello Guys,
There is a issue from the customer, who is complaining that buffer reading
sometimes lasts too much time ( 1 - 10 seconds) in case reading/writing the same file from different nodes concurrently.
Quoted 1 line
According to the demo code from the customer, we also can reproduce this
issue at home (run the test program under SLES11SP4 OCFS2 cluster), actually this issue can be reproduced in openSuSe 13.2 (more newer code), but in direct-io mode, this issue will disappear.
Quoted 1 line
Base on my investigation, the root cause is the buffer-io using cluster-lock
is different from direct-io, I do not know why buffer-io use cluster-lock like this way.
Quoted 8 lines
the code details are as below,
inaops.cfile,
281 static intocfs2_readpage(struct file *file, struct page *page)282 {283 struct inode *inode = page->mapping->host; 284 struct ocfs2_inode_info *oi = OCFS2_I(inode); 285 loff_t start = (loff_t)page->index << PAGE_CACHE_SHIFT; 286 int ret, unlock = 1;Quoted 5 lines
287
288 trace_ocfs2_readpage((unsigned long long)oi->ip_blkno,
289 (page ?page->index: 0));
290
291 ret =ocfs2_inode_lock_with_page(inode, NULL, 0, page); <<==this line
Quoted 9 lines
292 if (ret != 0) {
293 if (ret ==AOP_TRUNCATED_PAGE)
294 unlock = 0;
295mlog_errno(ret);
296 goto out;
297 }in
dlmglue.cfile,
2 int ocfs2_inode_lock_with_page(struct inode *inode,Quoted 7 lines
2443 struct buffer_head **ret_bh, 2444 int ex, 2445 struct page *page)2446 {
2447 int ret;
2448
2449 ret = ocfs2_inode_lock_full(inode,ret_bh, ex,
OCFS2_LOCK_NONBLOCK); <<== there, why using NONBLOCK mode to get the cluster lock? this way will let reading IO get starvation.Quoted 11 lines
2450 if (ret ==
-EAGAIN) {
2451unlock_page(page);
2452 if (ocfs2_inode_lock(inode, ret_bh, ex)== 0)
2453ocfs2_inode_unlock(inode, ex);
2454 ret =AOP_TRUNCATED_PAGE;
2455 }
2456
2457 return ret;
2458 }If you know the background behind the code, please tell us, why not use
block way to get the lock in reading a page, then reading IO will get the page fairly when there is a concurrent writing IO from the other node.
Quoted 1 line
Second, I tried to modify that line from
OCFS2_LOCK_NONBLOCKto 0 (switch toblocking way), the reading IO will not be blocked too much time (can erase the customer's complaining), but a new problem arises, sometimes the reading IO and writing IO get a dead lock (why dead lock? I am looking at).
Quoted 9 lines
Thanks
Gang.
Hi,
Quoted 7 lines · joseph
Hi Gang,
Eric and I have discussed this case before.
Using NONBLOCK here is because there is a lock inversion between inode lock and page lock. You can refer to the comments ofocfs2_inode_lock_with_pagefor details.
Actually I have found that NONBLOCK mode is only used in lock inversion cases.
Yes, that comments can helps;-) I try to explain it, if any problem please correct me.
On node 1, when calling ocfs2_inode_lock_with_page(), thread A(likely doing reading) has loced this page. Before thread A stepping into ocfs2_inode_lock_full(), on node 2, thread B(doing writing) required EX lock on the same inode, if lockres->l_level is PR, so lockres needs to been downconverted PR->NL on node1, i.e. ocfs2_blocking_ast()->ocfs2_wake_downconvert_thread().
On node 1, if tread ocfs2dc proceeds like this:ocfs2_downconvert_thread()
ocfs2_downconvert_thread_do_work()
ocfs2_process_blocked_lock()
ocfs2_unblock_lock()
lockres->l_ops->downconvert_worker(lockres, blocking)
ocfs2_data_convert_worker() {
...
3557 if (blocking == DLM_LOCK_EX) {
3558 truncate_inode_pages(mapping, 0);
3559 } else {
3560 /* We only need to wait on the I/O if we're not also
3561 * truncating pages because truncate_inode_pages waits
3562 * for us above. We don't truncate pages if we're
3563 * blocking anything < EXMODE because we want to keep
3564 * them around in that case. */
3565 filemap_fdatawait(mapping);
3566 }
...
}
We can see truncate_inode_pages()
truncate_inode_pages_range()
trylock_page()/lock_page()/find_lock_page()if thread A call ocfs2_inode_lock_full() in BLOCK way, there's a window that flag OCFS2_LOCK_BLOCED and ->l_blocking=EX have been set by BAST like ocfs2_blocking_ast()-> ocfs2_generic_handle_bast(), so thread A may be blocked.
Now, ocfs2dc wants page lock, but thread A hold page lock and has been blocked because of thread B. Deadlock occurs, right? Again, please correct me if any.
So, the author had to use UNBLOCK way here thus create livelock problem. But, I cannot understand very clearly how livelock come up. Joseph or anyone else, could you please elaborate it?
Thanks,
Eric
Quoted 68 lines
Thanks,
JosephQuoted 48 lines · Gang He
Hello Guys,
There is a issue from the customer, who is complaining that buffer reading sometimes lasts too much time ( 1 - 10 seconds) in case reading/writing the same file from different nodes concurrently.
According to the demo code from the customer, we also can reproduce this issue at home (run the test program under SLES11SP4 OCFS2 cluster), actually this issue can be reproduced in openSuSe 13.2 (more newer code), but in direct-io mode, this issue will disappear. Base on my investigation, the root cause is the buffer-io using cluster-lock is different from direct-io, I do not know why buffer-io use cluster-lock like this way.
the code details are as below,
inaops.cfile,
281 static intocfs2_readpage(struct file *file, struct page *page)
282 {283 struct inode *inode = page->mapping->host; 284 struct ocfs2_inode_info *oi = OCFS2_I(inode); 285 loff_t start = (loff_t)page->index << PAGE_CACHE_SHIFT; 286 int ret, unlock = 1;287
288 trace_ocfs2_readpage((unsigned long long)oi->ip_blkno,
289 (page ?page->index: 0));
290
291 ret =ocfs2_inode_lock_with_page(inode, NULL, 0, page); <<== this line
292 if (ret != 0) {
293 if (ret ==AOP_TRUNCATED_PAGE)
294 unlock = 0;
295mlog_errno(ret);
296 goto out;
297 }in
dlmglue.cfile,
2 int ocfs2_inode_lock_with_page(struct inode *inode,2443 struct buffer_head **ret_bh, 2444 int ex, 2445 struct page *page)2446 {
2447 int ret;
2448
2449 ret =ocfs2_inode_lock_full(inode, ret_bh, ex, OCFS2_LOCK_NONBLOCK); <<== there, why using NONBLOCK mode to get the cluster lock? this way will let reading IO get starvation.
2450 if (ret ==-EAGAIN) {
2451unlock_page(page);
2452 if (ocfs2_inode_lock(inode, ret_bh, ex)== 0)
2453ocfs2_inode_unlock(inode, ex);
2454 ret =AOP_TRUNCATED_PAGE;
2455 }
2456
2457 return ret;
2458 }If you know the background behind the code, please tell us, why not use block way to get the lock in reading a page, then reading IO will get the page fairly when there is a concurrent writing IO from the other node.
Second, I tried to modify that line fromOCFS2_LOCK_NONBLOCKto 0 (switch to blocking way), the reading IO will not be blocked too much time (can erase the customer's complaining), but a new problem arises, sometimes the reading IO and writing IO get a dead lock (why dead lock? I am looking at).Quoted 7 lines
Thanks
Gang.
_______________________________________________
Ocfs2-devel mailing list
Ocfs2-devel at oss.oracle.com
https://oss.oracle.com/mailman/listinfo/ocfs2-devel
Quoted 41 lines · Eric Ren
Hi,
Quoted 7 lines · joseph
Hi Gang,
Eric and I have discussed this case before.
Using NONBLOCK here is because there is a lock inversion between inode lock and page lock. You can refer to the comments ofocfs2_inode_lock_with_pagefor details.
Actually I have found that NONBLOCK mode is only used in lock inversion cases.Yes, that comments can helps;-) I try to explain it, if any problem please correct me.
On node 1, when calling
ocfs2_inode_lock_with_page(), thread A(likely doing reading) has loced this page. Before thread A stepping intoocfs2_inode_lock_full(), on node 2, thread B(doing writing) required EX lock on the same inode, iflockres->l_levelis PR, so lockres needs to been downconvertedPR->NLon node1, i.e. ocfs2_blocking_ast()->ocfs2_wake_downconvert_thread().On node 1, if tread ocfs2dc proceeds like this:
ocfs2_downconvert_thread()
ocfs2_downconvert_thread_do_work()
ocfs2_process_blocked_lock()
ocfs2_unblock_lock()lockres->l_ops->downconvert_worker(lockres, blocking) ocfs2_data_convert_worker() { ... 3557 if (blocking == DLM_LOCK_EX) { 3558 truncate_inode_pages(mapping, 0); 3559 } else { 3560 /* We only need to wait on the I/O if we're not also 3561 * truncating pages because truncate_inode_pages waits 3562 * for us above. We don't truncate pages if we're 3563 * blocking anything < EXMODE because we want to keep 3564 * them around in that case. */ 3565 filemap_fdatawait(mapping); 3566 } ... } We can see truncate_inode_pages() truncate_inode_pages_range() trylock_page()/lock_page()/find_lock_page()
Quoted 6 lines
if thread A call
ocfs2_inode_lock_full()in BLOCK way, there's a window that flagOCFS2_LOCK_BLOCEDand ->l_blocking=EX have been set by BAST like ocfs2_blocking_ast()->ocfs2_generic_handle_bast(), so thread A may be blocked.Now, ocfs2dc wants page lock, but thread A hold page lock and has been blocked because of thread B. Deadlock occurs, right? Again, please correct me if any.
Yes, you are right.
Quoted 3 lines
So, the author had to use UNBLOCK way here thus create livelock problem. But, I cannot understand very clearly how livelock come up. Joseph or anyone else, could you please elaborate it?
Firstly it takes inode lock in NONBLOCK way, if it couldn't be fulfilled currently and returns -EAGAIN, then unlock page and make downconvert go on. This is to release the deadlock.
But we do have to take page lock and inode lock to safely accomplish the request. So it has to return to VFS and retry with page lock. Here taking inode lock and then unlocking it immediately in BLOCK way wants to cache the inode and increase the chance of the next retry. But if another node successfully takes the inode lock again immediately after this node unlocks inode, the flow you described above happens again and this node still couldn't be fulfilled. And so forth.
Quoted 80 lines
Thanks,
EricQuoted 63 lines
Thanks,
JosephQuoted 48 lines · Gang He
Hello Guys,
There is a issue from the customer, who is complaining that buffer reading sometimes lasts too much time ( 1 - 10 seconds) in case reading/writing the same file from different nodes concurrently.
According to the demo code from the customer, we also can reproduce this issue at home (run the test program under SLES11SP4 OCFS2 cluster), actually this issue can be reproduced in openSuSe 13.2 (more newer code), but in direct-io mode, this issue will disappear. Base on my investigation, the root cause is the buffer-io using cluster-lock is different from direct-io, I do not know why buffer-io use cluster-lock like this way.
the code details are as below,
inaops.cfile,
281 static intocfs2_readpage(struct file *file, struct page *page)
282 {283 struct inode *inode = page->mapping->host; 284 struct ocfs2_inode_info *oi = OCFS2_I(inode); 285 loff_t start = (loff_t)page->index << PAGE_CACHE_SHIFT; 286 int ret, unlock = 1;287
288 trace_ocfs2_readpage((unsigned long long)oi->ip_blkno,
289 (page ?page->index: 0));
290
291 ret =ocfs2_inode_lock_with_page(inode, NULL, 0, page); <<== this line
292 if (ret != 0) {
293 if (ret ==AOP_TRUNCATED_PAGE)
294 unlock = 0;
295mlog_errno(ret);
296 goto out;
297 }in
dlmglue.cfile,
2 int ocfs2_inode_lock_with_page(struct inode *inode,2443 struct buffer_head **ret_bh, 2444 int ex, 2445 struct page *page)2446 {
2447 int ret;
2448
2449 ret =ocfs2_inode_lock_full(inode, ret_bh, ex, OCFS2_LOCK_NONBLOCK); <<== there, why using NONBLOCK mode to get the cluster lock? this way will let reading IO get starvation.
2450 if (ret ==-EAGAIN) {
2451unlock_page(page);
2452 if (ocfs2_inode_lock(inode, ret_bh, ex)== 0)
2453ocfs2_inode_unlock(inode, ex);
2454 ret =AOP_TRUNCATED_PAGE;
2455 }
2456
2457 return ret;
2458 }If you know the background behind the code, please tell us, why not use block way to get the lock in reading a page, then reading IO will get the page fairly when there is a concurrent writing IO from the other node.
Second, I tried to modify that line fromOCFS2_LOCK_NONBLOCKto 0 (switch to blocking way), the reading IO will not be blocked too much time (can erase the customer's complaining), but a new problem arises, sometimes the reading IO and writing IO get a dead lock (why dead lock? I am looking at).Quoted 7 lines
Thanks
Gang.
Quoted 5 lines
_______________________________________________
Ocfs2-devel mailing list
Ocfs2-devel at oss.oracle.com
https://oss.oracle.com/mailman/listinfo/ocfs2-devel_______________________________________________
Ocfs2-devel mailing list
Ocfs2-devel at oss.oracle.com
https://oss.oracle.com/mailman/listinfo/ocfs2-devel.
Hi Joseph,
Quoted 50 lines · joseph
Quoted 41 lines · Eric Ren
Hi,
Quoted 7 lines · joseph
Hi Gang,
Eric and I have discussed this case before.
Using NONBLOCK here is because there is a lock inversion between inode lock and page lock. You can refer to the comments ofocfs2_inode_lock_with_pagefor details.
Actually I have found that NONBLOCK mode is only used in lock inversion cases.Yes, that comments can helps;-) I try to explain it, if any problem please correct me.
On node 1, when calling
ocfs2_inode_lock_with_page(), thread A(likely doing reading) has loced this page. Before thread A stepping intoocfs2_inode_lock_full(), on node 2, thread B(doing writing) required EX lock on the same inode, iflockres->l_levelis PR, so lockres needs to been downconvertedPR->NLon node1, i.e. ocfs2_blocking_ast()->ocfs2_wake_downconvert_thread().On node 1, if tread ocfs2dc proceeds like this:
ocfs2_downconvert_thread()
ocfs2_downconvert_thread_do_work()
ocfs2_process_blocked_lock()
ocfs2_unblock_lock()lockres->l_ops->downconvert_worker(lockres, blocking) ocfs2_data_convert_worker() { ... 3557 if (blocking == DLM_LOCK_EX) { 3558 truncate_inode_pages(mapping, 0); 3559 } else { 3560 /* We only need to wait on the I/O if we're not also 3561 * truncating pages because truncate_inode_pages waits 3562 * for us above. We don't truncate pages if we're 3563 * blocking anything < EXMODE because we want to keep 3564 * them around in that case. */ 3565 filemap_fdatawait(mapping); 3566 } ... } We can see truncate_inode_pages() truncate_inode_pages_range() trylock_page()/lock_page()/find_lock_page()Quoted 6 lines
if thread A call
ocfs2_inode_lock_full()in BLOCK way, there's a window that flagOCFS2_LOCK_BLOCEDand ->l_blocking=EX have been set by BAST like ocfs2_blocking_ast()->ocfs2_generic_handle_bast(), so thread A may be blocked.Now, ocfs2dc wants page lock, but thread A hold page lock and has been blocked because of thread B. Deadlock occurs, right? Again, please correct me if any.
Yes, you are right.
Quoted 1 line
Quoted 8 lines
Quoted 2 lines
So, the author had to use UNBLOCK way here thus create livelock problem. But, I cannot understand very clearly how livelock come up. Joseph or anyone else, could you please elaborate it?
Firstly it takes inode lock in NONBLOCK way, if it couldn't be fulfilled currently and returns
-EAGAIN, then unlock page and make downconvert go on. This is to release the deadlock.
But we do have to take page lock and inode lock to safely accomplish the request. So it has to return to VFS and retry with page lock. Here taking inode lock and then unlocking it immediately in BLOCK way wants
Thanks! But unfortunately in our case, it oftern takes long time waiting here for inode lock, for some reasons I don't know yet. This is likely the cause why ocfs2_readpage() takes long.
I really want to know why to lock & unlock inode here? I'm glad you mention the reason, but is it the only one?
Quoted 1 line
to cache the inode and increase the chance of the next retry. But if
Any reason to cache the inode? And how this can increase the chance of retry? It's really interesting... Please elaborate more;-)
Thanks,
Eric
Quoted 87 lines
another node successfully takes the inode lock again immediately after this node unlocks inode, the flow you described above happens again and this node still couldn't be fulfilled. And so forth.
Quoted 80 lines
Thanks,
EricQuoted 63 lines
Thanks,
JosephQuoted 48 lines · Gang He
Hello Guys,
There is a issue from the customer, who is complaining that buffer reading sometimes lasts too much time ( 1 - 10 seconds) in case reading/writing the same file from different nodes concurrently.
According to the demo code from the customer, we also can reproduce this issue at home (run the test program under SLES11SP4 OCFS2 cluster), actually this issue can be reproduced in openSuSe 13.2 (more newer code), but in direct-io mode, this issue will disappear. Base on my investigation, the root cause is the buffer-io using cluster-lock is different from direct-io, I do not know why buffer-io use cluster-lock like this way.
the code details are as below,
inaops.cfile,
281 static intocfs2_readpage(struct file *file, struct page *page)
282 {283 struct inode *inode = page->mapping->host; 284 struct ocfs2_inode_info *oi = OCFS2_I(inode); 285 loff_t start = (loff_t)page->index << PAGE_CACHE_SHIFT; 286 int ret, unlock = 1;287
288 trace_ocfs2_readpage((unsigned long long)oi->ip_blkno,
289 (page ?page->index: 0));
290
291 ret =ocfs2_inode_lock_with_page(inode, NULL, 0, page); <<== this line
292 if (ret != 0) {
293 if (ret ==AOP_TRUNCATED_PAGE)
294 unlock = 0;
295mlog_errno(ret);
296 goto out;
297 }in
dlmglue.cfile,
2 int ocfs2_inode_lock_with_page(struct inode *inode,2443 struct buffer_head **ret_bh, 2444 int ex, 2445 struct page *page)2446 {
2447 int ret;
2448
2449 ret =ocfs2_inode_lock_full(inode, ret_bh, ex, OCFS2_LOCK_NONBLOCK); <<== there, why using NONBLOCK mode to get the cluster lock? this way will let reading IO get starvation.
2450 if (ret ==-EAGAIN) {
2451unlock_page(page);
2452 if (ocfs2_inode_lock(inode, ret_bh, ex)== 0)
2453ocfs2_inode_unlock(inode, ex);
2454 ret =AOP_TRUNCATED_PAGE;
2455 }
2456
2457 return ret;
2458 }If you know the background behind the code, please tell us, why not use block way to get the lock in reading a page, then reading IO will get the page fairly when there is a concurrent writing IO from the other node.
Second, I tried to modify that line fromOCFS2_LOCK_NONBLOCKto 0 (switch to blocking way), the reading IO will not be blocked too much time (can erase the customer's complaining), but a new problem arises, sometimes the reading IO and writing IO get a dead lock (why dead lock? I am looking at).Quoted 7 lines
Thanks
Gang.
Quoted 5 lines
_______________________________________________
Ocfs2-devel mailing list
Ocfs2-devel at oss.oracle.com
https://oss.oracle.com/mailman/listinfo/ocfs2-devel_______________________________________________
Ocfs2-devel mailing list
Ocfs2-devel at oss.oracle.com
https://oss.oracle.com/mailman/listinfo/ocfs2-devel.
Quoted 60 lines · Eric Ren
Hi Joseph,
Quoted 50 lines · joseph
Quoted 41 lines · Eric Ren
Hi,
Quoted 7 lines · joseph
Hi Gang,
Eric and I have discussed this case before.
Using NONBLOCK here is because there is a lock inversion between inode lock and page lock. You can refer to the comments ofocfs2_inode_lock_with_pagefor details.
Actually I have found that NONBLOCK mode is only used in lock inversion cases.Yes, that comments can helps;-) I try to explain it, if any problem please correct me.
On node 1, when calling
ocfs2_inode_lock_with_page(), thread A(likely doing reading) has loced this page. Before thread A stepping intoocfs2_inode_lock_full(), on node 2, thread B(doing writing) required EX lock on the same inode, iflockres->l_levelis PR, so lockres needs to been downconvertedPR->NLon node1, i.e. ocfs2_blocking_ast()->ocfs2_wake_downconvert_thread().On node 1, if tread ocfs2dc proceeds like this:
ocfs2_downconvert_thread()
ocfs2_downconvert_thread_do_work()
ocfs2_process_blocked_lock()
ocfs2_unblock_lock()lockres->l_ops->downconvert_worker(lockres, blocking) ocfs2_data_convert_worker() { ... 3557 if (blocking == DLM_LOCK_EX) { 3558 truncate_inode_pages(mapping, 0); 3559 } else { 3560 /* We only need to wait on the I/O if we're not also 3561 * truncating pages because truncate_inode_pages waits 3562 * for us above. We don't truncate pages if we're 3563 * blocking anything < EXMODE because we want to keep 3564 * them around in that case. */ 3565 filemap_fdatawait(mapping); 3566 } ... } We can see truncate_inode_pages() truncate_inode_pages_range() trylock_page()/lock_page()/find_lock_page()Quoted 6 lines
if thread A call
ocfs2_inode_lock_full()in BLOCK way, there's a window that flagOCFS2_LOCK_BLOCEDand ->l_blocking=EX have been set by BAST like ocfs2_blocking_ast()->ocfs2_generic_handle_bast(), so thread A may be blocked.Now, ocfs2dc wants page lock, but thread A hold page lock and has been blocked because of thread B. Deadlock occurs, right? Again, please correct me if any.
Yes, you are right.
Quoted 1 line
Quoted 8 lines
Quoted 2 lines
So, the author had to use UNBLOCK way here thus create livelock problem. But, I cannot understand very clearly how livelock come up. Joseph or anyone else, could you please elaborate it?
Firstly it takes inode lock in NONBLOCK way, if it couldn't be fulfilled currently and returns
-EAGAIN, then unlock page and make downconvert go on. This is to release the deadlock.
But we do have to take page lock and inode lock to safely accomplish the request. So it has to return to VFS and retry with page lock. Here taking inode lock and then unlocking it immediately in BLOCK way wants
Quoted 3 lines
Thanks! But unfortunately in our case, it oftern takes long time waiting here for inode lock, for some reasons I don't know yet. This is likely the cause why
ocfs2_readpage()takes long.
One time takes long time or retry many times? The former may be because downconvert take too much time, or there are many requests ahead of this node. And the latter may be this node still fails the race when retry.
Quoted 6 lines
I really want to know why to lock & unlock inode here? I'm glad you mention the reason, but is it the only one?
Quoted 1 line
to cache the inode and increase the chance of the next retry. But if
Any reason to cache the inode? And how this can increase the chance of retry? It's really interesting... Please elaborate more;-)
IMO? this is because unlock is not truly unlock. This node retry is somewhat 'local' operation, and another node has to send messages, so this node has more chance to win the race.
Thanks,
Joseph
Quoted 98 lines
Thanks,
EricQuoted 87 lines
another node successfully takes the inode lock again immediately after this node unlocks inode, the flow you described above happens again and this node still couldn't be fulfilled. And so forth.
Quoted 80 lines
Thanks,
EricQuoted 63 lines
Thanks,
JosephQuoted 48 lines · Gang He
Hello Guys,
There is a issue from the customer, who is complaining that buffer reading sometimes lasts too much time ( 1 - 10 seconds) in case reading/writing the same file from different nodes concurrently.
According to the demo code from the customer, we also can reproduce this issue at home (run the test program under SLES11SP4 OCFS2 cluster), actually this issue can be reproduced in openSuSe 13.2 (more newer code), but in direct-io mode, this issue will disappear. Base on my investigation, the root cause is the buffer-io using cluster-lock is different from direct-io, I do not know why buffer-io use cluster-lock like this way.
the code details are as below,
inaops.cfile,
281 static intocfs2_readpage(struct file *file, struct page *page)
282 {283 struct inode *inode = page->mapping->host; 284 struct ocfs2_inode_info *oi = OCFS2_I(inode); 285 loff_t start = (loff_t)page->index << PAGE_CACHE_SHIFT; 286 int ret, unlock = 1;287
288 trace_ocfs2_readpage((unsigned long long)oi->ip_blkno,
289 (page ?page->index: 0));
290
291 ret =ocfs2_inode_lock_with_page(inode, NULL, 0, page); <<== this line
292 if (ret != 0) {
293 if (ret ==AOP_TRUNCATED_PAGE)
294 unlock = 0;
295mlog_errno(ret);
296 goto out;
297 }in
dlmglue.cfile,
2 int ocfs2_inode_lock_with_page(struct inode *inode,2443 struct buffer_head **ret_bh, 2444 int ex, 2445 struct page *page)2446 {
2447 int ret;
2448
2449 ret =ocfs2_inode_lock_full(inode, ret_bh, ex, OCFS2_LOCK_NONBLOCK); <<== there, why using NONBLOCK mode to get the cluster lock? this way will let reading IO get starvation.
2450 if (ret ==-EAGAIN) {
2451unlock_page(page);
2452 if (ocfs2_inode_lock(inode, ret_bh, ex)== 0)
2453ocfs2_inode_unlock(inode, ex);
2454 ret =AOP_TRUNCATED_PAGE;
2455 }
2456
2457 return ret;
2458 }If you know the background behind the code, please tell us, why not use block way to get the lock in reading a page, then reading IO will get the page fairly when there is a concurrent writing IO from the other node.
Second, I tried to modify that line fromOCFS2_LOCK_NONBLOCKto 0 (switch to blocking way), the reading IO will not be blocked too much time (can erase the customer's complaining), but a new problem arises, sometimes the reading IO and writing IO get a dead lock (why dead lock? I am looking at).Quoted 7 lines
Thanks
Gang.
Quoted 5 lines
_______________________________________________
Ocfs2-devel mailing list
Ocfs2-devel at oss.oracle.com
https://oss.oracle.com/mailman/listinfo/ocfs2-devel_______________________________________________
Ocfs2-devel mailing list
Ocfs2-devel at oss.oracle.com
https://oss.oracle.com/mailman/listinfo/ocfs2-devel.
_______________________________________________
Ocfs2-devel mailing list
Ocfs2-devel at oss.oracle.com
https://oss.oracle.com/mailman/listinfo/ocfs2-devel.
Hi Joseph,
Quoted 61 lines · joseph
Quoted 60 lines · Eric Ren
Hi Joseph,
Quoted 58 lines · joseph
Quoted 41 lines · Eric Ren
Hi,
Quoted 7 lines · joseph
Hi Gang,
Eric and I have discussed this case before.
Using NONBLOCK here is because there is a lock inversion between inode lock and page lock. You can refer to the comments ofocfs2_inode_lock_with_pagefor details.
Actually I have found that NONBLOCK mode is only used in lock inversion cases.Yes, that comments can helps;-) I try to explain it, if any problem please correct me.
On node 1, when calling
ocfs2_inode_lock_with_page(), thread A(likely doing reading) has loced this page. Before thread A stepping intoocfs2_inode_lock_full(), on node 2, thread B(doing writing) required EX lock on the same inode, iflockres->l_levelis PR, so lockres needs to been downconvertedPR->NLon node1, i.e. ocfs2_blocking_ast()->ocfs2_wake_downconvert_thread().On node 1, if tread ocfs2dc proceeds like this:
ocfs2_downconvert_thread()
ocfs2_downconvert_thread_do_work()
ocfs2_process_blocked_lock()
ocfs2_unblock_lock()lockres->l_ops->downconvert_worker(lockres, blocking) ocfs2_data_convert_worker() { ... 3557 if (blocking == DLM_LOCK_EX) { 3558 truncate_inode_pages(mapping, 0); 3559 } else { 3560 /* We only need to wait on the I/O if we're not also 3561 * truncating pages because truncate_inode_pages waits 3562 * for us above. We don't truncate pages if we're 3563 * blocking anything < EXMODE because we want to keep 3564 * them around in that case. */ 3565 filemap_fdatawait(mapping); 3566 } ... } We can see truncate_inode_pages() truncate_inode_pages_range() trylock_page()/lock_page()/find_lock_page()Quoted 6 lines
if thread A call
ocfs2_inode_lock_full()in BLOCK way, there's a window that flagOCFS2_LOCK_BLOCEDand ->l_blocking=EX have been set by BAST like ocfs2_blocking_ast()->ocfs2_generic_handle_bast(), so thread A may be blocked.Now, ocfs2dc wants page lock, but thread A hold page lock and has been blocked because of thread B. Deadlock occurs, right? Again, please correct me if any.
Yes, you are right.
Quoted 3 lines
So, the author had to use UNBLOCK way here thus create livelock problem. But, I cannot understand very clearly how livelock come up. Joseph or anyone else, could you please elaborate it?
Firstly it takes inode lock in NONBLOCK way, if it couldn't be fulfilled currently and returns
-EAGAIN, then unlock page and make downconvert go on. This is to release the deadlock.
But we do have to take page lock and inode lock to safely accomplish the request. So it has to return to VFS and retry with page lock. Here taking inode lock and then unlocking it immediately in BLOCK way wants
Quoted 4 lines
Quoted 3 lines
Thanks! But unfortunately in our case, it oftern takes long time waiting here for inode lock, for some reasons I don't know yet. This is likely the cause why
ocfs2_readpage()takes long.One time takes long time or retry many times? The former may be because
One time takes long time, that's observed by ftrace ;-)
Quoted 2 lines
downconvert take too much time, or there are many requests ahead of this node. And the latter may be this node still fails the race when retry.
Thanks very much for your info!
Quoted 10 lines
Quoted 7 lines
I really want to know why to lock & unlock inode here? I'm glad you mention the reason, but is it the only one?
Quoted 1 line
to cache the inode and increase the chance of the next retry. But if
Any reason to cache the inode? And how this can increase the chance of retry? It's really interesting... Please elaborate more;-)
IMO? this is because unlock is not truly unlock. This node retry is somewhat 'local' operation, and another node has to send messages, so this node has more chance to win the race.
Sounds reasonable, thanks!
Eric
Quoted 104 lines
Thanks,
JosephQuoted 98 lines
Thanks,
EricQuoted 87 lines
another node successfully takes the inode lock again immediately after this node unlocks inode, the flow you described above happens again and this node still couldn't be fulfilled. And so forth.
Quoted 80 lines
Thanks,
EricQuoted 63 lines
Thanks,
JosephQuoted 48 lines · Gang He
Hello Guys,
There is a issue from the customer, who is complaining that buffer reading sometimes lasts too much time ( 1 - 10 seconds) in case reading/writing the same file from different nodes concurrently.
According to the demo code from the customer, we also can reproduce this issue at home (run the test program under SLES11SP4 OCFS2 cluster), actually this issue can be reproduced in openSuSe 13.2 (more newer code), but in direct-io mode, this issue will disappear. Base on my investigation, the root cause is the buffer-io using cluster-lock is different from direct-io, I do not know why buffer-io use cluster-lock like this way.
the code details are as below,
inaops.cfile,
281 static intocfs2_readpage(struct file *file, struct page *page)
282 {283 struct inode *inode = page->mapping->host; 284 struct ocfs2_inode_info *oi = OCFS2_I(inode); 285 loff_t start = (loff_t)page->index << PAGE_CACHE_SHIFT; 286 int ret, unlock = 1;287
288 trace_ocfs2_readpage((unsigned long long)oi->ip_blkno,
289 (page ?page->index: 0));
290
291 ret =ocfs2_inode_lock_with_page(inode, NULL, 0, page); <<== this line
292 if (ret != 0) {
293 if (ret ==AOP_TRUNCATED_PAGE)
294 unlock = 0;
295mlog_errno(ret);
296 goto out;
297 }in
dlmglue.cfile,
2 int ocfs2_inode_lock_with_page(struct inode *inode,2443 struct buffer_head **ret_bh, 2444 int ex, 2445 struct page *page)2446 {
2447 int ret;
2448
2449 ret =ocfs2_inode_lock_full(inode, ret_bh, ex, OCFS2_LOCK_NONBLOCK); <<== there, why using NONBLOCK mode to get the cluster lock? this way will let reading IO get starvation.
2450 if (ret ==-EAGAIN) {
2451unlock_page(page);
2452 if (ocfs2_inode_lock(inode, ret_bh, ex)== 0)
2453ocfs2_inode_unlock(inode, ex);
2454 ret =AOP_TRUNCATED_PAGE;
2455 }
2456
2457 return ret;
2458 }If you know the background behind the code, please tell us, why not use block way to get the lock in reading a page, then reading IO will get the page fairly when there is a concurrent writing IO from the other node.
Second, I tried to modify that line fromOCFS2_LOCK_NONBLOCKto 0 (switch to blocking way), the reading IO will not be blocked too much time (can erase the customer's complaining), but a new problem arises, sometimes the reading IO and writing IO get a dead lock (why dead lock? I am looking at).Quoted 7 lines
Thanks
Gang.
Quoted 5 lines
_______________________________________________
Ocfs2-devel mailing list
Ocfs2-devel at oss.oracle.com
https://oss.oracle.com/mailman/listinfo/ocfs2-devel_______________________________________________
Ocfs2-devel mailing list
Ocfs2-devel at oss.oracle.com
https://oss.oracle.com/mailman/listinfo/ocfs2-devel.
_______________________________________________
Ocfs2-devel mailing list
Ocfs2-devel at oss.oracle.com
https://oss.oracle.com/mailman/listinfo/ocfs2-devel.