<div dir="ltr">Thank you all for your answers, they were very insightful. <div><br></div><div>>just curious, why would such a limit be useful?</div><div><br></div><div>Not really useful, just pretty. This all started because we got confused by the fact that programs can ask the kernel for more memory (we forgot that we were the kernel) and hence thought about a runtime extendable heap implementation for which we designed a structure that only supported allocation limited to 4kB (since our available memory is a multiple of 4kB). After we remembered that we are the kernel, we still considered that design neat so decided to ask about its main drawback.</div><div><br></div><div>Thanks again,</div><div>Strnadlová from Milkyway</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, 2 Nov 2020 at 09:09, Vojtech Horky <<a href="mailto:horky@d3s.mff.cuni.cz">horky@d3s.mff.cuni.cz</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hello.<br>
<br>
Dne 02. 11. 20 v 7:37 Petr Tuma napsal(a):<br>
> Hello,<br>
> <br>
> just curious, why would such a limit be useful ? The only thing I can <br>
> think of is trying very hard to keep the headers very small (saving bits <br>
> on size fields), but even for that a limit of around 4KB seems to be <br>
> quite small - and besides, by now I think you have all seen how hard it <br>
> is to avoid the alignment restrictions, which means aiming for a header <br>
> smaller than 4B in your assignments does not make much sense (and <br>
> possibly 8B would me more reasonable than 4B).<br>
<br>
The question might have arouse after the discussion we had last Friday <br>
about page and heap allocator. I remember I said something around the <br>
lines that kernel objects are rarely big and heap allocator usually <br>
allocates rather small objects.<br>
<br>
For example, in Linux one is not supposed to allocate objects bigger <br>
than page size and use other allocators for that [1].<br>
<br>
[1] <a href="https://www.kernel.org/doc/html/latest/core-api/memory-allocation.html" rel="noreferrer" target="_blank">https://www.kernel.org/doc/html/latest/core-api/memory-allocation.html</a><br>
<br>
<br>
For your implementation, it depends on where the limit comes from. If <br>
you create some kind of slab allocator with predefined object sizes <br>
(such as in HelenOS [2]) then 4KB would be okay as it would be _very_ <br>
easy to increase it to any value. However, if you choose this limit <br>
because you are unable to debug your implementation for bigger values, <br>
it is a completely different story.<br>
<br>
[2] <br>
<a href="https://github.com/HelenOS/helenos/blob/master/kernel/generic/src/mm/malloc.c#L49" rel="noreferrer" target="_blank">https://github.com/HelenOS/helenos/blob/master/kernel/generic/src/mm/malloc.c#L49</a><br>
<br>
If you have some smart and very memory efficient implementation, where <br>
4KB limit allows you to do some nice tricks, it is probably okay. I say <br>
probably, because if the implementation becomes totally unreadable and <br>
unmaintainable because of that, we will not be very happy about it.<br>
<br>
Note that for some time you will be using heap allocator to allocate <br>
thread stacks. It might be useful to have stack bigger than 4KB in <br>
certain cases (for debugging).<br>
<br>
<br>
> On 01/11/2020 23:08, FrantiÅ¡ek TrebuÅa wrote:<br>
>> In the tests malloc asks for maximum o f 32 KB if Im not mistaken.<br>
<br>
Actually, heap/stress allocates up to 128 KB. But the tests do not fail <br>
if such allocation is not possible and try to allocate smaller blocks.<br>
<br>
Hope this helps,<br>
- VH<br>
<br>
<br>
>><br>
>> TrebuÅa<br>
>><br>
>> On Sun, Nov 1, 2020, 22:33 R S <<a href="mailto:rstrnadlova@gmail.com" target="_blank">rstrnadlova@gmail.com</a> <br>
>> <mailto:<a href="mailto:rstrnadlova@gmail.com" target="_blank">rstrnadlova@gmail.com</a>>> wrote:<br>
>><br>
>> Â Â Â Hello,<br>
>>    can we limit how much memory can malloc ask for (for instance to <br>
>> 4056B) or can malloc theoretically ask for half our heap?<br>
>><br>
>> Â Â Â Thank you<br>
>>    Strnadlová from Milkyway<br>
>> Â Â Â _______________________________________________<br>
>> Â Â Â NSWI004 mailing list<br>
>> Â Â Â <a href="mailto:NSWI004@d3s.mff.cuni.cz" target="_blank">NSWI004@d3s.mff.cuni.cz</a> <mailto:<a href="mailto:NSWI004@d3s.mff.cuni.cz" target="_blank">NSWI004@d3s.mff.cuni.cz</a>><br>
>> Â Â Â <a href="https://d3s.mff.cuni.cz/mailman/listinfo/nswi004" rel="noreferrer" target="_blank">https://d3s.mff.cuni.cz/mailman/listinfo/nswi004</a> <br>
>> <<a href="https://d3s.mff.cuni.cz/mailman/listinfo/nswi004" rel="noreferrer" target="_blank">https://d3s.mff.cuni.cz/mailman/listinfo/nswi004</a>><br>
>><br>
>><br>
>> _______________________________________________<br>
>> NSWI004 mailing list<br>
>> <a href="mailto:NSWI004@d3s.mff.cuni.cz" target="_blank">NSWI004@d3s.mff.cuni.cz</a><br>
>> <a href="https://d3s.mff.cuni.cz/mailman/listinfo/nswi004" rel="noreferrer" target="_blank">https://d3s.mff.cuni.cz/mailman/listinfo/nswi004</a><br>
>><br>
> _______________________________________________<br>
> NSWI004 mailing list<br>
> <a href="mailto:NSWI004@d3s.mff.cuni.cz" target="_blank">NSWI004@d3s.mff.cuni.cz</a><br>
> <a href="https://d3s.mff.cuni.cz/mailman/listinfo/nswi004" rel="noreferrer" target="_blank">https://d3s.mff.cuni.cz/mailman/listinfo/nswi004</a><br>
_______________________________________________<br>
NSWI004 mailing list<br>
<a href="mailto:NSWI004@d3s.mff.cuni.cz" target="_blank">NSWI004@d3s.mff.cuni.cz</a><br>
<a href="https://d3s.mff.cuni.cz/mailman/listinfo/nswi004" rel="noreferrer" target="_blank">https://d3s.mff.cuni.cz/mailman/listinfo/nswi004</a><br>
</blockquote></div>