From: Hugh Dickins <hugh@veritas.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Christoph Rohland <hans-christoph.rohland@sap.com>,
linux-kernel@vger.kernel.org
Subject: [PATCH 3/9] tmpfs: move swap swizzling into shmem
Date: Tue, 18 Dec 2007 22:00:15 +0000 (GMT) [thread overview]
Message-ID: <Pine.LNX.4.64.0712182159280.27165@blonde.wat.veritas.com> (raw)
In-Reply-To: <Pine.LNX.4.64.0712182144370.26235@blonde.wat.veritas.com>
move_to_swap_cache and move_from_swap_cache functions (which swizzle a
page between tmpfs page cache and swap cache, to avoid page copying) are
only used by shmem.c; and our subsequent fix for unionfs needs different
treatments in the two instances of move_from_swap_cache. Move them from
swap_state.c into their callsites shmem_writepage, shmem_unuse_inode and
shmem_getpage, making add_to_swap_cache externally visible.
shmem.c likes to say set_page_dirty where swap_state.c liked to say
SetPageDirty: respect that diversity, which __set_page_dirty_no_writeback
makes moot (and implies we should lose that "shift page from clean_pages
to dirty_pages list" comment: it's on neither).
Signed-off-by: Hugh Dickins <hugh@veritas.com>
---
checkpatch.pl objects to the embedded assignment in
- } else if (!(error = move_from_swap_cache(
+ } else if (!(error = add_to_page_cache(
but please let me not mess with that here.
include/linux/swap.h | 15 ++++-----------
mm/shmem.c | 16 ++++++++++++----
mm/swap_state.c | 35 +----------------------------------
3 files changed, 17 insertions(+), 49 deletions(-)
--- tmpfs2/include/linux/swap.h 2007-12-05 10:38:43.000000000 +0000
+++ tmpfs3/include/linux/swap.h 2007-12-05 16:42:18.000000000 +0000
@@ -224,11 +224,9 @@ extern struct address_space swapper_spac
#define total_swapcache_pages swapper_space.nrpages
extern void show_swap_cache_info(void);
extern int add_to_swap(struct page *, gfp_t);
+extern int add_to_swap_cache(struct page *, swp_entry_t, gfp_t);
extern void __delete_from_swap_cache(struct page *);
extern void delete_from_swap_cache(struct page *);
-extern int move_to_swap_cache(struct page *, swp_entry_t);
-extern int move_from_swap_cache(struct page *, unsigned long,
- struct address_space *);
extern void free_page_and_swap_cache(struct page *);
extern void free_pages_and_swap_cache(struct page **, int);
extern struct page *lookup_swap_cache(swp_entry_t);
@@ -323,15 +321,10 @@ static inline struct page *lookup_swap_c
#define can_share_swap_page(p) (page_mapcount(p) == 1)
-static inline int move_to_swap_cache(struct page *page, swp_entry_t entry)
+static inline int add_to_swap_cache(struct page *page, swp_entry_t entry,
+ gfp_t gfp_mask)
{
- return 1;
-}
-
-static inline int move_from_swap_cache(struct page *page, unsigned long index,
- struct address_space *mapping)
-{
- return 1;
+ return -1;
}
static inline void __delete_from_swap_cache(struct page *page)
--- tmpfs2/mm/shmem.c 2007-12-05 10:38:45.000000000 +0000
+++ tmpfs3/mm/shmem.c 2007-12-05 16:42:18.000000000 +0000
@@ -884,7 +884,9 @@ lost2:
found:
idx += offset;
inode = &info->vfs_inode;
- if (move_from_swap_cache(page, idx, inode->i_mapping) == 0) {
+ if (add_to_page_cache(page, inode->i_mapping, idx, GFP_ATOMIC) == 0) {
+ delete_from_swap_cache(page);
+ set_page_dirty(page);
info->flags |= SHMEM_PAGEIN;
shmem_swp_set(info, ptr + offset, 0);
}
@@ -972,7 +974,8 @@ static int shmem_writepage(struct page *
BUG_ON(!entry);
BUG_ON(entry->val);
- if (move_to_swap_cache(page, swap) == 0) {
+ if (add_to_swap_cache(page, swap, GFP_ATOMIC) == 0) {
+ remove_from_page_cache(page);
shmem_swp_set(info, entry, swap.val);
shmem_swp_unmap(entry);
spin_unlock(&info->lock);
@@ -982,6 +985,9 @@ static int shmem_writepage(struct page *
list_move_tail(&info->swaplist, &shmem_swaplist);
spin_unlock(&shmem_swaplist_lock);
}
+ swap_duplicate(swap);
+ page_cache_release(page); /* pagecache ref */
+ set_page_dirty(page);
unlock_page(page);
return 0;
}
@@ -1217,13 +1223,15 @@ repeat:
SetPageUptodate(filepage);
set_page_dirty(filepage);
swap_free(swap);
- } else if (!(error = move_from_swap_cache(
- swappage, idx, mapping))) {
+ } else if (!(error = add_to_page_cache(
+ swappage, mapping, idx, GFP_ATOMIC))) {
info->flags |= SHMEM_PAGEIN;
shmem_swp_set(info, entry, 0);
shmem_swp_unmap(entry);
+ delete_from_swap_cache(swappage);
spin_unlock(&info->lock);
filepage = swappage;
+ set_page_dirty(filepage);
swap_free(swap);
} else {
shmem_swp_unmap(entry);
--- tmpfs2/mm/swap_state.c 2007-12-05 16:42:16.000000000 +0000
+++ tmpfs3/mm/swap_state.c 2007-12-05 16:42:18.000000000 +0000
@@ -67,8 +67,7 @@ void show_swap_cache_info(void)
* add_to_swap_cache resembles add_to_page_cache on swapper_space,
* but sets SwapCache flag and private instead of mapping and index.
*/
-static int add_to_swap_cache(struct page *page, swp_entry_t entry,
- gfp_t gfp_mask)
+int add_to_swap_cache(struct page *page, swp_entry_t entry, gfp_t gfp_mask)
{
int error;
@@ -183,38 +182,6 @@ void delete_from_swap_cache(struct page
page_cache_release(page);
}
-/*
- * Strange swizzling function only for use by shmem_writepage
- */
-int move_to_swap_cache(struct page *page, swp_entry_t entry)
-{
- int err = add_to_swap_cache(page, entry, GFP_ATOMIC);
- if (!err) {
- remove_from_page_cache(page);
- page_cache_release(page); /* pagecache ref */
- if (!swap_duplicate(entry))
- BUG();
- SetPageDirty(page);
- }
- return err;
-}
-
-/*
- * Strange swizzling function for shmem_getpage (and shmem_unuse)
- */
-int move_from_swap_cache(struct page *page, unsigned long index,
- struct address_space *mapping)
-{
- int err = add_to_page_cache(page, mapping, index, GFP_ATOMIC);
- if (!err) {
- delete_from_swap_cache(page);
- /* shift page from clean_pages to dirty_pages list */
- ClearPageDirty(page);
- set_page_dirty(page);
- }
- return err;
-}
-
/*
* If we are the only user, then try to free up the swap cache.
*
next prev parent reply other threads:[~2007-12-18 22:01 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-12-18 21:55 [PATCH 0/9] tmpfs: towards unionfs and memcgroups Hugh Dickins
2007-12-18 21:57 ` [PATCH 1/9] tmpfs: move swap_state stats update Hugh Dickins
2007-12-18 21:59 ` [PATCH 2/9] tmpfs: shuffle add_to_swap_caches Hugh Dickins
2007-12-19 1:55 ` Nick Piggin
2007-12-18 22:00 ` Hugh Dickins [this message]
2007-12-18 22:01 ` [PATCH 4/9] tmpfs: allow filepage alongside swappage Hugh Dickins
2007-12-18 22:51 ` Erez Zadok
2007-12-19 0:30 ` Hugh Dickins
2007-12-18 22:02 ` [PATCH 5/9] tmpfs: allocate on read when stacked Hugh Dickins
2007-12-18 22:03 ` [PATCH 6/9] tmpfs: make shmem_unuse more preemptible Hugh Dickins
2007-12-18 22:04 ` [PATCH 7/9] tmpfs: open a window in shmem_unuse_inode Hugh Dickins
2007-12-18 22:05 ` [PATCH 8/9] tmpfs: radix_tree_preloading Hugh Dickins
2007-12-19 6:50 ` Nick Piggin
2007-12-18 22:06 ` [PATCH 9/9] tmpfs: fix shmem_swaplist races Hugh Dickins
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=Pine.LNX.4.64.0712182159280.27165@blonde.wat.veritas.com \
--to=hugh@veritas.com \
--cc=akpm@linux-foundation.org \
--cc=hans-christoph.rohland@sap.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
all inboxes | Powered by JetHome®