2005-12-07 10:26:24

by Wu Fengguang

[permalink] [raw]
Subject: [PATCH 12/16] mm: fold sc.may_writepage and sc.may_swap into sc.flags

Fold bool values into flags to make struct scan_control more compact.

Signed-off-by: Wu Fengguang <[email protected]>
---

mm/vmscan.c | 22 ++++++++++------------
1 files changed, 10 insertions(+), 12 deletions(-)

--- linux.orig/mm/vmscan.c
+++ linux/mm/vmscan.c
@@ -72,12 +72,12 @@ struct scan_control {
/* This context's GFP mask */
gfp_t gfp_mask;

- int may_writepage;
-
- /* Can pages be swapped as part of reclaim? */
- int may_swap;
+ unsigned long flags;
};

+#define SC_MAY_WRITEPAGE 0x1
+#define SC_MAY_SWAP 0x2 /* Can pages be swapped as part of reclaim? */
+
#define lru_to_page(_head) (list_entry((_head)->prev, struct page, lru))

#ifdef ARCH_HAS_PREFETCH
@@ -488,7 +488,7 @@ static int shrink_list(struct list_head
* Try to allocate it some swap space here.
*/
if (PageAnon(page) && !PageSwapCache(page)) {
- if (!sc->may_swap)
+ if (!(sc->flags & SC_MAY_SWAP))
goto keep_locked;
if (!add_to_swap(page, GFP_ATOMIC))
goto activate_locked;
@@ -519,7 +519,7 @@ static int shrink_list(struct list_head
goto keep_locked;
if (!may_enter_fs)
goto keep_locked;
- if (laptop_mode && !sc->may_writepage)
+ if (laptop_mode && !(sc->flags & SC_MAY_WRITEPAGE))
goto keep_locked;

/* Page is dirty, try to write it out here */
@@ -1238,8 +1238,7 @@ int try_to_free_pages(struct zone **zone
delay_prefetch();

sc.gfp_mask = gfp_mask;
- sc.may_writepage = 0;
- sc.may_swap = 1;
+ sc.flags = SC_MAY_SWAP;
sc.nr_scanned = 0;
sc.nr_reclaimed = 0;

@@ -1287,7 +1286,7 @@ int try_to_free_pages(struct zone **zone
*/
if (sc.nr_scanned > SWAP_CLUSTER_MAX * 3 / 2) {
wakeup_pdflush(laptop_mode ? 0 : sc.nr_scanned);
- sc.may_writepage = 1;
+ sc.flags |= SC_MAY_WRITEPAGE;
}

/* Take a nap, wait for some writeback to complete */
@@ -1343,8 +1342,7 @@ static int balance_pgdat(pg_data_t *pgda

loop_again:
sc.gfp_mask = GFP_KERNEL;
- sc.may_writepage = 0;
- sc.may_swap = 1;
+ sc.flags = SC_MAY_SWAP;
sc.nr_mapped = read_page_state(nr_mapped);
sc.nr_scanned = 0;
sc.nr_reclaimed = 0;
@@ -1439,7 +1437,7 @@ scan_swspd:
*/
if (sc.nr_scanned > SWAP_CLUSTER_MAX * 2 &&
sc.nr_scanned > sc.nr_reclaimed + sc.nr_reclaimed / 2)
- sc.may_writepage = 1;
+ sc.flags |= SC_MAY_WRITEPAGE;

if (nr_pages && to_free > sc.nr_reclaimed)
continue; /* swsusp: need to do more work */

--


2005-12-07 10:36:34

by Nick Piggin

[permalink] [raw]
Subject: Re: [PATCH 12/16] mm: fold sc.may_writepage and sc.may_swap into sc.flags

Wu Fengguang wrote:
> Fold bool values into flags to make struct scan_control more compact.
>

Probably not a bad idea (although you haven't done anything for 64-bit
archs, yet)... do we wait until one more flag wants to be added?

> Signed-off-by: Wu Fengguang <[email protected]>
> ---
>
> mm/vmscan.c | 22 ++++++++++------------
> 1 files changed, 10 insertions(+), 12 deletions(-)
>
> --- linux.orig/mm/vmscan.c
> +++ linux/mm/vmscan.c
> @@ -72,12 +72,12 @@ struct scan_control {
> /* This context's GFP mask */
> gfp_t gfp_mask;
>
> - int may_writepage;
> -
> - /* Can pages be swapped as part of reclaim? */
> - int may_swap;
> + unsigned long flags;
> };
>
> +#define SC_MAY_WRITEPAGE 0x1
> +#define SC_MAY_SWAP 0x2 /* Can pages be swapped as part of reclaim? */
> +
> #define lru_to_page(_head) (list_entry((_head)->prev, struct page, lru))
>
> #ifdef ARCH_HAS_PREFETCH
> @@ -488,7 +488,7 @@ static int shrink_list(struct list_head
> * Try to allocate it some swap space here.
> */
> if (PageAnon(page) && !PageSwapCache(page)) {
> - if (!sc->may_swap)
> + if (!(sc->flags & SC_MAY_SWAP))
> goto keep_locked;
> if (!add_to_swap(page, GFP_ATOMIC))
> goto activate_locked;
> @@ -519,7 +519,7 @@ static int shrink_list(struct list_head
> goto keep_locked;
> if (!may_enter_fs)
> goto keep_locked;
> - if (laptop_mode && !sc->may_writepage)
> + if (laptop_mode && !(sc->flags & SC_MAY_WRITEPAGE))
> goto keep_locked;
>
> /* Page is dirty, try to write it out here */
> @@ -1238,8 +1238,7 @@ int try_to_free_pages(struct zone **zone
> delay_prefetch();
>
> sc.gfp_mask = gfp_mask;
> - sc.may_writepage = 0;
> - sc.may_swap = 1;
> + sc.flags = SC_MAY_SWAP;
> sc.nr_scanned = 0;
> sc.nr_reclaimed = 0;
>
> @@ -1287,7 +1286,7 @@ int try_to_free_pages(struct zone **zone
> */
> if (sc.nr_scanned > SWAP_CLUSTER_MAX * 3 / 2) {
> wakeup_pdflush(laptop_mode ? 0 : sc.nr_scanned);
> - sc.may_writepage = 1;
> + sc.flags |= SC_MAY_WRITEPAGE;
> }
>
> /* Take a nap, wait for some writeback to complete */
> @@ -1343,8 +1342,7 @@ static int balance_pgdat(pg_data_t *pgda
>
> loop_again:
> sc.gfp_mask = GFP_KERNEL;
> - sc.may_writepage = 0;
> - sc.may_swap = 1;
> + sc.flags = SC_MAY_SWAP;
> sc.nr_mapped = read_page_state(nr_mapped);
> sc.nr_scanned = 0;
> sc.nr_reclaimed = 0;
> @@ -1439,7 +1437,7 @@ scan_swspd:
> */
> if (sc.nr_scanned > SWAP_CLUSTER_MAX * 2 &&
> sc.nr_scanned > sc.nr_reclaimed + sc.nr_reclaimed / 2)
> - sc.may_writepage = 1;
> + sc.flags |= SC_MAY_WRITEPAGE;
>
> if (nr_pages && to_free > sc.nr_reclaimed)
> continue; /* swsusp: need to do more work */
>

--
SUSE Labs, Novell Inc.
Send instant messages to your online friends http://au.messenger.yahoo.com

2005-12-07 10:45:16

by Wu Fengguang

[permalink] [raw]
Subject: Re: [PATCH 12/16] mm: fold sc.may_writepage and sc.may_swap into sc.flags

On Wed, Dec 07, 2005 at 09:36:23PM +1100, Nick Piggin wrote:
> Wu Fengguang wrote:
> >Fold bool values into flags to make struct scan_control more compact.
> >
>
> Probably not a bad idea (although you haven't done anything for 64-bit
> archs, yet)... do we wait until one more flag wants to be added?

I did this to hold some more debug flags :)
I'll make it a standalone patch, too.

Wu

2005-12-07 10:48:42

by Wu Fengguang

[permalink] [raw]
Subject: mm: fold sc.may_writepage and sc.may_swap into sc.flags

Fold bool values into flags to make struct scan_control more compact.

Signed-off-by: Wu Fengguang <[email protected]>
---

mm/vmscan.c | 22 ++++++++++------------
1 files changed, 10 insertions(+), 12 deletions(-)

--- linux.orig/mm/vmscan.c
+++ linux/mm/vmscan.c
@@ -72,12 +72,12 @@ struct scan_control {
/* This context's GFP mask */
gfp_t gfp_mask;

- int may_writepage;
-
- /* Can pages be swapped as part of reclaim? */
- int may_swap;
+ unsigned long flags;
};

+#define SC_MAY_WRITEPAGE 0x1
+#define SC_MAY_SWAP 0x2 /* Can pages be swapped as part of reclaim? */
+
#define lru_to_page(_head) (list_entry((_head)->prev, struct page, lru))

#ifdef ARCH_HAS_PREFETCH
@@ -488,7 +488,7 @@ static int shrink_list(struct list_head
* Try to allocate it some swap space here.
*/
if (PageAnon(page) && !PageSwapCache(page)) {
- if (!sc->may_swap)
+ if (!(sc->flags & SC_MAY_SWAP))
goto keep_locked;
if (!add_to_swap(page, GFP_ATOMIC))
goto activate_locked;
@@ -519,7 +519,7 @@ static int shrink_list(struct list_head
goto keep_locked;
if (!may_enter_fs)
goto keep_locked;
- if (laptop_mode && !sc->may_writepage)
+ if (laptop_mode && !(sc->flags & SC_MAY_WRITEPAGE))
goto keep_locked;

/* Page is dirty, try to write it out here */
@@ -1238,8 +1238,7 @@ int try_to_free_pages(struct zone **zone
delay_prefetch();

sc.gfp_mask = gfp_mask;
- sc.may_writepage = 0;
- sc.may_swap = 1;
+ sc.flags = SC_MAY_SWAP;
sc.nr_scanned = 0;
sc.nr_reclaimed = 0;

@@ -1287,7 +1286,7 @@ int try_to_free_pages(struct zone **zone
*/
if (sc.nr_scanned > SWAP_CLUSTER_MAX * 3 / 2) {
wakeup_pdflush(laptop_mode ? 0 : sc.nr_scanned);
- sc.may_writepage = 1;
+ sc.flags |= SC_MAY_WRITEPAGE;
}

/* Take a nap, wait for some writeback to complete */
@@ -1343,8 +1342,7 @@ static int balance_pgdat(pg_data_t *pgda

loop_again:
sc.gfp_mask = GFP_KERNEL;
- sc.may_writepage = 0;
- sc.may_swap = 1;
+ sc.flags = SC_MAY_SWAP;
sc.nr_mapped = read_page_state(nr_mapped);
sc.nr_scanned = 0;
sc.nr_reclaimed = 0;
@@ -1439,7 +1437,7 @@ scan_swspd:
*/
if (sc.nr_scanned > SWAP_CLUSTER_MAX * 2 &&
sc.nr_scanned > sc.nr_reclaimed + sc.nr_reclaimed / 2)
- sc.may_writepage = 1;
+ sc.flags |= SC_MAY_WRITEPAGE;

if (nr_pages && to_free > sc.nr_reclaimed)
continue; /* swsusp: need to do more work */

2005-12-07 11:12:49

by Nick Piggin

[permalink] [raw]
Subject: Re: [PATCH 12/16] mm: fold sc.may_writepage and sc.may_swap into sc.flags

Wu Fengguang wrote:
> On Wed, Dec 07, 2005 at 09:36:23PM +1100, Nick Piggin wrote:
>
>>Wu Fengguang wrote:
>>
>>>Fold bool values into flags to make struct scan_control more compact.
>>>
>>
>>Probably not a bad idea (although you haven't done anything for 64-bit
>>archs, yet)... do we wait until one more flag wants to be added?
>
>
> I did this to hold some more debug flags :)

Yes, but if they make sense for the current kernel too, it reduces
the peripheral noise out of your patchset... which helps everyone :)

> I'll make it a standalone patch, too.
>

Thanks. I don't have strong feelings either way, but I had always
been meaning to do something like this if we picked up another flag.

--
SUSE Labs, Novell Inc.

Send instant messages to your online friends http://au.messenger.yahoo.com

2005-12-07 12:39:45

by Wu Fengguang

[permalink] [raw]
Subject: Re: [PATCH 12/16] mm: fold sc.may_writepage and sc.may_swap into sc.flags

On Wed, Dec 07, 2005 at 10:12:44PM +1100, Nick Piggin wrote:
> >I did this to hold some more debug flags :)
>
> Yes, but if they make sense for the current kernel too, it reduces
> the peripheral noise out of your patchset... which helps everyone :)

Thanks. I have not been quite aware of this, sorry.

Wu

2005-12-07 17:02:27

by Martin Hicks

[permalink] [raw]
Subject: Re: mm: fold sc.may_writepage and sc.may_swap into sc.flags


On Wed, Dec 07, 2005 at 07:15:01PM +0800, Wu Fengguang wrote:
> Fold bool values into flags to make struct scan_control more compact.
>

I suspect that the may_swap flag is still a left over from my failed
attempt at zone_reclaim. It should be removed.

mh

--
Martin Hicks || [email protected] || PGP/GnuPG: 0x4C7F2BEE


Attachments:
(No filename) (320.00 B)
signature.asc (189.00 B)
Digital signature
Download all attachments

2005-12-07 23:15:17

by Andrew Morton

[permalink] [raw]
Subject: Re: mm: fold sc.may_writepage and sc.may_swap into sc.flags

Martin Hicks <[email protected]> wrote:
>
> On Wed, Dec 07, 2005 at 07:15:01PM +0800, Wu Fengguang wrote:
> > Fold bool values into flags to make struct scan_control more compact.
> >
>
> I suspect that the may_swap flag is still a left over from my failed
> attempt at zone_reclaim. It should be removed.

Yes, it can be removed, thanks. I missed that. (Patch
`kill-last-zone_reclaim-bits.patch' in -mm updated).