Method and apparatus for querying for and traversing virtual memory area
AssigneeHuawei Technologies Co., Ltd.
InventorQiang Huang
Life of this patent
Estimating the term…
Abstract
Embodiments of the present invention disclose a method and an apparatuses for querying for and traversing a virtual memory area. The method includes: determining whether a virtual memory area (vma) corresponding to a query address is in an adjacent range of a cached vma, and if the vma corresponding to the query address is in the adjacent range of the cached vma, querying for the vma by using a thread on a node of a threaded red-black tree. Since an adjacent range of the cached vma can always be determined, the hit rate of accessing the cache is improved, and the time complexity of implementing the whole vma traversal is O(n), thereby improving vma query efficiency.
Claims18
A method for querying for a virtual memory area, the method comprising:
- determining whether a virtual memory area (vma) corresponding to a query address is in an adjacent range of a cached vma, wherein the adjacent range of the cached vma comprises an address range of at least one adjacent vma before the cached vma and an address range of at least one adjacent vma after the cached vma;
- and
- if the vma corresponding to the query address is in the adjacent range of the cached vma, querying for the vma by using a thread on a node of a threaded red-black tree, wherein the node is a node corresponding to the cached vma, and the thread is a pointer pointing to a predecessor node and a successor node of each node on the threaded red-black tree.
A method for traversing a virtual memory area (vma), the method comprising:
- obtaining a read semaphore of memory description information (mm), and determining whether a vma corresponding to a query address n is in an adjacent range of a cached vma, wherein the adjacent range of the cached vma comprises an address range of at least one adjacent vma before the cached vma and an address range of at least one adjacent vma after the cached vma;
- if the vma corresponding to the query address is in the adjacent range of the cached vma, querying for the vma corresponding to the query address n by using a thread on a node of a threaded red-black tree, and releasing the read semaphore, wherein the node is a node corresponding to the cached vma, and the thread is a pointer pointing to a predecessor node and a successor node of each node on the threaded red-black tree;
- updating an address range of the current cached vma to an address range (vma_start, vma_end) of the vma corresponding to the query address n, and updating a query address n+1 to the vma_end of the vma corresponding to the query address n, wherein the vma_start is a start address of the vma corresponding to the query address n, and the vma_end is an end address of the vma corresponding to the query address n;
- obtaining the read semaphore of the mm, determining that a vma corresponding to the query address n+1 is an adjacent vma after the current cached vma, querying for a successor node of the current cached vma by using a thread on a node of the threaded red-black tree, and querying for the vma corresponding to the query address n+1 according to the successor node;
- and
- repeating the foregoing steps cyclically until at least a part of address space is traversed.
An apparatus for querying for a virtual memory area, the apparatus comprising:
- a determining module, configured to determine whether a virtual memory area (vma) corresponding to a query address is in an adjacent range of a cached vma, wherein the adjacent range of the cached vma comprises an address range of at least one adjacent vma before the cached vma and an address range of at least one adjacent vma after the cached vma;
- and
- a thread query module, configured to:
- when the determining module determines that the vma is in the adjacent range of the cached vma, query for the vma by using a thread on a node of a threaded red-black tree, wherein the node is a node corresponding to the cached vma, and the thread is a pointer pointing to a predecessor node and a successor node of each node on the threaded red-black tree.
An apparatus for traversing a virtual memory area, wherein the apparatus comprises:
- a determining module, configured to determine whether a virtual memory area (vma) corresponding to a query address n is in an adjacent range of a cached vma, wherein the adjacent range of the cached vma comprises an address range of at least one adjacent vma before the cached vma and an address range of at least one adjacent vma after the cached vma;
- a thread query module, configured to:
- when the determining module determines that the vma is in the adjacent range of the cached vma, query for the vma by using a thread on a node of a threaded red-black tree, wherein the node is a node corresponding to the cached vma, and the thread is a pointer pointing to a predecessor node and a successor node of each node on the threaded red-black tree;
- and
- a cache update module, configured to:
- according to the vma that is corresponding to the query address n and that is queried for by the thread query module, update the current cached vma to an address range (vma_start, vma_end) of the vma corresponding to the query address n, and update a query address n+1 to the vma_end of the vma corresponding to the query address n, wherein the vma_start is a start address of the vma corresponding to the query address n, and the vma_end is an end address of the vma corresponding to the query address n.
Dependencies are inferred from the claim text.