201111966 六、發明說明: 【發明所屬之技術領域】 本發明係關於一種電腦系統開關機方法,特別是關於一種應用於 電腦系統在進入省電模式後,可以快速開關機的方法。 【先前技術】 一般電腦系統工作的狀態,除了正在執行作業系統與各種應用程 式的模式外’更包含了省電模式’電細系統進入休眠的目地一方面為 結省電能的消耗,另一方面為降低系統工作的雜訊。 φ 依據高等組態能源介面(Advanced Configumti^ & Pc)wei·201111966 VI. Description of the Invention: [Technical Field] The present invention relates to a computer system switching method, and more particularly to a method for quickly turning the machine on and off after the computer system enters the power saving mode. [Prior Art] The state of the general computer system works, except that the mode of the operating system and various applications is being executed, and the power saving mode is included. The purpose of the electric system is to sleep. On the other hand, the power consumption is saved. To reduce the noise of the system work. φ according to the advanced configuration energy interface (Advanced Configumti^ & Pc) wei·
Interface,ACPI)的設計分類,最常見的休眠將為兩種型態,一種為 Suspend To RAM (STR) ’稱為S3狀態,S3狀態為只對部份的揮發性 a己憶體持續供電’包括視訊§己憶體(FrameBuffer)與主記愧體(Main Memory ) 4 ’其餘部分一律斷電。S3狀態具有兩個優點,一為雪腦系 統回返到全速運作的時陳快;另-為安全性較佳,當朗 與操作屬於個人私密資料不希望回存至硬碟内時,即採用S3狀態。另 一種為spend To Disk (STD),稱為S4狀態,S4狀態是將工作^的資 料全部皆寫入到非揮發性記憶體内儲存,然後系統將全部斷電,S4的 φ 優點為其更為省電。 承上所述兩種休眠S3狀態與S4狀態,皆不盡完善,在進入兕狀 態後,仍需提供電力給電腦系、統中揮發性記憶體,以維持系統儲存的 狀痞;假設改採用S4狀態雖相較於S3狀態省電,但回返至電腦系統 全速運作的速度較則相對於S3狀態緩慢許多。 有鑑於此’本發明係在針對上述之缺失,改良以上所述的休眠, 提出-種快速開關機的方法,能夠於進入休眠時能減少目前記憶體使 用i,進而增進電腦系統重新啟動至全速運作的反應效率。 【發明内容】 〜 本發明之主要目的係在提供—種快速關機的方法,其係於電腦 201111966 系統進入休眠時大量縮減目前系統中使料記 憶體資料轉換存放至第二儲存裝置的 ΐ ’以減少主記 至全速工作的速度。 進而增進電腦系統恢復 其係可預防 電腦在提供一種快速開關機的方法, 電細糸統忍外喪失電力時資料的遺失與受損的程度。 本發明之再-目_在提供—種快稍職= 或載回皆採用隨機存取處理的技術,將大幅提升資料寫入 重新啟動彼此轉換時資料存取的速度。 旬二、、先進入休眠或 為達到上述之目的,本發明提出之快速開關機 腦系統進人休贿,舰分至少—記贿騎數個清⑽存 個非清白儲存頁,清白儲存頁係㈣放細存,非清數 休眠檔儲存於至少-第二儲存裝置之—切換/頁係寫入 當電腦系_統由切統二。 復至記舰’並且可從第二儲存裝置讀取倾,餘至記憶體眠= 將縮減記㈣轉換存放至第二儲存裝㈣㈣量,ς 啟動恢復公速i作的辭。 心κ统重新 ’當更容易瞭解本 底下藉由具體實施例配合所附的圖式詳加說明Interface, ACPI) design classification, the most common sleep will be two types, one is Suspend To RAM (STR) 'called S3 state, S3 state is only for some of the volatile a memory) Including the video § FrameBuffer and Main Memory 4 'the rest will be powered off. The S3 state has two advantages, one is when the snow-brain system returns to full-speed operation, and the other is better for security. When the lang and the operation are personal and private data do not want to be restored to the hard disk, the S3 is adopted. status. The other is the Send To Disk (STD), which is called the S4 state. The S4 state is to write all the data of the work to the non-volatile memory, and then the system will be powered off. The advantage of S4 is more. To save electricity. The two kinds of sleep S3 state and S4 state are not perfect. After entering the 兕 state, it is still necessary to provide power to the computer system and the volatility memory in the system to maintain the state of the system storage; Although the S4 state saves power compared to the S3 state, the speed of returning to the computer system at full speed is much slower than that of the S3 state. In view of the above, the present invention provides a method for quickly switching on and off according to the above-mentioned lack of the above-mentioned sleep, and can reduce the current memory usage i when entering sleep, thereby improving the computer system restart to full speed. The efficiency of the operation of the operation. SUMMARY OF THE INVENTION The main purpose of the present invention is to provide a method for quickly shutting down, which is to reduce the storage of the memory data in the current system to the second storage device when the system enters sleep. Reduce the speed at which the master works to full speed. In turn, the computer system can be restored. The system can prevent the computer from providing a quick turn-on and turn-off method, and the degree of loss and damage of the data when the power is lost. The re-examination of the present invention provides a technique for random access processing, which will greatly increase the speed of data access when restarting each other. In the second day, first enters dormancy or in order to achieve the above purpose, the fast-switching machine brain system proposed by the present invention enters a bribe, and the ship points at least - a few bribes to ride a few clear (10) to save a non-innocent storage page, innocent storage page (4) Putting the fine memory, the non-clearing dormant file is stored in at least the second storage device - the switching/page writing is performed when the computer system is unified. Return to the ship' and can read the tilt from the second storage device, and then to the memory sleep = convert the reduced record (4) to the second storage device (4) (four) amount, and start the recovery of the public speed i. The heart is re- _ when it is easier to understand the details by the specific examples with the attached drawings
發明之目的、技術内容、特點及其所達成之功效。 【實施方式】 本發明提種快賴_的綠,減少義线進人休 憶體裝置的使紐量’降低寫人第二儲存裝置龍量,以增進電腦系 統進入休眠·新啟驗復至全速轉的速度,底下聽以較佳實施 ,詳述本發明之技術特徵。如第-圖所示,—電腦系統1G係包含一計 鼻處理器(CPU)12、一主§己憶體(Main Memory)14與一第二儲存事置 (Secondary St〇mge)16。第二儲存裝置16係可為高速隨機存取 體裝置,如一快閃記憶體,主要用於儲存檔案系統(file system)18、 切換空間(swap-space)20 及休眠檔(hibernation fiie)22。 第二圖所示為本發明之快速開關機的方法流程圖,請同時參考 201111966 一圖之架構示意圖。首先,如步驟 (Operating System,OS)進入休目民模',將二:系統10之标作系統 憶體Μ為清白儲存頁與非清白=’,將由 區f記 ===主,體14,_清白儲==心 ^序了计异依據禮出之W儲存頁的數量配置主記憶體Μ,並於該 status)之非^儲存頁鑛存至休眠檔22,並存放於第二儲存裝置^ ^切換2G巾或前織18巾。其巾非清白儲存頁可依照位址排 序,以合併連續位址之非清白儲存頁成一單一寫入命令。之後,如步 驟S32,當電腦系統10重新啟動,電腦系統1〇從切換空間2〇與槽案 系統18讀取休眠槽22 ’回復儲存休眠檔至主記憶體14,恢復系統狀 態。最後’如步驟S34,電腦系統10將從第二儲存裝置16讀取資料 載回至主記憶體14。 當執行中止至為快閃記憶體之第二儲存裝置 16 (Suspend-to-f 1 ash)的速度主要取決於需要寫入到非揮發記憶體 (nonvolatile memory)的資料量的多寡。進入休眠之前換出 (Swapping-before-hibernating)利用操作操作系統(〇perating System ’ OS)中既有的記憶體管理技術,將大部分的記憶體頁(_〇^ page)直接捨棄而不做任何的寫入動作,因此可以加速中止(suspend) 的速度。回復(resume)的時候資料(data)將從三個地方取回,分別是 休眠檔(hibernation file)22、切換空間(swap-space)2〇及檔案系統 (file system)18,系統隸屬於核心(kernel)部分的主要資料(data) 及編碼(code) ’在重新開機時立刻取回’而剩餘的資料則使用需求頁 面調度(paging-on-demand)的方式取回使用者現階段所需的部分。由 於使用者所需要的資料量通常遠小於系統在中止前記憶體中的所有資 料量,因此可以加速回復(resume)的速度。 記憶體分頁(memory page)可分成三種,分別為自由分頁(free 201111966The purpose, technical content, characteristics and effects achieved by the invention. [Embodiment] The invention proposes to quickly lag the green color, reduce the amount of the right line into the memory device, and reduce the amount of the second storage device to improve the computer system to enter the dormancy and the new test to The speed of full speed rotation is better understood below, and the technical features of the present invention are detailed. As shown in the first figure, the computer system 1G includes a nasal processor (CPU) 12, a main memory 14 and a second storage device 16 (Secondary St〇mge) 16. The second storage device 16 can be a high speed random access device, such as a flash memory, and is mainly used to store a file system 18, a swap-space 20, and a hibernation fiie 22. The second figure shows the flow chart of the method of the fast switching machine of the present invention. Please refer to the schematic diagram of the structure of 201111966. First, if the Operating System (OS) enters the public mode, the second system: the system 10 is marked as a system memory and the non-innocence = ', will be recorded by the area f === main, body 14 , _ innocent storage == heart ^ sequence of the difference according to the number of W stored pages of the ritual configuration of the main memory Μ, and in the status of the non-storage page deposit to the dormant file 22, and stored in the second store Device ^ ^ Switch 2G towel or front weave 18 towel. The non-innocent storage page of the towel can be sorted according to the address, and the non-innocent storage page of the continuous address is combined into a single write command. Thereafter, as in step S32, when the computer system 10 is restarted, the computer system 1 reads the sleep slot 22' from the switching space 2 and the slot system 18 to restore the sleep stall to the main memory 14, and restores the system state. Finally, as in step S34, the computer system 10 loads the data from the second storage device 16 back to the main memory 14. The speed at which the execution of the second storage device 16 (Suspend-to-fash) to the flash memory is mainly determined by the amount of data that needs to be written to the nonvolatile memory. Swapping-before-hibernating uses the existing memory management technology in the operating system (OS) to discard most of the memory pages (_〇^ page) without doing it. Any write action can speed up the suspend. When replying, the data will be retrieved from three places: hibernation file 22, swap-space 2 and file system 18. The system belongs to the core. (kernel) part of the main data (data) and code (code) 'retrieve immediately after rebooting' and the remaining data is used in the paging-on-demand way to retrieve the user's current stage part. Since the amount of data required by the user is usually much smaller than the amount of data in the memory before the system is suspended, the speed of the resume can be accelerated. Memory page can be divided into three types, which are freely paged (free 201111966)
page)、匿名分頁(anonymous page)及指定分頁(named page)。自由分 頁(free page)是系統當下未使用到的記憶體,自由分頁(free page) 中的内容對系統而言毫無意義。匿名分頁(anonymous page)是程式在 執行時期動態分配的記憶體,這部分的記憶體主要包含了堆疊(stack) 和堆積(heap)二種。指定分頁(named page)則是播案在主記憶體14中 的副本。形式上它的行為類似於第二儲存裝置16的快取(cache)。指 定分頁(named page)主要包含了執行檔(executable file)、動態連結 庫(dynamic-linke library)在記憶體中的對應,或者程式使用記憶體 對應至檔案(memory-mapped-f i 1 e)將一個檔案映射到記憶體。 匿名分頁(anonymous page)及指定分頁(named page)都可能是清 白儲存頁(clean page)或非清白儲存頁(dirty page)。非清白匿名分 頁(dirty anonymous page)被換出(swap-out)時必須寫入到切換空間 (swap-space)20。而非清白指定分頁(dirty named page)則被換出 (swap-out)到檔案系統(fiie system) 18。當操作系統(⑹需要換出 (swap-out)—個清白儲存頁時’因為此分頁在第二儲存裝置16中必定 有-個内容完全-致_本’因此操作祕(⑹可以直接捨棄此分頁。 在系統開始執行SUSpend-t0_flash時,大部分的分頁不需要做任 何的寫回第二裝置16的動作,這是由敎部分的分頁都是清白儲 存頁。部分的分頁需要寫回到切換空Μ 2〇或者檔案系統18中。剩下 的分頁是非換出記憶體(_-swappable mem〇ry),這些分頁主要是 作系統(0S)的核心(kernel) ’或者程式為了效能的因素,將某些分頁 設定為非換出-卿pable)。賴綠鍾最後麵寫人到休眠楷 (hibernation file)22 。 重新開機時 梦殖籍ς'Η ^ 例行性硬體初始化動作及载入操作& ,真器(GS 1論〇後’錢會酬是否要從休嘛⑹伽相 態回復或執行-般的開機動作嗜眠槽(hibernati 1 料將首先載入到主記憶體14中,τ 一; 成基本的開機動作。隨後 ,、使用者的需要,從檔案系統18及切換^ 201111966 間20中將之前的系統狀態载回。若再次執行 pping-before-hibemating,由於部分非清白儲存頁在上—欠執行 swapping-before-hibernating時已經寫入切換空間2〇,因此這個= 頁就變成了清白赫頁,並且之後計算處理器咖)12不再對此八^ 作寫入的動作,故這個分頁不需要再次的寫人婦空間}因此在第 二次以後的swapping-before-hibernatinga行速度將更加快速。 以快閃記憶體(flash)做為第二儲存裝置16透過最佳化技術,可 在隨機存取(randan access)上有近似於連續存取(sequential咖⑹ 的表現。透過組合寫入(Write-combining)主要將記憶體頁在換出時 所產生的小的賴寫人(small random write),在實際寫人快閃記愫 體前先排列(queue)起來,首先針對這些要寫出分頁的實體位^ (Physical address)做排序,排序後便可知道這些要被寫出的分頁中 疋否存在著連續棚的寫出’之後便可以—個較大的寫人需要〜曲 request)取代數個較小的寫入。藉此提昇 swapping-before-hibernating 的速度。 少將換出分頁(swaPPable Pages)寫回第二儲存裝置16可經向操作 系統(0S)要求大量的記紐’為了避免操作祕(⑹於分配記憶體時 的最佳化動作影響到實際配置記憶體的數量。於每配置到一個分頁隨 即會在此分頁寫入一個位元組(byte)的資料,以強制〇s須立即配置 physical memory給該pr〇gram。藉此強迫操作系統(⑹將大部分的記 憶體換出。隨後執行一連串的釋放(free)動作,將之前向系統要求的 記憶體全數歸還給操作系統⑺幻。經過這二個步驟以後,操作系統(〇s) 中大部分的分頁都會變成自由分頁(free page),而自由分頁(free page)不而要寫回到休眠檔(hibernati〇n fiie)22。 此外’可直接在操作系統(〇S)的核心(kernel)中要求配置記憶 體,將透過核心程序(kernei functi〇n)立即配置所需的分頁,將不需 要額外的寫入以強制操作系統(0S)真實的配發記憶體。在配置完記憶 aa後立即執行釋放的動作,系統將產生大量的自由分頁(斤沈page)。 201111966 由於藉由核心、程序(kernel function)配置記.隨不需要額外的寫入 動作。因此可以事綺算換出分頁缝量,藉此推算出需要配置多少 記憶體。 另外’可直接操控操作系統(〇S)中的換出器(swapper)機制。以 Linux為例,在核心(kernel)中具有一記憶體管理程序,其係為 shrmk_all_memory程序,此程序將回收記憶體分頁,於呼叫其時傳 入欲回收的分頁數量,其能夠在不影響系統穩定、使用者使用程式的 情況下釋放出記憶體分頁。shrink—all_meinory程序的機制為在核心 (kernel)中有兩近來最少使用目錄(ieast-recently_used Hst,LRU 籲list)分別為活動目錄(active list)及閒置目錄(inactive Ust), 活動目錄(active list)包含了最近被存取過的分頁,閒置目錄 (inactive list)則為有段時間沒有被存取的分頁。 shrink_all_memory程序會先從閒置目錄(inactive list)開始回收’ 接著再回收活動目錄(active list)。利用shirink_all_memory程序, 可以在不影響到系統核心的運作'使用者的程式下’盡可能的換出。 在Linux之核心(kernel)中,第二儲存裝置16會被視為一般的 區塊輸入/輸出裝置(I/Odevice) ’而在我們將記憶體分頁換出到切換 空間20時’將呼叫submit_bio程序其所接受的參數包含了要寫入的 _ 區段數量(sector number)、讀取/寫入指令(r/w command)、記憶體位 址(memory address)、記憶體長度(memory length)等資訊。可以藉由 攔截submit_bio程序對即將被換出的分頁再進行處理。 上述之即將被換出的分頁係由shirink_al ljemory程序所決 定,決定的依據為此分頁的使用情況而非此分頁在主記憶體14中的實 體位址。我們將shirink_all_memory程序所產生的寫入需求先排列。 再依照此分頁的實體記憶體位址進行排序,並進行合併,以減少存取 輸入/輸出(I/O)的次數並增加此輸入/輸出(I/O)的需求大小(request size)。需求大小(request size)越大,將使得為快閃記憶體(flash) 之第二儲存裝置16的寫入效能越好。 201111966 當一個記憶體分頁被換出時,核心(kernel)需要紀錄此分頁在切換空 間20中所擺放的位置。使核心(kernel)能夠重新將此分頁從第二儲存 裝置20載入。由於組合寫入(write-combining)將重新改寫 shirink—all_memory 程序,當每次執行完 shirink_all_memory 程序 後’必須於確定了每個分頁寫入至切換空間20的位置後,再將資訊填 入到分頁表格(page table)中的換出分頁鑑別符(swapped__ 〇此仲 identifier) 〇 gPage), anonymous page (anonymous page) and designated page (named page). The free page is the memory that is not used by the system at the moment. The content in the free page is meaningless to the system. Anonymous page is the memory dynamically allocated by the program during the execution period. This part of the memory mainly includes stack and heap. The designated page is a copy of the broadcast in the main memory 14. Formally it behaves like a cache of the second storage device 16. The designated page mainly includes the executable file, the correspondence of the dynamic-linke library in the memory, or the program uses the memory corresponding to the file (memory-mapped-f i 1 e) Map a file to memory. Both an anonymous page and a named page may be a clean page or a dirty page. A non-invisible anonymous page must be written to the swap-space 20 when it is swapped out. The dirty named page is swapped out to the file system (fiie system) 18 . When the operating system ((6) needs to swap-out - innocent storage page 'because this page must have in the second storage device 16 - the content is completely - the _ the original" so the operation secret ((6) can directly discard this When the system starts executing SUSpend-t0_flash, most of the paging does not need to do any write back to the second device 16, which is because the partial pages are innocent to store the page. Part of the paging needs to be written back to the switch. Empty 2Μ or file system 18. The remaining pages are non-swappable memory (_-swappable mem〇ry), these pages are mainly used as the core of the system (0S) 'or program for performance reasons, Set some pagination to non-replacement-qing pable. Lai Qingzhong writes to hibernation file22 at the end. Re-boot when dreaming ς'Η ^ Routine hardware initialization action and loading Operation &, the real device (after the GS 1 ' ' 钱 钱 钱 钱 钱 钱 钱 ( ( ( ( 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 钱 钱 钱 钱 钱 钱 钱 钱 钱 钱 钱 钱 钱 钱τ a; into a basic boot action. Then, make The needs of the system, from the file system 18 and switch ^ 201111966 20 in the previous system state back. If pping-before-hibemating is executed again, because some non-innocent storage pages are on - under execution swapping-before-hibernating Write the switching space 2〇, so this = page becomes the innocence page, and then the processor processor 12 is no longer writing the action, so this page does not need to write the space again} Therefore, the swapping-before-hibernatinga line speed will be faster after the second time. The flash memory (flash) as the second storage device 16 can be optimized on the random access (randan access). Approximate to continuous access (sequential coffee (6) performance. Through write-combining, the memory page is mainly generated by the small random write generated by the memory page, in the actual write flash Before the carcass is queued, first sort the physical bits that are to be paged. After sorting, you can know whether there are continuous sheds in the pages to be written. Write 'after you can - a larger writer needs ~ song request) to replace several smaller writes. This improves the speed of swapping-before-hibernating. Majors swap out paging (swaPPable Pages) write back to the second The storage device 16 can request a large number of entries to the operating system (OS) to avoid the operational secrets ((6) the optimal operation when the memory is allocated affects the number of actual configuration memories. Each configuration to a page will then write a byte (byte) of data in this page to force 〇s to immediately configure physical memory to the pr〇gram. This forces the operating system ((6) to swap out most of the memory. Then perform a series of free actions, returning all the memory required by the system to the operating system (7). After these two steps, the operation Most of the paging in the system (〇s) becomes a free page, and the free page does not have to be written back to the hibernati〇n fiie 22. In addition, it can be directly in the operating system ( 〇S) The kernel (kernel) requires configuration memory, the required paging will be configured immediately through the kernel program (kernei functi〇n), no additional writes will be required to force the operating system (0S) true distribution memory The system performs a release action immediately after the memory aa is configured, and the system generates a large number of free pages. The 201111966 is configured by the kernel and the kernel function. No additional write actions are required. Therefore, you can calculate the amount of page breaks and calculate how much memory you need to configure. In addition, you can directly manipulate the swapper mechanism in the operating system (〇S). Take Linux as an example. There is a memory management program in the kernel, which is shrmk_all_memory program. This program will recycle the memory page, and the number of pages to be recycled will be transmitted when calling, which can affect the stability of the system and the user. In the case of the program, the memory page is released. The mechanism of the shrink-all_meinory program is that there are two recently used directories in the kernel (ieast-recently_used Hst, LRU list) are active list and idle directory. (inactive Ust), the active list contains the most recently accessed pages, and the inactive list is the pages that have not been accessed for a while. The shrink_all_memory program will first be from the inactive list. Start recycling 'and then recycle the active list. Use the shirink_all_memory program to swap out the program as much as possible without affecting the operation of the system core. In the kernel of Linux, second The storage device 16 will be treated as a general block input/output device (I/O device)' while we divide the memory When the page is swapped out to the switching space 20, the parameters accepted by the call submit_bio program include the number of sectors to be written (sector number), read/write command (r/w command), and memory address ( Memory address), memory length (memory length) and other information. The page to be swapped out can be processed by intercepting the submit_bio program. The above-mentioned paging that is to be swapped out is determined by the shirink_al ljemory program, and the decision is based on the use of the paging for this page rather than the physical address of the page in the main memory 14. We will first arrange the write requirements generated by the shirink_all_memory program. The physical memory addresses of this page are then sorted and merged to reduce the number of access/output (I/O) accesses and increase the input/output (I/O) request size. The larger the request size, the better the write performance of the second storage device 16 for flash memory. 201111966 When a memory page is swapped out, the kernel needs to record the position of this page in the switch space 20. The kernel is enabled to reload this page from the second storage device 20. Since the write-combining will rewrite the shirink_all_memory program, after each execution of the shirink_all_memory program, 'must determine the position of each page to be written to the switch space 20, then fill the information into the page. The page break discriminator in the table (swapped__ 〇 this identifier) 〇 g
r神所作之均 以上所述之實施例僅係為說明本發明之技術思想及特點,复 在使熟習此項技藝之人士能夠瞭解本發明之内容並據以實施,二的 以之限縣發明之專利細,較凡依本發騎揭示奸 *不能 等變化或修飾,仍應涵蓋在本發明之專利範圍内〇 " 【圖式簡單說明】 第一圖為本發明之架構示意圖。 第二圖為本發明之處理步驟流程圖。 【主要元件符號說明】 10電腦系統 12計算處理器 14主記憶體 • 16第二儲存裝置 W檔案系統 20切換空間 22休眠檔Rather, the embodiments described above are merely illustrative of the technical idea and features of the present invention, and those skilled in the art can understand the contents of the present invention and implement it according to the second invention. The patents are finer and more versatile and cannot be changed or modified according to the present invention. They should still be included in the scope of the patent of the present invention. The first figure is a schematic diagram of the structure of the present invention. The second figure is a flow chart of the processing steps of the present invention. [Main component symbol description] 10 computer system 12 calculation processor 14 main memory • 16 second storage device W file system 20 switching space 22 sleep file