Cycles: Test Embree huge pages #117175
Labels
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
5 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#117175
Loading…
Reference in New Issue
No description provided.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
In #116663 huge pages were enabled in jemalloc on Linux, which helps for Embree too.
But Embree also has its own option, which may or may not provide additional benefit. This is to be tested.
https://github.com/embree/embree/blob/master/doc/src/api.md#huge-page-support
On Windows it is also possible to use huge pages, but this requires Blender to run in elevated mode. However it means memory can't be paged out. While an option to enable it could be added, it seems too obscure to be worth it.
Hey Brecht, I'd like to try this out if you don't mind.
Sure, you can try it. Did you want to check this for Windows or Linux?
Hey Brecht, I checked out #116663 and understood huge pages, to enable huge pages we need to pass 'hugepages=1' in 'rtcNewDevice' (which is a function) , but I was not able to find the files where Embree was included to pass the parameter value(I tried finding it in blender/source/blender and blender/intern/cycles), also I am checking for Linux, as I just set it up on my PC and this is my first good first issue.
I assume we need to install Embree and add it to Blender ourselves. I also built Blender for Linux but I have Windows dual-booted so I can test this out on Windows too if needed.
Blender builds with Embree by default, it is included in the precompiled libraries. It should be possible to find
rtcNewDevice
by searching the code, with grep or search functionality in an IDE.I don't think this is a good idea, huge pages on windows cannot be paged out, which is i suppose a performance benefit, but having a single memory hungry process on the system, that can't be paged out feels like a bad idea to automatically enable. i could live with a cli switch i suppose, but automatic seems like a bit of an over reach.
I was not aware of that, indeed we should not do this on Windows then.
Ah, thanks for the heads up.
I took a closer look here, and it seems someone already did the tbbmalloc changes required to support this [1]. I applied the patch to our copy of tbb and build a new
tbbmalloc.dll
I'm in no way set up to run any kind of repeatable performance benchmark though, so beyond validating large pages are actually being allocated i can't really say if there is a performance benefit or not.
To test:
Make sure your user has the
Lock pages in memory
privilege in the local security policy [2]. If you just assigned this privilege you need to logoff or reboot otherwise the new policy will not apply.Replace blenders
tbbmalloc.dll
with the copy attached to this post.Open up a command prompt with administrator privileges
Run
set TBBMALLOC_USE_HUGE_PAGES=1
Run blender from this same command prompt
Validate with rammap [3] large pages are allocated.
[1] https://github.com/oneapi-src/oneTBB/compare/master...Hardcode84:oneTBB:huge-pages-win
[2] https://learn.microsoft.com/en-us/windows/security/threat-protection/security-policy-settings/lock-pages-in-memory
[3] https://learn.microsoft.com/en-us/sysinternals/downloads/rammap
(For Linux) Well, I understood what I need to do, as in Linux huge pages are enabled by default, I need to check it with disabling THP using ' echo /sys/kernel/mm/transparent_hugepage/disabled ' and compare timings for both enabled and disabled THP using the ' huge_page_test.cc ' given in #116663, but I do not know how to unit test, so I'll try to learn it.
(Linux)
I tried to recreate Eugene's benchmark and may or may not see a speedup with Embree.
I ran his command although I could not figure out how to run it as 4 samples per pixel:
time ./build_linux/bin/blender -b monkey_test.blend -a -- --cycles-device CPU
I enabled Embree thp by:
echo always > /sys/kernel/mm/transparent_hugepage/enabled
restart
and disabled Embree thp by:
echo never > /sys/kernel/mm/transparent_hugepage/enabled
restart
I tried to disable jemalloc thp by undoing commit
10dfa07e36
Could not figure out how to recreate @brecht 's cycles cpu rendering benchmark with these conditions.
Is this on the right track?
It's not really what I meant for this task.
It's a bit confusing because the Embree docs contain some information about how to change the system settings to enable huge pages. But there is nothing Embree specific about, and we can't change those system settings from Blender.
What I wanted to investigate is if enabling huge pages in the
rtcNewDevice
call provides any additional benefit over jemalloc huge pages. It likely does not provide a benefit, but I wanted to check to be sure.Took a closer look. Embree calls
mmap
(linux/mac) andVirtualAlloc
(windows) directly for its memory management, bypassing jemalloc / tbbmalloc so i'm expecting it to make a difference.I see, I seem to have misunderstood some things. Are the benchmark tests that I ran the right idea or how should we do that?
I looked at testing for Windows mentioned above by following the steps in that comment. Though had some trouble building Blender on Windows.
Just to get some information out, primarily for @holly-l . Linux supports an option called "Transparent Huge Pages". With this feature enabled, the Linux kernel will try to combine the normal 4KB pages into 2MB pages. This can improve performance in some applications, and this can be enabled with
sudo echo always > /sys/kernel/mm/transparent_hugepage/enabled
. Enabling and disabling this is practically out of the control of the Blender foundation, and so it's not worth testing here.An application also has the option to direclty allocate huge pages. So instead of the app creating 4KB pages and the kernel combining them into 2MB pages, the app just creates 2MB pages. This is the feature we want to test. And Embree has an option for this.
It seems like to let Embree directly allocate 2MB huge pages on Linux, you need to create a "huge page pool" (run
echo number_of_huge_pages_in_pool > /proc/sys/vm/nr_overcommit_hugepages
as root) So if you want 1000 pages in that pool (roughly 2GB of avaliable space for Embree to allocate into), then you need to runecho 1000 > /proc/sys/vm/nr_overcommit_hugepages
. And then you need to tell Embree to use huge pages (which the Embree readme claims is enabled by default for Linux).But just so it's clear. To tell Embree to use or not to use huge pages, you need to pass
hugepages=1
orhugepages=0
tortcNewDevice
in the Cycles code. An example of how to do this can be found here:f5d09cce0c
There might be something I'm missing. So please correct me if I'm wrong.
How would you test this? Assuming the Embree readme is right, there's no point testing this on Linux. Huge pages offers a performance boost, and it's enabled by default on Linux. Nothing needs to be done on the Blender/Cycles side.
But if the Embree readme is wrong, or you just want to test this on Linux then you need too:
hugepages=1
inrtcNewDevice
. This is your version of Blender for testing huge pages.hugepages=0
inrtcNewDevice
. This is your version of Blender for testing without huge pages.echo 1000 > /proc/sys/vm/nr_overcommit_hugepages
as root).Testing should consist of:
Here's some scenes you can use for testing:
I should note that Blender does come with a benchmark script for automatically benchmarking different Blender versions with the Cycles benchmark files. Information about it can be found here: https://developer.blender.org/docs/handbook/testing/performance/
And lastly report your results.
I ran some quick tests on Windows using the Cycles benchmark files. And I could be doing something wrong. With huge pages I saw a average performance increase of 0.68%. The maximum performance increase was 2.04%. And only one scene saw a performance deficient of 0.05%.
I should note that it seems the tools to enable huge pages on Windows is limited to Pro editions and higher. Which once again limits the availability of huge pages on Windows.
Hardware used for testing:
CPU: AMD Ryzen 5 5600
RAM: 32GB of 3200mhz DDR4 RAM (unsure of timings)
Thanks for the explanation and test.
Comparing render times on a few scenes is fine, they just have to be complicated enough like the benchmark ones we use. Small scenes may fit entirely in the cache and would not get much benefit from this change.
For the Windows performance impact, hard to say if anything was wrong in that test. It's quite possible the impact is really that small. If so it's not worth adding support for that.
I did some testing for Linux using the Cycles benchmark files.
The Embree readme is correct. Hugepages is enabled on Linux, even if you don't explictly request for hugepages to be enabled. This can be verified with
grep -i HugePages_Total /proc/meminfo
while running a Cycles render on an unmodified main version of Blender (requires a hugepage pool to be setup).Even with that, performance seems to be different between
rtcNewDevice("verbose=0")
andrtcNewDevice("hugepages=1,verbose=0")
(they're supposed to be the same since hugepages is enabled on both). Typicallyhugepages=1,verbose=0
is faster.Finally performance:
With
rtcNewDevice("verbose=0")
(as found in main), It provides a 0.15% performance uplift on average over explicitly disabling hugepages. The max performance uplift was 1.13%. And some scenes saw a performance deficit, with the worse being 0.72%.With
rtcNewDevice("hugepages=1,verbose=0")
, It provides a 0.50% performance uplift on average over explicitly disabling hugepages. The max performance uplift was 1.67%. And some scenes saw a performance deficit, with the worse being 1.11%.Hardware used for testing:
CPU: AMD Ryzen 5 5600
RAM: 32GB of 3200mhz DDR4 RAM (unsure of timings)
Thanks for the tests. If it's 0.5% and it's worse in some files, I think it's too small to be a clear win, and may depend more on specifics of the scene and coincidences in favorable memory layout. So I would just stay with the jemalloc huge pages then.
@Alaska I looked at your explanation and found it to be very clear. Thanks.