linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Wei Yang <richard.weiyang@gmail.com>
To: Wei Yang <richard.weiyang@gmail.com>
Cc: Liam.Howlett@oracle.com, akpm@linux-foundation.org,
	maple-tree@lists.infradead.org, linux-mm@kvack.org,
	Sidhartha Kumar <sidhartha.kumar@oracle.com>
Subject: Re: [PATCH 4/4] maple_tree: fix potential allocation failure even has memory
Date: Fri, 11 Oct 2024 01:27:25 +0000	[thread overview]
Message-ID: <20241011012725.ffof6uh4huffz73q@master> (raw)
In-Reply-To: <20240924123954.18933-5-richard.weiyang@gmail.com>


Related fix has been posted, but not merged yet.

lkml.kernel.org/r/20240626160631.3636515-1-Liam.Howlett@oracle.com

May drop this one.

On Tue, Sep 24, 2024 at 12:39:54PM +0000, Wei Yang wrote:
>We got an rare case when mas_node_count() would fail even there is
>enough memory.
>
>The reason is the maple_alloc grows downward. And when hit a full
>maple_alloc, the max_req would be 0. This leads to mt_alloc_bulk()
>return 0, which means failure here.
>
>For example, here is the test code:
>
>	expect = MAPLE_ALLOC_SLOTS + 1;
>	mas_node_count(&ms, expect);
>	pr_info("expect %d allocated %lu\n", expect, mas_allocated(&ms));
>	expect = MAPLE_ALLOC_SLOTS * 2 + 2;
>	mas_node_count(&ms, expect);
>	pr_info("expect %d allocated %lu\n", expect, mas_allocated(&ms));
>
>We will get the following output, which shows we fail to allocate the
>required number of nodes.
>
>	expect 31 allocated 31
>        expect 62 allocated 61
>
>The straight forward way to fix it is go down one level more.
>
>Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
>CC: Liam R. Howlett <Liam.Howlett@Oracle.com>
>CC: Sidhartha Kumar <sidhartha.kumar@oracle.com>
>---
> lib/maple_tree.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
>diff --git a/lib/maple_tree.c b/lib/maple_tree.c
>index 1cbc5f7ca40d..dd33d0793dd1 100644
>--- a/lib/maple_tree.c
>+++ b/lib/maple_tree.c
>@@ -1253,8 +1253,10 @@ static inline void mas_alloc_nodes(struct ma_state *mas, gfp_t gfp)
> 	}
> 
> 	node = mas->alloc;
>-	while (requested) {
>+	for (; requested; node = node->slot[0]) {
> 		max_req = MAPLE_ALLOC_SLOTS - node->node_count;
>+		if (unlikely(!max_req))
>+			continue;
> 		slots = (void **)&node->slot[node->node_count];
> 		max_req = min(requested, max_req);
> 		count = mt_alloc_bulk(gfp, max_req, slots);
>@@ -1268,7 +1270,6 @@ static inline void mas_alloc_nodes(struct ma_state *mas, gfp_t gfp)
> 
> 		node->node_count += count;
> 		allocated += count;
>-		node = node->slot[0];
> 		requested -= count;
> 	}
> 	mas->alloc->total = allocated;
>-- 
>2.34.1

-- 
Wei Yang
Help you, Help me


  reply	other threads:[~2024-10-11  1:27 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-24 12:39 [PATCH 0/4] cleanup maple_alloc related functions Wei Yang
2024-09-24 12:39 ` [PATCH 1/4] maple_tree: clear request_count for new allocated one Wei Yang
2024-10-15  1:18   ` Liam R. Howlett
2024-09-24 12:39 ` [PATCH 2/4] maple_tree: total is not changed for nomem_one case Wei Yang
2024-10-15  1:20   ` Liam R. Howlett
2024-09-24 12:39 ` [PATCH 3/4] maple_tree: simplify mas_push_node() Wei Yang
2024-10-15  1:29   ` Liam R. Howlett
2024-09-24 12:39 ` [PATCH 4/4] maple_tree: fix potential allocation failure even has memory Wei Yang
2024-10-11  1:27   ` Wei Yang [this message]
2024-10-15  1:14     ` Liam R. Howlett
2024-10-15  1:29     ` Liam R. Howlett
2024-09-24 15:03 ` [PATCH 0/4] cleanup maple_alloc related functions Lorenzo Stoakes
2024-09-25  1:03   ` Wei Yang
2024-09-25  7:41     ` Lorenzo Stoakes

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241011012725.ffof6uh4huffz73q@master \
    --to=richard.weiyang@gmail.com \
    --cc=Liam.Howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-mm@kvack.org \
    --cc=maple-tree@lists.infradead.org \
    --cc=sidhartha.kumar@oracle.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox