Skip to contentSkip to conversation

ocfs2: try a blocking lock before return AOP_TRUNCATED_PAGE

PATCH Superseded Gang He 5 participants 13 messages Dec 27, 2017 – Dec 28, 2017 OCFS2

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Gang He

author
#0 lore raw

PATCH 1/1 ocfs2: try a blocking lock before return AOP_TRUNCATED_PAGE

If we can't get inode lock immediately in the function ocfs2_inode_lock_with_page() when reading a page, we should not return directly here, since this will lead to a softlockup problem. The method is to get a blocking lock and immediately unlock before returning, this can avoid CPU resource waste due to lots of retries, and benefits fairness in getting lock among multiple nodes, increase efficiency in case modifying the same file frequently from multiple nodes.
The softlockup problem looks like,

Kernel panic - not syncing: softlockup: hung tasks
CPU: 0 PID: 885 Comm: multi_mmap Tainted: G L 4.12.14-6.1-default #1
Hardware name: Bochs Bochs, BIOS Bochs 01/01/2011
Call Trace:
  <IRQ>
  dump_stack+0x5c/0x82
  panic+0xd5/0x21e
  watchdog_timer_fn+0x208/0x210
  ? watchdog_park_threads+0x70/0x70
  __hrtimer_run_queues+0xcc/0x200
  hrtimer_interrupt+0xa6/0x1f0
  smp_apic_timer_interrupt+0x34/0x50
  apic_timer_interrupt+0x96/0xa0
  </IRQ>
 RIP: 0010:unlock_page+0x17/0x30
 RSP: 0000:ffffaf154080bc88 EFLAGS: 00000246 ORIG_RAX: ffffffffffffff10
 RAX: dead000000000100 RBX: fffff21e009f5300 RCX: 0000000000000004
 RDX: dead0000000000ff RSI: 0000000000000202 RDI: fffff21e009f5300
 RBP: 0000000000000000 R08: 0000000000000000 R09: ffffaf154080bb00
 R10: ffffaf154080bc30 R11: 0000000000000040 R12: ffff993749a39518
 R13: 0000000000000000 R14: fffff21e009f5300 R15: fffff21e009f5300
  ocfs2_inode_lock_with_page+0x25/0x30 [ocfs2]
  ocfs2_readpage+0x41/0x2d0 [ocfs2]
  ? pagecache_get_page+0x30/0x200
  filemap_fault+0x12b/0x5c0
  ? recalc_sigpending+0x17/0x50
  ? __set_task_blocked+0x28/0x70
  ? __set_current_blocked+0x3d/0x60
  ocfs2_fault+0x29/0xb0 [ocfs2]
  __do_fault+0x1a/0xa0
  __handle_mm_fault+0xbe8/0x1090
  handle_mm_fault+0xaa/0x1f0
  __do_page_fault+0x235/0x4b0
  trace_do_page_fault+0x3c/0x110
  async_page_fault+0x28/0x30
 RIP: 0033:0x7fa75ded638e
 RSP: 002b:00007ffd6657db18 EFLAGS: 00010287
 RAX: 000055c7662fb700 RBX: 0000000000000001 RCX: 000055c7662fb700
 RDX: 0000000000001770 RSI: 00007fa75e909000 RDI: 000055c7662fb700
 RBP: 0000000000000003 R08: 000000000000000e R09: 0000000000000000
 R10: 0000000000000483 R11: 00007fa75ded61b0 R12: 00007fa75e90a770
 R13: 000000000000000e R14: 0000000000001770 R15: 0000000000000000
Fixes 1cce4df04f37 ("ocfs2: do not lock/unlock() inode DLM lock")
---
 fs/ocfs2/dlmglue.c | 9 +++++++++
 1 file changed, 9 insertions(+)
