Skip to content
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

Closed
wants to merge 4 commits into from

Conversation

c0d3z3r0
Copy link
Contributor

@c0d3z3r0 c0d3z3r0 commented Jul 13, 2019

Motivation and Context

This is a spin-off of #8384

Modifications:

  • removed kvmalloc interface
  • moved kvmalloc stuff into vmem (Well, actually it was there before, but implemented with its own KM_* flag)
  • remove new but currently unused KM_ONCE flag implementation
  • removed spl_kvfree in favor of spl_kmem_free_impl
  • code style fixes
  • adapt commit message
  • documentation

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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Performance enhancement (non-breaking change which improves efficiency)
  • Code cleanup (non-breaking change which makes code smaller or more readable)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation (a change to man pages or other documentation)

Checklist:

@c0d3z3r0 c0d3z3r0 force-pushed the for-upstream/kvmem branch 3 times, most recently from 5073b09 to db77af2 Compare July 14, 2019 08:59
@behlendorf behlendorf added Status: Code Review Needed Ready for review and testing Status: Work in Progress Not yet ready for general review labels Jul 15, 2019
config/kernel-kmem.m4 Outdated Show resolved Hide resolved
include/spl/sys/kmem.h Outdated Show resolved Hide resolved
module/spl/spl-kmem-cache.c Outdated Show resolved Hide resolved
include/spl/sys/vmem.h Outdated Show resolved Hide resolved
module/spl/spl-kmem.c Outdated Show resolved Hide resolved
@c0d3z3r0 c0d3z3r0 changed the title Make use of kvmalloc if available [WIP/RFC] Make use of kvmalloc if available Jul 16, 2019
module/spl/spl-kmem.c Outdated Show resolved Hide resolved
@c0d3z3r0 c0d3z3r0 force-pushed the for-upstream/kvmem branch 2 times, most recently from e143c65 to 263b0dc Compare July 17, 2019 19:59
@c0d3z3r0
Copy link
Contributor Author

c0d3z3r0 commented Jul 17, 2019

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.

@behlendorf
Copy link
Contributor

Completely reworked and rebased onto master.

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.

@BrainSlayer
Copy link
Contributor

BrainSlayer commented Jul 18, 2019 via email

@BrainSlayer
Copy link
Contributor

BrainSlayer commented Jul 18, 2019 via email

@BrainSlayer
Copy link
Contributor

BrainSlayer commented Jul 18, 2019 via email

@c0d3z3r0
Copy link
Contributor Author

@BrainSlayer WIP ;)

@c0d3z3r0
Copy link
Contributor Author

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

@BrainSlayer
Copy link
Contributor

BrainSlayer commented Jul 18, 2019 via email

@c0d3z3r0
Copy link
Contributor Author

want it only for the codepieces i wrote or where it makes sense in some
way.

no, we want to use it for any vmem alloc, as discussed above...

its also possible to use it unconditionally for the vmem allocation
then.

yes...

but not for kmem since it has a different behaviour unlike the
original zfs allocation code

again... I'll redo this later...

@c0d3z3r0 c0d3z3r0 force-pushed the for-upstream/kvmem branch 4 times, most recently from e28fcb5 to 4df62eb Compare July 18, 2019 21:06
@c0d3z3r0
Copy link
Contributor Author

@BrainSlayer can you have a look at this again, now?

@BrainSlayer
Copy link
Contributor

BrainSlayer commented Jul 19, 2019 via email

@c0d3z3r0
Copy link
Contributor Author

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.

Ok, then I will readd KMC_KVMEM to make this possible again. Thanks for your explanations!

@c0d3z3r0
Copy link
Contributor Author

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.

Ok, then I will readd KMC_KVMEM to make this possible again. Thanks for your explanations!

@BrainSlayer done (but I am not sure about that spl proc stuff)

@behlendorf behlendorf added Status: Accepted Ready to integrate (reviewed, tested) and removed Status: Code Review Needed Ready for review and testing labels Nov 13, 2019
behlendorf pushed a commit that referenced this pull request Nov 13, 2019
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
behlendorf pushed a commit that referenced this pull request Nov 13, 2019
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
behlendorf pushed a commit that referenced this pull request Nov 13, 2019
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
@behlendorf
Copy link
Contributor

@c0d3z3r0 @BrainSlayer merged! Thank's for all your hard work on this improvement.

@c0d3z3r0
Copy link
Contributor Author

@c0d3z3r0 @BrainSlayer merged! Thank's for all your hard work on this improvement.

yay! Thank you, too!

@BrainSlayer
Copy link
Contributor

yeah now i have the painfull work to resolve the conflicts :-)

@c0d3z3r0 c0d3z3r0 mentioned this pull request Dec 16, 2019
12 tasks
tonyhutter pushed a commit to tonyhutter/zfs that referenced this pull request Dec 26, 2019
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
tonyhutter pushed a commit to tonyhutter/zfs that referenced this pull request Dec 27, 2019
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
tonyhutter pushed a commit that referenced this pull request Jan 23, 2020
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
@c0d3z3r0 c0d3z3r0 mentioned this pull request May 1, 2020
17 tasks
ahrens added a commit to ahrens/zfs that referenced this pull request Aug 7, 2020
`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>
@ahrens ahrens mentioned this pull request Aug 7, 2020
12 tasks
BtbN pushed a commit to BtbN/zfs that referenced this pull request Aug 14, 2020
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
minextu pushed a commit to minextu/zfs that referenced this pull request Aug 16, 2020
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
ahrens added a commit to ahrens/zfs that referenced this pull request Sep 28, 2020
`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>
ahrens added a commit to ahrens/zfs that referenced this pull request Sep 29, 2020
`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>
adamdmoss pushed a commit to adamdmoss/zfs that referenced this pull request Oct 2, 2020
`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>
adamdmoss added a commit to adamdmoss/zfs that referenced this pull request Oct 7, 2020
`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
adamdmoss added a commit to adamdmoss/zfs that referenced this pull request Oct 9, 2020
`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
adamdmoss added a commit to adamdmoss/zfs that referenced this pull request Oct 10, 2020
`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
adamdmoss added a commit to adamdmoss/zfs that referenced this pull request Oct 11, 2020
`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
veggiemike pushed a commit to veggiemike/zfs that referenced this pull request Sep 6, 2021
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
veggiemike pushed a commit to veggiemike/zfs that referenced this pull request Sep 6, 2021
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
veggiemike pushed a commit to veggiemike/zfs that referenced this pull request Sep 6, 2021
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Memory Management kernel memory management Status: Accepted Ready to integrate (reviewed, tested)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants