1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
38 * Author: Nikita Danilov <nikita.danilov@sun.com>
41 #define DEBUG_SUBSYSTEM S_CLASS
43 # define EXPORT_SYMTAB
46 #include <libcfs/libcfs.h>
47 #include <obd_class.h>
48 #include <obd_support.h>
49 #include <libcfs/list.h>
51 #include <cl_object.h>
52 #include "cl_internal.h"
54 static void cl_page_delete0(const struct lu_env *env, struct cl_page *pg,
57 static cfs_mem_cache_t *cl_page_kmem = NULL;
59 static struct lu_kmem_descr cl_page_caches[] = {
61 .ckd_cache = &cl_page_kmem,
62 .ckd_name = "cl_page_kmem",
63 .ckd_size = sizeof (struct cl_page)
71 # define PASSERT(env, page, expr) \
73 if (unlikely(!(expr))) { \
74 CL_PAGE_DEBUG(D_ERROR, (env), (page), #expr "\n"); \
78 #else /* !LIBCFS_DEBUG */
79 # define PASSERT(env, page, exp) \
80 ((void)sizeof(env), (void)sizeof(page), (void)sizeof !!(exp))
81 #endif /* !LIBCFS_DEBUG */
83 #ifdef INVARIANT_CHECK
84 # define PINVRNT(env, page, expr) \
86 if (unlikely(!(expr))) { \
87 CL_PAGE_DEBUG(D_ERROR, (env), (page), #expr "\n"); \
91 #else /* !INVARIANT_CHECK */
92 # define PINVRNT(env, page, exp) \
93 ((void)sizeof(env), (void)sizeof(page), (void)sizeof !!(exp))
94 #endif /* !INVARIANT_CHECK */
97 * Internal version of cl_page_top, it should be called with page referenced,
98 * or coh_page_guard held.
100 static struct cl_page *cl_page_top_trusted(struct cl_page *page)
102 LASSERT(cl_is_page(page));
103 while (page->cp_parent != NULL)
104 page = page->cp_parent;
109 * Internal version of cl_page_get().
111 * This function can be used to obtain initial reference to previously
112 * unreferenced cached object. It can be called only if concurrent page
113 * reclamation is somehow prevented, e.g., by locking page radix-tree
114 * (cl_object_header::hdr->coh_page_guard), or by keeping a lock on a VM page,
115 * associated with \a page.
117 * Use with care! Not exported.
119 static void cl_page_get_trust(struct cl_page *page)
121 LASSERT(cl_is_page(page));
123 * Checkless version for trusted users.
125 if (cfs_atomic_inc_return(&page->cp_ref) == 1)
126 cfs_atomic_inc(&cl_object_site(page->cp_obj)->cs_pages.cs_busy);
130 * Returns a slice within a page, corresponding to the given layer in the
135 static const struct cl_page_slice *
136 cl_page_at_trusted(const struct cl_page *page,
137 const struct lu_device_type *dtype)
139 const struct cl_page_slice *slice;
141 #ifdef INVARIANT_CHECK
142 struct cl_object_header *ch = cl_object_header(page->cp_obj);
144 if (!cfs_atomic_read(&page->cp_ref))
145 LASSERT_SPIN_LOCKED(&ch->coh_page_guard);
149 page = cl_page_top_trusted((struct cl_page *)page);
151 cfs_list_for_each_entry(slice, &page->cp_layers, cpl_linkage) {
152 if (slice->cpl_obj->co_lu.lo_dev->ld_type == dtype)
155 page = page->cp_child;
156 } while (page != NULL);
161 * Returns a page with given index in the given object, or NULL if no page is
162 * found. Acquires a reference on \a page.
164 * Locking: called under cl_object_header::coh_page_guard spin-lock.
166 struct cl_page *cl_page_lookup(struct cl_object_header *hdr, pgoff_t index)
168 struct cl_page *page;
170 LASSERT_SPIN_LOCKED(&hdr->coh_page_guard);
172 page = radix_tree_lookup(&hdr->coh_tree, index);
174 LASSERT(cl_is_page(page));
175 cl_page_get_trust(page);
179 EXPORT_SYMBOL(cl_page_lookup);
182 * Returns a list of pages by a given [start, end] of \a obj.
184 * \param resched If not NULL, then we give up before hogging CPU for too
185 * long and set *resched = 1, in that case caller should implement a retry
188 * Gang tree lookup (radix_tree_gang_lookup()) optimization is absolutely
189 * crucial in the face of [offset, EOF] locks.
191 void cl_page_gang_lookup(const struct lu_env *env, struct cl_object *obj,
192 struct cl_io *io, pgoff_t start, pgoff_t end,
193 struct cl_page_list *queue, int nonblock,
196 struct cl_object_header *hdr;
197 struct cl_page *page;
198 struct cl_page **pvec;
199 const struct cl_page_slice *slice;
200 const struct lu_device_type *dtype;
205 int (*page_own)(const struct lu_env *env,
212 page_own = nonblock ? cl_page_own_try : cl_page_own;
215 hdr = cl_object_header(obj);
216 pvec = cl_env_info(env)->clt_pvec;
217 dtype = cl_object_top(obj)->co_lu.lo_dev->ld_type;
218 cfs_spin_lock(&hdr->coh_page_guard);
219 while ((nr = radix_tree_gang_lookup(&hdr->coh_tree, (void **)pvec,
220 idx, CLT_PVEC_SIZE)) > 0) {
221 idx = pvec[nr - 1]->cp_index + 1;
222 for (i = 0, j = 0; i < nr; ++i) {
224 PASSERT(env, page, cl_is_page(page));
226 if (page->cp_index > end)
228 if (page->cp_state == CPS_FREEING)
230 if (page->cp_type == CPT_TRANSIENT) {
231 /* God, we found a transient page!*/
235 slice = cl_page_at_trusted(page, dtype);
237 * Pages for lsm-less file has no underneath sub-page
238 * for osc, in case of ...
240 PASSERT(env, page, slice != NULL);
242 page = slice->cpl_page;
244 * Can safely call cl_page_get_trust() under
245 * radix-tree spin-lock.
247 * XXX not true, because @page is from object another
248 * than @hdr and protected by different tree lock.
250 cl_page_get_trust(page);
251 lu_ref_add_atomic(&page->cp_reference,
252 "page_list", cfs_current());
257 * Here a delicate locking dance is performed. Current thread
258 * holds a reference to a page, but has to own it before it
259 * can be placed into queue. Owning implies waiting, so
260 * radix-tree lock is to be released. After a wait one has to
261 * check that pages weren't truncated (cl_page_own() returns
262 * error in the latter case).
264 cfs_spin_unlock(&hdr->coh_page_guard);
265 for (i = 0; i < j; ++i) {
267 if (page_own(env, io, page) == 0)
268 cl_page_list_add(queue, page);
269 lu_ref_del(&page->cp_reference,
270 "page_list", cfs_current());
271 cl_page_put(env, page);
273 cfs_spin_lock(&hdr->coh_page_guard);
274 if (nr < CLT_PVEC_SIZE)
276 if (resched != NULL && cfs_need_resched()) {
281 cfs_spin_unlock(&hdr->coh_page_guard);
284 EXPORT_SYMBOL(cl_page_gang_lookup);
286 static void cl_page_free(const struct lu_env *env, struct cl_page *page)
288 struct cl_object *obj = page->cp_obj;
289 struct cl_site *site = cl_object_site(obj);
291 PASSERT(env, page, cl_is_page(page));
292 PASSERT(env, page, cfs_list_empty(&page->cp_batch));
293 PASSERT(env, page, page->cp_owner == NULL);
294 PASSERT(env, page, page->cp_req == NULL);
295 PASSERT(env, page, page->cp_parent == NULL);
296 PASSERT(env, page, page->cp_state == CPS_FREEING);
300 while (!cfs_list_empty(&page->cp_layers)) {
301 struct cl_page_slice *slice;
303 slice = cfs_list_entry(page->cp_layers.next,
304 struct cl_page_slice, cpl_linkage);
305 cfs_list_del_init(page->cp_layers.next);
306 slice->cpl_ops->cpo_fini(env, slice);
308 cfs_atomic_dec(&site->cs_pages.cs_total);
309 cfs_atomic_dec(&site->cs_pages_state[page->cp_state]);
310 lu_object_ref_del_at(&obj->co_lu, page->cp_obj_ref, "cl_page", page);
311 cl_object_put(env, obj);
312 lu_ref_fini(&page->cp_reference);
313 OBD_SLAB_FREE_PTR(page, cl_page_kmem);
318 * Helper function updating page state. This is the only place in the code
319 * where cl_page::cp_state field is mutated.
321 static inline void cl_page_state_set_trust(struct cl_page *page,
322 enum cl_page_state state)
325 *(enum cl_page_state *)&page->cp_state = state;
328 static int cl_page_alloc(const struct lu_env *env, struct cl_object *o,
329 pgoff_t ind, struct page *vmpage,
330 enum cl_page_type type, struct cl_page **out)
332 struct cl_page *page;
333 struct cl_page *err = NULL;
334 struct lu_object_header *head;
335 struct cl_site *site = cl_object_site(o);
340 OBD_SLAB_ALLOC_PTR_GFP(page, cl_page_kmem, CFS_ALLOC_IO);
342 cfs_atomic_set(&page->cp_ref, 1);
345 page->cp_obj_ref = lu_object_ref_add(&o->co_lu,
347 page->cp_index = ind;
348 cl_page_state_set_trust(page, CPS_CACHED);
349 page->cp_type = type;
350 CFS_INIT_LIST_HEAD(&page->cp_layers);
351 CFS_INIT_LIST_HEAD(&page->cp_batch);
352 CFS_INIT_LIST_HEAD(&page->cp_flight);
353 cfs_mutex_init(&page->cp_mutex);
354 lu_ref_init(&page->cp_reference);
355 head = o->co_lu.lo_header;
356 cfs_list_for_each_entry(o, &head->loh_layers,
358 if (o->co_ops->coo_page_init != NULL) {
359 err = o->co_ops->coo_page_init(env, o,
362 cl_page_state_set_trust(page,
364 cl_page_free(env, page);
371 cfs_atomic_inc(&site->cs_pages.cs_busy);
372 cfs_atomic_inc(&site->cs_pages.cs_total);
373 cfs_atomic_inc(&site->cs_pages_state[CPS_CACHED]);
374 cfs_atomic_inc(&site->cs_pages.cs_created);
378 page = ERR_PTR(-ENOMEM);
384 * Returns a cl_page with index \a idx at the object \a o, and associated with
385 * the VM page \a vmpage.
387 * This is the main entry point into the cl_page caching interface. First, a
388 * cache (implemented as a per-object radix tree) is consulted. If page is
389 * found there, it is returned immediately. Otherwise new page is allocated
390 * and returned. In any case, additional reference to page is acquired.
392 * \see cl_object_find(), cl_lock_find()
394 static struct cl_page *cl_page_find0(const struct lu_env *env,
396 pgoff_t idx, struct page *vmpage,
397 enum cl_page_type type,
398 struct cl_page *parent)
400 struct cl_page *page;
401 struct cl_page *ghost = NULL;
402 struct cl_object_header *hdr;
403 struct cl_site *site = cl_object_site(o);
406 LINVRNT(type == CPT_CACHEABLE || type == CPT_TRANSIENT);
411 hdr = cl_object_header(o);
412 cfs_atomic_inc(&site->cs_pages.cs_lookup);
414 CDEBUG(D_PAGE, "%lu@"DFID" %p %lu %d\n",
415 idx, PFID(&hdr->coh_lu.loh_fid), vmpage, vmpage->private, type);
417 if (type == CPT_CACHEABLE) {
419 * cl_vmpage_page() can be called here without any locks as
421 * - "vmpage" is locked (which prevents ->private from
422 * concurrent updates), and
424 * - "o" cannot be destroyed while current thread holds a
427 page = cl_vmpage_page(vmpage, o);
430 cl_page_vmpage(env, page) == vmpage &&
431 (void *)radix_tree_lookup(&hdr->coh_tree,
434 cfs_spin_lock(&hdr->coh_page_guard);
435 page = cl_page_lookup(hdr, idx);
436 cfs_spin_unlock(&hdr->coh_page_guard);
439 cfs_atomic_inc(&site->cs_pages.cs_hit);
443 /* allocate and initialize cl_page */
444 err = cl_page_alloc(env, o, idx, vmpage, type, &page);
448 * XXX optimization: use radix_tree_preload() here, and change tree
449 * gfp mask to GFP_KERNEL in cl_object_header_init().
451 cfs_spin_lock(&hdr->coh_page_guard);
452 err = radix_tree_insert(&hdr->coh_tree, idx, page);
456 * Noted by Jay: a lock on \a vmpage protects cl_page_find()
457 * from this race, but
459 * 0. it's better to have cl_page interface "locally
460 * consistent" so that its correctness can be reasoned
461 * about without appealing to the (obscure world of) VM
464 * 1. handling this race allows ->coh_tree to remain
465 * consistent even when VM locking is somehow busted,
466 * which is very useful during diagnosing and debugging.
469 if (err == -EEXIST) {
471 * XXX in case of a lookup for CPT_TRANSIENT page,
472 * nothing protects a CPT_CACHEABLE page from being
473 * concurrently moved into CPS_FREEING state.
475 page = cl_page_lookup(hdr, idx);
476 PASSERT(env, page, page != NULL);
477 if (page->cp_type == CPT_TRANSIENT &&
478 type == CPT_CACHEABLE) {
479 /* XXX: We should make sure that inode sem
480 * keeps being held in the lifetime of
481 * transient pages, so it is impossible to
482 * have conflicting transient pages.
484 cfs_spin_unlock(&hdr->coh_page_guard);
485 cl_page_put(env, page);
486 cfs_spin_lock(&hdr->coh_page_guard);
487 page = ERR_PTR(-EBUSY);
492 LASSERT(page->cp_parent == NULL);
493 page->cp_parent = parent;
494 parent->cp_child = page;
498 cfs_spin_unlock(&hdr->coh_page_guard);
500 if (unlikely(ghost != NULL)) {
501 cfs_atomic_dec(&site->cs_pages.cs_busy);
502 cl_page_delete0(env, ghost, 0);
503 cl_page_free(env, ghost);
508 struct cl_page *cl_page_find(const struct lu_env *env, struct cl_object *o,
509 pgoff_t idx, struct page *vmpage,
510 enum cl_page_type type)
512 return cl_page_find0(env, o, idx, vmpage, type, NULL);
514 EXPORT_SYMBOL(cl_page_find);
517 struct cl_page *cl_page_find_sub(const struct lu_env *env, struct cl_object *o,
518 pgoff_t idx, struct page *vmpage,
519 struct cl_page *parent)
521 return cl_page_find0(env, o, idx, vmpage, parent->cp_type, parent);
523 EXPORT_SYMBOL(cl_page_find_sub);
525 static inline int cl_page_invariant(const struct cl_page *pg)
527 struct cl_object_header *header;
528 struct cl_page *parent;
529 struct cl_page *child;
532 LASSERT(cl_is_page(pg));
534 * Page invariant is protected by a VM lock.
536 LINVRNT(cl_page_is_vmlocked(NULL, pg));
538 header = cl_object_header(pg->cp_obj);
539 parent = pg->cp_parent;
540 child = pg->cp_child;
541 owner = pg->cp_owner;
543 return cfs_atomic_read(&pg->cp_ref) > 0 &&
544 ergo(parent != NULL, parent->cp_child == pg) &&
545 ergo(child != NULL, child->cp_parent == pg) &&
546 ergo(child != NULL, pg->cp_obj != child->cp_obj) &&
547 ergo(parent != NULL, pg->cp_obj != parent->cp_obj) &&
548 ergo(owner != NULL && parent != NULL,
549 parent->cp_owner == pg->cp_owner->ci_parent) &&
550 ergo(owner != NULL && child != NULL,
551 child->cp_owner->ci_parent == owner) &&
553 * Either page is early in initialization (has neither child
554 * nor parent yet), or it is in the object radix tree.
556 ergo(pg->cp_state < CPS_FREEING,
557 (void *)radix_tree_lookup(&header->coh_tree,
558 pg->cp_index) == pg ||
559 (child == NULL && parent == NULL));
562 static void cl_page_state_set0(const struct lu_env *env,
563 struct cl_page *page, enum cl_page_state state)
565 enum cl_page_state old;
566 struct cl_site *site = cl_object_site(page->cp_obj);
569 * Matrix of allowed state transitions [old][new], for sanity
572 static const int allowed_transitions[CPS_NR][CPS_NR] = {
575 [CPS_OWNED] = 1, /* io finds existing cached page */
577 [CPS_PAGEOUT] = 1, /* write-out from the cache */
578 [CPS_FREEING] = 1, /* eviction on the memory pressure */
581 [CPS_CACHED] = 1, /* release to the cache */
583 [CPS_PAGEIN] = 1, /* start read immediately */
584 [CPS_PAGEOUT] = 1, /* start write immediately */
585 [CPS_FREEING] = 1, /* lock invalidation or truncate */
588 [CPS_CACHED] = 1, /* io completion */
595 [CPS_CACHED] = 1, /* io completion */
611 old = page->cp_state;
612 PASSERT(env, page, allowed_transitions[old][state]);
613 CL_PAGE_HEADER(D_TRACE, env, page, "%d -> %d\n", old, state);
614 for (; page != NULL; page = page->cp_child) {
615 PASSERT(env, page, page->cp_state == old);
617 equi(state == CPS_OWNED, page->cp_owner != NULL));
619 cfs_atomic_dec(&site->cs_pages_state[page->cp_state]);
620 cfs_atomic_inc(&site->cs_pages_state[state]);
621 cl_page_state_set_trust(page, state);
626 static void cl_page_state_set(const struct lu_env *env,
627 struct cl_page *page, enum cl_page_state state)
629 PINVRNT(env, page, cl_page_invariant(page));
630 cl_page_state_set0(env, page, state);
634 * Acquires an additional reference to a page.
636 * This can be called only by caller already possessing a reference to \a
639 * \see cl_object_get(), cl_lock_get().
641 void cl_page_get(struct cl_page *page)
644 LASSERT(page->cp_state != CPS_FREEING);
645 cl_page_get_trust(page);
648 EXPORT_SYMBOL(cl_page_get);
651 * Releases a reference to a page.
653 * When last reference is released, page is returned to the cache, unless it
654 * is in cl_page_state::CPS_FREEING state, in which case it is immediately
657 * \see cl_object_put(), cl_lock_put().
659 void cl_page_put(const struct lu_env *env, struct cl_page *page)
661 struct cl_object_header *hdr;
662 struct cl_site *site = cl_object_site(page->cp_obj);
664 PASSERT(env, page, cfs_atomic_read(&page->cp_ref) > !!page->cp_parent);
667 CL_PAGE_HEADER(D_TRACE, env, page, "%d\n",
668 cfs_atomic_read(&page->cp_ref));
670 hdr = cl_object_header(cl_object_top(page->cp_obj));
671 if (cfs_atomic_dec_and_lock(&page->cp_ref, &hdr->coh_page_guard)) {
672 cfs_atomic_dec(&site->cs_pages.cs_busy);
673 /* We're going to access the page w/o a reference, but it's
674 * ok because we have grabbed the lock coh_page_guard, which
675 * means nobody is able to free this page behind us.
677 if (page->cp_state == CPS_FREEING) {
678 /* We drop the page reference and check the page state
679 * inside the coh_page_guard. So that if it gets here,
680 * it is the REALLY last reference to this page.
682 cfs_spin_unlock(&hdr->coh_page_guard);
684 LASSERT(cfs_atomic_read(&page->cp_ref) == 0);
685 PASSERT(env, page, page->cp_owner == NULL);
686 PASSERT(env, page, cfs_list_empty(&page->cp_batch));
688 * Page is no longer reachable by other threads. Tear
691 cl_page_free(env, page);
696 cfs_spin_unlock(&hdr->coh_page_guard);
701 EXPORT_SYMBOL(cl_page_put);
704 * Returns a VM page associated with a given cl_page.
706 cfs_page_t *cl_page_vmpage(const struct lu_env *env, struct cl_page *page)
708 const struct cl_page_slice *slice;
711 * Find uppermost layer with ->cpo_vmpage() method, and return its
714 page = cl_page_top(page);
716 cfs_list_for_each_entry(slice, &page->cp_layers, cpl_linkage) {
717 if (slice->cpl_ops->cpo_vmpage != NULL)
718 RETURN(slice->cpl_ops->cpo_vmpage(env, slice));
720 page = page->cp_child;
721 } while (page != NULL);
722 LBUG(); /* ->cpo_vmpage() has to be defined somewhere in the stack */
724 EXPORT_SYMBOL(cl_page_vmpage);
727 * Returns a cl_page associated with a VM page, and given cl_object.
729 struct cl_page *cl_vmpage_page(cfs_page_t *vmpage, struct cl_object *obj)
731 struct cl_page *page;
732 struct cl_object_header *hdr;
735 KLASSERT(PageLocked(vmpage));
738 * NOTE: absence of races and liveness of data are guaranteed by page
739 * lock on a "vmpage". That works because object destruction has
740 * bottom-to-top pass.
744 * This loop assumes that ->private points to the top-most page. This
745 * can be rectified easily.
747 hdr = cl_object_header(cl_object_top(obj));
748 cfs_spin_lock(&hdr->coh_page_guard);
749 for (page = (void *)vmpage->private;
750 page != NULL; page = page->cp_child) {
751 if (cl_object_same(page->cp_obj, obj)) {
752 cl_page_get_trust(page);
756 cfs_spin_unlock(&hdr->coh_page_guard);
757 LASSERT(ergo(page, cl_is_page(page) && page->cp_type == CPT_CACHEABLE));
760 EXPORT_SYMBOL(cl_vmpage_page);
763 * Returns the top-page for a given page.
765 * \see cl_object_top(), cl_io_top()
767 struct cl_page *cl_page_top(struct cl_page *page)
769 return cl_page_top_trusted(page);
771 EXPORT_SYMBOL(cl_page_top);
774 * Returns true if \a addr is an address of an allocated cl_page. Used in
775 * assertions. This check is optimistically imprecise, i.e., it occasionally
776 * returns true for the incorrect addresses, but if it returns false, then the
777 * address is guaranteed to be incorrect. (Should be named cl_pagep().)
781 int cl_is_page(const void *addr)
783 return cfs_mem_is_in_cache(addr, cl_page_kmem);
785 EXPORT_SYMBOL(cl_is_page);
787 const struct cl_page_slice *cl_page_at(const struct cl_page *page,
788 const struct lu_device_type *dtype)
790 return cl_page_at_trusted(page, dtype);
792 EXPORT_SYMBOL(cl_page_at);
794 #define CL_PAGE_OP(opname) offsetof(struct cl_page_operations, opname)
796 #define CL_PAGE_INVOKE(_env, _page, _op, _proto, ...) \
798 const struct lu_env *__env = (_env); \
799 struct cl_page *__page = (_page); \
800 const struct cl_page_slice *__scan; \
802 ptrdiff_t __op = (_op); \
803 int (*__method)_proto; \
806 __page = cl_page_top(__page); \
808 cfs_list_for_each_entry(__scan, &__page->cp_layers, \
810 __method = *(void **)((char *)__scan->cpl_ops + \
812 if (__method != NULL) { \
813 __result = (*__method)(__env, __scan, \
819 __page = __page->cp_child; \
820 } while (__page != NULL && __result == 0); \
826 #define CL_PAGE_INVOID(_env, _page, _op, _proto, ...) \
828 const struct lu_env *__env = (_env); \
829 struct cl_page *__page = (_page); \
830 const struct cl_page_slice *__scan; \
831 ptrdiff_t __op = (_op); \
832 void (*__method)_proto; \
834 __page = cl_page_top(__page); \
836 cfs_list_for_each_entry(__scan, &__page->cp_layers, \
838 __method = *(void **)((char *)__scan->cpl_ops + \
840 if (__method != NULL) \
841 (*__method)(__env, __scan, \
844 __page = __page->cp_child; \
845 } while (__page != NULL); \
848 #define CL_PAGE_INVOID_REVERSE(_env, _page, _op, _proto, ...) \
850 const struct lu_env *__env = (_env); \
851 struct cl_page *__page = (_page); \
852 const struct cl_page_slice *__scan; \
853 ptrdiff_t __op = (_op); \
854 void (*__method)_proto; \
856 /* get to the bottom page. */ \
857 while (__page->cp_child != NULL) \
858 __page = __page->cp_child; \
860 cfs_list_for_each_entry_reverse(__scan, &__page->cp_layers, \
862 __method = *(void **)((char *)__scan->cpl_ops + \
864 if (__method != NULL) \
865 (*__method)(__env, __scan, \
868 __page = __page->cp_parent; \
869 } while (__page != NULL); \
872 static int cl_page_invoke(const struct lu_env *env,
873 struct cl_io *io, struct cl_page *page, ptrdiff_t op)
876 PINVRNT(env, page, cl_object_same(page->cp_obj, io->ci_obj));
878 RETURN(CL_PAGE_INVOKE(env, page, op,
879 (const struct lu_env *,
880 const struct cl_page_slice *, struct cl_io *),
884 static void cl_page_invoid(const struct lu_env *env,
885 struct cl_io *io, struct cl_page *page, ptrdiff_t op)
888 PINVRNT(env, page, cl_object_same(page->cp_obj, io->ci_obj));
890 CL_PAGE_INVOID(env, page, op,
891 (const struct lu_env *,
892 const struct cl_page_slice *, struct cl_io *), io);
896 static void cl_page_owner_clear(struct cl_page *page)
899 for (page = cl_page_top(page); page != NULL; page = page->cp_child) {
900 if (page->cp_owner != NULL) {
901 LASSERT(page->cp_owner->ci_owned_nr > 0);
902 page->cp_owner->ci_owned_nr--;
903 page->cp_owner = NULL;
904 page->cp_task = NULL;
910 static void cl_page_owner_set(struct cl_page *page)
913 for (page = cl_page_top(page); page != NULL; page = page->cp_child) {
914 LASSERT(page->cp_owner != NULL);
915 page->cp_owner->ci_owned_nr++;
920 void cl_page_disown0(const struct lu_env *env,
921 struct cl_io *io, struct cl_page *pg)
923 enum cl_page_state state;
926 state = pg->cp_state;
927 PINVRNT(env, pg, state == CPS_OWNED || state == CPS_FREEING);
928 PINVRNT(env, pg, cl_page_invariant(pg));
929 cl_page_owner_clear(pg);
931 if (state == CPS_OWNED)
932 cl_page_state_set(env, pg, CPS_CACHED);
934 * Completion call-backs are executed in the bottom-up order, so that
935 * uppermost layer (llite), responsible for VFS/VM interaction runs
936 * last and can release locks safely.
938 CL_PAGE_INVOID_REVERSE(env, pg, CL_PAGE_OP(cpo_disown),
939 (const struct lu_env *,
940 const struct cl_page_slice *, struct cl_io *),
946 * returns true, iff page is owned by the given io.
948 int cl_page_is_owned(const struct cl_page *pg, const struct cl_io *io)
950 LINVRNT(cl_object_same(pg->cp_obj, io->ci_obj));
952 RETURN(pg->cp_state == CPS_OWNED && pg->cp_owner == io);
954 EXPORT_SYMBOL(cl_page_is_owned);
957 * Try to own a page by IO.
959 * Waits until page is in cl_page_state::CPS_CACHED state, and then switch it
960 * into cl_page_state::CPS_OWNED state.
962 * \pre !cl_page_is_owned(pg, io)
963 * \post result == 0 iff cl_page_is_owned(pg, io)
967 * \retval -ve failure, e.g., page was destroyed (and landed in
968 * cl_page_state::CPS_FREEING instead of cl_page_state::CPS_CACHED).
969 * or, page was owned by another thread, or in IO.
971 * \see cl_page_disown()
972 * \see cl_page_operations::cpo_own()
973 * \see cl_page_own_try()
976 static int cl_page_own0(const struct lu_env *env, struct cl_io *io,
977 struct cl_page *pg, int nonblock)
981 PINVRNT(env, pg, !cl_page_is_owned(pg, io));
984 pg = cl_page_top(pg);
987 if (pg->cp_state == CPS_FREEING) {
990 result = CL_PAGE_INVOKE(env, pg, CL_PAGE_OP(cpo_own),
991 (const struct lu_env *,
992 const struct cl_page_slice *,
993 struct cl_io *, int),
996 PASSERT(env, pg, pg->cp_owner == NULL);
997 PASSERT(env, pg, pg->cp_req == NULL);
999 pg->cp_task = current;
1000 cl_page_owner_set(pg);
1001 if (pg->cp_state != CPS_FREEING) {
1002 cl_page_state_set(env, pg, CPS_OWNED);
1004 cl_page_disown0(env, io, pg);
1009 PINVRNT(env, pg, ergo(result == 0, cl_page_invariant(pg)));
1014 * Own a page, might be blocked.
1016 * \see cl_page_own0()
1018 int cl_page_own(const struct lu_env *env, struct cl_io *io, struct cl_page *pg)
1020 return cl_page_own0(env, io, pg, 0);
1022 EXPORT_SYMBOL(cl_page_own);
1025 * Nonblock version of cl_page_own().
1027 * \see cl_page_own0()
1029 int cl_page_own_try(const struct lu_env *env, struct cl_io *io,
1032 return cl_page_own0(env, io, pg, 1);
1034 EXPORT_SYMBOL(cl_page_own_try);
1038 * Assume page ownership.
1040 * Called when page is already locked by the hosting VM.
1042 * \pre !cl_page_is_owned(pg, io)
1043 * \post cl_page_is_owned(pg, io)
1045 * \see cl_page_operations::cpo_assume()
1047 void cl_page_assume(const struct lu_env *env,
1048 struct cl_io *io, struct cl_page *pg)
1050 PASSERT(env, pg, pg->cp_state < CPS_OWNED);
1051 PASSERT(env, pg, pg->cp_owner == NULL);
1052 PINVRNT(env, pg, cl_object_same(pg->cp_obj, io->ci_obj));
1053 PINVRNT(env, pg, cl_page_invariant(pg));
1056 pg = cl_page_top(pg);
1059 cl_page_invoid(env, io, pg, CL_PAGE_OP(cpo_assume));
1061 pg->cp_task = current;
1062 cl_page_owner_set(pg);
1063 cl_page_state_set(env, pg, CPS_OWNED);
1066 EXPORT_SYMBOL(cl_page_assume);
1069 * Releases page ownership without unlocking the page.
1071 * Moves page into cl_page_state::CPS_CACHED without releasing a lock on the
1072 * underlying VM page (as VM is supposed to do this itself).
1074 * \pre cl_page_is_owned(pg, io)
1075 * \post !cl_page_is_owned(pg, io)
1077 * \see cl_page_assume()
1079 void cl_page_unassume(const struct lu_env *env,
1080 struct cl_io *io, struct cl_page *pg)
1082 PINVRNT(env, pg, cl_page_is_owned(pg, io));
1083 PINVRNT(env, pg, cl_page_invariant(pg));
1086 pg = cl_page_top(pg);
1088 cl_page_owner_clear(pg);
1089 cl_page_state_set(env, pg, CPS_CACHED);
1090 CL_PAGE_INVOID_REVERSE(env, pg, CL_PAGE_OP(cpo_unassume),
1091 (const struct lu_env *,
1092 const struct cl_page_slice *, struct cl_io *),
1096 EXPORT_SYMBOL(cl_page_unassume);
1099 * Releases page ownership.
1101 * Moves page into cl_page_state::CPS_CACHED.
1103 * \pre cl_page_is_owned(pg, io)
1104 * \post !cl_page_is_owned(pg, io)
1106 * \see cl_page_own()
1107 * \see cl_page_operations::cpo_disown()
1109 void cl_page_disown(const struct lu_env *env,
1110 struct cl_io *io, struct cl_page *pg)
1112 PINVRNT(env, pg, cl_page_is_owned(pg, io));
1115 pg = cl_page_top(pg);
1117 cl_page_disown0(env, io, pg);
1120 EXPORT_SYMBOL(cl_page_disown);
1123 * Called when page is to be removed from the object, e.g., as a result of
1126 * Calls cl_page_operations::cpo_discard() top-to-bottom.
1128 * \pre cl_page_is_owned(pg, io)
1130 * \see cl_page_operations::cpo_discard()
1132 void cl_page_discard(const struct lu_env *env,
1133 struct cl_io *io, struct cl_page *pg)
1135 PINVRNT(env, pg, cl_page_is_owned(pg, io));
1136 PINVRNT(env, pg, cl_page_invariant(pg));
1138 cl_page_invoid(env, io, pg, CL_PAGE_OP(cpo_discard));
1140 EXPORT_SYMBOL(cl_page_discard);
1143 * Version of cl_page_delete() that can be called for not fully constructed
1144 * pages, e.g,. in a error handling cl_page_find()->cl_page_delete0()
1145 * path. Doesn't check page invariant.
1147 static void cl_page_delete0(const struct lu_env *env, struct cl_page *pg,
1150 struct cl_page *tmp = pg;
1153 PASSERT(env, pg, pg == cl_page_top(pg));
1154 PASSERT(env, pg, pg->cp_state != CPS_FREEING);
1157 * Severe all ways to obtain new pointers to @pg.
1159 cl_page_owner_clear(pg);
1162 * unexport the page firstly before freeing it so that
1163 * the page content is considered to be invalid.
1164 * We have to do this because a CPS_FREEING cl_page may
1165 * be NOT under the protection of a cl_lock.
1166 * Afterwards, if this page is found by other threads, then this
1167 * page will be forced to reread.
1169 cl_page_export(env, pg, 0);
1170 cl_page_state_set0(env, pg, CPS_FREEING);
1174 * !radix means that @pg is not yet in the radix tree, skip
1178 for (; tmp != NULL; tmp = tmp->cp_child) {
1180 struct cl_object_header *hdr;
1182 hdr = cl_object_header(tmp->cp_obj);
1183 cfs_spin_lock(&hdr->coh_page_guard);
1184 value = radix_tree_delete(&hdr->coh_tree, tmp->cp_index);
1185 PASSERT(env, tmp, value == tmp);
1186 PASSERT(env, tmp, hdr->coh_pages > 0);
1188 cfs_spin_unlock(&hdr->coh_page_guard);
1191 CL_PAGE_INVOID(env, pg, CL_PAGE_OP(cpo_delete),
1192 (const struct lu_env *, const struct cl_page_slice *));
1197 * Called when a decision is made to throw page out of memory.
1199 * Notifies all layers about page destruction by calling
1200 * cl_page_operations::cpo_delete() method top-to-bottom.
1202 * Moves page into cl_page_state::CPS_FREEING state (this is the only place
1203 * where transition to this state happens).
1205 * Eliminates all venues through which new references to the page can be
1208 * - removes page from the radix trees,
1210 * - breaks linkage from VM page to cl_page.
1212 * Once page reaches cl_page_state::CPS_FREEING, all remaining references will
1213 * drain after some time, at which point page will be recycled.
1215 * \pre pg == cl_page_top(pg)
1216 * \pre VM page is locked
1217 * \post pg->cp_state == CPS_FREEING
1219 * \see cl_page_operations::cpo_delete()
1221 void cl_page_delete(const struct lu_env *env, struct cl_page *pg)
1223 PINVRNT(env, pg, cl_page_invariant(pg));
1225 cl_page_delete0(env, pg, 1);
1228 EXPORT_SYMBOL(cl_page_delete);
1231 * Unmaps page from user virtual memory.
1233 * Calls cl_page_operations::cpo_unmap() through all layers top-to-bottom. The
1234 * layer responsible for VM interaction has to unmap page from user space
1237 * \see cl_page_operations::cpo_unmap()
1239 int cl_page_unmap(const struct lu_env *env,
1240 struct cl_io *io, struct cl_page *pg)
1242 PINVRNT(env, pg, cl_page_is_owned(pg, io));
1243 PINVRNT(env, pg, cl_page_invariant(pg));
1245 return cl_page_invoke(env, io, pg, CL_PAGE_OP(cpo_unmap));
1247 EXPORT_SYMBOL(cl_page_unmap);
1250 * Marks page up-to-date.
1252 * Call cl_page_operations::cpo_export() through all layers top-to-bottom. The
1253 * layer responsible for VM interaction has to mark/clear page as up-to-date
1254 * by the \a uptodate argument.
1256 * \see cl_page_operations::cpo_export()
1258 void cl_page_export(const struct lu_env *env, struct cl_page *pg, int uptodate)
1260 PINVRNT(env, pg, cl_page_invariant(pg));
1261 CL_PAGE_INVOID(env, pg, CL_PAGE_OP(cpo_export),
1262 (const struct lu_env *,
1263 const struct cl_page_slice *, int), uptodate);
1265 EXPORT_SYMBOL(cl_page_export);
1268 * Returns true, iff \a pg is VM locked in a suitable sense by the calling
1271 int cl_page_is_vmlocked(const struct lu_env *env, const struct cl_page *pg)
1274 const struct cl_page_slice *slice;
1277 pg = cl_page_top_trusted((struct cl_page *)pg);
1278 slice = container_of(pg->cp_layers.next,
1279 const struct cl_page_slice, cpl_linkage);
1280 PASSERT(env, pg, slice->cpl_ops->cpo_is_vmlocked != NULL);
1282 * Call ->cpo_is_vmlocked() directly instead of going through
1283 * CL_PAGE_INVOKE(), because cl_page_is_vmlocked() is used by
1284 * cl_page_invariant().
1286 result = slice->cpl_ops->cpo_is_vmlocked(env, slice);
1287 PASSERT(env, pg, result == -EBUSY || result == -ENODATA);
1288 RETURN(result == -EBUSY);
1290 EXPORT_SYMBOL(cl_page_is_vmlocked);
1292 static enum cl_page_state cl_req_type_state(enum cl_req_type crt)
1295 RETURN(crt == CRT_WRITE ? CPS_PAGEOUT : CPS_PAGEIN);
1298 static void cl_page_io_start(const struct lu_env *env,
1299 struct cl_page *pg, enum cl_req_type crt)
1302 * Page is queued for IO, change its state.
1305 cl_page_owner_clear(pg);
1306 cl_page_state_set(env, pg, cl_req_type_state(crt));
1311 * Prepares page for immediate transfer. cl_page_operations::cpo_prep() is
1312 * called top-to-bottom. Every layer either agrees to submit this page (by
1313 * returning 0), or requests to omit this page (by returning -EALREADY). Layer
1314 * handling interactions with the VM also has to inform VM that page is under
1317 int cl_page_prep(const struct lu_env *env, struct cl_io *io,
1318 struct cl_page *pg, enum cl_req_type crt)
1322 PINVRNT(env, pg, cl_page_is_owned(pg, io));
1323 PINVRNT(env, pg, cl_page_invariant(pg));
1324 PINVRNT(env, pg, crt < CRT_NR);
1327 * XXX this has to be called bottom-to-top, so that llite can set up
1328 * PG_writeback without risking other layers deciding to skip this
1331 result = cl_page_invoke(env, io, pg, CL_PAGE_OP(io[crt].cpo_prep));
1333 cl_page_io_start(env, pg, crt);
1335 KLASSERT(ergo(crt == CRT_WRITE && pg->cp_type == CPT_CACHEABLE,
1337 PageWriteback(cl_page_vmpage(env, pg)))));
1338 CL_PAGE_HEADER(D_TRACE, env, pg, "%d %d\n", crt, result);
1341 EXPORT_SYMBOL(cl_page_prep);
1344 * Notify layers about transfer completion.
1346 * Invoked by transfer sub-system (which is a part of osc) to notify layers
1347 * that a transfer, of which this page is a part of has completed.
1349 * Completion call-backs are executed in the bottom-up order, so that
1350 * uppermost layer (llite), responsible for the VFS/VM interaction runs last
1351 * and can release locks safely.
1353 * \pre pg->cp_state == CPS_PAGEIN || pg->cp_state == CPS_PAGEOUT
1354 * \post pg->cp_state == CPS_CACHED
1356 * \see cl_page_operations::cpo_completion()
1358 void cl_page_completion(const struct lu_env *env,
1359 struct cl_page *pg, enum cl_req_type crt, int ioret)
1361 struct cl_sync_io *anchor = pg->cp_sync_io;
1363 PASSERT(env, pg, crt < CRT_NR);
1364 /* cl_page::cp_req already cleared by the caller (osc_completion()) */
1365 PASSERT(env, pg, pg->cp_req == NULL);
1366 PASSERT(env, pg, pg->cp_state == cl_req_type_state(crt));
1367 PINVRNT(env, pg, cl_page_invariant(pg));
1370 CL_PAGE_HEADER(D_TRACE, env, pg, "%d %d\n", crt, ioret);
1371 if (crt == CRT_READ && ioret == 0) {
1372 PASSERT(env, pg, !(pg->cp_flags & CPF_READ_COMPLETED));
1373 pg->cp_flags |= CPF_READ_COMPLETED;
1376 cl_page_state_set(env, pg, CPS_CACHED);
1377 CL_PAGE_INVOID_REVERSE(env, pg, CL_PAGE_OP(io[crt].cpo_completion),
1378 (const struct lu_env *,
1379 const struct cl_page_slice *, int), ioret);
1381 LASSERT(pg->cp_sync_io == anchor);
1382 pg->cp_sync_io = NULL;
1383 cl_sync_io_note(anchor, ioret);
1386 /* Don't assert the page writeback bit here because the lustre file
1387 * may be as a backend of swap space. in this case, the page writeback
1388 * is set by VM, and obvious we shouldn't clear it at all. Fortunately
1389 * this type of pages are all TRANSIENT pages. */
1390 KLASSERT(ergo(pg->cp_type == CPT_CACHEABLE,
1391 !PageWriteback(cl_page_vmpage(env, pg))));
1394 EXPORT_SYMBOL(cl_page_completion);
1397 * Notify layers that transfer formation engine decided to yank this page from
1398 * the cache and to make it a part of a transfer.
1400 * \pre pg->cp_state == CPS_CACHED
1401 * \post pg->cp_state == CPS_PAGEIN || pg->cp_state == CPS_PAGEOUT
1403 * \see cl_page_operations::cpo_make_ready()
1405 int cl_page_make_ready(const struct lu_env *env, struct cl_page *pg,
1406 enum cl_req_type crt)
1410 PINVRNT(env, pg, crt < CRT_NR);
1413 result = CL_PAGE_INVOKE(env, pg, CL_PAGE_OP(io[crt].cpo_make_ready),
1414 (const struct lu_env *,
1415 const struct cl_page_slice *));
1417 PASSERT(env, pg, pg->cp_state == CPS_CACHED);
1418 cl_page_io_start(env, pg, crt);
1420 CL_PAGE_HEADER(D_TRACE, env, pg, "%d %d\n", crt, result);
1423 EXPORT_SYMBOL(cl_page_make_ready);
1426 * Notify layers that high level io decided to place this page into a cache
1427 * for future transfer.
1429 * The layer implementing transfer engine (osc) has to register this page in
1432 * \pre cl_page_is_owned(pg, io)
1433 * \post ergo(result == 0,
1434 * pg->cp_state == CPS_PAGEIN || pg->cp_state == CPS_PAGEOUT)
1436 * \see cl_page_operations::cpo_cache_add()
1438 int cl_page_cache_add(const struct lu_env *env, struct cl_io *io,
1439 struct cl_page *pg, enum cl_req_type crt)
1443 PINVRNT(env, pg, crt < CRT_NR);
1444 PINVRNT(env, pg, cl_page_is_owned(pg, io));
1445 PINVRNT(env, pg, cl_page_invariant(pg));
1448 result = cl_page_invoke(env, io, pg, CL_PAGE_OP(io[crt].cpo_cache_add));
1450 cl_page_owner_clear(pg);
1451 cl_page_state_set(env, pg, CPS_CACHED);
1453 CL_PAGE_HEADER(D_TRACE, env, pg, "%d %d\n", crt, result);
1456 EXPORT_SYMBOL(cl_page_cache_add);
1459 * Checks whether page is protected by any extent lock is at least required
1462 * \return the same as in cl_page_operations::cpo_is_under_lock() method.
1463 * \see cl_page_operations::cpo_is_under_lock()
1465 int cl_page_is_under_lock(const struct lu_env *env, struct cl_io *io,
1466 struct cl_page *page)
1470 PINVRNT(env, page, cl_page_invariant(page));
1473 rc = CL_PAGE_INVOKE(env, page, CL_PAGE_OP(cpo_is_under_lock),
1474 (const struct lu_env *,
1475 const struct cl_page_slice *, struct cl_io *),
1477 PASSERT(env, page, rc != 0);
1480 EXPORT_SYMBOL(cl_page_is_under_lock);
1483 * Purges all cached pages belonging to the object \a obj.
1485 int cl_pages_prune(const struct lu_env *env, struct cl_object *clobj)
1487 struct cl_thread_info *info;
1488 struct cl_object *obj = cl_object_top(clobj);
1490 struct cl_page_list *plist;
1495 info = cl_env_info(env);
1496 plist = &info->clt_list;
1500 * initialize the io. This is ugly since we never do IO in this
1501 * function, we just make cl_page_list functions happy. -jay
1504 result = cl_io_init(env, io, CIT_MISC, obj);
1506 cl_io_fini(env, io);
1507 RETURN(io->ci_result);
1511 cl_page_list_init(plist);
1512 cl_page_gang_lookup(env, obj, io, 0, CL_PAGE_EOF, plist, 0,
1515 * Since we're purging the pages of an object, we don't care
1516 * the possible outcomes of the following functions.
1518 cl_page_list_unmap(env, io, plist);
1519 cl_page_list_discard(env, io, plist);
1520 cl_page_list_disown(env, io, plist);
1521 cl_page_list_fini(env, plist);
1527 cl_io_fini(env, io);
1530 EXPORT_SYMBOL(cl_pages_prune);
1533 * Tells transfer engine that only part of a page is to be transmitted.
1535 * \see cl_page_operations::cpo_clip()
1537 void cl_page_clip(const struct lu_env *env, struct cl_page *pg,
1540 PINVRNT(env, pg, cl_page_invariant(pg));
1542 CL_PAGE_HEADER(D_TRACE, env, pg, "%d %d\n", from, to);
1543 CL_PAGE_INVOID(env, pg, CL_PAGE_OP(cpo_clip),
1544 (const struct lu_env *,
1545 const struct cl_page_slice *,int, int),
1548 EXPORT_SYMBOL(cl_page_clip);
1551 * Prints human readable representation of \a pg to the \a f.
1553 void cl_page_header_print(const struct lu_env *env, void *cookie,
1554 lu_printer_t printer, const struct cl_page *pg)
1556 (*printer)(env, cookie,
1557 "page@%p[%d %p:%lu ^%p_%p %d %d %d %p %p %#x]\n",
1558 pg, cfs_atomic_read(&pg->cp_ref), pg->cp_obj,
1559 pg->cp_index, pg->cp_parent, pg->cp_child,
1560 pg->cp_state, pg->cp_error, pg->cp_type,
1561 pg->cp_owner, pg->cp_req, pg->cp_flags);
1563 EXPORT_SYMBOL(cl_page_header_print);
1566 * Prints human readable representation of \a pg to the \a f.
1568 void cl_page_print(const struct lu_env *env, void *cookie,
1569 lu_printer_t printer, const struct cl_page *pg)
1571 struct cl_page *scan;
1573 for (scan = cl_page_top((struct cl_page *)pg);
1574 scan != NULL; scan = scan->cp_child)
1575 cl_page_header_print(env, cookie, printer, scan);
1576 CL_PAGE_INVOKE(env, (struct cl_page *)pg, CL_PAGE_OP(cpo_print),
1577 (const struct lu_env *env,
1578 const struct cl_page_slice *slice,
1579 void *cookie, lu_printer_t p), cookie, printer);
1580 (*printer)(env, cookie, "end page@%p\n", pg);
1582 EXPORT_SYMBOL(cl_page_print);
1585 * Cancel a page which is still in a transfer.
1587 int cl_page_cancel(const struct lu_env *env, struct cl_page *page)
1589 return CL_PAGE_INVOKE(env, page, CL_PAGE_OP(cpo_cancel),
1590 (const struct lu_env *,
1591 const struct cl_page_slice *));
1593 EXPORT_SYMBOL(cl_page_cancel);
1596 * Converts a byte offset within object \a obj into a page index.
1598 loff_t cl_offset(const struct cl_object *obj, pgoff_t idx)
1603 return (loff_t)idx << CFS_PAGE_SHIFT;
1605 EXPORT_SYMBOL(cl_offset);
1608 * Converts a page index into a byte offset within object \a obj.
1610 pgoff_t cl_index(const struct cl_object *obj, loff_t offset)
1615 return offset >> CFS_PAGE_SHIFT;
1617 EXPORT_SYMBOL(cl_index);
1619 int cl_page_size(const struct cl_object *obj)
1621 return 1 << CFS_PAGE_SHIFT;
1623 EXPORT_SYMBOL(cl_page_size);
1626 * Adds page slice to the compound page.
1628 * This is called by cl_object_operations::coo_page_init() methods to add a
1629 * per-layer state to the page. New state is added at the end of
1630 * cl_page::cp_layers list, that is, it is at the bottom of the stack.
1632 * \see cl_lock_slice_add(), cl_req_slice_add(), cl_io_slice_add()
1634 void cl_page_slice_add(struct cl_page *page, struct cl_page_slice *slice,
1635 struct cl_object *obj,
1636 const struct cl_page_operations *ops)
1639 cfs_list_add_tail(&slice->cpl_linkage, &page->cp_layers);
1640 slice->cpl_obj = obj;
1641 slice->cpl_ops = ops;
1642 slice->cpl_page = page;
1645 EXPORT_SYMBOL(cl_page_slice_add);
1647 int cl_page_init(void)
1649 return lu_kmem_init(cl_page_caches);
1652 void cl_page_fini(void)
1654 lu_kmem_fini(cl_page_caches);