From: Tejun Heo <tj@kernel.org>
To: NeilBrown <neilb@suse.de>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-kernel@vger.kernel.org, Al Viro <viro@ZenIV.linux.org.uk>
Subject: Re: [PATCH 1/2] sysfs/kernfs: allow attributes to request write buffer be pre-allocated.
Date: Thu, 9 Oct 2014 09:32:37 -0400 [thread overview]
Message-ID: <20141009133237.GC14387@htj.dyndns.org> (raw)
In-Reply-To: <20141008235706.19126.68493.stgit@notabene.brown>
On Thu, Oct 09, 2014 at 10:57:06AM +1100, NeilBrown wrote:
> md/raid allows metadata management to be performed in user-space.
> A various times, particularly on device failure, the metadata needs
> to be updated before further writes can be permitted.
> This means that the user-space program which updates metadata much
> not block on writeout, and so must not allocate memory.
>
> mlockall(MCL_CURRENT|MCL_FUTURE) and pre-allocation can avoid all
> memory allocation issues for user-memory, but that does not help
> kernel memory.
> Several kernel objects can be pre-allocated. e.g. files opened before
> any writes to the array are permitted.
> However some kernel allocation happens in places that cannot be
> pre-allocated.
> In particular, writes to sysfs files (to tell md that it can now
> allow writes to the array) allocate a buffer using GFP_KERNEL.
>
> This patch allows attributes to be marked as "PREALLOC". In that case
> the maximal buffer is allocated when the file is opened, and then used
> on each write instead of allocating a new buffer.
>
> As the same buffer is now shared for all writes on the same file
> description, the mutex is extended to cover full use of the buffer
> including the copy_from_user().
>
> The new __ATTR_PREALLOC() 'or's a new flag in to the 'mode', which is
> inspected by sysfs_add_file_mode_ns() to determine if the file should be
> marked as requiring prealloc.
>
> Signed-off-by: NeilBrown <neilb@suse.de>
Reviewed-by: Tejun Heo <tj@kernel.org>
A trivial nitpick follows.
> @@ -685,6 +690,13 @@ static int kernfs_fop_open(struct inode *inode, struct file *file)
> */
> of->atomic_write_len = ops->atomic_write_len;
>
> + if (ops->prealloc) {
> + int len = of->atomic_write_len ?: PAGE_SIZE;
> + of->prealloc_buf = kmalloc(len + 1, GFP_KERNEL);
> + error = -ENOMEM;
> + if (!of->prealloc_buf)
> + goto err_free;
> + }
We prolly want a new line here for style consistency?
> /*
> * Always instantiate seq_file even if read access doesn't use
> * seq_file or is not requested. This unifies private data access
Thanks.
--
tejun
next prev parent reply other threads:[~2014-10-09 13:32 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-08 23:57 [PATCH 0/2 V2] Allow access to sysfs attributes without mem allocations NeilBrown
2014-10-08 23:57 ` [PATCH 2/2] sysfs/kernfs: make read requests on pre-alloc files use the buffer NeilBrown
2014-10-09 13:52 ` Tejun Heo
2014-10-08 23:57 ` [PATCH 1/2] sysfs/kernfs: allow attributes to request write buffer be pre-allocated NeilBrown
2014-10-09 13:32 ` Tejun Heo [this message]
-- strict thread matches above, loose matches on Subject: below --
2014-10-13 5:41 [PATCH 0/2 V3] Allow access to sysfs attributes without mem allocations NeilBrown
2014-10-13 5:41 ` [PATCH 1/2] sysfs/kernfs: allow attributes to request write buffer be pre-allocated NeilBrown
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=20141009133237.GC14387@htj.dyndns.org \
--to=tj@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=neilb@suse.de \
--cc=viro@ZenIV.linux.org.uk \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox