All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dmitry Monakhov <dmonakhov@openvz.org>
To: Jan Kara <jack@suse.cz>, linux-fsdevel@vger.kernel.org
Subject: quota file question
Date: Tue, 09 Mar 2010 07:57:59 +0300	[thread overview]
Message-ID: <87bpeyozvs.fsf@openvz.org> (raw)

[-- Attachment #1: Type: text/plain, Size: 536 bytes --]

I'm always wonder why do we have to allocate space for quota-file
as normal file. Because of this we have to grab i_mutex on each
quota write. And still getting in to risk of ENOSPC. The later is
really annoying issue for me(when i run fsstress tests).
Let's live the i_mutex's story for another day and consider the
simplest one. Why don't we preallocate a space for quota file
during creation. In fact we may imagine some reasonable quota-file
size expectation (65538 * 64) = 4Mb, At least this may be sufficient
for most use-cases.


[-- Attachment #2: 0001-quota-prealloc-space-for-new-quota-file.patch --]
[-- Type: text/plain, Size: 3155 bytes --]

>From ef72d4ad7d23db734a7ce74b350cdd47a594130b Mon Sep 17 00:00:00 2001
From: Dmitry Monakhov <dmonakhov@openvz.org>
Date: Sun, 7 Mar 2010 20:08:51 +0300
Subject: [PATCH] quota: prealloc space for new quota file.


Signed-off-by: Dmitry Monakhov <dmonakhov@openvz.org>
---
 convertquota.c |    4 ++--
 quotacheck.c   |    2 +-
 quotaio.c      |   15 ++++++++++++++-
 quotaio.h      |    2 +-
 4 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/convertquota.c b/convertquota.c
index 1572cb9..2304be6 100644
--- a/convertquota.c
+++ b/convertquota.c
@@ -287,7 +287,7 @@ static int convert_format(int type, struct mntent *mnt)
 			type2name(type), mnt->mnt_dir);
 		return -1;
 	}
-	if (!(qn = new_io(mnt, type, QF_VFSV0))) {
+	if (!(qn = new_io(mnt, type, QF_VFSV0, 8192*1024))) {
 		errstr(_("Cannot create file for %ss for new format on %s: %s\n"),
 			type2name(type), mnt->mnt_dir, strerror(errno));
 		end_io(qo);
@@ -320,7 +320,7 @@ static int convert_endian(int type, struct mntent *mnt)
 		close(ofd);
 		return -1;
 	}
-	if (!(qn = new_io(mnt, type, QF_VFSV0))) {
+	if (!(qn = new_io(mnt, type, QF_VFSV0, 8192*1024))) {
 		errstr(_("Cannot create file for %ss for new format on %s: %s\n"),
 			type2name(type), mnt->mnt_dir, strerror(errno));
 		close(ofd);
diff --git a/quotacheck.c b/quotacheck.c
index b5f7e2e..2b49820 100644
--- a/quotacheck.c
+++ b/quotacheck.c
@@ -794,7 +794,7 @@ static int dump_to_file(struct mntent *mnt, int type)
 	struct quota_handle *h;
 
 	debug(FL_DEBUG, _("Dumping gathered data for %ss.\n"), type2name(type));
-	if (!(h = new_io(mnt, type, cfmt))) {
+	if (!(h = new_io(mnt, type, cfmt, 8192*1024))) {
 		errstr(_("Cannot initialize IO on new quotafile: %s\n"),
 			strerror(errno));
 		return -1;
diff --git a/quotaio.c b/quotaio.c
index d74a37d..540e89b 100644
--- a/quotaio.c
+++ b/quotaio.c
@@ -166,7 +166,7 @@ out_handle:
 /*
  *	Create new quotafile of specified format on given filesystem
  */
-struct quota_handle *new_io(struct mntent *mnt, int type, int fmt)
+struct quota_handle *new_io(struct mntent *mnt, int type, int fmt, int prealloc)
 {
 	char *qfname;
 	int fd;
@@ -212,6 +212,19 @@ struct quota_handle *new_io(struct mntent *mnt, int type, int fmt)
 		free(h);
 		goto out_fd;
 	}
+	if (prealloc) {
+		char zbuf[4096];
+		int len, ret;
+		memset(zbuf, 0, sizeof(zbuf));
+		while (prealloc) {
+			len = (sizeof(zbuf) < prealloc) ? sizeof(zbuf) : prealloc;
+			ret = write(fd, zbuf, len);
+			if (ret < 0)
+				goto out_fd;
+			prealloc -= len;
+		}
+		lseek(fd, 0, SEEK_SET);
+	}
 	return h;
       out_fd:
 	close(fd);
diff --git a/quotaio.h b/quotaio.h
index f6eef50..c66db43 100644
--- a/quotaio.h
+++ b/quotaio.h
@@ -169,7 +169,7 @@ static inline void mark_quotafile_info_dirty(struct quota_handle *h)
 struct quota_handle *init_io(struct mntent *mnt, int type, int fmt, int flags);
 
 /* Create new quotafile of specified format on given filesystem */
-struct quota_handle *new_io(struct mntent *mnt, int type, int fmt);
+struct quota_handle *new_io(struct mntent *mnt, int type, int fmt, int prealloc);
 
 /* Close quotafile */
 int end_io(struct quota_handle *h);
-- 
1.6.3.3


             reply	other threads:[~2010-03-09  4:58 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-09  4:57 Dmitry Monakhov [this message]
2010-03-09 12:25 ` quota file question Jan Kara

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=87bpeyozvs.fsf@openvz.org \
    --to=dmonakhov@openvz.org \
    --cc=jack@suse.cz \
    --cc=linux-fsdevel@vger.kernel.org \
    /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.