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

Side by Side Diff: storage/browser/blob/README.md

Issue 2637023003: [BlobStorage] Adding explainer for blob storage system. (Closed)
Patch Set: Created 3 years, 11 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # Chrome's Blob Storage System Design
2 Elaboration of the blob storage system in Chrome.
jsbell 2017/01/18 01:05:50 Leave a blank after headers (# ## etc) Some markd
3
4 # What are blobs?
5 Please see [Mozilla's Blob documentation](https://developer.mozilla.org/en-US/do cs/Web/API/Blob) for a description of how Blobs are used in the Web Platform in general. For the purposes of this document, the important aspects of blobs are:
jsbell 2017/01/18 01:05:50 I'd wrap to 80 Also, I'd like to the File API spe
dmurph 2017/01/18 01:57:58 Done.
6
7 1. Blobs are immutable.
8 2. Blob can be made using one or more of: bytes, files, or other blobs.
9 3. Blobs can be 'sliced', which creates a blob that is a subsection of another b lob.
10 4. Reading blobs is asynchronous.
11 5. Blobs can be passed to other browsing contexts, such as Javascript workers or other tabs.
12
13 In Chrome, after blob creation the actual blob 'data' (gets transported to and) lives in the browser process. The renderer just holds a reference - specifically a string UUID - to the blob, which it can use to read the blob or pass it to ot her processes.
jsbell 2017/01/18 01:05:50 Why () here?
dmurph 2017/01/18 01:57:58 Done.
14
15 # Summary & Terminology
16
17 Blobs are created in the renderer process, where their data is temporarily held for the browser (while javascript execution can continue). When the browser has enough memory quota for the blob, it requests the data from the renderer. Once a ll data is transported and construction is complete, any pending reads for the b lob are allowed to complete.
jsbell 2017/01/18 01:05:50 Maybe note that blobs can be huge, e.g. GBs; other
jsbell 2017/01/18 01:05:50 Consistently capitalize (or not) javascript throug
18
19 If the in-memory space for blobs is getting full, or a new blob is too large to be in-memory, then the blob system uses the disk. This can either be paging old blobs to disk, or saving the new too-large blob straight to disk.
20
21 Blob reading goes through the network layer, where the renderer dispatches a net work request for the blob.
jsbell 2017/01/18 01:05:50 Maybe mention the type here, e.g. URLRequest (or w
dmurph 2017/01/18 01:57:58 Done.
22
23 Generally Chrome terminology:
jsbell 2017/01/18 01:05:50 Generally -> General ?
dmurph 2017/01/18 01:57:58 Done.
24
25 * **Renderer (Process)**: Process where the web contents and javascript lives. T his is basically a tab. There are multiple renderers, and they all have security restrictions.
26 * **Browser (Process)**: There is only one browser process, and it doesn't have security restrictions.
27 * **Shared Memory**: Memory that both the browser and renderer process can read & write. Created only between 2 processes.
28 * **IPC**: A message sent between processes. To avoid crashes and memory issues the blob system tries to limit the maximum size of an ipc message.
29
30 Blob system terminology:
31
32 * **Blob**: This is a blob object, which can consist of bytes or files, as descr ibed above.
33 * **BlobItem** or **[DataElement](https://cs.chromium.org/chromium/src/storage/c ommon/data_element.h)**: This is a primitive element that can basically be a Fil e, Bytes, or another Blob. It also stores an offset and size, so this can be a p art of a file. (This can also represent "future" file and "future" bytes, which is used to signify a bytes or file item that has not been transported yet).
34 * **dependent blobs**: These are blobs that our blob depends on to be constructe d. As in, we were constructed with a dependency on another blob (maybe we're a s lice or just a blob was in our constructor), and we might need to wait for these to complete constuction before we can declare ourselves constructed as well.
35 * **transportation strategy**: We can have one of 3 transportation strategies fo r Blobs: send data over IPC, Shared Memory, or Files.
36
37
38 # Blob Creation & Transportation (Renderer)
39 **This process is outlined with diagrams and illustrations [here](https://docs.g oogle.com/presentation/d/1MOm-8kacXAon1L2tF6VthesNjXgx0fp5AP17L7XDPSM/edit#slide =id.g75c319281_0_681).**
40
41 This outlines the renderer-side responsabilities of the blob system. The rendere r needs to:
42
43 1. Consolidate small bytes items into larger chunks (avoiding a huge array of 1 byte items).
44 2. Communicate the blob componsition to the browser immediately on construction .
45 3. Populate shared memory or files sent from the browser with the consolidated blob data items.
46 4. Hold the blob data until the browser is finished requesting it.
47
48 The meat of blob construction starts in the [WebBlobRegistryImpl](https://cs.chr omium.org/chromium/src/content/child/blob_storage/webblobregistry_impl.h)'s `cre ateBuilder(uuid, content_type)`.
49
50 ## Blob Data Consolidation
51 Since blobs are often constructed with arrays with single bytes, we try to conso lidate all **adjacent** memory blob items into one. This is done in [BlobConsoli dation](https://cs.chromium.org/chromium/src/content/child/blob_storage/blob_con solidation.h). The implementation doesn't actually do any copying or allocating of new memory buffers, instead it facilitates the transformation between the 'co nsolidated' blob items and the underlying bytes items. This way we don't waste a ny memory.
52
53 ## Blob Transportation, Renderer
54 After the blob has been 'consolidated', it is given to the [BlobTransportControl ler](https://cs.chromium.org/chromium/src/content/child/blob_storage/blob_transp ort_controller.h). This class:
55
56 1. Immediately communicates the contents of the blob to the Browser. We also [op timistically send](https://cs.chromium.org/chromium/src/content/child/blob_stora ge/blob_transport_controller.cc?l=325) the blob data if the total memory is less than our IPC threshold.
57 2. Stores the blob consolidation for data requests from the browser.
58 3. Answers requests from the browser to populate or send the blob data. The brow ser can request the renderer:
59 1. Send items and populate the data in IPC ([code](https://cs.chromium.org/chr omium/src/content/child/blob_storage/blob_transport_controller.cc?l=238)).
60 2. Populate items in shared memory and notify the browser when population is c omplete ([code](https://cs.chromium.org/chromium/src/content/child/blob_storage/ blob_transport_controller.cc?l=249)).
61 3. Populate items in files and notify the browser when population is complete ([code](https://cs.chromium.org/chromium/src/content/child/blob_storage/blob_tra nsport_controller.cc?l=292)).
62 4. Destroys the blob consolidation when the browser says it's done.
63
64 The transport controller also tries to keep the renderer alive while we are send ing blobs, as if the renderer is closed then we would lose any pending blob data . It does this by using the [incrementing and decrementing the process ref count ](https://cs.chromium.org/chromium/src/content/child/blob_storage/blob_transport _controller.cc?l=62), which should prevent fast shutdown.
65
66 # Blob Transportation & Storage (Browser).
67
68 The browser side is a little more complicated. We are thinking about:
69
70 1. Do we have enough space for this blob?
71 2. If so, how do we want to transport it? IPC? Shared Memory? IPC?
72 3. Can I save this in memory right now? Or do I need to wait for older blob data to be paged to disk?
73 4. Do I need to wait for files to be created?
74 5. Do I need to wait for dependent blobs?
75
76 ## Summary
77 We follow this general flow for constructing a blob on the browser side:
78
79 1. Does the blob fit, and what transportation strategy should be used.
80 2. Create our browser-side representation of the blob data, including any data i tems from dependent blobs. We try to share data items as much as possible, and a llow for the dependent blob items to be not populated yet.
81 3. Request memory and/or file quota from the BlobMemoryController, which manages our blob storage limits. Quota can be requested for both transportation and any copies we have to do from dependent blobs.
82 4. If transporation quota is needed and when it is granted:
83 1. Tell the BlobTransportHost to start asking for blob data given the earlier decision of strategy.
84 * The BlobTransportHost populates the browser-side blob data item.
85 2. When transportation is done we notify the BlobStorageContext
86 5. When transportation is done, copy quota is granted, and dependent blobs are c omplete, we finish the blob.
87 1. We perform any pending copies from dependent blobs
88 2. We notify any listeners that the blob has been completed.
89
90 Note: The transportation sections (steps 1, 2, 3) of this process are described (without thinking about blob dependencies) with diagrams and details in [this pr esentation](https://docs.google.com/presentation/d/1MOm-8kacXAon1L2tF6VthesNjXgx 0fp5AP17L7XDPSM/edit#slide=id.g75d5729ce_0_105).
91
92 ## BlobTransportHost
93 The `BlobTransportHost` is in charge of the actual transportation of the data fr om the renderer to the browser. When the initial description of the blob is sent to the browser, the BlobTransportHost asks the BlobMemoryController which 'stra tegy' (IPC, Shared Memory, or File) it should use to transport the file. Based o n this strategy it can transform the memory items sent from the renderer into a browser represetation to facilitate the transportation. See [this](https://docs. google.com/presentation/d/1MOm-8kacXAon1L2tF6VthesNjXgx0fp5AP17L7XDPSM/edit#slid e=id.g75d5729ce_0_145) slide, which illustrates how the browser might segment or split up the renderer's memory into transportable chunks.
94
95 Once the transport host decides it's strategy, it will create it's own transport state for the blob, including a `BlobDataBuilder` using the transport's data se gment representation. Then it will tell the `BlobStorageContext` that it is read y to build the blob.
96
97 When the `BlobStorageContext` tells the transport host that it is ready to trans port the blob data, this class's responsability is to populate the `BlobDataBuil der` with all the data from the renderer, then signal the storage context that i t is done.
98
99 ## BlobStorageContext
100 The `BlobStorageContext` is the hub of the blob storage system. It is responsibl e for creating & managing all the state of constructing blobs, as well as all bl ob handle generation and general blob status access.
101
102 When a `BlobDataBuilder` is given to the context, whether from the `BlobTranspor tHost` or from elsewhere, the context will do the following:
103
104 1. Find all dependent blobs in the new blob (any blob reference in the blob item list), and create a 'slice' of their items for the new blob.
105 2. Create the final blob item list representation, which creates a new blob item list which inserts these 'slice' items into the blob reference spots. This is ' flattening' the blob.
106 3. Ask the `BlobMemoryManager` for file or memory quota for the transportation i f necessary
107 * When this is approved, it notifies the `BlobTransportHost` that it can begin transporting the data.
108 4. Ask the `BlobMemoryManager` for memory quota for any copies necessary from th e blob slicing.
109 5. Adds completion callbacks to any dependent blobs that our blob depends on.
110
111 When all of the following conditions are met:
112
113 1. The `BlobTransportHost` tells us it has transported all the data (or we don't need to transport data),
114 2. The `BlobMemoryManager` approves our memory quota for slice copies (or we don 't need slice copies), and
115 3. All dependent blobs are completed (or we don't have dependent blobs),
116
117 The blob can finish constructing, where any pending blob slice copies are perfor med, and we set the status of the blob.
118
119 ### BlobStatus lifecycle
120 The BlobStatus outlines this procedure (specifically the transport process), and the copy memory quota and dependent blob process is encompassed in `PENDING_INT ERNALS`.
121
122 Once a blob is finished constructing, the status is set to `DONE`, or any of the `ERR_*` values if there was an error.
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698