]>
git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - drivers/lightnvm/pblk-cache.c
2 * Copyright (C) 2016 CNEX Labs
3 * Initial release: Javier Gonzalez <javier@cnexlabs.com>
4 * Matias Bjorling <matias@cnexlabs.com>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License version
8 * 2 as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * pblk-cache.c - pblk's write cache
20 int pblk_write_to_cache(struct pblk
*pblk
, struct bio
*bio
, unsigned long flags
)
22 struct pblk_w_ctx w_ctx
;
23 sector_t lba
= pblk_get_lba(bio
);
24 unsigned int bpos
, pos
;
25 int nr_entries
= pblk_get_secs(bio
);
28 /* Update the write buffer head (mem) with the entries that we can
29 * write. The write in itself cannot fail, so there is no need to
30 * rollback from here on.
33 ret
= pblk_rb_may_write_user(&pblk
->rwb
, bio
, nr_entries
, &bpos
);
34 if (ret
== NVM_IO_REQUEUE
) {
39 if (unlikely(!bio_has_data(bio
)))
43 pblk_ppa_set_empty(&w_ctx
.ppa
);
45 for (i
= 0; i
< nr_entries
; i
++) {
46 void *data
= bio_data(bio
);
50 pos
= pblk_rb_wrap_pos(&pblk
->rwb
, bpos
+ i
);
51 pblk_rb_write_entry_user(&pblk
->rwb
, data
, w_ctx
, pos
);
53 bio_advance(bio
, PBLK_EXPOSED_PAGE_SIZE
);
56 #ifdef CONFIG_NVM_DEBUG
57 atomic_long_add(nr_entries
, &pblk
->inflight_writes
);
58 atomic_long_add(nr_entries
, &pblk
->req_writes
);
62 pblk_write_should_kick(pblk
);
67 * On GC the incoming lbas are not necessarily sequential. Also, some of the
68 * lbas might not be valid entries, which are marked as empty by the GC thread
70 int pblk_write_gc_to_cache(struct pblk
*pblk
, void *data
, u64
*lba_list
,
71 unsigned int nr_entries
, unsigned int nr_rec_entries
,
72 struct pblk_line
*gc_line
, unsigned long flags
)
74 struct pblk_w_ctx w_ctx
;
75 unsigned int bpos
, pos
;
78 /* Update the write buffer head (mem) with the entries that we can
79 * write. The write in itself cannot fail, so there is no need to
80 * rollback from here on.
83 if (!pblk_rb_may_write_gc(&pblk
->rwb
, nr_rec_entries
, &bpos
)) {
89 pblk_ppa_set_empty(&w_ctx
.ppa
);
91 for (i
= 0, valid_entries
= 0; i
< nr_entries
; i
++) {
92 if (lba_list
[i
] == ADDR_EMPTY
)
95 w_ctx
.lba
= lba_list
[i
];
97 pos
= pblk_rb_wrap_pos(&pblk
->rwb
, bpos
+ valid_entries
);
98 pblk_rb_write_entry_gc(&pblk
->rwb
, data
, w_ctx
, gc_line
, pos
);
100 data
+= PBLK_EXPOSED_PAGE_SIZE
;
104 WARN_ONCE(nr_rec_entries
!= valid_entries
,
105 "pblk: inconsistent GC write\n");
107 #ifdef CONFIG_NVM_DEBUG
108 atomic_long_add(valid_entries
, &pblk
->inflight_writes
);
109 atomic_long_add(valid_entries
, &pblk
->recov_gc_writes
);
112 pblk_write_should_kick(pblk
);