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 page->private |= page_region_mask(offset, length);
185 if (page->private == ~0UL)
186 SetPageUptodate(page);
195 unsigned long mask = page_region_mask(offset, length);
197 return (mask && (page->private & mask) == mask);
201 * Mapping of multi-page buffers into contiguous virtual space
204 typedef struct a_list {
209 STATIC a_list_t *as_free_head;
210 STATIC int as_list_len;
211 STATIC DEFINE_SPINLOCK(as_lock);
214 * Try to batch vunmaps because they are costly.
222 aentry = kmalloc(sizeof(a_list_t), GFP_ATOMIC & ~__GFP_HIGH);
223 if (likely(aentry)) {
225 aentry->next = as_free_head;
226 aentry->vm_addr = addr;
227 as_free_head = aentry;
229 spin_unlock(&as_lock);
236 purge_addresses(void)
238 a_list_t *aentry, *old;
240 if (as_free_head == NULL)
244 aentry = as_free_head;
247 spin_unlock(&as_lock);
249 while ((old = aentry) != NULL) {
250 vunmap(aentry->vm_addr);
251 aentry = aentry->next;
257 * Internal pagebuf object manipulation
263 xfs_buftarg_t *target,
266 page_buf_flags_t flags)
269 * We don't want certain flags to appear in pb->pb_flags.
271 flags &= ~(PBF_LOCK|PBF_MAPPED|PBF_DONT_BLOCK|PBF_READ_AHEAD);
273 memset(pb, 0, sizeof(xfs_buf_t));
274 atomic_set(&pb->pb_hold, 1);
275 init_MUTEX_LOCKED(&pb->pb_iodonesema);
276 INIT_LIST_HEAD(&pb->pb_list);
277 INIT_LIST_HEAD(&pb->pb_hash_list);
278 init_MUTEX_LOCKED(&pb->pb_sema); /* held, no waiters */
280 pb->pb_target = target;
281 pb->pb_file_offset = range_base;
283 * Set buffer_length and count_desired to the same value initially.
284 * I/O routines should use count_desired, which will be the same in
285 * most cases but may be reset (e.g. XFS recovery).
287 pb->pb_buffer_length = pb->pb_count_desired = range_length;
288 pb->pb_flags = flags | PBF_NONE;
289 pb->pb_bn = XFS_BUF_DADDR_NULL;
290 atomic_set(&pb->pb_pin_count, 0);
291 init_waitqueue_head(&pb->pb_waiters);
293 XFS_STATS_INC(pb_create);
294 PB_TRACE(pb, "initialize", target);
298 * Allocate a page array capable of holding a specified number
299 * of pages, and point the page buf at it.
305 page_buf_flags_t flags)
307 /* Make sure that we have a page list */
308 if (pb->pb_pages == NULL) {
309 pb->pb_offset = page_buf_poff(pb->pb_file_offset);
310 pb->pb_page_count = page_count;
311 if (page_count <= PB_PAGES) {
312 pb->pb_pages = pb->pb_page_array;
314 pb->pb_pages = kmem_alloc(sizeof(struct page *) *
315 page_count, pb_to_km(flags));
316 if (pb->pb_pages == NULL)
319 memset(pb->pb_pages, 0, sizeof(struct page *) * page_count);
325 * Frees pb_pages if it was malloced.
331 if (bp->pb_pages != bp->pb_page_array) {
332 kmem_free(bp->pb_pages,
333 bp->pb_page_count * sizeof(struct page *));
338 * Releases the specified buffer.
340 * The modification state of any associated pages is left unchanged.
341 * The buffer most not be on any hash - use pagebuf_rele instead for
342 * hashed and refcounted buffers
348 PB_TRACE(bp, "free", 0);
350 ASSERT(list_empty(&bp->pb_hash_list));
352 if (bp->pb_flags & _PBF_PAGE_CACHE) {
355 if ((bp->pb_flags & PBF_MAPPED) && (bp->pb_page_count > 1))
356 free_address(bp->pb_addr - bp->pb_offset);
358 for (i = 0; i < bp->pb_page_count; i++)
359 page_cache_release(bp->pb_pages[i]);
360 _pagebuf_free_pages(bp);
361 } else if (bp->pb_flags & _PBF_KMEM_ALLOC) {
363 * XXX(hch): bp->pb_count_desired might be incorrect (see
364 * pagebuf_associate_memory for details), but fortunately
365 * the Linux version of kmem_free ignores the len argument..
367 kmem_free(bp->pb_addr, bp->pb_count_desired);
368 _pagebuf_free_pages(bp);
371 pagebuf_deallocate(bp);
375 * Finds all pages for buffer in question and builds it's page list.
378 _pagebuf_lookup_pages(
382 struct address_space *mapping = bp->pb_target->pbr_mapping;
383 size_t blocksize = bp->pb_target->pbr_bsize;
384 size_t size = bp->pb_count_desired;
385 size_t nbytes, offset;
386 gfp_t gfp_mask = pb_to_gfp(flags);
387 unsigned short page_count, i;
392 end = bp->pb_file_offset + bp->pb_buffer_length;
393 page_count = page_buf_btoc(end) - page_buf_btoct(bp->pb_file_offset);
395 error = _pagebuf_get_pages(bp, page_count, flags);
398 bp->pb_flags |= _PBF_PAGE_CACHE;
400 offset = bp->pb_offset;
401 first = bp->pb_file_offset >> PAGE_CACHE_SHIFT;
403 for (i = 0; i < bp->pb_page_count; i++) {
408 page = find_or_create_page(mapping, first + i, gfp_mask);
409 if (unlikely(page == NULL)) {
410 if (flags & PBF_READ_AHEAD) {
411 bp->pb_page_count = i;
412 for (i = 0; i < bp->pb_page_count; i++)
413 unlock_page(bp->pb_pages[i]);
418 * This could deadlock.
420 * But until all the XFS lowlevel code is revamped to
421 * handle buffer allocation failures we can't do much.
423 if (!(++retries % 100))
425 "XFS: possible memory allocation "
426 "deadlock in %s (mode:0x%x)\n",
427 __FUNCTION__, gfp_mask);
429 XFS_STATS_INC(pb_page_retries);
430 xfsbufd_wakeup(0, gfp_mask);
431 blk_congestion_wait(WRITE, HZ/50);
435 XFS_STATS_INC(pb_page_found);
437 nbytes = min_t(size_t, size, PAGE_CACHE_SIZE - offset);
440 if (!PageUptodate(page)) {
442 if (blocksize >= PAGE_CACHE_SIZE) {
443 if (flags & PBF_READ)
445 } else if (!PagePrivate(page)) {
446 if (test_page_region(page, offset, nbytes))
451 bp->pb_pages[i] = page;
455 if (!bp->pb_locked) {
456 for (i = 0; i < bp->pb_page_count; i++)
457 unlock_page(bp->pb_pages[i]);
461 /* if we have any uptodate pages, mark that in the buffer */
462 bp->pb_flags &= ~PBF_NONE;
464 /* if some pages aren't uptodate, mark that in the buffer */
465 if (page_count != bp->pb_page_count)
466 bp->pb_flags |= PBF_PARTIAL;
469 PB_TRACE(bp, "lookup_pages", (long)page_count);
474 * Map buffer into kernel address-space if nessecary.
481 /* A single page buffer is always mappable */
482 if (bp->pb_page_count == 1) {
483 bp->pb_addr = page_address(bp->pb_pages[0]) + bp->pb_offset;
484 bp->pb_flags |= PBF_MAPPED;
485 } else if (flags & PBF_MAPPED) {
486 if (as_list_len > 64)
488 bp->pb_addr = vmap(bp->pb_pages, bp->pb_page_count,
489 VM_MAP, PAGE_KERNEL);
490 if (unlikely(bp->pb_addr == NULL))
492 bp->pb_addr += bp->pb_offset;
493 bp->pb_flags |= PBF_MAPPED;
500 * Finding and Reading Buffers
506 * Looks up, and creates if absent, a lockable buffer for
507 * a given range of an inode. The buffer is returned
508 * locked. If other overlapping buffers exist, they are
509 * released before the new buffer is created and locked,
510 * which may imply that this call will block until those buffers
511 * are unlocked. No I/O is implied by this call.
515 xfs_buftarg_t *btp, /* block device target */
516 loff_t ioff, /* starting offset of range */
517 size_t isize, /* length of range */
518 page_buf_flags_t flags, /* PBF_TRYLOCK */
519 xfs_buf_t *new_pb)/* newly allocated buffer */
526 range_base = (ioff << BBSHIFT);
527 range_length = (isize << BBSHIFT);
529 /* Check for IOs smaller than the sector size / not sector aligned */
530 ASSERT(!(range_length < (1 << btp->pbr_sshift)));
531 ASSERT(!(range_base & (loff_t)btp->pbr_smask));
533 hash = &btp->bt_hash[hash_long((unsigned long)ioff, btp->bt_hashshift)];
535 spin_lock(&hash->bh_lock);
537 list_for_each_entry_safe(pb, n, &hash->bh_list, pb_hash_list) {
538 ASSERT(btp == pb->pb_target);
539 if (pb->pb_file_offset == range_base &&
540 pb->pb_buffer_length == range_length) {
542 * If we look at something bring it to the
543 * front of the list for next time.
545 atomic_inc(&pb->pb_hold);
546 list_move(&pb->pb_hash_list, &hash->bh_list);
553 _pagebuf_initialize(new_pb, btp, range_base,
554 range_length, flags);
555 new_pb->pb_hash = hash;
556 list_add(&new_pb->pb_hash_list, &hash->bh_list);
558 XFS_STATS_INC(pb_miss_locked);
561 spin_unlock(&hash->bh_lock);
565 spin_unlock(&hash->bh_lock);
567 /* Attempt to get the semaphore without sleeping,
568 * if this does not work then we need to drop the
569 * spinlock and do a hard attempt on the semaphore.
571 if (down_trylock(&pb->pb_sema)) {
572 if (!(flags & PBF_TRYLOCK)) {
573 /* wait for buffer ownership */
574 PB_TRACE(pb, "get_lock", 0);
576 XFS_STATS_INC(pb_get_locked_waited);
578 /* We asked for a trylock and failed, no need
579 * to look at file offset and length here, we
580 * know that this pagebuf at least overlaps our
581 * pagebuf and is locked, therefore our buffer
582 * either does not exist, or is this buffer
586 XFS_STATS_INC(pb_busy_locked);
594 if (pb->pb_flags & PBF_STALE) {
595 ASSERT((pb->pb_flags & _PBF_DELWRI_Q) == 0);
596 pb->pb_flags &= PBF_MAPPED;
598 PB_TRACE(pb, "got_lock", 0);
599 XFS_STATS_INC(pb_get_locked);
604 * xfs_buf_get_flags assembles a buffer covering the specified range.
606 * Storage in memory for all portions of the buffer will be allocated,
607 * although backing storage may not be.
610 xfs_buf_get_flags( /* allocate a buffer */
611 xfs_buftarg_t *target,/* target for buffer */
612 loff_t ioff, /* starting offset of range */
613 size_t isize, /* length of range */
614 page_buf_flags_t flags) /* PBF_TRYLOCK */
616 xfs_buf_t *pb, *new_pb;
619 new_pb = pagebuf_allocate(flags);
620 if (unlikely(!new_pb))
623 pb = _pagebuf_find(target, ioff, isize, flags, new_pb);
625 error = _pagebuf_lookup_pages(pb, flags);
629 pagebuf_deallocate(new_pb);
630 if (unlikely(pb == NULL))
634 for (i = 0; i < pb->pb_page_count; i++)
635 mark_page_accessed(pb->pb_pages[i]);
637 if (!(pb->pb_flags & PBF_MAPPED)) {
638 error = _pagebuf_map_pages(pb, flags);
639 if (unlikely(error)) {
640 printk(KERN_WARNING "%s: failed to map pages\n",
646 XFS_STATS_INC(pb_get);
649 * Always fill in the block number now, the mapped cases can do
650 * their own overlay of this later.
653 pb->pb_count_desired = pb->pb_buffer_length;
655 PB_TRACE(pb, "get", (unsigned long)flags);
659 if (flags & (PBF_LOCK | PBF_TRYLOCK))
667 xfs_buftarg_t *target,
670 page_buf_flags_t flags)
676 pb = xfs_buf_get_flags(target, ioff, isize, flags);
678 if (PBF_NOT_DONE(pb)) {
679 PB_TRACE(pb, "read", (unsigned long)flags);
680 XFS_STATS_INC(pb_get_read);
681 pagebuf_iostart(pb, flags);
682 } else if (flags & PBF_ASYNC) {
683 PB_TRACE(pb, "read_async", (unsigned long)flags);
685 * Read ahead call which is already satisfied,
690 PB_TRACE(pb, "read_done", (unsigned long)flags);
691 /* We do not want read in the flags */
692 pb->pb_flags &= ~PBF_READ;
699 if (flags & (PBF_LOCK | PBF_TRYLOCK))
706 * If we are not low on memory then do the readahead in a deadlock
711 xfs_buftarg_t *target,
714 page_buf_flags_t flags)
716 struct backing_dev_info *bdi;
718 bdi = target->pbr_mapping->backing_dev_info;
719 if (bdi_read_congested(bdi))
722 flags |= (PBF_TRYLOCK|PBF_ASYNC|PBF_READ_AHEAD);
723 xfs_buf_read_flags(target, ioff, isize, flags);
729 xfs_buftarg_t *target)
733 pb = pagebuf_allocate(0);
735 _pagebuf_initialize(pb, target, 0, len, 0);
739 static inline struct page *
743 if (((unsigned long)addr < VMALLOC_START) ||
744 ((unsigned long)addr >= VMALLOC_END)) {
745 return virt_to_page(addr);
747 return vmalloc_to_page(addr);
752 pagebuf_associate_memory(
764 page_count = PAGE_CACHE_ALIGN(len) >> PAGE_CACHE_SHIFT;
765 offset = (off_t) mem - ((off_t)mem & PAGE_CACHE_MASK);
766 if (offset && (len > PAGE_CACHE_SIZE))
769 /* Free any previous set of page pointers */
771 _pagebuf_free_pages(pb);
776 rval = _pagebuf_get_pages(pb, page_count, 0);
780 pb->pb_offset = offset;
781 ptr = (size_t) mem & PAGE_CACHE_MASK;
782 end = PAGE_CACHE_ALIGN((size_t) mem + len);
784 /* set up first page */
785 pb->pb_pages[0] = mem_to_page(mem);
787 ptr += PAGE_CACHE_SIZE;
788 pb->pb_page_count = ++i;
790 pb->pb_pages[i] = mem_to_page((void *)ptr);
791 pb->pb_page_count = ++i;
792 ptr += PAGE_CACHE_SIZE;
796 pb->pb_count_desired = pb->pb_buffer_length = len;
797 pb->pb_flags |= PBF_MAPPED;
803 pagebuf_get_no_daddr(
805 xfs_buftarg_t *target)
807 size_t malloc_len = len;
812 bp = pagebuf_allocate(0);
813 if (unlikely(bp == NULL))
815 _pagebuf_initialize(bp, target, 0, len, PBF_FORCEIO);
818 data = kmem_alloc(malloc_len, KM_SLEEP | KM_MAYFAIL);
819 if (unlikely(data == NULL))
822 /* check whether alignment matches.. */
823 if ((__psunsigned_t)data !=
824 ((__psunsigned_t)data & ~target->pbr_smask)) {
825 /* .. else double the size and try again */
826 kmem_free(data, malloc_len);
831 error = pagebuf_associate_memory(bp, data, len);
834 bp->pb_flags |= _PBF_KMEM_ALLOC;
838 PB_TRACE(bp, "no_daddr", data);
841 kmem_free(data, malloc_len);
851 * Increment reference count on buffer, to hold the buffer concurrently
852 * with another thread which may release (free) the buffer asynchronously.
854 * Must hold the buffer already to call this function.
860 atomic_inc(&pb->pb_hold);
861 PB_TRACE(pb, "hold", 0);
867 * pagebuf_rele releases a hold on the specified buffer. If the
868 * the hold count is 1, pagebuf_rele calls pagebuf_free.
874 xfs_bufhash_t *hash = pb->pb_hash;
876 PB_TRACE(pb, "rele", pb->pb_relse);
879 * pagebuf_lookup buffers are not hashed, not delayed write,
880 * and don't have their own release routines. Special case.
882 if (unlikely(!hash)) {
883 ASSERT(!pb->pb_relse);
884 if (atomic_dec_and_test(&pb->pb_hold))
889 if (atomic_dec_and_lock(&pb->pb_hold, &hash->bh_lock)) {
893 atomic_inc(&pb->pb_hold);
894 spin_unlock(&hash->bh_lock);
895 (*(pb->pb_relse)) (pb);
896 spin_lock(&hash->bh_lock);
900 if (pb->pb_flags & PBF_FS_MANAGED) {
905 ASSERT((pb->pb_flags & (PBF_DELWRI|_PBF_DELWRI_Q)) == 0);
906 list_del_init(&pb->pb_hash_list);
907 spin_unlock(&hash->bh_lock);
910 spin_unlock(&hash->bh_lock);
914 * Catch reference count leaks
916 ASSERT(atomic_read(&pb->pb_hold) >= 0);
922 * Mutual exclusion on buffers. Locking model:
924 * Buffers associated with inodes for which buffer locking
925 * is not enabled are not protected by semaphores, and are
926 * assumed to be exclusively owned by the caller. There is a
927 * spinlock in the buffer, used by the caller when concurrent
928 * access is possible.
934 * pagebuf_cond_lock locks a buffer object, if it is not already locked.
935 * Note that this in no way
936 * locks the underlying pages, so it is only useful for synchronizing
937 * concurrent use of page buffer objects, not for synchronizing independent
938 * access to the underlying pages.
941 pagebuf_cond_lock( /* lock buffer, if not locked */
942 /* returns -EBUSY if locked) */
947 locked = down_trylock(&pb->pb_sema) == 0;
951 PB_TRACE(pb, "cond_lock", (long)locked);
952 return(locked ? 0 : -EBUSY);
955 #if defined(DEBUG) || defined(XFS_BLI_TRACE)
959 * Return lock value for a pagebuf
965 return(atomic_read(&pb->pb_sema.count));
972 * pagebuf_lock locks a buffer object. Note that this in no way
973 * locks the underlying pages, so it is only useful for synchronizing
974 * concurrent use of page buffer objects, not for synchronizing independent
975 * access to the underlying pages.
981 PB_TRACE(pb, "lock", 0);
982 if (atomic_read(&pb->pb_io_remaining))
983 blk_run_address_space(pb->pb_target->pbr_mapping);
986 PB_TRACE(pb, "locked", 0);
993 * pagebuf_unlock releases the lock on the buffer object created by
994 * pagebuf_lock or pagebuf_cond_lock (not any pinning of underlying pages
995 * created by pagebuf_pin).
997 * If the buffer is marked delwri but is not queued, do so before we
998 * unlock the buffer as we need to set flags correctly. We also need to
999 * take a reference for the delwri queue because the unlocker is going to
1000 * drop their's and they don't know we just queued it.
1003 pagebuf_unlock( /* unlock buffer */
1004 xfs_buf_t *pb) /* buffer to unlock */
1006 if ((pb->pb_flags & (PBF_DELWRI|_PBF_DELWRI_Q)) == PBF_DELWRI) {
1007 atomic_inc(&pb->pb_hold);
1008 pb->pb_flags |= PBF_ASYNC;
1009 pagebuf_delwri_queue(pb, 0);
1014 PB_TRACE(pb, "unlock", 0);
1019 * Pinning Buffer Storage in Memory
1025 * pagebuf_pin locks all of the memory represented by a buffer in
1026 * memory. Multiple calls to pagebuf_pin and pagebuf_unpin, for
1027 * the same or different buffers affecting a given page, will
1028 * properly count the number of outstanding "pin" requests. The
1029 * buffer may be released after the pagebuf_pin and a different
1030 * buffer used when calling pagebuf_unpin, if desired.
1031 * pagebuf_pin should be used by the file system when it wants be
1032 * assured that no attempt will be made to force the affected
1033 * memory to disk. It does not assure that a given logical page
1034 * will not be moved to a different physical page.
1040 atomic_inc(&pb->pb_pin_count);
1041 PB_TRACE(pb, "pin", (long)pb->pb_pin_count.counter);
1047 * pagebuf_unpin reverses the locking of memory performed by
1048 * pagebuf_pin. Note that both functions affected the logical
1049 * pages associated with the buffer, not the buffer itself.
1055 if (atomic_dec_and_test(&pb->pb_pin_count)) {
1056 wake_up_all(&pb->pb_waiters);
1058 PB_TRACE(pb, "unpin", (long)pb->pb_pin_count.counter);
1065 return atomic_read(&pb->pb_pin_count);
1069 * pagebuf_wait_unpin
1071 * pagebuf_wait_unpin waits until all of the memory associated
1072 * with the buffer is not longer locked in memory. It returns
1073 * immediately if none of the affected pages are locked.
1076 _pagebuf_wait_unpin(
1079 DECLARE_WAITQUEUE (wait, current);
1081 if (atomic_read(&pb->pb_pin_count) == 0)
1084 add_wait_queue(&pb->pb_waiters, &wait);
1086 set_current_state(TASK_UNINTERRUPTIBLE);
1087 if (atomic_read(&pb->pb_pin_count) == 0)
1089 if (atomic_read(&pb->pb_io_remaining))
1090 blk_run_address_space(pb->pb_target->pbr_mapping);
1093 remove_wait_queue(&pb->pb_waiters, &wait);
1094 set_current_state(TASK_RUNNING);
1098 * Buffer Utility Routines
1104 * pagebuf_iodone marks a buffer for which I/O is in progress
1105 * done with respect to that I/O. The pb_iodone routine, if
1106 * present, will be called as a side-effect.
1109 pagebuf_iodone_work(
1112 xfs_buf_t *bp = (xfs_buf_t *)v;
1115 (*(bp->pb_iodone))(bp);
1116 else if (bp->pb_flags & PBF_ASYNC)
1126 pb->pb_flags &= ~(PBF_READ | PBF_WRITE);
1127 if (pb->pb_error == 0) {
1128 pb->pb_flags &= ~(PBF_PARTIAL | PBF_NONE);
1131 PB_TRACE(pb, "iodone", pb->pb_iodone);
1133 if ((pb->pb_iodone) || (pb->pb_flags & PBF_ASYNC)) {
1135 INIT_WORK(&pb->pb_iodone_work, pagebuf_iodone_work, pb);
1136 queue_work(dataio ? xfsdatad_workqueue :
1137 xfslogd_workqueue, &pb->pb_iodone_work);
1139 pagebuf_iodone_work(pb);
1142 up(&pb->pb_iodonesema);
1149 * pagebuf_ioerror sets the error code for a buffer.
1152 pagebuf_ioerror( /* mark/clear buffer error flag */
1153 xfs_buf_t *pb, /* buffer to mark */
1154 int error) /* error to store (0 if none) */
1156 ASSERT(error >= 0 && error <= 0xffff);
1157 pb->pb_error = (unsigned short)error;
1158 PB_TRACE(pb, "ioerror", (unsigned long)error);
1164 * pagebuf_iostart initiates I/O on a buffer, based on the flags supplied.
1165 * If necessary, it will arrange for any disk space allocation required,
1166 * and it will break up the request if the block mappings require it.
1167 * The pb_iodone routine in the buffer supplied will only be called
1168 * when all of the subsidiary I/O requests, if any, have been completed.
1169 * pagebuf_iostart calls the pagebuf_ioinitiate routine or
1170 * pagebuf_iorequest, if the former routine is not defined, to start
1171 * the I/O on a given low-level request.
1174 pagebuf_iostart( /* start I/O on a buffer */
1175 xfs_buf_t *pb, /* buffer to start */
1176 page_buf_flags_t flags) /* PBF_LOCK, PBF_ASYNC, PBF_READ, */
1177 /* PBF_WRITE, PBF_DELWRI, */
1178 /* PBF_DONT_BLOCK */
1182 PB_TRACE(pb, "iostart", (unsigned long)flags);
1184 if (flags & PBF_DELWRI) {
1185 pb->pb_flags &= ~(PBF_READ | PBF_WRITE | PBF_ASYNC);
1186 pb->pb_flags |= flags & (PBF_DELWRI | PBF_ASYNC);
1187 pagebuf_delwri_queue(pb, 1);
1191 pb->pb_flags &= ~(PBF_READ | PBF_WRITE | PBF_ASYNC | PBF_DELWRI | \
1192 PBF_READ_AHEAD | _PBF_RUN_QUEUES);
1193 pb->pb_flags |= flags & (PBF_READ | PBF_WRITE | PBF_ASYNC | \
1194 PBF_READ_AHEAD | _PBF_RUN_QUEUES);
1196 BUG_ON(pb->pb_bn == XFS_BUF_DADDR_NULL);
1198 /* For writes allow an alternate strategy routine to precede
1199 * the actual I/O request (which may not be issued at all in
1200 * a shutdown situation, for example).
1202 status = (flags & PBF_WRITE) ?
1203 pagebuf_iostrategy(pb) : pagebuf_iorequest(pb);
1205 /* Wait for I/O if we are not an async request.
1206 * Note: async I/O request completion will release the buffer,
1207 * and that can already be done by this point. So using the
1208 * buffer pointer from here on, after async I/O, is invalid.
1210 if (!status && !(flags & PBF_ASYNC))
1211 status = pagebuf_iowait(pb);
1217 * Helper routine for pagebuf_iorequest
1220 STATIC __inline__ int
1224 ASSERT(pb->pb_flags & (PBF_READ|PBF_WRITE));
1225 if (pb->pb_flags & PBF_READ)
1226 return pb->pb_locked;
1230 STATIC __inline__ void
1235 if (atomic_dec_and_test(&pb->pb_io_remaining) == 1) {
1237 pagebuf_iodone(pb, (pb->pb_flags & PBF_FS_DATAIOD), schedule);
1244 unsigned int bytes_done,
1247 xfs_buf_t *pb = (xfs_buf_t *)bio->bi_private;
1248 unsigned int blocksize = pb->pb_target->pbr_bsize;
1249 struct bio_vec *bvec = bio->bi_io_vec + bio->bi_vcnt - 1;
1254 if (!test_bit(BIO_UPTODATE, &bio->bi_flags))
1258 struct page *page = bvec->bv_page;
1260 if (unlikely(pb->pb_error)) {
1261 if (pb->pb_flags & PBF_READ)
1262 ClearPageUptodate(page);
1264 } else if (blocksize == PAGE_CACHE_SIZE) {
1265 SetPageUptodate(page);
1266 } else if (!PagePrivate(page) &&
1267 (pb->pb_flags & _PBF_PAGE_CACHE)) {
1268 set_page_region(page, bvec->bv_offset, bvec->bv_len);
1271 if (--bvec >= bio->bi_io_vec)
1272 prefetchw(&bvec->bv_page->flags);
1274 if (_pagebuf_iolocked(pb)) {
1277 } while (bvec >= bio->bi_io_vec);
1279 _pagebuf_iodone(pb, 1);
1288 int i, rw, map_i, total_nr_pages, nr_pages;
1290 int offset = pb->pb_offset;
1291 int size = pb->pb_count_desired;
1292 sector_t sector = pb->pb_bn;
1293 unsigned int blocksize = pb->pb_target->pbr_bsize;
1294 int locking = _pagebuf_iolocked(pb);
1296 total_nr_pages = pb->pb_page_count;
1299 if (pb->pb_flags & _PBF_RUN_QUEUES) {
1300 pb->pb_flags &= ~_PBF_RUN_QUEUES;
1301 rw = (pb->pb_flags & PBF_READ) ? READ_SYNC : WRITE_SYNC;
1303 rw = (pb->pb_flags & PBF_READ) ? READ : WRITE;
1306 /* Special code path for reading a sub page size pagebuf in --
1307 * we populate up the whole page, and hence the other metadata
1308 * in the same page. This optimization is only valid when the
1309 * filesystem block size and the page size are equal.
1311 if ((pb->pb_buffer_length < PAGE_CACHE_SIZE) &&
1312 (pb->pb_flags & PBF_READ) && locking &&
1313 (blocksize == PAGE_CACHE_SIZE)) {
1314 bio = bio_alloc(GFP_NOIO, 1);
1316 bio->bi_bdev = pb->pb_target->pbr_bdev;
1317 bio->bi_sector = sector - (offset >> BBSHIFT);
1318 bio->bi_end_io = bio_end_io_pagebuf;
1319 bio->bi_private = pb;
1321 bio_add_page(bio, pb->pb_pages[0], PAGE_CACHE_SIZE, 0);
1324 atomic_inc(&pb->pb_io_remaining);
1329 /* Lock down the pages which we need to for the request */
1330 if (locking && (pb->pb_flags & PBF_WRITE) && (pb->pb_locked == 0)) {
1331 for (i = 0; size; i++) {
1332 int nbytes = PAGE_CACHE_SIZE - offset;
1333 struct page *page = pb->pb_pages[i];
1343 offset = pb->pb_offset;
1344 size = pb->pb_count_desired;
1348 atomic_inc(&pb->pb_io_remaining);
1349 nr_pages = BIO_MAX_SECTORS >> (PAGE_SHIFT - BBSHIFT);
1350 if (nr_pages > total_nr_pages)
1351 nr_pages = total_nr_pages;
1353 bio = bio_alloc(GFP_NOIO, nr_pages);
1354 bio->bi_bdev = pb->pb_target->pbr_bdev;
1355 bio->bi_sector = sector;
1356 bio->bi_end_io = bio_end_io_pagebuf;
1357 bio->bi_private = pb;
1359 for (; size && nr_pages; nr_pages--, map_i++) {
1360 int nbytes = PAGE_CACHE_SIZE - offset;
1365 if (bio_add_page(bio, pb->pb_pages[map_i],
1366 nbytes, offset) < nbytes)
1370 sector += nbytes >> BBSHIFT;
1376 if (likely(bio->bi_size)) {
1377 submit_bio(rw, bio);
1382 pagebuf_ioerror(pb, EIO);
1387 * pagebuf_iorequest -- the core I/O request routine.
1390 pagebuf_iorequest( /* start real I/O */
1391 xfs_buf_t *pb) /* buffer to convey to device */
1393 PB_TRACE(pb, "iorequest", 0);
1395 if (pb->pb_flags & PBF_DELWRI) {
1396 pagebuf_delwri_queue(pb, 1);
1400 if (pb->pb_flags & PBF_WRITE) {
1401 _pagebuf_wait_unpin(pb);
1406 /* Set the count to 1 initially, this will stop an I/O
1407 * completion callout which happens before we have started
1408 * all the I/O from calling pagebuf_iodone too early.
1410 atomic_set(&pb->pb_io_remaining, 1);
1411 _pagebuf_ioapply(pb);
1412 _pagebuf_iodone(pb, 0);
1421 * pagebuf_iowait waits for I/O to complete on the buffer supplied.
1422 * It returns immediately if no I/O is pending. In any case, it returns
1423 * the error code, if any, or 0 if there is no error.
1429 PB_TRACE(pb, "iowait", 0);
1430 if (atomic_read(&pb->pb_io_remaining))
1431 blk_run_address_space(pb->pb_target->pbr_mapping);
1432 down(&pb->pb_iodonesema);
1433 PB_TRACE(pb, "iowaited", (long)pb->pb_error);
1434 return pb->pb_error;
1444 offset += pb->pb_offset;
1446 page = pb->pb_pages[offset >> PAGE_CACHE_SHIFT];
1447 return (caddr_t) page_address(page) + (offset & (PAGE_CACHE_SIZE - 1));
1453 * Move data into or out of a buffer.
1457 xfs_buf_t *pb, /* buffer to process */
1458 size_t boff, /* starting buffer offset */
1459 size_t bsize, /* length to copy */
1460 caddr_t data, /* data address */
1461 page_buf_rw_t mode) /* read/write flag */
1463 size_t bend, cpoff, csize;
1466 bend = boff + bsize;
1467 while (boff < bend) {
1468 page = pb->pb_pages[page_buf_btoct(boff + pb->pb_offset)];
1469 cpoff = page_buf_poff(boff + pb->pb_offset);
1470 csize = min_t(size_t,
1471 PAGE_CACHE_SIZE-cpoff, pb->pb_count_desired-boff);
1473 ASSERT(((csize + cpoff) <= PAGE_CACHE_SIZE));
1477 memset(page_address(page) + cpoff, 0, csize);
1480 memcpy(data, page_address(page) + cpoff, csize);
1483 memcpy(page_address(page) + cpoff, data, csize);
1492 * Handling of buftargs.
1496 * Wait for any bufs with callbacks that have been submitted but
1497 * have not yet returned... walk the hash list for the target.
1504 xfs_bufhash_t *hash;
1507 for (i = 0; i < (1 << btp->bt_hashshift); i++) {
1508 hash = &btp->bt_hash[i];
1510 spin_lock(&hash->bh_lock);
1511 list_for_each_entry_safe(bp, n, &hash->bh_list, pb_hash_list) {
1512 ASSERT(btp == bp->pb_target);
1513 if (!(bp->pb_flags & PBF_FS_MANAGED)) {
1514 spin_unlock(&hash->bh_lock);
1516 * Catch superblock reference count leaks
1519 BUG_ON(bp->pb_bn == 0);
1524 spin_unlock(&hash->bh_lock);
1529 * Allocate buffer hash table for a given target.
1530 * For devices containing metadata (i.e. not the log/realtime devices)
1531 * we need to allocate a much larger hash table.
1540 btp->bt_hashshift = external ? 3 : 8; /* 8 or 256 buckets */
1541 btp->bt_hashmask = (1 << btp->bt_hashshift) - 1;
1542 btp->bt_hash = kmem_zalloc((1 << btp->bt_hashshift) *
1543 sizeof(xfs_bufhash_t), KM_SLEEP);
1544 for (i = 0; i < (1 << btp->bt_hashshift); i++) {
1545 spin_lock_init(&btp->bt_hash[i].bh_lock);
1546 INIT_LIST_HEAD(&btp->bt_hash[i].bh_list);
1554 kmem_free(btp->bt_hash,
1555 (1 << btp->bt_hashshift) * sizeof(xfs_bufhash_t));
1556 btp->bt_hash = NULL;
1564 xfs_flush_buftarg(btp, 1);
1566 xfs_blkdev_put(btp->pbr_bdev);
1567 xfs_free_bufhash(btp);
1568 iput(btp->pbr_mapping->host);
1569 kmem_free(btp, sizeof(*btp));
1573 xfs_setsize_buftarg_flags(
1575 unsigned int blocksize,
1576 unsigned int sectorsize,
1579 btp->pbr_bsize = blocksize;
1580 btp->pbr_sshift = ffs(sectorsize) - 1;
1581 btp->pbr_smask = sectorsize - 1;
1583 if (set_blocksize(btp->pbr_bdev, sectorsize)) {
1585 "XFS: Cannot set_blocksize to %u on device %s\n",
1586 sectorsize, XFS_BUFTARG_NAME(btp));
1591 (PAGE_CACHE_SIZE / BITS_PER_LONG) > sectorsize) {
1593 "XFS: %u byte sectors in use on device %s. "
1594 "This is suboptimal; %u or greater is ideal.\n",
1595 sectorsize, XFS_BUFTARG_NAME(btp),
1596 (unsigned int)PAGE_CACHE_SIZE / BITS_PER_LONG);
1603 * When allocating the initial buffer target we have not yet
1604 * read in the superblock, so don't know what sized sectors
1605 * are being used is at this early stage. Play safe.
1608 xfs_setsize_buftarg_early(
1610 struct block_device *bdev)
1612 return xfs_setsize_buftarg_flags(btp,
1613 PAGE_CACHE_SIZE, bdev_hardsect_size(bdev), 0);
1617 xfs_setsize_buftarg(
1619 unsigned int blocksize,
1620 unsigned int sectorsize)
1622 return xfs_setsize_buftarg_flags(btp, blocksize, sectorsize, 1);
1626 xfs_mapping_buftarg(
1628 struct block_device *bdev)
1630 struct backing_dev_info *bdi;
1631 struct inode *inode;
1632 struct address_space *mapping;
1633 static struct address_space_operations mapping_aops = {
1634 .sync_page = block_sync_page,
1637 inode = new_inode(bdev->bd_inode->i_sb);
1640 "XFS: Cannot allocate mapping inode for device %s\n",
1641 XFS_BUFTARG_NAME(btp));
1644 inode->i_mode = S_IFBLK;
1645 inode->i_bdev = bdev;
1646 inode->i_rdev = bdev->bd_dev;
1647 bdi = blk_get_backing_dev_info(bdev);
1649 bdi = &default_backing_dev_info;
1650 mapping = &inode->i_data;
1651 mapping->a_ops = &mapping_aops;
1652 mapping->backing_dev_info = bdi;
1653 mapping_set_gfp_mask(mapping, GFP_NOFS);
1654 btp->pbr_mapping = mapping;
1660 struct block_device *bdev,
1665 btp = kmem_zalloc(sizeof(*btp), KM_SLEEP);
1667 btp->pbr_dev = bdev->bd_dev;
1668 btp->pbr_bdev = bdev;
1669 if (xfs_setsize_buftarg_early(btp, bdev))
1671 if (xfs_mapping_buftarg(btp, bdev))
1673 xfs_alloc_bufhash(btp, external);
1677 kmem_free(btp, sizeof(*btp));
1683 * Pagebuf delayed write buffer handling
1686 STATIC LIST_HEAD(pbd_delwrite_queue);
1687 STATIC DEFINE_SPINLOCK(pbd_delwrite_lock);
1690 pagebuf_delwri_queue(
1694 PB_TRACE(pb, "delwri_q", (long)unlock);
1695 ASSERT((pb->pb_flags & (PBF_DELWRI|PBF_ASYNC)) ==
1696 (PBF_DELWRI|PBF_ASYNC));
1698 spin_lock(&pbd_delwrite_lock);
1699 /* If already in the queue, dequeue and place at tail */
1700 if (!list_empty(&pb->pb_list)) {
1701 ASSERT(pb->pb_flags & _PBF_DELWRI_Q);
1703 atomic_dec(&pb->pb_hold);
1705 list_del(&pb->pb_list);
1708 pb->pb_flags |= _PBF_DELWRI_Q;
1709 list_add_tail(&pb->pb_list, &pbd_delwrite_queue);
1710 pb->pb_queuetime = jiffies;
1711 spin_unlock(&pbd_delwrite_lock);
1718 pagebuf_delwri_dequeue(
1723 spin_lock(&pbd_delwrite_lock);
1724 if ((pb->pb_flags & PBF_DELWRI) && !list_empty(&pb->pb_list)) {
1725 ASSERT(pb->pb_flags & _PBF_DELWRI_Q);
1726 list_del_init(&pb->pb_list);
1729 pb->pb_flags &= ~(PBF_DELWRI|_PBF_DELWRI_Q);
1730 spin_unlock(&pbd_delwrite_lock);
1735 PB_TRACE(pb, "delwri_dq", (long)dequeued);
1739 pagebuf_runall_queues(
1740 struct workqueue_struct *queue)
1742 flush_workqueue(queue);
1745 /* Defines for pagebuf daemon */
1746 STATIC struct task_struct *xfsbufd_task;
1747 STATIC int xfsbufd_force_flush;
1748 STATIC int xfsbufd_force_sleep;
1755 if (xfsbufd_force_sleep)
1757 xfsbufd_force_flush = 1;
1759 wake_up_process(xfsbufd_task);
1767 struct list_head tmp;
1769 xfs_buftarg_t *target;
1772 current->flags |= PF_MEMALLOC;
1774 INIT_LIST_HEAD(&tmp);
1776 if (unlikely(freezing(current))) {
1777 xfsbufd_force_sleep = 1;
1780 xfsbufd_force_sleep = 0;
1783 schedule_timeout_interruptible
1784 (xfs_buf_timer_centisecs * msecs_to_jiffies(10));
1786 age = xfs_buf_age_centisecs * msecs_to_jiffies(10);
1787 spin_lock(&pbd_delwrite_lock);
1788 list_for_each_entry_safe(pb, n, &pbd_delwrite_queue, pb_list) {
1789 PB_TRACE(pb, "walkq1", (long)pagebuf_ispin(pb));
1790 ASSERT(pb->pb_flags & PBF_DELWRI);
1792 if (!pagebuf_ispin(pb) && !pagebuf_cond_lock(pb)) {
1793 if (!xfsbufd_force_flush &&
1794 time_before(jiffies,
1795 pb->pb_queuetime + age)) {
1800 pb->pb_flags &= ~(PBF_DELWRI|_PBF_DELWRI_Q);
1801 pb->pb_flags |= PBF_WRITE;
1802 list_move(&pb->pb_list, &tmp);
1805 spin_unlock(&pbd_delwrite_lock);
1807 while (!list_empty(&tmp)) {
1808 pb = list_entry(tmp.next, xfs_buf_t, pb_list);
1809 target = pb->pb_target;
1811 list_del_init(&pb->pb_list);
1812 pagebuf_iostrategy(pb);
1814 blk_run_address_space(target->pbr_mapping);
1817 if (as_list_len > 0)
1820 xfsbufd_force_flush = 0;
1821 } while (!kthread_should_stop());
1827 * Go through all incore buffers, and release buffers if they belong to
1828 * the given device. This is used in filesystem error handling to
1829 * preserve the consistency of its metadata.
1833 xfs_buftarg_t *target,
1836 struct list_head tmp;
1840 pagebuf_runall_queues(xfsdatad_workqueue);
1841 pagebuf_runall_queues(xfslogd_workqueue);
1843 INIT_LIST_HEAD(&tmp);
1844 spin_lock(&pbd_delwrite_lock);
1845 list_for_each_entry_safe(pb, n, &pbd_delwrite_queue, pb_list) {
1847 if (pb->pb_target != target)
1850 ASSERT(pb->pb_flags & (PBF_DELWRI|_PBF_DELWRI_Q));
1851 PB_TRACE(pb, "walkq2", (long)pagebuf_ispin(pb));
1852 if (pagebuf_ispin(pb)) {
1857 list_move(&pb->pb_list, &tmp);
1859 spin_unlock(&pbd_delwrite_lock);
1862 * Dropped the delayed write list lock, now walk the temporary list
1864 list_for_each_entry_safe(pb, n, &tmp, pb_list) {
1866 pb->pb_flags &= ~(PBF_DELWRI|_PBF_DELWRI_Q);
1867 pb->pb_flags |= PBF_WRITE;
1869 pb->pb_flags &= ~PBF_ASYNC;
1871 list_del_init(&pb->pb_list);
1873 pagebuf_iostrategy(pb);
1877 * Remaining list items must be flushed before returning
1879 while (!list_empty(&tmp)) {
1880 pb = list_entry(tmp.next, xfs_buf_t, pb_list);
1882 list_del_init(&pb->pb_list);
1888 blk_run_address_space(target->pbr_mapping);
1894 xfs_buf_daemons_start(void)
1896 int error = -ENOMEM;
1898 xfslogd_workqueue = create_workqueue("xfslogd");
1899 if (!xfslogd_workqueue)
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;
1913 out_destroy_xfsdatad_workqueue:
1914 destroy_workqueue(xfsdatad_workqueue);
1915 out_destroy_xfslogd_workqueue:
1916 destroy_workqueue(xfslogd_workqueue);
1922 * Note: do not mark as __exit, it is called from pagebuf_terminate.
1925 xfs_buf_daemons_stop(void)
1927 kthread_stop(xfsbufd_task);
1928 destroy_workqueue(xfslogd_workqueue);
1929 destroy_workqueue(xfsdatad_workqueue);
1933 * Initialization and Termination
1939 int error = -ENOMEM;
1941 pagebuf_zone = kmem_zone_init(sizeof(xfs_buf_t), "xfs_buf");
1945 #ifdef PAGEBUF_TRACE
1946 pagebuf_trace_buf = ktrace_alloc(PAGEBUF_TRACE_SIZE, KM_SLEEP);
1949 error = xfs_buf_daemons_start();
1951 goto out_free_buf_zone;
1953 pagebuf_shake = kmem_shake_register(xfsbufd_wakeup);
1954 if (!pagebuf_shake) {
1956 goto out_stop_daemons;
1962 xfs_buf_daemons_stop();
1964 #ifdef PAGEBUF_TRACE
1965 ktrace_free(pagebuf_trace_buf);
1967 kmem_zone_destroy(pagebuf_zone);
1974 * pagebuf_terminate.
1976 * Note: do not mark as __exit, this is also called from the __init code.
1979 pagebuf_terminate(void)
1981 xfs_buf_daemons_stop();
1983 #ifdef PAGEBUF_TRACE
1984 ktrace_free(pagebuf_trace_buf);
1987 kmem_zone_destroy(pagebuf_zone);
1988 kmem_shake_deregister(pagebuf_shake);