Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>See <a href="http://man7.org/linux/man-pages/man2/mremap.2.html" rel="nofollow noreferrer">man <code>mremap()</code></a> for the mechanism that <code>realloc()</code> uses. The mechanisms to implement this are in the kernel. See <a href="https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/mm/mremap.c" rel="nofollow noreferrer">mremap.c</a>. <code>mremap()</code> attempts to setup adjacent memory for user space so that a range maybe grown. It may not apply well to kernel space.</p> <p>You can request a region of virtual address space and also request it at <a href="https://www.kernel.org/doc/htmldocs/kernel-api/API-vmap.html" rel="nofollow noreferrer">a specific address</a>. See <a href="http://lwn.net/Articles/304188/" rel="nofollow noreferrer"><code>vmap()</code></a> at LWN. All that remains is to assign some physical pages to this virtual addresses.</p> <p><code>kmalloc()</code> works at the page level and then provides binning within pages (via SLAB, SLUB, etc). See <a href="https://stackoverflow.com/questions/12568379/kmalloc-size-allocation">kmalloc size allocation‌</a>​. In your case, you can not share the page so others can use it. If you grow the region and someone else uses it, then you have to move the memory. </p> <p>See <a href="http://lxr.free-electrons.com/source/mm/util.c#L110" rel="nofollow noreferrer"><code>do_krealloc()</code></a> for the moving. If your total size is small, then you can use <code>krealloc()</code>. If they are large (>16k), then you should be using <code>vmap()</code> or use the alternate interface of <code>vfs_writev()</code> instead of <code>vfs_write()</code>. Note that even sizes of 16k may fail as system memory gets fragmented. This is why people generally use only a page as it can never get fragmented.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload