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

Clean up OS-specific ARC and kmem code #10499

Merged
merged 1 commit into from Jun 29, 2020
Merged

Conversation

ahrens
Copy link
Member

@ahrens ahrens commented Jun 25, 2020

Motivation and Context

OS-specific code (e.g. under module/os/linux) does not need to share its code structure with any other operating systems. In particular, the ARC and kmem code need not be similar to the code in illumos, because we won't be syncing this OS-specific code between operating systems. For example, if/when illumos support is added to the common repo, we would add a file module/os/illumos/zfs/arc_os.c for the illumos versions of this code.

Therefore, we can simplify the code in the OS-specific ARC and kmem routines.

Description

These changes do not impact system behavior, they are purely code cleanup. The changes are:

Arenas are not used on Linux or FreeBSD (they are always NULL), so heap_arena, zio_arena, and zio_alloc_arena can be removed, along with code that uses them.

In arc_available_memory():

  • desfree is unused, remove it
  • rename freemem to avoid conflict with pre-existing #define
  • remove checks related to arenas
  • use units of bytes, rather than converting from bytes to pages and then back to bytes

SPL_KMEM_CACHE_REAP is unused, remove it.

skc_reap is unused, remove it.

The count argument to spl_kmem_cache_reap_now() is unused, remove it.

vmem_size() and associated type and macros are unused, remove them.

In arc_memory_throttle(), use a less confusing variable name to store the result of arc_free_memory().

Note: I've kept this as several commits to aid in reviewing; I'll collapse this to one commit once the review is approved.

How Has This Been Tested?

ZTS

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:

  • My code follows the ZFS on Linux code style requirements.
  • I have updated the documentation accordingly.
  • I have read the contributing document.
  • I have added tests to cover my changes.
  • I have run the ZFS Test Suite with this change applied.
  • All commit messages are properly formatted and contain Signed-off-by.

@ahrens ahrens requested review from behlendorf and a user June 25, 2020 17:00
@ahrens ahrens added the Status: Code Review Needed Ready for review and testing label Jun 25, 2020
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice cleanup!

@codecov
Copy link

codecov bot commented Jun 26, 2020

Codecov Report

Merging #10499 into master will decrease coverage by 0.08%.
The diff coverage is 75.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #10499      +/-   ##
==========================================
- Coverage   79.62%   79.53%   -0.09%     
==========================================
  Files         391      391              
  Lines      123908   123887      -21     
==========================================
- Hits        98656    98539     -117     
- Misses      25252    25348      +96     
Flag Coverage Δ
#kernel 80.02% <75.00%> (-0.07%) ⬇️
#user 65.74% <ø> (+0.06%) ⬆️
Impacted Files Coverage Δ
lib/libzpool/kernel.c 67.81% <ø> (ø)
module/os/linux/spl/spl-vmem.c 100.00% <ø> (+45.83%) ⬆️
module/zfs/arc.c 89.17% <ø> (-0.27%) ⬇️
module/os/linux/zfs/arc_os.c 59.50% <66.66%> (+0.58%) ⬆️
module/os/linux/spl/spl-kmem-cache.c 75.44% <100.00%> (-9.67%) ⬇️
module/zfs/vdev_indirect.c 72.83% <0.00%> (-7.84%) ⬇️
module/zfs/dsl_synctask.c 92.40% <0.00%> (-2.54%) ⬇️
lib/libzfs/libzfs_changelist.c 84.37% <0.00%> (-1.96%) ⬇️
module/zfs/vdev_mirror.c 94.77% <0.00%> (-1.50%) ⬇️
... and 59 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 94a2dca...a0f1427. Read the comment docs.

Copy link
Contributor

@pzakha pzakha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice cleanup! It does seem like there's a small change in logic, perhaps it would be better to take it out to another review?

* the scanner doesn't start up while we're freeing memory.
*/
n = PAGESIZE * (realfree - sysfree - needfree);
n = arc_free_memory() - arc_sys_free;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like you've removed arc_need_free from this calculation, was this intentional?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thinking was that if arc_need_free is nonzero, we'll hit the case above and lowest will already be lower than what we could have here. On second examination, that's only true if arc_free_memory() - arc_sys_free is not negative. So I'll add arc_need_free back in here, just in case.

@behlendorf behlendorf added Status: Accepted Ready to integrate (reviewed, tested) and removed Status: Code Review Needed Ready for review and testing labels Jun 26, 2020
@behlendorf
Copy link
Contributor

@ahrens would you mind squashing and rebasing this to resolve the conflict.

OS-specific code (e.g. under `module/os/linux`) does not need to share
its code structure with any other operating systems.  In particular, the
ARC and kmem code need not be similar to the code in illumos, because we
won't be syncing this OS-specific code between operating systems.  For
example, if/when illumos support is added to the common repo, we would
add a file `module/os/illumos/zfs/arc_os.c` for the illumos versions of
this code.

