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

Check that THP is not set to always (madvise is ok) #4001

Merged
merged 1 commit into from
Sep 9, 2020
Merged

Check that THP is not set to always (madvise is ok) #4001

merged 1 commit into from
Sep 9, 2020

Conversation

badboy
Copy link
Contributor

@badboy badboy commented May 15, 2017

THP can also be set to madvise, in which case it shouldn't cause
problems for Redis.

Fixes #3895

@reneklacan
Copy link

@badboy @antirez should this be merged?

@antirez
Copy link
Contributor

antirez commented Jul 24, 2017

Thanks @badboy, please could you make != NULL explicit? Otherwise certain compiler versions may complain with a warning.

THP can also be set to madvise, in which case it shouldn't cause
problems for Redis.

Fixes #3895
@badboy
Copy link
Contributor Author

badboy commented Jul 24, 2017

Force-pushed with the changes.

@volkertb
Copy link

volkertb commented Oct 24, 2017

@badboy Wait a minute. According to this blog at DigitalOcean, using Redis with madvise actually caused memory release problems: https://blog.digitalocean.com/transparent-huge-pages-and-alternative-memory-allocators/

Wouldn't that mean that both "enabled" and "madvise" are problematic options and that the current warning as shown by Redis (with the recommendation to completely disable THP by setting it to "never") is actually justified? Or did I misread the blog?

@badboy
Copy link
Contributor Author

badboy commented Oct 24, 2017

From my limited understanding of madvise it should work. I have not (yet) read the DO blog post though.

@badboy
Copy link
Contributor Author

badboy commented Oct 24, 2017

@volkertb I read the article and the problem there is caused by huge-pages, not by the madvise setting for THP.
/sys/kernel/mm/transparent_hugepage/enabled allows for three settings:

  • always:: Always use THP
  • never: Never use THP
  • madvise: Let user programs opt-in to THP using the madvise functions with the MADV_HUGEPAGE flag. See madvise(2).

As neither Redis nor the bundled jemalloc will use the MADV_HUGEPAGE flag, Redis won't use THP.

@volkertb
Copy link

volkertb commented Nov 3, 2017

OK, thanks for checking and clarifying this, @badboy. I hope this pull request gets reviewed and approved soon. 🙂

@minus7
Copy link

minus7 commented Nov 28, 2017

With the kernel option set to madvise, khugepaged will still be running and possibly cause latency issues. Thus checking for [never] might actually make sense.

Another thing: why are the server and the latency report using different ways to detect THP?

@antirez
Copy link
Contributor

antirez commented Nov 29, 2017

Based on this thread I would rather be strict than wrong and leave things as they are, requiring [never]...

@wbolster
Copy link

i think @badboy is correct and that this pr can be merged as-is.

when the setting is set to madvise, applications must opt-in. redis does not opt-in. that means that the warning only makes sense when the setting is set to always. and this pr changes exactly that.

@aguilarm
Copy link

Ran across this when adding redis to a kubernetes cluster. Since it's a host/node level modification I would prefer using [madvise] as the host may be home to many more processes than redis.

@volkertb
Copy link

So that means this PR can now be merged, right? Or does it still require additional code reviews?

@akumria
Copy link

akumria commented May 23, 2018

@antirez Is the decision to leave this open then? Personally I've had customers ask about the message (when the value is set to 'madvise'). It is annoying THP doesn't impact redis (or jemalloc) and the theory that hugepaged causes latency issues when 'madvise' is set, is just that.

Theory.

There is no information, that I am aware of, that having the value set to 'madvise' and there being no THP consumers can cause a latency issue in redis.

@minus7
Copy link

minus7 commented May 25, 2018

Assuming whoever changes the kernel config to madvise knows what they're doing, only showing the message when set to always seems fine. Maybe adjust the message with a hint about madvise.

@czka
Copy link

czka commented Nov 14, 2018

I wonder how Google solved this for their "Memorystore" https://cloud.google.com/memorystore/docs/redis/. Maybe Redis team could leverage their Google Cloud partnership https://redislabs.com/partner/google/ and share the information?

FWIW, the 190 Google Container Engine VMs I checked (COS images) all have /sys/kernel/mm/transparent_hugepage/enabled set to madvise. I don't want to change this blindly to never and risk side effects for other workloads only to satisfy a (probably incorrect?) Redis hint about never being the only setting allowed.

@gjcarneiro
Copy link

