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

abd_os: iovec-based scatter abd for userspace #16253

Closed
wants to merge 5 commits into from

Conversation

robn
Copy link
Member

@robn robn commented Jun 7, 2024

Motivation and Context

The main motivator here is that I want to experiment with various ways of more efficiently moving memory around and avoiding copies. Both method and goals are different in kernel and userspace, and I'm finding that the shared implementation is more of a burden than a help. Much better to have separate, focused implementations.

Description

See commits. The summary is:

  • abd: remove unused ABD_FLAG_ZEROS flag
  • zio: don't use allocation canary in userspace, as it gets in the way of userspace memory debuggers (eg valgrind)
  • abd_os: rework to provide cleaner separation of commont and platform-specific parts, including creating a specific abd_is for userspace
  • abd_os: replace the userspace abd_os with a new one based on struct iovec.

As noted in the last commit message, the new userspace abd_os is relatively simple. It's perhaps the simplest thing that could work, and so useful as an example. It's also should be a good base for further development.

How Has This Been Tested?

Compiled on Linux 6.1.x and FreeBSD 14. Two main tests performed: zdb -b on a user pool, and a number of ztest runs on both. Everything seems fine in userspace.

I don't expect any difference on the in-kernel versions. I'll let the test suite decide if that's true.

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)
  • Library ABI change (libzfs, libzfs_core, libnvpair, libuutil and libzfsbootenv)
  • Documentation (a change to man pages or other documentation)

Checklist:

Copy link
Member

@amotin amotin left a comment

Choose a reason for hiding this comment

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

Looks like a good cleanup to me. Just few comments:

Comment on lines 64 to 69
/*
* Zero-sized means it will be used for a linear or gang abd, so just
* allaocate the abd itself and return.
*/
if (size == 0)
return (umem_alloc(sizeof (abd_t), UMEM_NOFAIL));
Copy link
Member

Choose a reason for hiding this comment

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

There is a typo in "allocate", but generally I am thinking is this special case even needed.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed the typo.

Until final testing last night, abd_iov was declared as [], so this made sense: for the zero case, we don't want the extra allocation. During testing, Clang complained that it couldn't embed a variable-sized structure into raidz_col_t.rc_abdstruct, so I changed it to [1], same as FreeBSD. Given that, every abd_t has at least one iovec, so you're right - the special case isn't needed, because we can't avoid allocating one iovec.

I took it out, but the comment below just had to be made more complicated to explain it. I think its easier to follow this way, so unless you feel strongly, I will leave it this way.

lib/libzpool/abd_os.c Outdated Show resolved Hide resolved
@robn robn force-pushed the abd-os-iovec branch 2 times, most recently from e126cf8 to 6e9c5c2 Compare June 7, 2024 21:55
@amotin amotin mentioned this pull request Jun 13, 2024
17 tasks
@robn robn force-pushed the abd-os-iovec branch 2 times, most recently from 6b2e012 to c80fa8e Compare July 20, 2024 05:08
@amotin
Copy link
Member

amotin commented Aug 6, 2024

@robn Seems failed to build:

In file included from ./include/sys/zio_compress.h:33,
                 from ./include/sys/dmu.h:50,
                 from ./include/sys/spa.h:45,
                 from ./include/sys/zio.h:39,
                 from ./include/sys/zio_checksum.h:31,
                 from module/zfs/zfs_impl.c:26:
./include/sys/abd.h:33:10: fatal error: sys/abd_os.h: No such file or directory
   33 | #include <sys/abd_os.h>
      |          ^~~~~~~~~~~~~~

@robn
Copy link
Member Author

robn commented Aug 7, 2024

@amotin not sure. Just pushed a rebase to master, and checked it builds in a fresh clone. I'll see what the builders make of it.

@robn
Copy link
Member Author

robn commented Aug 7, 2024

