Skip to contentSkip to conversation

objrmap and nonlinear vma:s

DISCUSSION Magnus Damm 3 participants 5 messages Oct 25, 2004 Memory management

lore
Share & tools
lore
#0 lore raw

Hello all,

I am currently investigating how to unmap a physical page belonging to a nonlinear file backed vma.

By studying the 2.6.9 source code and by reading the excellent VMM book by Mel Gorman I believe that:

- physical pages belonging to linear file backed vma:s are currently reverse mapped using the prio_tree i_mmap.

- physical pages belonging to nonlinear file backed vma:s are currently reverse mapped using the linked list i_mmap_nonlinear.

Please let me know if something above is incorrect.

The reverse mapping code for nonlinear vma:s does not seem to scale very well today with the linked list implementation. It seems to me that the assumption is made that the number of users of nonlinear vma:s are few and that they probably not very often want do anything resulting in a reverse mapping operation.

Some questions:

1) Is everyone happy with the solution today? Is the linked list implementation fast enough? It seems to me that the nonlinear code in try_to_unmap_file() is good enough for swap but does not always unmap the requested page. This behavior is not very suitable for memory hotswap. And a linear scan of all page tables is not very suitable for swap.

2) Any particular reason why the prio_tree is avoided for nonlinear vma:s? We could modify the code to use one "union shared" together with one vm_pgoff per page in struct vm_area_struct for nonlinear vma:s. That way it would be possible to rmap nonlinear vma:s with the prio_tree. But maybe that is unholy misuse of the prio_tree data structure, who knows.

3) Using prio_tree to rmap nonlinear vma:s like above would of course lead to a higher memory use per page belonging to a nonlinear vma. That raises the question why nonlinear vma:s aren't implemented as several vma:s - one vma per page? I mean, if remap_file_pages() should be able to change protection per page in the future - exactly what do we have then? Several vma:s?

Thanks!

/ magnus

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#1 lore raw
Quoted 6 lines · Magnus Damm

I am currently investigating how to unmap a physical page belonging to a nonlinear file backed vma.
By studying the 2.6.9 source code and by reading the excellent VMM book by Mel Gorman I believe that:
- physical pages belonging to linear file backed vma:s are currently reverse mapped using the prio_tree i_mmap.

That description is somewhat vague. The prio_tree is a 2-dimensional search structure indexed by start and end of file offset range, similar to the more commonly-known k-d trees and the like. One must know the file offset range covered by a vma for this to work.

Quoted 8 lines · Magnus Damm

- physical pages belonging to nonlinear file backed vma:s are currently reverse mapped using the linked list i_mmap_nonlinear. Please let me know if something above is incorrect.
The reverse mapping code for nonlinear vma:s does not seem to scale very well today with the linked list implementation. It seems to me that the assumption is made that the number of users of nonlinear vma:s are few and that they probably not very often want do anything resulting in a reverse mapping operation.

This is for two obvious reasons. The first is linear search for the vma. The second is that the virtual position of a physical page at a given file offset within a nonlinear vma is not predictable, so there is a second linear search within the vma.

Quoted 7 lines · Magnus Damm

Some questions:
1) Is everyone happy with the solution today? Is the linked list implementation fast enough? It seems to me that the nonlinear code in try_to_unmap_file() is good enough for swap but does not always unmap the requested page. This behavior is not very suitable for memory hotswap. And a linear scan of all page tables is not very suitable for swap.

It's not a linear scan of all page tables. It's a rather restricted subset. The linked list you're referring to is actually not the aspect that makes it "slow". It's the pagetable scan beneath the nonlinear vmas.

Quoted 11 lines · Magnus Damm

2) Any particular reason why the prio_tree is avoided for nonlinear vma:s? We could modify the code to use one "union shared" together with one vm_pgoff per page in struct vm_area_struct for nonlinear vma:s. That way it would be possible to rmap nonlinear vma:s with the prio_tree. But maybe that is unholy misuse of the prio_tree data structure, who knows.
3) Using prio_tree to rmap nonlinear vma:s like above would of course lead to a higher memory use per page belonging to a nonlinear vma. That raises the question why nonlinear vma:s aren't implemented as several vma:s - one vma per page? I mean, if remap_file_pages() should be able to change protection per page in the future - exactly what do we have then? Several vma:s?

Please read what I wrote above. Your "suggestion" is actually not sufficiently well-described, so I'm not doing much with it. Before going on with further suggestions, you may also want to notice that the precise point of remap_file_pages() is to prevent kernel data structure proliferation in the cases where your suggestions would create some new data structure for every pte under the nonlinear vma. That space overhead is prohibitive and renders workloads reliant on remap_file_pages() nonfunctional.

