Memory management method and electronic device using the same
A memory management method or an electronic device for managing memory is provided. The method may include checking available capacity to allocate new process to first memory. The method may include determining whether to swap out the page of the first process to the first memory or the second memory, based on the available capacity and characteristics of the first process that is running in the first memory. The method may include allocating, as a swap space, a partial region of the first memory or the second memory that is determined. The method may include swapping out the page of the first process from the first memory to the swap space. The method may include identifying whether the swapped-out page is swapped-in from the swap space to the first memory. The method may include releasing the swap space.
1 . An electronic device comprising:
a first memory;
a second memory; and
at least one processor configured to execute a first process by loading, to the first memory, pages of the first process related to an application stored in the second memory,
wherein the at least one processor is further configured to:
determine an available capacity of the first memory for executing a new process,
determine whether to swap out the page of the first process to the first memory or the second memory, based on the available capacity, and based on characteristics of the first process that is running in the first memory, by:
when a space in the first memory is insufficient for allocating a region of the first memory as a swap space, determine a first page among the pages of the first process, based on a number of times that the pages of the first process are referred to by a plurality of processes, and remove the first page from the first memory,
when the available capacity for allocating the new process to the first memory is still insufficient even after removing the first page from the first memory, identify whether a space in the second memory is sufficient to swap-out a page of a process that is running in the first memory, and
when the space in the second memory is insufficient, determine a second page among pages written to the second memory, based on a time at which the pages written to the second memory were swapped out to the second memory, and remove the second page from the second memory,
allocate a partial region of the first memory or the second memory that is determined as a new swap space,
swap-out the page of the first process from the first memory to the new swap space, identify whether the swapped-out page is swapped-in from the new swap space to the first memory, and
release the new swap space based on the new swap space being empty by the identifying that the swapped-out page is swapped-in.
2 . The electronic device of claim 1 , wherein the characteristics of the first process comprise at least one of a reaction time of the application or a degree of state preservation of a process.
3 . The electronic device of claim 2 , wherein the at least one processor is configured to determine the number of times the page of the first process is referred to by the plurality of processes.
4 . The electronic device of claim 1 , wherein the pages of the first process comprise a shared object (SO) page belonging to a shared library.
5 . The electronic device of claim 1 , wherein the first page and the second page comprise a shared object (SO) page belonging to a shared library.
6 . The electronic device of claim 1 , wherein the at least one processor is further configured to, when the available capacity for allocating the new process to the first memory is still insufficient even after removing the second page from the second memory, calculate a required time for driving each process of a plurality of processes that are running in the first memory,
determine, based on the calculated times, an order of terminating the plurality of processes that are running in the first memory, and
terminate at least one process from among the plurality of processes that are running in the first memory.
7 . The electronic device of claim 6 , wherein the required time comprises at least one of a time required for searching for an SO symbol of the page of the process or a time required for executing an extensible Markup Language (XML)-based User Interface (UI) process.
8 . A memory management method of an electronic device, the memory management method comprising:
determining an available capacity of a first memory for executing a new process,
determining whether to swap out a page of a first process to the first memory or to a second memory, based on the available capacity, and based on characteristics of the first process that is running in the first memory, by:
when a space in the first memory is insufficient for allocating a region of the first memory as a swap space, determining a first page among pages of the first process, based on a number of times that the pages of the first process are referred to by a plurality of processes, and removing the first page from the first memory,
when the available capacity for allocating the new process to the first memory is still insufficient even after removing the first page from the first memory, identifying whether a space in the second memory is sufficient to swap-out a page of a process that is running in the first memory,
when the space in the second memory is insufficient, determining a second page among pages written to the second memory, based on a time at which the pages written to the second memory were swapped out to the second memory, and removing the second page from the second memory,
allocating a partial region of the first memory or the second memory that is determined as a new swap space,
swapping out the page of the first process from the first memory to the new swap space,
identifying whether the swapped-out page is swapped-in from the new swap space to the first memory, and
releasing the new swap space based on the new swap space being empty by the identifying that the swapped-out page is swapped-in.
9 . The memory management method of claim 8 , wherein the characteristics of the first process comprise at least one of a reaction time of an application or a degree of state preservation of a process.
10 . The memory management method of claim 9 , further comprising determining the number of times the page of the first process is referred to by the plurality of processes.
11 . The memory management method of claim 8 , wherein the pages of the first process comprise a shared object (SO) page belonging to a shared library.
12 . The memory management method of claim 8 , wherein the first page and the second page comprise a shared object (SO) page belonging to a shared library.
13 . The memory management method of claim 8 , further comprising:
when the available capacity for allocating the new process to the first memory is still insufficient even after removing the second page from the second memory, calculating a required time for driving each process of a plurality of processes that are running in the first memory;
determining an order of terminating the plurality of processes that are running in the first memory, based on the calculated times; and
terminating at least one process from among the plurality of processes that are running in the first memory.
14 . The memory management method of claim 13 , wherein the required time comprises at least one of a time required for searching for an SO symbol of the page of the process or a time required for executing an extensible Markup Language (XML)-based User Interface (UI) process.