Skip to contentSkip to conversation

mm/hugetlb: Avoid soft lockup in set_max_huge_pages()

RFC PATCH Superseded Jia He 2 participants 5 messages Jul 26, 2016 – Jul 27, 2016

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Jia He

author
#0 lore raw

RFC PATCH 1/1 mm/hugetlb: Avoid soft lockup in set_max_huge_pages()

In large memory(32TB) powerpc servers, we watched several soft lockup under stress tests.
The call trace are as follows:
1.

get_page_from_freelist+0x2d8/0xd50  
__alloc_pages_nodemask+0x180/0xc20  
alloc_fresh_huge_page+0xb0/0x190    
set_max_huge_pages+0x164/0x3b0      

2.

prep_new_huge_page+0x5c/0x100             
alloc_fresh_huge_page+0xc8/0x190          
set_max_huge_pages+0x164/0x3b0

This patch is to fix such soft lockup. I thouhgt it is safe to call cond_resched() because alloc_fresh_gigantic_page and alloc_fresh_huge_page are out of spin_lock/unlock section.

Cc Andrew Morton <[email protected]>
Cc Naoya Horiguchi <[email protected]>
Cc Mike Kravetz <[email protected]>
Cc "Kirill A. Shutemov" <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Dave Hansen <[email protected]>
Cc Paul Gortmaker <[email protected]>
---
 mm/hugetlb.c | 8 ++++++++
 1 file changed, 8 insertions(+)
mm/hugetlb.c +8 -0
index addfe4ac..d51759d 100644
@@ -1146,6 +1146,10 @@ static int alloc_fresh_gigantic_page(struct hstate *h,
 
 	for_each_node_mask_to_alloc(h, nr_nodes, node, nodes_allowed) {
 		page = alloc_fresh_gigantic_page_node(h, node);
+
+		/* yield cpu */
+		cond_resched();
+
 		if (page)
 			return 1;
 	}
@@ -1381,6 +1385,10 @@ static int alloc_fresh_huge_page(struct hstate *h, nodemask_t *nodes_allowed)
 
 	for_each_node_mask_to_alloc(h, nr_nodes, node, nodes_allowed) {
 		page = alloc_fresh_huge_page_node(h, node);
+
+		/* yield cpu */
+		cond_resched();
+
 		if (page) {
 			ret = 1;
 			break;
Signature · 7 lines
2.5.0

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#1 lore raw
Quoted 3 lines · Jia He

This patch is to fix such soft lockup. I thouhgt it is safe to call cond_resched() because alloc_fresh_gigantic_page and alloc_fresh_huge_page are out of spin_lock/unlock section.

Yikes. So the call site for both the things you patch is this:

Quoted 1 line
        while (count > persistent_huge_pages(h)) {

...

Quoted 6 lines
                spin_unlock(&hugetlb_lock);
                if (hstate_is_gigantic(h))
                        ret = alloc_fresh_gigantic_page(h, nodes_allowed);
                else
                        ret = alloc_fresh_huge_page(h, nodes_allowed);
                spin_lock(&hugetlb_lock);

and you choose to patch both of the alloc_*() functions. Why not just fix it at the common call site? Seems like that spin_lock(&hugetlb_lock) could be a cond_resched_lock() which would fix both cases.

Also, putting that cond_resched() inside the for_each_node*() loop is an odd choice. It seems to indicate that the loops can take a long time, which really isn't the case. The _loop_ isn't long, right?

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

author
#2 lore raw
Quoted 14 lines · Dave Hansen
Quoted 3 lines · Jia He

This patch is to fix such soft lockup. I thouhgt it is safe to call cond_resched() because alloc_fresh_gigantic_page and alloc_fresh_huge_page are out of spin_lock/unlock section.

Yikes. So the call site for both the things you patch is this:

Quoted 1 line
         while (count > persistent_huge_pages(h)) {

...

Quoted 6 lines
                 spin_unlock(&hugetlb_lock);
                 if (hstate_is_gigantic(h))
                         ret = alloc_fresh_gigantic_page(h, nodes_allowed);
                 else
                         ret = alloc_fresh_huge_page(h, nodes_allowed);
                 spin_lock(&hugetlb_lock);
Quoted 8 lines

and you choose to patch both of the alloc_*() functions. Why not just fix it at the common call site? Seems like that spin_lock(&hugetlb_lock) could be a cond_resched_lock() which would fix both cases.

Also, putting that cond_resched() inside the for_each_node*() loop is an odd choice. It seems to indicate that the loops can take a long time, which really isn't the case. The _loop_ isn't long, right?

Yes,thanks for the suggestions
Will send out V2 later

B.R.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

author
#3 lore raw
In reply to Dave Hansen

Hi Dave

Quoted 14 lines · Dave Hansen
Quoted 3 lines · Jia He

This patch is to fix such soft lockup. I thouhgt it is safe to call cond_resched() because alloc_fresh_gigantic_page and alloc_fresh_huge_page are out of spin_lock/unlock section.

Yikes. So the call site for both the things you patch is this:

Quoted 1 line
         while (count > persistent_huge_pages(h)) {

...

Quoted 6 lines
                 spin_unlock(&hugetlb_lock);
                 if (hstate_is_gigantic(h))
                         ret = alloc_fresh_gigantic_page(h, nodes_allowed);
                 else
                         ret = alloc_fresh_huge_page(h, nodes_allowed);
                 spin_lock(&hugetlb_lock);
Quoted 4 lines

and you choose to patch both of the alloc_*() functions. Why not just fix it at the common call site? Seems like that spin_lock(&hugetlb_lock) could be a cond_resched_lock() which would fix both cases.

I agree to move the cond_resched() to a common site in set_max_huge_pages(). But do you mean the spin_lock in this while loop can be replaced by cond_resched_lock?
IIUC, cond_resched_lock = spin_unlock+cond_resched+spin_lock.
So could you please explain more details about it? Thanks.

B.R.
Justin

Quoted 4 lines

Also, putting that cond_resched() inside the for_each_node*() loop is an odd choice. It seems to indicate that the loops can take a long time, which really isn't the case. The _loop_ isn't long, right?

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#4 lore raw
Quoted 10 lines · hejianet
Quoted 5 lines
Quoted 1 line

and you choose to patch both of the alloc_*() functions. Why not just fix it at the common call site? Seems like that spin_lock(&hugetlb_lock) could be a cond_resched_lock() which would fix both cases.

I agree to move the cond_resched() to a common site in set_max_huge_pages(). But do you mean the spin_lock in this while loop can be replaced by cond_resched_lock? IIUC, cond_resched_lock = spin_unlock+cond_resched+spin_lock. So could you please explain more details about it? Thanks.

Ahh, good point. A plain cond_resched() outside the lock is probably sufficient here.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>