xfs
[Top] [All Lists]

[PATCH v2 5/7] xfs: xfs_dquot prealloc throttling watermarks and low fre

To: xfs@xxxxxxxxxxx
Subject: [PATCH v2 5/7] xfs: xfs_dquot prealloc throttling watermarks and low free space
From: Brian Foster <bfoster@xxxxxxxxxx>
Date: Wed, 2 Jan 2013 13:08:09 -0500
In-reply-to: <1357150091-37530-1-git-send-email-bfoster@xxxxxxxxxx>
References: <1357150091-37530-1-git-send-email-bfoster@xxxxxxxxxx>
Enable tracking of high and low watermarks for preallocation
throttling of files under quota restrictions. These values are
calculated when the quota limit is read from disk or modified and
cached for later use by the throttling algorithm.

The high watermark specifies when preallocation is disabled, the
low watermark specifies when throttling is enabled and the low free
space data structure contains precalculated low free space limits
to serve as input to determine the level of throttling required.

Note that the low free space data structure is based on the
existing global low free space data structure with the exception of
using three stages (5%, 3% and 1%) rather than five to reduce the
impact of xfs_dquot memory overhead.

Signed-off-by: Brian Foster <bfoster@xxxxxxxxxx>
---
 fs/xfs/xfs_dquot.c       |   43 +++++++++++++++++++++++++++++++++++++++++--
 fs/xfs/xfs_dquot.h       |   13 +++++++++++++
 fs/xfs/xfs_qm_syscalls.c |    1 +
 3 files changed, 55 insertions(+), 2 deletions(-)

