Skip to content

Commit dd59a64

Browse files
committed
orangefs: copy Orangefs-sized blocks into the pagecache if possible.
->readpage looks in file->private_data to try and find out how the userspace program set "count" in read(2) or with "dd bs=" or whatever. ->readpage uses "count" and inode->i_size to calculate how much data Orangefs should deposit in the Orangefs shared buffer, and remembers which slot the data is in. After copying data from the Orangefs shared buffer slot into "the page", readpage tries to increment through the pagecache index and fill as many pages as it can from the extra data in the shared buffer. Hopefully these extra pages will soon be needed by the vfs, and they'll be in the pagecache already. Signed-off-by: Mike Marshall <hubcap@omnibond.com> Signed-off-by: Martin Brandenburg <martin@omnibond.com>
1 parent 4077a0f commit dd59a64

5 files changed

Lines changed: 156 additions & 15 deletions

File tree

‎fs/orangefs/file.c‎

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ ssize_t wait_for_direct_io(enum ORANGEFS_io_type type, struct inode *inode,
5454
struct orangefs_kernel_op_s *new_op = NULL;
5555
int buffer_index = -1;
5656
ssize_t ret;
57+
size_t copy_amount;
5758

5859
new_op = op_alloc(ORANGEFS_VFS_OP_FILE_IO);
5960
if (!new_op)
@@ -212,8 +213,25 @@ ssize_t wait_for_direct_io(enum ORANGEFS_io_type type, struct inode *inode,
212213
* can futher be kernel-space or user-space addresses.
213214
* or it can pointers to struct page's
214215
*/
216+
217+
/*
218+
* When reading, readahead_size will only be zero when
219+
* we're doing O_DIRECT, otherwise we got here from
220+
* orangefs_readpage.
221+
*
222+
* If we got here from orangefs_readpage we want to
223+
* copy either a page or the whole file into the io
224+
* vector, whichever is smaller.
225+
*/
226+
if (readahead_size)
227+
copy_amount =
228+
min(new_op->downcall.resp.io.amt_complete,
229+
(__s64)PAGE_SIZE);
230+
else
231+
copy_amount = new_op->downcall.resp.io.amt_complete;
232+
215233
ret = orangefs_bufmap_copy_to_iovec(iter, buffer_index,
216-
new_op->downcall.resp.io.amt_complete);
234+
copy_amount);
217235
if (ret < 0) {
218236
gossip_err("%s: Failed to copy-out buffers. Please make sure that the pvfs2-client is running (%ld)\n",
219237
__func__, (long)ret);
@@ -231,10 +249,19 @@ ssize_t wait_for_direct_io(enum ORANGEFS_io_type type, struct inode *inode,
231249

232250
out:
233251
if (buffer_index >= 0) {
234-
orangefs_bufmap_put(buffer_index);
235-
gossip_debug(GOSSIP_FILE_DEBUG,
236-
"%s(%pU): PUT buffer_index %d\n",
237-
__func__, handle, buffer_index);
252+
if ((readahead_size) && (type == ORANGEFS_IO_READ)) {
253+
/* readpage */
254+
*index_return = buffer_index;
255+
gossip_debug(GOSSIP_FILE_DEBUG,
256+
"%s: hold on to buffer_index :%d:\n",
257+
__func__, buffer_index);
258+
} else {
259+
/* O_DIRECT */
260+
orangefs_bufmap_put(buffer_index);
261+
gossip_debug(GOSSIP_FILE_DEBUG,
262+
"%s(%pU): PUT buffer_index %d\n",
263+
__func__, handle, buffer_index);
264+
}
238265
buffer_index = -1;
239266
}
240267
op_release(new_op);

‎fs/orangefs/inode.c‎

Lines changed: 107 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -247,31 +247,80 @@ static int orangefs_writepages(struct address_space *mapping,
247247
return ret;
248248
}
249249

250+
static int orangefs_launder_page(struct page *);
251+
250252
static int orangefs_readpage(struct file *file, struct page *page)
251253
{
252254
struct inode *inode = page->mapping->host;
253255
struct iov_iter iter;
254256
struct bio_vec bv;
255257
ssize_t ret;
256-
loff_t off;
258+
loff_t off; /* offset into this page */
259+
pgoff_t index; /* which page */
260+
struct page *next_page;
261+
char *kaddr;
262+
struct orangefs_read_options *ro = file->private_data;
263+
loff_t read_size;
264+
loff_t roundedup;
265+
int buffer_index = -1; /* orangefs shared memory slot */
266+
int slot_index; /* index into slot */
267+
int remaining;
268+
269+
/*
270+
* If they set some miniscule size for "count" in read(2)
271+
* (for example) then let's try to read a page, or the whole file
272+
* if it is smaller than a page. Once "count" goes over a page
273+
* then lets round up to the highest page size multiple that is
274+
* less than or equal to "count" and do that much orangefs IO and
275+
* try to fill as many pages as we can from it.
276+
*
277+
* "count" should be represented in ro->blksiz.
278+
*
279+
* inode->i_size = file size.
280+
*/
281+
if (ro) {
282+
if (ro->blksiz < PAGE_SIZE) {
283+
if (inode->i_size < PAGE_SIZE)
284+
read_size = inode->i_size;
285+
else
286+
read_size = PAGE_SIZE;
287+
} else {
288+
roundedup = ((PAGE_SIZE - 1) & ro->blksiz) ?
289+
((ro->blksiz + PAGE_SIZE) & ~(PAGE_SIZE -1)) :
290+
ro->blksiz;
291+
if (roundedup > inode->i_size)
292+
read_size = inode->i_size;
293+
else
294+
read_size = roundedup;
295+
296+
}
297+
} else {
298+
read_size = PAGE_SIZE;
299+
}
300+
if (!read_size)
301+
read_size = PAGE_SIZE;
302+
303+
if (PageDirty(page))
304+
orangefs_launder_page(page);
257305

258306
off = page_offset(page);
307+
index = off >> PAGE_SHIFT;
259308
bv.bv_page = page;
260309
bv.bv_len = PAGE_SIZE;
261310
bv.bv_offset = 0;
262311
iov_iter_bvec(&iter, READ, &bv, 1, PAGE_SIZE);
263312

264-
if (PageDirty(page))
265-
orangefs_launder_page(page);
266-
267313
ret = wait_for_direct_io(ORANGEFS_IO_READ, inode, &off, &iter,
268-
PAGE_SIZE, inode->i_size, NULL, NULL);
314+
read_size, inode->i_size, NULL, &buffer_index);
315+
remaining = ret;
269316
/* this will only zero remaining unread portions of the page data */
270317
iov_iter_zero(~0U, &iter);
271318
/* takes care of potential aliasing */
272319
flush_dcache_page(page);
273320
if (ret < 0) {
274321
SetPageError(page);
322+
unlock_page(page);
323+
goto out;
275324
} else {
276325
SetPageUptodate(page);
277326
if (PageError(page))
@@ -280,11 +329,62 @@ static int orangefs_readpage(struct file *file, struct page *page)
280329
}
281330
/* unlock the page after the ->readpage() routine completes */
282331
unlock_page(page);
332+
333+
if (remaining > PAGE_SIZE) {
334+
slot_index = 0;
335+
while ((remaining - PAGE_SIZE) >= PAGE_SIZE) {
336+
remaining -= PAGE_SIZE;
337+
/*
338+
* It is an optimization to try and fill more than one
339+
* page... by now we've already gotten the single
340+
* page we were after, if stuff doesn't seem to
341+
* be going our way at this point just return
342+
* and hope for the best.
343+
*
344+
* If we look for pages and they're already there is
345+
* one reason to give up, and if they're not there
346+
* and we can't create them is another reason.
347+
*/
348+
349+
index++;
350+
slot_index++;
351+
next_page = find_get_page(inode->i_mapping, index);
352+
if (next_page) {
353+
gossip_debug(GOSSIP_FILE_DEBUG,
354+
"%s: found next page, quitting\n",
355+
__func__);
356+
put_page(next_page);
357+
goto out;
358+
}
359+
next_page = find_or_create_page(inode->i_mapping,
360+
index,
361+
GFP_KERNEL);
362+
/*
363+
* I've never hit this, leave it as a printk for
364+
* now so it will be obvious.
365+
*/
366+
if (!next_page) {
367+
printk("%s: can't create next page, quitting\n",
368+
__func__);
369+
goto out;
370+
}
371+
kaddr = kmap_atomic(next_page);
372+
orangefs_bufmap_page_fill(kaddr,
373+
buffer_index,
374+
slot_index);
375+
kunmap_atomic(kaddr);
376+
SetPageUptodate(next_page);
377+
unlock_page(next_page);
378+
put_page(next_page);
379+
}
380+
}
381+
382+
out:
383+
if (buffer_index != -1)
384+
orangefs_bufmap_put(buffer_index);
283385
return ret;
284386
}
285387

286-
static int orangefs_launder_page(struct page *);
287-
288388
static int orangefs_write_begin(struct file *file,
289389
struct address_space *mapping,
290390
loff_t pos, unsigned len, unsigned flags, struct page **pagep,
@@ -326,7 +426,6 @@ static int orangefs_write_begin(struct file *file,
326426
if (ret)
327427
return ret;
328428
}
329-
330429
}
331430

332431
wr = kmalloc(sizeof *wr, GFP_KERNEL);

‎fs/orangefs/orangefs-bufmap.c‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,3 +538,16 @@ int orangefs_bufmap_copy_to_iovec(struct iov_iter *iter,
538538
}
539539
return 0;
540540
}
541+
542+
void orangefs_bufmap_page_fill(void *page_to,
543+
int buffer_index,
544+
int slot_index)
545+
{
546+
struct orangefs_bufmap_desc *from;
547+
void *page_from;
548+
549+
from = &__orangefs_bufmap->desc_array[buffer_index];
550+
page_from = kmap_atomic(from->page_array[slot_index]);
551+
memcpy(page_to, page_from, PAGE_SIZE);
552+
kunmap_atomic(page_from);
553+
}

‎fs/orangefs/orangefs-bufmap.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,6 @@ int orangefs_bufmap_copy_to_iovec(struct iov_iter *iter,
3434
int buffer_index,
3535
size_t size);
3636

37+
void orangefs_bufmap_page_fill(void *kaddr, int buffer_index, int slot_index);
38+
3739
#endif /* __ORANGEFS_BUFMAP_H */

‎fs/orangefs/orangefs-debugfs.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -963,7 +963,7 @@ int orangefs_debugfs_new_client_mask(void __user *arg)
963963
return ret;
964964
}
965965

966-
int orangefs_debugfs_new_client_string(void __user *arg)
966+
int orangefs_debugfs_new_client_string(void __user *arg)
967967
{
968968
int ret;
969969

@@ -1016,7 +1016,7 @@ int orangefs_debugfs_new_client_string(void __user *arg)
10161016
return 0;
10171017
}
10181018

1019-
int orangefs_debugfs_new_debug(void __user *arg)
1019+
int orangefs_debugfs_new_debug(void __user *arg)
10201020
{
10211021
struct dev_mask_info_s mask_info = {0};
10221022
int ret;

0 commit comments

Comments
 (0)