201037516 六、發明說明: 【發明所屬之技術領域】 本發明是有關於-種使用記憶體的方法,特別是有關 於一種使用壓縮型記憶體的方法。 【先前技術】 當現行記憶體系統之實體記憶體(RAM)容量被用完, Ο而記憶體系統需要更多的記憶體資源時,實體記憶體上不 活動的頁面將會被移到之-預先規劃好的SWAp交換空間 中’雖然賺交換空間可以幫助記憶體系統增加一小部 份容量的記憶體,但卻仍不能視為記憶體的替代品。傳統 SWAP交換空間是位於硬碟(Hard Disk)中,其存取速度 係較實體記憶體慢。 然而,對於記憶體系統具較少實體記憶體的容量,卻 時常使用SWAP交換空間之方式來放置記憶體資料的情況 下’為了不降低記憶體系統本身之操作性能,於現階段來 而言,增加較大容量的實體記憶體來增加此記憶體系統之 操作性能看似是無法避免之解決方式。 【發明内容】 有繁於此,本發明揭露一種使用記憶體的方法,可於 使用者取得較大容量的實體記憶體之前,提供介於使用實 體記憶體之原操作性能及使用硬碟SWAP交換空間之較低 操作性能間之另一種變通之解決方案,使其既具有較使用 201037516 硬碟SWAP交換空間之方式高的操作性能,又可不須急著 購買額外實體記憶體、而增加了設備成本。 根據上述之目的而提出一種使用記憶體的方法,適用 於一記憶體系統中’記憶體系統具主記憶體及次記憶體, 主記憶體區分有固定容量之原使用區及壓縮型備用區,壓 縮型備用區預設至少一 SWAP交換區,此方法首先依照原 使用區、壓縮塑備用區及次記憶體之順序設定一記憶體使 用優先順序。當原使用區之容量不足使用時,放置壓縮資 0 料至壓縮型備用區之預設SWAP交換區。當壓縮型備用區 之預設SWAP交換區之容量即將不足使用時,新增設另一 SWAP交換區至壓縮型備用區中,以供放置壓縮資料。每 當最新之SWAP交換區之容量即將不足使用時,持續新增 一 SWAP交換區至壓縮型備用區中,直到壓縮型備用區之 容量不足使用時,才改放置資料至次記憶體。 【實施方式】 〇 以下將以圖示及詳細說明清楚說明本發明之精神,如 熟悉此技術之人員在瞭解本發明之實施例後,當可由本發 明所教示之技術’加以改變及修飾’其並不脫離本發明之 精神與範圍。 本發明為一種使用記憶體的方法,此方法於一主記憶 體140中規劃有一原使用區142及一壓縮型備用區144, 壓縮型備用區144預先汉有SWAP交換區145,當原使用 區142之容量不足存放暫存資料時’壓縮原使用區142之 暫存資料並放置於廢縮型備用區144之預設SWAP交換區 201037516 145 ’當預設SWAP交換區145不足存放暫存資料時,動態 地新增另一 SWAP交換區146,直到壓縮型備用區144之 容量不足使用為止。 本發明之一實施例中’此方法係適用於一記憶體系統 100中’請參閱第1圖所示,第1圖為此記憶體系統1〇〇 於一實施例中之電子方塊圖’記憶體系統1〇〇例如為一精201037516 VI. Description of the Invention: [Technical Field] The present invention relates to a method of using a memory, and more particularly to a method of using a compression type memory. [Prior Art] When the physical memory (RAM) capacity of the current memory system is used up, and the memory system requires more memory resources, the inactive pages on the physical memory will be moved to - In the pre-planned SWAp swap space, 'while earning swap space can help the memory system to add a small amount of memory, but it can't be considered as a substitute for memory. The traditional SWAP swap space is located on the Hard Disk and its access speed is slower than that of physical memory. However, in the case where the memory system has a small amount of physical memory, but often uses the SWAP swap space to place the memory data, 'in order not to degrade the operational performance of the memory system itself, at this stage, Increasing the amount of physical memory to increase the operational performance of this memory system seems to be an unavoidable solution. SUMMARY OF THE INVENTION In view of the above, the present invention discloses a method for using a memory, which can provide the original operational performance of using physical memory and exchange using a hard disk SWAP before the user obtains a large-capacity physical memory. Another workaround between the lower operating performance of space, which provides higher operating performance than the 201037516 hard disk SWAP swap space, and increases the cost of equipment without having to rush to purchase additional physical memory. . According to the above object, a method for using a memory is proposed, which is suitable for a memory system having a main memory and a secondary memory, and the main memory is divided into a original use area and a compressed spare area. The compressed spare area presets at least one SWAP exchange area. The method first sets a memory usage priority order according to the order of the original use area, the compressed plastic spare area, and the secondary memory. When the capacity of the original use area is insufficient, the compressed material is placed to the preset SWAP exchange area of the compressed spare area. When the capacity of the preset SWAP exchange area of the compressed spare area is about to be insufficient, another SWAP exchange area is newly added to the compressed spare area for placing the compressed data. Whenever the capacity of the latest SWAP exchange area is about to be insufficient, a SWAP exchange area is continuously added to the compressed spare area until the capacity of the compressed spare area is insufficient, and the data is changed to the secondary memory. BRIEF DESCRIPTION OF THE DRAWINGS The spirit of the present invention will be apparent from the following description and the detailed description of the embodiments of the invention. The spirit and scope of the invention are not departed. The present invention is a method for using a memory. The method has a original use area 142 and a compression type spare area 144 in a main memory 140. The compressed spare area 144 has a SWAP exchange area 145 in advance. When the capacity of the 142 is insufficient to store the temporary data, the temporary storage data of the original use area 142 is compressed and placed in the default SWAP exchange area of the scrapped spare area 144 201037516 145 'When the preset SWAP exchange area 145 is insufficient for storing the temporary storage data Another SWAP swap area 146 is dynamically added until the capacity of the compressed spare area 144 is insufficient. In one embodiment of the present invention, the method is applicable to a memory system 100. Please refer to FIG. 1 . FIG. 1 is an electronic block diagram of the memory system 1 in an embodiment. Body system 1〇〇, for example, a fine
簡型電腦(thin client)或飼服|§電腦(server ),係以LINUX 作業系統120為主’具有一主記憶體140 (或稱實體記憶 0 體’如揮發性記憶體,RAM )及一次記憶體16〇 (或稱第 二記憶體,如非揮發性記憶體,Hard Disk或Flash),主記 憶體140預先定義容量(例如:1 : 1或2 : 1等等之比例) 而分割有一原使用區142及一壓縮型備用區144。原使用 區142即主記憶體140原用以暫存資料之位置。壓縮型備 用區144於開機前尚未預先規劃任何SWAp交換區145。 此實施例中,例如主記憶體14〇為512 MB,其中原使 用區142及壓縮型備用區144分別被預先規劃為256mb, ❹壓縮型備用區144可供放置壓縮資料之壓縮比例通常可以 壓縮至未壓縮前的1/2(即壓縮比為2)以上,使得原使用區 142(256 MB)加上壓縮型備用區i44(256 MB*2)可供充分使 用768 MB之容量,而大於主記憶體14〇為512 MB之容 量。請參閱第1圖及第2圖所示,第2圖為本發明伺服器 設備於此實施例中之流程圖,記憶體系統100於此實施例 中進行之詳細步驟如下: 步驟(201)當記憶體系統1〇〇開機時,LINUX之作業系 統預先設置一個以上(不限定為一個)之SWAP交換區145 6 201037516 (例如RAMDISK)至壓縮型備用區144中,當多個預設 SWAP交換區145時’其容量不限是否—致,本實施例中 皆例如為8MB ; 步驟(202)依照原使用區142、壓縮型備用區144及次 記憶體160之順序設定一記憶體使用優先順序,使得 UNUX之作㈣祕守上述之記‘_使職先順序進行存 放暫存資料; 步驟(203)當記憶體系統100進行正常工作時,linux ❹之作業系統使用主記憶體140之原使用區142進行暫存資 料之存取; 步驟(204)利用LINUX之作業系統監控原使用區142 之容量,並判斷原使用區142之容量是否不夠存放資料’ 若是,進行步驟(205),否則回步驟(2〇3); 步驟(205)利用LINUX之作業系統監控壓縮型備用區 144之預設SWAP交換區145,並判斷預設SWAp交換區 145是否即將不夠存放壓縮資料,若是,進行步驟(施), 〇 否則回步驟(207); 步驟(206)當原使用區142之容量不夠讓LINUX之作 業系統存放暫存資料’但預設SWAp交換區145仍足_ LINUf之作業系統存放壓縮資料時’記憶體系統議將原 使用區142上不活動的暫存資料經上述之壓縮比例麗縮 像,存至壓縮型備用區144之預設SWAP交換區145中, 進行步驟(203)以便主記憶體14〇之原使用區142挪出空間 以提供LINUX之作業系統繼續進行暫存資料之存取。 201037516 步驟(207)當原使用區142之容量再度不夠存放暫存資 料’且壓縮型備用區144之預没SWAP交換區145也即將 不夠存放壓縮資料時’新增另一 SWAP交換區146至壓縮 型備用區144中,以供LINUX之作業系統放置壓縮資料, 回步驟(203),或壓縮型備用區144之新増的sWAp交換區 146也即將不夠讓記憶體系統100存放壓縮資料時,進行 步驟(208)。其中步驟(207)中之SWAP交換區146的容量^ 限是否與預設之SWAP交換區145 —致。 0 此外,當預設SWAP交換區丨45中所存放之暫存資料 到達一預設點147(例如預設SWAP交換區145為8 Mb, 則預設點147可例如為7.5 MB)時,LINUX之作業系統便 認定壓縮型備用區144之預設SWAP交換區145即將不夠 存放壓縮資料。 步驟(208)直到壓縮型備用區H4之容量整體完全不夠 讓LINUX作業系統120存放壓縮資料時,LINUX作業系 統120將原使用區142上不活動的暫存資料存至次記憶體 之SWAP交換空間162,以便主記憶體14〇之原使用區 142挪出空間以供進行暫存資料之存取。 如此,本發明擁有大於主記憶體原容量之記憶體暫存 空間,其所具有的操作性能大於使用次記憶體之SWAp交 換空間之方式的操作性能,同時亦可延遲使用次記憶體作 為SWAP交換的時機。 本發明所揭露如上之各實施例中,並非用以限定本發 明,任何熟1此技藝者,在不脫離本發明之精神和範圍内, 古可作各種之更動與潤飾,因此本發明之保護範圍當視後 8 201037516 附之申請專利範圍所界定者為準。 【圖式簡單說明】 為讓本發明之上述和其他目的、特徵、優點與實施例 能更明顯易懂,所附圖式之詳細說明如下: 第1圖繪示本發明記憶體系統於一實施例中之電子方塊 圖。 第2圖繪示本發明伺服器設備於此實施例中之流程圖。 【主要元件符號說明】 100 :記憶體系統 120 : LINUX作業系統 140 :主記憶體 142 :原使用區 144 :壓縮型備用區 145 :預設之SWAP交換區 146 :新增之SWAP交換區 147 :預設點 160 :次記憶體 162 : SWAP交換空間 210-280 :步驟A simple computer (thin client) or a feeding service|§computer (server), which is based on the LINUX operating system 120, has a main memory 140 (or physical memory 0 such as volatile memory, RAM) and once Memory 16〇 (or second memory, such as non-volatile memory, Hard Disk or Flash), the main memory 140 pre-defined capacity (for example: ratio of 1: 1 or 2: 1 etc.) The original use area 142 and a compression type spare area 144. The original use area 142 is the location where the main memory 140 was originally used to temporarily store data. The compressed spare area 144 has not previously planned any SWAp exchange area 145 prior to power up. In this embodiment, for example, the main memory 14 is 512 MB, wherein the original usage area 142 and the compression type spare area 144 are respectively planned to be 256 mb, and the compression ratio of the compression type spare area 144 for placing compressed data is usually compressed. Up to 1/2 of the uncompressed (ie, the compression ratio is 2) or more, so that the original use area 142 (256 MB) plus the compressed spare area i44 (256 MB*2) can fully utilize the capacity of 768 MB, and is larger than The main memory 14 is 512 MB in capacity. Please refer to FIG. 1 and FIG. 2 . FIG. 2 is a flowchart of the server device of the present invention. The detailed steps of the memory system 100 in this embodiment are as follows: Step (201) When the memory system is turned on, the LINUX operating system presets more than one (not limited to one) SWAP exchange area 145 6 201037516 (for example, RAMDISK) to the compression type spare area 144, when a plurality of preset SWAP exchange areas At 145 o'clock, the capacity is not limited, for example, in the embodiment, for example, 8 MB; the step (202) sets a memory usage priority order according to the order of the original use area 142, the compressed spare area 144, and the secondary memory 160. Make UNUX (4) secretly keep the above words '_ to store the temporary data in order of priority; Step (203) When the memory system 100 performs normal work, the operating system of the Linux system uses the original use area of the main memory 140 142: accessing the temporary data; step (204) using the LINUX operating system to monitor the capacity of the original use area 142, and determining whether the capacity of the original use area 142 is insufficient to store the data 'If yes, proceed to step (205), otherwise returning Step (2): Step (205) monitors the preset SWAP exchange area 145 of the compressed spare area 144 by using the LINUX operating system, and determines whether the preset SWAp exchange area 145 is about to store insufficient compressed data, and if so, proceeds to the step ( )), otherwise return to step (207); Step (206) when the original use area 142 is not enough capacity for the LINUX operating system to store temporary data 'but the default SWAp exchange area 145 is still sufficient _ LINUf operating system to store compressed data At the time of the memory system, the inactive data stored in the original use area 142 is stored in the preset SWAP exchange area 145 of the compressed spare area 144 via the above-described compression ratio, and step (203) is performed for the main The original usage area 142 of the memory 14 挪 leaves the space to provide the LINUX operating system to continue accessing the temporary data. 201037516 Step (207) When the capacity of the original use area 142 is insufficient to store the temporary storage data and the pre-emptive SWAP exchange area 145 of the compressed spare area 144 is also insufficient to store the compressed data, 'add another SWAP exchange area 146 to the compression In the spare area 144, the compressed data is placed in the operating system for the LINUX, the step (203) is returned, or the new sWAp exchange area 146 of the compressed spare area 144 is not enough for the memory system 100 to store the compressed data. Step (208). Whether the capacity limit of the SWAP exchange area 146 in the step (207) is consistent with the preset SWAP exchange area 145. In addition, when the temporary storage data stored in the preset SWAP exchange area 到达45 reaches a preset point 147 (for example, the preset SWAP exchange area 145 is 8 Mb, and the preset point 147 can be, for example, 7.5 MB), LINUX The operating system determines that the predetermined SWAP exchange area 145 of the compressed spare area 144 is not sufficient to store the compressed data. Step (208) until the capacity of the compressed spare area H4 is completely insufficient for the LINUX operating system 120 to store the compressed data, the LINUX operating system 120 stores the inactive temporary data on the original use area 142 to the SWAP swap space of the secondary memory. 162, so that the original memory area 142 of the main memory 14 vacates the space for accessing the temporary data. Thus, the present invention has a memory temporary storage space larger than the original capacity of the main memory, and has an operational performance greater than that of the SWAp swap space using the secondary memory, and can also delay the use of the secondary memory as the SWAP exchange. The timing. The present invention is not limited to the embodiments of the present invention, and various modifications and refinements may be made without departing from the spirit and scope of the present invention. The scope is subject to the definition of the patent application scope of 2010. BRIEF DESCRIPTION OF THE DRAWINGS The above and other objects, features, advantages and embodiments of the present invention will become more <RTIgt; The electronic block diagram in the example. FIG. 2 is a flow chart showing the server device of the present invention in this embodiment. [Main component symbol description] 100: Memory system 120: LINUX operating system 140: Main memory 142: Original use area 144: Compressed spare area 145: Preset SWAP exchange area 146: New SWAP exchange area 147: Preset point 160: Secondary memory 162: SWAP swap space 210-280: Steps