Forum Jump

Select Group :
Select Forum :
Sorted By :
Sort Order :
From The :
 
Thread Tools  Search this thread 
t.redeske
Total Points:
95
Status Points:
45
Green Belt
November 6, 2009 6:03 AM PST
huge pages on linux?
Our team is interested in using the TBB memory allocation library on linux.  Is there a way to have this library use huge pages instead of 4k pages?
Dmitriy Vyukov
Total Points:
25,382
Status Points:
25,382
Black Belt
November 6, 2009 6:23 AM PST
Rate
 
|Best Answer
#1
Quoting - t.redeske
Our team is interested in using the TBB memory allocation library on linux.  Is there a way to have this library use huge pages instead of 4k pages?

There is no support for large pages currently. However I believe one can add it quite easily. All one has to do is:
1. set up mmapRequestSize to large page size (2MB or whatever it is on your system):
static size_t mmapRequestSize = 0x0100000;
2. patch getRawMemory() function to allocate large pages.
3. patch freeRawMemory() function to free large pages.
That's it.
Since current raw block size used by TBB is 1MB which is quite close to size of large pages (2MB), I think one may leave allocation algorithm itself as-is.



Dmitriy Vyukov
Total Points:
25,382
Status Points:
25,382
Black Belt
November 6, 2009 6:26 AM PST
Rate
 
#2
Quoting - t.redeske
Our team is interested in using the TBB memory allocation library on linux.  Is there a way to have this library use huge pages instead of 4k pages?

Btw, are large pages are useful on Linux?
I've found that they are completely useless on Windows. Right after system boot I am able to allocate about hundred large pages, but after ten minutes of work I am unable to allocate any large pages. Windows ungracefully fragments physical memory so that there is just no space for large pages. (I tested on Windows Vista)



jimdempseyatthecove
Total Points:
36,092
Status Points:
36,092
Black Belt
November 6, 2009 8:11 AM PST
Rate
 
#3 Reply to #2
Quoting - Dmitriy Vyukov

Btw, are large pages are useful on Linux?
I've found that they are completely useless on Windows. Right after system boot I am able to allocate about hundred large pages, but after ten minutes of work I am unable to allocate any large pages. Windows ungracefully fragments physical memory so that there is just no space for large pages. (I tested on Windows Vista)


Dmitriy,

Maybe things are OK when you have 128GB of physical RAM? (or some other "large" ammount of physical RAM).

Jim

--------

Blog: The Parallel Void


www.quickthreadprogramming.com


Alexey Kukanov (Intel)
Total Points:
13,376
Status Points:
13,376
Black Belt
November 6, 2009 9:18 AM PST
Rate
 
#4
Quoting - t.redeske
Our team is interested in using the TBB memory allocation library on linux.  Is there a way to have this library use huge pages instead of 4k pages?

Maybe I miss some point, but it seems to me that the way TBB allocator works does not depend on the page size. It just relies on OS mechanisms that map physical memory into virtual address space, and is agnostic of the details of mapping such as pages. If I am mistaken and there are some problems with the allocator when large pages are enabled, I would like to know about that.

t.redeske
Total Points:
95
Status Points:
45
Green Belt
November 6, 2009 10:04 AM PST
Rate
 
#5 Reply to #1
Quoting - Dmitriy Vyukov

There is no support for large pages currently. However I believe one can add it quite easily. All one has to do is:
1. set up mmapRequestSize to large page size (2MB or whatever it is on your system):
static size_t mmapRequestSize = 0x0100000;
2. patch getRawMemory() function to allocate large pages.
3. patch freeRawMemory() function to free large pages.
That's it.
Since current raw block size used by TBB is 1MB which is quite close to size of large pages (2MB), I think one may leave allocation algorithm itself as-is.


This is in the TBB source code?  I haven't looked at that as of yet.  Does TBB use mmap to get more memory?  With TC malloc, it is possible to set an env variable to tell it where to mmap memory from, which makes it easy to hook up to huge pages.


t.redeske
Total Points:
95
Status Points:
45
Green Belt
November 6, 2009 10:11 AM PST
Rate
 
#6 Reply to #2
Quoting - Dmitriy Vyukov

Btw, are large pages are useful on Linux?
I've found that they are completely useless on Windows. Right after system boot I am able to allocate about hundred large pages, but after ten minutes of work I am unable to allocate any large pages. Windows ungracefully fragments physical memory so that there is just no space for large pages. (I tested on Windows Vista)


They are very useful if you have a long running process that starts soon after boot and stays running a long time.  We've seen 5 - 25% performance improvements using them.

t.redeske
Total Points:
95
Status Points:
45
Green Belt
November 6, 2009 10:16 AM PST
Rate
 
#7 Reply to #4

Maybe I miss some point, but it seems to me that the way TBB allocator works does not depend on the page size. It just relies on OS mechanisms that map physical memory into virtual address space, and is agnostic of the details of mapping such as pages. If I am mistaken and there are some problems with the allocator when large pages are enabled, I would like to know about that.

In order to use huge pages, you have to tell the OS to reserve some.  Then, your program has to specially ask for them.  libhugetlbfs can be used to have malloc() and other calls allocate from huge pages.  The following link shows details: http://www.ibm.com/developerworks/systems/library/es-lop-leveragepages/

We would like to combine the performance boost we get from huge pages with the boost we get from TBB.

t.redeske
Total Points:
95
Status Points:
45
Green Belt
November 6, 2009 11:06 AM PST
Rate
 
#8 Reply to #1
Quoting - Dmitriy Vyukov

There is no support for large pages currently. However I believe one can add it quite easily. All one has to do is:
1. set up mmapRequestSize to large page size (2MB or whatever it is on your system):
static size_t mmapRequestSize = 0x0100000;
2. patch getRawMemory() function to allocate large pages.
3. patch freeRawMemory() function to free large pages.
That's it.
Since current raw block size used by TBB is 1MB which is quite close to size of large pages (2MB), I think one may leave allocation algorithm itself as-is.


In looking at the code, I can see what to do - I'll need to change the mmap calls.  It would be great if the next version would allow the setting of an ENV variable to dictate where to mmap from so that huge pages could be mapped in with no code changes.  This would also need a change to the mmapRequestSize (by ENV variable or otherwise).

Alexey Kukanov (Intel)
Total Points:
13,376
Status Points:
13,376
Black Belt
November 7, 2009 12:31 AM PST
Rate
 
#9 Reply to #7
Quoting - t.redeske
In order to use huge pages, you have to tell the OS to reserve some.  Then, your program has to specially ask for them.  libhugetlbfs can be used to have malloc() and other calls allocate from huge pages.  The following link shows details: http://www.ibm.com/developerworks/systems/library/es-lop-leveragepages/

We would like to combine the performance boost we get from huge pages with the boost we get from TBB.

Oh, I see - the problem is in the need to specially ask for large pages. I thought that it would be enough to just say the program wants to use large pages. Do you know if Windows operates the same way in this regard?

And, could you please enter a feature request into our bug tracker?



Intel Software Network Forums Statistics

8435 users have contributed to 31536 threads and 100341 posts to date.
In the past 24 hours, we have 24 new thread(s) 104 new posts(s), and 141 new user(s).

In the past 3 days, the most popular thread for everyone has been Strange results from operator overloading The most posts were made to IVF 11.1.051 freezes during build The post with the most views is Can you show us a test case?

Please welcome our newest member dearjason