All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dave Chinner <david@fromorbit.com>
To: xfs@oss.sgi.com
Subject: ***** SUSPECTED SPAM *****  [PATCH 41/50] xfs: Add xfs_log_rlimit.c
Date: Mon, 12 Aug 2013 20:50:02 +1000	[thread overview]
Message-ID: <1376304611-22994-42-git-send-email-david@fromorbit.com> (raw)
In-Reply-To: <1376304611-22994-1-git-send-email-david@fromorbit.com>

From: Jie Liu <jeff.liu@oracle.com>

Add source files for xfs_log_rlimit.c The new file is used for log
size calculations and validation shared with userspace.

[dchinner: xfs_log_calc_max_attrsetm_res() does not modify the
tr_attrsetm reservation, just calculates the maximum. ]

[dchinner: rework loop in xfs_log_get_max_trans_res() ]

Signed-off-by: Jie Liu <jeff.liu@oracle.com>
Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Mark Tinguely <tinguely@sgi.com>
---
 fs/xfs/Makefile         |   1 +
 fs/xfs/xfs_log_format.h |   7 ++-
 fs/xfs/xfs_log_rlimit.c | 145 ++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 152 insertions(+), 1 deletion(-)
 create mode 100644 fs/xfs/xfs_log_rlimit.c

diff --git a/fs/xfs/Makefile b/fs/xfs/Makefile
index d6ccf57..0719e4d 100644
--- a/fs/xfs/Makefile
+++ b/fs/xfs/Makefile
@@ -79,6 +79,7 @@ xfs-y				+= xfs_alloc.o \
 				   xfs_inode_fork.o \
 				   xfs_inode_buf.o \
 				   xfs_log_recover.o \
+				   xfs_log_rlimit.o \
 				   xfs_sb.o \
 				   xfs_symlink_remote.o \
 				   xfs_trans_resv.o
diff --git a/fs/xfs/xfs_log_format.h b/fs/xfs/xfs_log_format.h
index cc08f59..a49ab2c 100644
--- a/fs/xfs/xfs_log_format.h
+++ b/fs/xfs/xfs_log_format.h
@@ -19,6 +19,7 @@
 #define __XFS_LOG_FORMAT_H__
 
 struct xfs_mount;
+struct xfs_trans_res;
 
 /*
  * On-disk Log Format definitions.
@@ -51,6 +52,9 @@ typedef __uint32_t xlog_tid_t;
 
 #define XLOG_HEADER_SIZE	512
 
+/* Minimum number of transactions that must fit in the log (defined by mkfs) */
+#define XFS_MIN_LOG_FACTOR	3
+
 #define XLOG_REC_SHIFT(log) \
 	BTOBB(1 << (xfs_sb_version_haslogv2(&log->l_mp->m_sb) ? \
 	 XLOG_MAX_RECORD_BSHIFT : XLOG_BIG_RECORD_BSHIFT))
@@ -135,7 +139,6 @@ typedef struct xlog_op_header {
 	__u16	   oh_res2;	/* 32 bit align			:  2 b */
 } xlog_op_header_t;
 
-
 /* valid values for h_fmt */
 #define XLOG_FMT_UNKNOWN  0
 #define XLOG_FMT_LINUX_LE 1
@@ -837,5 +840,7 @@ struct xfs_icreate_log {
 };
 
 int	xfs_log_calc_unit_res(struct xfs_mount *mp, int unit_bytes);
+int	xfs_log_calc_minimum_size(struct xfs_mount *);
+
 
 #endif /* __XFS_LOG_FORMAT_H__ */
