public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@osdl.org>
To: Nick Piggin <npiggin@suse.de>
Cc: torvalds@osdl.org, linux-kernel@vger.kernel.org,
	linux-scsi@vger.kernel.org
Subject: Re: [patch] sg: simplify page_count manipulations
Date: Wed, 18 Jan 2006 19:59:37 -0800	[thread overview]
Message-ID: <20060118195937.3586c94f.akpm@osdl.org> (raw)
In-Reply-To: <20060118155242.GB28418@wotan.suse.de>

Nick Piggin <npiggin@suse.de> wrote:
>
> Hi Linus,
> 
> What do you think about the following couple of patches? Hugh's had a
> look and thinks they're OK.
> 

Gad.  You're brave.

> Allocate a compound page for the user mapping instead of tweaking
> the page refcounts.
> 
> Signed-off-by: Nick Piggin <npiggin@suse.de>
> 
> Index: linux-2.6/drivers/scsi/sg.c
> ===================================================================
> --- linux-2.6.orig/drivers/scsi/sg.c
> +++ linux-2.6/drivers/scsi/sg.c
> @@ -1140,32 +1140,6 @@ sg_fasync(int fd, struct file *filp, int
>  	return (retval < 0) ? retval : 0;
>  }
>  
> -/* When startFinish==1 increments page counts for pages other than the 
> -   first of scatter gather elements obtained from alloc_pages().
> -   When startFinish==0 decrements ... */
> -static void
> -sg_rb_correct4mmap(Sg_scatter_hold * rsv_schp, int startFinish)
> -{
> -	struct scatterlist *sg = rsv_schp->buffer;
> -	struct page *page;
> -	int k, m;
> -
> -	SCSI_LOG_TIMEOUT(3, printk("sg_rb_correct4mmap: startFinish=%d, scatg=%d\n", 
> -				   startFinish, rsv_schp->k_use_sg));
> -	/* N.B. correction _not_ applied to base page of each allocation */
> -	for (k = 0; k < rsv_schp->k_use_sg; ++k, ++sg) {
> -		for (m = PAGE_SIZE; m < sg->length; m += PAGE_SIZE) {
> -			page = sg->page;
> -			if (startFinish)
> -				get_page(page);
> -			else {
> -				if (page_count(page) > 0)
> -					__put_page(page);
> -			}
> -		}
> -	}
> -}

What on earth is the above trying to do?  The inner loop is a rather
complex way of doing atomic_add(&page->count, sg->length/PAGE_SIZE).  One
suspects there's a missing "[m]" in there.

Yes, using a compound page for the refcounting sounds sane, but I think
this code is fragile and has monsters in it.


       reply	other threads:[~2006-01-19  3:59 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20060118155242.GB28418@wotan.suse.de>
2006-01-19  3:59 ` Andrew Morton [this message]
2006-01-19 14:45   ` [patch] sg: simplify page_count manipulations Nick Piggin
2006-01-19 22:05     ` Andrew Morton
2006-01-20 10:18       ` Nick Piggin
2006-01-20 10:47         ` Andrew Morton
2006-01-20 16:32           ` Hugh Dickins
2006-01-21 10:15             ` Nick Piggin

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=20060118195937.3586c94f.akpm@osdl.org \
    --to=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=npiggin@suse.de \
    --cc=torvalds@osdl.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