Therefore, we can simplify the code in the OS-specific ARC and kmem
routines.

These changes do not impact system behavior, they are purely code
cleanup.  The changes are:

Arenas are not used on Linux or FreeBSD (they are always `NULL`), so
`heap_arena`, `zio_arena`, and `zio_alloc_arena` can be removed, along
with code that uses them.

In `arc_available_memory()`:
 * `desfree` is unused, remove it
 * rename `freemem` to avoid conflict with pre-existing `#define`
 * remove checks related to arenas
 * use units of bytes, rather than converting from bytes to pages and
   then back to bytes

`SPL_KMEM_CACHE_REAP` is unused, remove it.

`skc_reap` is unused, remove it.

The `count` argument to `spl_kmem_cache_reap_now()` is unused, remove
it.

`vmem_size()` and associated type and macros are unused, remove them.

In `arc_memory_throttle()`, use a less confusing variable name to store
the result of `arc_free_memory()`.

Signed-off-by: Matthew Ahrens <mahrens@delphix.com>
@ahrens
Copy link
Member Author

ahrens commented Jun 29, 2020

@behlendorf done.

@behlendorf behlendorf merged commit 3c42c9e into openzfs:master Jun 29, 2020
@ahrens ahrens deleted the arc-cleanup branch June 29, 2020 16:21
jsai20 pushed a commit to jsai20/zfs that referenced this pull request Mar 30, 2021
OS-specific code (e.g. under `module/os/linux`) does not need to share
its code structure with any other operating systems.  In particular, the
ARC and kmem code need not be similar to the code in illumos, because we
won't be syncing this OS-specific code between operating systems.  For
example, if/when illumos support is added to the common repo, we would
add a file `module/os/illumos/zfs/arc_os.c` for the illumos versions of
this code.

Therefore, we can simplify the code in the OS-specific ARC and kmem
routines.

These changes do not impact system behavior, they are purely code
cleanup.  The changes are:

Arenas are not used on Linux or FreeBSD (they are always `NULL`), so
`heap_arena`, `zio_arena`, and `zio_alloc_arena` can be removed, along
with code that uses them.

In `arc_available_memory()`:
 * `desfree` is unused, remove it
 * rename `freemem` to avoid conflict with pre-existing `#define`
 * remove checks related to arenas
 * use units of bytes, rather than converting from bytes to pages and
   then back to bytes

`SPL_KMEM_CACHE_REAP` is unused, remove it.

`skc_reap` is unused, remove it.

The `count` argument to `spl_kmem_cache_reap_now()` is unused, remove
it.

`vmem_size()` and associated type and macros are unused, remove them.

In `arc_memory_throttle()`, use a less confusing variable name to store
the result of `arc_free_memory()`.

Reviewed-by: George Wilson <gwilson@delphix.com>
Reviewed-by: Pavel Zakharov <pavel.zakharov@delphix.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Ryan Moeller <ryan@ixsystems.com>
Signed-off-by: Matthew Ahrens <mahrens@delphix.com>
Closes openzfs#10499
sempervictus pushed a commit to sempervictus/zfs that referenced this pull request May 31, 2021
OS-specific code (e.g. under `module/os/linux`) does not need to share
its code structure with any other operating systems.  In particular, the
ARC and kmem code need not be similar to the code in illumos, because we
won't be syncing this OS-specific code between operating systems.  For
example, if/when illumos support is added to the common repo, we would
add a file `module/os/illumos/zfs/arc_os.c` for the illumos versions of
this code.

Therefore, we can simplify the code in the OS-specific ARC and kmem
routines.

These changes do not impact system behavior, they are purely code
cleanup.  The changes are:

Arenas are not used on Linux or FreeBSD (they are always `NULL`), so
`heap_arena`, `zio_arena`, and `zio_alloc_arena` can be removed, along
with code that uses them.

In `arc_available_memory()`:
 * `desfree` is unused, remove it
 * rename `freemem` to avoid conflict with pre-existing `#define`
 * remove checks related to arenas
 * use units of bytes, rather than converting from bytes to pages and
   then back to bytes

`SPL_KMEM_CACHE_REAP` is unused, remove it.

`skc_reap` is unused, remove it.

The `count` argument to `spl_kmem_cache_reap_now()` is unused, remove
it.

`vmem_size()` and associated type and macros are unused, remove them.

In `arc_memory_throttle()`, use a less confusing variable name to store
the result of `arc_free_memory()`.

Reviewed-by: George Wilson <gwilson@delphix.com>
Reviewed-by: Pavel Zakharov <pavel.zakharov@delphix.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Ryan Moeller <ryan@ixsystems.com>
Signed-off-by: Matthew Ahrens <mahrens@delphix.com>
Closes openzfs#10499
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Accepted Ready to integrate (reviewed, tested)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants