From: Nick Piggin <nickpiggin@yahoo.com.au>
To: David Howells <dhowells@redhat.com>
Cc: Jens Axboe <axboe@suse.de>,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] BLOCK: Make it possible to disable the block layer
Date: Fri, 25 Aug 2006 00:42:14 +1000 [thread overview]
Message-ID: <44EDBAC6.3090809@yahoo.com.au> (raw)
In-Reply-To: <32640.1156424442@warthog.cambridge.redhat.com>
David Howells wrote:
[...]
Cool. How much RAM does it save?
> --- /dev/null
> +++ b/fs/no-block.c
> @@ -0,0 +1,160 @@
> +/* no-block.c: implementation of routines required for non-BLOCK configuration
> + *
> + * Copyright (C) 2006 Red Hat, Inc. All Rights Reserved.
> + * Written by David Howells (dhowells@redhat.com)
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License
> + * as published by the Free Software Foundation; either version
> + * 2 of the License, or (at your option) any later version.
> + */
> +
> +#include <linux/kernel.h>
> +#include <linux/module.h>
> +#include <linux/fs.h>
> +#include <linux/mm.h>
> +#include <linux/mpage.h>
> +#include <linux/writeback.h>
> +#include <linux/backing-dev.h>
> +#include <linux/pagevec.h>
> +#include <linux/pagemap.h>
> +
> +/**
> + * generic_writepages - walk the list of dirty pages of the given
> + * address space and writepage() all of them.
> + *
> + * @mapping: address space structure to write
> + * @wbc: subtract the number of written pages from *@wbc->nr_to_write
> + *
> + * This is a library function, which implements the writepages()
> + * address_space_operation.
> + *
> + * If a page is already under I/O, generic_writepages() skips it, even
> + * if it's dirty. This is desirable behaviour for memory-cleaning writeback,
> + * but it is INCORRECT for data-integrity system calls such as fsync(). fsync()
> + * and msync() need to guarantee that all the data which was dirty at the time
> + * the call was made get new I/O started against them. If wbc->sync_mode is
> + * WB_SYNC_ALL then we were called for data integrity and we must wait for
> + * existing IO to complete.
> + */
> +int generic_writepages(struct address_space *mapping,
> + struct writeback_control *wbc)
This isn't the right thing to do. Even just ifdefing the bio stuff would
seem better... but you didn't seem shy about adding ifdefs in other code,
so what is the problem with doing it here?
You also forgot to put akpm in your copyright notice, fwiw.
> +{
> + struct backing_dev_info *bdi = mapping->backing_dev_info;
> + int ret = 0;
> + int done = 0;
> + int (*writepage)(struct page *page, struct writeback_control *wbc);
> + struct pagevec pvec;
> + int nr_pages;
> g+ pgoff_t index;
> + pgoff_t end; /* Inclusive */
> + int scanned = 0;
> + int range_whole = 0;
> +
> + if (wbc->nonblocking && bdi_write_congested(bdi)) {
> + wbc->encountered_congestion = 1;
> + return 0;
> + }
> +
> + writepage = mapping->a_ops->writepage;
> +
> + /* deal with chardevs and other special file */
> + if (!writepage)
> + return 0;
> +
> + pagevec_init(&pvec, 0);
> + if (wbc->range_cyclic) {
> + index = mapping->writeback_index; /* Start from prev offset */
> + end = -1;
> + } else {
> + index = wbc->range_start >> PAGE_CACHE_SHIFT;
> + end = wbc->range_end >> PAGE_CACHE_SHIFT;
> + if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
> + range_whole = 1;
> + scanned = 1;
> + }
> +retry:
> + while (!done && (index <= end) &&
> + (nr_pages = pagevec_lookup_tag(&pvec, mapping, &index,
> + PAGECACHE_TAG_DIRTY,
> + min(end - index, (pgoff_t)PAGEVEC_SIZE-1) + 1))) {
> + unsigned i;
> +
> + scanned = 1;
> + for (i = 0; i < nr_pages; i++) {
> + struct page *page = pvec.pages[i];
> +
> + /*
> + * At this point we hold neither mapping->tree_lock nor
> + * lock on the page itself: the page may be truncated or
> + * invalidated (changing page->mapping to NULL), or even
> + * swizzled back from swapper_space to tmpfs file
> + * mapping
> + */
> +
> + lock_page(page);
> +
> + if (unlikely(page->mapping != mapping)) {
> + unlock_page(page);
> + continue;
> + }
> +
> + if (!wbc->range_cyclic && page->index > end) {
> + done = 1;
> + unlock_page(page);
> + continue;
> + }
> +
> + if (wbc->sync_mode != WB_SYNC_NONE)
> + wait_on_page_writeback(page);
> +
> + if (PageWriteback(page) ||
> + !clear_page_dirty_for_io(page)) {
> + unlock_page(page);
> + continue;
> + }
> +
> + ret = (*writepage)(page, wbc);
> + if (ret) {
> + if (ret == -ENOSPC)
> + set_bit(AS_ENOSPC, &mapping->flags);
> + else
> + set_bit(AS_EIO, &mapping->flags);
> + }
> +
> + if (unlikely(ret == AOP_WRITEPAGE_ACTIVATE))
> + unlock_page(page);
> + if (ret || (--(wbc->nr_to_write) <= 0))
> + done = 1;
> + if (wbc->nonblocking && bdi_write_congested(bdi)) {
> + wbc->encountered_congestion = 1;
> + done = 1;
> + }
> + }
> + pagevec_release(&pvec);
> + cond_resched();
> + }
> + if (!scanned && !done) {
> + /*
> + * We hit the last page and there is more work to be done: wrap
> + * back to the start of the file
> + */
> + scanned = 1;
> + index = 0;
> + goto retry;
> + }
> + if (wbc->range_cyclic || (range_whole && wbc->nr_to_write > 0))
> + mapping->writeback_index = index;
> + return ret;
> +}
> +
> +EXPORT_SYMBOL(generic_writepages);
--
SUSE Labs, Novell Inc.
Send instant messages to your online friends http://au.messenger.yahoo.com
next prev parent reply other threads:[~2006-08-24 14:42 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-08-24 13:00 [PATCH] BLOCK: Make it possible to disable the block layer David Howells
2006-08-24 13:13 ` David Woodhouse
2006-08-24 13:34 ` David Howells
2006-08-24 13:40 ` David Woodhouse
2006-08-24 13:54 ` David Howells
2006-08-24 13:47 ` Christoph Hellwig
2006-08-24 14:42 ` Nick Piggin [this message]
2006-08-24 15:29 ` Adrian Bunk
2006-08-24 15:44 ` David Woodhouse
2006-08-24 15:58 ` Adrian Bunk
2006-08-24 16:00 ` David Woodhouse
2006-08-24 16:09 ` Adrian Bunk
2006-08-24 16:47 ` Alexey Dobriyan
2006-08-24 17:07 ` Adrian Bunk
2006-08-24 17:16 ` David Woodhouse
2006-08-24 17:34 ` Randy.Dunlap
2006-08-24 17:48 ` David Woodhouse
2006-08-24 17:59 ` Sam Ravnborg
2006-08-25 6:23 ` Jan Engelhardt
2006-08-25 7:19 ` Sam Ravnborg
2006-08-24 18:01 ` Randy.Dunlap
2006-08-25 6:21 ` Jan Engelhardt
2006-08-25 6:07 ` Jan Engelhardt
2006-08-25 10:37 ` Adrian Bunk
2006-08-25 13:09 ` Alexey Dobriyan
2006-08-24 16:39 ` Jan Engelhardt
2006-08-24 16:44 ` David Woodhouse
2006-08-24 16:48 ` Adrian Bunk
2006-08-24 21:31 ` Johannes Stezenbach
2006-08-25 6:04 ` Jan Engelhardt
2006-08-24 18:39 ` Matthias Schniedermeyer
2006-08-25 6:06 ` Jan Engelhardt
2006-08-24 17:18 ` David Howells
2006-08-24 17:23 ` Adrian Bunk
2006-08-24 16:23 ` Stefan Richter
2006-08-25 12:16 ` Jens Axboe
2006-08-25 13:40 ` 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=44EDBAC6.3090809@yahoo.com.au \
--to=nickpiggin@yahoo.com.au \
--cc=axboe@suse.de \
--cc=dhowells@redhat.com \
--cc=linux-fsdevel@vger.kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.