-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make use of kvmalloc if available #9034
Conversation
5073b09
to
db77af2
Compare
db77af2
to
b91ed0c
Compare
e143c65
to
263b0dc
Compare
Completely reworked and rebased onto master. I also temporarily removed the vmem allocation retry fix. I'll readd this again as a separate commit later. |
263b0dc
to
915faef
Compare
Thanks! I'll take a proper look at this tomorrow, but I happened to notice the updated code in now triggering the allocation size warning for several slabs. |
Am 17.07.2019 um 21:05 schrieb Michael Niewöhner:
***@***.**** commented on this pull request.
------------------------------------------------------------------------
In module/spl/spl-kmem-cache.c
<#9034 (comment)>:
> } else {
- ptr = __vmalloc(size, lflags | __GFP_HIGHMEM, PAGE_KERNEL);
+ /*
+ * GFP_KERNEL allocations can safe use kvmalloc allocator which
+ * may increase performance since vmalloc overhead might not
+ * be applicated since enough contiguous memory was available
+ * at allocation time. unfortunatly the slab statistic will
+ * show allocations as VMEM without any care if kmalloc was
+ * used in reality. but this is just cosmetic
+ */
Hmmm.... don't we need a check for size <= spl_kmem_alloc_max in
|kv_alloc|, too?
no. kv_alloc must always succeed. no matter which size is allocated. i
want physical mem at any size if available. this is how its used in zstd
…
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#9034>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AB2WNEY3DPOPX4WWTNJE6D3P75UQVANCNFSM4IC7IAVA>.
|
Am 17.07.2019 um 22:01 schrieb Michael Niewöhner:
Completely reworked and rebased onto master.
I also temporarily remove the vmem allocation retry fix. I'll readd
this again as a separate commit later.
you removed also the whole kvmalloc implementation for kernels without
this function. so the current code is broken
you just kall kvmalloc if its available. so this code is now unusable
for me in the zstd code since it does not allow me to allocate
bigger physical memory anymore if available.
…
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#9034>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AB2WNEZICXIGDMX2PBLRAETP753BZANCNFSM4IC7IAVA>.
|
Am 17.07.2019 um 22:01 schrieb Michael Niewöhner:
Completely reworked and rebased onto master.
I also temporarily remove the vmem allocation retry fix. I'll readd
this again as a separate commit later.
and your code introduces also bad bugs
any call of spl_kmem_alloc_impl with GFP_ATOMIC will return NULL now
see
if ((size > spl_kmem_alloc_max) || use_vmem ||
!((flags & GFP_KERNEL) != GFP_KERNEL)) {
Am 17.07.2019 um 22:01 schrieb Michael Niewöhner:
…
Completely reworked and rebased onto master.
I also temporarily remove the vmem allocation retry fix. I'll readd
this again as a separate commit later.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#9034>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AB2WNEZICXIGDMX2PBLRAETP753BZANCNFSM4IC7IAVA>.
|
@BrainSlayer WIP ;) |
Ok... I will redo this later |
Am 18.07.2019 um 09:54 schrieb Michael Niewöhner:
Hmmm.... don't we need a check for size <= spl_kmem_alloc_max
in |kv_alloc|, too?
no. kv_alloc must always succeed. no matter which size is
allocated. i want physical mem at any size if available. this is
how its used in zstd
Ok... I will redo this later
thats hard without having a indepenend spl_kvmalloc implementation. the
original zfs kmem_alloc code restricts the maximum allocatable physical
memory per allocation.
changing this behaviour is surelly not accepted by the maintainers. this
is why i added the new api. so i can conditionally use it in the way i
want it only for the codepieces i wrote or where it makes sense in some
way.
its also possible to use it unconditionally for the vmem allocation
then. but not for kmem since it has a different behaviour unlike the
original zfs allocation code
…
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#9034>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AB2WNEYB2S4HMJV4KANU3ULQAAOTFANCNFSM4IC7IAVA>.
|
no, we want to use it for any vmem alloc, as discussed above...
yes...
again... I'll redo this later... |
e28fcb5
to
4df62eb
Compare
@BrainSlayer can you have a look at this again, now? |
this looks much better and allows me to override the kmem_alloc_max
condition by directly calling spl_kvmalloc from codepaths where its
needed like zstd. but what if i want to make use
of kmem_cache_create using exclusive kvmem allocator without
kmem_alloc_max condition. this was also a major part of the change.
without my patch kmem_cache_create more or less always fails in zstd
code due the nature of its allocation implementation. basicly
kmem_cache_create does allocate using nosleep like gfp_atomic but this
makes no sense if its just called once in a init module function but
only from time critical contexts
zstd does make use of very big kmem caches. if it fails it falls back to
a custom allocator. but kmem_cache_create doesnt work for large blocks
(alloc_max condition for vmem + nosleep problem using kmem) without my
changes which make use of the extra kmc_kvmem flag so your patch will
still work with the zstd code, but will decrease the performance since
kmem_cache_create is unable to allocate the larger blocks.
kmc_kvmem was using spl_kvmalloc exclusivly which has no alloc_max
problem for vmem and is able to allocate kmem at any size without
getting a kernel warning.
while researching the freebsd variant of the zstd implementation this
was a major point since freebsd allows such big kmem allocations
Am 19.07.2019 um 09:45 schrieb Michael Niewöhner:
…
@BrainSlayer <https://github.com/BrainSlayer> can you have a look at
this again, now?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#9034>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AB2WNE2W6WM3PWIDUYHNN7DQAFWJ7ANCNFSM4IC7IAVA>.
|
Ok, then I will readd KMC_KVMEM to make this possible again. Thanks for your explanations! |
4df62eb
to
08ae414
Compare
@BrainSlayer done (but I am not sure about that spl proc stuff) |
This patch implements use of kvmalloc for GFP_KERNEL allocations, which may increase performance if the allocator is able to allocate physical memory, if kvmalloc is available as a public kernel interface (since v4.12). Otherwise it will simply fall back to virtual memory (vmalloc). Also fix vmem_alloc implementation which can lead to slow allocations since the first attempt with kmalloc does not make use of the noretry flag but tells the linux kernel to retry several times before it fails. Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: Matt Ahrens <matt@delphix.com> Signed-off-by: Sebastian Gottschall <s.gottschall@dd-wrt.com> Signed-off-by: Michael Niewöhner <foss@mniewoehner.de> Closes #9034
This adds a new KMC_KVMEM flag was added to enforce use of the kvmalloc allocator in kmem_cache_create even for large blocks, which may also increase performance in some specific cases (e.g. zstd), too. Default to KVMEM instead of VMEM in spl_kmem_cache_create. Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: Matt Ahrens <matt@delphix.com> Signed-off-by: Sebastian Gottschall <s.gottschall@dd-wrt.com> Signed-off-by: Michael Niewöhner <foss@mniewoehner.de> Closes #9034
Check for __GFP_RECLAIM instead of GFP_KERNEL because zfs modifies IO and FS flags which breaks the check for GFP_KERNEL. Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: Matt Ahrens <matt@delphix.com> Reviewed-by: Sebastian Gottschall <s.gottschall@dd-wrt.com> Signed-off-by: Michael Niewöhner <foss@mniewoehner.de> Closes #9034
@c0d3z3r0 @BrainSlayer merged! Thank's for all your hard work on this improvement. |
yay! Thank you, too! |
yeah now i have the painfull work to resolve the conflicts :-) |
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: Matt Ahrens <matt@delphix.com> Signed-off-by: Sebastian Gottschall <s.gottschall@dd-wrt.com> Signed-off-by: Michael Niewöhner <foss@mniewoehner.de> Closes openzfs#9034
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: Matt Ahrens <matt@delphix.com> Signed-off-by: Sebastian Gottschall <s.gottschall@dd-wrt.com> Signed-off-by: Michael Niewöhner <foss@mniewoehner.de> Closes openzfs#9034
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: Matt Ahrens <matt@delphix.com> Signed-off-by: Sebastian Gottschall <s.gottschall@dd-wrt.com> Signed-off-by: Michael Niewöhner <foss@mniewoehner.de> Closes #9034
`KMC_KVMEM` was designed to use `kvmalloc()` (see openzfs#9034). However, this was changed by openzfs#9813 to use `vmalloc()`, because `kvmalloc()` doesn't always return page-aligned addresses. However, the SPL kmem-cache implementation doesn't need page-aligned addresses, because no SPL caches request any particular alignment. This commit changes `KMC_KVMEM` to use `kvmalloc()`, removes the assertion that it returns page-aligned addresses, and asserts that SPL caches to not request any particular alignment. Signed-off-by: Matthew Ahrens <mahrens@delphix.com>
This patch implements use of kvmalloc for GFP_KERNEL allocations, which may increase performance if the allocator is able to allocate physical memory, if kvmalloc is available as a public kernel interface (since v4.12). Otherwise it will simply fall back to virtual memory (vmalloc). Also fix vmem_alloc implementation which can lead to slow allocations since the first attempt with kmalloc does not make use of the noretry flag but tells the linux kernel to retry several times before it fails. Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: Matt Ahrens <matt@delphix.com> Signed-off-by: Sebastian Gottschall <s.gottschall@dd-wrt.com> Signed-off-by: Michael Niewöhner <foss@mniewoehner.de> Closes openzfs#9034
This patch implements use of kvmalloc for GFP_KERNEL allocations, which may increase performance if the allocator is able to allocate physical memory, if kvmalloc is available as a public kernel interface (since v4.12). Otherwise it will simply fall back to virtual memory (vmalloc). Also fix vmem_alloc implementation which can lead to slow allocations since the first attempt with kmalloc does not make use of the noretry flag but tells the linux kernel to retry several times before it fails. Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: Matt Ahrens <matt@delphix.com> Signed-off-by: Sebastian Gottschall <s.gottschall@dd-wrt.com> Signed-off-by: Michael Niewöhner <foss@mniewoehner.de> Closes openzfs#9034
`KMC_KVMEM` was designed to use `kvmalloc()` (see openzfs#9034). However, this was changed by openzfs#9813 to use `vmalloc()`, because `kvmalloc()` doesn't always return page-aligned addresses. However, the SPL kmem-cache implementation doesn't need page-aligned addresses, because no SPL caches request any particular alignment. This commit changes `KMC_KVMEM` to use `kvmalloc()`, removes the assertion that it returns page-aligned addresses, and asserts that SPL caches to not request any particular alignment. Signed-off-by: Matthew Ahrens <mahrens@delphix.com>
`KMC_KVMEM` was designed to use `kvmalloc()` (see openzfs#9034). However, this was changed by openzfs#9813 to use `vmalloc()`, because `kvmalloc()` doesn't always return page-aligned addresses. However, the SPL kmem-cache implementation doesn't need page-aligned addresses, because no SPL caches request any particular alignment. This commit changes `KMC_KVMEM` to use `kvmalloc()`, removes the assertion that it returns page-aligned addresses, and asserts that SPL caches to not request any particular alignment. Signed-off-by: Matthew Ahrens <mahrens@delphix.com>
`KMC_KVMEM` was designed to use `kvmalloc()` (see openzfs#9034). However, this was changed by openzfs#9813 to use `vmalloc()`, because `kvmalloc()` doesn't always return page-aligned addresses. However, the SPL kmem-cache implementation doesn't need page-aligned addresses, because no SPL caches request any particular alignment. This commit changes `KMC_KVMEM` to use `kvmalloc()`, removes the assertion that it returns page-aligned addresses, and asserts that SPL caches to not request any particular alignment. Signed-off-by: Matthew Ahrens <mahrens@delphix.com>
`KMC_KVMEM` was designed to use `kvmalloc()` (see openzfs#9034). However, this was changed by openzfs#9813 to use `vmalloc()`, because `kvmalloc()` doesn't always return page-aligned addresses. This commit changes `KMC_KVMEM` back to using `kvmalloc()` and introduces a page-aligning wrapper atop it. Signed-off-by: Adam Moss <c@yotes.com> Closes openzfs#11009 Closes openzfs#10686
`KMC_KVMEM` was designed to use `kvmalloc()` (see openzfs#9034). However, this was changed by openzfs#9813 to use `vmalloc()`, because `kvmalloc()` doesn't always return page-aligned addresses. This commit changes `KMC_KVMEM` back to using `kvmalloc()` and introduces a page-aligning wrapper atop it. Signed-off-by: Adam Moss <c@yotes.com> Closes openzfs#11009 Closes openzfs#10686
`KMC_KVMEM` was designed to use `kvmalloc()` (see openzfs#9034). However, this was changed by openzfs#9813 to use `vmalloc()`, because `kvmalloc()` doesn't always return page-aligned addresses. This commit changes `KMC_KVMEM` back to using `kvmalloc()` and introduces a page-aligning wrapper atop it. Signed-off-by: Adam Moss <c@yotes.com> Closes openzfs#11009 Closes openzfs#10686
`KMC_KVMEM` was designed to use `kvmalloc()` (see openzfs#9034). However, this was changed by openzfs#9813 to use `vmalloc()`, because `kvmalloc()` doesn't always return page-aligned addresses. This commit changes `KMC_KVMEM` back to using `kvmalloc()` and introduces a page-aligning wrapper atop it. Signed-off-by: Adam Moss <c@yotes.com> Closes openzfs#11009 Closes openzfs#10686
This patch implements use of kvmalloc for GFP_KERNEL allocations, which may increase performance if the allocator is able to allocate physical memory, if kvmalloc is available as a public kernel interface (since v4.12). Otherwise it will simply fall back to virtual memory (vmalloc). Also fix vmem_alloc implementation which can lead to slow allocations since the first attempt with kmalloc does not make use of the noretry flag but tells the linux kernel to retry several times before it fails. Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: Matt Ahrens <matt@delphix.com> Signed-off-by: Sebastian Gottschall <s.gottschall@dd-wrt.com> Signed-off-by: Michael Niewöhner <foss@mniewoehner.de> Closes openzfs#9034
This adds a new KMC_KVMEM flag was added to enforce use of the kvmalloc allocator in kmem_cache_create even for large blocks, which may also increase performance in some specific cases (e.g. zstd), too. Default to KVMEM instead of VMEM in spl_kmem_cache_create. Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: Matt Ahrens <matt@delphix.com> Signed-off-by: Sebastian Gottschall <s.gottschall@dd-wrt.com> Signed-off-by: Michael Niewöhner <foss@mniewoehner.de> Closes openzfs#9034
Check for __GFP_RECLAIM instead of GFP_KERNEL because zfs modifies IO and FS flags which breaks the check for GFP_KERNEL. Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: Matt Ahrens <matt@delphix.com> Reviewed-by: Sebastian Gottschall <s.gottschall@dd-wrt.com> Signed-off-by: Michael Niewöhner <foss@mniewoehner.de> Closes openzfs#9034
Motivation and Context
This is a spin-off of #8384
Modifications:
This PR introduces several improvements / fixes:
This patch implements use of kvmalloc for GFP_KERNEL allocations, which
may increase performance if the allocator is able to allocate physical
memory, if kvmalloc is available as a public kernel interface (since
v4.12). Otherwise it will simply fall back to virtual memory (vmalloc).
Also fix vmem_alloc implementation which can lead to slow allocations
since the first attempt with kmalloc does not make use of the noretry
flag but tells the linux kernel to retry several times before it fails.
This adds a new KMC_KVMEM flag was added to enforce use of the
kvmalloc allocator in kmem_cache_create even for large blocks, which
may also increase performance in some specific cases (e.g. zstd), too.
Make use of KMC_KVMEM for spl_zlib_workspace_cache, ddt_cache, zio_buf
and zio_data_buf.
Add missing documentation for some KMC flags
Make use of kvmalloc if available and fix vmem_alloc implementation
Signed-off-by: Sebastian Gottschall s.gottschall@dd-wrt.com
Signed-off-by: Michael Niewöhner foss@mniewoehner.de
Description
How Has This Been Tested?
Running stable on Debian testing, currently kernel 5.2.0, since months with very low load. @BrainSlayer did stress tests (see #8384).
Types of changes
Checklist:
Signed-off-by
.