|
18 | 18 | #include "xfs_trace.h" |
19 | 19 | #include "xfs_icache.h" |
20 | 20 | #include "xfs_log.h" |
| 21 | +#include "xfs_rmap.h" |
| 22 | +#include "xfs_refcount.h" |
| 23 | +#include "xfs_bmap.h" |
| 24 | + |
| 25 | +static struct kmem_cache *xfs_defer_pending_cache; |
21 | 26 |
|
22 | 27 | /* |
23 | 28 | * Deferred Operations in XFS |
@@ -365,7 +370,7 @@ xfs_defer_cancel_list( |
365 | 370 | ops->cancel_item(pwi); |
366 | 371 | } |
367 | 372 | ASSERT(dfp->dfp_count == 0); |
368 | | - kmem_free(dfp); |
| 373 | + kmem_cache_free(xfs_defer_pending_cache, dfp); |
369 | 374 | } |
370 | 375 | } |
371 | 376 |
|
@@ -462,7 +467,7 @@ xfs_defer_finish_one( |
462 | 467 |
|
463 | 468 | /* Done with the dfp, free it. */ |
464 | 469 | list_del(&dfp->dfp_list); |
465 | | - kmem_free(dfp); |
| 470 | + kmem_cache_free(xfs_defer_pending_cache, dfp); |
466 | 471 | out: |
467 | 472 | if (ops->finish_cleanup) |
468 | 473 | ops->finish_cleanup(tp, state, error); |
@@ -596,8 +601,8 @@ xfs_defer_add( |
596 | 601 | dfp = NULL; |
597 | 602 | } |
598 | 603 | if (!dfp) { |
599 | | - dfp = kmem_alloc(sizeof(struct xfs_defer_pending), |
600 | | - KM_NOFS); |
| 604 | + dfp = kmem_cache_zalloc(xfs_defer_pending_cache, |
| 605 | + GFP_NOFS | __GFP_NOFAIL); |
601 | 606 | dfp->dfp_type = type; |
602 | 607 | dfp->dfp_intent = NULL; |
603 | 608 | dfp->dfp_done = NULL; |
@@ -809,3 +814,55 @@ xfs_defer_resources_rele( |
809 | 814 | dres->dr_bufs = 0; |
810 | 815 | dres->dr_ordered = 0; |
811 | 816 | } |
| 817 | + |
| 818 | +static inline int __init |
| 819 | +xfs_defer_init_cache(void) |
| 820 | +{ |
| 821 | + xfs_defer_pending_cache = kmem_cache_create("xfs_defer_pending", |
| 822 | + sizeof(struct xfs_defer_pending), |
| 823 | + 0, 0, NULL); |
| 824 | + |
| 825 | + return xfs_defer_pending_cache != NULL ? 0 : -ENOMEM; |
| 826 | +} |
| 827 | + |
| 828 | +static inline void |
| 829 | +xfs_defer_destroy_cache(void) |
| 830 | +{ |
| 831 | + kmem_cache_destroy(xfs_defer_pending_cache); |
| 832 | + xfs_defer_pending_cache = NULL; |
| 833 | +} |
| 834 | + |
| 835 | +/* Set up caches for deferred work items. */ |
| 836 | +int __init |
| 837 | +xfs_defer_init_item_caches(void) |
| 838 | +{ |
| 839 | + int error; |
| 840 | + |
| 841 | + error = xfs_defer_init_cache(); |
| 842 | + if (error) |
| 843 | + return error; |
| 844 | + error = xfs_rmap_intent_init_cache(); |
| 845 | + if (error) |
| 846 | + goto err; |
| 847 | + error = xfs_refcount_intent_init_cache(); |
| 848 | + if (error) |
| 849 | + goto err; |
| 850 | + error = xfs_bmap_intent_init_cache(); |
| 851 | + if (error) |
| 852 | + goto err; |
| 853 | + |
| 854 | + return 0; |
| 855 | +err: |
| 856 | + xfs_defer_destroy_item_caches(); |
| 857 | + return error; |
| 858 | +} |
| 859 | + |
| 860 | +/* Destroy all the deferred work item caches, if they've been allocated. */ |
| 861 | +void |
| 862 | +xfs_defer_destroy_item_caches(void) |
| 863 | +{ |
| 864 | + xfs_bmap_intent_destroy_cache(); |
| 865 | + xfs_refcount_intent_destroy_cache(); |
| 866 | + xfs_rmap_intent_destroy_cache(); |
| 867 | + xfs_defer_destroy_cache(); |
| 868 | +} |
0 commit comments