LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] SMP support for drain local pages.
@ 2004-05-26 10:39 Nigel Cunningham
  2004-05-26 22:32 ` Dave Jones
  2004-05-27 19:25 ` [PATCH] SMP support for drain local pages Pavel Machek
  0 siblings, 2 replies; 10+ messages in thread
From: Nigel Cunningham @ 2004-05-26 10:39 UTC (permalink / raw)
  To: Linux Kernel Mailing List

	From: Nigel Cunningham <ncunningham@linuxmail.org>

Hi.

This patch adds SMP support for drain_local_pages, so that suspend
implementations can drain pcp structures on all CPUs and thus accurately
determine which pages are free.

Please apply.

diff -ruN 2.6.6-current-bk/mm/page_alloc.c smp-drain-local-pages/mm/page_alloc.c
--- 2.6.6-current-bk/mm/page_alloc.c    2004-05-26 19:47:15.000000000 +1000
+++ smp-drain-local-pages/mm/page_alloc.c       2004-05-26 19:56:19.000000000 +1000
@@ -459,6 +459,24 @@
         __drain_pages(smp_processor_id());
         local_irq_restore(flags);
  }
+
+#ifdef CONFIG_SMP
+static void __smp_drain_local_pages(void * data)
+{
+       drain_local_pages();
+}
+
+void smp_drain_local_pages(void)
+{
+       smp_call_function(__smp_drain_local_pages, NULL, 0, 1);
+       drain_local_pages();
+}
+#else
+void smp_drain_local_pages(void)
+{
+       drain_local_pages();
+}
+#endif
  #endif /* CONFIG_PM */

  static void zone_statistics(struct zonelist *zonelist, struct zone *z)




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] SMP support for drain local pages.
  2004-05-26 10:39 [PATCH] SMP support for drain local pages Nigel Cunningham
@ 2004-05-26 22:32 ` Dave Jones
  2004-05-26 22:56   ` [PATCH] SMP support for drain local pages v2 Nigel Cunningham
  2004-05-27 19:25 ` [PATCH] SMP support for drain local pages Pavel Machek
  1 sibling, 1 reply; 10+ messages in thread
From: Dave Jones @ 2004-05-26 22:32 UTC (permalink / raw)
  To: Nigel Cunningham; +Cc: Linux Kernel Mailing List

On Wed, May 26, 2004 at 08:39:51PM +1000, Nigel Cunningham wrote:

 > +#ifdef CONFIG_SMP
 > +static void __smp_drain_local_pages(void * data)
 > +{
 > +       drain_local_pages();
 > +}
 > +
 > +void smp_drain_local_pages(void)
 > +{
 > +       smp_call_function(__smp_drain_local_pages, NULL, 0, 1);
 > +       drain_local_pages();
 > +}
 > +#else
 > +void smp_drain_local_pages(void)
 > +{
 > +       drain_local_pages();
 > +}
 > +#endif
 >  #endif /* CONFIG_PM */

if you use on_each_cpu() you can do away with the ifdef.
It also takes care of preemption issues.

		Dave


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] SMP support for drain local pages v2.
  2004-05-26 22:32 ` Dave Jones
@ 2004-05-26 22:56   ` Nigel Cunningham
  2004-05-26 23:26     ` Andrew Morton
  0 siblings, 1 reply; 10+ messages in thread
From: Nigel Cunningham @ 2004-05-26 22:56 UTC (permalink / raw)
  To: Dave Jones; +Cc: Linux Kernel Mailing List, Andrew Morton

Thanks Dave for educating the ignorant :>.

Is this better?

--- 2.6.6-current-bk/mm/page_alloc.c    2004-05-26 19:47:15.000000000 +1000
+++ smp-drain-local-pages/mm/page_alloc.c       2004-05-27 08:50:36.000000000 +1000
@@ -459,6 +459,20 @@
         __drain_pages(smp_processor_id());
         local_irq_restore(flags);
  }
