Skip to content

blk, os/bluestore: introduce huge page-based read buffers - #43849

Merged
yuriw merged 9 commits into
ceph:masterfrom
rzarzynski:wip-bs-lucky-buffers
Jan 14, 2022
Merged

yuriw merged 9 commits into
ceph:masterfrom
rzarzynski:wip-bs-lucky-buffers

Conversation

@rzarzynski

@rzarzynski rzarzynski commented Nov 8, 2021 •

Copy link
Copy Markdown
Contributor

Summary

This PR brings two facilities that enable efficient utilization of some NICs during large reads in BlueStore:

  1. configurable alignment for allocating read buffers in KernelDevice,
  2. allocation from a configurable pools of reusable buffers placed on huge pages.

These features allow to minimize the size of scatter-gather list a network hardware is provided with. For instance, on a system offering 2 MB pages, reading an entire RBD segment may require up to 2 different, non-contiguous regions of physical memory.

By default all these facilities are disabled and there shouldn't be flow difference in comparison to the current master.

The provided unit test requires a machine with HP available. I'm not sure we can assume this is always the case; if not, we can disable it by default.

Checklist

  • References tracker ticket
  • Updates documentation if necessary
  • Includes tests for new functionality or reproducer for bug

Show available Jenkins commands
  • jenkins retest this please
  • jenkins test classic perf
  • jenkins test crimson perf
  • jenkins test signed
  • jenkins test make check
  • jenkins test make check arm64
  • jenkins test submodules
  • jenkins test dashboard
  • jenkins test dashboard cephadm
  • jenkins test api
  • jenkins test docs
  • jenkins render docs
  • jenkins test ceph-volume all
  • jenkins test ceph-volume tox

@ifed01

ifed01 commented Dec 2, 2021

Copy link
Copy Markdown
Contributor

@rzarzynski - could you please add the rationales/goals for this PR in the description?

@ifed01

ifed01 commented Dec 2, 2021

Copy link
Copy Markdown
Contributor

And it would be great to have some test coverage in store_test if possible, please

@rzarzynski

Copy link
Copy Markdown
Contributor Author

@ifed01: sure, will add. Thanks for the review!

Comment thread src/blk/kernel/KernelDevice.cc Resolved
@github-actions

Copy link
Copy Markdown

This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved

@rzarzynski

Copy link
Copy Markdown
Contributor Author

Added unit testing & rebased. I will add a summary to PR's description basing on the commit messages in the morning.

@rzarzynski

Copy link
Copy Markdown
Contributor Author

jenkins retest this please

The following tests FAILED:
	236 - unittest-btree-lba-manager (Child aborted)

@rzarzynski

Copy link
Copy Markdown
Contributor Author

jenkins retest this please

Test failures:

	234 - unittest-seastar-errorator (Child aborted)

@rzarzynski

Copy link
Copy Markdown
Contributor Author

@ifed01: updated! Could you please take another look?

The aborts in the Seastar-related unit tests are addressed in #44532.

Comment thread src/blk/kernel/KernelDevice.cc Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why not starting exposure in buffer.h?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, probably making it public is the way to go.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Switched to create_small_page_aligned() which also avoids duplicating the constant.

Comment thread src/blk/kernel/KernelDevice.cc Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

IMO redundant

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed!

Comment thread src/blk/kernel/KernelDevice.cc Resolved
Comment thread src/blk/kernel/KernelDevice.cc Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

tag with override?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Tagged.

Comment thread src/blk/kernel/KernelDevice.cc Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

shouldn't we make this a bit more user friendly and permit ODS functioning after such a failure, e.g. using regular allocation mechanics?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is the setup code called once & early. I believe a user who wants to poke with such low-level things would like to see the failure as explicitly as possible; there is simply no business is requesting HP and falling back plain ones.

@ifed01 ifed01 Jan 11, 2022 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Well - that's questionable to me given the expected lack of proper documentation. IIUC one has to preconfigure large enough amount of HP in the system beforehand. Something like OSD_count * num_hp_per_osd. If something goes wrong along the way, e.g. OSD count is increased or some pages are allocated (or even leaked?) by different apps - user would get non-operational OSDs which might be tricky to fix for a one who is unaware of all the implementation details...
That's not very critical given this is disabled by default but I can easily imagine relevant questions/tickets.... ;)