Could redis maybe use this option?

       MADV_NOHUGEPAGE (since Linux 2.6.38)
              Ensures that memory in the address range specified by addr and
              length will not be collapsed into huge pages.

This way, even if THP is always,it should in theory disable hugepages for redis memory allocations?...

@hyperknot
Copy link

So what is the conclusion of this? Is the DO blog post valid for normal use cases? Like a stock Ubuntu 18.04 install?

Since Ubuntu 18.04 madvise is the default both for transparent_hugepage/enabled and /defrag, and configuring it is really not simple anymore (no rc.local supplied, systemd unit needs to be created), it'd be a huge help for installlations if the default madvise could be used.

@oranagra
Copy link
Member

oranagra commented Sep 6, 2020

@badboy considering the feedback we got from Jason in #3895 (comment)
do you wanna complement this PR ans also change the text that suggests:
echo never > /sys/kernel/mm/transparent_hugepage/enabled

@oranagra oranagra added the state:to-be-merged The PR should be merged soon, even if not yet ready, this is used so that it won't be forgotten label Sep 6, 2020
@oranagra oranagra changed the title Check that THP is always enabled Check that THP is not set to always (madvise is ok) Sep 9, 2020
@oranagra oranagra merged commit b2419c3 into redis:unstable Sep 9, 2020
SuperSandro2000 added a commit to SuperSandro2000/nixpkgs that referenced this pull request Apr 3, 2024
Since redis/redis#4001 included in 6.2.0
transparent hugepages works when being set to madvise which is the NixOS
and upstream recommended default.
SuperSandro2000 added a commit to SuperSandro2000/nixpkgs that referenced this pull request Apr 3, 2024
Since redis/redis#4001 included in 6.2.0
transparent hugepages works when being set to madvise which is the NixOS
and upstream recommended default.
SuperSandro2000 added a commit to SuperSandro2000/nixpkgs that referenced this pull request Apr 3, 2024
Since redis/redis#4001 included in 6.2.0
transparent hugepages works when being set to madvise which is the NixOS
and upstream recommended default.
SuperSandro2000 added a commit to SuperSandro2000/nixpkgs that referenced this pull request Apr 3, 2024
Since redis/redis#4001 included in 6.2.0
transparent hugepages works when being set to madvise which is the NixOS
and upstream recommended default.
SuperSandro2000 added a commit to SuperSandro2000/nixpkgs that referenced this pull request Apr 4, 2024
Since redis/redis#4001 included in 6.2.0
transparent hugepages works when being set to madvise which is the NixOS
and upstream recommended default.
SuperSandro2000 added a commit to SuperSandro2000/nixpkgs that referenced this pull request Apr 4, 2024
Since redis/redis#4001 included in 6.2.0
transparent hugepages works when being set to madvise which is the NixOS
and upstream recommended default.
SuperSandro2000 added a commit to SuperSandro2000/nixpkgs that referenced this pull request Apr 4, 2024
Since redis/redis#4001 included in 6.2.0
transparent hugepages works when being set to madvise which is the NixOS
and upstream recommended default.
SuperSandro2000 added a commit to SuperSandro2000/nixpkgs that referenced this pull request Apr 7, 2024
Since redis/redis#4001 included in 6.2.0
transparent hugepages works when being set to madvise which is the NixOS
and upstream recommended default.
SuperSandro2000 added a commit to SuperSandro2000/nixpkgs that referenced this pull request Apr 10, 2024
Since redis/redis#4001 included in 6.2.0
transparent hugepages works when being set to madvise which is the NixOS
and upstream recommended default.
SuperSandro2000 added a commit to SuperSandro2000/nixpkgs that referenced this pull request Apr 11, 2024
Since redis/redis#4001 included in 6.2.0
transparent hugepages works when being set to madvise which is the NixOS
and upstream recommended default.
SuperSandro2000 added a commit to SuperSandro2000/nixpkgs that referenced this pull request Apr 12, 2024
Since redis/redis#4001 included in 6.2.0
transparent hugepages works when being set to madvise which is the NixOS
and upstream recommended default.
SuperSandro2000 added a commit to SuperSandro2000/nixpkgs that referenced this pull request Apr 14, 2024
Since redis/redis#4001 included in 6.2.0
transparent hugepages works when being set to madvise which is the NixOS
and upstream recommended default.
SuperSandro2000 added a commit to SuperSandro2000/nixpkgs that referenced this pull request Apr 17, 2024
Since redis/redis#4001 included in 6.2.0
transparent hugepages works when being set to madvise which is the NixOS
and upstream recommended default.
SuperSandro2000 added a commit to SuperSandro2000/nixpkgs that referenced this pull request Apr 17, 2024
Since redis/redis#4001 included in 6.2.0
transparent hugepages works when being set to madvise which is the NixOS
and upstream recommended default.
SuperSandro2000 added a commit to SuperSandro2000/nixpkgs that referenced this pull request Apr 17, 2024
Since redis/redis#4001 included in 6.2.0
transparent hugepages works when being set to madvise which is the NixOS
and upstream recommended default.
SuperSandro2000 added a commit to SuperSandro2000/nixpkgs that referenced this pull request Apr 17, 2024
Since redis/redis#4001 included in 6.2.0
transparent hugepages works when being set to madvise which is the NixOS
and upstream recommended default.
SuperSandro2000 added a commit to SuperSandro2000/nixpkgs that referenced this pull request Apr 17, 2024
Since redis/redis#4001 included in 6.2.0
transparent hugepages works when being set to madvise which is the NixOS
and upstream recommended default.
SuperSandro2000 added a commit to SuperSandro2000/nixpkgs that referenced this pull request Apr 20, 2024
Since redis/redis#4001 included in 6.2.0
transparent hugepages works when being set to madvise which is the NixOS
and upstream recommended default.
SuperSandro2000 added a commit to SuperSandro2000/nixpkgs that referenced this pull request Apr 21, 2024
Since redis/redis#4001 included in 6.2.0
transparent hugepages works when being set to madvise which is the NixOS
and upstream recommended default.
SuperSandro2000 added a commit to SuperSandro2000/nixpkgs that referenced this pull request Apr 22, 2024
Since redis/redis#4001 included in 6.2.0
transparent hugepages works when being set to madvise which is the NixOS
and upstream recommended default.
SuperSandro2000 added a commit to SuperSandro2000/nixpkgs that referenced this pull request Apr 25, 2024
Since redis/redis#4001 included in 6.2.0
transparent hugepages works when being set to madvise which is the NixOS
and upstream recommended default.
SuperSandro2000 added a commit to SuperSandro2000/nixpkgs that referenced this pull request Apr 25, 2024
Since redis/redis#4001 included in 6.2.0
transparent hugepages works when being set to madvise which is the NixOS
and upstream recommended default.
SuperSandro2000 added a commit to SuperSandro2000/nixpkgs that referenced this pull request Apr 25, 2024
Since redis/redis#4001 included in 6.2.0
transparent hugepages works when being set to madvise which is the NixOS
and upstream recommended default.
SuperSandro2000 added a commit to SuperSandro2000/nixpkgs that referenced this pull request Apr 25, 2024
Since redis/redis#4001 included in 6.2.0
transparent hugepages works when being set to madvise which is the NixOS
and upstream recommended default.
SuperSandro2000 added a commit to SuperSandro2000/nixpkgs that referenced this pull request Apr 27, 2024
Since redis/redis#4001 included in 6.2.0
transparent hugepages works when being set to madvise which is the NixOS
and upstream recommended default.
SuperSandro2000 added a commit to SuperSandro2000/nixpkgs that referenced this pull request Apr 28, 2024
Since redis/redis#4001 included in 6.2.0
transparent hugepages works when being set to madvise which is the NixOS
and upstream recommended default.
SuperSandro2000 added a commit to SuperSandro2000/nixpkgs that referenced this pull request Apr 28, 2024
Since redis/redis#4001 included in 6.2.0
transparent hugepages works when being set to madvise which is the NixOS
and upstream recommended default.
SuperSandro2000 added a commit to SuperSandro2000/nixpkgs that referenced this pull request Apr 28, 2024
Since redis/redis#4001 included in 6.2.0
transparent hugepages works when being set to madvise which is the NixOS
and upstream recommended default.
SuperSandro2000 added a commit to SuperSandro2000/nixpkgs that referenced this pull request Apr 28, 2024
Since redis/redis#4001 included in 6.2.0
transparent hugepages works when being set to madvise which is the NixOS
and upstream recommended default.
WGUNDERWOOD pushed a commit to WGUNDERWOOD/nixpkgs that referenced this pull request Jul 6, 2024
Since redis/redis#4001 included in 6.2.0
transparent hugepages works when being set to madvise which is the NixOS
and upstream recommended default.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
safe-to-merge state:to-be-merged The PR should be merged soon, even if not yet ready, this is used so that it won't be forgotten
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Transparent Huge Pages (THP) warning should not print when madvise selected