public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Jens Axboe <jens.axboe@oracle.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH 11/13] SCSI: support for allocating large scatterlists
Date: Thu, 10 May 2007 03:48:04 -0700	[thread overview]
Message-ID: <20070510034804.3caa9fa9.akpm@linux-foundation.org> (raw)
In-Reply-To: <11787925161084-git-send-email-jens.axboe@oracle.com>

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*)?

> +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.

> +		prev = sgl;
> +	} while (left);
> +
> +	/*
> +	 * ->use_sg may get modified after dma mapping has potentially
> +	 * shrunk the number of segments, so keep a copy of it for free.
> +	 */
> +	cmd->__use_sg = cmd->use_sg;
> +	return ret;
> +enomem:
> +	if (ret) {
> +		/*
> +		 * Free entries chained off ret. Since we were trying to
> +		 * allocate another sglist, we know that all entries are of
> +		 * the max size.
> +		 */
> +		sgp = scsi_sg_pools + SG_MEMPOOL_NR - 1;
> +		prev = &ret[SCSI_MAX_SG_SEGMENTS - 1];
> +
> +		while ((sgl = sg_chain_ptr(ret)) != NULL) {
> +			ret = &sgl[SCSI_MAX_SG_SEGMENTS - 1];
> +			mempool_free(sgl, sgp->pool);
> +		}
> +
> +		mempool_free(prev, sgp->pool);
> +	}
> +	return NULL;
>  }


  reply	other threads:[~2007-05-10 10:48 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 [this message]
2007-05-10 10:52     ` Jens Axboe
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=20070510034804.3caa9fa9.akpm@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=jens.axboe@oracle.com \
    --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