diff --git a/fs/xfs/xfs_log_rlimit.c b/fs/xfs/xfs_log_rlimit.c
new file mode 100644
index 0000000..6b17ef4
--- /dev/null
+++ b/fs/xfs/xfs_log_rlimit.c
@@ -0,0 +1,145 @@
+/*
+ * Copyright (c) 2013 Jie Liu.
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write the Free Software Foundation,
+ * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+#include "xfs.h"
+#include "xfs_fs.h"
+#include "xfs_log.h"
+#include "xfs_trans.h"
+#include "xfs_ag.h"
+#include "xfs_sb.h"
+#include "xfs_mount.h"
+#include "xfs_trans_space.h"
+#include "xfs_bmap_btree.h"
+#include "xfs_inode.h"
+#include "xfs_da_btree.h"
+#include "xfs_attr_leaf.h"
+
+/*
+ * Calculate the maximum length in bytes that would be required for a local
+ * attribute value as large attributes out of line are not logged.
+ */
+STATIC int
+xfs_log_calc_max_attrsetm_res(
+	struct xfs_mount	*mp)
+{
+	int			size;
+	int			nblks;
+
+	size = xfs_attr_leaf_entsize_local_max(mp->m_sb.sb_blocksize) -
+	       MAXNAMELEN - 1;
+	nblks = XFS_DAENTER_SPACE_RES(mp, XFS_ATTR_FORK);
+	nblks += XFS_B_TO_FSB(mp, size);
+	nblks += XFS_NEXTENTADD_SPACE_RES(mp, size, XFS_ATTR_FORK);
+
+	return  M_RES(mp)->tr_attrsetm.tr_logres +
+		M_RES(mp)->tr_attrsetrt.tr_logres * nblks;
+}
+
+/*
+ * Iterate over the log space reservation table to figure out and return
+ * the maximum one in terms of the pre-calculated values which were done
+ * at mount time.
+ */
+STATIC void
+xfs_log_get_max_trans_res(
+	struct xfs_mount	*mp,
+	struct xfs_trans_res	*max_resp)
+{
+	struct xfs_trans_res	*resp;
+	struct xfs_trans_res	*end_resp;
+	int			log_space = 0;
+	int			attr_space;
+
+	attr_space = xfs_log_calc_max_attrsetm_res(mp);
+
+	resp = (struct xfs_trans_res *)M_RES(mp);
+	end_resp = (struct xfs_trans_res *)(M_RES(mp) + 1);
+	for (; resp < end_resp; resp++) {
+		int		tmp = resp->tr_logcount > 1 ?
+				      resp->tr_logres * resp->tr_logcount :
+				      resp->tr_logres;
+		if (log_space < tmp) {
+			log_space = tmp;
+			*max_resp = *resp;		/* struct copy */
+		}
+	}
+
+	if (attr_space > log_space) {
+		*max_resp = M_RES(mp)->tr_attrsetm;	/* struct copy */
+		max_resp->tr_logres = attr_space;
+	}
+}
+
+/*
+ * Calculate the minimum valid log size for the given superblock configuration.
+ * Used to calculate the minimum log size at mkfs time, and to determine if
+ * the log is large enough or not at mount time. Returns the minimum size in
+ * filesystem block size units.
+ */
+int
+xfs_log_calc_minimum_size(
+	struct xfs_mount	*mp)
+{
+	struct xfs_trans_res	tres = {0};
+	int			max_logres;
+	int			min_logblks = 0;
+	int			lsunit = 0;
+
+	xfs_log_get_max_trans_res(mp, &tres);
+
+	max_logres = xfs_log_calc_unit_res(mp, tres.tr_logres);
+	if (tres.tr_logcount > 1)
+		max_logres *= tres.tr_logcount;
+
+	if (xfs_sb_version_haslogv2(&mp->m_sb) && mp->m_sb.sb_logsunit > 1)
+		lsunit = BTOBB(mp->m_sb.sb_logsunit);
+
+	/*
+	 * Two factors should be taken into account for calculating the minimum
+	 * log space.
+	 * 1) The fundamental limitation is that no single transaction can be
+	 *    larger than half size of the log.
+	 *
+	 *    From mkfs.xfs, this is considered by the XFS_MIN_LOG_FACTOR
+	 *    define, which is set to 3. That means we can definitely fit
+	 *    maximally sized 2 transactions in the log. We'll use this same
+	 *    value here.
+	 *
+	 * 2) If the lsunit option is specified, a transaction requires 2 LSU
+	 *    for the reservation because there are two log writes that can
+	 *    require padding - the transaction data and the commit record which
+	 *    are written separately and both can require padding to the LSU.
+	 *    Consider that we can have an active CIL reservation holding 2*LSU,
+	 *    but the CIL is not over a push threshold, in this case, if we
+	 *    don't have enough log space for at one new transaction, which
+	 *    includes another 2*LSU in the reservation, we will run into dead
+	 *    loop situation in log space grant procedure. i.e.
+	 *    xlog_grant_head_wait().
+	 *
+	 *    Hence the log size needs to be able to contain two maximally sized
+	 *    and padded transactions, which is (2 * (2 * LSU + maxlres)).
+	 *
+	 * Also, the log size should be a multiple of the log stripe unit, round
+	 * it up to lsunit boundary if lsunit is specified.
+	 */
+	if (lsunit)
+		min_logblks = roundup(BTOBB(max_logres), lsunit) + 2 * lsunit;
+	else
+		min_logblks = BTOBB(max_logres) + 2 * BBSIZE;
+	min_logblks *= XFS_MIN_LOG_FACTOR;
+	return XFS_BB_TO_FSB(mp, min_logblks);
+}
-- 
1.8.3.2

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

  parent reply	other threads:[~2013-08-12 10:51 UTC|newest]