@rzarzynski rzarzynski Jan 11, 2022 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If something goes wrong along the way, e.g. OSD count is increased or some pages are allocated (or even leaked?) by different apps - user would get non-operational OSDs which might be tricky to fix for a one who is unaware of all the implementation details...

Yes, this is nasty but nasty in the very explicit way. With the implicit fallback there could even worse scenario: somebody adds a new OSD and the fine-n-costly-tuned performance gets hit. Initially nobody notice as a cluster is underloaded but some time later the targeted peak load comes...
Chasing such a problem would be far harder than investigating an assertion failure, I think.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hmm, on the other hand maybe dout(0) / warning + extra sentence in the configurable's description would do? If somebody does such a tuning, he should have log monitoring as well?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

IMO the best way would be to raise cluster warning(alert) if something goes wrong here and proceed working. But may be a bit of overkill....

Comment thread src/common/options/global.yaml.in Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It would be nice to provide a description about what are the key and the value in this list. And some sample(s)...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Makes sense!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Improved comments and added an example.

Comment thread src/blk/kernel/KernelDevice.cc Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

isn't that too verbose? This will print at level 5 on each allocation if huge pool is disabled. And probably successful allocation logging above is too verbose as well...
IMO one should distinguish failed-to-allocate (important) and huge-pool-disabled (debug-only) cases and log accordingly.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Very likely is. Will retake a look on those debugs.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Moved everything to 20.

Comment thread src/common/options/global.yaml.in Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

does it really make any sense here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's useful when filling the store with data -- you want to avoid scattering over many small blobs.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sorry it's absolutely unclear from user perspective why this new parameter refers to bluestore_max_blob_size...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

So it deserves a comment! Will do.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Explained in the desc why bluestore_max_blob_size is needed.

Comment thread src/blk/kernel/KernelDevice.cc Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This doesn't look pretty elegant to me - it's rather an implicit side-effect that single huge page allocation causes no caching for the whole IO context... That's rather not critical but doubtful/questionable.
IMO it should be buffer's DO-NOT-CACHE (or RELEASE-ASAP) property not IO context one
May be there are any ideas how to fix that?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed. It's a compromise that takes into account the burden on interfaces the per-buffer flag would bring.
I'm sincerely open to a better solution.

Comment thread src/test/objectstore/store_test.cc Outdated

@ifed01 ifed01 Jan 11, 2022 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Would this test case work properly if huge pages are disabled at the host? I presume it wouldn't due to assertion/abort at ExplicitHugePagePool's ctor.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No, it won't. Commented on that in the PR's description.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

so this would rather fail the general QA testing. Not to mention private dev runs... IMO we should have automatic disablement of it then....

@rzarzynski rzarzynski Jan 11, 2022 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Well, I was and still am afraid of that. Though, my dev env. offered HP support out-of-the-box and I was curious even about the nodes serving make check. It looks they are fine. Therefore I'm having mixed feelings.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Disabled by default; commented why.

@rzarzynski
rzarzynski force-pushed the wip-bs-lucky-buffers branch from 10c4b9b to 50a37ac Compare January 12, 2022 14:34
The idea here is to bring a pool of `mmap`-allocated,
constantly-sized buffers which would take precedence
over the 2 MB-aligned, THP-based mechanism. On first
attempt to acquire a 4 MB buffer, KernelDevice mmaps
`bdev_read_preallocated_huge_buffer_num` (default 128)
memory regions using the MAP_HUGETLB option. If this
fails, the entire process is aborted. Buffers, after
their life-times going over, are recycled with lock-
free queue shared across entire process.

Remember about allocating the appropriate number of
huge pages in the system! For instance:

```
echo 256 | sudo tee /proc/sys/vm/nr_hugepages
```

This commit bases on / cherry-picks with changes
897a493.

