Linux-RISC-V Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: William Pierce <wgpierce17@gmail.com>
To: "Clément Léger" <cleger@rivosinc.com>
Cc: alex@ghiti.fr, linux-riscv@lists.infradead.org,
	paul.walmsley@sifive.com, aou@eecs.berkeley.edu,
	palmer@dabbelt.com
Subject: Re: [BUG] Module load relocation hashtable size can become huge and unallocatable
Date: Tue, 1 Apr 2025 14:00:52 -0700	[thread overview]
Message-ID: <d9714824-810c-4dd8-aff4-d1431235702b@gmail.com> (raw)
In-Reply-To: <8559a9f9-9100-48a7-a996-700b4a5852a9@rivosinc.com>

On 4/1/25 12:55 AM, Clément Léger wrote:
> 
> 
> On 01/04/2025 05:10, William Pierce wrote:
>> Using vmalloc_array/vfree on the relocation_hashtable
>> allows the kernel module to load just fine. I can send this
>> as a patch if the fix sounds good.
> 
> Hey William,
> 
> Using vmalloc sounds reasonable since there is no need to have
> physically contiguous memory.
> 
> However, there is also a new API named kvmalloc which uses kmalloc for
> small sizes and vmalloc for large allocations exceeding kmalloc
> capabilities, potentially leading to better performances than using
> vmalloc only.
> 
> Clément
> 

Hi Clément,

Thank you for checking. Yes I expect kvmalloc should also work just fine.

I can send out a patch based on that, unless someone wants to just take
the change. I'll do so in the next day or so.

- Will

>>
>> On 3/30/25 1:12 PM, William Pierce wrote:
>>> Hello, I have a kernel module that requires a huge number
>>> of relocations upon loading.
>>>
>>> On other architectures, it loads into the kernel just fine.
>>> However, on riscv, while allocating memory for its relocation
>>> hashtable, it ends up requesting 2097152 elements to kmalloc_array.
>>>
>>> Right here I've dumped the values by recompiling the kernel:
>>> num_relocations: 1630985, hastable_size: 2097152
>>> https://elixir.bootlin.com/linux/v6.14-rc6/source/arch/riscv/kernel/module.c#L734
>>>
>>> which kmalloc_array->...->___kmalloc_large_node->...->
>>> __alloc_frozen_pages_noprof can't handle and returns
>>> "Cannot allocate memory" on insmod.
>>>
>>> How would it be recommended to fix this?
>>> I could imagine allocating a more discontiguous data structure
>>> to track the relocations or otherwise reworking the tracking to
>>> do the relocation tracking inline.
>>>
>>> Thank you,
>>> Will Pierce
>>
>>
>> _______________________________________________
>> linux-riscv mailing list
>> linux-riscv@lists.infradead.org
>> http://lists.infradead.org/mailman/listinfo/linux-riscv
> 


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

  reply	other threads:[~2025-04-01 21:12 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-30 20:12 [BUG] Module load relocation hashtable size can become huge and unallocatable William Pierce
2025-04-01  3:10 ` William Pierce
2025-04-01  7:55   ` Clément Léger
2025-04-01 21:00     ` William Pierce [this message]
2025-04-02  5:34       ` [PATCH] riscv: Use kvmalloc_array on relocation_hashtable wgpierce17
2025-04-02  6:56         ` Alexandre Ghiti
2025-04-02  8:12           ` William Pierce

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=d9714824-810c-4dd8-aff4-d1431235702b@gmail.com \
    --to=wgpierce17@gmail.com \
    --cc=alex@ghiti.fr \
    --cc=aou@eecs.berkeley.edu \
    --cc=cleger@rivosinc.com \
    --cc=linux-riscv@lists.infradead.org \
    --cc=palmer@dabbelt.com \
    --cc=paul.walmsley@sifive.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