Thread overview: 86+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-12 10:49 ***** SUSPECTED SPAM ***** [PATCH 00/50] xfs: patches for 3.12 Dave Chinner
2013-08-12 10:49 ` ***** SUSPECTED SPAM ***** [PATCH 01/50] xfs: separate out log format definitions Dave Chinner
2013-08-12 10:49 ` ***** SUSPECTED SPAM ***** [PATCH 02/50] xfs: split out inode log item format definition Dave Chinner
2013-08-12 10:49 ` ***** SUSPECTED SPAM ***** [PATCH 03/50] xfs: split out buf log item format definitions Dave Chinner
2013-08-12 10:49 ` ***** SUSPECTED SPAM ***** [PATCH 04/50] xfs: split out EFI/EFD log item format definition Dave Chinner
2013-08-12 10:49 ` ***** SUSPECTED SPAM ***** [PATCH 05/50] xfs: separate dquot on disk format definitions out of xfs_quota.h Dave Chinner
2013-08-12 10:49 ` ***** SUSPECTED SPAM ***** [PATCH 06/50] xfs: separate icreate log format definitions from xfs_icreate_item.h Dave Chinner
2013-08-12 10:49 ` ***** SUSPECTED SPAM ***** [PATCH 07/50] xfs: split out on-disk transaction definitions Dave Chinner
2013-08-12 10:49 ` ***** SUSPECTED SPAM ***** [PATCH 08/50] xfs: introduce xfs_rtalloc_defs.h Dave Chinner
2013-08-12 10:49 ` ***** SUSPECTED SPAM ***** [PATCH 09/50] xfs: introduce xfs_quota_defs.h Dave Chinner
2013-08-12 10:49 ` ***** SUSPECTED SPAM ***** [PATCH 10/50] xfs: sync minor header differences needed by userspace Dave Chinner
2013-08-12 10:49 ` ***** SUSPECTED SPAM ***** [PATCH 11/50] xfs: split out transaction reservation code Dave Chinner
2013-08-12 10:49 ` ***** SUSPECTED SPAM ***** [PATCH 12/50] xfs: move inode fork definitions to a new header file Dave Chinner
2013-08-12 10:49 ` ***** SUSPECTED SPAM ***** [PATCH 13/50] xfs: move unrelated definitions out of xfs_inode.h Dave Chinner
2013-08-12 10:49 ` ***** SUSPECTED SPAM ***** [PATCH 14/50] xfs: introduce xfs_inode_buf.c for inode buffer operations Dave Chinner
2013-08-12 10:49 ` ***** SUSPECTED SPAM ***** [PATCH 15/50] xfs: move getdents code into it's own file Dave Chinner
2013-08-12 10:49 ` ***** SUSPECTED SPAM ***** [PATCH 16/50] xfs: reshuffle dir2 definitions around for userspace Dave Chinner
2013-08-12 10:49 ` ***** SUSPECTED SPAM ***** [PATCH 17/50] xfs: split out attribute listing code into separate file Dave Chinner
2013-08-12 10:49 ` ***** SUSPECTED SPAM ***** [PATCH 18/50] xfs: split out attribute fork truncation " Dave Chinner
2013-08-12 10:49 ` ***** SUSPECTED SPAM ***** [PATCH 19/50] xfs: split out the remote symlink handling Dave Chinner
2013-08-12 10:49 ` ***** SUSPECTED SPAM ***** [PATCH 20/50] xfs: introduce xfs_sb.c for sharing with libxfs Dave Chinner
2013-08-12 10:49 ` ***** SUSPECTED SPAM ***** [PATCH 21/50] xfs: create xfs_bmap_util.[ch] Dave Chinner
2013-08-12 10:49 ` ***** SUSPECTED SPAM ***** [PATCH 22/50] xfs: minor cleanups Dave Chinner
2013-08-12 10:49 ` ***** SUSPECTED SPAM ***** [PATCH 23/50] xfs: fix issues that cause userspace warnings Dave Chinner
2013-08-12 10:49 ` ***** SUSPECTED SPAM ***** [PATCH 24/50] xfs: kill xfs_vnodeops.[ch] Dave Chinner
2013-08-12 10:49 ` ***** SUSPECTED SPAM ***** [PATCH 25/50] xfs: consolidate xfs_rename.c Dave Chinner
2013-08-12 10:49 ` ***** SUSPECTED SPAM ***** [PATCH 26/50] xfs: consolidate xfs_utils.c Dave Chinner
2013-08-12 10:49 ` ***** SUSPECTED SPAM ***** [PATCH 27/50] xfs: consolidate extent swap code Dave Chinner
2013-08-12 10:49 ` ***** SUSPECTED SPAM ***** [PATCH 28/50] xfs: don't special case shared superblock mounts Dave Chinner
2013-08-12 10:49 ` ***** SUSPECTED SPAM ***** [PATCH 29/50] xfs: kill __KERNEL__ check for debug code in allocation code Dave Chinner
2013-08-12 10:49 ` ***** SUSPECTED SPAM ***** [PATCH 30/50] xfs: remove __KERNEL__ from debug code Dave Chinner
2013-08-12 10:49 ` ***** SUSPECTED SPAM ***** [PATCH 31/50] xfs: remove __KERNEL__ check from xfs_dir2_leaf.c Dave Chinner
2013-08-12 10:49 ` ***** SUSPECTED SPAM ***** [PATCH 32/50] xfs: xfs_filestreams.h doesn't need __KERNEL__ Dave Chinner
2013-08-12 10:49 ` ***** SUSPECTED SPAM ***** [PATCH 33/50] xfs: move kernel specific type definitions to xfs.h Dave Chinner
2013-08-12 10:49 ` ***** SUSPECTED SPAM ***** [PATCH 34/50] xfs: make struct xfs_perag kernel only Dave Chinner
2013-08-12 10:49 ` ***** SUSPECTED SPAM ***** [PATCH 35/50] xfs: Introduce a new structure to hold transaction reservation items Dave Chinner
2013-08-12 10:49 ` ***** SUSPECTED SPAM ***** [PATCH 36/50] xfs: Introduce tr_fsyncts to m_reservation Dave Chinner
2013-08-12 10:49 ` ***** SUSPECTED SPAM ***** [PATCH 37/50] xfs: Make writeid transaction use tr_writeid Dave Chinner
2013-08-12 10:49 ` ***** SUSPECTED SPAM ***** [PATCH 38/50] xfs: refactor xfs_trans_reserve() interface Dave Chinner
2013-08-12 10:50 ` ***** SUSPECTED SPAM ***** [PATCH 39/50] xfs: Get rid of all XFS_XXX_LOG_RES() macro Dave Chinner
2013-08-12 10:50 ` ***** SUSPECTED SPAM ***** [PATCH 40/50] xfs: Refactor xfs_ticket_alloc() to extract a new helper Dave Chinner
2013-08-12 10:50 ` Dave Chinner [this message]
2013-08-12 10:50 ` ***** SUSPECTED SPAM ***** [PATCH 42/50] xfs: Validate log space at mount time Dave Chinner
2013-08-12 18:46   ` Mark Tinguely
2013-08-12 10:50 ` ***** SUSPECTED SPAM ***** [PATCH 43/50] xfs: return log item size in IOP_SIZE Dave Chinner
2013-08-12 10:50 ` ***** SUSPECTED SPAM ***** [PATCH 44/50] xfs: Reduce allocations during CIL insertion Dave Chinner
2013-08-13 13:28   ` Mark Tinguely
2013-08-12 10:50 ` ***** SUSPECTED SPAM ***** [PATCH 45/50] xfs: avoid CIL allocation during insert Dave Chinner
2013-08-13 13:37   ` Mark Tinguely
2013-08-12 10:50 ` ***** SUSPECTED SPAM ***** [PATCH 46/50] xfs: Combine CIL insert and prepare passes Dave Chinner
2013-08-13 14:02   ` Mark Tinguely
2013-08-12 10:50 ` ***** SUSPECTED SPAM ***** [PATCH 47/50] xfs: split the CIL lock Dave Chinner
2013-08-12 10:50 ` ***** SUSPECTED SPAM ***** [PATCH 48/50] xfs: Add read-only support for dirent filetype field Dave Chinner
2013-08-12 10:50 ` ***** SUSPECTED SPAM ***** [PATCH 49/50] xfs: Add write " Dave Chinner
2013-08-12 10:50 ` ***** SUSPECTED SPAM ***** [PATCH 50/50] xfs: use reference counts to free clean buffer items Dave Chinner
2013-08-13 15:03   ` Mark Tinguely
2013-08-13 21:46     ` Dave Chinner
2013-08-13 22:00       ` Mark Tinguely
2013-08-14  3:57         ` Dave Chinner
2013-08-14  4:12           ` Zhi Yong Wu
2013-08-14  6:41             ` Dave Chinner
2013-08-14 13:26           ` Mark Tinguely
2013-08-14 17:49             ` Mark Tinguely
2013-08-15  0:48               ` Dave Chinner
2013-08-15 21:43   ` ***** SUSPECTED SPAM ***** " Ben Myers
2013-08-12 22:55 ` ***** SUSPECTED SPAM ***** [PATCH 00/50] xfs: patches for 3.12 Ben Myers
2013-08-13 21:28   ` Ben Myers
2013-08-19 20:19 ` [PATCH 51/50] xfs: add xfs sb v4 support for dirent filetype field Mark Tinguely
2013-08-19 23:28   ` Eric Sandeen
2013-08-20 14:29     ` Mark Tinguely
2013-08-20 14:45       ` Eric Sandeen
2013-08-20 18:50         ` Ben Myers
2013-08-20 21:00           ` Mark Tinguely
2013-08-20 21:05             ` Ben Myers
2013-08-20 23:19       ` Dave Chinner
2013-08-21  0:06       ` Dave Chinner
2013-08-21 17:03         ` Ben Myers
2013-08-22  2:02           ` Dave Chinner
2013-08-22 16:14             ` Geoffrey Wehrman
2013-08-22 18:19               ` Ben Myers
2013-08-25  5:18                 ` Michael L. Semon
2013-08-25 23:21                   ` Michael L. Semon
2013-08-26 15:40                   ` Mark Tinguely
2013-08-19 23:40   ` Dave Chinner
2013-08-20 19:57   ` Geoffrey Wehrman
2013-08-22 15:59 ` ***** SUSPECTED SPAM ***** [PATCH 00/50] xfs: patches for 3.12 Ben Myers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1376304611-22994-42-git-send-email-david@fromorbit.com \
    --to=david@fromorbit.com \
    --cc=xfs@oss.sgi.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.