Oh, I see. The builders generate a package and build from that, and for some baffling reason I marked the new headers nodist_ so they weren't included in the package. Fixed in last push, lets see how that goes.

@behlendorf behlendorf added the Status: Code Review Needed Ready for review and testing label Aug 8, 2024
@behlendorf behlendorf self-requested a review August 8, 2024 23:58
robn added 5 commits August 17, 2024 13:43
Nothing ever checks it.

Sponsored-by: Klara, Inc.
Sponsored-by: Wasabi Technology, Inc.
Signed-off-by: Rob Norris <rob.norris@klarasystems.com>
Makes it harder to use memory debuggers like valgrind directly, because
they can't see canary overruns.

Sponsored-by: Klara, Inc.
Sponsored-by: Wasabi Technology, Inc.
Signed-off-by: Rob Norris <rob.norris@klarasystems.com>
The Linux abd_os.c serves double-duty as the userspace scatter abd
implementation, by carrying an emulation of kernel scatterlists. This
commit lifts common and userspace-specific parts out into a separate
abd_os.c for libzpool.

Sponsored-by: Klara, Inc.
Sponsored-by: Wasabi Technology, Inc.
Signed-off-by: Rob Norris <rob.norris@klarasystems.com>
Removing the platform #ifdefs from shared headers in favour of
per-platform headers. Makes abd_t much leaner, among other things.

Sponsored-by: Klara, Inc.
Sponsored-by: Wasabi Technology, Inc.
Signed-off-by: Rob Norris <rob.norris@klarasystems.com>
This is intended to be a simple userspace scatter abd based on struct
iovec. It's not very sophisticated as-is, but sets a base for something
much more interesting.

Sponsored-by: Klara, Inc.
Sponsored-by: Wasabi Technology, Inc.
Signed-off-by: Rob Norris <rob.norris@klarasystems.com>
@behlendorf behlendorf added Status: Accepted Ready to integrate (reviewed, tested) and removed Status: Code Review Needed Ready for review and testing labels Aug 21, 2024
behlendorf pushed a commit that referenced this pull request Aug 21, 2024
Makes it harder to use memory debuggers like valgrind directly, because
they can't see canary overruns.

Sponsored-by: Klara, Inc.
Sponsored-by: Wasabi Technology, Inc.
Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Rob Norris <rob.norris@klarasystems.com>
Closes #16253
behlendorf pushed a commit that referenced this pull request Aug 21, 2024
The Linux abd_os.c serves double-duty as the userspace scatter abd
implementation, by carrying an emulation of kernel scatterlists. This
commit lifts common and userspace-specific parts out into a separate
abd_os.c for libzpool.

Sponsored-by: Klara, Inc.
Sponsored-by: Wasabi Technology, Inc.
Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Rob Norris <rob.norris@klarasystems.com>
Closes #16253
behlendorf pushed a commit that referenced this pull request Aug 21, 2024
Removing the platform #ifdefs from shared headers in favour of
per-platform headers. Makes abd_t much leaner, among other things.

Sponsored-by: Klara, Inc.
Sponsored-by: Wasabi Technology, Inc.
Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Rob Norris <rob.norris@klarasystems.com>
Closes #16253
behlendorf pushed a commit that referenced this pull request Aug 21, 2024
This is intended to be a simple userspace scatter abd based on struct
iovec. It's not very sophisticated as-is, but sets a base for something
much more interesting.

Sponsored-by: Klara, Inc.
Sponsored-by: Wasabi Technology, Inc.
Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Rob Norris <rob.norris@klarasystems.com>
Closes #16253
lundman pushed a commit to openzfsonwindows/openzfs that referenced this pull request Sep 4, 2024
Nothing ever checks it.

Sponsored-by: Klara, Inc.
Sponsored-by: Wasabi Technology, Inc.
Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Rob Norris <rob.norris@klarasystems.com>
Closes openzfs#16253
lundman pushed a commit to openzfsonwindows/openzfs that referenced this pull request Sep 4, 2024
Makes it harder to use memory debuggers like valgrind directly, because
they can't see canary overruns.

