linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: David Howells <dhowells@redhat.com>
To: Jesper Dangaard Brouer <brouer@redhat.com>
Cc: dhowells@redhat.com, Christoph Lameter <cl@linux.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-mm <linux-mm@kvack.org>
Subject: Re: Bulk kmalloc
Date: Fri, 10 May 2019 17:23:23 +0100	[thread overview]
Message-ID: <3261.1557505403@warthog.procyon.org.uk> (raw)
In-Reply-To: <20190510135031.1e8908fd@carbon>

Jesper Dangaard Brouer <brouer@redhat.com> wrote:

> > Is it possible to use kmem_cache_alloc_bulk() with kmalloc slabs to
> > effect a bulk kmalloc?
> 
> Well, we have kfree_bulk() which is a simple wrapper around
> kmem_cache_free_bulk() (as Christoph make me handle that case).
> 
> We/I didn't code the kmalloc_bulk() variant.
> 
> What is you use case?

afs_do_lookup() allocates an array of file status records and an array of
callback records:

	/* Need space for examining all the selected files */
	inode = ERR_PTR(-ENOMEM);
	cookie->statuses = kcalloc(cookie->nr_fids, sizeof(struct afs_file_status),
				   GFP_KERNEL);
	if (!cookie->statuses)
		goto out;

	cookie->callbacks = kcalloc(cookie->nr_fids, sizeof(struct afs_callback),
				    GFP_KERNEL);
	if (!cookie->callbacks)
		goto out_s;

These, however, may go to order-1 allocations or higher if nr_fids > 39, say,
and it may be as many as 50 for AFS3 or 1024 for YFS.

Also, I'd like to combine the afs_file_status record with the afs_callback
record inside another struct so that I can pass these around in more places
and fix the locking over applying them to the relevant inodes.

So what I want to do is to allocate an array of pointers to {status,callback}
records and then bulk allocate those records.  As it happens, the tuple is
just shy of 128 bytes, so they should fit into that slab very nicely.

Note also that the records are transient - they're freed at the end of the
operation.

David


  parent reply	other threads:[~2019-05-10 16:23 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <14647.1557415738@warthog.procyon.org.uk>
2019-05-10 11:50 ` Bulk kmalloc Jesper Dangaard Brouer
2019-05-10 16:23 ` David Howells [this message]
2019-05-10 16:50   ` Matthew Wilcox
2019-05-10 17:11     ` Christoph Hellwig
2019-05-10 17:35       ` Matthew Wilcox
2019-05-13 12:04   ` David Howells

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=3261.1557505403@warthog.procyon.org.uk \
    --to=dhowells@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=brouer@redhat.com \
    --cc=cl@linux.com \
    --cc=linux-mm@kvack.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).