+
+/*
+ * Spill per-cpu pages on all CPUs back into the buddy allocator.
+ * The first function is just to avoid a compiler warning.
+ */
+static void __smp_drain_local_pages(void * data)
+{
+       drain_local_pages();
+}
+
+void smp_drain_local_pages(void)
+{
+       on_each_cpu(__smp_drain_local_pages, NULL, 0, 1);
+}
  #endif /* CONFIG_PM */

  static void zone_statistics(struct zonelist *zonelist, struct zone *z)

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] SMP support for drain local pages v2.
  2004-05-26 22:56   ` [PATCH] SMP support for drain local pages v2 Nigel Cunningham
@ 2004-05-26 23:26     ` Andrew Morton
  2004-05-26 23:38       ` Nigel Cunningham
  0 siblings, 1 reply; 10+ messages in thread
From: Andrew Morton @ 2004-05-26 23:26 UTC (permalink / raw)
  To: Nigel Cunningham; +Cc: davej, linux-kernel

Nigel Cunningham <ncunningham@linuxmail.org> wrote:
>
> +/*
> + * Spill per-cpu pages on all CPUs back into the buddy allocator.
> + * The first function is just to avoid a compiler warning.
> + */
> +static void __smp_drain_local_pages(void * data)
> +{
> +       drain_local_pages();
> +}
> +
> +void smp_drain_local_pages(void)
> +{
> +       on_each_cpu(__smp_drain_local_pages, NULL, 0, 1);
> +}

I think we only need a single entry point.  Make it a new "drain_percpu_pages()"
or such to break unconverted callers, switch callers of drain_local_pages()
over to the new function.   It needs no SMP ifdefs in it - on_each_cpu() will
do the right thing on UP.

But until something which needs this change is merged into the tree I'd say
that this patch should live with the patch which requires it.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] SMP support for drain local pages v2.
  2004-05-26 23:26     ` Andrew Morton
@ 2004-05-26 23:38       ` Nigel Cunningham
  2004-05-26 23:56         ` Andrew Morton
  2004-05-27 19:29         ` Pavel Machek
  0 siblings, 2 replies; 10+ messages in thread
From: Nigel Cunningham @ 2004-05-26 23:38 UTC (permalink / raw)
  To: Andrew Morton; +Cc: davej, linux-kernel

Hi.

Andrew Morton wrote:
> I think we only need a single entry point.  Make it a new "drain_percpu_pages()"
> or such to break unconverted callers, switch callers of drain_local_pages()
> over to the new function.   It needs no SMP ifdefs in it - on_each_cpu() will
> do the right thing on UP.
> 
> But until something which needs this change is merged into the tree I'd say
> that this patch should live with the patch which requires it.

CPU hotplugging uses drain_local_pages, and shouldn't drain the pcp lists for all cpus. That's why I 
left the original version alone.

I'm submitting it now in preparation for merging, but Pavel's work on SMP support for swsusp should 
be using this too. (It's not, but it should be).

Nigel
-- 
Nigel & Michelle Cunningham
C/- Westminster Presbyterian Church Belconnen
61 Templeton Street, Cook, ACT 2614.
+61 (2) 6251 7727(wk); +61 (2) 6254 0216 (home)

Evolution (n): A hypothetical process whereby infinitely improbable events occur
with alarming frequency, order arises from chaos, and no one is given credit.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] SMP support for drain local pages v2.
  2004-05-26 23:56         ` Andrew Morton