diff --git a/fs/xfs/xfs_dquot.c b/fs/xfs/xfs_dquot.c
index cc52462..c459b00 100644
--- a/fs/xfs/xfs_dquot.c
+++ b/fs/xfs/xfs_dquot.c
@@ -90,13 +90,18 @@ xfs_qm_adjust_dqlimits(
 {
        xfs_quotainfo_t         *q = mp->m_quotainfo;
        xfs_disk_dquot_t        *d = &dq->q_core;
+       int                     prealloc = 0;
 
        ASSERT(d->d_id);
 
-       if (q->qi_bsoftlimit && !d->d_blk_softlimit)
+       if (q->qi_bsoftlimit && !d->d_blk_softlimit) {
                d->d_blk_softlimit = cpu_to_be64(q->qi_bsoftlimit);
-       if (q->qi_bhardlimit && !d->d_blk_hardlimit)
+               prealloc = 1;
+       }
+       if (q->qi_bhardlimit && !d->d_blk_hardlimit) {
                d->d_blk_hardlimit = cpu_to_be64(q->qi_bhardlimit);
+               prealloc = 1;
+       }
        if (q->qi_isoftlimit && !d->d_ino_softlimit)
                d->d_ino_softlimit = cpu_to_be64(q->qi_isoftlimit);
        if (q->qi_ihardlimit && !d->d_ino_hardlimit)
@@ -105,6 +110,9 @@ xfs_qm_adjust_dqlimits(
                d->d_rtb_softlimit = cpu_to_be64(q->qi_rtbsoftlimit);
        if (q->qi_rtbhardlimit && !d->d_rtb_hardlimit)
                d->d_rtb_hardlimit = cpu_to_be64(q->qi_rtbhardlimit);
+
+       if (prealloc)
+               xfs_dquot_init_prealloc(dq);
 }
 
 /*
@@ -249,6 +257,34 @@ xfs_qm_init_dquot_blk(
        xfs_trans_log_buf(tp, bp, 0, BBTOB(q->qi_dqchunklen) - 1);
 }
 
+/*
+ * Initialize the preallocation throttling watermarks and low free space table.
+ * The lo/hi watermarks correspond to the soft and hard limits by default. If a
+ * soft limit is not specified, we use 95% of the hard limit.
+ */
+void
+xfs_dquot_init_prealloc(struct xfs_dquot *dqp)
+{
+       int i;
+       int pct = 1;
+
+       dqp->q_prealloc_hi_wmark = be64_to_cpu(dqp->q_core.d_blk_hardlimit);
+       dqp->q_prealloc_lo_wmark = be64_to_cpu(dqp->q_core.d_blk_softlimit);
+       if (!dqp->q_prealloc_lo_wmark) {
+               dqp->q_prealloc_lo_wmark = dqp->q_prealloc_hi_wmark;
+               do_div(dqp->q_prealloc_lo_wmark, 100);
+               dqp->q_prealloc_lo_wmark *= 95;
+       }
+
+       for (i = 0; i < XFS_QLOWSP_MAX; i++) {
+               __uint64_t space = dqp->q_prealloc_hi_wmark;
+
+               do_div(space, 100);
+               dqp->q_low_space[i] = space * pct;
+               pct += XFS_QLOWSP_PCNT_INCR;
+       }
+}
+
 static void
 xfs_dquot_buf_verify(
        struct xfs_buf          *bp)
@@ -655,6 +691,9 @@ xfs_qm_dqread(
        dqp->q_res_icount = be64_to_cpu(ddqp->d_icount);
        dqp->q_res_rtbcount = be64_to_cpu(ddqp->d_rtbcount);
 
+       /* initialize dquot prealloc throttling watermarks */
+       xfs_dquot_init_prealloc(dqp);
+
        /* Mark the buf so that this will stay incore a little longer */
        xfs_buf_set_ref(bp, XFS_DQUOT_REF);
 
diff --git a/fs/xfs/xfs_dquot.h b/fs/xfs/xfs_dquot.h
index 69491b6..7b026fe 100644
--- a/fs/xfs/xfs_dquot.h
+++ b/fs/xfs/xfs_dquot.h
@@ -32,6 +32,14 @@
 struct xfs_mount;
 struct xfs_trans;
 
+enum {
+       XFS_QLOWSP_1_PCNT = 0,
+       XFS_QLOWSP_3_PCNT,
+       XFS_QLOWSP_5_PCNT,
+       XFS_QLOWSP_MAX
+};
+#define XFS_QLOWSP_PCNT_INCR 2
+
 /*
  * The incore dquot structure
  */
@@ -51,6 +59,9 @@ typedef struct xfs_dquot {
        xfs_qcnt_t       q_res_bcount;  /* total regular nblks used+reserved */
        xfs_qcnt_t       q_res_icount;  /* total inos allocd+reserved */
        xfs_qcnt_t       q_res_rtbcount;/* total realtime blks used+reserved */
+       xfs_qcnt_t       q_prealloc_lo_wmark;/* prealloc throttle wmark */
+       xfs_qcnt_t       q_prealloc_hi_wmark;/* prealloc disabled wmark */
+       int64_t          q_low_space[XFS_QLOWSP_MAX];
        struct mutex     q_qlock;       /* quota lock */
        struct completion q_flush;      /* flush completion queue */
        atomic_t          q_pincount;   /* dquot pin count */
@@ -153,6 +164,8 @@ extern void         xfs_qm_dqput(xfs_dquot_t *);
 
 extern void            xfs_dqlock2(struct xfs_dquot *, struct xfs_dquot *);
 
+extern void            xfs_dquot_init_prealloc(struct xfs_dquot *);
+
 static inline struct xfs_dquot *xfs_qm_dqhold(struct xfs_dquot *dqp)
 {
        xfs_dqlock(dqp);
diff --git a/fs/xfs/xfs_qm_syscalls.c b/fs/xfs/xfs_qm_syscalls.c
index 5f53e75..f486d85 100644
--- a/fs/xfs/xfs_qm_syscalls.c
+++ b/fs/xfs/xfs_qm_syscalls.c
@@ -528,6 +528,7 @@ xfs_qm_scall_setqlim(
        if (hard == 0 || hard >= soft) {
                ddq->d_blk_hardlimit = cpu_to_be64(hard);
                ddq->d_blk_softlimit = cpu_to_be64(soft);
+               xfs_dquot_init_prealloc(dqp);
                if (id == 0) {
                        q->qi_bhardlimit = hard;
                        q->qi_bsoftlimit = soft;
-- 
1.7.7.6

<Prev in Thread] Current Thread [Next in Thread>