-- wli
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#2 lore raw
Quoted 8 lines · William Lee Irwin III
Quoted 6 lines · Magnus Damm

I am currently investigating how to unmap a physical page belonging to a nonlinear file backed vma.
By studying the 2.6.9 source code and by reading the excellent VMM book by Mel Gorman I believe that:
- physical pages belonging to linear file backed vma:s are currently reverse mapped using the prio_tree i_mmap.

Quoted 4 lines

That description is somewhat vague. The prio_tree is a 2-dimensional search structure indexed by start and end of file offset range, similar to the more commonly-known k-d trees and the like. One must know the file offset range covered by a vma for this to work.

Thank you for clarifying.

Quoted 10 lines · William Lee Irwin III
Quoted 8 lines · Magnus Damm

- physical pages belonging to nonlinear file backed vma:s are currently reverse mapped using the linked list i_mmap_nonlinear. Please let me know if something above is incorrect.
The reverse mapping code for nonlinear vma:s does not seem to scale very well today with the linked list implementation. It seems to me that the assumption is made that the number of users of nonlinear vma:s are few and that they probably not very often want do anything resulting in a reverse mapping operation.

Quoted 4 lines

This is for two obvious reasons. The first is linear search for the vma. The second is that the virtual position of a physical page at a given file offset within a nonlinear vma is not predictable, so there is a second linear search within the vma.

Exactly.

Quoted 9 lines · William Lee Irwin III
Quoted 7 lines · Magnus Damm

Some questions:
1) Is everyone happy with the solution today? Is the linked list implementation fast enough? It seems to me that the nonlinear code in try_to_unmap_file() is good enough for swap but does not always unmap the requested page. This behavior is not very suitable for memory hotswap. And a linear scan of all page tables is not very suitable for swap.

Quoted 4 lines

It's not a linear scan of all page tables. It's a rather restricted subset. The linked list you're referring to is actually not the aspect that makes it "slow". It's the pagetable scan beneath the nonlinear vmas.

Yes, and another for-loop is added on top of that when a range of physical pages are unmapped:

// slow quasi-code to unmap a physical page range

for_each_page_in_physical_page_range() {
unmap_anonymous_and_linear_file_backed_page();

  if (page_nonlinear_and_mapped()) {
    for_each_nonlinear_vma() {
      for_each_virtual_page_in_vma_range() {}
        if (physical_address_matches()) {
          unmap();
        }
      }
    }

}
}

Quoted 13 lines · William Lee Irwin III
Quoted 11 lines · Magnus Damm

2) Any particular reason why the prio_tree is avoided for nonlinear vma:s? We could modify the code to use one "union shared" together with one vm_pgoff per page in struct vm_area_struct for nonlinear vma:s. That way it would be possible to rmap nonlinear vma:s with the prio_tree. But maybe that is unholy misuse of the prio_tree data structure, who knows.
3) Using prio_tree to rmap nonlinear vma:s like above would of course lead to a higher memory use per page belonging to a nonlinear vma. That raises the question why nonlinear vma:s aren't implemented as several vma:s - one vma per page? I mean, if remap_file_pages() should be able to change protection per page in the future - exactly what do we have then? Several vma:s?

Quoted 8 lines

Please read what I wrote above. Your "suggestion" is actually not sufficiently well-described, so I'm not doing much with it. Before going on with further suggestions, you may also want to notice that the precise point of remap_file_pages() is to prevent kernel data structure proliferation in the cases where your suggestions would create some new data structure for every pte under the nonlinear vma. That space overhead is prohibitive and renders workloads reliant on remap_file_pages() nonfunctional.

Allright. So, remap_file_pages() should be as fast as possible and the linked-list implementation for nonlinear pages is suitable as long as reverse mapping is not that common... Point taken.

Thanks!

/ magnus

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#3 lore raw
In reply to Magnus Damm
Quoted 7 lines · Magnus Damm

I am currently investigating how to unmap a physical page belonging to a nonlinear file backed vma.

By studying the 2.6.9 source code and by reading the excellent VMM book by Mel Gorman I believe that:

Quoted 7 lines

- physical pages belonging to linear file backed vma:s are currently reverse mapped using the prio_tree i_mmap.

- physical pages belonging to nonlinear file backed vma:s are currently reverse mapped using the linked list i_mmap_nonlinear.

Please let me know if something above is incorrect.

The above is correct.

Quoted 5 lines

The reverse mapping code for nonlinear vma:s does not seem to scale very well today with the linked list implementation. It seems to me that the assumption is made that the number of users of nonlinear vma:s are few and that they probably not very often want do anything resulting in a reverse mapping operation.