Signed-off-by: Radoslaw Zarzynski <[email protected]>
When testing remember about `bluestore_max_blob_size` as it's
only 64 KB by default while the entire huge page-based pools
machinery targets far bigger scenrios (initially 4 MB!).

Signed-off-by: Radoslaw Zarzynski <[email protected]>
We're going to reuse it outside `test/bufferlist.cc`.

Signed-off-by: Radoslaw Zarzynski <[email protected]>
Its initial user will be a unit test for BlueStore's huge
paged-backed reading.

Signed-off-by: Radoslaw Zarzynski <[email protected]>
@rzarzynski
rzarzynski force-pushed the wip-bs-lucky-buffers branch from 50a37ac to 62650c2 Compare January 12, 2022 20:36
@rzarzynski

Copy link
Copy Markdown
Contributor Author

@ifed01: just rebased to include the fix the crimson's unit testing. Ready for re-review!

@amathuria

Copy link
Copy Markdown
Contributor

@yuriw
yuriw merged commit 31ff495 into ceph:master Jan 14, 2022
@wjwithagen

Copy link
Copy Markdown
Member

@rzarzynski
'mmmm
Just got a nice challenge to Fix this for not working on FreeBSD.

/home/jenkins/workspace/ceph-master-compile/src/blk/kernel/KernelDevice.cc:1081:39: error: use of undeclared identifier 'MAP_POPULATE'
        MAP_PRIVATE | MAP_ANONYMOUS | MAP_POPULATE | MAP_HUGETLB,
                                      ^
/home/jenkins/workspace/ceph-master-compile/src/blk/kernel/KernelDevice.cc:1081:54: error: use of undeclared identifier 'MAP_HUGETLB'
        MAP_PRIVATE | MAP_ANONYMOUS | MAP_POPULATE | MAP_HUGETLB,
                                             

The first is probably from a missing FreeBSD specific include file, since it is known in mmap(2).
What would happen if I remove the MAP_HUGETLB from the mmap() call?
Would all the other code still do the right thing?

Otherwise I'll have I could wiggle it with MAP_ALIGNED_SUPER to get huge page allignment.
Last I would like to do is undo all this for FreeBSD.

@rzarzynski

Copy link
Copy Markdown
Contributor Author

@wjwithagen: thanks for bringing this up!

MAP_POPULATE is Linux-specific too. However, it's absence isn't a big deal as, IIUC, all it does is populating pages with frames immediately. I guess we could mimic that with just a memset to these regions.

MAP_HUGETLB is essential on Linux but, according to a discussion, FreebSD has a different, more-automated mechanism. MAP_ALIGNED_SUPER looks useful for handling the situation where the number of huge pages is not enough.

I will make a fix but will need help with testing as I'm missing a FreeBSD dev env :-(.

@wjwithagen

Copy link
Copy Markdown
Member

@rzarzynski
I agree with your anaylis, and I think this would almost get the same effect.
Thing I'm a bit worried about is wether it will error/softfail in the same way...
When the only thing is that the pages are not preread, but paged in, and causing a perfomance penalty, that is not too bad.
Other/wierder issues might be hard to detect.

ATM I replace those 2 with:

--- a/src/blk/kernel/KernelDevice.cc
+++ b/src/blk/kernel/KernelDevice.cc
@@ -1078,7 +1078,7 @@ struct ExplicitHugePagePool {
         nullptr,
         buffer_size,
         PROT_READ | PROT_WRITE,
-        MAP_PRIVATE | MAP_ANONYMOUS | MAP_POPULATE | MAP_HUGETLB,
+        MAP_PRIVATE | MAP_ANONYMOUS | MAP_PREFAULT_READ | MAP_ALIGNED_SUPER,
         -1,
         0);
       if (mmaped_region == MAP_FAILED) {

And that compiles, and all my test run oke.
But then I do not excersise the BlueStore too much, since that PR still needs work and be accepted. (my bad)

@rzarzynski

Copy link
Copy Markdown
Contributor Author

Created #44612 to address the FTBFS while – hopefully (no testing env :-(, unfortunately) – preserving the huge page-backed read buffers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants