Skip to content

Commit 73f233b

Browse files
Matthew Wilcox (Oracle)brauner
authored andcommitted
orangefs: Convert orangefs_writepages to contain an array of folios
The pages being passed in are always folios (since they come from the page cache). This eliminates several hidden calls to compound_head(), and uses of legacy APIs. Signed-off-by: "Matthew Wilcox (Oracle)" <[email protected]> Link: https://lore.kernel.org/r/[email protected] Tested-by: Mike Marshall <[email protected]> Signed-off-by: Christian Brauner <[email protected]>
1 parent 377afd9 commit 73f233b

File tree

1 file changed

+26
-31
lines changed

1 file changed

+26
-31
lines changed

fs/orangefs/inode.c

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ struct orangefs_writepages {
7070
kuid_t uid;
7171
kgid_t gid;
7272
int maxpages;
73-
int npages;
73+
int nfolios;
7474
struct address_space *mapping;
75-
struct page **pages;
75+
struct folio **folios;
7676
struct bio_vec *bv;
7777
};
7878

@@ -89,14 +89,14 @@ static int orangefs_writepages_work(struct orangefs_writepages *ow,
8989

9090
len = i_size_read(inode);
9191

92-
start = offset_in_page(ow->off);
93-
for (i = 0; i < ow->npages; i++) {
94-
set_page_writeback(ow->pages[i]);
95-
bvec_set_page(&ow->bv[i], ow->pages[i], PAGE_SIZE - start,
96-
start);
92+
start = offset_in_folio(ow->folios[0], ow->off);
93+
for (i = 0; i < ow->nfolios; i++) {
94+
folio_start_writeback(ow->folios[i]);
95+
bvec_set_folio(&ow->bv[i], ow->folios[i],
96+
folio_size(ow->folios[i]) - start, start);
9797
start = 0;
9898
}
99-
iov_iter_bvec(&iter, ITER_SOURCE, ow->bv, ow->npages, ow->len);
99+
iov_iter_bvec(&iter, ITER_SOURCE, ow->bv, ow->nfolios, ow->len);
100100

101101
WARN_ON(ow->off >= len);
102102
if (ow->off + ow->len > len)
@@ -112,16 +112,11 @@ static int orangefs_writepages_work(struct orangefs_writepages *ow,
112112
else
113113
ret = 0;
114114

115-
for (i = 0; i < ow->npages; i++) {
116-
if (PagePrivate(ow->pages[i])) {
117-
wrp = (struct orangefs_write_range *)
118-
page_private(ow->pages[i]);
119-
ClearPagePrivate(ow->pages[i]);
120-
put_page(ow->pages[i]);
121-
kfree(wrp);
122-
}
123-
end_page_writeback(ow->pages[i]);
124-
unlock_page(ow->pages[i]);
115+
for (i = 0; i < ow->nfolios; i++) {
116+
wrp = folio_detach_private(ow->folios[i]);
117+
kfree(wrp);
118+
folio_end_writeback(ow->folios[i]);
119+
folio_unlock(ow->folios[i]);
125120
}
126121

127122
return ret;
@@ -142,41 +137,41 @@ static int orangefs_writepages_callback(struct folio *folio,
142137
}
143138

144139
ret = -1;
145-
if (ow->npages == 0) {
140+
if (ow->nfolios == 0) {
146141
ow->off = wr->pos;
147142
ow->len = wr->len;
148143
ow->uid = wr->uid;
149144
ow->gid = wr->gid;
150-
ow->pages[ow->npages++] = &folio->page;
145+
ow->folios[ow->nfolios++] = folio;
151146
ret = 0;
152147
goto done;
153148
}
154149
if (!uid_eq(ow->uid, wr->uid) || !gid_eq(ow->gid, wr->gid)) {
155150
orangefs_writepages_work(ow, wbc);
156-
ow->npages = 0;
151+
ow->nfolios = 0;
157152
ret = -1;
158153
goto done;
159154
}
160155
if (ow->off + ow->len == wr->pos) {
161156
ow->len += wr->len;
162-
ow->pages[ow->npages++] = &folio->page;
157+
ow->folios[ow->nfolios++] = folio;
163158
ret = 0;
164159
goto done;
165160
}
166161
done:
167162
if (ret == -1) {
168-
if (ow->npages) {
163+
if (ow->nfolios) {
169164
orangefs_writepages_work(ow, wbc);
170-
ow->npages = 0;
165+
ow->nfolios = 0;
171166
}
172167
ret = orangefs_writepage_locked(folio, wbc);
173168
mapping_set_error(folio->mapping, ret);
174169
folio_unlock(folio);
175170
folio_end_writeback(folio);
176171
} else {
177-
if (ow->npages == ow->maxpages) {
172+
if (ow->nfolios == ow->maxpages) {
178173
orangefs_writepages_work(ow, wbc);
179-
ow->npages = 0;
174+
ow->nfolios = 0;
180175
}
181176
}
182177
return ret;
@@ -194,25 +189,25 @@ static int orangefs_writepages(struct address_space *mapping,
194189
if (!ow)
195190
return -ENOMEM;
196191
ow->maxpages = orangefs_bufmap_size_query()/PAGE_SIZE;
197-
ow->pages = kcalloc(ow->maxpages, sizeof(struct page *), GFP_KERNEL);
198-
if (!ow->pages) {
192+
ow->folios = kcalloc(ow->maxpages, sizeof(struct folio *), GFP_KERNEL);
193+
if (!ow->folios) {
199194
kfree(ow);
200195
return -ENOMEM;
201196
}
202197
ow->bv = kcalloc(ow->maxpages, sizeof(struct bio_vec), GFP_KERNEL);
203198
if (!ow->bv) {
204-
kfree(ow->pages);
199+
kfree(ow->folios);
205200
kfree(ow);
206201
return -ENOMEM;
207202
}
208203
ow->mapping = mapping;
209204
blk_start_plug(&plug);
210205
while ((folio = writeback_iter(mapping, wbc, folio, &error)))
211206
error = orangefs_writepages_callback(folio, wbc, ow);
212-
if (ow->npages)
207+
if (ow->nfolios)
213208
error = orangefs_writepages_work(ow, wbc);
214209
blk_finish_plug(&plug);
215-
kfree(ow->pages);
210+
kfree(ow->folios);
216211
kfree(ow->bv);
217212
kfree(ow);
218213
return error;

0 commit comments

Comments
 (0)