@ 2004-05-26 23:56           ` Nigel Cunningham
  0 siblings, 0 replies; 10+ messages in thread
From: Nigel Cunningham @ 2004-05-26 23:56 UTC (permalink / raw)
  To: Andrew Morton; +Cc: davej, linux-kernel

Andrew Morton wrote:
> Nigel Cunningham <ncunningham@linuxmail.org> wrote:
>>CPU hotplugging uses drain_local_pages,
> Early versions did, but not now.

Oh. Okay. :>

Nigel
-- 
Nigel & Michelle Cunningham
C/- Westminster Presbyterian Church Belconnen
61 Templeton Street, Cook, ACT 2614.
+61 (2) 6251 7727(wk); +61 (2) 6254 0216 (home)

Evolution (n): A hypothetical process whereby infinitely improbable events occur
with alarming frequency, order arises from chaos, and no one is given credit.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] SMP support for drain local pages v2.
  2004-05-26 23:38       ` Nigel Cunningham
@ 2004-05-26 23:56         ` Andrew Morton
  2004-05-26 23:56           ` Nigel Cunningham
  2004-05-27 19:29         ` Pavel Machek
  1 sibling, 1 reply; 10+ messages in thread
From: Andrew Morton @ 2004-05-26 23:56 UTC (permalink / raw)
  To: Nigel Cunningham; +Cc: davej, linux-kernel

Nigel Cunningham <ncunningham@linuxmail.org> wrote:
>
> Hi.
> 
> Andrew Morton wrote:
> > I think we only need a single entry point.  Make it a new "drain_percpu_pages()"
> > or such to break unconverted callers, switch callers of drain_local_pages()
> > over to the new function.   It needs no SMP ifdefs in it - on_each_cpu() will
> > do the right thing on UP.
> > 
> > But until something which needs this change is merged into the tree I'd say
> > that this patch should live with the patch which requires it.
> 
> CPU hotplugging uses drain_local_pages,

Early versions did, but not now.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] SMP support for drain local pages.
  2004-05-26 10:39 [PATCH] SMP support for drain local pages Nigel Cunningham
  2004-05-26 22:32 ` Dave Jones
@ 2004-05-27 19:25 ` Pavel Machek
  1 sibling, 0 replies; 10+ messages in thread
From: Pavel Machek @ 2004-05-27 19:25 UTC (permalink / raw)
  To: Nigel Cunningham; +Cc: Linux Kernel Mailing List

Hi!

> This patch adds SMP support for drain_local_pages, so that suspend
> implementations can drain pcp structures on all CPUs and thus 
> accurately
> determine which pages are free.

Why do you need it, btw?

1st it might be easier to just on_each_cpu(drain_local_pages)
in suspend2

2nd all but one cpus are stopped, right? That mrans that their local pages can't
mess up suspnd's accounting => no need to drain them.
				Pavel

2.6.6-current-bk/mm/page_alloc.c 
> smp-drain-local-pages/mm/page_alloc.c
> --- 2.6.6-current-bk/mm/page_alloc.c    2004-05-26 19:47:15.000000000 
> +1000
> +++ smp-drain-local-pages/mm/page_alloc.c       2004-05-26 
> 19:56:19.000000000 +1000
> @@ -459,6 +459,24 @@
>         __drain_pages(smp_processor_id());
>         local_irq_restore(flags);
>  }
> +
> +#ifdef CONFIG_SMP
> +static void __smp_drain_local_pages(void * data)
> +{
> +       drain_local_pages();
> +}
> +
> +void smp_drain_local_pages(void)
> +{
> +       smp_call_function(__smp_drain_local_pages, NULL, 0, 1);
> +       drain_local_pages();
> +}
> +#else
> +void smp_drain_local_pages(void)
> +{
> +       drain_local_pages();
> +}
> +#endif
>  #endif /* CONFIG_PM */
> 
>  static void zone_statistics(struct zonelist *zonelist, struct zone 
>  *z)
> 
> 
> 
> -
> To unsubscribe from this list: send the line "unsubscribe 
> linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/

-- 
64 bytes from 195.113.31.123: icmp_seq=28 ttl=51 time=448769.1 ms         


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] SMP support for drain local pages v2.
  2004-05-26 23:38       ` Nigel Cunningham
  2004-05-26 23:56         ` Andrew Morton
@ 2004-05-27 19:29         ` Pavel Machek
  2004-05-27 21:22           ` Nigel Cunningham
  1 sibling, 1 reply; 10+ messages in thread
From: Pavel Machek @ 2004-05-27 19:29 UTC (permalink / raw)
  To: Nigel Cunningham; +Cc: Andrew Morton, davej, linux-kernel

Hi!

> >But until something which needs this change is merged into the tree 
> >I'd say
> >that this patch should live with the patch which requires it.
> 
> CPU hotplugging uses drain_local_pages, and shouldn't drain the pcp 
> lists for all cpus. That's why I left the original version alone.
> 
> I'm submitting it now in preparation for merging, but Pavel's work on 
> SMP support for swsusp should be using this too. (It's not, but it 
> should be).

drain_local_pages was there so that accounting is not
screwed by local pages. That should be non-issue for stopped cpus.

OTOH you are right that my swsusp with smp does not work
on my smp machine, and I do not yet know why.
-- 
64 bytes from 195.113.31.123: icmp_seq=28 ttl=51 time=448769.1 ms         


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] SMP support for drain local pages v2.
  2004-05-27 19:29         ` Pavel Machek
