diff options
Diffstat (limited to 'fs/xfs/linux-2.6/xfs_buf.c')
-rw-r--r-- | fs/xfs/linux-2.6/xfs_buf.c | 59 |
1 files changed, 27 insertions, 32 deletions
diff --git a/fs/xfs/linux-2.6/xfs_buf.c b/fs/xfs/linux-2.6/xfs_buf.c index fe4f66a5af14..2df63622354e 100644 --- a/fs/xfs/linux-2.6/xfs_buf.c +++ b/fs/xfs/linux-2.6/xfs_buf.c | |||
@@ -35,7 +35,7 @@ | |||
35 | #include <linux/freezer.h> | 35 | #include <linux/freezer.h> |
36 | 36 | ||
37 | static kmem_zone_t *xfs_buf_zone; | 37 | static kmem_zone_t *xfs_buf_zone; |
38 | static kmem_shaker_t xfs_buf_shake; | 38 | static struct shrinker *xfs_buf_shake; |
39 | STATIC int xfsbufd(void *); | 39 | STATIC int xfsbufd(void *); |
40 | STATIC int xfsbufd_wakeup(int, gfp_t); | 40 | STATIC int xfsbufd_wakeup(int, gfp_t); |
41 | STATIC void xfs_buf_delwri_queue(xfs_buf_t *, int); | 41 | STATIC void xfs_buf_delwri_queue(xfs_buf_t *, int); |
@@ -314,7 +314,7 @@ xfs_buf_free( | |||
314 | 314 | ||
315 | ASSERT(list_empty(&bp->b_hash_list)); | 315 | ASSERT(list_empty(&bp->b_hash_list)); |
316 | 316 | ||
317 | if (bp->b_flags & _XBF_PAGE_CACHE) { | 317 | if (bp->b_flags & (_XBF_PAGE_CACHE|_XBF_PAGES)) { |
318 | uint i; | 318 | uint i; |
319 | 319 | ||
320 | if ((bp->b_flags & XBF_MAPPED) && (bp->b_page_count > 1)) | 320 | if ((bp->b_flags & XBF_MAPPED) && (bp->b_page_count > 1)) |
@@ -323,18 +323,11 @@ xfs_buf_free( | |||
323 | for (i = 0; i < bp->b_page_count; i++) { | 323 | for (i = 0; i < bp->b_page_count; i++) { |
324 | struct page *page = bp->b_pages[i]; | 324 | struct page *page = bp->b_pages[i]; |
325 | 325 | ||
326 | ASSERT(!PagePrivate(page)); | 326 | if (bp->b_flags & _XBF_PAGE_CACHE) |
327 | ASSERT(!PagePrivate(page)); | ||
327 | page_cache_release(page); | 328 | page_cache_release(page); |
328 | } | 329 | } |
329 | _xfs_buf_free_pages(bp); | 330 | _xfs_buf_free_pages(bp); |
330 | } else if (bp->b_flags & _XBF_KMEM_ALLOC) { | ||
331 | /* | ||
332 | * XXX(hch): bp->b_count_desired might be incorrect (see | ||
333 | * xfs_buf_associate_memory for details), but fortunately | ||
334 | * the Linux version of kmem_free ignores the len argument.. | ||
335 | */ | ||
336 | kmem_free(bp->b_addr, bp->b_count_desired); | ||
337 | _xfs_buf_free_pages(bp); | ||
338 | } | 331 | } |
339 | 332 | ||
340 | xfs_buf_deallocate(bp); | 333 | xfs_buf_deallocate(bp); |
@@ -764,43 +757,44 @@ xfs_buf_get_noaddr( | |||
764 | size_t len, | 757 | size_t len, |
765 | xfs_buftarg_t *target) | 758 | xfs_buftarg_t *target) |
766 | { | 759 | { |
767 | size_t malloc_len = len; | 760 | unsigned long page_count = PAGE_ALIGN(len) >> PAGE_SHIFT; |
761 | int error, i; | ||
768 | xfs_buf_t *bp; | 762 | xfs_buf_t *bp; |
769 | void *data; | ||
770 | int error; | ||
771 | 763 | ||
772 | bp = xfs_buf_allocate(0); | 764 | bp = xfs_buf_allocate(0); |
773 | if (unlikely(bp == NULL)) | 765 | if (unlikely(bp == NULL)) |
774 | goto fail; | 766 | goto fail; |
775 | _xfs_buf_initialize(bp, target, 0, len, 0); | 767 | _xfs_buf_initialize(bp, target, 0, len, 0); |
776 | 768 | ||
777 | try_again: | 769 | error = _xfs_buf_get_pages(bp, page_count, 0); |
778 | data = kmem_alloc(malloc_len, KM_SLEEP | KM_MAYFAIL | KM_LARGE); | 770 | if (error) |
779 | if (unlikely(data == NULL)) | ||
780 | goto fail_free_buf; | 771 | goto fail_free_buf; |
781 | 772 | ||
782 | /* check whether alignment matches.. */ | 773 | for (i = 0; i < page_count; i++) { |
783 | if ((__psunsigned_t)data != | 774 | bp->b_pages[i] = alloc_page(GFP_KERNEL); |
784 | ((__psunsigned_t)data & ~target->bt_smask)) { | 775 | if (!bp->b_pages[i]) |
785 | /* .. else double the size and try again */ | 776 | goto fail_free_mem; |
786 | kmem_free(data, malloc_len); | ||
787 | malloc_len <<= 1; | ||
788 | goto try_again; | ||
789 | } | 777 | } |
778 | bp->b_flags |= _XBF_PAGES; | ||
790 | 779 | ||
791 | error = xfs_buf_associate_memory(bp, data, len); | 780 | error = _xfs_buf_map_pages(bp, XBF_MAPPED); |
792 | if (error) | 781 | if (unlikely(error)) { |
782 | printk(KERN_WARNING "%s: failed to map pages\n", | ||
783 | __FUNCTION__); | ||
793 | goto fail_free_mem; | 784 | goto fail_free_mem; |
794 | bp->b_flags |= _XBF_KMEM_ALLOC; | 785 | } |
795 | 786 | ||
796 | xfs_buf_unlock(bp); | 787 | xfs_buf_unlock(bp); |
797 | 788 | ||
798 | XB_TRACE(bp, "no_daddr", data); | 789 | XB_TRACE(bp, "no_daddr", len); |
799 | return bp; | 790 | return bp; |
791 | |||
800 | fail_free_mem: | 792 | fail_free_mem: |
801 | kmem_free(data, malloc_len); | 793 | while (--i >= 0) |
794 | __free_page(bp->b_pages[i]); | ||
795 | _xfs_buf_free_pages(bp); | ||
802 | fail_free_buf: | 796 | fail_free_buf: |
803 | xfs_buf_free(bp); | 797 | xfs_buf_deallocate(bp); |
804 | fail: | 798 | fail: |
805 | return NULL; | 799 | return NULL; |
806 | } | 800 | } |
@@ -1453,6 +1447,7 @@ xfs_free_buftarg( | |||
1453 | int external) | 1447 | int external) |
1454 | { | 1448 | { |
1455 | xfs_flush_buftarg(btp, 1); | 1449 | xfs_flush_buftarg(btp, 1); |
1450 | xfs_blkdev_issue_flush(btp); | ||
1456 | if (external) | 1451 | if (external) |
1457 | xfs_blkdev_put(btp->bt_bdev); | 1452 | xfs_blkdev_put(btp->bt_bdev); |
1458 | xfs_free_bufhash(btp); | 1453 | xfs_free_bufhash(btp); |
@@ -1837,7 +1832,7 @@ xfs_buf_init(void) | |||
1837 | if (!xfsdatad_workqueue) | 1832 | if (!xfsdatad_workqueue) |
1838 | goto out_destroy_xfslogd_workqueue; | 1833 | goto out_destroy_xfslogd_workqueue; |
1839 | 1834 | ||
1840 | xfs_buf_shake = kmem_shake_register(xfsbufd_wakeup); | 1835 | xfs_buf_shake = set_shrinker(DEFAULT_SEEKS, xfsbufd_wakeup); |
1841 | if (!xfs_buf_shake) | 1836 | if (!xfs_buf_shake) |
1842 | goto out_destroy_xfsdatad_workqueue; | 1837 | goto out_destroy_xfsdatad_workqueue; |
1843 | 1838 | ||
@@ -1859,7 +1854,7 @@ xfs_buf_init(void) | |||
1859 | void | 1854 | void |
1860 | xfs_buf_terminate(void) | 1855 | xfs_buf_terminate(void) |
1861 | { | 1856 | { |
1862 | kmem_shake_deregister(xfs_buf_shake); | 1857 | remove_shrinker(xfs_buf_shake); |
1863 | destroy_workqueue(xfsdatad_workqueue); | 1858 | destroy_workqueue(xfsdatad_workqueue); |
1864 | destroy_workqueue(xfslogd_workqueue); | 1859 | destroy_workqueue(xfslogd_workqueue); |
1865 | kmem_zone_destroy(xfs_buf_zone); | 1860 | kmem_zone_destroy(xfs_buf_zone); |