Flash Translation Layer  1.0
page.h
Go to the documentation of this file.
1 
8 #ifndef PAGE_H
9 #define PAGE_H
10 
11 #include <stdint.h>
12 #include <pthread.h>
13 
14 #include <limits.h>
15 #include <unistd.h>
16 
17 #include <glib.h>
18 
19 #include "flash.h"
20 #include "device.h"
21 
22 #define PAGE_FTL_CACHE_SIZE (2)
23 #define PAGE_FTL_GC_RATIO \
24  ((double)30 / \
25  100)
26 #define PAGE_FTL_GC_THRESHOLD \
27  ((double)80 / \
28  100)
30 enum { PAGE_FTL_IOCTL_TRIM = 0,
31 };
32 
41  gint is_gc;
42 
43  uint64_t *use_bits;
44  GList *lpn_list;
45 };
46 
50 struct page_ftl {
51  uint32_t *trans_map;
52  uint64_t alloc_segnum;
54  struct device *dev;
55  pthread_mutex_t mutex;
56  pthread_rwlock_t gc_rwlock;
57  pthread_rwlock_t *bus_rwlock;
58 #ifdef PAGE_FTL_USE_GLOBAL_RWLOCK
59  pthread_rwlock_t rwlock;
60 #endif
61  pthread_t gc_thread;
62  int o_flags;
63 
64  GList *gc_list;
65  uint64_t *gc_seg_bits;
66 };
67 
68 /* page-interface.c */
69 int page_ftl_open(struct page_ftl *, const char *name, int flags);
70 int page_ftl_close(struct page_ftl *);
71 
72 ssize_t page_ftl_submit_request(struct page_ftl *, struct device_request *);
73 ssize_t page_ftl_write(struct page_ftl *, struct device_request *);
74 ssize_t page_ftl_read(struct page_ftl *, struct device_request *);
75 
76 int page_ftl_module_init(struct flash_device *, uint64_t flags);
78 
79 /* page-map.c */
81 int page_ftl_update_map(struct page_ftl *, size_t sector, uint32_t ppn);
82 
83 /* page-core.c */
85 
86 /* page-gc.c */
87 int page_ftl_do_gc(struct page_ftl *);
88 
89 static inline size_t page_ftl_get_map_size(struct page_ftl *pgftl)
90 {
91  struct device *dev = pgftl->dev;
92  return ((device_get_total_size(dev) / device_get_page_size(dev)) + 1) *
93  sizeof(uint32_t);
94 }
95 static inline size_t page_ftl_get_lpn(struct page_ftl *pgftl, size_t sector)
96 {
97  return sector / device_get_page_size(pgftl->dev);
98 }
99 
100 static inline size_t page_ftl_get_page_offset(struct page_ftl *pgftl,
101  size_t sector)
102 {
103  return sector % device_get_page_size(pgftl->dev);
104 }
105 
106 static inline size_t page_ftl_get_segment_number(struct page_ftl *pgftl,
107  uintptr_t segment)
108 {
109  return (segment - (uintptr_t)pgftl->segments) /
110  sizeof(struct page_ftl_segment);
111 }
112 #endif
pthread_rwlock_t * bus_rwlock
Definition: page.h:57
int page_ftl_module_init(struct flash_device *, uint64_t flags)
initialize the page flash translation layer module
Definition: page-interface.c:336
static size_t page_ftl_get_page_offset(struct page_ftl *pgftl, size_t sector)
Definition: page.h:100
uint32_t * trans_map
Definition: page.h:51
uint64_t * gc_seg_bits
Definition: page.h:65
int o_flags
Definition: page.h:62
generic device address format
Definition: device.h:95
pthread_mutex_t mutex
Definition: page.h:55
GList * lpn_list
Definition: page.h:44
int page_ftl_close(struct page_ftl *)
deallocate the page ftl structure&#39;s members
Definition: page-core.c:432
static size_t page_ftl_get_map_size(struct page_ftl *pgftl)
Definition: page.h:89
pthread_t gc_thread
Definition: page.h:61
int page_ftl_update_map(struct page_ftl *, size_t sector, uint32_t ppn)
pthread_rwlock_t gc_rwlock
Definition: page.h:56
int page_ftl_module_exit(struct flash_device *)
free resources in the page flash translation layer module
Definition: page-interface.c:379
int page_ftl_open(struct page_ftl *, const char *name, int flags)
allocate the page ftl structure&#39;s members
Definition: page-core.c:228
metadata of the device
Definition: device.h:163
int page_ftl_segment_data_init(struct page_ftl *, struct page_ftl_segment *)
initialize the page ftl&#39;s segment data only
Definition: page-core.c:151
ssize_t page_ftl_submit_request(struct page_ftl *, struct device_request *)
submit the request to the valid function
Definition: page-core.c:345
gint is_gc
Definition: page.h:41
ssize_t page_ftl_write(struct page_ftl *, struct device_request *)
the core logic for writing the request to the device.
Definition: page-write.c:147
contain the page flash translation layer information
Definition: page.h:50
int page_ftl_do_gc(struct page_ftl *)
core logic of the garbage collection
Definition: page-gc.c:251
uint64_t * use_bits
Definition: page.h:43
uint64_t alloc_segnum
Definition: page.h:52
gint nr_valid_pages
Definition: page.h:40
struct device_address page_ftl_get_free_page(struct page_ftl *)
get page from the segment
Definition: page-map.c:22
static size_t device_get_total_size(struct device *dev)
total size of a flash board
Definition: device.h:248
static size_t page_ftl_get_lpn(struct page_ftl *pgftl, size_t sector)
Definition: page.h:95
segment information structure
Definition: page.h:38
struct page_ftl_segment * segments
Definition: page.h:53
struct device * dev
Definition: ramdisk-test.c:10
contain the device information header
GList * gc_list
Definition: page.h:64
gint nr_free_pages
Definition: page.h:39
static size_t page_ftl_get_segment_number(struct page_ftl *pgftl, uintptr_t segment)
Definition: page.h:106
generic flash control interfaces&#39; header
struct device * dev
Definition: page.h:54
contain the flash device information
Definition: flash.h:31
static size_t device_get_page_size(struct device *dev)
get flash board&#39;s NAND page size
Definition: device.h:232
ssize_t page_ftl_read(struct page_ftl *, struct device_request *)
the core logic for reading the request to the device.
Definition: page-read.c:56
request for device
Definition: device.h:110