[linux-mm-cc] [PATCH 01/12] clean up initialization
Anderson Briglia
anderson.briglia at indt.org.br
Fri Aug 3 15:51:02 EDT 2007
Hi Munehiro,
I tried to apply this patch but I got some hunk's errors.
I'm using linux-kernel 2.6.21, patch-ccache-alpha-008-2.6.21 from CCache project's page and
UTIL-PATCH1_2-proc_entry_to_select_algo_ver2 and UTIL-PATCH2_2-proc_entry_to_select_algo_ver2 that you sent to
linux-mm-cc mailing list. Is this correct or should I apply some previous patch?
Cheers,
Anderson Briglia
ext IKEDA Munehiro wrote:
> This is code clean up patch for Ccache initialization part.
> This tries to make fs_backed and anon ccache procedures
> as symmetric as possible for readabiliby and maintenanceability.
>
> In v1, should_add_to_ccache() was left as it was and
> the number of compressed anon pages can be negative improperly.
> This version fixed the bug.
>
> Signed-off-by: IKEDA, Munehiro <m-ikeda at ds.jp.nec.com>
> ---
> include/linux/ccache.h | 3 +--
> mm/ccache.c | 47 +++++++++++++++++++++++++++++++++++------------
> mm/swapfile.c | 6 ++----
> 3 files changed, 38 insertions(+), 18 deletions(-)
>
> diff --git a/include/linux/ccache.h b/include/linux/ccache.h
> index 8aee787..31e3b49 100644
> --- a/include/linux/ccache.h
> +++ b/include/linux/ccache.h
> @@ -138,9 +138,8 @@ static inline void wait_on_chunk_head(unsigned long *flags)
> #endif
> }
>
> -extern int init_ccache(void);
> extern int is_page_in_virt_swap(struct page *page);
> -extern int set_anon_cc_size(unsigned long size);
> +extern int init_virt_swap(unsigned long size);
> extern int should_add_to_ccache(struct page *page);
> extern int cc_writepage(struct page *page);
> extern struct page* handle_ccache_fault(struct chunk_head *ch,
> diff --git a/mm/ccache.c b/mm/ccache.c
> index 2d20b2c..cf315b0 100644
> --- a/mm/ccache.c
> +++ b/mm/ccache.c
> @@ -408,7 +408,7 @@ out:
> return len;
> }
>
> -int init_ccache(void)
> +static int init_ccache(void)
> {
> if (anon_cc_started || fs_backed_cc_started) return 0;
>
> @@ -442,6 +442,24 @@ int init_ccache(void)
> return 0;
> }
>
> +static int init_anon_ccache(unsigned long num)
> +{
> + if (anon_cc_started)
> + return 0;
> +
> + init_ccache();
> + return init_virt_swap(num);
> +}
> +
> +static int init_fs_backed_ccache(unsigned long num)
> +{
> + if (fs_backed_cc_started)
> + return 0;
> +
> + init_ccache();
> + return 0;
> +}
> +
> int sysctl_max_anon_cc_size(ctl_table *table, int write,
> struct file *file, void __user *buffer, size_t *length, loff_t *ppos)
> {
> @@ -461,9 +479,13 @@ int sysctl_max_anon_cc_size(ctl_table *table, int write,
> proc_doulongvec_minmax(table, write, file, buffer, length, ppos);
> if (!write)
> goto out;
> - ret = set_anon_cc_size(max_anon_cc_size);
> - if (ret)
> +
> + ret = init_anon_ccache(max_anon_cc_size);
> + if (ret) {
> + CC_INFO("Error Initializing anon ccache");
> goto out;
> + }
> +
> CC_INFO("Max anon ccache size: %lu pages", max_anon_cc_size);
> anon_cc_started=1;
> out:
> @@ -490,15 +512,14 @@ int sysctl_max_fs_backed_cc_size(ctl_table *table, int write,
> if (!write)
> goto out;
>
> - ret = init_ccache();
> + ret = init_fs_backed_ccache(max_fs_backed_cc_size);
> if (ret) {
> - CC_INFO("Error Initializing ccache");
> + CC_INFO("Error Initializing fs_backed ccache");
> goto out;
> }
>
> CC_INFO("Max filesystem backed ccache size: %lu pages\n",
> max_fs_backed_cc_size);
> - atomic_set(&fs_backed_cc_size, 0);
> fs_backed_cc_started = 1;
> out:
> return ret;
> @@ -541,7 +562,8 @@ int should_add_to_ccache(struct page *page)
> if (anon_cc_started &&
> PageSwapCache(page) &&
> is_page_in_virt_swap(page)) {
> - return 1;
> + return atomic_add_unless(&anon_cc_size, 1,
> + max_anon_cc_size);
> }
>
> return 0;
> @@ -672,7 +694,9 @@ int cc_writepage(struct page *page)
> if (page_count(page) != 2) {
> CC_DEBUG2("(start) Page count not 2 (%d)"
> "flags=0x%08lx", page_count(page), page->flags);
> - if (!PageSwapCache(page))
> + if (PageSwapCache(page))
> + atomic_dec(&anon_cc_size);
> + else
> atomic_dec(&fs_backed_cc_size);
> return -EBUSY;
> }
> @@ -764,9 +788,6 @@ int cc_writepage(struct page *page)
> radix_tree_replace_slot((void **)slot, (void *)ch);
> CC_DEBUG2("after set slot");
>
> - if (PageSwapCache(page))
> - atomic_inc(&anon_cc_size);
> -
> /* or else it will be bad_page() when freed */
> page->mapping = NULL;
> ClearPageDirty(page);
> @@ -793,7 +814,9 @@ out_locked:
> write_unlock_irq(&mapping->tree_lock);
> CC_DEBUG2("in out_locked: after WUQ");
> out:
> - if (!PageSwapCache(page))
> + if (PageSwapCache(page))
> + atomic_dec(&anon_cc_size);
> + else
> atomic_dec(&fs_backed_cc_size);
> if (ch)
> free_chunk_head(ch);
> diff --git a/mm/swapfile.c b/mm/swapfile.c
> index f2df6b2..c94a56f 100644
> --- a/mm/swapfile.c
> +++ b/mm/swapfile.c
> @@ -1451,7 +1451,7 @@ int is_page_in_virt_swap(struct page *page)
> return 0;
> }
>
> -int set_anon_cc_size(unsigned long num_pages)
> +int init_virt_swap(unsigned long num_pages)
> {
> int i, error, prev;
> unsigned int type;
> @@ -1459,8 +1459,6 @@ int set_anon_cc_size(unsigned long num_pages)
> struct swap_info_struct *p;
> struct swap_extent *new_se;
>
> - init_ccache();
> -
> error=0;
> spin_lock(&swap_lock);
> p = swap_info;
> @@ -1542,7 +1540,7 @@ out:
> return error;
> }
>
> -EXPORT_SYMBOL(set_anon_cc_size);
> +EXPORT_SYMBOL(init_virt_swap);
>
> /*
> * Written 01/25/92 by Simmule Turner, heavily changed by Linus.
More information about the linux-mm-cc
mailing list