2 * Copyright (c) 2000-2005 Silicon Graphics, Inc. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
28 * For further information regarding this notice, see:
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
34 * The xfs_buf.c code provides an abstract buffer cache model on top
35 * of the Linux page cache. Cached metadata blocks for a file system
36 * are hashed to the inode for the block device. xfs_buf.c assembles
37 * buffers (xfs_buf_t) on demand to aggregate such cached pages for I/O.
39 * Written by Steve Lord, Jim Mostek, Russell Cattelan
40 * and Rajagopal Ananthanarayanan ("ananth") at SGI.
44 #include <linux/stddef.h>
45 #include <linux/errno.h>
46 #include <linux/slab.h>
47 #include <linux/pagemap.h>
48 #include <linux/init.h>
49 #include <linux/vmalloc.h>
50 #include <linux/bio.h>
51 #include <linux/sysctl.h>
52 #include <linux/proc_fs.h>
53 #include <linux/workqueue.h>
54 #include <linux/percpu.h>
55 #include <linux/blkdev.h>
56 #include <linux/hash.h>
57 #include <linux/kthread.h>
59 #include "xfs_linux.h"
65 STATIC kmem_cache_t *pagebuf_zone;
66 STATIC kmem_shaker_t pagebuf_shake;
67 STATIC int xfsbufd_wakeup(int, gfp_t);
68 STATIC void pagebuf_delwri_queue(xfs_buf_t *, int);
70 STATIC struct workqueue_struct *xfslogd_workqueue;
71 struct workqueue_struct *xfsdatad_workqueue;
85 ktrace_enter(pagebuf_trace_buf,
87 (void *)(unsigned long)pb->pb_flags,
88 (void *)(unsigned long)pb->pb_hold.counter,
89 (void *)(unsigned long)pb->pb_sema.count.counter,
92 (void *)(unsigned long)((pb->pb_file_offset>>32) & 0xffffffff),
93 (void *)(unsigned long)(pb->pb_file_offset & 0xffffffff),
94 (void *)(unsigned long)pb->pb_buffer_length,
95 NULL, NULL, NULL, NULL, NULL);
97 ktrace_t *pagebuf_trace_buf;
98 #define PAGEBUF_TRACE_SIZE 4096
99 #define PB_TRACE(pb, id, data) \
100 pagebuf_trace(pb, id, (void *)data, (void *)__builtin_return_address(0))
102 #define PB_TRACE(pb, id, data) do { } while (0)
105 #ifdef PAGEBUF_LOCK_TRACKING
106 # define PB_SET_OWNER(pb) ((pb)->pb_last_holder = current->pid)
107 # define PB_CLEAR_OWNER(pb) ((pb)->pb_last_holder = -1)
108 # define PB_GET_OWNER(pb) ((pb)->pb_last_holder)
110 # define PB_SET_OWNER(pb) do { } while (0)
111 # define PB_CLEAR_OWNER(pb) do { } while (0)
112 # define PB_GET_OWNER(pb) do { } while (0)
116 * Pagebuf allocation / freeing.
119 #define pb_to_gfp(flags) \
120 ((((flags) & PBF_READ_AHEAD) ? __GFP_NORETRY : \
121 ((flags) & PBF_DONT_BLOCK) ? GFP_NOFS : GFP_KERNEL) | __GFP_NOWARN)
123 #define pb_to_km(flags) \
124 (((flags) & PBF_DONT_BLOCK) ? KM_NOFS : KM_SLEEP)
127 #define pagebuf_allocate(flags) \
128 kmem_zone_alloc(pagebuf_zone, pb_to_km(flags))
129 #define pagebuf_deallocate(pb) \
130 kmem_zone_free(pagebuf_zone, (pb));
133 * Page Region interfaces.
135 * For pages in filesystems where the blocksize is smaller than the
136 * pagesize, we use the page->private field (long) to hold a bitmap
137 * of uptodate regions within the page.
139 * Each such region is "bytes per page / bits per long" bytes long.
141 * NBPPR == number-of-bytes-per-page-region
142 * BTOPR == bytes-to-page-region (rounded up)
143 * BTOPRT == bytes-to-page-region-truncated (rounded down)
145 #if (BITS_PER_LONG == 32)
146 #define PRSHIFT (PAGE_CACHE_SHIFT - 5) /* (32 == 1<<5) */
147 #elif (BITS_PER_LONG == 64)
148 #define PRSHIFT (PAGE_CACHE_SHIFT - 6) /* (64 == 1<<6) */
150 #error BITS_PER_LONG must be 32 or 64
152 #define NBPPR (PAGE_CACHE_SIZE/BITS_PER_LONG)
153 #define BTOPR(b) (((unsigned int)(b) + (NBPPR - 1)) >> PRSHIFT)
154 #define BTOPRT(b) (((unsigned int)(b) >> PRSHIFT))
164 first = BTOPR(offset);
165 final = BTOPRT(offset + length - 1);
166 first = min(first, final);
169 mask <<= BITS_PER_LONG - (final - first);
170 mask >>= BITS_PER_LONG - (final);
172 ASSERT(offset + length <= PAGE_CACHE_SIZE);
173 ASSERT((final - first) < BITS_PER_LONG && (final - first) >= 0);
184 set_page_private(page,
185 page_private(page) | page_region_mask(offset, length));
186 if (page_private(page) == ~0UL)
187 SetPageUptodate(page);
196 unsigned long mask = page_region_mask(offset, length);
198 return (mask && (page_private(page) & mask) == mask);
202 * Mapping of multi-page buffers into contiguous virtual space
205 typedef struct a_list {
210 STATIC a_list_t *as_free_head;
211 STATIC int as_list_len;
212 STATIC DEFINE_SPINLOCK(as_lock);
215 * Try to batch vunmaps because they are costly.
223 aentry = kmalloc(sizeof(a_list_t), GFP_ATOMIC & ~__GFP_HIGH);
224 if (likely(aentry)) {
226 aentry->next = as_free_head;
227 aentry->vm_addr = addr;
228 as_free_head = aentry;
230 spin_unlock(&as_lock);
237 purge_addresses(void)
239 a_list_t *aentry, *old;
241 if (as_free_head == NULL)
245 aentry = as_free_head;
248 spin_unlock(&as_lock);
250 while ((old = aentry) != NULL) {
251 vunmap(aentry->vm_addr);
252 aentry = aentry->next;
258 * Internal pagebuf object manipulation
264 xfs_buftarg_t *target,
267 page_buf_flags_t flags)
270 * We don't want certain flags to appear in pb->pb_flags.
272 flags &= ~(PBF_LOCK|PBF_MAPPED|PBF_DONT_BLOCK|PBF_READ_AHEAD);
274 memset(pb, 0, sizeof(xfs_buf_t));
275 atomic_set(&pb->pb_hold, 1);
276 init_MUTEX_LOCKED(&pb->pb_iodonesema);
277 INIT_LIST_HEAD(&pb->pb_list);
278 INIT_LIST_HEAD(&pb->pb_hash_list);
279 init_MUTEX_LOCKED(&pb->pb_sema); /* held, no waiters */
281 pb->pb_target = target;
282 pb->pb_file_offset = range_base;
284 * Set buffer_length and count_desired to the same value initially.
285 * I/O routines should use count_desired, which will be the same in
286 * most cases but may be reset (e.g. XFS recovery).
288 pb->pb_buffer_length = pb->pb_count_desired = range_length;
289 pb->pb_flags = flags | PBF_NONE;
290 pb->pb_bn = XFS_BUF_DADDR_NULL;
291 atomic_set(&pb->pb_pin_count, 0);
292 init_waitqueue_head(&pb->pb_waiters);
294 XFS_STATS_INC(pb_create);
295 PB_TRACE(pb, "initialize", target);
299 * Allocate a page array capable of holding a specified number
300 * of pages, and point the page buf at it.
306 page_buf_flags_t flags)
308 /* Make sure that we have a page list */
309 if (pb->pb_pages == NULL) {
310 pb->pb_offset = page_buf_poff(pb->pb_file_offset);
311 pb->pb_page_count = page_count;
312 if (page_count <= PB_PAGES) {
313 pb->pb_pages = pb->pb_page_array;
315 pb->pb_pages = kmem_alloc(sizeof(struct page *) *
316 page_count, pb_to_km(flags));
317 if (pb->pb_pages == NULL)
320 memset(pb->pb_pages, 0, sizeof(struct page *) * page_count);
326 * Frees pb_pages if it was malloced.
332 if (bp->pb_pages != bp->pb_page_array) {
333 kmem_free(bp->pb_pages,
334 bp->pb_page_count * sizeof(struct page *));
339 * Releases the specified buffer.
341 * The modification state of any associated pages is left unchanged.
342 * The buffer most not be on any hash - use pagebuf_rele instead for
343 * hashed and refcounted buffers
349 PB_TRACE(bp, "free", 0);
351 ASSERT(list_empty(&bp->pb_hash_list));
353 if (bp->pb_flags & _PBF_PAGE_CACHE) {
356 if ((bp->pb_flags & PBF_MAPPED) && (bp->pb_page_count > 1))
357 free_address(bp->pb_addr - bp->pb_offset);
359 for (i = 0; i < bp->pb_page_count; i++)
360 page_cache_release(bp->pb_pages[i]);
361 _pagebuf_free_pages(bp);
362 } else if (bp->pb_flags & _PBF_KMEM_ALLOC) {
364 * XXX(hch): bp->pb_count_desired might be incorrect (see
365 * pagebuf_associate_memory for details), but fortunately
366 * the Linux version of kmem_free ignores the len argument..
368 kmem_free(bp->pb_addr, bp->pb_count_desired);
369 _pagebuf_free_pages(bp);
372 pagebuf_deallocate(bp);
376 * Finds all pages for buffer in question and builds it's page list.
379 _pagebuf_lookup_pages(
383 struct address_space *mapping = bp->pb_target->pbr_mapping;
384 size_t blocksize = bp->pb_target->pbr_bsize;
385 size_t size = bp->pb_count_desired;
386 size_t nbytes, offset;
387 gfp_t gfp_mask = pb_to_gfp(flags);
388 unsigned short page_count, i;
393 end = bp->pb_file_offset + bp->pb_buffer_length;
394 page_count = page_buf_btoc(end) - page_buf_btoct(bp->pb_file_offset);
396 error = _pagebuf_get_pages(bp, page_count, flags);
399 bp->pb_flags |= _PBF_PAGE_CACHE;
401 offset = bp->pb_offset;
402 first = bp->pb_file_offset >> PAGE_CACHE_SHIFT;
404 for (i = 0; i < bp->pb_page_count; i++) {
409 page = find_or_create_page(mapping, first + i, gfp_mask);
410 if (unlikely(page == NULL)) {
411 if (flags & PBF_READ_AHEAD) {
412 bp->pb_page_count = i;
413 for (i = 0; i < bp->pb_page_count; i++)
414 unlock_page(bp->pb_pages[i]);
419 * This could deadlock.
421 * But until all the XFS lowlevel code is revamped to
422 * handle buffer allocation failures we can't do much.
424 if (!(++retries % 100))
426 "XFS: possible memory allocation "
427 "deadlock in %s (mode:0x%x)\n",
428 __FUNCTION__, gfp_mask);
430 XFS_STATS_INC(pb_page_retries);
431 xfsbufd_wakeup(0, gfp_mask);
432 blk_congestion_wait(WRITE, HZ/50);
436 XFS_STATS_INC(pb_page_found);
438 nbytes = min_t(size_t, size, PAGE_CACHE_SIZE - offset);
441 if (!PageUptodate(page)) {
443 if (blocksize >= PAGE_CACHE_SIZE) {
444 if (flags & PBF_READ)
446 } else if (!PagePrivate(page)) {
447 if (test_page_region(page, offset, nbytes))
452 bp->pb_pages[i] = page;
456 if (!bp->pb_locked) {
457 for (i = 0; i < bp->pb_page_count; i++)
458 unlock_page(bp->pb_pages[i]);
462 bp->pb_flags &= ~PBF_NONE;
464 PB_TRACE(bp, "lookup_pages", (long)page_count);
469 * Map buffer into kernel address-space if nessecary.
476 /* A single page buffer is always mappable */
477 if (bp->pb_page_count == 1) {
478 bp->pb_addr = page_address(bp->pb_pages[0]) + bp->pb_offset;
479 bp->pb_flags |= PBF_MAPPED;
480 } else if (flags & PBF_MAPPED) {
481 if (as_list_len > 64)
483 bp->pb_addr = vmap(bp->pb_pages, bp->pb_page_count,
484 VM_MAP, PAGE_KERNEL);
485 if (unlikely(bp->pb_addr == NULL))
487 bp->pb_addr += bp->pb_offset;
488 bp->pb_flags |= PBF_MAPPED;
495 * Finding and Reading Buffers
501 * Looks up, and creates if absent, a lockable buffer for
502 * a given range of an inode. The buffer is returned
503 * locked. If other overlapping buffers exist, they are
504 * released before the new buffer is created and locked,
505 * which may imply that this call will block until those buffers
506 * are unlocked. No I/O is implied by this call.
510 xfs_buftarg_t *btp, /* block device target */
511 loff_t ioff, /* starting offset of range */
512 size_t isize, /* length of range */
513 page_buf_flags_t flags, /* PBF_TRYLOCK */
514 xfs_buf_t *new_pb)/* newly allocated buffer */
521 range_base = (ioff << BBSHIFT);
522 range_length = (isize << BBSHIFT);
524 /* Check for IOs smaller than the sector size / not sector aligned */
525 ASSERT(!(range_length < (1 << btp->pbr_sshift)));
526 ASSERT(!(range_base & (loff_t)btp->pbr_smask));
528 hash = &btp->bt_hash[hash_long((unsigned long)ioff, btp->bt_hashshift)];
530 spin_lock(&hash->bh_lock);
532 list_for_each_entry_safe(pb, n, &hash->bh_list, pb_hash_list) {
533 ASSERT(btp == pb->pb_target);
534 if (pb->pb_file_offset == range_base &&
535 pb->pb_buffer_length == range_length) {
537 * If we look at something bring it to the
538 * front of the list for next time.
540 atomic_inc(&pb->pb_hold);
541 list_move(&pb->pb_hash_list, &hash->bh_list);
548 _pagebuf_initialize(new_pb, btp, range_base,
549 range_length, flags);
550 new_pb->pb_hash = hash;
551 list_add(&new_pb->pb_hash_list, &hash->bh_list);
553 XFS_STATS_INC(pb_miss_locked);
556 spin_unlock(&hash->bh_lock);
560 spin_unlock(&hash->bh_lock);
562 /* Attempt to get the semaphore without sleeping,
563 * if this does not work then we need to drop the
564 * spinlock and do a hard attempt on the semaphore.
566 if (down_trylock(&pb->pb_sema)) {
567 if (!(flags & PBF_TRYLOCK)) {
568 /* wait for buffer ownership */
569 PB_TRACE(pb, "get_lock", 0);
571 XFS_STATS_INC(pb_get_locked_waited);
573 /* We asked for a trylock and failed, no need
574 * to look at file offset and length here, we
575 * know that this pagebuf at least overlaps our
576 * pagebuf and is locked, therefore our buffer
577 * either does not exist, or is this buffer
581 XFS_STATS_INC(pb_busy_locked);
589 if (pb->pb_flags & PBF_STALE) {
590 ASSERT((pb->pb_flags & _PBF_DELWRI_Q) == 0);
591 pb->pb_flags &= PBF_MAPPED;
593 PB_TRACE(pb, "got_lock", 0);
594 XFS_STATS_INC(pb_get_locked);
599 * xfs_buf_get_flags assembles a buffer covering the specified range.
601 * Storage in memory for all portions of the buffer will be allocated,
602 * although backing storage may not be.
605 xfs_buf_get_flags( /* allocate a buffer */
606 xfs_buftarg_t *target,/* target for buffer */
607 loff_t ioff, /* starting offset of range */
608 size_t isize, /* length of range */
609 page_buf_flags_t flags) /* PBF_TRYLOCK */
611 xfs_buf_t *pb, *new_pb;
614 new_pb = pagebuf_allocate(flags);
615 if (unlikely(!new_pb))
618 pb = _pagebuf_find(target, ioff, isize, flags, new_pb);
620 error = _pagebuf_lookup_pages(pb, flags);
624 pagebuf_deallocate(new_pb);
625 if (unlikely(pb == NULL))
629 for (i = 0; i < pb->pb_page_count; i++)
630 mark_page_accessed(pb->pb_pages[i]);
632 if (!(pb->pb_flags & PBF_MAPPED)) {
633 error = _pagebuf_map_pages(pb, flags);
634 if (unlikely(error)) {
635 printk(KERN_WARNING "%s: failed to map pages\n",
641 XFS_STATS_INC(pb_get);
644 * Always fill in the block number now, the mapped cases can do
645 * their own overlay of this later.
648 pb->pb_count_desired = pb->pb_buffer_length;
650 PB_TRACE(pb, "get", (unsigned long)flags);
654 if (flags & (PBF_LOCK | PBF_TRYLOCK))
662 xfs_buftarg_t *target,
665 page_buf_flags_t flags)
671 pb = xfs_buf_get_flags(target, ioff, isize, flags);
673 if (!XFS_BUF_ISDONE(pb)) {
674 PB_TRACE(pb, "read", (unsigned long)flags);
675 XFS_STATS_INC(pb_get_read);
676 pagebuf_iostart(pb, flags);
677 } else if (flags & PBF_ASYNC) {
678 PB_TRACE(pb, "read_async", (unsigned long)flags);
680 * Read ahead call which is already satisfied,
685 PB_TRACE(pb, "read_done", (unsigned long)flags);
686 /* We do not want read in the flags */
687 pb->pb_flags &= ~PBF_READ;
694 if (flags & (PBF_LOCK | PBF_TRYLOCK))
701 * If we are not low on memory then do the readahead in a deadlock
706 xfs_buftarg_t *target,
709 page_buf_flags_t flags)
711 struct backing_dev_info *bdi;
713 bdi = target->pbr_mapping->backing_dev_info;
714 if (bdi_read_congested(bdi))
717 flags |= (PBF_TRYLOCK|PBF_ASYNC|PBF_READ_AHEAD);
718 xfs_buf_read_flags(target, ioff, isize, flags);
724 xfs_buftarg_t *target)
728 pb = pagebuf_allocate(0);
730 _pagebuf_initialize(pb, target, 0, len, 0);
734 static inline struct page *
738 if (((unsigned long)addr < VMALLOC_START) ||
739 ((unsigned long)addr >= VMALLOC_END)) {
740 return virt_to_page(addr);
742 return vmalloc_to_page(addr);
747 pagebuf_associate_memory(
759 page_count = PAGE_CACHE_ALIGN(len) >> PAGE_CACHE_SHIFT;
760 offset = (off_t) mem - ((off_t)mem & PAGE_CACHE_MASK);
761 if (offset && (len > PAGE_CACHE_SIZE))
764 /* Free any previous set of page pointers */
766 _pagebuf_free_pages(pb);
771 rval = _pagebuf_get_pages(pb, page_count, 0);
775 pb->pb_offset = offset;
776 ptr = (size_t) mem & PAGE_CACHE_MASK;
777 end = PAGE_CACHE_ALIGN((size_t) mem + len);
779 /* set up first page */
780 pb->pb_pages[0] = mem_to_page(mem);
782 ptr += PAGE_CACHE_SIZE;
783 pb->pb_page_count = ++i;
785 pb->pb_pages[i] = mem_to_page((void *)ptr);
786 pb->pb_page_count = ++i;
787 ptr += PAGE_CACHE_SIZE;
791 pb->pb_count_desired = pb->pb_buffer_length = len;
792 pb->pb_flags |= PBF_MAPPED;
798 pagebuf_get_no_daddr(
800 xfs_buftarg_t *target)
802 size_t malloc_len = len;
807 bp = pagebuf_allocate(0);
808 if (unlikely(bp == NULL))
810 _pagebuf_initialize(bp, target, 0, len, 0);
813 data = kmem_alloc(malloc_len, KM_SLEEP | KM_MAYFAIL);
814 if (unlikely(data == NULL))
817 /* check whether alignment matches.. */
818 if ((__psunsigned_t)data !=
819 ((__psunsigned_t)data & ~target->pbr_smask)) {
820 /* .. else double the size and try again */
821 kmem_free(data, malloc_len);
826 error = pagebuf_associate_memory(bp, data, len);
829 bp->pb_flags |= _PBF_KMEM_ALLOC;
833 PB_TRACE(bp, "no_daddr", data);
836 kmem_free(data, malloc_len);
846 * Increment reference count on buffer, to hold the buffer concurrently
847 * with another thread which may release (free) the buffer asynchronously.
849 * Must hold the buffer already to call this function.
855 atomic_inc(&pb->pb_hold);
856 PB_TRACE(pb, "hold", 0);
862 * pagebuf_rele releases a hold on the specified buffer. If the
863 * the hold count is 1, pagebuf_rele calls pagebuf_free.
869 xfs_bufhash_t *hash = pb->pb_hash;
871 PB_TRACE(pb, "rele", pb->pb_relse);
874 * pagebuf_lookup buffers are not hashed, not delayed write,
875 * and don't have their own release routines. Special case.
877 if (unlikely(!hash)) {
878 ASSERT(!pb->pb_relse);
879 if (atomic_dec_and_test(&pb->pb_hold))
884 if (atomic_dec_and_lock(&pb->pb_hold, &hash->bh_lock)) {
888 atomic_inc(&pb->pb_hold);
889 spin_unlock(&hash->bh_lock);
890 (*(pb->pb_relse)) (pb);
891 spin_lock(&hash->bh_lock);
895 if (pb->pb_flags & PBF_FS_MANAGED) {
900 ASSERT((pb->pb_flags & (PBF_DELWRI|_PBF_DELWRI_Q)) == 0);
901 list_del_init(&pb->pb_hash_list);
902 spin_unlock(&hash->bh_lock);
905 spin_unlock(&hash->bh_lock);
909 * Catch reference count leaks
911 ASSERT(atomic_read(&pb->pb_hold) >= 0);
917 * Mutual exclusion on buffers. Locking model:
919 * Buffers associated with inodes for which buffer locking
920 * is not enabled are not protected by semaphores, and are
921 * assumed to be exclusively owned by the caller. There is a
922 * spinlock in the buffer, used by the caller when concurrent
923 * access is possible.
929 * pagebuf_cond_lock locks a buffer object, if it is not already locked.
930 * Note that this in no way
931 * locks the underlying pages, so it is only useful for synchronizing
932 * concurrent use of page buffer objects, not for synchronizing independent
933 * access to the underlying pages.
936 pagebuf_cond_lock( /* lock buffer, if not locked */
937 /* returns -EBUSY if locked) */
942 locked = down_trylock(&pb->pb_sema) == 0;
946 PB_TRACE(pb, "cond_lock", (long)locked);
947 return(locked ? 0 : -EBUSY);
950 #if defined(DEBUG) || defined(XFS_BLI_TRACE)
954 * Return lock value for a pagebuf
960 return(atomic_read(&pb->pb_sema.count));
967 * pagebuf_lock locks a buffer object. Note that this in no way
968 * locks the underlying pages, so it is only useful for synchronizing
969 * concurrent use of page buffer objects, not for synchronizing independent
970 * access to the underlying pages.
976 PB_TRACE(pb, "lock", 0);
977 if (atomic_read(&pb->pb_io_remaining))
978 blk_run_address_space(pb->pb_target->pbr_mapping);
981 PB_TRACE(pb, "locked", 0);
988 * pagebuf_unlock releases the lock on the buffer object created by
989 * pagebuf_lock or pagebuf_cond_lock (not any pinning of underlying pages
990 * created by pagebuf_pin).
992 * If the buffer is marked delwri but is not queued, do so before we
993 * unlock the buffer as we need to set flags correctly. We also need to
994 * take a reference for the delwri queue because the unlocker is going to
995 * drop their's and they don't know we just queued it.
998 pagebuf_unlock( /* unlock buffer */
999 xfs_buf_t *pb) /* buffer to unlock */
1001 if ((pb->pb_flags & (PBF_DELWRI|_PBF_DELWRI_Q)) == PBF_DELWRI) {
1002 atomic_inc(&pb->pb_hold);
1003 pb->pb_flags |= PBF_ASYNC;
1004 pagebuf_delwri_queue(pb, 0);
1009 PB_TRACE(pb, "unlock", 0);
1014 * Pinning Buffer Storage in Memory
1020 * pagebuf_pin locks all of the memory represented by a buffer in
1021 * memory. Multiple calls to pagebuf_pin and pagebuf_unpin, for
1022 * the same or different buffers affecting a given page, will
1023 * properly count the number of outstanding "pin" requests. The
1024 * buffer may be released after the pagebuf_pin and a different
1025 * buffer used when calling pagebuf_unpin, if desired.
1026 * pagebuf_pin should be used by the file system when it wants be
1027 * assured that no attempt will be made to force the affected
1028 * memory to disk. It does not assure that a given logical page
1029 * will not be moved to a different physical page.
1035 atomic_inc(&pb->pb_pin_count);
1036 PB_TRACE(pb, "pin", (long)pb->pb_pin_count.counter);
1042 * pagebuf_unpin reverses the locking of memory performed by
1043 * pagebuf_pin. Note that both functions affected the logical
1044 * pages associated with the buffer, not the buffer itself.
1050 if (atomic_dec_and_test(&pb->pb_pin_count)) {
1051 wake_up_all(&pb->pb_waiters);
1053 PB_TRACE(pb, "unpin", (long)pb->pb_pin_count.counter);
1060 return atomic_read(&pb->pb_pin_count);
1064 * pagebuf_wait_unpin
1066 * pagebuf_wait_unpin waits until all of the memory associated
1067 * with the buffer is not longer locked in memory. It returns
1068 * immediately if none of the affected pages are locked.
1071 _pagebuf_wait_unpin(
1074 DECLARE_WAITQUEUE (wait, current);
1076 if (atomic_read(&pb->pb_pin_count) == 0)
1079 add_wait_queue(&pb->pb_waiters, &wait);
1081 set_current_state(TASK_UNINTERRUPTIBLE);
1082 if (atomic_read(&pb->pb_pin_count) == 0)
1084 if (atomic_read(&pb->pb_io_remaining))
1085 blk_run_address_space(pb->pb_target->pbr_mapping);
1088 remove_wait_queue(&pb->pb_waiters, &wait);
1089 set_current_state(TASK_RUNNING);
1093 * Buffer Utility Routines
1099 * pagebuf_iodone marks a buffer for which I/O is in progress
1100 * done with respect to that I/O. The pb_iodone routine, if
1101 * present, will be called as a side-effect.
1104 pagebuf_iodone_work(
1107 xfs_buf_t *bp = (xfs_buf_t *)v;
1110 (*(bp->pb_iodone))(bp);
1111 else if (bp->pb_flags & PBF_ASYNC)
1120 pb->pb_flags &= ~(PBF_READ | PBF_WRITE);
1121 if (pb->pb_error == 0)
1122 pb->pb_flags &= ~PBF_NONE;
1124 PB_TRACE(pb, "iodone", pb->pb_iodone);
1126 if ((pb->pb_iodone) || (pb->pb_flags & PBF_ASYNC)) {
1128 INIT_WORK(&pb->pb_iodone_work, pagebuf_iodone_work, pb);
1129 queue_work(xfslogd_workqueue, &pb->pb_iodone_work);
1131 pagebuf_iodone_work(pb);
1134 up(&pb->pb_iodonesema);
1141 * pagebuf_ioerror sets the error code for a buffer.
1144 pagebuf_ioerror( /* mark/clear buffer error flag */
1145 xfs_buf_t *pb, /* buffer to mark */
1146 int error) /* error to store (0 if none) */
1148 ASSERT(error >= 0 && error <= 0xffff);
1149 pb->pb_error = (unsigned short)error;
1150 PB_TRACE(pb, "ioerror", (unsigned long)error);
1156 * pagebuf_iostart initiates I/O on a buffer, based on the flags supplied.
1157 * If necessary, it will arrange for any disk space allocation required,
1158 * and it will break up the request if the block mappings require it.
1159 * The pb_iodone routine in the buffer supplied will only be called
1160 * when all of the subsidiary I/O requests, if any, have been completed.
1161 * pagebuf_iostart calls the pagebuf_ioinitiate routine or
1162 * pagebuf_iorequest, if the former routine is not defined, to start
1163 * the I/O on a given low-level request.
1166 pagebuf_iostart( /* start I/O on a buffer */
1167 xfs_buf_t *pb, /* buffer to start */
1168 page_buf_flags_t flags) /* PBF_LOCK, PBF_ASYNC, PBF_READ, */
1169 /* PBF_WRITE, PBF_DELWRI, */
1170 /* PBF_DONT_BLOCK */
1174 PB_TRACE(pb, "iostart", (unsigned long)flags);
1176 if (flags & PBF_DELWRI) {
1177 pb->pb_flags &= ~(PBF_READ | PBF_WRITE | PBF_ASYNC);
1178 pb->pb_flags |= flags & (PBF_DELWRI | PBF_ASYNC);
1179 pagebuf_delwri_queue(pb, 1);
1183 pb->pb_flags &= ~(PBF_READ | PBF_WRITE | PBF_ASYNC | PBF_DELWRI | \
1184 PBF_READ_AHEAD | _PBF_RUN_QUEUES);
1185 pb->pb_flags |= flags & (PBF_READ | PBF_WRITE | PBF_ASYNC | \
1186 PBF_READ_AHEAD | _PBF_RUN_QUEUES);
1188 BUG_ON(pb->pb_bn == XFS_BUF_DADDR_NULL);
1190 /* For writes allow an alternate strategy routine to precede
1191 * the actual I/O request (which may not be issued at all in
1192 * a shutdown situation, for example).
1194 status = (flags & PBF_WRITE) ?
1195 pagebuf_iostrategy(pb) : pagebuf_iorequest(pb);
1197 /* Wait for I/O if we are not an async request.
1198 * Note: async I/O request completion will release the buffer,
1199 * and that can already be done by this point. So using the
1200 * buffer pointer from here on, after async I/O, is invalid.
1202 if (!status && !(flags & PBF_ASYNC))
1203 status = pagebuf_iowait(pb);
1209 * Helper routine for pagebuf_iorequest
1212 STATIC __inline__ int
1216 ASSERT(pb->pb_flags & (PBF_READ|PBF_WRITE));
1217 if (pb->pb_flags & PBF_READ)
1218 return pb->pb_locked;
1222 STATIC __inline__ void
1227 if (atomic_dec_and_test(&pb->pb_io_remaining) == 1) {
1229 pagebuf_iodone(pb, schedule);
1236 unsigned int bytes_done,
1239 xfs_buf_t *pb = (xfs_buf_t *)bio->bi_private;
1240 unsigned int blocksize = pb->pb_target->pbr_bsize;
1241 struct bio_vec *bvec = bio->bi_io_vec + bio->bi_vcnt - 1;
1246 if (!test_bit(BIO_UPTODATE, &bio->bi_flags))
1250 struct page *page = bvec->bv_page;
1252 if (unlikely(pb->pb_error)) {
1253 if (pb->pb_flags & PBF_READ)
1254 ClearPageUptodate(page);
1256 } else if (blocksize == PAGE_CACHE_SIZE) {
1257 SetPageUptodate(page);
1258 } else if (!PagePrivate(page) &&
1259 (pb->pb_flags & _PBF_PAGE_CACHE)) {
1260 set_page_region(page, bvec->bv_offset, bvec->bv_len);
1263 if (--bvec >= bio->bi_io_vec)
1264 prefetchw(&bvec->bv_page->flags);
1266 if (_pagebuf_iolocked(pb)) {
1269 } while (bvec >= bio->bi_io_vec);
1271 _pagebuf_iodone(pb, 1);
1280 int i, rw, map_i, total_nr_pages, nr_pages;
1282 int offset = pb->pb_offset;
1283 int size = pb->pb_count_desired;
1284 sector_t sector = pb->pb_bn;
1285 unsigned int blocksize = pb->pb_target->pbr_bsize;
1286 int locking = _pagebuf_iolocked(pb);
1288 total_nr_pages = pb->pb_page_count;
1291 if (pb->pb_flags & _PBF_RUN_QUEUES) {
1292 pb->pb_flags &= ~_PBF_RUN_QUEUES;
1293 rw = (pb->pb_flags & PBF_READ) ? READ_SYNC : WRITE_SYNC;
1295 rw = (pb->pb_flags & PBF_READ) ? READ : WRITE;
1298 /* Special code path for reading a sub page size pagebuf in --
1299 * we populate up the whole page, and hence the other metadata
1300 * in the same page. This optimization is only valid when the
1301 * filesystem block size and the page size are equal.
1303 if ((pb->pb_buffer_length < PAGE_CACHE_SIZE) &&
1304 (pb->pb_flags & PBF_READ) && locking &&
1305 (blocksize == PAGE_CACHE_SIZE)) {
1306 bio = bio_alloc(GFP_NOIO, 1);
1308 bio->bi_bdev = pb->pb_target->pbr_bdev;
1309 bio->bi_sector = sector - (offset >> BBSHIFT);
1310 bio->bi_end_io = bio_end_io_pagebuf;
1311 bio->bi_private = pb;
1313 bio_add_page(bio, pb->pb_pages[0], PAGE_CACHE_SIZE, 0);
1316 atomic_inc(&pb->pb_io_remaining);
1321 /* Lock down the pages which we need to for the request */
1322 if (locking && (pb->pb_flags & PBF_WRITE) && (pb->pb_locked == 0)) {
1323 for (i = 0; size; i++) {
1324 int nbytes = PAGE_CACHE_SIZE - offset;
1325 struct page *page = pb->pb_pages[i];
1335 offset = pb->pb_offset;
1336 size = pb->pb_count_desired;
1340 atomic_inc(&pb->pb_io_remaining);
1341 nr_pages = BIO_MAX_SECTORS >> (PAGE_SHIFT - BBSHIFT);
1342 if (nr_pages > total_nr_pages)
1343 nr_pages = total_nr_pages;
1345 bio = bio_alloc(GFP_NOIO, nr_pages);
1346 bio->bi_bdev = pb->pb_target->pbr_bdev;
1347 bio->bi_sector = sector;
1348 bio->bi_end_io = bio_end_io_pagebuf;
1349 bio->bi_private = pb;
1351 for (; size && nr_pages; nr_pages--, map_i++) {
1352 int nbytes = PAGE_CACHE_SIZE - offset;
1357 if (bio_add_page(bio, pb->pb_pages[map_i],
1358 nbytes, offset) < nbytes)
1362 sector += nbytes >> BBSHIFT;
1368 if (likely(bio->bi_size)) {
1369 submit_bio(rw, bio);
1374 pagebuf_ioerror(pb, EIO);
1379 * pagebuf_iorequest -- the core I/O request routine.
1382 pagebuf_iorequest( /* start real I/O */
1383 xfs_buf_t *pb) /* buffer to convey to device */
1385 PB_TRACE(pb, "iorequest", 0);
1387 if (pb->pb_flags & PBF_DELWRI) {
1388 pagebuf_delwri_queue(pb, 1);
1392 if (pb->pb_flags & PBF_WRITE) {
1393 _pagebuf_wait_unpin(pb);
1398 /* Set the count to 1 initially, this will stop an I/O
1399 * completion callout which happens before we have started
1400 * all the I/O from calling pagebuf_iodone too early.
1402 atomic_set(&pb->pb_io_remaining, 1);
1403 _pagebuf_ioapply(pb);
1404 _pagebuf_iodone(pb, 0);
1413 * pagebuf_iowait waits for I/O to complete on the buffer supplied.
1414 * It returns immediately if no I/O is pending. In any case, it returns
1415 * the error code, if any, or 0 if there is no error.
1421 PB_TRACE(pb, "iowait", 0);
1422 if (atomic_read(&pb->pb_io_remaining))
1423 blk_run_address_space(pb->pb_target->pbr_mapping);
1424 down(&pb->pb_iodonesema);
1425 PB_TRACE(pb, "iowaited", (long)pb->pb_error);
1426 return pb->pb_error;
1436 offset += pb->pb_offset;
1438 page = pb->pb_pages[offset >> PAGE_CACHE_SHIFT];
1439 return (caddr_t) page_address(page) + (offset & (PAGE_CACHE_SIZE - 1));
1445 * Move data into or out of a buffer.
1449 xfs_buf_t *pb, /* buffer to process */
1450 size_t boff, /* starting buffer offset */
1451 size_t bsize, /* length to copy */
1452 caddr_t data, /* data address */
1453 page_buf_rw_t mode) /* read/write flag */
1455 size_t bend, cpoff, csize;
1458 bend = boff + bsize;
1459 while (boff < bend) {
1460 page = pb->pb_pages[page_buf_btoct(boff + pb->pb_offset)];
1461 cpoff = page_buf_poff(boff + pb->pb_offset);
1462 csize = min_t(size_t,
1463 PAGE_CACHE_SIZE-cpoff, pb->pb_count_desired-boff);
1465 ASSERT(((csize + cpoff) <= PAGE_CACHE_SIZE));
1469 memset(page_address(page) + cpoff, 0, csize);
1472 memcpy(data, page_address(page) + cpoff, csize);
1475 memcpy(page_address(page) + cpoff, data, csize);
1484 * Handling of buftargs.
1488 * Wait for any bufs with callbacks that have been submitted but
1489 * have not yet returned... walk the hash list for the target.
1496 xfs_bufhash_t *hash;
1499 for (i = 0; i < (1 << btp->bt_hashshift); i++) {
1500 hash = &btp->bt_hash[i];
1502 spin_lock(&hash->bh_lock);
1503 list_for_each_entry_safe(bp, n, &hash->bh_list, pb_hash_list) {
1504 ASSERT(btp == bp->pb_target);
1505 if (!(bp->pb_flags & PBF_FS_MANAGED)) {
1506 spin_unlock(&hash->bh_lock);
1508 * Catch superblock reference count leaks
1511 BUG_ON(bp->pb_bn == 0);
1516 spin_unlock(&hash->bh_lock);
1521 * Allocate buffer hash table for a given target.
1522 * For devices containing metadata (i.e. not the log/realtime devices)
1523 * we need to allocate a much larger hash table.
1532 btp->bt_hashshift = external ? 3 : 8; /* 8 or 256 buckets */
1533 btp->bt_hashmask = (1 << btp->bt_hashshift) - 1;
1534 btp->bt_hash = kmem_zalloc((1 << btp->bt_hashshift) *
1535 sizeof(xfs_bufhash_t), KM_SLEEP);
1536 for (i = 0; i < (1 << btp->bt_hashshift); i++) {
1537 spin_lock_init(&btp->bt_hash[i].bh_lock);
1538 INIT_LIST_HEAD(&btp->bt_hash[i].bh_list);
1546 kmem_free(btp->bt_hash,
1547 (1 << btp->bt_hashshift) * sizeof(xfs_bufhash_t));
1548 btp->bt_hash = NULL;
1556 xfs_flush_buftarg(btp, 1);
1558 xfs_blkdev_put(btp->pbr_bdev);
1559 xfs_free_bufhash(btp);
1560 iput(btp->pbr_mapping->host);
1561 kmem_free(btp, sizeof(*btp));
1565 xfs_setsize_buftarg_flags(
1567 unsigned int blocksize,
1568 unsigned int sectorsize,
1571 btp->pbr_bsize = blocksize;
1572 btp->pbr_sshift = ffs(sectorsize) - 1;
1573 btp->pbr_smask = sectorsize - 1;
1575 if (set_blocksize(btp->pbr_bdev, sectorsize)) {
1577 "XFS: Cannot set_blocksize to %u on device %s\n",
1578 sectorsize, XFS_BUFTARG_NAME(btp));
1583 (PAGE_CACHE_SIZE / BITS_PER_LONG) > sectorsize) {
1585 "XFS: %u byte sectors in use on device %s. "
1586 "This is suboptimal; %u or greater is ideal.\n",
1587 sectorsize, XFS_BUFTARG_NAME(btp),
1588 (unsigned int)PAGE_CACHE_SIZE / BITS_PER_LONG);
1595 * When allocating the initial buffer target we have not yet
1596 * read in the superblock, so don't know what sized sectors
1597 * are being used is at this early stage. Play safe.
1600 xfs_setsize_buftarg_early(
1602 struct block_device *bdev)
1604 return xfs_setsize_buftarg_flags(btp,
1605 PAGE_CACHE_SIZE, bdev_hardsect_size(bdev), 0);
1609 xfs_setsize_buftarg(
1611 unsigned int blocksize,
1612 unsigned int sectorsize)
1614 return xfs_setsize_buftarg_flags(btp, blocksize, sectorsize, 1);
1618 xfs_mapping_buftarg(
1620 struct block_device *bdev)
1622 struct backing_dev_info *bdi;
1623 struct inode *inode;
1624 struct address_space *mapping;
1625 static struct address_space_operations mapping_aops = {
1626 .sync_page = block_sync_page,
1629 inode = new_inode(bdev->bd_inode->i_sb);
1632 "XFS: Cannot allocate mapping inode for device %s\n",
1633 XFS_BUFTARG_NAME(btp));
1636 inode->i_mode = S_IFBLK;
1637 inode->i_bdev = bdev;
1638 inode->i_rdev = bdev->bd_dev;
1639 bdi = blk_get_backing_dev_info(bdev);
1641 bdi = &default_backing_dev_info;
1642 mapping = &inode->i_data;
1643 mapping->a_ops = &mapping_aops;
1644 mapping->backing_dev_info = bdi;
1645 mapping_set_gfp_mask(mapping, GFP_NOFS);
1646 btp->pbr_mapping = mapping;
1652 struct block_device *bdev,
1657 btp = kmem_zalloc(sizeof(*btp), KM_SLEEP);
1659 btp->pbr_dev = bdev->bd_dev;
1660 btp->pbr_bdev = bdev;
1661 if (xfs_setsize_buftarg_early(btp, bdev))
1663 if (xfs_mapping_buftarg(btp, bdev))
1665 xfs_alloc_bufhash(btp, external);
1669 kmem_free(btp, sizeof(*btp));
1675 * Pagebuf delayed write buffer handling
1678 STATIC LIST_HEAD(pbd_delwrite_queue);
1679 STATIC DEFINE_SPINLOCK(pbd_delwrite_lock);
1682 pagebuf_delwri_queue(
1686 PB_TRACE(pb, "delwri_q", (long)unlock);
1687 ASSERT((pb->pb_flags & (PBF_DELWRI|PBF_ASYNC)) ==
1688 (PBF_DELWRI|PBF_ASYNC));
1690 spin_lock(&pbd_delwrite_lock);
1691 /* If already in the queue, dequeue and place at tail */
1692 if (!list_empty(&pb->pb_list)) {
1693 ASSERT(pb->pb_flags & _PBF_DELWRI_Q);
1695 atomic_dec(&pb->pb_hold);
1697 list_del(&pb->pb_list);
1700 pb->pb_flags |= _PBF_DELWRI_Q;
1701 list_add_tail(&pb->pb_list, &pbd_delwrite_queue);
1702 pb->pb_queuetime = jiffies;
1703 spin_unlock(&pbd_delwrite_lock);
1710 pagebuf_delwri_dequeue(
1715 spin_lock(&pbd_delwrite_lock);
1716 if ((pb->pb_flags & PBF_DELWRI) && !list_empty(&pb->pb_list)) {
1717 ASSERT(pb->pb_flags & _PBF_DELWRI_Q);
1718 list_del_init(&pb->pb_list);
1721 pb->pb_flags &= ~(PBF_DELWRI|_PBF_DELWRI_Q);
1722 spin_unlock(&pbd_delwrite_lock);
1727 PB_TRACE(pb, "delwri_dq", (long)dequeued);
1731 pagebuf_runall_queues(
1732 struct workqueue_struct *queue)
1734 flush_workqueue(queue);
1737 /* Defines for pagebuf daemon */
1738 STATIC struct task_struct *xfsbufd_task;
1739 STATIC int xfsbufd_force_flush;
1740 STATIC int xfsbufd_force_sleep;
1747 if (xfsbufd_force_sleep)
1749 xfsbufd_force_flush = 1;
1751 wake_up_process(xfsbufd_task);
1759 struct list_head tmp;
1761 xfs_buftarg_t *target;
1764 current->flags |= PF_MEMALLOC;
1766 INIT_LIST_HEAD(&tmp);
1768 if (unlikely(freezing(current))) {
1769 xfsbufd_force_sleep = 1;
1772 xfsbufd_force_sleep = 0;
1775 schedule_timeout_interruptible
1776 (xfs_buf_timer_centisecs * msecs_to_jiffies(10));
1778 age = xfs_buf_age_centisecs * msecs_to_jiffies(10);
1779 spin_lock(&pbd_delwrite_lock);
1780 list_for_each_entry_safe(pb, n, &pbd_delwrite_queue, pb_list) {
1781 PB_TRACE(pb, "walkq1", (long)pagebuf_ispin(pb));
1782 ASSERT(pb->pb_flags & PBF_DELWRI);
1784 if (!pagebuf_ispin(pb) && !pagebuf_cond_lock(pb)) {
1785 if (!xfsbufd_force_flush &&
1786 time_before(jiffies,
1787 pb->pb_queuetime + age)) {
1792 pb->pb_flags &= ~(PBF_DELWRI|_PBF_DELWRI_Q);
1793 pb->pb_flags |= PBF_WRITE;
1794 list_move(&pb->pb_list, &tmp);
1797 spin_unlock(&pbd_delwrite_lock);
1799 while (!list_empty(&tmp)) {
1800 pb = list_entry(tmp.next, xfs_buf_t, pb_list);
1801 target = pb->pb_target;
1803 list_del_init(&pb->pb_list);
1804 pagebuf_iostrategy(pb);
1806 blk_run_address_space(target->pbr_mapping);
1809 if (as_list_len > 0)
1812 xfsbufd_force_flush = 0;
1813 } while (!kthread_should_stop());
1819 * Go through all incore buffers, and release buffers if they belong to
1820 * the given device. This is used in filesystem error handling to
1821 * preserve the consistency of its metadata.
1825 xfs_buftarg_t *target,
1828 struct list_head tmp;
1832 pagebuf_runall_queues(xfsdatad_workqueue);
1833 pagebuf_runall_queues(xfslogd_workqueue);
1835 INIT_LIST_HEAD(&tmp);
1836 spin_lock(&pbd_delwrite_lock);
1837 list_for_each_entry_safe(pb, n, &pbd_delwrite_queue, pb_list) {
1839 if (pb->pb_target != target)
1842 ASSERT(pb->pb_flags & (PBF_DELWRI|_PBF_DELWRI_Q));
1843 PB_TRACE(pb, "walkq2", (long)pagebuf_ispin(pb));
1844 if (pagebuf_ispin(pb)) {
1849 list_move(&pb->pb_list, &tmp);
1851 spin_unlock(&pbd_delwrite_lock);
1854 * Dropped the delayed write list lock, now walk the temporary list
1856 list_for_each_entry_safe(pb, n, &tmp, pb_list) {
1858 pb->pb_flags &= ~(PBF_DELWRI|_PBF_DELWRI_Q);
1859 pb->pb_flags |= PBF_WRITE;
1861 pb->pb_flags &= ~PBF_ASYNC;
1863 list_del_init(&pb->pb_list);
1865 pagebuf_iostrategy(pb);
1869 * Remaining list items must be flushed before returning
1871 while (!list_empty(&tmp)) {
1872 pb = list_entry(tmp.next, xfs_buf_t, pb_list);
1874 list_del_init(&pb->pb_list);
1880 blk_run_address_space(target->pbr_mapping);
1888 int error = -ENOMEM;
1890 #ifdef PAGEBUF_TRACE
1891 pagebuf_trace_buf = ktrace_alloc(PAGEBUF_TRACE_SIZE, KM_SLEEP);
1894 pagebuf_zone = kmem_zone_init(sizeof(xfs_buf_t), "xfs_buf");
1896 goto out_free_trace_buf;
1898 xfslogd_workqueue = create_workqueue("xfslogd");
1899 if (!xfslogd_workqueue)
1900 goto out_free_buf_zone;
1902 xfsdatad_workqueue = create_workqueue("xfsdatad");
1903 if (!xfsdatad_workqueue)
1904 goto out_destroy_xfslogd_workqueue;
1906 xfsbufd_task = kthread_run(xfsbufd, NULL, "xfsbufd");
1907 if (IS_ERR(xfsbufd_task)) {
1908 error = PTR_ERR(xfsbufd_task);
1909 goto out_destroy_xfsdatad_workqueue;
1912 pagebuf_shake = kmem_shake_register(xfsbufd_wakeup);
1914 goto out_stop_xfsbufd;
1919 kthread_stop(xfsbufd_task);
1920 out_destroy_xfsdatad_workqueue:
1921 destroy_workqueue(xfsdatad_workqueue);
1922 out_destroy_xfslogd_workqueue:
1923 destroy_workqueue(xfslogd_workqueue);
1925 kmem_zone_destroy(pagebuf_zone);
1927 #ifdef PAGEBUF_TRACE
1928 ktrace_free(pagebuf_trace_buf);
1934 pagebuf_terminate(void)
1936 kmem_shake_deregister(pagebuf_shake);
1937 kthread_stop(xfsbufd_task);
1938 destroy_workqueue(xfsdatad_workqueue);
1939 destroy_workqueue(xfslogd_workqueue);
1940 kmem_zone_destroy(pagebuf_zone);
1941 #ifdef PAGEBUF_TRACE
1942 ktrace_free(pagebuf_trace_buf);