4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * 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 version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
34 * Lustre Lite I/O page cache routines shared by different kernel revs
37 #include <linux/kernel.h>
39 #include <linux/string.h>
40 #include <linux/stat.h>
41 #include <linux/errno.h>
42 #include <linux/unistd.h>
43 #include <linux/writeback.h>
44 #include <asm/uaccess.h>
47 #include <linux/file.h>
48 #include <linux/stat.h>
49 #include <asm/uaccess.h>
51 #include <linux/pagemap.h>
52 /* current_is_kswapd() */
53 #include <linux/swap.h>
54 #include <linux/task_io_accounting_ops.h>
56 #define DEBUG_SUBSYSTEM S_LLITE
58 #include <obd_cksum.h>
59 #include "llite_internal.h"
60 #include <lustre_compat.h>
62 static void ll_ra_stats_inc_sbi(struct ll_sb_info *sbi, enum ra_stat which);
65 * Get readahead pages from the filesystem readahead pool of the client for a
68 * /param sbi superblock for filesystem readahead state ll_ra_info
69 * /param ria per-thread readahead state
70 * /param pages number of pages requested for readahead for the thread.
72 * WARNING: This algorithm is used to reduce contention on sbi->ll_lock.
73 * It should work well if the ra_max_pages is much greater than the single
74 * file's read-ahead window, and not too many threads contending for
75 * these readahead pages.
77 * TODO: There may be a 'global sync problem' if many threads are trying
78 * to get an ra budget that is larger than the remaining readahead pages
79 * and reach here at exactly the same time. They will compute /a ret to
80 * consume the remaining pages, but will fail at atomic_add_return() and
81 * get a zero ra window, although there is still ra space remaining. - Jay */
83 static unsigned long ll_ra_count_get(struct ll_sb_info *sbi,
84 struct ra_io_arg *ria,
86 unsigned long pages_min)
88 struct ll_ra_info *ra = &sbi->ll_ra_info;
92 /* If read-ahead pages left are less than 1M, do not do read-ahead,
93 * otherwise it will form small read RPC(< 1M), which hurt server
94 * performance a lot. */
95 ret = min(ra->ra_max_pages - atomic_read(&ra->ra_cur_pages),
97 if (ret < 0 || ret < min_t(long, PTLRPC_MAX_BRW_PAGES, pages))
100 if (atomic_add_return(ret, &ra->ra_cur_pages) > ra->ra_max_pages) {
101 atomic_sub(ret, &ra->ra_cur_pages);
106 if (ret < pages_min) {
107 /* override ra limit for maximum performance */
108 atomic_add(pages_min - ret, &ra->ra_cur_pages);
114 void ll_ra_count_put(struct ll_sb_info *sbi, unsigned long pages)
116 struct ll_ra_info *ra = &sbi->ll_ra_info;
117 atomic_sub(pages, &ra->ra_cur_pages);
120 static void ll_ra_stats_inc_sbi(struct ll_sb_info *sbi, enum ra_stat which)
122 LASSERTF(which < _NR_RA_STAT, "which: %u\n", which);
123 lprocfs_counter_incr(sbi->ll_ra_stats, which);
126 void ll_ra_stats_inc(struct inode *inode, enum ra_stat which)
128 struct ll_sb_info *sbi = ll_i2sbi(inode);
129 ll_ra_stats_inc_sbi(sbi, which);
132 #define RAS_CDEBUG(ras) \
134 "lre %llu cr %lu cb %llu wsi %lu wp %lu nra %lu rpc %lu " \
135 "r %lu csr %lu so %llu sb %llu sl %llu lr %lu\n", \
136 ras->ras_last_read_end_bytes, ras->ras_consecutive_requests, \
137 ras->ras_consecutive_bytes, ras->ras_window_start_idx, \
138 ras->ras_window_pages, ras->ras_next_readahead_idx, \
139 ras->ras_rpc_pages, ras->ras_requests, \
140 ras->ras_consecutive_stride_requests, ras->ras_stride_offset, \
141 ras->ras_stride_bytes, ras->ras_stride_length, \
142 ras->ras_async_last_readpage_idx)
144 static bool pos_in_window(loff_t pos, loff_t point,
145 unsigned long before, unsigned long after)
147 loff_t start = point - before;
148 loff_t end = point + after;
155 return start <= pos && pos <= end;
159 * Initiates read-ahead of a page with given index.
161 * \retval +ve: page was already uptodate so it will be skipped
163 * \retval -ve: page wasn't added to \a queue for error;
164 * \retval 0: page was added into \a queue for read ahead.
166 static int ll_read_ahead_page(const struct lu_env *env, struct cl_io *io,
167 struct cl_page_list *queue, pgoff_t index)
169 struct cl_object *clob = io->ci_obj;
170 struct inode *inode = vvp_object_inode(clob);
172 struct cl_page *page;
173 struct vvp_page *vpg;
174 enum ra_stat which = _NR_RA_STAT; /* keep gcc happy */
176 const char *msg = NULL;
179 vmpage = grab_cache_page_nowait(inode->i_mapping, index);
180 if (vmpage == NULL) {
181 which = RA_STAT_FAILED_GRAB_PAGE;
182 msg = "g_c_p_n failed";
183 GOTO(out, rc = -EBUSY);
186 /* Check if vmpage was truncated or reclaimed */
187 if (vmpage->mapping != inode->i_mapping) {
188 which = RA_STAT_WRONG_GRAB_PAGE;
189 msg = "g_c_p_n returned invalid page";
190 GOTO(out, rc = -EBUSY);
193 page = cl_page_find(env, clob, vmpage->index, vmpage, CPT_CACHEABLE);
195 which = RA_STAT_FAILED_GRAB_PAGE;
196 msg = "cl_page_find failed";
197 GOTO(out, rc = PTR_ERR(page));
200 lu_ref_add(&page->cp_reference, "ra", current);
201 cl_page_assume(env, io, page);
202 vpg = cl2vvp_page(cl_object_page_slice(clob, page));
203 if (!vpg->vpg_defer_uptodate && !PageUptodate(vmpage)) {
204 vpg->vpg_defer_uptodate = 1;
205 vpg->vpg_ra_used = 0;
206 cl_page_list_add(queue, page);
208 /* skip completed pages */
209 cl_page_unassume(env, io, page);
210 /* This page is already uptodate, returning a positive number
211 * to tell the callers about this */
215 lu_ref_del(&page->cp_reference, "ra", current);
216 cl_page_put(env, page);
219 if (vmpage != NULL) {
225 ll_ra_stats_inc(inode, which);
226 CDEBUG(D_READA, "%s\n", msg);
233 #define RIA_DEBUG(ria) \
234 CDEBUG(D_READA, "rs %lu re %lu ro %llu rl %llu rb %llu\n", \
235 ria->ria_start_idx, ria->ria_end_idx, ria->ria_stoff, \
236 ria->ria_length, ria->ria_bytes)
238 static inline int stride_io_mode(struct ll_readahead_state *ras)
240 return ras->ras_consecutive_stride_requests > 1;
243 /* The function calculates how many bytes will be read in
244 * [off, off + length], in such stride IO area,
245 * stride_offset = st_off, stride_lengh = st_len,
246 * stride_bytes = st_bytes
248 * |------------------|*****|------------------|*****|------------|*****|....
251 * |----- st_len -----|
253 * How many bytes it should read in such pattern
254 * |-------------------------------------------------------------|
256 * |<------ length ------->|
258 * = |<----->| + |-------------------------------------| + |---|
259 * start_left st_bytes * i end_left
261 static loff_t stride_byte_count(loff_t st_off, loff_t st_len, loff_t st_bytes,
262 loff_t off, loff_t length)
264 u64 start = off > st_off ? off - st_off : 0;
265 u64 end = off + length > st_off ? off + length - st_off : 0;
270 if (st_len == 0 || length == 0 || end == 0)
273 start = div64_u64_rem(start, st_len, &start_left);
274 if (start_left < st_bytes)
275 start_left = st_bytes - start_left;
279 end = div64_u64_rem(end, st_len, &end_left);
280 if (end_left > st_bytes)
283 CDEBUG(D_READA, "start %llu, end %llu start_left %llu end_left %llu\n",
284 start, end, start_left, end_left);
287 bytes_count = end_left - (st_bytes - start_left);
289 bytes_count = start_left +
290 st_bytes * (end - start - 1) + end_left;
293 "st_off %llu, st_len %llu st_bytes %llu off %llu length %llu bytescount %llu\n",
294 st_off, st_len, st_bytes, off, length, bytes_count);
299 static unsigned long ria_page_count(struct ra_io_arg *ria)
301 loff_t length_bytes = ria->ria_end_idx >= ria->ria_start_idx ?
302 (loff_t)(ria->ria_end_idx -
303 ria->ria_start_idx + 1) << PAGE_SHIFT : 0;
306 if (ria->ria_length > ria->ria_bytes && ria->ria_bytes &&
307 (ria->ria_length & ~PAGE_MASK || ria->ria_bytes & ~PAGE_MASK ||
308 ria->ria_stoff & ~PAGE_MASK)) {
309 /* Over-estimate un-aligned page stride read */
310 unsigned long pg_count = ((ria->ria_bytes +
311 PAGE_SIZE - 1) >> PAGE_SHIFT) + 1;
312 pg_count *= length_bytes / ria->ria_length + 1;
316 bytes_count = stride_byte_count(ria->ria_stoff, ria->ria_length,
318 (loff_t)ria->ria_start_idx<<PAGE_SHIFT,
320 return (bytes_count + PAGE_SIZE - 1) >> PAGE_SHIFT;
323 static pgoff_t ras_align(struct ll_readahead_state *ras, pgoff_t index)
325 return index - (index % ras->ras_rpc_pages);
328 /* Check whether the index is in the defined ra-window */
329 static bool ras_inside_ra_window(pgoff_t idx, struct ra_io_arg *ria)
331 loff_t pos = (loff_t)idx << PAGE_SHIFT;
333 /* If ria_length == ria_bytes, it means non-stride I/O mode,
334 * idx should always inside read-ahead window in this case
335 * For stride I/O mode, just check whether the idx is inside
338 if (ria->ria_length == 0 || ria->ria_length == ria->ria_bytes)
341 if (pos >= ria->ria_stoff) {
344 div64_u64_rem(pos - ria->ria_stoff, ria->ria_length, &offset);
346 if (offset < ria->ria_bytes ||
347 (ria->ria_length - offset) < PAGE_SIZE)
349 } else if (pos + PAGE_SIZE > ria->ria_stoff) {
357 ll_read_ahead_pages(const struct lu_env *env, struct cl_io *io,
358 struct cl_page_list *queue, struct ll_readahead_state *ras,
359 struct ra_io_arg *ria, pgoff_t *ra_end)
361 struct cl_read_ahead ra = { 0 };
362 int rc = 0, count = 0;
365 LASSERT(ria != NULL);
368 for (page_idx = ria->ria_start_idx;
369 page_idx <= ria->ria_end_idx && ria->ria_reserved > 0;
371 if (ras_inside_ra_window(page_idx, ria)) {
372 if (ra.cra_end_idx == 0 || ra.cra_end_idx < page_idx) {
375 cl_read_ahead_release(env, &ra);
377 rc = cl_io_read_ahead(env, io, page_idx, &ra);
381 /* Do not shrink ria_end_idx at any case until
382 * the minimum end of current read is covered.
383 * And only shrink ria_end_idx if the matched
384 * LDLM lock doesn't cover more. */
385 if (page_idx > ra.cra_end_idx ||
386 (ra.cra_contention &&
387 page_idx > ria->ria_end_idx_min)) {
388 ria->ria_end_idx = ra.cra_end_idx;
392 CDEBUG(D_READA, "idx: %lu, ra: %lu, rpc: %lu\n",
393 page_idx, ra.cra_end_idx,
395 LASSERTF(ra.cra_end_idx >= page_idx,
396 "object: %p, indcies %lu / %lu\n",
397 io->ci_obj, ra.cra_end_idx, page_idx);
398 /* update read ahead RPC size.
399 * NB: it's racy but doesn't matter */
400 if (ras->ras_rpc_pages != ra.cra_rpc_pages &&
401 ra.cra_rpc_pages > 0)
402 ras->ras_rpc_pages = ra.cra_rpc_pages;
403 /* trim it to align with optimal RPC size */
404 end_idx = ras_align(ras, ria->ria_end_idx + 1);
405 if (end_idx > 0 && !ria->ria_eof)
406 ria->ria_end_idx = end_idx - 1;
407 if (ria->ria_end_idx < ria->ria_end_idx_min)
408 ria->ria_end_idx = ria->ria_end_idx_min;
410 if (page_idx > ria->ria_end_idx)
413 /* If the page is inside the read-ahead window */
414 rc = ll_read_ahead_page(env, io, queue, page_idx);
419 /* Only subtract from reserve & count the page if we
420 * really did readahead on that page. */
425 } else if (stride_io_mode(ras)) {
426 /* If it is not in the read-ahead window, and it is
427 * read-ahead mode, then check whether it should skip
430 loff_t pos = (loff_t)page_idx << PAGE_SHIFT;
433 div64_u64_rem(pos - ria->ria_stoff, ria->ria_length,
435 if (offset >= ria->ria_bytes) {
436 pos += (ria->ria_length - offset);
437 if ((pos >> PAGE_SHIFT) >= page_idx + 1)
438 page_idx = (pos >> PAGE_SHIFT) - 1;
440 "Stride: jump %llu pages to %lu\n",
441 ria->ria_length - offset, page_idx);
447 cl_read_ahead_release(env, &ra);
452 static void ll_readahead_work_free(struct ll_readahead_work *work)
454 fput(work->lrw_file);
458 static void ll_readahead_handle_work(struct work_struct *wq);
459 static void ll_readahead_work_add(struct inode *inode,
460 struct ll_readahead_work *work)
462 INIT_WORK(&work->lrw_readahead_work, ll_readahead_handle_work);
463 queue_work(ll_i2sbi(inode)->ll_ra_info.ll_readahead_wq,
464 &work->lrw_readahead_work);
467 static int ll_readahead_file_kms(const struct lu_env *env,
468 struct cl_io *io, __u64 *kms)
470 struct cl_object *clob;
472 struct cl_attr *attr = vvp_env_thread_attr(env);
476 inode = vvp_object_inode(clob);
478 cl_object_attr_lock(clob);
479 ret = cl_object_attr_get(env, clob, attr);
480 cl_object_attr_unlock(clob);
485 *kms = attr->cat_kms;
489 static void ll_readahead_handle_work(struct work_struct *wq)
491 struct ll_readahead_work *work;
494 struct ra_io_arg *ria;
496 struct ll_file_data *fd;
497 struct ll_readahead_state *ras;
499 struct cl_2queue *queue;
500 pgoff_t ra_end_idx = 0;
501 unsigned long pages, pages_min = 0;
507 work = container_of(wq, struct ll_readahead_work,
509 fd = LUSTRE_FPRIVATE(work->lrw_file);
511 file = work->lrw_file;
512 inode = file_inode(file);
514 env = cl_env_alloc(&refcheck, LCT_NOREF);
516 GOTO(out_free_work, rc = PTR_ERR(env));
518 io = vvp_env_thread_io(env);
519 ll_io_init(io, file, CIT_READ, NULL);
521 rc = ll_readahead_file_kms(env, io, &kms);
523 GOTO(out_put_env, rc);
526 ll_ra_stats_inc(inode, RA_STAT_ZERO_LEN);
527 GOTO(out_put_env, rc = 0);
530 ria = &ll_env_info(env)->lti_ria;
531 memset(ria, 0, sizeof(*ria));
533 ria->ria_start_idx = work->lrw_start_idx;
534 /* Truncate RA window to end of file */
535 eof_index = (pgoff_t)(kms - 1) >> PAGE_SHIFT;
536 if (eof_index <= work->lrw_end_idx) {
537 work->lrw_end_idx = eof_index;
540 if (work->lrw_end_idx <= work->lrw_start_idx)
541 GOTO(out_put_env, rc = 0);
543 ria->ria_end_idx = work->lrw_end_idx;
544 pages = ria->ria_end_idx - ria->ria_start_idx + 1;
545 ria->ria_reserved = ll_ra_count_get(ll_i2sbi(inode), ria,
546 ria_page_count(ria), pages_min);
549 "async reserved pages: %lu/%lu/%lu, ra_cur %d, ra_max %lu\n",
550 ria->ria_reserved, pages, pages_min,
551 atomic_read(&ll_i2sbi(inode)->ll_ra_info.ra_cur_pages),
552 ll_i2sbi(inode)->ll_ra_info.ra_max_pages);
554 if (ria->ria_reserved < pages) {
555 ll_ra_stats_inc(inode, RA_STAT_MAX_IN_FLIGHT);
556 if (PAGES_TO_MiB(ria->ria_reserved) < 1) {
557 ll_ra_count_put(ll_i2sbi(inode), ria->ria_reserved);
558 GOTO(out_put_env, rc = 0);
562 rc = cl_io_rw_init(env, io, CIT_READ, ria->ria_start_idx, pages);
564 GOTO(out_put_env, rc);
566 vvp_env_io(env)->vui_io_subtype = IO_NORMAL;
567 vvp_env_io(env)->vui_fd = fd;
568 io->ci_state = CIS_LOCKED;
569 io->ci_async_readahead = true;
570 rc = cl_io_start(env, io);
572 GOTO(out_io_fini, rc);
574 queue = &io->ci_queue;
575 cl_2queue_init(queue);
577 rc = ll_read_ahead_pages(env, io, &queue->c2_qin, ras, ria,
579 if (ria->ria_reserved != 0)
580 ll_ra_count_put(ll_i2sbi(inode), ria->ria_reserved);
581 if (queue->c2_qin.pl_nr > 0) {
582 int count = queue->c2_qin.pl_nr;
584 rc = cl_io_submit_rw(env, io, CRT_READ, queue);
586 task_io_account_read(PAGE_SIZE * count);
588 if (ria->ria_end_idx == ra_end_idx && ra_end_idx == (kms >> PAGE_SHIFT))
589 ll_ra_stats_inc(inode, RA_STAT_EOF);
591 if (ra_end_idx != ria->ria_end_idx)
592 ll_ra_stats_inc(inode, RA_STAT_FAILED_REACH_END);
594 /* TODO: discard all pages until page reinit route is implemented */
595 cl_page_list_discard(env, io, &queue->c2_qin);
597 /* Unlock unsent read pages in case of error. */
598 cl_page_list_disown(env, io, &queue->c2_qin);
600 cl_2queue_fini(env, queue);
605 cl_env_put(env, &refcheck);
608 ll_ra_stats_inc_sbi(ll_i2sbi(inode), RA_STAT_ASYNC);
609 ll_readahead_work_free(work);
612 static int ll_readahead(const struct lu_env *env, struct cl_io *io,
613 struct cl_page_list *queue,
614 struct ll_readahead_state *ras, bool hit,
617 struct vvp_io *vio = vvp_env_io(env);
618 struct ll_thread_info *lti = ll_env_info(env);
619 unsigned long pages, pages_min = 0;
620 pgoff_t ra_end_idx = 0, start_idx = 0, end_idx = 0;
622 struct ra_io_arg *ria = <i->lti_ria;
623 struct cl_object *clob;
629 inode = vvp_object_inode(clob);
631 memset(ria, 0, sizeof(*ria));
632 ret = ll_readahead_file_kms(env, io, &kms);
637 ll_ra_stats_inc(inode, RA_STAT_ZERO_LEN);
641 spin_lock(&ras->ras_lock);
644 * Note: other thread might rollback the ras_next_readahead_idx,
645 * if it can not get the full size of prepared pages, see the
646 * end of this function. For stride read ahead, it needs to
647 * make sure the offset is no less than ras_stride_offset,
648 * so that stride read ahead can work correctly.
650 if (stride_io_mode(ras))
651 start_idx = max_t(pgoff_t, ras->ras_next_readahead_idx,
652 ras->ras_stride_offset >> PAGE_SHIFT);
654 start_idx = ras->ras_next_readahead_idx;
656 if (ras->ras_window_pages > 0)
657 end_idx = ras->ras_window_start_idx + ras->ras_window_pages - 1;
659 /* Enlarge the RA window to encompass the full read */
660 if (vio->vui_ra_valid &&
661 end_idx < vio->vui_ra_start_idx + vio->vui_ra_pages - 1)
662 end_idx = vio->vui_ra_start_idx + vio->vui_ra_pages - 1;
667 /* Truncate RA window to end of file */
668 eof_index = (pgoff_t)((kms - 1) >> PAGE_SHIFT);
669 if (eof_index <= end_idx) {
674 ria->ria_start_idx = start_idx;
675 ria->ria_end_idx = end_idx;
676 /* If stride I/O mode is detected, get stride window*/
677 if (stride_io_mode(ras)) {
678 ria->ria_stoff = ras->ras_stride_offset;
679 ria->ria_length = ras->ras_stride_length;
680 ria->ria_bytes = ras->ras_stride_bytes;
682 spin_unlock(&ras->ras_lock);
685 ll_ra_stats_inc(inode, RA_STAT_ZERO_WINDOW);
688 pages = ria_page_count(ria);
690 ll_ra_stats_inc(inode, RA_STAT_ZERO_WINDOW);
695 CDEBUG(D_READA, DFID": ria: %lu/%lu, bead: %lu/%lu, hit: %d\n",
696 PFID(lu_object_fid(&clob->co_lu)),
697 ria->ria_start_idx, ria->ria_end_idx,
698 vio->vui_ra_valid ? vio->vui_ra_start_idx : 0,
699 vio->vui_ra_valid ? vio->vui_ra_pages : 0,
702 /* at least to extend the readahead window to cover current read */
703 if (!hit && vio->vui_ra_valid &&
704 vio->vui_ra_start_idx + vio->vui_ra_pages > ria->ria_start_idx)
705 ria->ria_end_idx_min =
706 vio->vui_ra_start_idx + vio->vui_ra_pages - 1;
708 ria->ria_reserved = ll_ra_count_get(ll_i2sbi(inode), ria, pages,
710 if (ria->ria_reserved < pages)
711 ll_ra_stats_inc(inode, RA_STAT_MAX_IN_FLIGHT);
713 CDEBUG(D_READA, "reserved pages: %lu/%lu/%lu, ra_cur %d, ra_max %lu\n",
714 ria->ria_reserved, pages, pages_min,
715 atomic_read(&ll_i2sbi(inode)->ll_ra_info.ra_cur_pages),
716 ll_i2sbi(inode)->ll_ra_info.ra_max_pages);
718 ret = ll_read_ahead_pages(env, io, queue, ras, ria, &ra_end_idx);
720 if (ria->ria_reserved != 0)
721 ll_ra_count_put(ll_i2sbi(inode), ria->ria_reserved);
723 if (ra_end_idx == end_idx && ra_end_idx == (kms >> PAGE_SHIFT))
724 ll_ra_stats_inc(inode, RA_STAT_EOF);
727 "ra_end_idx = %lu end_idx = %lu stride end = %lu pages = %d\n",
728 ra_end_idx, end_idx, ria->ria_end_idx, ret);
730 if (ra_end_idx != end_idx)
731 ll_ra_stats_inc(inode, RA_STAT_FAILED_REACH_END);
732 if (ra_end_idx > 0) {
733 /* update the ras so that the next read-ahead tries from
734 * where we left off. */
735 spin_lock(&ras->ras_lock);
736 ras->ras_next_readahead_idx = ra_end_idx + 1;
737 spin_unlock(&ras->ras_lock);
744 static void ras_set_start(struct ll_readahead_state *ras, pgoff_t index)
746 ras->ras_window_start_idx = ras_align(ras, index);
749 /* called with the ras_lock held or from places where it doesn't matter */
750 static void ras_reset(struct ll_readahead_state *ras, pgoff_t index)
752 ras->ras_consecutive_requests = 0;
753 ras->ras_consecutive_bytes = 0;
754 ras->ras_window_pages = 0;
755 ras_set_start(ras, index);
756 ras->ras_next_readahead_idx = max(ras->ras_window_start_idx, index + 1);
761 /* called with the ras_lock held or from places where it doesn't matter */
762 static void ras_stride_reset(struct ll_readahead_state *ras)
764 ras->ras_consecutive_stride_requests = 0;
765 ras->ras_stride_length = 0;
766 ras->ras_stride_bytes = 0;
770 void ll_readahead_init(struct inode *inode, struct ll_readahead_state *ras)
772 spin_lock_init(&ras->ras_lock);
773 ras->ras_rpc_pages = PTLRPC_MAX_BRW_PAGES;
775 ras->ras_last_read_end_bytes = 0;
776 ras->ras_requests = 0;
780 * Check whether the read request is in the stride window.
781 * If it is in the stride window, return true, otherwise return false.
783 static bool read_in_stride_window(struct ll_readahead_state *ras,
784 loff_t pos, loff_t count)
788 if (ras->ras_stride_length == 0 || ras->ras_stride_bytes == 0 ||
789 ras->ras_stride_bytes == ras->ras_stride_length)
792 stride_gap = pos - ras->ras_last_read_end_bytes - 1;
794 /* If it is contiguous read */
796 return ras->ras_consecutive_bytes + count <=
797 ras->ras_stride_bytes;
799 /* Otherwise check the stride by itself */
800 return (ras->ras_stride_length - ras->ras_stride_bytes) == stride_gap &&
801 ras->ras_consecutive_bytes == ras->ras_stride_bytes &&
802 count <= ras->ras_stride_bytes;
805 static void ras_init_stride_detector(struct ll_readahead_state *ras,
806 loff_t pos, loff_t count)
808 loff_t stride_gap = pos - ras->ras_last_read_end_bytes - 1;
810 LASSERT(ras->ras_consecutive_stride_requests == 0);
812 if (pos <= ras->ras_last_read_end_bytes) {
813 /*Reset stride window for forward read*/
814 ras_stride_reset(ras);
818 ras->ras_stride_bytes = ras->ras_consecutive_bytes;
819 ras->ras_stride_length = stride_gap + ras->ras_consecutive_bytes;
820 ras->ras_consecutive_stride_requests++;
821 ras->ras_stride_offset = pos;
827 stride_page_count(struct ll_readahead_state *ras, loff_t len)
830 stride_byte_count(ras->ras_stride_offset,
831 ras->ras_stride_length, ras->ras_stride_bytes,
832 ras->ras_stride_offset, len);
834 return (bytes_count + PAGE_SIZE - 1) >> PAGE_SHIFT;
837 /* Stride Read-ahead window will be increased inc_len according to
838 * stride I/O pattern */
839 static void ras_stride_increase_window(struct ll_readahead_state *ras,
840 struct ll_ra_info *ra, loff_t inc_bytes)
842 loff_t window_bytes, stride_bytes;
847 /* temporarily store in page units to reduce LASSERT() cost below */
848 end = ras->ras_window_start_idx + ras->ras_window_pages;
850 LASSERT(ras->ras_stride_length > 0);
851 LASSERTF(end >= (ras->ras_stride_offset >> PAGE_SHIFT),
852 "window_start_idx %lu, window_pages %lu stride_offset %llu\n",
853 ras->ras_window_start_idx, ras->ras_window_pages,
854 ras->ras_stride_offset);
857 if (end <= ras->ras_stride_offset)
860 stride_bytes = end - ras->ras_stride_offset;
862 div64_u64_rem(stride_bytes, ras->ras_stride_length, &left_bytes);
863 window_bytes = ((loff_t)ras->ras_window_pages << PAGE_SHIFT) -
866 if (left_bytes < ras->ras_stride_bytes)
867 left_bytes += inc_bytes;
869 left_bytes = ras->ras_stride_bytes + inc_bytes;
871 LASSERT(ras->ras_stride_bytes != 0);
873 step = div64_u64_rem(left_bytes, ras->ras_stride_bytes, &left_bytes);
875 window_bytes += step * ras->ras_stride_length + left_bytes;
877 if (stride_page_count(ras, window_bytes) <= ra->ra_max_pages_per_file)
878 ras->ras_window_pages = (window_bytes >> PAGE_SHIFT);
883 static void ras_increase_window(struct inode *inode,
884 struct ll_readahead_state *ras,
885 struct ll_ra_info *ra)
887 /* The stretch of ra-window should be aligned with max rpc_size
888 * but current clio architecture does not support retrieve such
889 * information from lower layer. FIXME later
891 if (stride_io_mode(ras)) {
892 ras_stride_increase_window(ras, ra,
893 (loff_t)ras->ras_rpc_pages << PAGE_SHIFT);
895 pgoff_t window_pages;
897 window_pages = min(ras->ras_window_pages + ras->ras_rpc_pages,
898 ra->ra_max_pages_per_file);
899 if (window_pages < ras->ras_rpc_pages)
900 ras->ras_window_pages = window_pages;
902 ras->ras_window_pages = ras_align(ras, window_pages);
907 * Seek within 8 pages are considered as sequential read for now.
909 static inline bool is_loose_seq_read(struct ll_readahead_state *ras, loff_t pos)
911 return pos_in_window(pos, ras->ras_last_read_end_bytes,
912 8UL << PAGE_SHIFT, 8UL << PAGE_SHIFT);
915 static void ras_detect_read_pattern(struct ll_readahead_state *ras,
916 struct ll_sb_info *sbi,
917 loff_t pos, size_t count, bool mmap)
919 bool stride_detect = false;
920 pgoff_t index = pos >> PAGE_SHIFT;
923 * Reset the read-ahead window in two cases. First when the app seeks
924 * or reads to some other part of the file. Secondly if we get a
925 * read-ahead miss that we think we've previously issued. This can
926 * be a symptom of there being so many read-ahead pages that the VM
927 * is reclaiming it before we get to it.
929 if (!is_loose_seq_read(ras, pos)) {
930 /* Check whether it is in stride I/O mode */
931 if (!read_in_stride_window(ras, pos, count)) {
932 if (ras->ras_consecutive_stride_requests == 0)
933 ras_init_stride_detector(ras, pos, count);
935 ras_stride_reset(ras);
936 ras->ras_consecutive_bytes = 0;
937 ras_reset(ras, index);
939 ras->ras_consecutive_bytes = 0;
940 ras->ras_consecutive_requests = 0;
941 if (++ras->ras_consecutive_stride_requests > 1)
942 stride_detect = true;
945 ll_ra_stats_inc_sbi(sbi, RA_STAT_DISTANT_READPAGE);
946 } else if (stride_io_mode(ras)) {
948 * If this is contiguous read but in stride I/O mode
949 * currently, check whether stride step still is valid,
950 * if invalid, it will reset the stride ra window to
953 if (!read_in_stride_window(ras, pos, count)) {
954 ras_stride_reset(ras);
955 ras->ras_window_pages = 0;
956 ras->ras_next_readahead_idx = index;
960 ras->ras_consecutive_bytes += count;
962 pgoff_t idx = ras->ras_consecutive_bytes >> PAGE_SHIFT;
964 if ((idx >= 4 && (idx & 3UL) == 0) || stride_detect)
965 ras->ras_need_increase_window = true;
966 } else if ((ras->ras_consecutive_requests > 1 || stride_detect)) {
967 ras->ras_need_increase_window = true;
970 ras->ras_last_read_end_bytes = pos + count - 1;
973 void ll_ras_enter(struct file *f, loff_t pos, size_t count)
975 struct ll_file_data *fd = LUSTRE_FPRIVATE(f);
976 struct ll_readahead_state *ras = &fd->fd_ras;
977 struct inode *inode = file_inode(f);
978 unsigned long index = pos >> PAGE_SHIFT;
979 struct ll_sb_info *sbi = ll_i2sbi(inode);
981 spin_lock(&ras->ras_lock);
983 ras->ras_consecutive_requests++;
984 ras->ras_need_increase_window = false;
985 ras->ras_no_miss_check = false;
987 * On the second access to a file smaller than the tunable
988 * ra_max_read_ahead_whole_pages trigger RA on all pages in the
989 * file up to ra_max_pages_per_file. This is simply a best effort
990 * and only occurs once per open file. Normal RA behavior is reverted
991 * to for subsequent IO.
993 if (ras->ras_requests >= 2) {
995 struct ll_ra_info *ra = &sbi->ll_ra_info;
997 kms_pages = (i_size_read(inode) + PAGE_SIZE - 1) >>
1000 CDEBUG(D_READA, "kmsp %llu mwp %lu mp %lu\n", kms_pages,
1001 ra->ra_max_read_ahead_whole_pages,
1002 ra->ra_max_pages_per_file);
1005 kms_pages <= ra->ra_max_read_ahead_whole_pages) {
1006 ras->ras_window_start_idx = 0;
1007 ras->ras_next_readahead_idx = index + 1;
1008 ras->ras_window_pages = min(ra->ra_max_pages_per_file,
1009 ra->ra_max_read_ahead_whole_pages);
1010 ras->ras_no_miss_check = true;
1011 GOTO(out_unlock, 0);
1014 ras_detect_read_pattern(ras, sbi, pos, count, false);
1016 spin_unlock(&ras->ras_lock);
1019 static bool index_in_stride_window(struct ll_readahead_state *ras,
1022 loff_t pos = (loff_t)index << PAGE_SHIFT;
1024 if (ras->ras_stride_length == 0 || ras->ras_stride_bytes == 0 ||
1025 ras->ras_stride_bytes == ras->ras_stride_length)
1028 if (pos >= ras->ras_stride_offset) {
1031 div64_u64_rem(pos - ras->ras_stride_offset,
1032 ras->ras_stride_length, &offset);
1033 if (offset < ras->ras_stride_bytes ||
1034 ras->ras_stride_length - offset < PAGE_SIZE)
1036 } else if (ras->ras_stride_offset - pos < PAGE_SIZE) {
1044 * ll_ras_enter() is used to detect read pattern according to pos and count.
1046 * ras_update() is used to detect cache miss and
1047 * reset window or increase window accordingly
1049 static void ras_update(struct ll_sb_info *sbi, struct inode *inode,
1050 struct ll_readahead_state *ras, pgoff_t index,
1051 enum ras_update_flags flags)
1053 struct ll_ra_info *ra = &sbi->ll_ra_info;
1054 bool hit = flags & LL_RAS_HIT;
1057 spin_lock(&ras->ras_lock);
1060 CDEBUG(D_READA, DFID " pages at %lu miss.\n",
1061 PFID(ll_inode2fid(inode)), index);
1062 ll_ra_stats_inc_sbi(sbi, hit ? RA_STAT_HIT : RA_STAT_MISS);
1065 * The readahead window has been expanded to cover whole
1066 * file size, we don't care whether ra miss happen or not.
1067 * Because we will read whole file to page cache even if
1068 * some pages missed.
1070 if (ras->ras_no_miss_check)
1071 GOTO(out_unlock, 0);
1073 if (flags & LL_RAS_MMAP)
1074 ras_detect_read_pattern(ras, sbi, (loff_t)index << PAGE_SHIFT,
1077 if (!hit && ras->ras_window_pages &&
1078 index < ras->ras_next_readahead_idx &&
1079 pos_in_window(index, ras->ras_window_start_idx, 0,
1080 ras->ras_window_pages)) {
1081 ll_ra_stats_inc_sbi(sbi, RA_STAT_MISS_IN_WINDOW);
1082 ras->ras_need_increase_window = false;
1084 if (index_in_stride_window(ras, index) &&
1085 stride_io_mode(ras)) {
1087 * if (index != ras->ras_last_readpage + 1)
1088 * ras->ras_consecutive_pages = 0;
1090 ras_reset(ras, index);
1093 * If stride-RA hit cache miss, the stride
1094 * detector will not be reset to avoid the
1095 * overhead of redetecting read-ahead mode,
1096 * but on the condition that the stride window
1097 * is still intersect with normal sequential
1098 * read-ahead window.
1100 if (ras->ras_window_start_idx < ras->ras_stride_offset)
1101 ras_stride_reset(ras);
1105 * Reset both stride window and normal RA
1108 ras_reset(ras, index);
1109 /* ras->ras_consecutive_pages++; */
1110 ras->ras_consecutive_bytes = 0;
1111 ras_stride_reset(ras);
1112 GOTO(out_unlock, 0);
1115 ras_set_start(ras, index);
1117 if (stride_io_mode(ras)) {
1118 /* Since stride readahead is sentivite to the offset
1119 * of read-ahead, so we use original offset here,
1120 * instead of ras_window_start_idx, which is RPC aligned.
1122 ras->ras_next_readahead_idx = max(index + 1,
1123 ras->ras_next_readahead_idx);
1124 ras->ras_window_start_idx =
1125 max_t(pgoff_t, ras->ras_window_start_idx,
1126 ras->ras_stride_offset >> PAGE_SHIFT);
1128 if (ras->ras_next_readahead_idx < ras->ras_window_start_idx)
1129 ras->ras_next_readahead_idx = ras->ras_window_start_idx;
1131 ras->ras_next_readahead_idx = index + 1;
1134 if (ras->ras_need_increase_window) {
1135 ras_increase_window(inode, ras, ra);
1136 ras->ras_need_increase_window = false;
1141 spin_unlock(&ras->ras_lock);
1144 int ll_writepage(struct page *vmpage, struct writeback_control *wbc)
1146 struct inode *inode = vmpage->mapping->host;
1147 struct ll_inode_info *lli = ll_i2info(inode);
1150 struct cl_page *page;
1151 struct cl_object *clob;
1152 bool redirtied = false;
1153 bool unlocked = false;
1158 LASSERT(PageLocked(vmpage));
1159 LASSERT(!PageWriteback(vmpage));
1161 LASSERT(ll_i2dtexp(inode) != NULL);
1163 env = cl_env_get(&refcheck);
1165 GOTO(out, result = PTR_ERR(env));
1167 clob = ll_i2info(inode)->lli_clob;
1168 LASSERT(clob != NULL);
1170 io = vvp_env_thread_io(env);
1172 io->ci_ignore_layout = 1;
1173 result = cl_io_init(env, io, CIT_MISC, clob);
1175 page = cl_page_find(env, clob, vmpage->index,
1176 vmpage, CPT_CACHEABLE);
1177 if (!IS_ERR(page)) {
1178 lu_ref_add(&page->cp_reference, "writepage",
1180 cl_page_assume(env, io, page);
1181 result = cl_page_flush(env, io, page);
1184 * Re-dirty page on error so it retries write,
1185 * but not in case when IO has actually
1186 * occurred and completed with an error.
1188 if (!PageError(vmpage)) {
1189 redirty_page_for_writepage(wbc, vmpage);
1194 cl_page_disown(env, io, page);
1196 lu_ref_del(&page->cp_reference,
1197 "writepage", current);
1198 cl_page_put(env, page);
1200 result = PTR_ERR(page);
1203 cl_io_fini(env, io);
1205 if (redirtied && wbc->sync_mode == WB_SYNC_ALL) {
1206 loff_t offset = cl_offset(clob, vmpage->index);
1208 /* Flush page failed because the extent is being written out.
1209 * Wait for the write of extent to be finished to avoid
1210 * breaking kernel which assumes ->writepage should mark
1211 * PageWriteback or clean the page. */
1212 result = cl_sync_file_range(inode, offset,
1213 offset + PAGE_SIZE - 1,
1216 /* actually we may have written more than one page.
1217 * decreasing this page because the caller will count
1219 wbc->nr_to_write -= result - 1;
1224 cl_env_put(env, &refcheck);
1229 if (!lli->lli_async_rc)
1230 lli->lli_async_rc = result;
1231 SetPageError(vmpage);
1233 unlock_page(vmpage);
1238 int ll_writepages(struct address_space *mapping, struct writeback_control *wbc)
1240 struct inode *inode = mapping->host;
1243 enum cl_fsync_mode mode;
1244 int range_whole = 0;
1248 if (wbc->range_cyclic) {
1249 start = (loff_t)mapping->writeback_index << PAGE_SHIFT;
1250 end = OBD_OBJECT_EOF;
1252 start = wbc->range_start;
1253 end = wbc->range_end;
1254 if (end == LLONG_MAX) {
1255 end = OBD_OBJECT_EOF;
1256 range_whole = start == 0;
1260 mode = CL_FSYNC_NONE;
1261 if (wbc->sync_mode == WB_SYNC_ALL)
1262 mode = CL_FSYNC_LOCAL;
1264 if (ll_i2info(inode)->lli_clob == NULL)
1267 /* for directio, it would call writepages() to evict cached pages
1268 * inside the IO context of write, which will cause deadlock at
1269 * layout_conf since it waits for active IOs to complete. */
1270 result = cl_sync_file_range(inode, start, end, mode, 1);
1272 wbc->nr_to_write -= result;
1276 if (wbc->range_cyclic || (range_whole && wbc->nr_to_write > 0)) {
1277 if (end == OBD_OBJECT_EOF)
1278 mapping->writeback_index = 0;
1280 mapping->writeback_index = (end >> PAGE_SHIFT) + 1;
1285 struct ll_cl_context *ll_cl_find(struct file *file)
1287 struct ll_file_data *fd = LUSTRE_FPRIVATE(file);
1288 struct ll_cl_context *lcc;
1289 struct ll_cl_context *found = NULL;
1291 read_lock(&fd->fd_lock);
1292 list_for_each_entry(lcc, &fd->fd_lccs, lcc_list) {
1293 if (lcc->lcc_cookie == current) {
1298 read_unlock(&fd->fd_lock);
1303 void ll_cl_add(struct file *file, const struct lu_env *env, struct cl_io *io,
1306 struct ll_file_data *fd = LUSTRE_FPRIVATE(file);
1307 struct ll_cl_context *lcc = &ll_env_info(env)->lti_io_ctx;
1309 memset(lcc, 0, sizeof(*lcc));
1310 INIT_LIST_HEAD(&lcc->lcc_list);
1311 lcc->lcc_cookie = current;
1314 lcc->lcc_type = type;
1316 write_lock(&fd->fd_lock);
1317 list_add(&lcc->lcc_list, &fd->fd_lccs);
1318 write_unlock(&fd->fd_lock);
1321 void ll_cl_remove(struct file *file, const struct lu_env *env)
1323 struct ll_file_data *fd = LUSTRE_FPRIVATE(file);
1324 struct ll_cl_context *lcc = &ll_env_info(env)->lti_io_ctx;
1326 write_lock(&fd->fd_lock);
1327 list_del_init(&lcc->lcc_list);
1328 write_unlock(&fd->fd_lock);
1331 int ll_io_read_page(const struct lu_env *env, struct cl_io *io,
1332 struct cl_page *page, struct file *file)
1334 struct inode *inode = vvp_object_inode(page->cp_obj);
1335 struct ll_sb_info *sbi = ll_i2sbi(inode);
1336 struct ll_file_data *fd = LUSTRE_FPRIVATE(file);
1337 struct ll_readahead_state *ras = &fd->fd_ras;
1338 struct cl_2queue *queue = &io->ci_queue;
1339 struct cl_sync_io *anchor = NULL;
1340 struct vvp_page *vpg;
1345 vpg = cl2vvp_page(cl_object_page_slice(page->cp_obj, page));
1346 uptodate = vpg->vpg_defer_uptodate;
1348 if (sbi->ll_ra_info.ra_max_pages_per_file > 0 &&
1349 sbi->ll_ra_info.ra_max_pages > 0 &&
1350 !vpg->vpg_ra_updated) {
1351 struct vvp_io *vio = vvp_env_io(env);
1352 enum ras_update_flags flags = 0;
1355 flags |= LL_RAS_HIT;
1356 if (!vio->vui_ra_valid)
1357 flags |= LL_RAS_MMAP;
1358 ras_update(sbi, inode, ras, vvp_index(vpg), flags);
1361 cl_2queue_init(queue);
1363 vpg->vpg_ra_used = 1;
1364 cl_page_export(env, page, 1);
1365 cl_page_disown(env, io, page);
1367 anchor = &vvp_env_info(env)->vti_anchor;
1368 cl_sync_io_init(anchor, 1);
1369 page->cp_sync_io = anchor;
1371 cl_2queue_add(queue, page);
1374 if (sbi->ll_ra_info.ra_max_pages_per_file > 0 &&
1375 sbi->ll_ra_info.ra_max_pages > 0) {
1378 rc2 = ll_readahead(env, io, &queue->c2_qin, ras,
1380 CDEBUG(D_READA, DFID "%d pages read ahead at %lu\n",
1381 PFID(ll_inode2fid(inode)), rc2, vvp_index(vpg));
1384 if (queue->c2_qin.pl_nr > 0) {
1385 int count = queue->c2_qin.pl_nr;
1386 rc = cl_io_submit_rw(env, io, CRT_READ, queue);
1388 task_io_account_read(PAGE_SIZE * count);
1392 if (anchor != NULL && !cl_page_is_owned(page, io)) { /* have sent */
1393 rc = cl_sync_io_wait(env, anchor, 0);
1395 cl_page_assume(env, io, page);
1396 cl_page_list_del(env, &queue->c2_qout, page);
1398 if (!PageUptodate(cl_page_vmpage(page))) {
1399 /* Failed to read a mirror, discard this page so that
1400 * new page can be created with new mirror.
1402 * TODO: this is not needed after page reinit
1403 * route is implemented */
1404 cl_page_discard(env, io, page);
1406 cl_page_disown(env, io, page);
1409 /* TODO: discard all pages until page reinit route is implemented */
1410 cl_page_list_discard(env, io, &queue->c2_qin);
1412 /* Unlock unsent read pages in case of error. */
1413 cl_page_list_disown(env, io, &queue->c2_qin);
1415 cl_2queue_fini(env, queue);
1421 * Possible return value:
1422 * 0 no async readahead triggered and fast read could not be used.
1423 * 1 no async readahead, but fast read could be used.
1424 * 2 async readahead triggered and fast read could be used too.
1427 static int kickoff_async_readahead(struct file *file, unsigned long pages)
1429 struct ll_readahead_work *lrw;
1430 struct inode *inode = file_inode(file);
1431 struct ll_sb_info *sbi = ll_i2sbi(inode);
1432 struct ll_file_data *fd = LUSTRE_FPRIVATE(file);
1433 struct ll_readahead_state *ras = &fd->fd_ras;
1434 struct ll_ra_info *ra = &sbi->ll_ra_info;
1435 unsigned long throttle;
1436 pgoff_t start_idx = ras_align(ras, ras->ras_next_readahead_idx);
1437 pgoff_t end_idx = start_idx + pages - 1;
1439 throttle = min(ra->ra_async_pages_per_file_threshold,
1440 ra->ra_max_pages_per_file);
1442 * If this is strided i/o or the window is smaller than the
1443 * throttle limit, we do not do async readahead. Otherwise,
1444 * we do async readahead, allowing the user thread to do fast i/o.
1446 if (stride_io_mode(ras) || !throttle ||
1447 ras->ras_window_pages < throttle)
1450 if ((atomic_read(&ra->ra_cur_pages) + pages) > ra->ra_max_pages)
1453 if (ras->ras_async_last_readpage_idx == start_idx)
1456 /* ll_readahead_work_free() free it */
1459 lrw->lrw_file = get_file(file);
1460 lrw->lrw_start_idx = start_idx;
1461 lrw->lrw_end_idx = end_idx;
1462 spin_lock(&ras->ras_lock);
1463 ras->ras_next_readahead_idx = end_idx + 1;
1464 ras->ras_async_last_readpage_idx = start_idx;
1465 spin_unlock(&ras->ras_lock);
1466 ll_readahead_work_add(inode, lrw);
1474 int ll_readpage(struct file *file, struct page *vmpage)
1476 struct inode *inode = file_inode(file);
1477 struct cl_object *clob = ll_i2info(inode)->lli_clob;
1478 struct ll_cl_context *lcc;
1479 const struct lu_env *env = NULL;
1480 struct cl_io *io = NULL;
1481 struct cl_page *page;
1482 struct ll_sb_info *sbi = ll_i2sbi(inode);
1486 lcc = ll_cl_find(file);
1492 if (io == NULL) { /* fast read */
1493 struct inode *inode = file_inode(file);
1494 struct ll_file_data *fd = LUSTRE_FPRIVATE(file);
1495 struct ll_readahead_state *ras = &fd->fd_ras;
1496 struct lu_env *local_env = NULL;
1497 unsigned long fast_read_pages =
1498 max(RA_REMAIN_WINDOW_MIN, ras->ras_rpc_pages);
1499 struct vvp_page *vpg;
1503 /* TODO: need to verify the layout version to make sure
1504 * the page is not invalid due to layout change. */
1505 page = cl_vmpage_page(vmpage, clob);
1507 unlock_page(vmpage);
1508 ll_ra_stats_inc_sbi(sbi, RA_STAT_FAILED_FAST_READ);
1512 vpg = cl2vvp_page(cl_object_page_slice(page->cp_obj, page));
1513 if (vpg->vpg_defer_uptodate) {
1514 enum ras_update_flags flags = LL_RAS_HIT;
1516 if (lcc && lcc->lcc_type == LCC_MMAP)
1517 flags |= LL_RAS_MMAP;
1519 /* For fast read, it updates read ahead state only
1520 * if the page is hit in cache because non cache page
1521 * case will be handled by slow read later. */
1522 ras_update(sbi, inode, ras, vvp_index(vpg), flags);
1523 /* avoid duplicate ras_update() call */
1524 vpg->vpg_ra_updated = 1;
1526 /* Check if we can issue a readahead RPC, if that is
1527 * the case, we can't do fast IO because we will need
1528 * a cl_io to issue the RPC. */
1529 if (ras->ras_window_start_idx + ras->ras_window_pages <
1530 ras->ras_next_readahead_idx + fast_read_pages ||
1531 kickoff_async_readahead(file, fast_read_pages) > 0)
1536 local_env = cl_env_percpu_get();
1540 /* export the page and skip io stack */
1542 vpg->vpg_ra_used = 1;
1543 cl_page_export(env, page, 1);
1545 ll_ra_stats_inc_sbi(sbi, RA_STAT_FAILED_FAST_READ);
1547 /* release page refcount before unlocking the page to ensure
1548 * the object won't be destroyed in the calling path of
1549 * cl_page_put(). Please see comment in ll_releasepage(). */
1550 cl_page_put(env, page);
1551 unlock_page(vmpage);
1553 cl_env_percpu_put(local_env);
1558 LASSERT(io->ci_state == CIS_IO_GOING);
1559 page = cl_page_find(env, clob, vmpage->index, vmpage, CPT_CACHEABLE);
1560 if (!IS_ERR(page)) {
1561 LASSERT(page->cp_type == CPT_CACHEABLE);
1562 if (likely(!PageUptodate(vmpage))) {
1563 cl_page_assume(env, io, page);
1565 result = ll_io_read_page(env, io, page, file);
1567 /* Page from a non-object file. */
1568 unlock_page(vmpage);
1571 cl_page_put(env, page);
1573 unlock_page(vmpage);
1574 result = PTR_ERR(page);