fs/ocfs2/dlmglue.c +9 -0
index 4689940..5193218 100644
@@ -2486,6 +2486,15 @@ int ocfs2_inode_lock_with_page(struct inode *inode,
 	ret = ocfs2_inode_lock_full(inode, ret_bh, ex, OCFS2_LOCK_NONBLOCK);
 	if (ret == -EAGAIN) {
 		unlock_page(page);
+		/*
+		 * If we can't get inode lock immediately, we should not return
+		 * directly here, since this will lead to a softlockup problem.
+		 * The method is to get a blocking lock and immediately unlock
+		 * before returning, this can avoid CPU resource waste due to
+		 * lots of retries, and benefits fairness in getting lock.
+		 */
+		if (ocfs2_inode_lock(inode, ret_bh, ex) == 0)
+			ocfs2_inode_unlock(inode, ex);
 		ret = AOP_TRUNCATED_PAGE;
 	}
 
Signature · 1 line
1.8.5.6
#1 lore raw

Hi Gang,

Do you mean that too many retrys in loop cast losts of CPU-time and block page-fault interrupt? We should not add any delay in ocfs2_fault(), right? And I still feel a little confused why your method can solve this problem.

thanks,
Jun

Quoted 79 lines · Gang He

If we can't get inode lock immediately in the function ocfs2_inode_lock_with_page() when reading a page, we should not return directly here, since this will lead to a softlockup problem. The method is to get a blocking lock and immediately unlock before returning, this can avoid CPU resource waste due to lots of retries, and benefits fairness in getting lock among multiple nodes, increase efficiency in case modifying the same file frequently from multiple nodes.
The softlockup problem looks like,

Kernel panic - not syncing: softlockup: hung tasks
CPU: 0 PID: 885 Comm: multi_mmap Tainted: G L 4.12.14-6.1-default #1
Hardware name: Bochs Bochs, BIOS Bochs 01/01/2011
Call Trace:
  <IRQ>
  dump_stack+0x5c/0x82
  panic+0xd5/0x21e
  watchdog_timer_fn+0x208/0x210
  ? watchdog_park_threads+0x70/0x70
  __hrtimer_run_queues+0xcc/0x200
  hrtimer_interrupt+0xa6/0x1f0
  smp_apic_timer_interrupt+0x34/0x50
  apic_timer_interrupt+0x96/0xa0
  </IRQ>
 RIP: 0010:unlock_page+0x17/0x30
 RSP: 0000:ffffaf154080bc88 EFLAGS: 00000246 ORIG_RAX: ffffffffffffff10
 RAX: dead000000000100 RBX: fffff21e009f5300 RCX: 0000000000000004
 RDX: dead0000000000ff RSI: 0000000000000202 RDI: fffff21e009f5300
 RBP: 0000000000000000 R08: 0000000000000000 R09: ffffaf154080bb00
 R10: ffffaf154080bc30 R11: 0000000000000040 R12: ffff993749a39518
 R13: 0000000000000000 R14: fffff21e009f5300 R15: fffff21e009f5300
  ocfs2_inode_lock_with_page+0x25/0x30 [ocfs2]
  ocfs2_readpage+0x41/0x2d0 [ocfs2]
  ? pagecache_get_page+0x30/0x200
  filemap_fault+0x12b/0x5c0
  ? recalc_sigpending+0x17/0x50
  ? __set_task_blocked+0x28/0x70
  ? __set_current_blocked+0x3d/0x60
  ocfs2_fault+0x29/0xb0 [ocfs2]
  __do_fault+0x1a/0xa0
  __handle_mm_fault+0xbe8/0x1090
  handle_mm_fault+0xaa/0x1f0
  __do_page_fault+0x235/0x4b0
  trace_do_page_fault+0x3c/0x110
  async_page_fault+0x28/0x30
 RIP: 0033:0x7fa75ded638e
 RSP: 002b:00007ffd6657db18 EFLAGS: 00010287
 RAX: 000055c7662fb700 RBX: 0000000000000001 RCX: 000055c7662fb700
 RDX: 0000000000001770 RSI: 00007fa75e909000 RDI: 000055c7662fb700
 RBP: 0000000000000003 R08: 000000000000000e R09: 0000000000000000
 R10: 0000000000000483 R11: 00007fa75ded61b0 R12: 00007fa75e90a770
 R13: 000000000000000e R14: 0000000000001770 R15: 0000000000000000
Fixes 1cce4df04f37 ("ocfs2: do not lock/unlock() inode DLM lock")
---
 fs/ocfs2/dlmglue.c | 9 +++++++++
 1 file changed, 9 insertions(+)
fs/ocfs2/dlmglue.c +9 -0
index 4689940..5193218 100644
@@ -2486,6 +2486,15 @@ int ocfs2_inode_lock_with_page(struct inode *inode,
 	ret = ocfs2_inode_lock_full(inode, ret_bh, ex, OCFS2_LOCK_NONBLOCK);
 	if (ret == -EAGAIN) {
 		unlock_page(page);
+		/*
+		 * If we can't get inode lock immediately, we should not return
+		 * directly here, since this will lead to a softlockup problem.
+		 * The method is to get a blocking lock and immediately unlock
+		 * before returning, this can avoid CPU resource waste due to
+		 * lots of retries, and benefits fairness in getting lock.
+		 */
+		if (ocfs2_inode_lock(inode, ret_bh, ex) == 0)
+			ocfs2_inode_unlock(inode, ex);
 		ret = AOP_TRUNCATED_PAGE;
 	}
 
author
#2 lore raw

Hi Jun,

Quoted 7 lines
Quoted 1 line
Quoted 1 line

Hi Gang,

Do you mean that too many retrys in loop cast losts of CPU-time and block page-fault interrupt? We should not add any delay in ocfs2_fault(), right? And I still feel a little confused why your method can solve this problem.

You can see the related code in function filemap_fault(), if ocfs2 fails to read a page since it can not get a inode lock with non-block mode, the VFS layer code will invoke ocfs2
read page call back function circularly, this will lead to a softlockup problem (like the below back trace). So, we should get a blocking lock to let the dlm lock to this node and also can avoid CPU loop, second, base on my testing, the patch also can improve the efficiency in case modifying the same file frequently from multiple nodes, since the lock acquisition chance is more fair.
In fact, the code was modified by a patch 1cce4df04f37 ("ocfs2: do not lock/unlock() inode DLM lock"), before that patch, the code is the same, this patch can be considered to revert that patch, except adding more clear comments.

Thanks
Gang

Quoted 84 lines

thanks,
Jun

Quoted 79 lines · Gang He

If we can't get inode lock immediately in the function ocfs2_inode_lock_with_page() when reading a page, we should not return directly here, since this will lead to a softlockup problem. The method is to get a blocking lock and immediately unlock before returning, this can avoid CPU resource waste due to lots of retries, and benefits fairness in getting lock among multiple nodes, increase efficiency in case modifying the same file frequently from multiple nodes.
The softlockup problem looks like,

Kernel panic - not syncing: softlockup: hung tasks
CPU: 0 PID: 885 Comm: multi_mmap Tainted: G L 4.12.14-6.1-default #1
Hardware name: Bochs Bochs, BIOS Bochs 01/01/2011
Call Trace:
  <IRQ>
  dump_stack+0x5c/0x82
  panic+0xd5/0x21e
  watchdog_timer_fn+0x208/0x210
  ? watchdog_park_threads+0x70/0x70
  __hrtimer_run_queues+0xcc/0x200
  hrtimer_interrupt+0xa6/0x1f0
  smp_apic_timer_interrupt+0x34/0x50
  apic_timer_interrupt+0x96/0xa0
  </IRQ>
 RIP: 0010:unlock_page+0x17/0x30
 RSP: 0000:ffffaf154080bc88 EFLAGS: 00000246 ORIG_RAX: ffffffffffffff10
 RAX: dead000000000100 RBX: fffff21e009f5300 RCX: 0000000000000004
 RDX: dead0000000000ff RSI: 0000000000000202 RDI: fffff21e009f5300
 RBP: 0000000000000000 R08: 0000000000000000 R09: ffffaf154080bb00
 R10: ffffaf154080bc30 R11: 0000000000000040 R12: ffff993749a39518
 R13: 0000000000000000 R14: fffff21e009f5300 R15: fffff21e009f5300
  ocfs2_inode_lock_with_page+0x25/0x30 [ocfs2]
  ocfs2_readpage+0x41/0x2d0 [ocfs2]
  ? pagecache_get_page+0x30/0x200
  filemap_fault+0x12b/0x5c0
  ? recalc_sigpending+0x17/0x50
  ? __set_task_blocked+0x28/0x70
  ? __set_current_blocked+0x3d/0x60
  ocfs2_fault+0x29/0xb0 [ocfs2]
  __do_fault+0x1a/0xa0
  __handle_mm_fault+0xbe8/0x1090
  handle_mm_fault+0xaa/0x1f0
  __do_page_fault+0x235/0x4b0
  trace_do_page_fault+0x3c/0x110
  async_page_fault+0x28/0x30
 RIP: 0033:0x7fa75ded638e
 RSP: 002b:00007ffd6657db18 EFLAGS: 00010287
 RAX: 000055c7662fb700 RBX: 0000000000000001 RCX: 000055c7662fb700
 RDX: 0000000000001770 RSI: 00007fa75e909000 RDI: 000055c7662fb700
 RBP: 0000000000000003 R08: 000000000000000e R09: 0000000000000000
 R10: 0000000000000483 R11: 00007fa75ded61b0 R12: 00007fa75e90a770
 R13: 000000000000000e R14: 0000000000001770 R15: 0000000000000000
Fixes 1cce4df04f37 ("ocfs2: do not lock/unlock() inode DLM lock")
---
 fs/ocfs2/dlmglue.c | 9 +++++++++
 1 file changed, 9 insertions(+)
fs/ocfs2/dlmglue.c +9 -0
index 4689940..5193218 100644
@@ -2486,6 +2486,15 @@ int ocfs2_inode_lock_with_page(struct inode *inode,
 	ret = ocfs2_inode_lock_full(inode, ret_bh, ex, OCFS2_LOCK_NONBLOCK);
 	if (ret == -EAGAIN) {
 		unlock_page(page);
+		/*
+		 * If we can't get inode lock immediately, we should not return
+		 * directly here, since this will lead to a softlockup problem.
+		 * The method is to get a blocking lock and immediately unlock
+		 * before returning, this can avoid CPU resource waste due to
+		 * lots of retries, and benefits fairness in getting lock.
+		 */
+		if (ocfs2_inode_lock(inode, ret_bh, ex) == 0)
+			ocfs2_inode_unlock(inode, ex);
 		ret = AOP_TRUNCATED_PAGE;
 	}
 
#3 lore raw

Hi Gang,

Thanks for your explaination, and I just have one more question. Could we use 'ocfs2_inode_lock' instead of 'ocfs2_inode_lock_full' to avoid -EAGAIN circularly?

thanks,
Jun

Quoted 110 lines · Gang He

Hi Jun,

Quoted 7 lines
Quoted 1 line
Quoted 1 line

Hi Gang,

Do you mean that too many retrys in loop cast losts of CPU-time and block page-fault interrupt? We should not add any delay in ocfs2_fault(), right? And I still feel a little confused why your method can solve this problem.

You can see the related code in function filemap_fault(), if ocfs2 fails to read a page since it can not get a inode lock with non-block mode, the VFS layer code will invoke ocfs2
read page call back function circularly, this will lead to a softlockup problem (like the below back trace). So, we should get a blocking lock to let the dlm lock to this node and also can avoid CPU loop, second, base on my testing, the patch also can improve the efficiency in case modifying the same file frequently from multiple nodes, since the lock acquisition chance is more fair.
In fact, the code was modified by a patch 1cce4df04f37 ("ocfs2: do not lock/unlock() inode DLM lock"), before that patch, the code is the same, this patch can be considered to revert that patch, except adding more clear comments.

Thanks
Gang

Quoted 76 lines

thanks,
Jun

Quoted 71 lines · Gang He

If we can't get inode lock immediately in the function ocfs2_inode_lock_with_page() when reading a page, we should not return directly here, since this will lead to a softlockup problem. The method is to get a blocking lock and immediately unlock before returning, this can avoid CPU resource waste due to lots of retries, and benefits fairness in getting lock among multiple nodes, increase efficiency in case modifying the same file frequently from multiple nodes.
The softlockup problem looks like,

Kernel panic - not syncing: softlockup: hung tasks
CPU: 0 PID: 885 Comm: multi_mmap Tainted: G L 4.12.14-6.1-default #1
Hardware name: Bochs Bochs, BIOS Bochs 01/01/2011
Call Trace:
  <IRQ>
  dump_stack+0x5c/0x82
  panic+0xd5/0x21e
  watchdog_timer_fn+0x208/0x210
  ? watchdog_park_threads+0x70/0x70
  __hrtimer_run_queues+0xcc/0x200
  hrtimer_interrupt+0xa6/0x1f0
  smp_apic_timer_interrupt+0x34/0x50
  apic_timer_interrupt+0x96/0xa0
  </IRQ>
 RIP: 0010:unlock_page+0x17/0x30
 RSP: 0000:ffffaf154080bc88 EFLAGS: 00000246 ORIG_RAX: ffffffffffffff10
 RAX: dead000000000100 RBX: fffff21e009f5300 RCX: 0000000000000004
 RDX: dead0000000000ff RSI: 0000000000000202 RDI: fffff21e009f5300
 RBP: 0000000000000000 R08: 0000000000000000 R09: ffffaf154080bb00
 R10: ffffaf154080bc30 R11: 0000000000000040 R12: ffff993749a39518
 R13: 0000000000000000 R14: fffff21e009f5300 R15: fffff21e009f5300
  ocfs2_inode_lock_with_page+0x25/0x30 [ocfs2]
  ocfs2_readpage+0x41/0x2d0 [ocfs2]
  ? pagecache_get_page+0x30/0x200
  filemap_fault+0x12b/0x5c0
  ? recalc_sigpending+0x17/0x50
  ? __set_task_blocked+0x28/0x70
  ? __set_current_blocked+0x3d/0x60
  ocfs2_fault+0x29/0xb0 [ocfs2]
  __do_fault+0x1a/0xa0
  __handle_mm_fault+0xbe8/0x1090
  handle_mm_fault+0xaa/0x1f0
  __do_page_fault+0x235/0x4b0
  trace_do_page_fault+0x3c/0x110
  async_page_fault+0x28/0x30
 RIP: 0033:0x7fa75ded638e
 RSP: 002b:00007ffd6657db18 EFLAGS: 00010287
 RAX: 000055c7662fb700 RBX: 0000000000000001 RCX: 000055c7662fb700
 RDX: 0000000000001770 RSI: 00007fa75e909000 RDI: 000055c7662fb700
 RBP: 0000000000000003 R08: 000000000000000e R09: 0000000000000000
 R10: 0000000000000483 R11: 00007fa75ded61b0 R12: 00007fa75e90a770
 R13: 000000000000000e R14: 0000000000001770 R15: 0000000000000000
Fixes 1cce4df04f37 ("ocfs2: do not lock/unlock() inode DLM lock")
---
 fs/ocfs2/dlmglue.c | 9 +++++++++
 1 file changed, 9 insertions(+)
fs/ocfs2/dlmglue.c +5 -0
index 4689940..5193218 100644
@@ -2486,6 +2486,15 @@ int ocfs2_inode_lock_with_page(struct inode *inode,
 	ret = ocfs2_inode_lock_full(inode, ret_bh, ex, OCFS2_LOCK_NONBLOCK);
 	if (ret == -EAGAIN) {
 		unlock_page(page);
+		/*
+		 * If we can't get inode lock immediately, we should not return
+		 * directly here, since this will lead to a softlockup problem.
+		 * The method is to get a blocking lock and immediately unlock
+		 * before returning, this can avoid CPU resource waste due to
Quoted 8 lines

fs/ocfs2/dlmglue.c int ocfs2_inode_lock_with_page(struct inode *inode, · line 2500

Quoted 8 lines
fs/ocfs2/dlmglue.c +4 -0
+		 * lots of retries, and benefits fairness in getting lock.
+		 */
+		if (ocfs2_inode_lock(inode, ret_bh, ex) == 0)
+			ocfs2_inode_unlock(inode, ex);
 		ret = AOP_TRUNCATED_PAGE;
 	}
 

.

author
#4 lore raw

Hi Jun,

Quoted 6 lines
Quoted 1 line
Quoted 1 line

Hi Gang,

Thanks for your explaination, and I just have one more question. Could we use 'ocfs2_inode_lock' instead of 'ocfs2_inode_lock_full' to avoid -EAGAIN circularly?

No, please see the comments above the function ocfs2_inode_lock_with_page(), there will be probably a deadlock between tasks acquiring DLM locks while holding a page lock and the downconvert thread which blocks dlm lock acquiry while acquiring page locks.
Then, the OCFS2_LOCK_NONBLOCK flag was introduced as a workaround to avoid this case.

Thanks
Gang

Quoted 123 lines

thanks,
Jun

Quoted 11 lines · Gang He

Hi Jun,

Quoted 7 lines
Quoted 1 line
Quoted 1 line

Hi Gang,

Do you mean that too many retrys in loop cast losts of CPU-time and block page-fault interrupt? We should not add any delay in ocfs2_fault(), right? And I still feel a little confused why your method can solve this problem.

You can see the related code in function filemap_fault(), if ocfs2 fails to

read a page since

Quoted 1 line

it can not get a inode lock with non-block mode, the VFS layer code will

invoke ocfs2

Quoted 1 line

read page call back function circularly, this will lead to a softlockup

problem (like the below back trace).

Quoted 1 line

So, we should get a blocking lock to let the dlm lock to this node and also

can avoid CPU loop,

Quoted 1 line

second, base on my testing, the patch also can improve the efficiency in

case modifying the same

Quoted 1 line

file frequently from multiple nodes, since the lock acquisition chance is

more fair.

Quoted 1 line

In fact, the code was modified by a patch 1cce4df04f37 ("ocfs2: do not

lock/unlock() inode DLM lock"),

Quoted 1 line

before that patch, the code is the same, this patch can be considered to

revert that patch, except adding more

Quoted 92 lines

clear comments.

Thanks
Gang

Quoted 76 lines

thanks,
Jun

Quoted 71 lines · Gang He

If we can't get inode lock immediately in the function ocfs2_inode_lock_with_page() when reading a page, we should not return directly here, since this will lead to a softlockup problem. The method is to get a blocking lock and immediately unlock before returning, this can avoid CPU resource waste due to lots of retries, and benefits fairness in getting lock among multiple nodes, increase efficiency in case modifying the same file frequently from multiple nodes.
The softlockup problem looks like,

Kernel panic - not syncing: softlockup: hung tasks
CPU: 0 PID: 885 Comm: multi_mmap Tainted: G L 4.12.14-6.1-default #1
Hardware name: Bochs Bochs, BIOS Bochs 01/01/2011
Call Trace:
  <IRQ>
  dump_stack+0x5c/0x82
  panic+0xd5/0x21e
  watchdog_timer_fn+0x208/0x210
  ? watchdog_park_threads+0x70/0x70
  __hrtimer_run_queues+0xcc/0x200
  hrtimer_interrupt+0xa6/0x1f0
  smp_apic_timer_interrupt+0x34/0x50
  apic_timer_interrupt+0x96/0xa0
  </IRQ>
 RIP: 0010:unlock_page+0x17/0x30
 RSP: 0000:ffffaf154080bc88 EFLAGS: 00000246 ORIG_RAX: ffffffffffffff10
 RAX: dead000000000100 RBX: fffff21e009f5300 RCX: 0000000000000004
 RDX: dead0000000000ff RSI: 0000000000000202 RDI: fffff21e009f5300
 RBP: 0000000000000000 R08: 0000000000000000 R09: ffffaf154080bb00
 R10: ffffaf154080bc30 R11: 0000000000000040 R12: ffff993749a39518
 R13: 0000000000000000 R14: fffff21e009f5300 R15: fffff21e009f5300
  ocfs2_inode_lock_with_page+0x25/0x30 [ocfs2]
  ocfs2_readpage+0x41/0x2d0 [ocfs2]
  ? pagecache_get_page+0x30/0x200
  filemap_fault+0x12b/0x5c0
  ? recalc_sigpending+0x17/0x50
  ? __set_task_blocked+0x28/0x70
  ? __set_current_blocked+0x3d/0x60
  ocfs2_fault+0x29/0xb0 [ocfs2]
  __do_fault+0x1a/0xa0
  __handle_mm_fault+0xbe8/0x1090
  handle_mm_fault+0xaa/0x1f0
  __do_page_fault+0x235/0x4b0
  trace_do_page_fault+0x3c/0x110
  async_page_fault+0x28/0x30
 RIP: 0033:0x7fa75ded638e
 RSP: 002b:00007ffd6657db18 EFLAGS: 00010287
 RAX: 000055c7662fb700 RBX: 0000000000000001 RCX: 000055c7662fb700
 RDX: 0000000000001770 RSI: 00007fa75e909000 RDI: 000055c7662fb700
 RBP: 0000000000000003 R08: 000000000000000e R09: 0000000000000000
 R10: 0000000000000483 R11: 00007fa75ded61b0 R12: 00007fa75e90a770
 R13: 000000000000000e R14: 0000000000001770 R15: 0000000000000000
Fixes 1cce4df04f37 ("ocfs2: do not lock/unlock() inode DLM lock")
---
 fs/ocfs2/dlmglue.c | 9 +++++++++
 1 file changed, 9 insertions(+)
fs/ocfs2/dlmglue.c +5 -0
index 4689940..5193218 100644
@@ -2486,6 +2486,15 @@ int ocfs2_inode_lock_with_page(struct inode *inode,
 	ret = ocfs2_inode_lock_full(inode, ret_bh, ex, OCFS2_LOCK_NONBLOCK);
 	if (ret == -EAGAIN) {
 		unlock_page(page);
+		/*
+		 * If we can't get inode lock immediately, we should not return
+		 * directly here, since this will lead to a softlockup problem.
+		 * The method is to get a blocking lock and immediately unlock
+		 * before returning, this can avoid CPU resource waste due to
Quoted 8 lines

fs/ocfs2/dlmglue.c int ocfs2_inode_lock_with_page(struct inode *inode, · line 2500

Quoted 8 lines
fs/ocfs2/dlmglue.c +4 -0
+		 * lots of retries, and benefits fairness in getting lock.
+		 */
+		if (ocfs2_inode_lock(inode, ret_bh, ex) == 0)
+			ocfs2_inode_unlock(inode, ex);
 		ret = AOP_TRUNCATED_PAGE;
 	}
 

.

#5 lore raw

Hi Gang,

You cleared my doubt. Should we handle the errno of ocfs2_inode_lock() or just use mlog_errno()?

thanks,
Jun

Quoted 144 lines · Gang He

Hi Jun,

Quoted 6 lines
Quoted 1 line
Quoted 1 line

Hi Gang,

Thanks for your explaination, and I just have one more question. Could we use 'ocfs2_inode_lock' instead of 'ocfs2_inode_lock_full' to avoid -EAGAIN circularly?

No, please see the comments above the function ocfs2_inode_lock_with_page(), there will be probably a deadlock between tasks acquiring DLM locks while holding a page lock and the downconvert thread which blocks dlm lock acquiry while acquiring page locks.
Then, the OCFS2_LOCK_NONBLOCK flag was introduced as a workaround to avoid this case.

Thanks
Gang

Quoted 23 lines

thanks,
Jun

Quoted 11 lines · Gang He

Hi Jun,

Quoted 7 lines
Quoted 1 line
Quoted 1 line

Hi Gang,

Do you mean that too many retrys in loop cast losts of CPU-time and block page-fault interrupt? We should not add any delay in ocfs2_fault(), right? And I still feel a little confused why your method can solve this problem.

You can see the related code in function filemap_fault(), if ocfs2 fails to

read a page since

Quoted 1 line

it can not get a inode lock with non-block mode, the VFS layer code will

invoke ocfs2

Quoted 1 line

read page call back function circularly, this will lead to a softlockup

problem (like the below back trace).

Quoted 1 line

So, we should get a blocking lock to let the dlm lock to this node and also

can avoid CPU loop,

Quoted 100 lines
Quoted 1 line

second, base on my testing, the patch also can improve the efficiency in

case modifying the same

Quoted 1 line

file frequently from multiple nodes, since the lock acquisition chance is

more fair.

Quoted 1 line

In fact, the code was modified by a patch 1cce4df04f37 ("ocfs2: do not

lock/unlock() inode DLM lock"),

Quoted 1 line

before that patch, the code is the same, this patch can be considered to

revert that patch, except adding more

Quoted 92 lines

clear comments.

Thanks
Gang

Quoted 76 lines

thanks,
Jun

Quoted 71 lines · Gang He

If we can't get inode lock immediately in the function ocfs2_inode_lock_with_page() when reading a page, we should not return directly here, since this will lead to a softlockup problem. The method is to get a blocking lock and immediately unlock before returning, this can avoid CPU resource waste due to lots of retries, and benefits fairness in getting lock among multiple nodes, increase efficiency in case modifying the same file frequently from multiple nodes.
The softlockup problem looks like,

Kernel panic - not syncing: softlockup: hung tasks
CPU: 0 PID: 885 Comm: multi_mmap Tainted: G L 4.12.14-6.1-default #1
Hardware name: Bochs Bochs, BIOS Bochs 01/01/2011
Call Trace:
  <IRQ>
  dump_stack+0x5c/0x82
  panic+0xd5/0x21e
  watchdog_timer_fn+0x208/0x210
  ? watchdog_park_threads+0x70/0x70
  __hrtimer_run_queues+0xcc/0x200
  hrtimer_interrupt+0xa6/0x1f0
  smp_apic_timer_interrupt+0x34/0x50
  apic_timer_interrupt+0x96/0xa0
  </IRQ>
 RIP: 0010:unlock_page+0x17/0x30
 RSP: 0000:ffffaf154080bc88 EFLAGS: 00000246 ORIG_RAX: ffffffffffffff10
 RAX: dead000000000100 RBX: fffff21e009f5300 RCX: 0000000000000004
 RDX: dead0000000000ff RSI: 0000000000000202 RDI: fffff21e009f5300
 RBP: 0000000000000000 R08: 0000000000000000 R09: ffffaf154080bb00
 R10: ffffaf154080bc30 R11: 0000000000000040 R12: ffff993749a39518
 R13: 0000000000000000 R14: fffff21e009f5300 R15: fffff21e009f5300
  ocfs2_inode_lock_with_page+0x25/0x30 [ocfs2]
  ocfs2_readpage+0x41/0x2d0 [ocfs2]
  ? pagecache_get_page+0x30/0x200
  filemap_fault+0x12b/0x5c0
  ? recalc_sigpending+0x17/0x50
  ? __set_task_blocked+0x28/0x70
  ? __set_current_blocked+0x3d/0x60
  ocfs2_fault+0x29/0xb0 [ocfs2]
  __do_fault+0x1a/0xa0
  __handle_mm_fault+0xbe8/0x1090
  handle_mm_fault+0xaa/0x1f0
  __do_page_fault+0x235/0x4b0
  trace_do_page_fault+0x3c/0x110
  async_page_fault+0x28/0x30
 RIP: 0033:0x7fa75ded638e
 RSP: 002b:00007ffd6657db18 EFLAGS: 00010287
 RAX: 000055c7662fb700 RBX: 0000000000000001 RCX: 000055c7662fb700
 RDX: 0000000000001770 RSI: 00007fa75e909000 RDI: 000055c7662fb700
 RBP: 0000000000000003 R08: 000000000000000e R09: 0000000000000000
 R10: 0000000000000483 R11: 00007fa75ded61b0 R12: 00007fa75e90a770
 R13: 000000000000000e R14: 0000000000001770 R15: 0000000000000000
Fixes 1cce4df04f37 ("ocfs2: do not lock/unlock() inode DLM lock")
---
 fs/ocfs2/dlmglue.c | 9 +++++++++
 1 file changed, 9 insertions(+)
fs/ocfs2/dlmglue.c +5 -0
index 4689940..5193218 100644
@@ -2486,6 +2486,15 @@ int ocfs2_inode_lock_with_page(struct inode *inode,
 	ret = ocfs2_inode_lock_full(inode, ret_bh, ex, OCFS2_LOCK_NONBLOCK);
 	if (ret == -EAGAIN) {
 		unlock_page(page);
+		/*
+		 * If we can't get inode lock immediately, we should not return
+		 * directly here, since this will lead to a softlockup problem.
+		 * The method is to get a blocking lock and immediately unlock
+		 * before returning, this can avoid CPU resource waste due to
Quoted 8 lines

fs/ocfs2/dlmglue.c int ocfs2_inode_lock_with_page(struct inode *inode, · line 2500

Quoted 8 lines
fs/ocfs2/dlmglue.c +4 -0
+		 * lots of retries, and benefits fairness in getting lock.
+		 */
+		if (ocfs2_inode_lock(inode, ret_bh, ex) == 0)
+			ocfs2_inode_unlock(inode, ex);
 		ret = AOP_TRUNCATED_PAGE;
 	}
 

.

.

author
#6 lore raw
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines

Hi Gang,

You cleared my doubt. Should we handle the errno of ocfs2_inode_lock() or just use mlog_errno()?

Hi Jun, I think it is not necessary, since we just want to hold a while before get the DLM lock, we do not care about the result, since we will unlock immediately here.
In fact, this patch does NOT add new code, just revert the old patch 1cce4df04f37, and add more clear comments in the front of these two lines code.

Thanks
Gang

Quoted 150 lines

thanks,
Jun

Quoted 10 lines · Gang He

Hi Jun,

Quoted 6 lines
Quoted 1 line
Quoted 1 line

Hi Gang,

Thanks for your explaination, and I just have one more question. Could we use 'ocfs2_inode_lock' instead of 'ocfs2_inode_lock_full' to avoid -EAGAIN circularly?

No, please see the comments above the function

ocfs2_inode_lock_with_page(),

Quoted 134 lines

there will be probably a deadlock between tasks acquiring DLM locks while holding a page lock and the downconvert thread which blocks dlm lock acquiry while acquiring page locks.
Then, the OCFS2_LOCK_NONBLOCK flag was introduced as a workaround to avoid this case.

Thanks
Gang

Quoted 23 lines

thanks,
Jun

Quoted 11 lines · Gang He

Hi Jun,

Quoted 7 lines
Quoted 1 line
Quoted 1 line

Hi Gang,

Do you mean that too many retrys in loop cast losts of CPU-time and block page-fault interrupt? We should not add any delay in ocfs2_fault(), right? And I still feel a little confused why your method can solve this problem.

You can see the related code in function filemap_fault(), if ocfs2 fails to

read a page since

Quoted 1 line

it can not get a inode lock with non-block mode, the VFS layer code will

invoke ocfs2

Quoted 1 line

read page call back function circularly, this will lead to a softlockup

problem (like the below back trace).

Quoted 1 line

So, we should get a blocking lock to let the dlm lock to this node and also

can avoid CPU loop,

Quoted 100 lines
Quoted 1 line

second, base on my testing, the patch also can improve the efficiency in

case modifying the same

Quoted 1 line

file frequently from multiple nodes, since the lock acquisition chance is

more fair.

Quoted 1 line

In fact, the code was modified by a patch 1cce4df04f37 ("ocfs2: do not

lock/unlock() inode DLM lock"),

Quoted 1 line

before that patch, the code is the same, this patch can be considered to

revert that patch, except adding more

Quoted 92 lines

clear comments.

Thanks
Gang

Quoted 76 lines

thanks,
Jun

Quoted 71 lines · Gang He

If we can't get inode lock immediately in the function ocfs2_inode_lock_with_page() when reading a page, we should not return directly here, since this will lead to a softlockup problem. The method is to get a blocking lock and immediately unlock before returning, this can avoid CPU resource waste due to lots of retries, and benefits fairness in getting lock among multiple nodes, increase efficiency in case modifying the same file frequently from multiple nodes.
The softlockup problem looks like,

Kernel panic - not syncing: softlockup: hung tasks
CPU: 0 PID: 885 Comm: multi_mmap Tainted: G L 4.12.14-6.1-default #1
Hardware name: Bochs Bochs, BIOS Bochs 01/01/2011
Call Trace:
  <IRQ>
  dump_stack+0x5c/0x82
  panic+0xd5/0x21e
  watchdog_timer_fn+0x208/0x210
  ? watchdog_park_threads+0x70/0x70
  __hrtimer_run_queues+0xcc/0x200
  hrtimer_interrupt+0xa6/0x1f0
  smp_apic_timer_interrupt+0x34/0x50
  apic_timer_interrupt+0x96/0xa0
  </IRQ>
 RIP: 0010:unlock_page+0x17/0x30
 RSP: 0000:ffffaf154080bc88 EFLAGS: 00000246 ORIG_RAX: ffffffffffffff10
 RAX: dead000000000100 RBX: fffff21e009f5300 RCX: 0000000000000004
 RDX: dead0000000000ff RSI: 0000000000000202 RDI: fffff21e009f5300
 RBP: 0000000000000000 R08: 0000000000000000 R09: ffffaf154080bb00
 R10: ffffaf154080bc30 R11: 0000000000000040 R12: ffff993749a39518
 R13: 0000000000000000 R14: fffff21e009f5300 R15: fffff21e009f5300
  ocfs2_inode_lock_with_page+0x25/0x30 [ocfs2]
  ocfs2_readpage+0x41/0x2d0 [ocfs2]
  ? pagecache_get_page+0x30/0x200
  filemap_fault+0x12b/0x5c0
  ? recalc_sigpending+0x17/0x50
  ? __set_task_blocked+0x28/0x70
  ? __set_current_blocked+0x3d/0x60
  ocfs2_fault+0x29/0xb0 [ocfs2]
  __do_fault+0x1a/0xa0
  __handle_mm_fault+0xbe8/0x1090
  handle_mm_fault+0xaa/0x1f0
  __do_page_fault+0x235/0x4b0
  trace_do_page_fault+0x3c/0x110
  async_page_fault+0x28/0x30
 RIP: 0033:0x7fa75ded638e
 RSP: 002b:00007ffd6657db18 EFLAGS: 00010287
 RAX: 000055c7662fb700 RBX: 0000000000000001 RCX: 000055c7662fb700
 RDX: 0000000000001770 RSI: 00007fa75e909000 RDI: 000055c7662fb700
 RBP: 0000000000000003 R08: 000000000000000e R09: 0000000000000000
 R10: 0000000000000483 R11: 00007fa75ded61b0 R12: 00007fa75e90a770
 R13: 000000000000000e R14: 0000000000001770 R15: 0000000000000000
Fixes 1cce4df04f37 ("ocfs2: do not lock/unlock() inode DLM lock")
---
 fs/ocfs2/dlmglue.c | 9 +++++++++
 1 file changed, 9 insertions(+)
fs/ocfs2/dlmglue.c +5 -0
index 4689940..5193218 100644
@@ -2486,6 +2486,15 @@ int ocfs2_inode_lock_with_page(struct inode *inode,
 	ret = ocfs2_inode_lock_full(inode, ret_bh, ex, OCFS2_LOCK_NONBLOCK);
 	if (ret == -EAGAIN) {
 		unlock_page(page);
+		/*
+		 * If we can't get inode lock immediately, we should not return
+		 * directly here, since this will lead to a softlockup problem.
+		 * The method is to get a blocking lock and immediately unlock
+		 * before returning, this can avoid CPU resource waste due to
Quoted 8 lines

fs/ocfs2/dlmglue.c int ocfs2_inode_lock_with_page(struct inode *inode, · line 2500

Quoted 8 lines
fs/ocfs2/dlmglue.c +4 -0
+		 * lots of retries, and benefits fairness in getting lock.
+		 */
+		if (ocfs2_inode_lock(inode, ret_bh, ex) == 0)
+			ocfs2_inode_unlock(inode, ex);
 		ret = AOP_TRUNCATED_PAGE;
 	}
 

.

.

Reviewed-by
#7 lore raw

Hi Gang,

This patch looks good to me.

thanks,
Jun

Quoted 8 lines · Gang He
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines

Hi Gang,

You cleared my doubt. Should we handle the errno of ocfs2_inode_lock() or just use mlog_errno()?

Quoted 129 lines

Hi Jun, I think it is not necessary, since we just want to hold a while before get the DLM lock, we do not care about the result, since we will unlock immediately here.
In fact, this patch does NOT add new code, just revert the old patch 1cce4df04f37, and add more clear comments in the front of these two lines code.

Thanks
Gang

Quoted 121 lines

thanks,
Jun

Quoted 10 lines · Gang He

Hi Jun,

Quoted 6 lines
Quoted 1 line
Quoted 1 line

Hi Gang,

Thanks for your explaination, and I just have one more question. Could we use 'ocfs2_inode_lock' instead of 'ocfs2_inode_lock_full' to avoid -EAGAIN circularly?

No, please see the comments above the function

ocfs2_inode_lock_with_page(),

Quoted 105 lines

there will be probably a deadlock between tasks acquiring DLM locks while holding a page lock and the downconvert thread which blocks dlm lock acquiry while acquiring page locks.
Then, the OCFS2_LOCK_NONBLOCK flag was introduced as a workaround to avoid this case.

Thanks
Gang

Quoted 96 lines

thanks,
Jun

Quoted 11 lines · Gang He

Hi Jun,

Quoted 7 lines
Quoted 1 line
Quoted 1 line

Hi Gang,

Do you mean that too many retrys in loop cast losts of CPU-time and block page-fault interrupt? We should not add any delay in ocfs2_fault(), right? And I still feel a little confused why your method can solve this problem.

You can see the related code in function filemap_fault(), if ocfs2 fails to

read a page since

Quoted 1 line

it can not get a inode lock with non-block mode, the VFS layer code will

invoke ocfs2

Quoted 1 line

read page call back function circularly, this will lead to a softlockup

problem (like the below back trace).

Quoted 1 line

So, we should get a blocking lock to let the dlm lock to this node and also

can avoid CPU loop,

Quoted 1 line

second, base on my testing, the patch also can improve the efficiency in

case modifying the same

Quoted 1 line

file frequently from multiple nodes, since the lock acquisition chance is

more fair.

Quoted 1 line

In fact, the code was modified by a patch 1cce4df04f37 ("ocfs2: do not

lock/unlock() inode DLM lock"),

Quoted 1 line

before that patch, the code is the same, this patch can be considered to

revert that patch, except adding more

Quoted 65 lines

clear comments.

Thanks
Gang

Quoted 59 lines

thanks,
Jun

Quoted 54 lines · Gang He

If we can't get inode lock immediately in the function ocfs2_inode_lock_with_page() when reading a page, we should not return directly here, since this will lead to a softlockup problem. The method is to get a blocking lock and immediately unlock before returning, this can avoid CPU resource waste due to lots of retries, and benefits fairness in getting lock among multiple nodes, increase efficiency in case modifying the same file frequently from multiple nodes.
The softlockup problem looks like,

Kernel panic - not syncing: softlockup: hung tasks
CPU: 0 PID: 885 Comm: multi_mmap Tainted: G L 4.12.14-6.1-default #1
Hardware name: Bochs Bochs, BIOS Bochs 01/01/2011
Call Trace:
  <IRQ>
  dump_stack+0x5c/0x82
  panic+0xd5/0x21e
  watchdog_timer_fn+0x208/0x210
  ? watchdog_park_threads+0x70/0x70
  __hrtimer_run_queues+0xcc/0x200
  hrtimer_interrupt+0xa6/0x1f0
  smp_apic_timer_interrupt+0x34/0x50
  apic_timer_interrupt+0x96/0xa0
  </IRQ>
 RIP: 0010:unlock_page+0x17/0x30
 RSP: 0000:ffffaf154080bc88 EFLAGS: 00000246 ORIG_RAX: ffffffffffffff10
 RAX: dead000000000100 RBX: fffff21e009f5300 RCX: 0000000000000004
 RDX: dead0000000000ff RSI: 0000000000000202 RDI: fffff21e009f5300
 RBP: 0000000000000000 R08: 0000000000000000 R09: ffffaf154080bb00
 R10: ffffaf154080bc30 R11: 0000000000000040 R12: ffff993749a39518
 R13: 0000000000000000 R14: fffff21e009f5300 R15: fffff21e009f5300
  ocfs2_inode_lock_with_page+0x25/0x30 [ocfs2]
  ocfs2_readpage+0x41/0x2d0 [ocfs2]
  ? pagecache_get_page+0x30/0x200
  filemap_fault+0x12b/0x5c0
  ? recalc_sigpending+0x17/0x50
  ? __set_task_blocked+0x28/0x70
  ? __set_current_blocked+0x3d/0x60
  ocfs2_fault+0x29/0xb0 [ocfs2]
  __do_fault+0x1a/0xa0
  __handle_mm_fault+0xbe8/0x1090
  handle_mm_fault+0xaa/0x1f0
  __do_page_fault+0x235/0x4b0
  trace_do_page_fault+0x3c/0x110
  async_page_fault+0x28/0x30
 RIP: 0033:0x7fa75ded638e
 RSP: 002b:00007ffd6657db18 EFLAGS: 00010287
 RAX: 000055c7662fb700 RBX: 0000000000000001 RCX: 000055c7662fb700
 RDX: 0000000000001770 RSI: 00007fa75e909000 RDI: 000055c7662fb700
 RBP: 0000000000000003 R08: 000000000000000e R09: 0000000000000000
 R10: 0000000000000483 R11: 00007fa75ded61b0 R12: 00007fa75e90a770
 R13: 000000000000000e R14: 0000000000001770 R15: 0000000000000000
Fixes 1cce4df04f37 ("ocfs2: do not lock/unlock() inode DLM lock")
Quoted 31 lines
Quoted 27 lines
Quoted 27 lines
Quoted 27 lines
Quoted 27 lines
Quoted 17 lines
Quoted 17 lines
---
 fs/ocfs2/dlmglue.c | 9 +++++++++
 1 file changed, 9 insertions(+)
fs/ocfs2/dlmglue.c +5 -0
index 4689940..5193218 100644
@@ -2486,6 +2486,15 @@ int ocfs2_inode_lock_with_page(struct inode *inode,
 	ret = ocfs2_inode_lock_full(inode, ret_bh, ex, OCFS2_LOCK_NONBLOCK);
 	if (ret == -EAGAIN) {
 		unlock_page(page);
+		/*
+		 * If we can't get inode lock immediately, we should not return
+		 * directly here, since this will lead to a softlockup problem.
+		 * The method is to get a blocking lock and immediately unlock
+		 * before returning, this can avoid CPU resource waste due to
Quoted 8 lines

fs/ocfs2/dlmglue.c int ocfs2_inode_lock_with_page(struct inode *inode, · line 2500

Quoted 8 lines
fs/ocfs2/dlmglue.c +4 -0
+		 * lots of retries, and benefits fairness in getting lock.
+		 */
+		if (ocfs2_inode_lock(inode, ret_bh, ex) == 0)
+			ocfs2_inode_unlock(inode, ex);
 		ret = AOP_TRUNCATED_PAGE;
 	}
 

.

Quoted 2 lines
Quoted 2 lines

.

.

#8 lore raw
In reply to Gang He

Hi Gang,

Quoted 6 lines · Gang He

Hi Jun,

Quoted 3 lines
Quoted 1 line
Quoted 1 line

Hi Gang,

Quoted 8 lines
Quoted 4 lines

Do you mean that too many retrys in loop cast losts of CPU-time and block page-fault interrupt? We should not add any delay in ocfs2_fault(), right? And I still feel a little confused why your method can solve this problem.

You can see the related code in function filemap_fault(), if ocfs2 fails to read a page since it can not get a inode lock with non-block mode, the VFS layer code will invoke ocfs2
read page call back function circularly, this will lead to a softlockup problem (like the below back trace). So, we should get a blocking lock to let the dlm lock to this node and also can avoid CPU loop,

Can we use 'cond_resched()' to allow the thread to release the CPU temperately for solving this softlockup?

Quoted 5 lines

second, base on my testing, the patch also can improve the efficiency in case modifying the same file frequently from multiple nodes, since the lock acquisition chance is more fair.
In fact, the code was modified by a patch 1cce4df04f37 ("ocfs2: do not lock/unlock() inode DLM lock"), before that patch, the code is the same, this patch can be considered to revert that patch, except adding more clear comments.

In patch 1cce4df04f37 ("ocfs2: do not lock/unlock() inode DLM lock"), Goldwyn says blocking lock and unlock will only make the performance worse where contention over the locks is high, which is the opposite of your described above. IMO, blocking lock and unlock here is indeed unnecessary.

Thanks,
Alex

Quoted 97 lines

Thanks
Gang

Quoted 76 lines

thanks,
Jun

Quoted 71 lines · Gang He

If we can't get inode lock immediately in the function ocfs2_inode_lock_with_page() when reading a page, we should not return directly here, since this will lead to a softlockup problem. The method is to get a blocking lock and immediately unlock before returning, this can avoid CPU resource waste due to lots of retries, and benefits fairness in getting lock among multiple nodes, increase efficiency in case modifying the same file frequently from multiple nodes.
The softlockup problem looks like,

Kernel panic - not syncing: softlockup: hung tasks
CPU: 0 PID: 885 Comm: multi_mmap Tainted: G L 4.12.14-6.1-default #1
Hardware name: Bochs Bochs, BIOS Bochs 01/01/2011
Call Trace:
  <IRQ>
  dump_stack+0x5c/0x82
  panic+0xd5/0x21e
  watchdog_timer_fn+0x208/0x210
  ? watchdog_park_threads+0x70/0x70
  __hrtimer_run_queues+0xcc/0x200
  hrtimer_interrupt+0xa6/0x1f0
  smp_apic_timer_interrupt+0x34/0x50
  apic_timer_interrupt+0x96/0xa0
  </IRQ>
 RIP: 0010:unlock_page+0x17/0x30
 RSP: 0000:ffffaf154080bc88 EFLAGS: 00000246 ORIG_RAX: ffffffffffffff10
 RAX: dead000000000100 RBX: fffff21e009f5300 RCX: 0000000000000004
 RDX: dead0000000000ff RSI: 0000000000000202 RDI: fffff21e009f5300
 RBP: 0000000000000000 R08: 0000000000000000 R09: ffffaf154080bb00
 R10: ffffaf154080bc30 R11: 0000000000000040 R12: ffff993749a39518
 R13: 0000000000000000 R14: fffff21e009f5300 R15: fffff21e009f5300
  ocfs2_inode_lock_with_page+0x25/0x30 [ocfs2]
  ocfs2_readpage+0x41/0x2d0 [ocfs2]
  ? pagecache_get_page+0x30/0x200
  filemap_fault+0x12b/0x5c0
  ? recalc_sigpending+0x17/0x50
  ? __set_task_blocked+0x28/0x70
  ? __set_current_blocked+0x3d/0x60
  ocfs2_fault+0x29/0xb0 [ocfs2]
  __do_fault+0x1a/0xa0
  __handle_mm_fault+0xbe8/0x1090
  handle_mm_fault+0xaa/0x1f0
  __do_page_fault+0x235/0x4b0
  trace_do_page_fault+0x3c/0x110
  async_page_fault+0x28/0x30
 RIP: 0033:0x7fa75ded638e
 RSP: 002b:00007ffd6657db18 EFLAGS: 00010287
 RAX: 000055c7662fb700 RBX: 0000000000000001 RCX: 000055c7662fb700
 RDX: 0000000000001770 RSI: 00007fa75e909000 RDI: 000055c7662fb700
 RBP: 0000000000000003 R08: 000000000000000e R09: 0000000000000000
 R10: 0000000000000483 R11: 00007fa75ded61b0 R12: 00007fa75e90a770
 R13: 000000000000000e R14: 0000000000001770 R15: 0000000000000000
Fixes 1cce4df04f37 ("ocfs2: do not lock/unlock() inode DLM lock")
---
 fs/ocfs2/dlmglue.c | 9 +++++++++
 1 file changed, 9 insertions(+)
fs/ocfs2/dlmglue.c +5 -0
index 4689940..5193218 100644
@@ -2486,6 +2486,15 @@ int ocfs2_inode_lock_with_page(struct inode *inode,
 	ret = ocfs2_inode_lock_full(inode, ret_bh, ex, OCFS2_LOCK_NONBLOCK);
 	if (ret == -EAGAIN) {
 		unlock_page(page);
+		/*
+		 * If we can't get inode lock immediately, we should not return
+		 * directly here, since this will lead to a softlockup problem.
+		 * The method is to get a blocking lock and immediately unlock
+		 * before returning, this can avoid CPU resource waste due to
Quoted 8 lines

fs/ocfs2/dlmglue.c int ocfs2_inode_lock_with_page(struct inode *inode, · line 2500

Quoted 8 lines
fs/ocfs2/dlmglue.c +4 -0
+		 * lots of retries, and benefits fairness in getting lock.
+		 */
+		if (ocfs2_inode_lock(inode, ret_bh, ex) == 0)
+			ocfs2_inode_unlock(inode, ex);
 		ret = AOP_TRUNCATED_PAGE;
 	}
 

_______________________________________________
Ocfs2-devel mailing list
Ocfs2-devel at oss.oracle.com
https://oss.oracle.com/mailman/listinfo/ocfs2-devel

.

author
#9 lore raw

Hi Alex,

Quoted 16 lines
Quoted 1 line
Quoted 1 line

Hi Gang,

Quoted 11 lines · Gang He

Hi Jun,

Quoted 7 lines
Quoted 1 line
Quoted 1 line

Hi Gang,

Do you mean that too many retrys in loop cast losts of CPU-time and block page-fault interrupt? We should not add any delay in ocfs2_fault(), right? And I still feel a little confused why your method can solve this problem.

You can see the related code in function filemap_fault(), if ocfs2 fails to

read a page since

Quoted 8 lines
Quoted 1 line

it can not get a inode lock with non-block mode, the VFS layer code will

invoke ocfs2

Quoted 1 line

read page call back function circularly, this will lead to a softlockup

problem (like the below back trace).

Quoted 1 line

So, we should get a blocking lock to let the dlm lock to this node and also

can avoid CPU loop,
Can we use 'cond_resched()' to allow the thread to release the CPU temperately for solving this softlockup?

Yes, we can use cond_resched() function to avoid this softlockup.
In fact, if the kernel is configured with CONFIG_PREEMPT=y, this softlockup does not happen since the kernel can help.
But, this way still leads to CPU resource waste, CPU usage can reach about 80% - 100% when
multiple nodes read/write/mmap-access the same file concurrently, and more, the read/write/mmap-access
speed is more lower (50% decrease).
Why?
Because we need to get DLM lock for each node, before one node gets DLM lock, another node has
to down-convert this DLM lock, that means flushing the memory data to the disk before DLM lock down-conversion.
this disk IO operation is very slow compared with CPU cycle, that means the node which want to get DLM lock,
will do lots of reties before another node complete down-converting this DLM lock, actual, these retries do not make
sense, just waste CPU cycle.
So, if we add a blocking lock/unlock here, we will avoid these unnecessary reties, especially in case slow-speed disk and more ocfs2 nodes(>=3). I did the ocfs2 test case (multi_mmap in multiple_run.sh), after applied this patch, the CPU rate on each node was about 40%-50%, and the test case execution time reduced by half.
the full command is as below,
multiple_run.sh -i eth0 -k ~/linux-4.4.21-69.tar.gz -o ~/ocfs2mullog -C hacluster -s pcmk -n nd1,nd2,nd3 -d /dev/sda1 -b 4096 -c 32768 -t multi_mmap /mnt/shared the shared storage is a iscsi disk.

Thanks
Gang

Quoted 115 lines
Quoted 2 lines

second, base on my testing, the patch also can improve the efficiency in

case modifying the same

Quoted 1 line

file frequently from multiple nodes, since the lock acquisition chance is

more fair.

Quoted 1 line

In fact, the code was modified by a patch 1cce4df04f37 ("ocfs2: do not

lock/unlock() inode DLM lock"),

Quoted 1 line

before that patch, the code is the same, this patch can be considered to

revert that patch, except adding more

Quoted 1 line

clear comments.

In patch 1cce4df04f37 ("ocfs2: do not lock/unlock() inode DLM lock"), Goldwyn says blocking lock and unlock will only make
the performance worse where contention over the locks is high, which is the opposite of your described above.
IMO, blocking lock and unlock here is indeed unnecessary.

Thanks,
Alex

Quoted 97 lines

Thanks
Gang

Quoted 76 lines

thanks,
Jun

Quoted 71 lines · Gang He

If we can't get inode lock immediately in the function ocfs2_inode_lock_with_page() when reading a page, we should not return directly here, since this will lead to a softlockup problem. The method is to get a blocking lock and immediately unlock before returning, this can avoid CPU resource waste due to lots of retries, and benefits fairness in getting lock among multiple nodes, increase efficiency in case modifying the same file frequently from multiple nodes.
The softlockup problem looks like,

Kernel panic - not syncing: softlockup: hung tasks
CPU: 0 PID: 885 Comm: multi_mmap Tainted: G L 4.12.14-6.1-default #1
Hardware name: Bochs Bochs, BIOS Bochs 01/01/2011
Call Trace:
  <IRQ>
  dump_stack+0x5c/0x82
  panic+0xd5/0x21e
  watchdog_timer_fn+0x208/0x210
  ? watchdog_park_threads+0x70/0x70
  __hrtimer_run_queues+0xcc/0x200
  hrtimer_interrupt+0xa6/0x1f0
  smp_apic_timer_interrupt+0x34/0x50
  apic_timer_interrupt+0x96/0xa0
  </IRQ>
 RIP: 0010:unlock_page+0x17/0x30
 RSP: 0000:ffffaf154080bc88 EFLAGS: 00000246 ORIG_RAX: ffffffffffffff10
 RAX: dead000000000100 RBX: fffff21e009f5300 RCX: 0000000000000004
 RDX: dead0000000000ff RSI: 0000000000000202 RDI: fffff21e009f5300
 RBP: 0000000000000000 R08: 0000000000000000 R09: ffffaf154080bb00
 R10: ffffaf154080bc30 R11: 0000000000000040 R12: ffff993749a39518
 R13: 0000000000000000 R14: fffff21e009f5300 R15: fffff21e009f5300
  ocfs2_inode_lock_with_page+0x25/0x30 [ocfs2]
  ocfs2_readpage+0x41/0x2d0 [ocfs2]
  ? pagecache_get_page+0x30/0x200
  filemap_fault+0x12b/0x5c0
  ? recalc_sigpending+0x17/0x50
  ? __set_task_blocked+0x28/0x70
  ? __set_current_blocked+0x3d/0x60
  ocfs2_fault+0x29/0xb0 [ocfs2]
  __do_fault+0x1a/0xa0
  __handle_mm_fault+0xbe8/0x1090
  handle_mm_fault+0xaa/0x1f0
  __do_page_fault+0x235/0x4b0
  trace_do_page_fault+0x3c/0x110
  async_page_fault+0x28/0x30
 RIP: 0033:0x7fa75ded638e
 RSP: 002b:00007ffd6657db18 EFLAGS: 00010287
 RAX: 000055c7662fb700 RBX: 0000000000000001 RCX: 000055c7662fb700
 RDX: 0000000000001770 RSI: 00007fa75e909000 RDI: 000055c7662fb700
 RBP: 0000000000000003 R08: 000000000000000e R09: 0000000000000000
 R10: 0000000000000483 R11: 00007fa75ded61b0 R12: 00007fa75e90a770
 R13: 000000000000000e R14: 0000000000001770 R15: 0000000000000000
Fixes 1cce4df04f37 ("ocfs2: do not lock/unlock() inode DLM lock")
---
 fs/ocfs2/dlmglue.c | 9 +++++++++
 1 file changed, 9 insertions(+)
fs/ocfs2/dlmglue.c +5 -0
index 4689940..5193218 100644
@@ -2486,6 +2486,15 @@ int ocfs2_inode_lock_with_page(struct inode *inode,
 	ret = ocfs2_inode_lock_full(inode, ret_bh, ex, OCFS2_LOCK_NONBLOCK);
 	if (ret == -EAGAIN) {
 		unlock_page(page);
+		/*
+		 * If we can't get inode lock immediately, we should not return
+		 * directly here, since this will lead to a softlockup problem.
+		 * The method is to get a blocking lock and immediately unlock
+		 * before returning, this can avoid CPU resource waste due to
Quoted 8 lines

fs/ocfs2/dlmglue.c int ocfs2_inode_lock_with_page(struct inode *inode, · line 2500

Quoted 8 lines
fs/ocfs2/dlmglue.c +4 -0
+		 * lots of retries, and benefits fairness in getting lock.
+		 */
+		if (ocfs2_inode_lock(inode, ret_bh, ex) == 0)
+			ocfs2_inode_unlock(inode, ex);
 		ret = AOP_TRUNCATED_PAGE;
 	}
 

_______________________________________________
Ocfs2-devel mailing list
Ocfs2-devel at oss.oracle.com
https://oss.oracle.com/mailman/listinfo/ocfs2-devel

.

#10 lore raw
Quoted 36 lines · Gang He

Hi Alex,

Quoted 16 lines
Quoted 1 line
Quoted 1 line

Hi Gang,

Quoted 11 lines · Gang He

Hi Jun,

Quoted 7 lines
Quoted 1 line
Quoted 1 line

Hi Gang,

Do you mean that too many retrys in loop cast losts of CPU-time and block page-fault interrupt? We should not add any delay in ocfs2_fault(), right? And I still feel a little confused why your method can solve this problem.

You can see the related code in function filemap_fault(), if ocfs2 fails to

read a page since

Quoted 8 lines
Quoted 1 line

it can not get a inode lock with non-block mode, the VFS layer code will

invoke ocfs2

Quoted 1 line

read page call back function circularly, this will lead to a softlockup

problem (like the below back trace).

Quoted 1 line

So, we should get a blocking lock to let the dlm lock to this node and also

can avoid CPU loop,
Can we use 'cond_resched()' to allow the thread to release the CPU temperately for solving this softlockup?

Yes, we can use cond_resched() function to avoid this softlockup.
In fact, if the kernel is configured with CONFIG_PREEMPT=y, this softlockup does not happen since the kernel can help. But, this way still leads to CPU resource waste, CPU usage can reach about 80% - 100% when
multiple nodes read/write/mmap-access the same file concurrently, and more, the read/write/mmap-access speed is more lower (50% decrease).
Why?
Because we need to get DLM lock for each node, before one node gets DLM lock, another node has
to down-convert this DLM lock, that means flushing the memory data to the disk before DLM lock down-conversion. this disk IO operation is very slow compared with CPU cycle, that means the node which want to get DLM lock,

Quoted 9 lines

will do lots of reties before another node complete down-converting this DLM lock, actual, these retries do not make
sense, just waste CPU cycle.
So, if we add a blocking lock/unlock here, we will avoid these unnecessary reties, especially in case slow-speed disk and more ocfs2 nodes(>=3). I did the ocfs2 test case (multi_mmap in multiple_run.sh), after applied this patch, the CPU rate on each node was about 40%-50%, and the test case execution time reduced by half.
the full command is as below,
multiple_run.sh -i eth0 -k ~/linux-4.4.21-69.tar.gz -o ~/ocfs2mullog -C hacluster -s pcmk -n nd1,nd2,nd3 -d /dev/sda1 -b 4096 -c 32768 -t multi_mmap /mnt/shared the shared storage is a iscsi disk.

OK, I think it is more better if you can add you test method and result in change log.

Thanks,
Alex

Quoted 121 lines

Thanks
Gang

Quoted 10 lines
Quoted 2 lines

second, base on my testing, the patch also can improve the efficiency in

case modifying the same

Quoted 1 line

file frequently from multiple nodes, since the lock acquisition chance is

more fair.

Quoted 1 line

In fact, the code was modified by a patch 1cce4df04f37 ("ocfs2: do not

lock/unlock() inode DLM lock"),

Quoted 1 line

before that patch, the code is the same, this patch can be considered to

revert that patch, except adding more

Quoted 1 line

clear comments.

Quoted 105 lines

In patch 1cce4df04f37 ("ocfs2: do not lock/unlock() inode DLM lock"), Goldwyn says blocking lock and unlock will only make
the performance worse where contention over the locks is high, which is the opposite of your described above.
IMO, blocking lock and unlock here is indeed unnecessary.

Thanks,
Alex

Quoted 97 lines

Thanks
Gang

Quoted 76 lines

thanks,
Jun

Quoted 71 lines · Gang He

If we can't get inode lock immediately in the function ocfs2_inode_lock_with_page() when reading a page, we should not return directly here, since this will lead to a softlockup problem. The method is to get a blocking lock and immediately unlock before returning, this can avoid CPU resource waste due to lots of retries, and benefits fairness in getting lock among multiple nodes, increase efficiency in case modifying the same file frequently from multiple nodes.
The softlockup problem looks like,

Kernel panic - not syncing: softlockup: hung tasks
CPU: 0 PID: 885 Comm: multi_mmap Tainted: G L 4.12.14-6.1-default #1
Hardware name: Bochs Bochs, BIOS Bochs 01/01/2011
Call Trace:
  <IRQ>
  dump_stack+0x5c/0x82
  panic+0xd5/0x21e
  watchdog_timer_fn+0x208/0x210
  ? watchdog_park_threads+0x70/0x70
  __hrtimer_run_queues+0xcc/0x200
  hrtimer_interrupt+0xa6/0x1f0
  smp_apic_timer_interrupt+0x34/0x50
  apic_timer_interrupt+0x96/0xa0
  </IRQ>
 RIP: 0010:unlock_page+0x17/0x30
 RSP: 0000:ffffaf154080bc88 EFLAGS: 00000246 ORIG_RAX: ffffffffffffff10
 RAX: dead000000000100 RBX: fffff21e009f5300 RCX: 0000000000000004
 RDX: dead0000000000ff RSI: 0000000000000202 RDI: fffff21e009f5300
 RBP: 0000000000000000 R08: 0000000000000000 R09: ffffaf154080bb00
 R10: ffffaf154080bc30 R11: 0000000000000040 R12: ffff993749a39518
 R13: 0000000000000000 R14: fffff21e009f5300 R15: fffff21e009f5300
  ocfs2_inode_lock_with_page+0x25/0x30 [ocfs2]
  ocfs2_readpage+0x41/0x2d0 [ocfs2]
  ? pagecache_get_page+0x30/0x200
  filemap_fault+0x12b/0x5c0
  ? recalc_sigpending+0x17/0x50
  ? __set_task_blocked+0x28/0x70
  ? __set_current_blocked+0x3d/0x60
  ocfs2_fault+0x29/0xb0 [ocfs2]
  __do_fault+0x1a/0xa0
  __handle_mm_fault+0xbe8/0x1090
  handle_mm_fault+0xaa/0x1f0
  __do_page_fault+0x235/0x4b0
  trace_do_page_fault+0x3c/0x110
  async_page_fault+0x28/0x30
 RIP: 0033:0x7fa75ded638e
 RSP: 002b:00007ffd6657db18 EFLAGS: 00010287
 RAX: 000055c7662fb700 RBX: 0000000000000001 RCX: 000055c7662fb700
 RDX: 0000000000001770 RSI: 00007fa75e909000 RDI: 000055c7662fb700
 RBP: 0000000000000003 R08: 000000000000000e R09: 0000000000000000
 R10: 0000000000000483 R11: 00007fa75ded61b0 R12: 00007fa75e90a770
 R13: 000000000000000e R14: 0000000000001770 R15: 0000000000000000
Fixes 1cce4df04f37 ("ocfs2: do not lock/unlock() inode DLM lock")
---
 fs/ocfs2/dlmglue.c | 9 +++++++++
 1 file changed, 9 insertions(+)
fs/ocfs2/dlmglue.c +5 -0
index 4689940..5193218 100644
@@ -2486,6 +2486,15 @@ int ocfs2_inode_lock_with_page(struct inode *inode,
 	ret = ocfs2_inode_lock_full(inode, ret_bh, ex, OCFS2_LOCK_NONBLOCK);
 	if (ret == -EAGAIN) {
 		unlock_page(page);
+		/*
+		 * If we can't get inode lock immediately, we should not return
+		 * directly here, since this will lead to a softlockup problem.
+		 * The method is to get a blocking lock and immediately unlock
+		 * before returning, this can avoid CPU resource waste due to
Quoted 8 lines

fs/ocfs2/dlmglue.c int ocfs2_inode_lock_with_page(struct inode *inode, · line 2500

Quoted 8 lines
fs/ocfs2/dlmglue.c +4 -0
+		 * lots of retries, and benefits fairness in getting lock.
+		 */
+		if (ocfs2_inode_lock(inode, ret_bh, ex) == 0)
+			ocfs2_inode_unlock(inode, ex);
 		ret = AOP_TRUNCATED_PAGE;
 	}
 

_______________________________________________
Ocfs2-devel mailing list
Ocfs2-devel at oss.oracle.com
https://oss.oracle.com/mailman/listinfo/ocfs2-devel

.

.

Reviewed-by on v1 1/1
#11 lore raw
In reply to Gang He

Hi Gang,
I like your fix.
It looks good to me.

Quoted 52 lines · Gang He

If we can't get inode lock immediately in the function ocfs2_inode_lock_with_page() when reading a page, we should not return directly here, since this will lead to a softlockup problem. The method is to get a blocking lock and immediately unlock before returning, this can avoid CPU resource waste due to lots of retries, and benefits fairness in getting lock among multiple nodes, increase efficiency in case modifying the same file frequently from multiple nodes.
The softlockup problem looks like,

Kernel panic - not syncing: softlockup: hung tasks
CPU: 0 PID: 885 Comm: multi_mmap Tainted: G L 4.12.14-6.1-default #1
Hardware name: Bochs Bochs, BIOS Bochs 01/01/2011
Call Trace:
   <IRQ>
   dump_stack+0x5c/0x82
   panic+0xd5/0x21e
   watchdog_timer_fn+0x208/0x210
   ? watchdog_park_threads+0x70/0x70
   __hrtimer_run_queues+0xcc/0x200
   hrtimer_interrupt+0xa6/0x1f0
   smp_apic_timer_interrupt+0x34/0x50
   apic_timer_interrupt+0x96/0xa0
   </IRQ>
  RIP: 0010:unlock_page+0x17/0x30
  RSP: 0000:ffffaf154080bc88 EFLAGS: 00000246 ORIG_RAX: ffffffffffffff10
  RAX: dead000000000100 RBX: fffff21e009f5300 RCX: 0000000000000004
  RDX: dead0000000000ff RSI: 0000000000000202 RDI: fffff21e009f5300
  RBP: 0000000000000000 R08: 0000000000000000 R09: ffffaf154080bb00
  R10: ffffaf154080bc30 R11: 0000000000000040 R12: ffff993749a39518
  R13: 0000000000000000 R14: fffff21e009f5300 R15: fffff21e009f5300
   ocfs2_inode_lock_with_page+0x25/0x30 [ocfs2]
   ocfs2_readpage+0x41/0x2d0 [ocfs2]
   ? pagecache_get_page+0x30/0x200
   filemap_fault+0x12b/0x5c0
   ? recalc_sigpending+0x17/0x50
   ? __set_task_blocked+0x28/0x70
   ? __set_current_blocked+0x3d/0x60
   ocfs2_fault+0x29/0xb0 [ocfs2]
   __do_fault+0x1a/0xa0
   __handle_mm_fault+0xbe8/0x1090
   handle_mm_fault+0xaa/0x1f0
   __do_page_fault+0x235/0x4b0
   trace_do_page_fault+0x3c/0x110
   async_page_fault+0x28/0x30
  RIP: 0033:0x7fa75ded638e
  RSP: 002b:00007ffd6657db18 EFLAGS: 00010287
  RAX: 000055c7662fb700 RBX: 0000000000000001 RCX: 000055c7662fb700
  RDX: 0000000000001770 RSI: 00007fa75e909000 RDI: 000055c7662fb700
  RBP: 0000000000000003 R08: 000000000000000e R09: 0000000000000000
  R10: 0000000000000483 R11: 00007fa75ded61b0 R12: 00007fa75e90a770
  R13: 000000000000000e R14: 0000000000001770 R15: 0000000000000000
Quoted 2 lines
Fixes 1cce4df04f37 ("ocfs2: do not lock/unlock() inode DLM lock")
Quoted 25 lines
---
  fs/ocfs2/dlmglue.c | 9 +++++++++
  1 file changed, 9 insertions(+)
fs/ocfs2/dlmglue.c +9 -0
index 4689940..5193218 100644
@@ -2486,6 +2486,15 @@ int ocfs2_inode_lock_with_page(struct inode *inode,
  	ret = ocfs2_inode_lock_full(inode, ret_bh, ex, OCFS2_LOCK_NONBLOCK);
  	if (ret == -EAGAIN) {
  		unlock_page(page);
+		/*
+		 * If we can't get inode lock immediately, we should not return
+		 * directly here, since this will lead to a softlockup problem.
+		 * The method is to get a blocking lock and immediately unlock
+		 * before returning, this can avoid CPU resource waste due to
+		 * lots of retries, and benefits fairness in getting lock.
+		 */
+		if (ocfs2_inode_lock(inode, ret_bh, ex) == 0)
+			ocfs2_inode_unlock(inode, ex);
  		ret = AOP_TRUNCATED_PAGE;
  	}
 
Reviewed-by on v1 1/1
#12 lore raw
In reply to Gang He

Hi,

Quoted 52 lines · Gang He

If we can't get inode lock immediately in the function ocfs2_inode_lock_with_page() when reading a page, we should not return directly here, since this will lead to a softlockup problem. The method is to get a blocking lock and immediately unlock before returning, this can avoid CPU resource waste due to lots of retries, and benefits fairness in getting lock among multiple nodes, increase efficiency in case modifying the same file frequently from multiple nodes.
The softlockup problem looks like,

Kernel panic - not syncing: softlockup: hung tasks
CPU: 0 PID: 885 Comm: multi_mmap Tainted: G L 4.12.14-6.1-default #1
Hardware name: Bochs Bochs, BIOS Bochs 01/01/2011
Call Trace:
   <IRQ>
   dump_stack+0x5c/0x82
   panic+0xd5/0x21e
   watchdog_timer_fn+0x208/0x210
   ? watchdog_park_threads+0x70/0x70
   __hrtimer_run_queues+0xcc/0x200
   hrtimer_interrupt+0xa6/0x1f0
   smp_apic_timer_interrupt+0x34/0x50
   apic_timer_interrupt+0x96/0xa0
   </IRQ>
  RIP: 0010:unlock_page+0x17/0x30
  RSP: 0000:ffffaf154080bc88 EFLAGS: 00000246 ORIG_RAX: ffffffffffffff10
  RAX: dead000000000100 RBX: fffff21e009f5300 RCX: 0000000000000004
  RDX: dead0000000000ff RSI: 0000000000000202 RDI: fffff21e009f5300
  RBP: 0000000000000000 R08: 0000000000000000 R09: ffffaf154080bb00
  R10: ffffaf154080bc30 R11: 0000000000000040 R12: ffff993749a39518
  R13: 0000000000000000 R14: fffff21e009f5300 R15: fffff21e009f5300
   ocfs2_inode_lock_with_page+0x25/0x30 [ocfs2]
   ocfs2_readpage+0x41/0x2d0 [ocfs2]
   ? pagecache_get_page+0x30/0x200
   filemap_fault+0x12b/0x5c0
   ? recalc_sigpending+0x17/0x50
   ? __set_task_blocked+0x28/0x70
   ? __set_current_blocked+0x3d/0x60
   ocfs2_fault+0x29/0xb0 [ocfs2]
   __do_fault+0x1a/0xa0
   __handle_mm_fault+0xbe8/0x1090
   handle_mm_fault+0xaa/0x1f0
   __do_page_fault+0x235/0x4b0
   trace_do_page_fault+0x3c/0x110
   async_page_fault+0x28/0x30
  RIP: 0033:0x7fa75ded638e
  RSP: 002b:00007ffd6657db18 EFLAGS: 00010287
  RAX: 000055c7662fb700 RBX: 0000000000000001 RCX: 000055c7662fb700
  RDX: 0000000000001770 RSI: 00007fa75e909000 RDI: 000055c7662fb700
  RBP: 0000000000000003 R08: 000000000000000e R09: 0000000000000000
  R10: 0000000000000483 R11: 00007fa75ded61b0 R12: 00007fa75e90a770
  R13: 000000000000000e R14: 0000000000001770 R15: 0000000000000000
Quoted 2 lines
Fixes 1cce4df04f37 ("ocfs2: do not lock/unlock() inode DLM lock")

On most linux server, CONFIG_PREEMPT is not set for better system-wide throughtput.
The long-time retry logic for getting page lock and inode lock can easily cause softlock,
resulting in real time task like corosync when using pcmk stack cannot be scheduled
on time.

When multiple nodes concurrently write the same file, the performance cannot be good
anyway, and it's also less possibility.

The trick for avoiding the busy loop looks good to me.

Reviewed-by zren at suse.com

Thanks,
Eric

Quoted 24 lines
---
  fs/ocfs2/dlmglue.c | 9 +++++++++
  1 file changed, 9 insertions(+)
fs/ocfs2/dlmglue.c +9 -0
index 4689940..5193218 100644
@@ -2486,6 +2486,15 @@ int ocfs2_inode_lock_with_page(struct inode *inode,
  	ret = ocfs2_inode_lock_full(inode, ret_bh, ex, OCFS2_LOCK_NONBLOCK);
  	if (ret == -EAGAIN) {
  		unlock_page(page);
+		/*
+		 * If we can't get inode lock immediately, we should not return
+		 * directly here, since this will lead to a softlockup problem.
+		 * The method is to get a blocking lock and immediately unlock
+		 * before returning, this can avoid CPU resource waste due to
+		 * lots of retries, and benefits fairness in getting lock.
+		 */
+		if (ocfs2_inode_lock(inode, ret_bh, ex) == 0)
+			ocfs2_inode_unlock(inode, ex);
  		ret = AOP_TRUNCATED_PAGE;
  	}