@ 2004-05-27 21:22           ` Nigel Cunningham
  0 siblings, 0 replies; 10+ messages in thread
From: Nigel Cunningham @ 2004-05-27 21:22 UTC (permalink / raw)
  To: Pavel Machek; +Cc: Andrew Morton, davej, linux-kernel

Hi.

Andrew, Dave: do you want to be cc'd still?

Pavel Machek wrote:
> drain_local_pages was there so that accounting is not
> screwed by local pages. That should be non-issue for stopped cpus.

You're probably right that it's not absolutely necessary. That said, I have three reasons for 
wanting to do it: each cpu has say 200 pages in its pcp structs (this varies with zone size). If we 
don't drain them, we're saving 200 extra pages (because they're not marked as free). That's fine for 
a dual CPU system, but it's not very scalable. (I admit I wouldn't want to suspend to disk a 4GB 
machine now, but in the future?).

More than that, though, my real motivation is to be able to account for every page in the system and 
ensure that suspend is doing the right thing with all of them. If I drain the PCP page lists, I can 
be more certain that allocations do come from the right place.

Thirdly, after suspending hot pages aren't really hot anymore. We may as well start with clean lists.

> 
> OTOH you are right that my swsusp with smp does not work
> on my smp machine, and I do not yet know why.

I found that I needed to:
- save context for other CPUs.
- ensure they're completely idle during copyback even running the idle thread messed things up (use 
a smp function)
- ensure suspend is always running on CPU0 (at the start of suspending and resuming)

You might also consider how you're restoring highmem pages and how that interacts with SMP esp in 
flushing tlbs.

Nigel
-- 
Nigel & Michelle Cunningham
C/- Westminster Presbyterian Church Belconnen
61 Templeton Street, Cook, ACT 2614.
+61 (2) 6251 7727(wk); +61 (2) 6254 0216 (home)

Evolution (n): A hypothetical process whereby infinitely improbable events occur
with alarming frequency, order arises from chaos, and no one is given credit.

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2004-05-27 21:29 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-05-26 10:39 [PATCH] SMP support for drain local pages Nigel Cunningham
2004-05-26 22:32 ` Dave Jones
2004-05-26 22:56   ` [PATCH] SMP support for drain local pages v2 Nigel Cunningham
2004-05-26 23:26     ` Andrew Morton
2004-05-26 23:38       ` Nigel Cunningham
2004-05-26 23:56         ` Andrew Morton
2004-05-26 23:56           ` Nigel Cunningham
2004-05-27 19:29         ` Pavel Machek
2004-05-27 21:22           ` Nigel Cunningham
2004-05-27 19:25 ` [PATCH] SMP support for drain local pages Pavel Machek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).