From: Jens Axboe <jens.axboe@oracle.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH 11/13] SCSI: support for allocating large scatterlists
Date: Thu, 10 May 2007 12:52:09 +0200 [thread overview]
Message-ID: <20070510105208.GN4629@kernel.dk> (raw)
In-Reply-To: <20070510034804.3caa9fa9.akpm@linux-foundation.org>
On Thu, May 10 2007, Andrew Morton wrote:
> On Thu, 10 May 2007 12:21:53 +0200 Jens Axboe <jens.axboe@oracle.com> wrote:
>
> > This is what enables large commands. If we need to allocate an
> > sgtable that doesn't fit in a single page, allocate several
> > SCSI_MAX_SG_SEGMENTS sized tables and chain them together.
> >
> > We default to the safe setup of NOT chaining, for now.
> >
> > ...
> >
> > +/*
> > + * Should fit within a single page, and must be a power-of-2.
> > + */
> > +#define SCSI_MAX_SG_SEGMENTS 128
>
> But what units is it in? Bytes? sizeof(void*)?
sg elements. It's not new, just juggled around a bit. The comment is a
bit stale now though, it doesn't have to be a pow-of-2. Ideally we just
want to make sure that sizeof(struct scatterlist) * SCSI_MAX_SG_SEGMENTS
<= PAGE_SIZE to avoid 2^1 allocations.
> > +struct scatterlist *scsi_alloc_sgtable(struct scsi_cmnd *cmd, gfp_t gfp_mask)
> > +{
> > + struct scsi_host_sg_pool *sgp;
> > + struct scatterlist *sgl, *prev, *ret;
> > + unsigned int index;
> > + int this, left;
> > +
> > + BUG_ON(!cmd->use_sg);
> > +
> > + left = cmd->use_sg;
> > + ret = prev = NULL;
> > + do {
> > + this = left;
> > + if (this > SCSI_MAX_SG_SEGMENTS) {
> > + this = SCSI_MAX_SG_SEGMENTS;
> > + index = SG_MEMPOOL_NR - 1;
> > + } else
> > + index = scsi_sgtable_index(this);
> > +
> > + left -= this;
> > +
> > + /*
> > + * if we have more entries after this round, reserve a slot
> > + * for the chain pointer.
> > + */
> > + if (left)
> > + left++;
> > +
> > + sgp = scsi_sg_pools + index;
> > +
> > + sgl = mempool_alloc(sgp->pool, gfp_mask);
> > + if (unlikely(!sgl))
> > + goto enomem;
> > +
> > + memset(sgl, 0, sizeof(*sgl) * sgp->size);
> > +
> > + /*
> > + * first loop through, set initial index and return value
> > + */
> > + if (!ret) {
> > + cmd->sglist_len = index;
> > + ret = sgl;
> > + }
> > +
> > + /*
> > + * chain previous sglist, if any. we know the previous
> > + * sglist must be the biggest one, or we would not have
> > + * ended up doing another loop.
> > + */
> > + if (prev)
> > + sg_chain(prev, SCSI_MAX_SG_SEGMENTS, sgl);
> > +
> > + /*
> > + * don't allow subsequent mempool allocs to sleep, it would
> > + * violate the mempool principle.
> > + */
> > + gfp_mask &= ~__GFP_WAIT;
>
> hrm.
>
> Might want to set __GFP_HIGH here too.
Agree, I did consider that (clear wait, set ATOMIC to get the __HIGH).
--
Jens Axboe
next prev parent reply other threads:[~2007-05-10 10:52 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-05-10 10:21 [PATCH 0/13] Chaining sg lists for bio IO commands v3 Jens Axboe
2007-05-10 10:21 ` [PATCH 1/13] crypto: don't pollute the global namespace with sg_next() Jens Axboe
2007-05-10 10:21 ` [PATCH 2/13] Add sg helpers for iterating over a scatterlist table Jens Axboe
2007-05-10 10:39 ` Andrew Morton
2007-05-10 10:42 ` Jens Axboe
2007-05-10 10:21 ` [PATCH 3/13] libata: convert to using sg helpers Jens Axboe
2007-05-10 10:21 ` [PATCH 4/13] block: " Jens Axboe
2007-05-10 10:21 ` [PATCH 5/13] scsi: " Jens Axboe
2007-05-10 10:21 ` [PATCH 6/13] i386 dma_map_sg: " Jens Axboe
2007-05-10 10:21 ` [PATCH 7/13] i386 sg: add support for chaining scatterlists Jens Axboe
2007-05-10 10:43 ` Andrew Morton
2007-05-10 10:44 ` Jens Axboe
2007-05-10 10:46 ` Jens Axboe
2007-05-10 10:52 ` Andrew Morton
2007-05-10 11:21 ` Jens Axboe
2007-05-10 10:59 ` Benny Halevy
2007-05-10 11:23 ` Jens Axboe
2007-05-10 10:21 ` [PATCH 8/13] x86-64: update iommu/dma mapping functions to sg helpers Jens Axboe
2007-05-10 10:21 ` [PATCH 9/13] [PATCH] x86-64: enable sg chaining Jens Axboe
2007-05-10 10:21 ` [PATCH 10/13] scsi: simplify scsi_free_sgtable() Jens Axboe
2007-05-10 10:21 ` [PATCH 11/13] SCSI: support for allocating large scatterlists Jens Axboe
2007-05-10 10:48 ` Andrew Morton
2007-05-10 10:52 ` Jens Axboe [this message]
2007-05-10 12:38 ` Alan Cox
2007-05-10 10:21 ` [PATCH 12/13] ll_rw_blk: temporarily enable max_segments tweaking Jens Axboe
2007-05-10 10:49 ` Andrew Morton
2007-05-10 11:20 ` Jens Axboe
2007-05-10 10:21 ` [PATCH 13/13] scsi drivers: sg chaining Jens Axboe
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=20070510105208.GN4629@kernel.dk \
--to=jens.axboe@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox