Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(24)

Side by Side Diff: chrome/app/image_pre_reader_win.h

Issue 9235053: Add a PartialPreReadImage function to file_util (on Windows). (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: make image_pre_reader project windows only Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2006-2011 The Chromium Authors. All rights reserved.
chrisha 2012/02/03 16:31:08 New file: Copyright (c) 2012.
Roger McFarlane (Chromium) 2012/02/03 17:45:42 Done.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // This file defines utility functions pre-read a PE Image in order to avoid
6 // hard page faults when the image is subsequently loaded into memory for
7 // execution.
8
9 #ifndef CHROME_APP_IMAGE_PRE_READER_WIN_H_
10 #define CHROME_APP_IMAGE_PRE_READER_WIN_H_
11 #pragma once
12
13 #include "base/basictypes.h"
14
15 // This class defines static helper functions to pre-read a PE Image in order
16 // to avoid hard page faults when the image is subsequently loaded into memory
17 // for execution.
18 class ImagePreReader {
19 public:
20 // Reads the file passed in as a PE Image and touches pages to avoid
21 // subsequent hard page faults during LoadLibrary. The size to be pre read
Sigurður Ásgeirsson 2012/02/03 16:36:39 nit: pre read->pre-read
Roger McFarlane (Chromium) 2012/02/03 17:45:42 Done.
22 // is passed in. If it is 0 then the whole file is paged in. The step size
23 // which indicates the number of bytes to skip after every page touched is
24 // also passed in.
25 //
26 // This function checks the Windows version to determine which pre-reading
27 // mechanism to use.
28 static bool PreReadImage(const wchar_t* file_path,
29 size_t size_to_read,
30 size_t step_size);
31
32 // Loads the file passed in as PE Image and touches a percentage of the
33 // pages in each of the image's sections to avoid subsequent hard page
34 // faults during LoadLibrary.
35 //
36 // This function checks the Windows version to determine which pre-reading
37 // mechanism to use.
38 //
39 // The percentage of the file to be read is an integral value between 0 and
Sigurður Ásgeirsson 2012/02/03 16:36:39 great comment!
Roger McFarlane (Chromium) 2012/02/03 17:45:42 Thanks!
40 // 100, inclusive. If it is 0 then this is a NOP, if it is 100 (or greater)
41 // then the whole file is paged in sequentially via PreReadImage. Otherwise,
42 // for each section, in order, the given percentage of the blocks in that
43 // section are paged in, starting at the beginning of each section. For
44 // example: if percentage is 30 and there is a .text section and a .data
45 // section, then the first 30% of .text will be paged and the first 30% of
46 // .data will be paged in.
47 //
48 // The max_chunk_size indicates the number of bytes to read off the disk in
49 // each step (for Vista and greater, where where this is the way the pages
chrisha 2012/02/03 16:31:08 where where
Roger McFarlane (Chromium) 2012/02/03 17:45:42 Done.
50 // are warmed).
51 //
52 // This function is intended to be used in the context of a PE image with
53 // an optimized layout, such that the blocks in each section are arranged
54 // with the data and code most needed for startup moved to the front.
55 // See also: http://code.google.com/p/chromium/issues/detail?id=98508
56 static bool PartialPreReadImage(const wchar_t* file_path,
57 uint8 percentage,
58 size_t max_chunk_size);
59
60 // Helper function used by PartialPreReadImage on Windows versions (Vista+)
61 // where reading through the file on disk serves to warm up the page cache.
62 // Exported for unit-testing purposes.
63 static bool PartialPreReadImageOnDisk(const wchar_t* file_path,
64 uint8 percentage,
65 size_t max_chunk_size);
66
67 // Helper function used by PartialPreReadImage on Windows versions (XP) where
68 // cheaply loading the image then stepping through its address space serves
69 // to warm up the page cache. Exported for unit-testing purposes.
70 static bool PartialPreReadImageInMemory(const wchar_t* file_path,
71 uint8 percentage);
72 }; // namespace internal
73
74 #endif // CHROME_APP_IMAGE_PRE_READER_WIN_H_
chrisha 2012/02/03 16:31:08 Great comments, btw!
Roger McFarlane (Chromium) 2012/02/03 17:45:42 Thanks!
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698