xfs: introduce an allocation workqueue
authorDave Chinner <dchinner@redhat.com>
Thu, 22 Mar 2012 05:15:07 +0000 (05:15 +0000)
committerBen Myers <bpm@sgi.com>
Thu, 22 Mar 2012 21:12:24 +0000 (16:12 -0500)
We currently have significant issues with the amount of stack that
allocation in XFS uses, especially in the writeback path. We can
easily consume 4k of stack between mapping the page, manipulating
the bmap btree and allocating blocks from the free list. Not to
mention btree block readahead and other functionality that issues IO
in the allocation path.

As a result, we can no longer fit allocation in the writeback path
in the stack space provided on x86_64. To alleviate this problem,
introduce an allocation workqueue and move all allocations to a
seperate context. This can be easily added as an interposing layer
into xfs_alloc_vextent(), which takes a single argument structure
and does not return until the allocation is complete or has failed.

To do this, add a work structure and a completion to the allocation
args structure. This allows xfs_alloc_vextent to queue the args onto
the workqueue and wait for it to be completed by the worker. This
can be done completely transparently to the caller.

The worker function needs to ensure that it sets and clears the
PF_TRANS flag appropriately as it is being run in an active
transaction context. Work can also be queued in a memory reclaim
context, so a rescuer is needed for the workqueue.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Ben Myers <bpm@sgi.com>
fs/xfs/xfs_alloc.c
fs/xfs/xfs_alloc.h
fs/xfs/xfs_super.c

index ce84ffd0264c86c77111145075c14fdc11b8a12f..31e90335b83d7d24a4a5fdebcc4f0e1c2ea1027e 100644 (file)
@@ -35,6 +35,7 @@
 #include "xfs_error.h"
 #include "xfs_trace.h"
 
+struct workqueue_struct *xfs_alloc_wq;
 
 #define XFS_ABSDIFF(a,b)       (((a) <= (b)) ? ((b) - (a)) : ((a) - (b)))
 
@@ -2207,7 +2208,7 @@ xfs_alloc_read_agf(
  * group or loop over the allocation groups to find the result.
  */
 int                            /* error */
-xfs_alloc_vextent(
+__xfs_alloc_vextent(
        xfs_alloc_arg_t *args)  /* allocation argument structure */
 {
        xfs_agblock_t   agsize; /* allocation group size */
@@ -2417,6 +2418,37 @@ error0:
        return error;
 }
 
+static void
+xfs_alloc_vextent_worker(
+       struct work_struct      *work)
+{
+       struct xfs_alloc_arg    *args = container_of(work,
+                                               struct xfs_alloc_arg, work);
+       unsigned long           pflags;
+
+       /* we are in a transaction context here */
+       current_set_flags_nested(&pflags, PF_FSTRANS);
+
+       args->result = __xfs_alloc_vextent(args);
+       complete(args->done);
+
+       current_restore_flags_nested(&pflags, PF_FSTRANS);
+}
+
+
+int                            /* error */
+xfs_alloc_vextent(
+       xfs_alloc_arg_t *args)  /* allocation argument structure */
+{
+       DECLARE_COMPLETION_ONSTACK(done);
+
+       args->done = &done;
+       INIT_WORK(&args->work, xfs_alloc_vextent_worker);
+       queue_work(xfs_alloc_wq, &args->work);
+       wait_for_completion(&done);
+       return args->result;
+}
+
 /*
  * Free an extent.
  * Just break up the extent address and hand off to xfs_free_ag_extent
index 2f52b924be79f424b0a3115849af602f719a6b79..ab5d0fd2f535954d0924c5ed933b8083133b6383 100644 (file)
@@ -25,6 +25,8 @@ struct xfs_perag;
 struct xfs_trans;
 struct xfs_busy_extent;
 
+extern struct workqueue_struct *xfs_alloc_wq;
+
 /*
  * Freespace allocation types.  Argument to xfs_alloc_[v]extent.
  */
@@ -119,6 +121,9 @@ typedef struct xfs_alloc_arg {
        char            isfl;           /* set if is freelist blocks - !acctg */
        char            userdata;       /* set if this is user data */
        xfs_fsblock_t   firstblock;     /* io first block allocated */
+       struct completion *done;
+       struct work_struct work;
+       int             result;
 } xfs_alloc_arg_t;
 
 /*
index 06d23b976f4cce6b87623532a5cd7bd2f2e4181a..5484888d39c4ca1ee4925d5f0e435cea721958bc 100644 (file)
@@ -1607,12 +1607,28 @@ xfs_init_workqueues(void)
        xfs_syncd_wq = alloc_workqueue("xfssyncd", WQ_NON_REENTRANT, 0);
        if (!xfs_syncd_wq)
                return -ENOMEM;
+
+       /*
+        * The allocation workqueue can be used in memory reclaim situations
+        * (writepage path), and parallelism is only limited by the number of
+        * AGs in all the filesystems mounted. Hence use the default large
+        * max_active value for this workqueue.
+        */
+       xfs_alloc_wq = alloc_workqueue("xfsalloc", WQ_MEM_RECLAIM, 0);
+       if (!xfs_alloc_wq)
+               goto out_destroy_syncd;
+
        return 0;
+
+out_destroy_syncd:
+       destroy_workqueue(xfs_syncd_wq);
+       return -ENOMEM;
 }
 
 STATIC void
 xfs_destroy_workqueues(void)
 {
+       destroy_workqueue(xfs_alloc_wq);
        destroy_workqueue(xfs_syncd_wq);
 }
 
This page took 0.032722 seconds and 5 git commands to generate.