Sponsored-by: Klara, Inc.
Sponsored-by: Wasabi Technology, Inc.
Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Rob Norris <rob.norris@klarasystems.com>
Closes openzfs#16253
lundman pushed a commit to openzfsonwindows/openzfs that referenced this pull request Sep 4, 2024
The Linux abd_os.c serves double-duty as the userspace scatter abd
implementation, by carrying an emulation of kernel scatterlists. This
commit lifts common and userspace-specific parts out into a separate
abd_os.c for libzpool.

Sponsored-by: Klara, Inc.
Sponsored-by: Wasabi Technology, Inc.
Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Rob Norris <rob.norris@klarasystems.com>
Closes openzfs#16253
lundman pushed a commit to openzfsonwindows/openzfs that referenced this pull request Sep 4, 2024
Removing the platform #ifdefs from shared headers in favour of
per-platform headers. Makes abd_t much leaner, among other things.

Sponsored-by: Klara, Inc.
Sponsored-by: Wasabi Technology, Inc.
Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Rob Norris <rob.norris@klarasystems.com>
Closes openzfs#16253
lundman pushed a commit to openzfsonwindows/openzfs that referenced this pull request Sep 4, 2024
This is intended to be a simple userspace scatter abd based on struct
iovec. It's not very sophisticated as-is, but sets a base for something
much more interesting.

Sponsored-by: Klara, Inc.
Sponsored-by: Wasabi Technology, Inc.
Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Rob Norris <rob.norris@klarasystems.com>
Closes openzfs#16253
lundman pushed a commit to openzfsonwindows/openzfs that referenced this pull request Sep 4, 2024
This is intended to be a simple userspace scatter abd based on struct
iovec. It's not very sophisticated as-is, but sets a base for something
much more interesting.

Sponsored-by: Klara, Inc.
Sponsored-by: Wasabi Technology, Inc.
Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Rob Norris <rob.norris@klarasystems.com>
Closes openzfs#16253
ptr1337 pushed a commit to CachyOS/zfs that referenced this pull request Nov 14, 2024
The Linux abd_os.c serves double-duty as the userspace scatter abd
implementation, by carrying an emulation of kernel scatterlists. This
commit lifts common and userspace-specific parts out into a separate
abd_os.c for libzpool.

Sponsored-by: Klara, Inc.
Sponsored-by: Wasabi Technology, Inc.
Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Rob Norris <rob.norris@klarasystems.com>
Closes openzfs#16253
ptr1337 pushed a commit to CachyOS/zfs that referenced this pull request Nov 14, 2024
Removing the platform #ifdefs from shared headers in favour of
per-platform headers. Makes abd_t much leaner, among other things.

Sponsored-by: Klara, Inc.
Sponsored-by: Wasabi Technology, Inc.
Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Rob Norris <rob.norris@klarasystems.com>
Closes openzfs#16253
ptr1337 pushed a commit to CachyOS/zfs that referenced this pull request Nov 21, 2024
The Linux abd_os.c serves double-duty as the userspace scatter abd
implementation, by carrying an emulation of kernel scatterlists. This
commit lifts common and userspace-specific parts out into a separate
abd_os.c for libzpool.

Sponsored-by: Klara, Inc.
Sponsored-by: Wasabi Technology, Inc.
Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Rob Norris <rob.norris@klarasystems.com>
Closes openzfs#16253
ptr1337 pushed a commit to CachyOS/zfs that referenced this pull request Nov 21, 2024
Removing the platform #ifdefs from shared headers in favour of
per-platform headers. Makes abd_t much leaner, among other things.

Sponsored-by: Klara, Inc.
Sponsored-by: Wasabi Technology, Inc.
Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Rob Norris <rob.norris@klarasystems.com>
Closes openzfs#16253
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.

3 participants