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.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2012, Whamcloud, Inc.
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 #include <libcfs/libcfs.h>
44 #include <obd_class.h>
45 #include <obd_support.h>
46 #include <libcfs/list.h>
48 #include <cl_object.h>
49 #include "cl_internal.h"
51 static void cl_page_delete0(const struct lu_env *env, struct cl_page *pg,
54 static cfs_mem_cache_t *cl_page_kmem = NULL;
56 static struct lu_kmem_descr cl_page_caches[] = {
58 .ckd_cache = &cl_page_kmem,
59 .ckd_name = "cl_page_kmem",
60 .ckd_size = sizeof (struct cl_page)
68 # define PASSERT(env, page, expr) \
70 if (unlikely(!(expr))) { \
71 CL_PAGE_DEBUG(D_ERROR, (env), (page), #expr "\n"); \
75 #else /* !LIBCFS_DEBUG */
76 # define PASSERT(env, page, exp) \
77 ((void)sizeof(env), (void)sizeof(page), (void)sizeof !!(exp))
78 #endif /* !LIBCFS_DEBUG */
80 #ifdef INVARIANT_CHECK
81 # define PINVRNT(env, page, expr) \
83 if (unlikely(!(expr))) { \
84 CL_PAGE_DEBUG(D_ERROR, (env), (page), #expr "\n"); \
88 #else /* !INVARIANT_CHECK */
89 # define PINVRNT(env, page, exp) \
90 ((void)sizeof(env), (void)sizeof(page), (void)sizeof !!(exp))
91 #endif /* !INVARIANT_CHECK */
94 * Internal version of cl_page_top, it should be called with page referenced,
95 * or coh_page_guard held.
97 static struct cl_page *cl_page_top_trusted(struct cl_page *page)
99 while (page->cp_parent != NULL)
100 page = page->cp_parent;
105 * Internal version of cl_page_get().
107 * This function can be used to obtain initial reference to previously
108 * unreferenced cached object. It can be called only if concurrent page
109 * reclamation is somehow prevented, e.g., by locking page radix-tree
110 * (cl_object_header::hdr->coh_page_guard), or by keeping a lock on a VM page,
111 * associated with \a page.
113 * Use with care! Not exported.
115 static void cl_page_get_trust(struct cl_page *page)
118 * Checkless version for trusted users.
120 if (cfs_atomic_inc_return(&page->cp_ref) == 1)
121 cfs_atomic_inc(&cl_object_site(page->cp_obj)->cs_pages.cs_busy);
125 * Returns a slice within a page, corresponding to the given layer in the
130 static const struct cl_page_slice *
131 cl_page_at_trusted(const struct cl_page *page,
132 const struct lu_device_type *dtype)
134 const struct cl_page_slice *slice;
136 #ifdef INVARIANT_CHECK
137 struct cl_object_header *ch = cl_object_header(page->cp_obj);
139 if (!cfs_atomic_read(&page->cp_ref))
140 LASSERT_SPIN_LOCKED(&ch->coh_page_guard);
144 page = cl_page_top_trusted((struct cl_page *)page);
146 cfs_list_for_each_entry(slice, &page->cp_layers, cpl_linkage) {
147 if (slice->cpl_obj->co_lu.lo_dev->ld_type == dtype)
150 page = page->cp_child;
151 } while (page != NULL);
156 * Returns a page with given index in the given object, or NULL if no page is
157 * found. Acquires a reference on \a page.
159 * Locking: called under cl_object_header::coh_page_guard spin-lock.
161 struct cl_page *cl_page_lookup(struct cl_object_header *hdr, pgoff_t index)
163 struct cl_page *page;
165 LASSERT_SPIN_LOCKED(&hdr->coh_page_guard);
167 page = radix_tree_lookup(&hdr->coh_tree, index);
169 cl_page_get_trust(page);
173 EXPORT_SYMBOL(cl_page_lookup);
176 * Returns a list of pages by a given [start, end] of \a obj.
178 * \param resched If not NULL, then we give up before hogging CPU for too
179 * long and set *resched = 1, in that case caller should implement a retry
182 * Gang tree lookup (radix_tree_gang_lookup()) optimization is absolutely
183 * crucial in the face of [offset, EOF] locks.
185 * Return at least one page in @queue unless there is no covered page.
187 int cl_page_gang_lookup(const struct lu_env *env, struct cl_object *obj,
188 struct cl_io *io, pgoff_t start, pgoff_t end,
189 cl_page_gang_cb_t cb, void *cbdata)
191 struct cl_object_header *hdr;
192 struct cl_page *page;
193 struct cl_page **pvec;
194 const struct cl_page_slice *slice;
195 const struct lu_device_type *dtype;
200 int res = CLP_GANG_OKAY;
205 hdr = cl_object_header(obj);
206 pvec = cl_env_info(env)->clt_pvec;
207 dtype = cl_object_top(obj)->co_lu.lo_dev->ld_type;
208 cfs_spin_lock(&hdr->coh_page_guard);
209 while ((nr = radix_tree_gang_lookup(&hdr->coh_tree, (void **)pvec,
210 idx, CLT_PVEC_SIZE)) > 0) {
211 int end_of_region = 0;
212 idx = pvec[nr - 1]->cp_index + 1;
213 for (i = 0, j = 0; i < nr; ++i) {
217 LASSERT(page->cp_type == CPT_CACHEABLE);
218 if (page->cp_index > end) {
222 if (page->cp_state == CPS_FREEING)
225 slice = cl_page_at_trusted(page, dtype);
227 * Pages for lsm-less file has no underneath sub-page
228 * for osc, in case of ...
230 PASSERT(env, page, slice != NULL);
232 page = slice->cpl_page;
234 * Can safely call cl_page_get_trust() under
235 * radix-tree spin-lock.
237 * XXX not true, because @page is from object another
238 * than @hdr and protected by different tree lock.
240 cl_page_get_trust(page);
241 lu_ref_add_atomic(&page->cp_reference,
242 "gang_lookup", cfs_current());
247 * Here a delicate locking dance is performed. Current thread
248 * holds a reference to a page, but has to own it before it
249 * can be placed into queue. Owning implies waiting, so
250 * radix-tree lock is to be released. After a wait one has to
251 * check that pages weren't truncated (cl_page_own() returns
252 * error in the latter case).
254 cfs_spin_unlock(&hdr->coh_page_guard);
257 for (i = 0; i < j; ++i) {
259 if (res == CLP_GANG_OKAY)
260 res = (*cb)(env, io, page, cbdata);
261 lu_ref_del(&page->cp_reference,
262 "gang_lookup", cfs_current());
263 cl_page_put(env, page);
265 if (nr < CLT_PVEC_SIZE || end_of_region)
268 if (res == CLP_GANG_OKAY && cfs_need_resched())
269 res = CLP_GANG_RESCHED;
270 if (res != CLP_GANG_OKAY)
273 cfs_spin_lock(&hdr->coh_page_guard);
277 cfs_spin_unlock(&hdr->coh_page_guard);
280 EXPORT_SYMBOL(cl_page_gang_lookup);
282 static void cl_page_free(const struct lu_env *env, struct cl_page *page)
284 struct cl_object *obj = page->cp_obj;
285 struct cl_site *site = cl_object_site(obj);
287 PASSERT(env, page, cfs_list_empty(&page->cp_batch));
288 PASSERT(env, page, page->cp_owner == NULL);
289 PASSERT(env, page, page->cp_req == NULL);
290 PASSERT(env, page, page->cp_parent == NULL);
291 PASSERT(env, page, page->cp_state == CPS_FREEING);
295 while (!cfs_list_empty(&page->cp_layers)) {
296 struct cl_page_slice *slice;
298 slice = cfs_list_entry(page->cp_layers.next,
299 struct cl_page_slice, cpl_linkage);
300 cfs_list_del_init(page->cp_layers.next);
301 slice->cpl_ops->cpo_fini(env, slice);
303 cfs_atomic_dec(&site->cs_pages.cs_total);
305 #ifdef LUSTRE_PAGESTATE_TRACKING
306 cfs_atomic_dec(&site->cs_pages_state[page->cp_state]);
308 lu_object_ref_del_at(&obj->co_lu, page->cp_obj_ref, "cl_page", page);
309 cl_object_put(env, obj);
310 lu_ref_fini(&page->cp_reference);
311 OBD_SLAB_FREE_PTR(page, cl_page_kmem);
316 * Helper function updating page state. This is the only place in the code
317 * where cl_page::cp_state field is mutated.
319 static inline void cl_page_state_set_trust(struct cl_page *page,
320 enum cl_page_state state)
323 *(enum cl_page_state *)&page->cp_state = state;
326 static int cl_page_alloc(const struct lu_env *env, struct cl_object *o,
327 pgoff_t ind, struct page *vmpage,
328 enum cl_page_type type, struct cl_page **out)
330 struct cl_page *page;
331 struct cl_page *err = NULL;
332 struct lu_object_header *head;
333 struct cl_site *site = cl_object_site(o);
338 OBD_SLAB_ALLOC_PTR_GFP(page, cl_page_kmem, CFS_ALLOC_IO);
340 cfs_atomic_set(&page->cp_ref, 1);
343 page->cp_obj_ref = lu_object_ref_add(&o->co_lu,
345 page->cp_index = ind;
346 cl_page_state_set_trust(page, CPS_CACHED);
347 page->cp_type = type;
348 CFS_INIT_LIST_HEAD(&page->cp_layers);
349 CFS_INIT_LIST_HEAD(&page->cp_batch);
350 CFS_INIT_LIST_HEAD(&page->cp_flight);
351 cfs_mutex_init(&page->cp_mutex);
352 lu_ref_init(&page->cp_reference);
353 head = o->co_lu.lo_header;
354 cfs_list_for_each_entry(o, &head->loh_layers,
356 if (o->co_ops->coo_page_init != NULL) {
357 err = o->co_ops->coo_page_init(env, o,
360 cl_page_delete0(env, page, 0);
361 cl_page_free(env, page);
368 cfs_atomic_inc(&site->cs_pages.cs_busy);
369 cfs_atomic_inc(&site->cs_pages.cs_total);
371 #ifdef LUSTRE_PAGESTATE_TRACKING
372 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 = NULL;
401 struct cl_page *ghost = NULL;
402 struct cl_object_header *hdr;
403 struct cl_site *site = cl_object_site(o);
406 LASSERT(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 %lx %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,
436 cfs_atomic_inc(&site->cs_pages.cs_hit);
440 /* allocate and initialize cl_page */
441 err = cl_page_alloc(env, o, idx, vmpage, type, &page);
445 if (type == CPT_TRANSIENT) {
447 LASSERT(page->cp_parent == NULL);
448 page->cp_parent = parent;
449 parent->cp_child = page;
455 * XXX optimization: use radix_tree_preload() here, and change tree
456 * gfp mask to GFP_KERNEL in cl_object_header_init().
458 cfs_spin_lock(&hdr->coh_page_guard);
459 err = radix_tree_insert(&hdr->coh_tree, idx, page);
463 * Noted by Jay: a lock on \a vmpage protects cl_page_find()
464 * from this race, but
466 * 0. it's better to have cl_page interface "locally
467 * consistent" so that its correctness can be reasoned
468 * about without appealing to the (obscure world of) VM
471 * 1. handling this race allows ->coh_tree to remain
472 * consistent even when VM locking is somehow busted,
473 * which is very useful during diagnosing and debugging.
476 CL_PAGE_DEBUG(D_ERROR, env, ghost,
477 "fail to insert into radix tree: %d\n", err);
480 LASSERT(page->cp_parent == NULL);
481 page->cp_parent = parent;
482 parent->cp_child = page;
486 cfs_spin_unlock(&hdr->coh_page_guard);
488 if (unlikely(ghost != NULL)) {
489 cfs_atomic_dec(&site->cs_pages.cs_busy);
490 cl_page_delete0(env, ghost, 0);
491 cl_page_free(env, ghost);
496 struct cl_page *cl_page_find(const struct lu_env *env, struct cl_object *o,
497 pgoff_t idx, struct page *vmpage,
498 enum cl_page_type type)
500 return cl_page_find0(env, o, idx, vmpage, type, NULL);
502 EXPORT_SYMBOL(cl_page_find);
505 struct cl_page *cl_page_find_sub(const struct lu_env *env, struct cl_object *o,
506 pgoff_t idx, struct page *vmpage,
507 struct cl_page *parent)
509 return cl_page_find0(env, o, idx, vmpage, parent->cp_type, parent);
511 EXPORT_SYMBOL(cl_page_find_sub);
513 static inline int cl_page_invariant(const struct cl_page *pg)
515 struct cl_object_header *header;
516 struct cl_page *parent;
517 struct cl_page *child;
521 * Page invariant is protected by a VM lock.
523 LINVRNT(cl_page_is_vmlocked(NULL, pg));
525 header = cl_object_header(pg->cp_obj);
526 parent = pg->cp_parent;
527 child = pg->cp_child;
528 owner = pg->cp_owner;
530 return cfs_atomic_read(&pg->cp_ref) > 0 &&
531 ergo(parent != NULL, parent->cp_child == pg) &&
532 ergo(child != NULL, child->cp_parent == pg) &&
533 ergo(child != NULL, pg->cp_obj != child->cp_obj) &&
534 ergo(parent != NULL, pg->cp_obj != parent->cp_obj) &&
535 ergo(owner != NULL && parent != NULL,
536 parent->cp_owner == pg->cp_owner->ci_parent) &&
537 ergo(owner != NULL && child != NULL,
538 child->cp_owner->ci_parent == owner) &&
540 * Either page is early in initialization (has neither child
541 * nor parent yet), or it is in the object radix tree.
543 ergo(pg->cp_state < CPS_FREEING && pg->cp_type == CPT_CACHEABLE,
544 (void *)radix_tree_lookup(&header->coh_tree,
545 pg->cp_index) == pg ||
546 (child == NULL && parent == NULL));
549 static void cl_page_state_set0(const struct lu_env *env,
550 struct cl_page *page, enum cl_page_state state)
552 enum cl_page_state old;
553 #ifdef LUSTRE_PAGESTATE_TRACKING
554 struct cl_site *site = cl_object_site(page->cp_obj);
558 * Matrix of allowed state transitions [old][new], for sanity
561 static const int allowed_transitions[CPS_NR][CPS_NR] = {
564 [CPS_OWNED] = 1, /* io finds existing cached page */
566 [CPS_PAGEOUT] = 1, /* write-out from the cache */
567 [CPS_FREEING] = 1, /* eviction on the memory pressure */
570 [CPS_CACHED] = 1, /* release to the cache */
572 [CPS_PAGEIN] = 1, /* start read immediately */
573 [CPS_PAGEOUT] = 1, /* start write immediately */
574 [CPS_FREEING] = 1, /* lock invalidation or truncate */
577 [CPS_CACHED] = 1, /* io completion */
584 [CPS_CACHED] = 1, /* io completion */
600 old = page->cp_state;
601 PASSERT(env, page, allowed_transitions[old][state]);
602 CL_PAGE_HEADER(D_TRACE, env, page, "%d -> %d\n", old, state);
603 for (; page != NULL; page = page->cp_child) {
604 PASSERT(env, page, page->cp_state == old);
606 equi(state == CPS_OWNED, page->cp_owner != NULL));
608 #ifdef LUSTRE_PAGESTATE_TRACKING
609 cfs_atomic_dec(&site->cs_pages_state[page->cp_state]);
610 cfs_atomic_inc(&site->cs_pages_state[state]);
612 cl_page_state_set_trust(page, state);
617 static void cl_page_state_set(const struct lu_env *env,
618 struct cl_page *page, enum cl_page_state state)
620 cl_page_state_set0(env, page, state);
624 * Acquires an additional reference to a page.
626 * This can be called only by caller already possessing a reference to \a
629 * \see cl_object_get(), cl_lock_get().
631 void cl_page_get(struct cl_page *page)
634 LASSERT(page->cp_state != CPS_FREEING);
635 cl_page_get_trust(page);
638 EXPORT_SYMBOL(cl_page_get);
641 * Releases a reference to a page.
643 * When last reference is released, page is returned to the cache, unless it
644 * is in cl_page_state::CPS_FREEING state, in which case it is immediately
647 * \see cl_object_put(), cl_lock_put().
649 void cl_page_put(const struct lu_env *env, struct cl_page *page)
651 struct cl_object_header *hdr;
652 struct cl_site *site = cl_object_site(page->cp_obj);
654 PASSERT(env, page, cfs_atomic_read(&page->cp_ref) > !!page->cp_parent);
657 CL_PAGE_HEADER(D_TRACE, env, page, "%d\n",
658 cfs_atomic_read(&page->cp_ref));
660 hdr = cl_object_header(cl_object_top(page->cp_obj));
661 if (cfs_atomic_dec_and_lock(&page->cp_ref, &hdr->coh_page_guard)) {
662 cfs_atomic_dec(&site->cs_pages.cs_busy);
663 /* We're going to access the page w/o a reference, but it's
664 * ok because we have grabbed the lock coh_page_guard, which
665 * means nobody is able to free this page behind us.
667 if (page->cp_state == CPS_FREEING) {
668 /* We drop the page reference and check the page state
669 * inside the coh_page_guard. So that if it gets here,
670 * it is the REALLY last reference to this page.
672 cfs_spin_unlock(&hdr->coh_page_guard);
674 LASSERT(cfs_atomic_read(&page->cp_ref) == 0);
675 PASSERT(env, page, page->cp_owner == NULL);
676 PASSERT(env, page, cfs_list_empty(&page->cp_batch));
678 * Page is no longer reachable by other threads. Tear
681 cl_page_free(env, page);
686 cfs_spin_unlock(&hdr->coh_page_guard);
691 EXPORT_SYMBOL(cl_page_put);
694 * Returns a VM page associated with a given cl_page.
696 cfs_page_t *cl_page_vmpage(const struct lu_env *env, struct cl_page *page)
698 const struct cl_page_slice *slice;
701 * Find uppermost layer with ->cpo_vmpage() method, and return its
704 page = cl_page_top(page);
706 cfs_list_for_each_entry(slice, &page->cp_layers, cpl_linkage) {
707 if (slice->cpl_ops->cpo_vmpage != NULL)
708 RETURN(slice->cpl_ops->cpo_vmpage(env, slice));
710 page = page->cp_child;
711 } while (page != NULL);
712 LBUG(); /* ->cpo_vmpage() has to be defined somewhere in the stack */
714 EXPORT_SYMBOL(cl_page_vmpage);
717 * Returns a cl_page associated with a VM page, and given cl_object.
719 struct cl_page *cl_vmpage_page(cfs_page_t *vmpage, struct cl_object *obj)
721 struct cl_page *page;
722 struct cl_object_header *hdr;
725 KLASSERT(PageLocked(vmpage));
728 * NOTE: absence of races and liveness of data are guaranteed by page
729 * lock on a "vmpage". That works because object destruction has
730 * bottom-to-top pass.
734 * This loop assumes that ->private points to the top-most page. This
735 * can be rectified easily.
737 hdr = cl_object_header(cl_object_top(obj));
738 cfs_spin_lock(&hdr->coh_page_guard);
739 for (page = (void *)vmpage->private;
740 page != NULL; page = page->cp_child) {
741 if (cl_object_same(page->cp_obj, obj)) {
742 cl_page_get_trust(page);
746 cfs_spin_unlock(&hdr->coh_page_guard);
747 LASSERT(ergo(page, page->cp_type == CPT_CACHEABLE));
750 EXPORT_SYMBOL(cl_vmpage_page);
753 * Returns the top-page for a given page.
755 * \see cl_object_top(), cl_io_top()
757 struct cl_page *cl_page_top(struct cl_page *page)
759 return cl_page_top_trusted(page);
761 EXPORT_SYMBOL(cl_page_top);
763 const struct cl_page_slice *cl_page_at(const struct cl_page *page,
764 const struct lu_device_type *dtype)
766 return cl_page_at_trusted(page, dtype);
768 EXPORT_SYMBOL(cl_page_at);
770 #define CL_PAGE_OP(opname) offsetof(struct cl_page_operations, opname)
772 #define CL_PAGE_INVOKE(_env, _page, _op, _proto, ...) \
774 const struct lu_env *__env = (_env); \
775 struct cl_page *__page = (_page); \
776 const struct cl_page_slice *__scan; \
778 ptrdiff_t __op = (_op); \
779 int (*__method)_proto; \
782 __page = cl_page_top(__page); \
784 cfs_list_for_each_entry(__scan, &__page->cp_layers, \
786 __method = *(void **)((char *)__scan->cpl_ops + \
788 if (__method != NULL) { \
789 __result = (*__method)(__env, __scan, \
795 __page = __page->cp_child; \
796 } while (__page != NULL && __result == 0); \
802 #define CL_PAGE_INVOID(_env, _page, _op, _proto, ...) \
804 const struct lu_env *__env = (_env); \
805 struct cl_page *__page = (_page); \
806 const struct cl_page_slice *__scan; \
807 ptrdiff_t __op = (_op); \
808 void (*__method)_proto; \
810 __page = cl_page_top(__page); \
812 cfs_list_for_each_entry(__scan, &__page->cp_layers, \
814 __method = *(void **)((char *)__scan->cpl_ops + \
816 if (__method != NULL) \
817 (*__method)(__env, __scan, \
820 __page = __page->cp_child; \
821 } while (__page != NULL); \
824 #define CL_PAGE_INVOID_REVERSE(_env, _page, _op, _proto, ...) \
826 const struct lu_env *__env = (_env); \
827 struct cl_page *__page = (_page); \
828 const struct cl_page_slice *__scan; \
829 ptrdiff_t __op = (_op); \
830 void (*__method)_proto; \
832 /* get to the bottom page. */ \
833 while (__page->cp_child != NULL) \
834 __page = __page->cp_child; \
836 cfs_list_for_each_entry_reverse(__scan, &__page->cp_layers, \
838 __method = *(void **)((char *)__scan->cpl_ops + \
840 if (__method != NULL) \
841 (*__method)(__env, __scan, \
844 __page = __page->cp_parent; \
845 } while (__page != NULL); \
848 static int cl_page_invoke(const struct lu_env *env,
849 struct cl_io *io, struct cl_page *page, ptrdiff_t op)
852 PINVRNT(env, page, cl_object_same(page->cp_obj, io->ci_obj));
854 RETURN(CL_PAGE_INVOKE(env, page, op,
855 (const struct lu_env *,
856 const struct cl_page_slice *, struct cl_io *),
860 static void cl_page_invoid(const struct lu_env *env,
861 struct cl_io *io, struct cl_page *page, ptrdiff_t op)
864 PINVRNT(env, page, cl_object_same(page->cp_obj, io->ci_obj));
866 CL_PAGE_INVOID(env, page, op,
867 (const struct lu_env *,
868 const struct cl_page_slice *, struct cl_io *), io);
872 static void cl_page_owner_clear(struct cl_page *page)
875 for (page = cl_page_top(page); page != NULL; page = page->cp_child) {
876 if (page->cp_owner != NULL) {
877 LASSERT(page->cp_owner->ci_owned_nr > 0);
878 page->cp_owner->ci_owned_nr--;
879 page->cp_owner = NULL;
880 page->cp_task = NULL;
886 static void cl_page_owner_set(struct cl_page *page)
889 for (page = cl_page_top(page); page != NULL; page = page->cp_child) {
890 LASSERT(page->cp_owner != NULL);
891 page->cp_owner->ci_owned_nr++;
896 void cl_page_disown0(const struct lu_env *env,
897 struct cl_io *io, struct cl_page *pg)
899 enum cl_page_state state;
902 state = pg->cp_state;
903 PINVRNT(env, pg, state == CPS_OWNED || state == CPS_FREEING);
904 PINVRNT(env, pg, cl_page_invariant(pg));
905 cl_page_owner_clear(pg);
907 if (state == CPS_OWNED)
908 cl_page_state_set(env, pg, CPS_CACHED);
910 * Completion call-backs are executed in the bottom-up order, so that
911 * uppermost layer (llite), responsible for VFS/VM interaction runs
912 * last and can release locks safely.
914 CL_PAGE_INVOID_REVERSE(env, pg, CL_PAGE_OP(cpo_disown),
915 (const struct lu_env *,
916 const struct cl_page_slice *, struct cl_io *),
922 * returns true, iff page is owned by the given io.
924 int cl_page_is_owned(const struct cl_page *pg, const struct cl_io *io)
926 LINVRNT(cl_object_same(pg->cp_obj, io->ci_obj));
928 RETURN(pg->cp_state == CPS_OWNED && pg->cp_owner == io);
930 EXPORT_SYMBOL(cl_page_is_owned);
933 * Try to own a page by IO.
935 * Waits until page is in cl_page_state::CPS_CACHED state, and then switch it
936 * into cl_page_state::CPS_OWNED state.
938 * \pre !cl_page_is_owned(pg, io)
939 * \post result == 0 iff cl_page_is_owned(pg, io)
943 * \retval -ve failure, e.g., page was destroyed (and landed in
944 * cl_page_state::CPS_FREEING instead of cl_page_state::CPS_CACHED).
945 * or, page was owned by another thread, or in IO.
947 * \see cl_page_disown()
948 * \see cl_page_operations::cpo_own()
949 * \see cl_page_own_try()
952 static int cl_page_own0(const struct lu_env *env, struct cl_io *io,
953 struct cl_page *pg, int nonblock)
957 PINVRNT(env, pg, !cl_page_is_owned(pg, io));
960 pg = cl_page_top(pg);
963 if (pg->cp_state == CPS_FREEING) {
966 result = CL_PAGE_INVOKE(env, pg, CL_PAGE_OP(cpo_own),
967 (const struct lu_env *,
968 const struct cl_page_slice *,
969 struct cl_io *, int),
972 PASSERT(env, pg, pg->cp_owner == NULL);
973 PASSERT(env, pg, pg->cp_req == NULL);
975 pg->cp_task = current;
976 cl_page_owner_set(pg);
977 if (pg->cp_state != CPS_FREEING) {
978 cl_page_state_set(env, pg, CPS_OWNED);
980 cl_page_disown0(env, io, pg);
985 PINVRNT(env, pg, ergo(result == 0, cl_page_invariant(pg)));
990 * Own a page, might be blocked.
992 * \see cl_page_own0()
994 int cl_page_own(const struct lu_env *env, struct cl_io *io, struct cl_page *pg)
996 return cl_page_own0(env, io, pg, 0);
998 EXPORT_SYMBOL(cl_page_own);
1001 * Nonblock version of cl_page_own().
1003 * \see cl_page_own0()
1005 int cl_page_own_try(const struct lu_env *env, struct cl_io *io,
1008 return cl_page_own0(env, io, pg, 1);
1010 EXPORT_SYMBOL(cl_page_own_try);
1014 * Assume page ownership.
1016 * Called when page is already locked by the hosting VM.
1018 * \pre !cl_page_is_owned(pg, io)
1019 * \post cl_page_is_owned(pg, io)
1021 * \see cl_page_operations::cpo_assume()
1023 void cl_page_assume(const struct lu_env *env,
1024 struct cl_io *io, struct cl_page *pg)
1026 PINVRNT(env, pg, cl_object_same(pg->cp_obj, io->ci_obj));
1029 pg = cl_page_top(pg);
1032 cl_page_invoid(env, io, pg, CL_PAGE_OP(cpo_assume));
1033 PASSERT(env, pg, pg->cp_owner == NULL);
1035 pg->cp_task = current;
1036 cl_page_owner_set(pg);
1037 cl_page_state_set(env, pg, CPS_OWNED);
1040 EXPORT_SYMBOL(cl_page_assume);
1043 * Releases page ownership without unlocking the page.
1045 * Moves page into cl_page_state::CPS_CACHED without releasing a lock on the
1046 * underlying VM page (as VM is supposed to do this itself).
1048 * \pre cl_page_is_owned(pg, io)
1049 * \post !cl_page_is_owned(pg, io)
1051 * \see cl_page_assume()
1053 void cl_page_unassume(const struct lu_env *env,
1054 struct cl_io *io, struct cl_page *pg)
1056 PINVRNT(env, pg, cl_page_is_owned(pg, io));
1057 PINVRNT(env, pg, cl_page_invariant(pg));
1060 pg = cl_page_top(pg);
1062 cl_page_owner_clear(pg);
1063 cl_page_state_set(env, pg, CPS_CACHED);
1064 CL_PAGE_INVOID_REVERSE(env, pg, CL_PAGE_OP(cpo_unassume),
1065 (const struct lu_env *,
1066 const struct cl_page_slice *, struct cl_io *),
1070 EXPORT_SYMBOL(cl_page_unassume);
1073 * Releases page ownership.
1075 * Moves page into cl_page_state::CPS_CACHED.
1077 * \pre cl_page_is_owned(pg, io)
1078 * \post !cl_page_is_owned(pg, io)
1080 * \see cl_page_own()
1081 * \see cl_page_operations::cpo_disown()
1083 void cl_page_disown(const struct lu_env *env,
1084 struct cl_io *io, struct cl_page *pg)
1086 PINVRNT(env, pg, cl_page_is_owned(pg, io));
1089 pg = cl_page_top(pg);
1091 cl_page_disown0(env, io, pg);
1094 EXPORT_SYMBOL(cl_page_disown);
1097 * Called when page is to be removed from the object, e.g., as a result of
1100 * Calls cl_page_operations::cpo_discard() top-to-bottom.
1102 * \pre cl_page_is_owned(pg, io)
1104 * \see cl_page_operations::cpo_discard()
1106 void cl_page_discard(const struct lu_env *env,
1107 struct cl_io *io, struct cl_page *pg)
1109 PINVRNT(env, pg, cl_page_is_owned(pg, io));
1110 PINVRNT(env, pg, cl_page_invariant(pg));
1112 cl_page_invoid(env, io, pg, CL_PAGE_OP(cpo_discard));
1114 EXPORT_SYMBOL(cl_page_discard);
1117 * Version of cl_page_delete() that can be called for not fully constructed
1118 * pages, e.g,. in a error handling cl_page_find()->cl_page_delete0()
1119 * path. Doesn't check page invariant.
1121 static void cl_page_delete0(const struct lu_env *env, struct cl_page *pg,
1124 struct cl_page *tmp = pg;
1127 PASSERT(env, pg, pg == cl_page_top(pg));
1128 PASSERT(env, pg, pg->cp_state != CPS_FREEING);
1131 * Severe all ways to obtain new pointers to @pg.
1133 cl_page_owner_clear(pg);
1136 * unexport the page firstly before freeing it so that
1137 * the page content is considered to be invalid.
1138 * We have to do this because a CPS_FREEING cl_page may
1139 * be NOT under the protection of a cl_lock.
1140 * Afterwards, if this page is found by other threads, then this
1141 * page will be forced to reread.
1143 cl_page_export(env, pg, 0);
1144 cl_page_state_set0(env, pg, CPS_FREEING);
1146 if (tmp->cp_type == CPT_CACHEABLE) {
1148 /* !radix means that @pg is not yet in the radix tree,
1152 for (; tmp != NULL; tmp = tmp->cp_child) {
1154 struct cl_object_header *hdr;
1156 hdr = cl_object_header(tmp->cp_obj);
1157 cfs_spin_lock(&hdr->coh_page_guard);
1158 value = radix_tree_delete(&hdr->coh_tree,
1160 PASSERT(env, tmp, value == tmp);
1161 PASSERT(env, tmp, hdr->coh_pages > 0);
1163 cfs_spin_unlock(&hdr->coh_page_guard);
1167 CL_PAGE_INVOID(env, pg, CL_PAGE_OP(cpo_delete),
1168 (const struct lu_env *, const struct cl_page_slice *));
1173 * Called when a decision is made to throw page out of memory.
1175 * Notifies all layers about page destruction by calling
1176 * cl_page_operations::cpo_delete() method top-to-bottom.
1178 * Moves page into cl_page_state::CPS_FREEING state (this is the only place
1179 * where transition to this state happens).
1181 * Eliminates all venues through which new references to the page can be
1184 * - removes page from the radix trees,
1186 * - breaks linkage from VM page to cl_page.
1188 * Once page reaches cl_page_state::CPS_FREEING, all remaining references will
1189 * drain after some time, at which point page will be recycled.
1191 * \pre pg == cl_page_top(pg)
1192 * \pre VM page is locked
1193 * \post pg->cp_state == CPS_FREEING
1195 * \see cl_page_operations::cpo_delete()
1197 void cl_page_delete(const struct lu_env *env, struct cl_page *pg)
1199 PINVRNT(env, pg, cl_page_invariant(pg));
1201 cl_page_delete0(env, pg, 1);
1204 EXPORT_SYMBOL(cl_page_delete);
1207 * Unmaps page from user virtual memory.
1209 * Calls cl_page_operations::cpo_unmap() through all layers top-to-bottom. The
1210 * layer responsible for VM interaction has to unmap page from user space
1213 * \see cl_page_operations::cpo_unmap()
1215 int cl_page_unmap(const struct lu_env *env,
1216 struct cl_io *io, struct cl_page *pg)
1218 PINVRNT(env, pg, cl_page_is_owned(pg, io));
1219 PINVRNT(env, pg, cl_page_invariant(pg));
1221 return cl_page_invoke(env, io, pg, CL_PAGE_OP(cpo_unmap));
1223 EXPORT_SYMBOL(cl_page_unmap);
1226 * Marks page up-to-date.
1228 * Call cl_page_operations::cpo_export() through all layers top-to-bottom. The
1229 * layer responsible for VM interaction has to mark/clear page as up-to-date
1230 * by the \a uptodate argument.
1232 * \see cl_page_operations::cpo_export()
1234 void cl_page_export(const struct lu_env *env, struct cl_page *pg, int uptodate)
1236 PINVRNT(env, pg, cl_page_invariant(pg));
1237 CL_PAGE_INVOID(env, pg, CL_PAGE_OP(cpo_export),
1238 (const struct lu_env *,
1239 const struct cl_page_slice *, int), uptodate);
1241 EXPORT_SYMBOL(cl_page_export);
1244 * Returns true, iff \a pg is VM locked in a suitable sense by the calling
1247 int cl_page_is_vmlocked(const struct lu_env *env, const struct cl_page *pg)
1250 const struct cl_page_slice *slice;
1253 pg = cl_page_top_trusted((struct cl_page *)pg);
1254 slice = container_of(pg->cp_layers.next,
1255 const struct cl_page_slice, cpl_linkage);
1256 PASSERT(env, pg, slice->cpl_ops->cpo_is_vmlocked != NULL);
1258 * Call ->cpo_is_vmlocked() directly instead of going through
1259 * CL_PAGE_INVOKE(), because cl_page_is_vmlocked() is used by
1260 * cl_page_invariant().
1262 result = slice->cpl_ops->cpo_is_vmlocked(env, slice);
1263 PASSERT(env, pg, result == -EBUSY || result == -ENODATA);
1264 RETURN(result == -EBUSY);
1266 EXPORT_SYMBOL(cl_page_is_vmlocked);
1268 static enum cl_page_state cl_req_type_state(enum cl_req_type crt)
1271 RETURN(crt == CRT_WRITE ? CPS_PAGEOUT : CPS_PAGEIN);
1274 static void cl_page_io_start(const struct lu_env *env,
1275 struct cl_page *pg, enum cl_req_type crt)
1278 * Page is queued for IO, change its state.
1281 cl_page_owner_clear(pg);
1282 cl_page_state_set(env, pg, cl_req_type_state(crt));
1287 * Prepares page for immediate transfer. cl_page_operations::cpo_prep() is
1288 * called top-to-bottom. Every layer either agrees to submit this page (by
1289 * returning 0), or requests to omit this page (by returning -EALREADY). Layer
1290 * handling interactions with the VM also has to inform VM that page is under
1293 int cl_page_prep(const struct lu_env *env, struct cl_io *io,
1294 struct cl_page *pg, enum cl_req_type crt)
1298 PINVRNT(env, pg, cl_page_is_owned(pg, io));
1299 PINVRNT(env, pg, cl_page_invariant(pg));
1300 PINVRNT(env, pg, crt < CRT_NR);
1303 * XXX this has to be called bottom-to-top, so that llite can set up
1304 * PG_writeback without risking other layers deciding to skip this
1307 result = cl_page_invoke(env, io, pg, CL_PAGE_OP(io[crt].cpo_prep));
1309 cl_page_io_start(env, pg, crt);
1311 KLASSERT(ergo(crt == CRT_WRITE && pg->cp_type == CPT_CACHEABLE,
1313 PageWriteback(cl_page_vmpage(env, pg)))));
1314 CL_PAGE_HEADER(D_TRACE, env, pg, "%d %d\n", crt, result);
1317 EXPORT_SYMBOL(cl_page_prep);
1320 * Notify layers about transfer completion.
1322 * Invoked by transfer sub-system (which is a part of osc) to notify layers
1323 * that a transfer, of which this page is a part of has completed.
1325 * Completion call-backs are executed in the bottom-up order, so that
1326 * uppermost layer (llite), responsible for the VFS/VM interaction runs last
1327 * and can release locks safely.
1329 * \pre pg->cp_state == CPS_PAGEIN || pg->cp_state == CPS_PAGEOUT
1330 * \post pg->cp_state == CPS_CACHED
1332 * \see cl_page_operations::cpo_completion()
1334 void cl_page_completion(const struct lu_env *env,
1335 struct cl_page *pg, enum cl_req_type crt, int ioret)
1337 struct cl_sync_io *anchor = pg->cp_sync_io;
1339 PASSERT(env, pg, crt < CRT_NR);
1340 /* cl_page::cp_req already cleared by the caller (osc_completion()) */
1341 PASSERT(env, pg, pg->cp_req == NULL);
1342 PASSERT(env, pg, pg->cp_state == cl_req_type_state(crt));
1345 CL_PAGE_HEADER(D_TRACE, env, pg, "%d %d\n", crt, ioret);
1346 if (crt == CRT_READ && ioret == 0) {
1347 PASSERT(env, pg, !(pg->cp_flags & CPF_READ_COMPLETED));
1348 pg->cp_flags |= CPF_READ_COMPLETED;
1351 cl_page_state_set(env, pg, CPS_CACHED);
1352 CL_PAGE_INVOID_REVERSE(env, pg, CL_PAGE_OP(io[crt].cpo_completion),
1353 (const struct lu_env *,
1354 const struct cl_page_slice *, int), ioret);
1356 LASSERT(cl_page_is_vmlocked(env, pg));
1357 LASSERT(pg->cp_sync_io == anchor);
1358 pg->cp_sync_io = NULL;
1359 cl_sync_io_note(anchor, ioret);
1362 /* Don't assert the page writeback bit here because the lustre file
1363 * may be as a backend of swap space. in this case, the page writeback
1364 * is set by VM, and obvious we shouldn't clear it at all. Fortunately
1365 * this type of pages are all TRANSIENT pages. */
1366 KLASSERT(ergo(pg->cp_type == CPT_CACHEABLE,
1367 !PageWriteback(cl_page_vmpage(env, pg))));
1370 EXPORT_SYMBOL(cl_page_completion);
1373 * Notify layers that transfer formation engine decided to yank this page from
1374 * the cache and to make it a part of a transfer.
1376 * \pre pg->cp_state == CPS_CACHED
1377 * \post pg->cp_state == CPS_PAGEIN || pg->cp_state == CPS_PAGEOUT
1379 * \see cl_page_operations::cpo_make_ready()
1381 int cl_page_make_ready(const struct lu_env *env, struct cl_page *pg,
1382 enum cl_req_type crt)
1386 PINVRNT(env, pg, crt < CRT_NR);
1389 result = CL_PAGE_INVOKE(env, pg, CL_PAGE_OP(io[crt].cpo_make_ready),
1390 (const struct lu_env *,
1391 const struct cl_page_slice *));
1393 PASSERT(env, pg, pg->cp_state == CPS_CACHED);
1394 cl_page_io_start(env, pg, crt);
1396 CL_PAGE_HEADER(D_TRACE, env, pg, "%d %d\n", crt, result);
1399 EXPORT_SYMBOL(cl_page_make_ready);
1402 * Notify layers that high level io decided to place this page into a cache
1403 * for future transfer.
1405 * The layer implementing transfer engine (osc) has to register this page in
1408 * \pre cl_page_is_owned(pg, io)
1409 * \post cl_page_is_owned(pg, io)
1411 * \see cl_page_operations::cpo_cache_add()
1413 int cl_page_cache_add(const struct lu_env *env, struct cl_io *io,
1414 struct cl_page *pg, enum cl_req_type crt)
1416 const struct cl_page_slice *scan;
1419 PINVRNT(env, pg, crt < CRT_NR);
1420 PINVRNT(env, pg, cl_page_is_owned(pg, io));
1421 PINVRNT(env, pg, cl_page_invariant(pg));
1425 cfs_list_for_each_entry(scan, &pg->cp_layers, cpl_linkage) {
1426 if (scan->cpl_ops->io[crt].cpo_cache_add == NULL)
1429 result = scan->cpl_ops->io[crt].cpo_cache_add(env, scan, io);
1433 CL_PAGE_HEADER(D_TRACE, env, pg, "%d %d\n", crt, result);
1436 EXPORT_SYMBOL(cl_page_cache_add);
1439 * Called if a pge is being written back by kernel's intention.
1441 * \pre cl_page_is_owned(pg, io)
1442 * \post ergo(result == 0, pg->cp_state == CPS_PAGEOUT)
1444 * \see cl_page_operations::cpo_flush()
1446 int cl_page_flush(const struct lu_env *env, struct cl_io *io,
1451 PINVRNT(env, pg, cl_page_is_owned(pg, io));
1452 PINVRNT(env, pg, cl_page_invariant(pg));
1456 result = cl_page_invoke(env, io, pg, CL_PAGE_OP(cpo_flush));
1458 CL_PAGE_HEADER(D_TRACE, env, pg, "%d\n", result);
1461 EXPORT_SYMBOL(cl_page_flush);
1464 * Checks whether page is protected by any extent lock is at least required
1467 * \return the same as in cl_page_operations::cpo_is_under_lock() method.
1468 * \see cl_page_operations::cpo_is_under_lock()
1470 int cl_page_is_under_lock(const struct lu_env *env, struct cl_io *io,
1471 struct cl_page *page)
1475 PINVRNT(env, page, cl_page_invariant(page));
1478 rc = CL_PAGE_INVOKE(env, page, CL_PAGE_OP(cpo_is_under_lock),
1479 (const struct lu_env *,
1480 const struct cl_page_slice *, struct cl_io *),
1482 PASSERT(env, page, rc != 0);
1485 EXPORT_SYMBOL(cl_page_is_under_lock);
1487 static int page_prune_cb(const struct lu_env *env, struct cl_io *io,
1488 struct cl_page *page, void *cbdata)
1490 cl_page_own(env, io, page);
1491 cl_page_unmap(env, io, page);
1492 cl_page_discard(env, io, page);
1493 cl_page_disown(env, io, page);
1494 return CLP_GANG_OKAY;
1498 * Purges all cached pages belonging to the object \a obj.
1500 int cl_pages_prune(const struct lu_env *env, struct cl_object *clobj)
1502 struct cl_thread_info *info;
1503 struct cl_object *obj = cl_object_top(clobj);
1508 info = cl_env_info(env);
1512 * initialize the io. This is ugly since we never do IO in this
1513 * function, we just make cl_page_list functions happy. -jay
1516 result = cl_io_init(env, io, CIT_MISC, obj);
1518 cl_io_fini(env, io);
1519 RETURN(io->ci_result);
1523 result = cl_page_gang_lookup(env, obj, io, 0, CL_PAGE_EOF,
1524 page_prune_cb, NULL);
1525 if (result == CLP_GANG_RESCHED)
1527 } while (result != CLP_GANG_OKAY);
1529 cl_io_fini(env, io);
1532 EXPORT_SYMBOL(cl_pages_prune);
1535 * Tells transfer engine that only part of a page is to be transmitted.
1537 * \see cl_page_operations::cpo_clip()
1539 void cl_page_clip(const struct lu_env *env, struct cl_page *pg,
1542 PINVRNT(env, pg, cl_page_invariant(pg));
1544 CL_PAGE_HEADER(D_TRACE, env, pg, "%d %d\n", from, to);
1545 CL_PAGE_INVOID(env, pg, CL_PAGE_OP(cpo_clip),
1546 (const struct lu_env *,
1547 const struct cl_page_slice *,int, int),
1550 EXPORT_SYMBOL(cl_page_clip);
1553 * Prints human readable representation of \a pg to the \a f.
1555 void cl_page_header_print(const struct lu_env *env, void *cookie,
1556 lu_printer_t printer, const struct cl_page *pg)
1558 (*printer)(env, cookie,
1559 "page@%p[%d %p:%lu ^%p_%p %d %d %d %p %p %#x]\n",
1560 pg, cfs_atomic_read(&pg->cp_ref), pg->cp_obj,
1561 pg->cp_index, pg->cp_parent, pg->cp_child,
1562 pg->cp_state, pg->cp_error, pg->cp_type,
1563 pg->cp_owner, pg->cp_req, pg->cp_flags);
1565 EXPORT_SYMBOL(cl_page_header_print);
1568 * Prints human readable representation of \a pg to the \a f.
1570 void cl_page_print(const struct lu_env *env, void *cookie,
1571 lu_printer_t printer, const struct cl_page *pg)
1573 struct cl_page *scan;
1575 for (scan = cl_page_top((struct cl_page *)pg);
1576 scan != NULL; scan = scan->cp_child)
1577 cl_page_header_print(env, cookie, printer, scan);
1578 CL_PAGE_INVOKE(env, (struct cl_page *)pg, CL_PAGE_OP(cpo_print),
1579 (const struct lu_env *env,
1580 const struct cl_page_slice *slice,
1581 void *cookie, lu_printer_t p), cookie, printer);
1582 (*printer)(env, cookie, "end page@%p\n", pg);
1584 EXPORT_SYMBOL(cl_page_print);
1587 * Cancel a page which is still in a transfer.
1589 int cl_page_cancel(const struct lu_env *env, struct cl_page *page)
1591 return CL_PAGE_INVOKE(env, page, CL_PAGE_OP(cpo_cancel),
1592 (const struct lu_env *,
1593 const struct cl_page_slice *));
1595 EXPORT_SYMBOL(cl_page_cancel);
1598 * Converts a byte offset within object \a obj into a page index.
1600 loff_t cl_offset(const struct cl_object *obj, pgoff_t idx)
1605 return (loff_t)idx << CFS_PAGE_SHIFT;
1607 EXPORT_SYMBOL(cl_offset);
1610 * Converts a page index into a byte offset within object \a obj.
1612 pgoff_t cl_index(const struct cl_object *obj, loff_t offset)
1617 return offset >> CFS_PAGE_SHIFT;
1619 EXPORT_SYMBOL(cl_index);
1621 int cl_page_size(const struct cl_object *obj)
1623 return 1 << CFS_PAGE_SHIFT;
1625 EXPORT_SYMBOL(cl_page_size);
1628 * Adds page slice to the compound page.
1630 * This is called by cl_object_operations::coo_page_init() methods to add a
1631 * per-layer state to the page. New state is added at the end of
1632 * cl_page::cp_layers list, that is, it is at the bottom of the stack.
1634 * \see cl_lock_slice_add(), cl_req_slice_add(), cl_io_slice_add()
1636 void cl_page_slice_add(struct cl_page *page, struct cl_page_slice *slice,
1637 struct cl_object *obj,
1638 const struct cl_page_operations *ops)
1641 cfs_list_add_tail(&slice->cpl_linkage, &page->cp_layers);
1642 slice->cpl_obj = obj;
1643 slice->cpl_ops = ops;
1644 slice->cpl_page = page;
1647 EXPORT_SYMBOL(cl_page_slice_add);
1649 int cl_page_init(void)
1651 return lu_kmem_init(cl_page_caches);
1654 void cl_page_fini(void)
1656 lu_kmem_fini(cl_page_caches);