Correct (well, the users might be many, but the kind of apps using them few, and it's exceptional to want to do an rmap of them, yes).

Quoted 8 lines

Some questions:

1) Is everyone happy with the solution today? Is the linked list implementation fast enough? It seems to me that the nonlinear code in try_to_unmap_file() is good enough for swap but does not always unmap the requested page. This behavior is not very suitable for memory hotswap. And a linear scan of all page tables is not very suitable for swap.

Correct. And however desirable, memory hotswap is exceptional too, yes?

Quoted 2 lines

2) Any particular reason why the prio_tree is avoided for nonlinear vma:s?

Their non-linearity makes the prio_tree useless for them.

Quoted 4 lines

We could modify the code to use one "union shared" together with one vm_pgoff per page in struct vm_area_struct for nonlinear vma:s. That way it would be possible to rmap nonlinear vma:s with the prio_tree. But maybe that is unholy misuse of the prio_tree data structure, who knows.

Sorry, I don't understand "one vm_pgoff per page in struct vm_area_struct". Allocate and associate a prio_tree node with each page, perhaps.

Quoted 4 lines

3) Using prio_tree to rmap nonlinear vma:s like above would of course lead to a higher memory use per page belonging to a nonlinear vma. That raises the question why nonlinear vma:s aren't implemented as several vma:s - one vma per page?

Non-linear vmas were introduced precisely to avoid the crippling memory and search overhead of having the per-page vmas some apps used to need. Non-linear vmas in themselves are awkward and regrettable, but better than not having that option at all.

Quoted 3 lines

I mean, if remap_file_pages() should be able
to change protection per page in the future - exactly what do we have then? Several vma:s?

There was a patch by Ingo in -mm for a while, to change protection per page: the non-linear vma remained a single non-linear vma.

Hugh

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#4 lore raw
Quoted 10 lines · Hugh Dickins
Quoted 5 lines · Magnus Damm

The reverse mapping code for nonlinear vma:s does not seem to scale very well today with the linked list implementation. It seems to me that the assumption is made that the number of users of nonlinear vma:s are few and that they probably not very often want do anything resulting in a reverse mapping operation.

Correct (well, the users might be many, but the kind of apps using them few, and it's exceptional to want to do an rmap of them, yes).

So, say that I run some kind of PC emulator that nonlinearly mmap():s 512 MiB memory on my desktop machine that has 512 MiB RAM. After a while the page out is needed. Would I then be better off if the emulator had mapped all pages in separate vma:s instead of used nonlinear vma:s?

Quoted 10 lines
Quoted 8 lines

Some questions:

1) Is everyone happy with the solution today? Is the linked list implementation fast enough? It seems to me that the nonlinear code in try_to_unmap_file() is good enough for swap but does not always unmap the requested page. This behavior is not very suitable for memory hotswap. And a linear scan of all page tables is not very suitable for swap.

Correct. And however desirable, memory hotswap is exceptional too, yes?

Yes, I guess it is a rather uncommon operation. But OTOH might these machines that have hotswap memory hardware run some kind of database server that nonlinearly mmap():s files to improve performance... It is probably _very_ uncommon. But how common is page out?

Quoted 8 lines
Quoted 5 lines

We could modify the code to use one "union shared" together with one vm_pgoff per page in struct vm_area_struct for nonlinear vma:s. That way it would be possible to rmap nonlinear vma:s with the prio_tree. But maybe that is unholy misuse of the prio_tree data structure, who knows.

Sorry, I don't understand "one vm_pgoff per page in struct vm_area_struct". Allocate and associate a prio_tree node with each page, perhaps.

Exactly what I meant. Sorry for my vagueness.

Instead of only adding linear vma:s to the prio_tree we in the nonlinear case add one single-page range per each page belonging to the vma range. And then we use the prio_tree to rmap both linear and nonlinear vma:s.

But maybe that could be considered as misuse of prio_tree and of course we have the memory usage trade off and the added complexity which might slow down remap_file_pages()...

Quoted 9 lines
Quoted 4 lines

3) Using prio_tree to rmap nonlinear vma:s like above would of course lead to a higher memory use per page belonging to a nonlinear vma. That raises the question why nonlinear vma:s aren't implemented as several vma:s - one vma per page?

Non-linear vmas were introduced precisely to avoid the crippling memory and search overhead of having the per-page vmas some apps used to need. Non-linear vmas in themselves are awkward and regrettable, but better than not having that option at all.

While at it, my VMM book by Mel Gorman basically says that the search used by get_unmapped_area() is slow for large number of mappings. Is it still true with 2.6?

Quoted 6 lines
Quoted 3 lines

I mean, if remap_file_pages() should be able
to change protection per page in the future - exactly what do we have then? Several vma:s?

There was a patch by Ingo in -mm for a while, to change protection per page: the non-linear vma remained a single non-linear vma.

Ok. Thanks for your input.

/ magnus

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>