2.6.30-rc2-git2: Reported regressions from 2.6.29
Subsystems (13)
This message contains a list of some regressions from 2.6.29, for which there are no fixes in the mainline I know of. If any of them have been fixed already, please let me know.
If you know of any other unresolved regressions from 2.6.29, please let me know either and I'll add them to the list. Also, please let me know if any of the entries below are invalid.
Each entry from the list will be sent additionally in an automatic reply to this message with CCs to the people involved in reporting and handling the issue.
Listed regressions statistics:
Date Total Pending Unresolved
----------------------------------------
2009-04-17 37 35 28
Unresolved regressions
----------------------
Bug-Entry : http://bugzilla.kernel.org/show_bug.cgi?id=13126
Subject : BUG: MAX_LOCKDEP_ENTRIES too low! when mounting rootfs
Submitter : Alexander Beregalov <[email protected]>
Date : 2009-04-15 12:43 (2 days old)
References : http://marc.info/?l=linux-kernel&m=123979949820538&w=4
Bug-Entry : http://bugzilla.kernel.org/show_bug.cgi?id=13125
Subject : active uvcvideo breaks over suspend
Submitter : Alan Jenkins <[email protected]>
Date : 2009-04-15 10:12 (2 days old)
References : http://marc.info/?l=linux-kernel&m=123979009508840&w=4
Bug-Entry : http://bugzilla.kernel.org/show_bug.cgi?id=13124
Subject : ioatdma: DMA-API: device driver frees DMA memory with wrong function
Submitter : Alexander Beregalov <[email protected]>
Date : 2009-04-09 12:36 (8 days old)
References : http://marc.info/?l=linux-kernel&m=123928064322503&w=4
Bug-Entry : http://bugzilla.kernel.org/show_bug.cgi?id=13122
Subject : reiserfs_delete_xattrs: Couldn't delete all xattrs (-13)
Submitter : Alexander Beregalov <[email protected]>
Date : 2009-04-16 19:23 (1 days old)
References : http://marc.info/?l=linux-kernel&m=123990989515105&w=4
Bug-Entry : http://bugzilla.kernel.org/show_bug.cgi?id=13121
Subject : commit 1a7c618a3f7bef1a20ae740df512eeba21397fa5 breaks ACPI video
Submitter : Maxim Levitsky <[email protected]>
Date : 2009-04-16 11:37 (1 days old)
First-Bad-Commit: http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=1a7c618a3f7bef1a20ae740df512eeba21397fa5
References : http://marc.info/?l=linux-kernel&m=123988189401913&w=4
Bug-Entry : http://bugzilla.kernel.org/show_bug.cgi?id=13119
Subject : Trouble with make-install from a NFS mount
Submitter : Gregory Haskins <[email protected]>
Date : 2009-04-14 21:32 (3 days old)
References : http://marc.info/?l=linux-kernel&m=123974482327044&w=4
Bug-Entry : http://bugzilla.kernel.org/show_bug.cgi?id=13118
Subject : iptables very slow after commit 784544739a25c30637397ace5489eeb6e15d7d49
Submitter : Jeff Chua <[email protected]>
Date : 2009-04-10 16:05 (7 days old)
References : http://lkml.org/lkml/2009/4/10/111
Bug-Entry : http://bugzilla.kernel.org/show_bug.cgi?id=13116
Subject : Can't boot with nosmp
Submitter : Stephen Hemminger <[email protected]>
Date : 2009-04-15 4:18 (2 days old)
References : http://marc.info/?l=linux-kernel&m=123976917817920&w=4
Bug-Entry : http://bugzilla.kernel.org/show_bug.cgi?id=13114
Subject : USB storage (usbstick) automount woes
Submitter : Mike Galbraith <[email protected]>
Date : 2009-04-09 9:26 (8 days old)
First-Bad-Commit: http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=e6e244b6cb1f70e7109381626293cd40a8334ed3
References : http://marc.info/?l=linux-kernel&m=123926928907568&w=4
Bug-Entry : http://bugzilla.kernel.org/show_bug.cgi?id=13112
Subject : Oops in drain_array
Submitter : Bart <mmx-G/[email protected]>
Date : 2009-04-14 10:21 (3 days old)
References : http://marc.info/?l=linux-kernel&m=123970493224628&w=4
Bug-Entry : http://bugzilla.kernel.org/show_bug.cgi?id=13111
Subject : Linux 2.6.30-rc1 tg3 endian issues with MAC addresses on BCM5701
Submitter : Robin Holt <holt-sJ/[email protected]>
Date : 2009-04-08 7:12 (9 days old)
First-Bad-Commit: http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=e4f341103e4a2b35f56a0f89802f1b1448e8d04b
References : http://marc.info/?l=linux-kernel&m=123917477312823&w=4
Bug-Entry : http://bugzilla.kernel.org/show_bug.cgi?id=13110
Subject : 2.6.30-rc1 problems with firmware loading
Submitter : Ben Castricum <mail0904-YLO5ZLKhJ/U/fZsR/[email protected]>
Date : 2009-04-12 6:20 (5 days old)
References : http://marc.info/?l=linux-kernel&m=123951774919978&w=4
Bug-Entry : http://bugzilla.kernel.org/show_bug.cgi?id=13109
Subject : High latency on /sys/class/thermal
Submitter : Tiago Simões Batista <[email protected]>
Date : 2009-04-11 14:56 (6 days old)
References : http://marc.info/?l=linux-kernel&m=123946182301248&w=4
Bug-Entry : http://bugzilla.kernel.org/show_bug.cgi?id=13108
Subject : 2.6.30-rc1: white screen during boot (regression) on spitz
Submitter : Pavel Machek <[email protected]>
Date : 2009-04-10 10:34 (7 days old)
References : http://marc.info/?l=linux-kernel&m=123935954223418&w=4
Bug-Entry : http://bugzilla.kernel.org/show_bug.cgi?id=13107
Subject : LTP 20080131 causes defunct processes w/2.6.30-rc1
Submitter : Kumar Gala <[email protected]>
Date : 2009-04-09 15:43 (8 days old)
First-Bad-Commit: http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=b3bfa0cba867f23365b81658b47efd906830879b
References : http://marc.info/?l=linux-kernel&m=123929187208953&w=4
Bug-Entry : http://bugzilla.kernel.org/show_bug.cgi?id=13106
Subject : 2.6.30-rc1: intel 3945 no wireless
Submitter : 2.6.30-rc1: intel 3945 no wireless
Date : 2009-04-08 5:36 (9 days old)
References : http://marc.info/?l=linux-kernel&m=123916905605534&w=4
Bug-Entry : http://bugzilla.kernel.org/show_bug.cgi?id=13101
Subject : BUG: scheduling while atomic: swapper/0/0x10000100
Submitter : Maciej Rutecki <[email protected]>
Date : 2009-04-07 7:37 (10 days old)
References : http://marc.info/?l=linux-kernel&m=123908995822195&w=4
Bug-Entry : http://bugzilla.kernel.org/show_bug.cgi?id=13099
Subject : net, sky2: BUG: unable to handle kernel NULL pointer dereference, pci_vpd_truncate()
Submitter : Ingo Molnar <[email protected]>
Date : 2009-04-06 9:03 (11 days old)
References : http://marc.info/?l=linux-kernel&m=123900867611321&w=4
Bug-Entry : http://bugzilla.kernel.org/show_bug.cgi?id=13098
Subject : 2.6.29-git12 breaks vga=0x0f07 on MSI/Intel GPU
Submitter : Andi Kleen <andi-Vw/[email protected]>
Date : 2009-04-06 01:14 (11 days old)
References : http://lkml.org/lkml/2009/4/5/200
Bug-Entry : http://bugzilla.kernel.org/show_bug.cgi?id=13097
Subject : Kernel will freeze network after using a tun/tap device
Submitter : Dâniel Fraga <[email protected]>
Date : 2009-04-15 22:19 (2 days old)
Bug-Entry : http://bugzilla.kernel.org/show_bug.cgi?id=13087
Subject : boot hang due to commit ff69f2bba67bd45514923aaedbf40fe351787c59
Submitter : Bruno <[email protected]>
Date : 2009-04-14 17:51 (3 days old)
First-Bad-Commit: http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=ff69f2bba67bd45514923aaedbf40fe351787c59
Bug-Entry : http://bugzilla.kernel.org/show_bug.cgi?id=13069
Subject : regression in 2.6.29-git3 on SH/Dreamcast
Submitter : Adrian McMenamin <[email protected]>
Date : 2009-03-29 19:04 (19 days old)
References : http://marc.info/?l=linux-kernel&m=123835353115372&w=4
Bug-Entry : http://bugzilla.kernel.org/show_bug.cgi?id=13068
Subject : Lockdep warining in inotify_dev_queue_event
Submitter : Sachin Sant <[email protected]>
Date : 2009-04-05 12:37 (12 days old)
References : http://marc.info/?l=linux-kernel&m=123893439229272&w=4
Bug-Entry : http://bugzilla.kernel.org/show_bug.cgi?id=13067
Subject : iwl3945: wlan0: beacon loss from AP - sending probe request
Submitter : Maciej Rutecki <[email protected]>
Date : 2009-04-05 9:11 (12 days old)
References : http://marc.info/?l=linux-kernel&m=123892272218266&w=4
Bug-Entry : http://bugzilla.kernel.org/show_bug.cgi?id=13066
Subject : Intel HD Audio oops
Submitter : Jeff Chua <[email protected]>
Date : 2009-04-01 8:28 (16 days old)
References : http://marc.info/?l=linux-kernel&m=123857454625829&w=4
Bug-Entry : http://bugzilla.kernel.org/show_bug.cgi?id=13058
Subject : First hibernation attempt fails
Submitter : Alan Jenkins <[email protected]>
Date : 2009-04-10 10:58 (7 days old)
First-Bad-Commit: http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=1faa16d22877f4839bd433547d770c676d1d964c
References : http://marc.info/?l=linux-kernel&m=123928022321917&w=2
Bug-Entry : http://bugzilla.kernel.org/show_bug.cgi?id=13044
Subject : 2.6.30-rc1 can't find the root fs
Submitter : Heinz Diehl <htd-HjJ2MNWy62to6+H+lsi3Gti2O/[email protected]>
Date : 2009-04-08 13:35 (9 days old)
Bug-Entry : http://bugzilla.kernel.org/show_bug.cgi?id=13031
Subject : Deadlock/hang in SATA probe
Submitter : Petr Vandrovec <[email protected]>
Date : 2009-04-06 23:33 (11 days old)
Regressions with patches
------------------------
Bug-Entry : http://bugzilla.kernel.org/show_bug.cgi?id=13123
Subject : 20 ACPI interrupts per second on EEEPC 4G
Submitter : Alan Jenkins <[email protected]>
Date : 2009-04-12 15:54 (5 days old)
References : http://marc.info/?l=linux-kernel&m=123955169317870&w=4
Patch : http://marc.info/?l=linux-kernel&m=123973665713690&w=4
Bug-Entry : http://bugzilla.kernel.org/show_bug.cgi?id=13120
Subject : BUG: using rootfstype=ext4 causes oops
Submitter : Andrew Price <andy-QvJ1taJFSUQwEI6hhNFqhFpr/1R2p/[email protected]>
Date : 2009-04-15 20:59 (2 days old)
References : http://marc.info/?l=linux-kernel&m=123982932807371&w=4
Patch : http://marc.info/?l=linux-kernel&m=123991090816794&w=4
Bug-Entry : http://bugzilla.kernel.org/show_bug.cgi?id=13115
Subject : microcode driver newly spews warnings
Submitter : Jeff Garzik <[email protected]>
Date : 2009-04-13 18:23 (4 days old)
References : http://marc.info/?l=linux-kernel&m=123964711725007&w=4
Patch : http://marc.info/?l=linux-kernel&m=123980715900884&w=4
Bug-Entry : http://bugzilla.kernel.org/show_bug.cgi?id=13113
Subject : tiobench read 50% regression with 2.6.30-rc1
Submitter : Zhang, Yanmin <yanmin_zhang-VuQAYsv1563Yd54FQh9/[email protected]>
Date : 2009-04-09 8:29 (8 days old)
References : http://marc.info/?l=linux-kernel&m=123926576802992&w=4
Patch : http://marc.info/?l=linux-kernel&m=123971130800697&w=4
Bug-Entry : http://bugzilla.kernel.org/show_bug.cgi?id=13096
Subject : 2.6.30-rc2 hangs in get_measured_perf on tigerton
Submitter : Zhang, Yanmin <yanmin_zhang-VuQAYsv1563Yd54FQh9/[email protected]>
Date : 2009-04-15 14:01 (2 days old)
References : http://lkml.org/lkml/2009/4/15/34
Patch : http://lkml.org/lkml/2009/4/15/355
Bug-Entry : http://bugzilla.kernel.org/show_bug.cgi?id=13095
Subject : thinkpad-acpi: cannot control brightness with hotkeys
Submitter : Niel Lambrechts <[email protected]>
Date : 2009-04-11 23:07 (6 days old)
References : http://lkml.org/lkml/2009/4/11/160
Patch : http://lkml.org/lkml/2009/4/15/339
Bug-Entry : http://bugzilla.kernel.org/show_bug.cgi?id=13048
Subject : /sys/class/backlight/acpi_video0/* is gone on vaio laptop with Intel GM45.
Submitter : Rodrigo L. Batista <[email protected]>
Date : 2009-04-09 04:57 (8 days old)
Patch : http://bugzilla.kernel.org/attachment.cgi?id=20967
http://bugzilla.kernel.org/attachment.cgi?id=20959
For details, please visit the bug entries and follow the links given in references.
As you can see, there is a Bugzilla entry for each of the listed regressions. There also is a Bugzilla entry used for tracking the regressions from 2.6.29, unresolved as well as resolved, at:
http://bugzilla.kernel.org/show_bug.cgi?id=13070
Please let me know if there are any Bugzilla entries that should be added to the list in there.
Thanks,
Rafael
[Bug #13058] First hibernation attempt fails
This message has been generated automatically as a part of a report of recent regressions.
The following bug entry is on the current list of known regressions from 2.6.29. Please verify if it still should be listed and let me know (either way).
Bug-Entry : http://bugzilla.kernel.org/show_bug.cgi?id=13058
Subject : First hibernation attempt fails
Submitter : Alan Jenkins <[email protected]>
Date : 2009-04-10 10:58 (7 days old)
First-Bad-Commit: http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=1faa16d22877f4839bd433547d770c676d1d964c
References : http://marc.info/?l=linux-kernel&m=123928022321917&w=2
Re: [Bug #13058] First hibernation attempt fails
Quoted 8 lines · Rafael J. Wysocki
This message has been generated automatically as a part of a report of recent regressions.
The following bug entry is on the current list of known regressions from 2.6.29. Please verify if it still should be listed and let me know (either way).
Quoted 6 lines
Bug-Entry : http://bugzilla.kernel.org/show_bug.cgi?id=13058
Subject : First hibernation attempt fails
Submitter : Alan Jenkins <[email protected]>
Date : 2009-04-10 10:58 (7 days old)
First-Bad-Commit: http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=1faa16d22877f4839bd433547d770c676d1d964c
References : http://marc.info/?l=linux-kernel&m=123928022321917&w=2
Alan, is this still a problem?
Signature · 1 line
Jens Axboe
Re: [Bug #13058] First hibernation attempt fails
Quoted 18 lines · Jens Axboe
Quoted 8 lines · Rafael J. Wysocki
This message has been generated automatically as a part of a report of recent regressions.
The following bug entry is on the current list of known regressions from 2.6.29. Please verify if it still should be listed and let me know (either way).
Quoted 7 lines
Bug-Entry : http://bugzilla.kernel.org/show_bug.cgi?id=13058
Subject : First hibernation attempt fails
Submitter : Alan Jenkins <[email protected]>
Date : 2009-04-10 10:58 (7 days old)
First-Bad-Commit: http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=1faa16d22877f4839bd433547d770c676d1d964c
References : http://marc.info/?l=linux-kernel&m=123928022321917&w=2
Quoted 2 lines
Alan, is this still a problem?
Yup. Still present in v2.6.30-rc2-195-g9f76208.
Re: [Bug #13058] First hibernation attempt fails
Quoted 19 lines · Alan Jenkins
Quoted 18 lines · Jens Axboe
Quoted 15 lines · Rafael J. Wysocki
This message has been generated automatically as a part of a report of recent regressions.
The following bug entry is on the current list of known regressions from 2.6.29. Please verify if it still should be listed and let me know (either way).
Bug-Entry : http://bugzilla.kernel.org/show_bug.cgi?id=13058
Subject : First hibernation attempt fails
Submitter : Alan Jenkins <[email protected]>
Date : 2009-04-10 10:58 (7 days old)
First-Bad-Commit: http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=1faa16d22877f4839bd433547d770c676d1d964c
References : http://marc.info/?l=linux-kernel&m=123928022321917&w=2
Quoted 4 lines
Quoted 2 lines
Alan, is this still a problem?
Yup. Still present in v2.6.30-rc2-195-g9f76208.
Given the somewhat odd nature of the bug and the requirements to trigger it, how confident are you in the bisection results?
I'll try and reproduce it here.
Signature · 1 line
Jens Axboe
Re: [Bug #13058] First hibernation attempt fails
Quoted 3 lines · Jens Axboe
Given the somewhat odd nature of the bug and the requirements to trigger it, how confident are you in the bisection results?
I suspect it's timing-dependent.
The failure case is a ENOMEM returned from the "echo disk > /sys/power/state", and sadly there are a _lot_ of potential sources of ENOMEM's in the path. And a numbe of them come from GFP_ATOMIC allocations etc.
Now, that explains why it only happens while in X (more memory being used), and also why it succeeds the second time (the first try will have triggered VM activity and then free'd the pages it allocated up to that point).
IOW, I bet it would work on the first try if you were to just run something like
ptr = malloc(BIGNUM); memset(ptr, 0, BIGNUM); exit(0);
first - just to make room for stuff.
And the thing is, swsusp_save() really does do odd things. For example, to get rid of unnecessary memory, it does "drain_local_pages()", where the "local" is "local cpu". Why does it do that? Likely nobody knows.
Now, that won't matter in Alan's case (he is UP), but the point is, the swsuspend code does these random things to try to free up memory, and I suspect it's mostly been a trial-and-error thing. And then subtle changes in memory usage when allocating or writing things out will change things.
For example, there is a magic "PAGES_FOR_IO" #define, which is somewhat arbitrarily set to 4MB worth of pages. Where did that number come from? Who knows? But that's the number the code uses for the _initial_ check of "do we have enough memory" (the one that must have passed, since it actually started doing things and didn't print out a warning message).
Anyway, from the dmesg, we can see:
[ 41.873619] PM: Shrinking memory... Restarting tasks ... done.
and this is a clear indication that it's "swsusp_shrink_memory()" that failed. If it had succeeded, you'd have seen
PM: Shrinking memory... done (xyz pages freed)
but it returned an error case, and then the suspend fails and starts restarting tasks.
And the thing is, that "swsusp_shrink_memory()" is just full of heuristics. There's no hard numbers there. It doesn't seem to wait for writeout, it just does the equivalent of "shrink_list()" and "shrink_slab()", but it seems to have been basically cribbed half-way from the regular "try to free memory", without really doing it all.
Just as an example: it does that "zone_is_all_unreclaimable()" logic that expects kswapd to mark things reclaimable again, but it doesn't seem to actually ever wait for kswapd or pdflush. It also seems to set "swappiness" to zero etc. Maybe it's all intentional, but it does mean that it uses some shared heuristics with the "real" VM, but uses them differently.
Linus
Pavel Machek
AppliedRe: [Bug #13058] First hibernation attempt fails
Hi!
Quoted 3 lines
And the thing is,
swsusp_save()really does do odd things. For example, to get rid of unnecessary memory, it does "drain_local_pages()", where the "local" is "local cpu". Why does it do that? Likely nobody knows.
I do :-). atomic image copying needs to copy any and all used pages, and needs to know beforehand how many to copy. local pages are strange in this area, so we just get rid of them to simplify stuff.
Quoted 4 lines
For example, there is a magic "
PAGES_FOR_IO" #define, which is somewhat arbitrarily set to 4MB worth of pages. Where did that number come from? Who knows? But that's the number the code uses for the _initial_ check of
I picked that up out of thin air. Intent there is to make sure small (<100K, lets say) allocations will work during suspend.
Quoted 5 lines
And the thing is, that "
swsusp_shrink_memory()" is just full of heuristics. There's no hard numbers there. It doesn't seem to wait for writeout, it just does the equivalent of "shrink_list()" and "shrink_slab()", but it seems to have been basically cribbed half-way from the regular "try to free memory", without really doing it all.
akpm designed shrink_memory(). Long time ago it was just while (1) kmalloc() loop. It should be waiting. Andrew?
Quoted 6 lines
Just as an example: it does that "
zone_is_all_unreclaimable()" logic that expects kswapd to mark things reclaimable again, but it doesn't seem to actually ever wait for kswapd or pdflush. It also seems to set "swappiness" to zero etc. Maybe it's all intentional, but it does mean that it uses some shared heuristics with the "real" VM, but uses them differently.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Andrew Morton
maintainerRe: [Bug #13058] First hibernation attempt fails
Quoted 8 lines · On Tue, 7 Apr 2009 10:06:32 +0200 Pavel Machek…
Quoted 5 lines
And the thing is, that "
swsusp_shrink_memory()" is just full of heuristics. There's no hard numbers there. It doesn't seem to wait for writeout, it just does the equivalent of "shrink_list()" and "shrink_slab()", but it seems to have been basically cribbed half-way from the regular "try to free memory", without really doing it all.akpm designed
shrink_memory(). Long time ago it was just while (1)kmalloc()loop. It should be waiting. Andrew?
I always wanted the thing to just allocate all the memory which it needed and then to either return it all to the caller or free it all again for the caller to reallocate (preferably the former).
But for some reason which I don't recall (Pavel provided it, iirc) that doesn't work. So the current (and subsequently tweaked) scheme was put in there instead. It turned out to be surprisingly difficult and ugly to graft it in top of the existing page reclaim code, and various changes were subsequently made to make it sort-of-work.
Remind me: why can't we just allocate N pages at suspend-time?
Re: [Bug #13058] First hibernation attempt fails
Quoted 16 lines · Andrew Morton
Quoted 8 lines · On Tue, 7 Apr 2009 10:06:32 +0200 Pavel Machek…
Quoted 5 lines
And the thing is, that "
swsusp_shrink_memory()" is just full of heuristics. There's no hard numbers there. It doesn't seem to wait for writeout, it just does the equivalent of "shrink_list()" and "shrink_slab()", but it seems to have been basically cribbed half-way from the regular "try to free memory", without really doing it all.akpm designed
shrink_memory(). Long time ago it was just while (1)kmalloc()loop. It should be waiting. Andrew?I always wanted the thing to just allocate all the memory which it needed and then to either return it all to the caller or free it all again for the caller to reallocate (preferably the former).
Quoted 7 lines
But for some reason which I don't recall (Pavel provided it, iirc) that doesn't work. So the current (and subsequently tweaked) scheme was put in there instead. It turned out to be surprisingly difficult and ugly to graft it in top of the existing page reclaim code, and various changes were subsequently made to make it sort-of-work.
Remind me: why can't we just allocate N pages at suspend-time?
Well, IMO it may be worth trying anyway.
Thanks,
Rafael
Re: [Bug #13058] First hibernation attempt fails
In reply to Andrew MortonHi!
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
And the thing is, that "
swsusp_shrink_memory()" is just full of heuristics. There's no hard numbers there. It doesn't seem to wait for writeout, it just does the equivalent of "shrink_list()" and "shrink_slab()", but it seems to have been basically cribbed half-way from the regular "try to free memory", without really doing it all.
Quoted 6 lines
Quoted 2 lines
akpm designed
shrink_memory(). Long time ago it was just while (1)kmalloc()loop. It should be waiting. Andrew?I always wanted the thing to just allocate all the memory which it needed and then to either return it all to the caller or free it all again for the caller to reallocate (preferably the former).
We need half of memory free for swsusp to work. If we "just allocate" it, we will trigger OOM killer; we'd prefer to fail suspend than to OOM kill.
Quoted 2 lines
But for some reason which I don't recall (Pavel provided it, iirc) that
Alas, I do not remember that clearly.
Quoted 6 lines
doesn't work. So the current (and subsequently tweaked) scheme was put in there instead. It turned out to be surprisingly difficult and ugly to graft it in top of the existing page reclaim code, and various changes were subsequently made to make it sort-of-work.
Remind me: why can't we just allocate N pages at suspend-time?
We need half of memory free. The reason we can't "just allocate" is probably OOM killer; but my memories are quite weak :-(.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Andrew Morton
maintainerRe: [Bug #13058] First hibernation attempt fails
Quoted 4 lines · On Mon, 20 Apr 2009 21:53:06 +0200 Pavel Machek…
Quoted 1 line
Remind me: why can't we just allocate N pages at suspend-time?
We need half of memory free. The reason we can't "just allocate" is probably OOM killer; but my memories are quite weak :-(.
hm. You'd think that with out splendid range of __GFP_foo falgs, there would be some combo which would suit this requirement but I can't immediately spot one.
We can always add another I guess. Something like...
mm/page_alloc.c renamed from mm/page_alloc.c~a +2 -1
@@ -1620,7 +1620,8 @@ nofail_alloc: }/* The OOM killer will not help higher order allocs so fail */ -if (order >PAGE_ALLOC_COSTLY_ORDER ) { +if (order >PAGE_ALLOC_COSTLY_ORDER || + (gfp_mask & __GFP_NO_OOM_KILL)) {clear_zonelist_oom (zonelist, gfp_mask); goto nopage; }
include/linux/gfp.h renamed from include/linux/gfp.h~a +2 -1
@@ -51,8 +51,9 @@ struct vm_area_struct;#define __GFP_THISNODE ((__force gfp_t)0x40000u)/* No fallback, no policies */ #define __GFP_RECLAIMABLE ((__force gfp_t)0x80000u)/* Page is reclaimable */ #define __GFP_MOVABLE ((__force gfp_t)0x100000u)/* Page is movable */ +#define __GFP_NO_OOM_KILL ((__force gfp_t)0x200000u)/* Don't invoke out_of_memory() */ -#define __GFP_BITS_SHIFT 21/* Room for 21 __GFP_FOO bits */ +#define __GFP_BITS_SHIFT 22/* Number of__GFP_FOO bits */ #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))/* This equals 0, but use constants in case they ever change */
_
Andrew Morton
maintainerRe: [Bug #13058] First hibernation attempt fails
Quoted 42 lines · On Mon, 20 Apr 2009 13:04:12 -0700 Andrew Morton…
Quoted 4 lines · On Mon, 20 Apr 2009 21:53:06 +0200 Pavel Machek…
Quoted 1 line
Remind me: why can't we just allocate N pages at suspend-time?
We need half of memory free. The reason we can't "just allocate" is probably OOM killer; but my memories are quite weak :-(.
hm. You'd think that with out splendid range of
__GFP_foofalgs, there would be some combo which would suit this requirement but I can't immediately spot one.We can always add another I guess. Something like...
diff -puN
mm/page_alloc.c~amm/page_alloc.cmm/page_alloc.c renamed from mm/page_alloc.c~a +2
-1@@ -1620,7 +1620,8 @@ nofail_alloc: }/* The OOM killer will not help higher order allocs so fail */ -if (order >PAGE_ALLOC_COSTLY_ORDER ) { +if (order >PAGE_ALLOC_COSTLY_ORDER || + (gfp_mask & __GFP_NO_OOM_KILL)) {clear_zonelist_oom (zonelist, gfp_mask); goto nopage; }diff -puN
include/linux/gfp.h~ainclude/linux/gfp.hinclude/linux/gfp.h renamed from include/linux/gfp.h~a +2
-1@@ -51,8 +51,9 @@ struct vm_area_struct;#define __GFP_THISNODE ((__force gfp_t)0x40000u)/* No fallback, no policies */ #define __GFP_RECLAIMABLE ((__force gfp_t)0x80000u)/* Page is reclaimable */ #define __GFP_MOVABLE ((__force gfp_t)0x100000u)/* Page is movable */ +#define __GFP_NO_OOM_KILL ((__force gfp_t)0x200000u)/* Don't invoke out_of_memory() */ -#define __GFP_BITS_SHIFT 21/* Room for 21 __GFP_FOO bits */ +#define __GFP_BITS_SHIFT 22/* Number of__GFP_FOO bits */ #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))/* This equals 0, but use constants in case they ever change */
Quoted 2 lines
_
Of course, this will protect the calling task from getting oom-killed. But it doesn't protect other tasks from getting oom-killed due to the activity of _this_ task.
But I think that problem already exists, and that this proposal doesn't worsen anything, yes?
Or is it the case that all other tasks are safely stuck in the freezer at this time, so they won't be allocating any memory anyway?
Re: [Bug #13058] First hibernation attempt fails
Quoted 52 lines · Andrew Morton
Quoted 42 lines · On Mon, 20 Apr 2009 13:04:12 -0700 Andrew Morton <[email protected]>…
Quoted 4 lines · On Mon, 20 Apr 2009 21:53:06 +0200 Pavel Machek <[email protected]> wrote:
Quoted 1 line
Remind me: why can't we just allocate N pages at suspend-time?
We need half of memory free. The reason we can't "just allocate" is probably OOM killer; but my memories are quite weak :-(.
hm. You'd think that with out splendid range of
__GFP_foofalgs, there would be some combo which would suit this requirement but I can't immediately spot one.We can always add another I guess. Something like...
diff -puN
mm/page_alloc.c~amm/page_alloc.cmm/page_alloc.c renamed from mm/page_alloc.c~a +2
-1@@ -1620,7 +1620,8 @@ nofail_alloc: }/* The OOM killer will not help higher order allocs so fail */ -if (order >PAGE_ALLOC_COSTLY_ORDER ) { +if (order >PAGE_ALLOC_COSTLY_ORDER || + (gfp_mask & __GFP_NO_OOM_KILL)) {clear_zonelist_oom (zonelist, gfp_mask); goto nopage; }diff -puN
include/linux/gfp.h~ainclude/linux/gfp.hinclude/linux/gfp.h renamed from include/linux/gfp.h~a +2
-1@@ -51,8 +51,9 @@ struct vm_area_struct;#define __GFP_THISNODE ((__force gfp_t)0x40000u)/* No fallback, no policies */ #define __GFP_RECLAIMABLE ((__force gfp_t)0x80000u)/* Page is reclaimable */ #define __GFP_MOVABLE ((__force gfp_t)0x100000u)/* Page is movable */ +#define __GFP_NO_OOM_KILL ((__force gfp_t)0x200000u)/* Don't invoke out_of_memory() */ -#define __GFP_BITS_SHIFT 21/* Room for 21 __GFP_FOO bits */ +#define __GFP_BITS_SHIFT 22/* Number of__GFP_FOO bits */ #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))/* This equals 0, but use constants in case they ever change */ Quoted 2 lines
_
Of course, this will protect the calling task from getting oom-killed. But it doesn't protect other tasks from getting oom-killed due to the activity of _this_ task.
Quoted 2 lines
But I think that problem already exists, and that this proposal doesn't worsen anything, yes?
I think it doesn't.
Quoted 2 lines
Or is it the case that all other tasks are safely stuck in the freezer at this time, so they won't be allocating any memory anyway?
Except for the tasks (kernel threads) that are not frozen and which can allocate memory as well.
However, the OOM killer is not really useful during suspend/hibernation, so perhaps we can just disable it temporarily before that?
Re: [Bug #13058] First hibernation attempt fails
In reply to Andrew MortonHi!
Quoted 9 lines
Of course, this will protect the calling task from getting oom-killed. But it doesn't protect other tasks from getting oom-killed due to the activity of _this_ task.
But I think that problem already exists, and that this proposal doesn't worsen anything, yes?
Or is it the case that all other tasks are safely stuck in the freezer at this time, so they won't be allocating any memory anyway?
That is the idea, yes. ... but we now have more threads that are not freezable... so they may allocate the memory.
Is it non-feasible to free memory without really going and allocating everything?
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: [Bug #13058] First hibernation attempt fails
Quoted 9 lines · Pavel Machek
Hi!
Quoted 7 lines
Of course, this will protect the calling task from getting oom-killed. But it doesn't protect other tasks from getting oom-killed due to the activity of _this_ task.
But I think that problem already exists, and that this proposal doesn't worsen anything, yes?
Quoted 8 lines
Quoted 2 lines
Or is it the case that all other tasks are safely stuck in the freezer at this time, so they won't be allocating any memory anyway?
That is the idea, yes. ... but we now have more threads that are not freezable... so they may allocate the memory.
Is it non-feasible to free memory without really going and allocating everything?
The question is whether there is a point. In principle we can just go and allocate as much as we need upfront. It shouldn't change anything, because we resume and suspend devices after creating the image anyway.
I think we could try to disable the OOM killer before suspend and just allocate the memory for the image right before devices are suspended for the first time.
Thanks,
Rafael
Andrew Morton
maintainerRe: [Bug #13058] First hibernation attempt fails
Quoted 19 lines · On Wed, 22 Apr 2009 22:11:17 +0200 "Rafael J. Wysocki"…
Quoted 9 lines · Pavel Machek
Hi!
Quoted 7 lines
Of course, this will protect the calling task from getting oom-killed. But it doesn't protect other tasks from getting oom-killed due to the activity of _this_ task.
But I think that problem already exists, and that this proposal doesn't worsen anything, yes?
Quoted 8 lines
Quoted 2 lines
Or is it the case that all other tasks are safely stuck in the freezer at this time, so they won't be allocating any memory anyway?
That is the idea, yes. ... but we now have more threads that are not freezable... so they may allocate the memory.
Is it non-feasible to free memory without really going and allocating everything?
Quoted 8 lines
The question is whether there is a point. In principle we can just go and allocate as much as we need upfront. It shouldn't change anything, because we resume and suspend devices after creating the image anyway.
I think we could try to disable the OOM killer before suspend and just allocate the memory for the image right before devices are suspended for the first time.
It would be nice to do.
shrink_all_memory() is simply trying to do something which page reclaim doesn't expect to do (free memory when there's already lots of memory free). Consequently it doesn't do it very well, and there's a good risk that changes to core reclaim will accidentally break shrink_all_memory().
cover PM: Drop shrink_all_memory (was: Re: [Bug #13058] First hibernation attempt fails)
Quoted 31 lines · Andrew Morton
Quoted 19 lines · On Wed, 22 Apr 2009 22:11:17 +0200 "Rafael J. Wysocki"…
Quoted 9 lines · Pavel Machek
Hi!
Quoted 7 lines
Of course, this will protect the calling task from getting oom-killed. But it doesn't protect other tasks from getting oom-killed due to the activity of _this_ task.
But I think that problem already exists, and that this proposal doesn't worsen anything, yes?
Quoted 8 lines
Quoted 2 lines
Or is it the case that all other tasks are safely stuck in the freezer at this time, so they won't be allocating any memory anyway?
That is the idea, yes. ... but we now have more threads that are not freezable... so they may allocate the memory.
Is it non-feasible to free memory without really going and allocating everything?
Quoted 8 lines
The question is whether there is a point. In principle we can just go and allocate as much as we need upfront. It shouldn't change anything, because we resume and suspend devices after creating the image anyway.
I think we could try to disable the OOM killer before suspend and just allocate the memory for the image right before devices are suspended for the first time.
Quoted 7 lines
It would be nice to do.
shrink_all_memory()is simply trying to do something which page reclaim doesn't expect to do (free memory when there's already lots of memory free). Consequently it doesn't do it very well, and there's a good risk that changes to core reclaim will accidentally breakshrink_all_memory().
OK, a patchset follows:
[1/3] - disable the OOM killer during system-wide power transitions (should be
done anyway IMO)
[2/3] - move swsusp_shrink_memory() to kernel/power/snapshot.c so that the
next patch is easier to read
[3/3] - drop shrink_all_memory()
Please have a look and tell me what you think.
Thanks,
Rafael
PATCH 1/3 PM: Disable OOM killer during system-wide power transitions
From: Rafael J. Wysocki <[email protected]>
The OOM killer is not particularly useful during system-wide power transitions, so do not use it if such a transition is in progress.
--- include/linux/suspend.h | 4 ++++ kernel/power/disk.c | 13 ++++++++++++- kernel/power/main.c | 13 +++++++++++++ kernel/power/power.h | 1 + mm/page_alloc.c | 8 ++++++-- 5 files changed, 36 insertions(+), 3 deletions(-)
include/linux/suspend.h +4 -0
@@ -282,6 +282,8 @@ extern int unregister_pm_notifier(struct { .notifier_call = fn, .priority = pri }; \ register_pm_notifier(&fn##_nb); \ } + +extern bool pm_transition_in_progress (void );#else /* !CONFIG_PM_SLEEP */ static inline int register_pm_notifier (struct notifier_block *nb)
@@ -295,6 +297,8 @@ static inline int unregister_pm_notifier }#define pm_notifier (fn, pri) do { (void)(fn); } while (0) + +static inline bool pm_transition_in_progress (void ) {return false; }#endif /* !CONFIG_PM_SLEEP */ #ifndef CONFIG_HIBERNATION
mm/page_alloc.c +6 -2
@@ -1619,8 +1619,12 @@ nofail_alloc: goto got_pg; } -/* The OOM killer will not help higher order allocs so fail */ -if (order >PAGE_ALLOC_COSTLY_ORDER ) { +/* +* The OOM killer will not help higher order allocs and it is +* not useful during system-wide power transitions, so fail. +*/ +if (order >PAGE_ALLOC_COSTLY_ORDER + ||pm_transition_in_progress ()) {clear_zonelist_oom (zonelist, gfp_mask); goto nopage; }
kernel/power/disk.c +12 -1
@@ -299,9 +299,11 @@ int hibernation_snapshot(int platform_mo {int error; + transition_in_progress = true; + error =platform_begin (platform_mode);if (error) -return error; + goto Out;/* Free memory before shutting down devices. */ error =swsusp_shrink_memory ();
@@ -325,6 +327,9 @@ int hibernation_snapshot(int platform_moresume_console (); Close:platform_end (platform_mode); + + Out: + transition_in_progress = false;return error; Recover_platform:
@@ -607,6 +612,7 @@ int hibernate(void)pr_debug ("PM: Image restored successfully.\n" );swsusp_free (); } + Thaw:thaw_processes (); Finish:
@@ -724,6 +730,8 @@ static int software_resume(void) goto Done; } + transition_in_progress = true; +pr_debug ("PM: Reading hibernation image.\n" ); error =swsusp_read (&flags);
@@ -732,6 +740,9 @@ static int software_resume(void)printk (KERN_ERR "PM: Restore failed, recovering.\n" );swsusp_free (); + + transition_in_progress = false; +thaw_processes (); Done:free_basic_memory_bitmaps ();
kernel/power/main.c +13 -0
@@ -32,6 +32,13 @@ EXPORT_SYMBOL(pm_flags);#ifdef CONFIG_PM_SLEEP +bool transition_in_progress; + +bool pm_transition_in_progress (void ) +{ +return transition_in_progress; +} +/* Routines for PM-transition notifications */ static BLOCKING_NOTIFIER_HEAD (pm_chain_head);
@@ -246,6 +253,8 @@ static int suspend_prepare(void) goto Thaw; } + transition_in_progress = true; + free_pages =global_page_state (NR_FREE_PAGES );if (free_pages <FREE_PAGE_NUMBER ) {pr_debug ("PM: free some memory\n" );
@@ -258,6 +267,8 @@ static int suspend_prepare(void)if (!error)return 0 ; + transition_in_progress = false; + Thaw:suspend_thaw_processes ();usermodehelper_enable ();
@@ -403,6 +414,8 @@ int suspend_devices_and_enter(suspend_st*/ static void suspend_finish (void ) { + transition_in_progress = false; +suspend_thaw_processes ();usermodehelper_enable ();pm_notifier_call_chain (PM_POST_SUSPEND );
kernel/power/power.h +1 -0
@@ -173,6 +173,7 @@ static inline int suspend_devices_and_en#ifdef CONFIG_PM_SLEEP /* kernel/power/main.c */ extern int pm_notifier_call_chain (unsigned long val); +extern bool transition_in_progress;#endif #ifdef CONFIG_HIGHMEM
Andrew Morton
maintainerRe: [PATCH 1/3] PM: Disable OOM killer during system-wide power transitions
Quoted 5 lines · On Sat, 2 May 2009 00:27:30 +0200 "Rafael J. Wysocki"…
From: Rafael J. Wysocki <[email protected]>
The OOM killer is not particularly useful during system-wide power transitions, so do not use it if such a transition is in progress.
so... I think what you've done here is to arrange for the page allocator to return NULL if we're hibernating rather than oom-killing, yes?
Does the same apply to suspending? If so, why?
I think this is an OK change, as long as the only thing which is allocating memory is hibernation itself. If random processes are still doing random memory allocations at this time then their failed memory allocation could be just as fatal as an oom-killing. Moreso if they're s/bin/init or whatever.
So is it the case that pm_transition_in_progress() is only true during the highly-constrained hibernation process? After everything is frozen?
If so, there are alternatives - the calling process could set PF_DONT_KILL_ANYONE_FOR_ME, or could pass __GFP_DONT_KILL_ANYONE_FOR_ME. Those might be worse alternatives, dunno - I'm just asking probing questions ;)
Re: [PATCH 1/3] PM: Disable OOM killer during system-wide power transitions
Quoted 5 lines · Andrew Morton
Quoted 2 lines · On Sat, 2 May 2009 00:27:30 +0200 "Rafael J. Wysocki"…
From: Rafael J. Wysocki <[email protected]>
Quoted 7 lines
Quoted 3 lines
The OOM killer is not particularly useful during system-wide power transitions, so do not use it if such a transition is in progress.
so... I think what you've done here is to arrange for the page allocator to return NULL if we're hibernating rather than oom-killing, yes?
Yes.
Quoted 1 line
Does the same apply to suspending? If so, why?
Because I think it doesn't work anyway. User space processes are frozen and effectively in TASK_UNINTERRUPTIBLE, so they won't be killed.
Quoted 5 lines
I think this is an OK change, as long as the only thing which is allocating memory is hibernation itself. If random processes are still doing random memory allocations at this time then their failed memory allocation could be just as fatal as an oom-killing. Moreso if they're s/bin/init or whatever.
At this point all of the user space tasks are frozen.
Quoted 2 lines
So is it the case that
pm_transition_in_progress()is only true during the highly-constrained hibernation process? After everything is frozen?
Yes.
Quoted 4 lines
If so, there are alternatives - the calling process could set
PF_DONT_KILL_ANYONE_FOR_ME, or could pass__GFP_DONT_KILL_ANYONE_FOR_ME. Those might be worse alternatives, dunno - I'm just asking probing questions ;)
Well, the __GFP_DONT_KILL_ANYONE_FOR_ME would be easier to implement.
I don't really think that the freezing of processes plays very well with the OOM killer, so disabling it altogether after the processes have been frozen seems reasonable to me. Still, if you prefer to use __GFP_DONT_KILL_ANYONE_FOR_ME, it's fine by me.
Re: [PATCH 1/3] PM: Disable OOM killer during system-wide power transitions
Quoted 6 lines
Quoted 2 lines
Does the same apply to suspending? If so, why?
Because I think it doesn't work anyway. User space processes are frozen and effectively in
TASK_UNINTERRUPTIBLE, so they won't be killed.
Quoted 7 lines
Quoted 5 lines
I think this is an OK change, as long as the only thing which is allocating memory is hibernation itself. If random processes are still doing random memory allocations at this time then their failed memory allocation could be just as fatal as an oom-killing. Moreso if they're s/bin/init or whatever.
At this point all of the user space tasks are frozen.
Well, many kernel threads still remain active. But it is true that OOM killer is unlikely to help.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: [PATCH 1/3] PM: Disable OOM killer during system-wide power transitions
In reply to Rafael J. WysockiQuoted 6 lines
Quoted 2 lines
Does the same apply to suspending? If so, why?
Because I think it doesn't work anyway. User space processes are frozen and effectively in
TASK_UNINTERRUPTIBLE, so they won't be killed.
Quoted 7 lines
Quoted 5 lines
I think this is an OK change, as long as the only thing which is allocating memory is hibernation itself. If random processes are still doing random memory allocations at this time then their failed memory allocation could be just as fatal as an oom-killing. Moreso if they're s/bin/init or whatever.
At this point all of the user space tasks are frozen.
Well, many kernel threads still remain active. But it is true that OOM killer is unlikely to help.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: [PATCH 1/3] PM: Disable OOM killer during system-wide power transitions
In reply to Andrew MortonQuoted 5 lines · Andrew Morton
Quoted 2 lines · On Sat, 2 May 2009 00:27:30 +0200 "Rafael J. Wysocki" <[email protected]> wrote:
From: Rafael J. Wysocki <[email protected]>
Quoted 7 lines
Quoted 3 lines
The OOM killer is not particularly useful during system-wide power transitions, so do not use it if such a transition is in progress.
so... I think what you've done here is to arrange for the page allocator to return NULL if we're hibernating rather than oom-killing, yes?
Yes.
Quoted 1 line
Does the same apply to suspending? If so, why?
Because I think it doesn't work anyway. User space processes are frozen and effectively in TASK_UNINTERRUPTIBLE, so they won't be killed.
Quoted 5 lines
I think this is an OK change, as long as the only thing which is allocating memory is hibernation itself. If random processes are still doing random memory allocations at this time then their failed memory allocation could be just as fatal as an oom-killing. Moreso if they're s/bin/init or whatever.
At this point all of the user space tasks are frozen.
Quoted 2 lines
So is it the case that
pm_transition_in_progress()is only true during the highly-constrained hibernation process? After everything is frozen?
Yes.
Quoted 4 lines
If so, there are alternatives - the calling process could set
PF_DONT_KILL_ANYONE_FOR_ME, or could pass__GFP_DONT_KILL_ANYONE_FOR_ME. Those might be worse alternatives, dunno - I'm just asking probing questions ;)
Well, the __GFP_DONT_KILL_ANYONE_FOR_ME would be easier to implement.
I don't really think that the freezing of processes plays very well with the OOM killer, so disabling it altogether after the processes have been frozen seems reasonable to me. Still, if you prefer to use __GFP_DONT_KILL_ANYONE_FOR_ME, it's fine by me.
Andrew Morton
maintainerRe: [PATCH 1/3] PM: Disable OOM killer during system-wide power transitions
In reply to Rafael J. WysockiQuoted 5 lines · On Sat, 2 May 2009 00:27:30 +0200 "Rafael J. Wysocki" <[email protected]> wrote:
From: Rafael J. Wysocki <[email protected]>
The OOM killer is not particularly useful during system-wide power transitions, so do not use it if such a transition is in progress.
so... I think what you've done here is to arrange for the page allocator to return NULL if we're hibernating rather than oom-killing, yes?
Does the same apply to suspending? If so, why?
I think this is an OK change, as long as the only thing which is allocating memory is hibernation itself. If random processes are still doing random memory allocations at this time then their failed memory allocation could be just as fatal as an oom-killing. Moreso if they're s/bin/init or whatever.
So is it the case that pm_transition_in_progress() is only true during the highly-constrained hibernation process? After everything is frozen?
If so, there are alternatives - the calling process could set PF_DONT_KILL_ANYONE_FOR_ME, or could pass __GFP_DONT_KILL_ANYONE_FOR_ME. Those might be worse alternatives, dunno - I'm just asking probing questions ;)
PATCH 1/3 PM: Disable OOM killer during system-wide power transitions
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
The OOM killer is not particularly useful during system-wide power transitions, so do not use it if such a transition is in progress.
--- include/linux/suspend.h | 4 ++++ kernel/power/disk.c | 13 ++++++++++++- kernel/power/main.c | 13 +++++++++++++ kernel/power/power.h | 1 + mm/page_alloc.c | 8 ++++++-- 5 files changed, 36 insertions(+), 3 deletions(-)
include/linux/suspend.h +4 -0
@@ -282,6 +282,8 @@ extern int unregister_pm_notifier(struct { .notifier_call = fn, .priority = pri }; \ register_pm_notifier(&fn##_nb); \ } + +extern bool pm_transition_in_progress (void );#else /* !CONFIG_PM_SLEEP */ static inline int register_pm_notifier (struct notifier_block *nb)
@@ -295,6 +297,8 @@ static inline int unregister_pm_notifier }#define pm_notifier (fn, pri) do { (void)(fn); } while (0) + +static inline bool pm_transition_in_progress (void ) {return false; }#endif /* !CONFIG_PM_SLEEP */ #ifndef CONFIG_HIBERNATION
mm/page_alloc.c +6 -2
@@ -1619,8 +1619,12 @@ nofail_alloc: goto got_pg; } -/* The OOM killer will not help higher order allocs so fail */ -if (order >PAGE_ALLOC_COSTLY_ORDER ) { +/* +* The OOM killer will not help higher order allocs and it is +* not useful during system-wide power transitions, so fail. +*/ +if (order >PAGE_ALLOC_COSTLY_ORDER + ||pm_transition_in_progress ()) {clear_zonelist_oom (zonelist, gfp_mask); goto nopage; }
kernel/power/disk.c +12 -1
@@ -299,9 +299,11 @@ int hibernation_snapshot(int platform_mo {int error; + transition_in_progress = true; + error =platform_begin (platform_mode);if (error) -return error; + goto Out;/* Free memory before shutting down devices. */ error =swsusp_shrink_memory ();
@@ -325,6 +327,9 @@ int hibernation_snapshot(int platform_moresume_console (); Close:platform_end (platform_mode); + + Out: + transition_in_progress = false;return error; Recover_platform:
@@ -607,6 +612,7 @@ int hibernate(void)pr_debug ("PM: Image restored successfully.\n" );swsusp_free (); } + Thaw:thaw_processes (); Finish:
@@ -724,6 +730,8 @@ static int software_resume(void) goto Done; } + transition_in_progress = true; +pr_debug ("PM: Reading hibernation image.\n" ); error =swsusp_read (&flags);
@@ -732,6 +740,9 @@ static int software_resume(void)printk (KERN_ERR "PM: Restore failed, recovering.\n" );swsusp_free (); + + transition_in_progress = false; +thaw_processes (); Done:free_basic_memory_bitmaps ();
kernel/power/main.c +13 -0
@@ -32,6 +32,13 @@ EXPORT_SYMBOL(pm_flags);#ifdef CONFIG_PM_SLEEP +bool transition_in_progress; + +bool pm_transition_in_progress (void ) +{ +return transition_in_progress; +} +/* Routines for PM-transition notifications */ static BLOCKING_NOTIFIER_HEAD (pm_chain_head);
@@ -246,6 +253,8 @@ static int suspend_prepare(void) goto Thaw; } + transition_in_progress = true; + free_pages =global_page_state (NR_FREE_PAGES );if (free_pages <FREE_PAGE_NUMBER ) {pr_debug ("PM: free some memory\n" );
@@ -258,6 +267,8 @@ static int suspend_prepare(void)if (!error)return 0 ; + transition_in_progress = false; + Thaw:suspend_thaw_processes ();usermodehelper_enable ();
@@ -403,6 +414,8 @@ int suspend_devices_and_enter(suspend_st*/ static void suspend_finish (void ) { + transition_in_progress = false; +suspend_thaw_processes ();usermodehelper_enable ();pm_notifier_call_chain (PM_POST_SUSPEND );
kernel/power/power.h +1 -0
@@ -173,6 +173,7 @@ static inline int suspend_devices_and_en#ifdef CONFIG_PM_SLEEP /* kernel/power/main.c */ extern int pm_notifier_call_chain (unsigned long val); +extern bool transition_in_progress;#endif #ifdef CONFIG_HIGHMEM
PATCH 2/3 PM/Hibernate: Move memory shrinking to snapshot.c
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
The next patch is going to modify the memory shrinking code so that it will make memory allocations to free memory instead of using an artificial memory shrinking mechanism for that. For this purpose it is convenient to move swsusp_shrink_memory() from kernel/power/swsusp.c to kernel/power/snapshot.c, because the new memory-shrinking code is going to use things that are local to kernel/power/snapshot.c .
--- kernel/power/snapshot.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++ kernel/power/swsusp.c | 76 ------------------------------------------------ 2 files changed, 76 insertions(+), 76 deletions(-)
kernel/power/snapshot.c +76 -0
@@ -39,6 +39,14 @@ static int swsusp_page_is_free(struct pastatic void swsusp_set_page_forbidden (struct page *);static void swsusp_unset_page_forbidden (struct page *); +/* +* Preferred image size in bytes (tunable via /sys/power/image_size). +* When it is set to N, swsusp will do its best to ensure the image +* size will not exceed N bytes, but if that is impossible, it will +* try to create the smallest image possible. +*/ +unsigned long image_size =500 *1024 *1024 ; +/* List of PBEs needed for restoring the pages that were allocated before * the suspend and included in the suspend image, but have also been * allocated by the "resume" kernel, so their contents cannot be written
@@ -569,6 +577,74 @@ static unsigned long memory_bm_next_pfn( }/** +* swsusp_shrink_memory - Try to free as much memory as needed +* +* ... but do not OOM-kill anyone +* +* Notice: all userland should be stopped before it is called, or +* livelock is possible. +*/ + +#define SHRINK_BITE 10000 +static inline unsigned long __shrink_memory (long tmp) +{ +if (tmp >SHRINK_BITE ) + tmp =SHRINK_BITE ; +return shrink_all_memory (tmp); +} + +int swsusp_shrink_memory (void ) +{ +long tmp; +struct zone *zone; +unsigned long pages =0 ; +unsigned int i =0 ; +char *p ="-\\|/" ; +struct timeval start, stop; + +printk (KERN_INFO "PM: Shrinking memory... " ); +do_gettimeofday (&start); +do { +long size, highmem_size; + + highmem_size =count_highmem_pages (); + size =count_data_pages () +PAGES_FOR_IO +SPARE_PAGES ; + tmp = size; + size += highmem_size; +for_each_populated_zone (zone) { + tmp +=snapshot_additional_pages (zone); +if (is_highmem (zone)) { + highmem_size -= +zone_page_state (zone,NR_FREE_PAGES ); + }else { + tmp -=zone_page_state (zone,NR_FREE_PAGES ); + tmp += zone->lowmem_reserve[ZONE_NORMAL ]; + } + } + +if (highmem_size <0 ) + highmem_size =0 ; + + tmp += highmem_size; +if (tmp >0 ) { + tmp =__shrink_memory (tmp); +if (!tmp) +return -ENOMEM ; + pages += tmp; + }else if (size > image_size /PAGE_SIZE ) { + tmp =__shrink_memory (size - (image_size /PAGE_SIZE )); + pages += tmp; + } +printk ("\b%c" , p[i++%4 ]); + }while (tmp >0 ); +do_gettimeofday (&stop); +printk ("\bdone (%lu pages freed)\n" , pages); +swsusp_show_speed (&start, &stop, pages,"Freed" ); + +return 0 ; +} + +/** * This structure represents a range of page frames the contents of which * should not be saved during the suspend. */
kernel/power/swsusp.c +0 -76
88 lines not on this page · raw message
PATCH 2/3 PM/Hibernate: Move memory shrinking to snapshot.c
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
The next patch is going to modify the memory shrinking code so that it will make memory allocations to free memory instead of using an artificial memory shrinking mechanism for that. For this purpose it is convenient to move swsusp_shrink_memory() from kernel/power/swsusp.c to kernel/power/snapshot.c, because the new memory-shrinking code is going to use things that are local to kernel/power/snapshot.c .
--- kernel/power/snapshot.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++ kernel/power/swsusp.c | 76 ------------------------------------------------ 2 files changed, 76 insertions(+), 76 deletions(-)
kernel/power/snapshot.c +76 -0
@@ -39,6 +39,14 @@ static int swsusp_page_is_free(struct pastatic void swsusp_set_page_forbidden (struct page *);static void swsusp_unset_page_forbidden (struct page *); +/* +* Preferred image size in bytes (tunable via /sys/power/image_size). +* When it is set to N, swsusp will do its best to ensure the image +* size will not exceed N bytes, but if that is impossible, it will +* try to create the smallest image possible. +*/ +unsigned long image_size =500 *1024 *1024 ; +/* List of PBEs needed for restoring the pages that were allocated before * the suspend and included in the suspend image, but have also been * allocated by the "resume" kernel, so their contents cannot be written
@@ -569,6 +577,74 @@ static unsigned long memory_bm_next_pfn( }/** +* swsusp_shrink_memory - Try to free as much memory as needed +* +* ... but do not OOM-kill anyone +* +* Notice: all userland should be stopped before it is called, or +* livelock is possible. +*/ + +#define SHRINK_BITE 10000 +static inline unsigned long __shrink_memory (long tmp) +{ +if (tmp >SHRINK_BITE ) + tmp =SHRINK_BITE ; +return shrink_all_memory (tmp); +} + +int swsusp_shrink_memory (void ) +{ +long tmp; +struct zone *zone; +unsigned long pages =0 ; +unsigned int i =0 ; +char *p ="-\\|/" ; +struct timeval start, stop; + +printk (KERN_INFO "PM: Shrinking memory... " ); +do_gettimeofday (&start); +do { +long size, highmem_size; + + highmem_size =count_highmem_pages (); + size =count_data_pages () +PAGES_FOR_IO +SPARE_PAGES ; + tmp = size; + size += highmem_size; +for_each_populated_zone (zone) { + tmp +=snapshot_additional_pages (zone); +if (is_highmem (zone)) { + highmem_size -= +zone_page_state (zone,NR_FREE_PAGES ); + }else { + tmp -=zone_page_state (zone,NR_FREE_PAGES ); + tmp += zone->lowmem_reserve[ZONE_NORMAL ]; + } + } + +if (highmem_size <0 ) + highmem_size =0 ; + + tmp += highmem_size; +if (tmp >0 ) { + tmp =__shrink_memory (tmp); +if (!tmp) +return -ENOMEM ; + pages += tmp; + }else if (size > image_size /PAGE_SIZE ) { + tmp =__shrink_memory (size - (image_size /PAGE_SIZE )); + pages += tmp; + } +printk ("\b%c" , p[i++%4 ]); + }while (tmp >0 ); +do_gettimeofday (&stop); +printk ("\bdone (%lu pages freed)\n" , pages); +swsusp_show_speed (&start, &stop, pages,"Freed" ); + +return 0 ; +} + +/** * This structure represents a range of page frames the contents of which * should not be saved during the suspend. */
kernel/power/swsusp.c +0 -76
88 lines not on this page · raw message
PATCH 3/3 PM/Hibernate: Use memory allocations to free memory
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Modify the hibernation memory shrinking code so that it will make memory allocations to free memory instead of using an artificial memory shrinking mechanism for that. Remove the shrinking of memory from the suspend-to-RAM code, where it is not really necessary. Finally, remove the no longer used memory shrinking functions from mm/vmscan.c .
--- kernel/power/main.c | 25 +------- kernel/power/snapshot.c | 118 ++++++++++++++++++++++++++++++--------- mm/vmscan.c | 142 ------------------------------------------------ 3 files changed, 93 insertions(+), 192 deletions(-)
kernel/power/snapshot.c +90 -28
@@ -576,39 +576,89 @@ static unsigned long memory_bm_next_pfn(return bb->start_pfn + bit; } +/* Helper functions used for the shrinking of memory. */ +/** -* swsusp_shrink_memory - Try to free as much memory as needed -* -* ... but do not OOM-kill anyone +* free_marked_pages - release pages allocated during memory shrinking +* @bm: Memory bitmap where the allocated pages were marked. * -* Notice: all userland should be stopped before it is called, or -* livelock is possible. +* Free all pages marked in given memory bitmap. */ +static void free_marked_pages (struct memory_bitmap *bm) +{ +memory_bm_position_reset (bm); +for (;;) { +unsigned long pfn; +struct page *page; -#define SHRINK_BITE 10000 -static inline unsigned long __shrink_memory (long tmp) + pfn =memory_bm_next_pfn (bm); +if (pfn ==BM_END_OF_MAP ) +break ; + page =pfn_to_page (pfn); +__free_page (page); + } +} + +/** +* alloc_and_mark_page - allocate given number of pages and mark their PFNs +* @bm: Memory bitmap to use for marking allocated pages. +* @nr_pages: Number of pages to allocate. +* +* Allocate given number of pages and mark their PFNs in given memory bitmap, +* so that they can be released by free_marked_pages(). +* Return value: The number of normal (ie. non-highmem) pages allocated or +* -ENOMEM on failure. +*/ +static long alloc_and_mark_pages (struct memory_bitmap *bm,long nr_pages) { -if (tmp >SHRINK_BITE ) - tmp =SHRINK_BITE ; -return shrink_all_memory (tmp); +long nr_normal =0 ; + +while (nr_pages-- >0 ) { +struct page *page; + + page =alloc_page (GFP_KERNEL | __GFP_HIGHMEM); +if (!page) +return -ENOMEM ; +memory_bm_set_bit (bm,page_to_pfn (page)); +if (!PageHighMem (page)) + nr_normal++; + } + +return nr_normal; } +#define SHRINK_BITE 10000 + +/** +* swsusp_shrink_memory - Try to make the kernel free as much memory as needed +*/ int swsusp_shrink_memory (void ) {long tmp;struct zone *zone; -unsigned long pages =0 ; +unsigned long pages =0 , alloc_normal =0 , alloc_highmem =0 ;unsigned int i =0 ;char *p ="-\\|/" ;struct timeval start, stop; +struct memory_bitmap *bm; +int error; + + bm =kzalloc (sizeof (*bm),GFP_KERNEL ); +if (!bm) +return -ENOMEM ; + error =memory_bm_create (bm,GFP_KERNEL ,PG_ANY ); +if (error) +return error;printk (KERN_INFO "PM: Shrinking memory... " );do_gettimeofday (&start); - do { - long size, highmem_size; - highmem_size = count_highmem_pages(); - size = count_data_pages() + PAGES_FOR_IO + SPARE_PAGES; +for (;;) { +long size, highmem_size, ret; + + highmem_size =count_highmem_pages () -2 * alloc_highmem; + size =count_data_pages () +PAGES_FOR_IO +SPARE_PAGES + -2 * alloc_normal; tmp = size; size += highmem_size;for_each_populated_zone (zone) {
@@ -621,27 +671,39 @@ int swsusp_shrink_memory(void) tmp += zone->lowmem_reserve[ZONE_NORMAL ]; } } -if (highmem_size <0 ) highmem_size =0 ; - tmp += highmem_size; -if (tmp >0 ) { - tmp =__shrink_memory (tmp); -if (!tmp) -return -ENOMEM ; - pages += tmp; - }else if (size > image_size /PAGE_SIZE ) { - tmp =__shrink_memory (size - (image_size /PAGE_SIZE )); - pages += tmp; + +if (tmp <=0 && size > image_size /PAGE_SIZE ) + tmp = size - (image_size /PAGE_SIZE ); + +if (tmp >SHRINK_BITE ) + tmp =SHRINK_BITE ; +else if (tmp <=0 ) +break ; + + ret =alloc_and_mark_pages (bm, tmp); +if (ret <0 ) { + error = -ENOMEM ; + goto out; } + alloc_normal += ret; + alloc_highmem += tmp - ret; + pages += tmp; +printk ("\b%c" , p[i++%4 ]); - }while (tmp >0 ); + } +do_gettimeofday (&stop); -printk ("\bdone (%lu pages freed)\n" , pages); +printk ("\bdone (preallocated %lu free pages)\n" , pages);swsusp_show_speed (&start, &stop, pages,"Freed" ); -return 0 ; + out: +free_marked_pages (bm); +memory_bm_free (bm,PG_UNSAFE_CLEAR ); + +return error; }/**
mm/vmscan.c +0 -142
148 lines not on this page · raw message
kernel/power/main.c +3 -22
@@ -195,9 +195,6 @@ static void suspend_test_finish(const ch#endif -/* This is just an arbitrary number */ -#define FREE_PAGE_NUMBER (100) -static struct platform_suspend_ops *suspend_ops;/**
@@ -233,7 +230,6 @@ int suspend_valid_only_mem(suspend_statestatic int suspend_prepare (void ) {int error; -unsigned int free_pages;if (!suspend_ops || !suspend_ops->enter)return -EPERM ;
@@ -250,26 +246,11 @@ static int suspend_prepare(void)if (suspend_freeze_processes ()) { error = -EAGAIN ; - goto Thaw; - } - - transition_in_progress = true; - - free_pages =global_page_state (NR_FREE_PAGES ); -if (free_pages <FREE_PAGE_NUMBER ) { -pr_debug ("PM: free some memory\n" ); -shrink_all_memory (FREE_PAGE_NUMBER - free_pages); -if (nr_free_pages () <FREE_PAGE_NUMBER ) { - error = -ENOMEM ; -printk (KERN_ERR "PM: No enough memory\n" ); - } - } -if (!error) + }else { + transition_in_progress = true;return 0 ; + } - transition_in_progress = false; - - Thaw:suspend_thaw_processes ();usermodehelper_enable (); Finish:
Andrew Morton
maintainerRe: [PATCH 3/3] PM/Hibernate: Use memory allocations to free memory
Quoted 21 lines · On Sat, 2 May 2009 00:29:38 +0200 "Rafael J. Wysocki"…
From: Rafael J. Wysocki <[email protected]>
Modify the hibernation memory shrinking code so that it will make memory allocations to free memory instead of using an artificial memory shrinking mechanism for that. Remove the shrinking of memory from the suspend-to-RAM code, where it is not really necessary. Finally, remove the no longer used memory shrinking functions from
mm/vmscan.c....
kernel/power/snapshot.c +6
-3+static long alloc_and_mark_pages (struct memory_bitmap *bm,long nr_pages) { -if (tmp >SHRINK_BITE ) - tmp =SHRINK_BITE ; -return shrink_all_memory (tmp); +long nr_normal =0 ; + +while (nr_pages-- >0 ) { +struct page *page; +
kernel/power/snapshot.c static unsigned long memory_bm_next_pfn( · line 628
Quoted 10 lines
kernel/power/snapshot.c +9
-0+ page =alloc_page (GFP_KERNEL | __GFP_HIGHMEM); +if (!page) +return -ENOMEM ; +memory_bm_set_bit (bm,page_to_pfn (page)); +if (!PageHighMem (page)) + nr_normal++; + } + +return nr_normal; }
Do we need the bitmap? I expect we can just string all these pages onto a local list via page.lru. Would need to check that - the pageframe fields are quite overloaded.
kernel/power/snapshot.c static unsigned long memory_bm_next_pfn( · line 661
Quoted 8 lines
...
kernel/power/snapshot.c +6
-0+#define SHRINK_BITE 10000 +long size, highmem_size, ret; + + highmem_size =count_highmem_pages () -2 * alloc_highmem; + size =count_data_pages () +PAGES_FOR_IO +SPARE_PAGES + -2 * alloc_normal;
It'd be nice if this head-spinning arithmetic were spelled out in a comment somewhere. There are rather a lot of magic-number heuristics in here.
kernel/power/snapshot.c int swsusp_shrink_memory(void)
Quoted 4 lines
kernel/power/snapshot.c +0
-0tmp = size; size += highmem_size;for_each_populated_zone (zone) {@@ -621,27 +671,39 @@ int swsusp_shrink_memory(void)
All looks pretty sane to me.
Re: [PATCH 3/3] PM/Hibernate: Use memory allocations to free memory
Quoted 30 lines · Andrew Morton
Quoted 27 lines · On Sat, 2 May 2009 00:29:38 +0200 "Rafael J. Wysocki"…
From: Rafael J. Wysocki <[email protected]>
Modify the hibernation memory shrinking code so that it will make memory allocations to free memory instead of using an artificial memory shrinking mechanism for that. Remove the shrinking of memory from the suspend-to-RAM code, where it is not really necessary. Finally, remove the no longer used memory shrinking functions from
mm/vmscan.c....
kernel/power/snapshot.c +12
-3+static long alloc_and_mark_pages (struct memory_bitmap *bm,long nr_pages) { -if (tmp >SHRINK_BITE ) - tmp =SHRINK_BITE ; -return shrink_all_memory (tmp); +long nr_normal =0 ; + +while (nr_pages-- >0 ) { +struct page *page; + + page =alloc_page (GFP_KERNEL | __GFP_HIGHMEM); +if (!page) +return -ENOMEM ; +memory_bm_set_bit (bm,page_to_pfn (page)); +if (!PageHighMem (page)) + nr_normal++;
Quoted 8 lines
kernel/power/snapshot.c static unsigned long memory_bm_next_pfn( · line 628
Quoted 4 lines
kernel/power/snapshot.c +3
-0+ } + +return nr_normal; }Do we need the bitmap? I expect we can just string all these pages onto a local list via page.lru. Would need to check that - the pageframe fields are quite overloaded.
This is the reason why we use the bitmaps for hibernation. :-)
Quoted 12 lines
kernel/power/snapshot.c static unsigned long memory_bm_next_pfn( · line 661
Quoted 8 lines
...
kernel/power/snapshot.c +6
-0+#define SHRINK_BITE 10000 +long size, highmem_size, ret; + + highmem_size =count_highmem_pages () -2 * alloc_highmem; + size =count_data_pages () +PAGES_FOR_IO +SPARE_PAGES + -2 * alloc_normal;It'd be nice if this head-spinning arithmetic were spelled out in a comment somewhere. There are rather a lot of magic-number heuristics in here.
Well, yeah. I'll try to write up something. :-)
Quoted 6 lines
kernel/power/snapshot.c int swsusp_shrink_memory(void)
Quoted 4 lines
kernel/power/snapshot.c +0
-0tmp = size; size += highmem_size;for_each_populated_zone (zone) {@@ -621,27 +671,39 @@ int swsusp_shrink_memory(void)All looks pretty sane to me.
Great, thanks for the comments!
Andrew Morton
maintainerRe: [PATCH 3/3] PM/Hibernate: Use memory allocations to free memory
Quoted 5 lines · On Sat, 2 May 2009 13:46:34 +0200 "Rafael J. Wysocki"…
Quoted 3 lines
Do we need the bitmap? I expect we can just string all these pages onto a local list via page.lru. Would need to check that - the pageframe fields are quite overloaded.
This is the reason why we use the bitmaps for hibernation. :-)
grep the tree for page->lru and you'll see that quite a few page consumers are using it. So you'd be pretty safe doing it this way.
Whether it's _worth_ doing it this way is debatable, given that hibernation uses bitmaps elsewhere. But it would shrink the patch a bit I expect?
cover PM: Drop shrink_all_memory (rev. 2) (was: Re: [PATCH 3/3] PM/Hibernate: Use memory allocations to free memory)
Quoted 6 lines · Andrew Morton
Quoted 4 lines · On Sat, 2 May 2009 13:46:34 +0200 "Rafael J. Wysocki"…
Quoted 3 lines
Do we need the bitmap? I expect we can just string all these pages onto a local list via page.lru. Would need to check that - the pageframe fields are quite overloaded.
Quoted 8 lines
Quoted 1 line
This is the reason why we use the bitmaps for hibernation. :-)
grep the tree for
page->lruand you'll see that quite a few page consumers are using it. So you'd be pretty safe doing it this way.Whether it's _worth_ doing it this way is debatable, given that hibernation uses bitmaps elsewhere. But it would shrink the patch a bit I expect?
It probably would, but it turns out we need not create the new bitmap, we can use the existing ones for marking the allocated pages. That also has the benefit that we can use swsusp_free() to release them.
Modified patch series follows:
[1/4] - your patch introducing __GFP_NO_OOM_KILL (I decided it would be better
do it this way in this particular case. The fact that the OOM killer is not going to work after tasks have been frozen is a different issue.)
[2/4] - move swsusp_shrink_memory to snapshot.c, no major changes
[3/4] - use memory allocations to for making the room for the image (added
comments, used the existing bitmaps, cleaned up a bit)
[4/4] - new thing: do not release memory allocated by [3/4] and use it for
creating the image directly.
Thanks,
Rafael
PATCH 1/4 mm: Add __GFP_NO_OOM_KILL flag
From: Andrew Morton <akpm-de/[email protected]>
Quoted 4 lines
Quoted 1 line
Remind me: why can't we just allocate N pages at suspend-time?
We need half of memory free. The reason we can't "just allocate" is probably OOM killer; but my memories are quite weak :-(.
hm. You'd think that with our splendid range of __GFP_foo falgs, there would be some combo which would suit this requirement but I can't immediately spot one.
We can always add another I guess. Something like...
--- include/linux/gfp.h | 3 ++- mm/page_alloc.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-)
mm/page_alloc.c +2 -1
@@ -1620,7 +1620,8 @@ nofail_alloc: }/* The OOM killer will not help higher order allocs so fail */ -if (order >PAGE_ALLOC_COSTLY_ORDER ) { +if (order >PAGE_ALLOC_COSTLY_ORDER || + (gfp_mask & __GFP_NO_OOM_KILL)) {clear_zonelist_oom (zonelist, gfp_mask); goto nopage; }
include/linux/gfp.h +2 -1
@@ -51,8 +51,9 @@ struct vm_area_struct;#define __GFP_THISNODE ((__force gfp_t)0x40000u)/* No fallback, no policies */ #define __GFP_RECLAIMABLE ((__force gfp_t)0x80000u)/* Page is reclaimable */ #define __GFP_MOVABLE ((__force gfp_t)0x100000u)/* Page is movable */ +#define __GFP_NO_OOM_KILL ((__force gfp_t)0x200000u)/* Don't invoke out_of_memory() */ -#define __GFP_BITS_SHIFT 21/* Room for 21 __GFP_FOO bits */ +#define __GFP_BITS_SHIFT 22/* Number of__GFP_FOO bits */ #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))/* This equals 0, but use constants in case they ever change */
Re: [PATCH 1/4] mm: Add __GFP_NO_OOM_KILL flag
Quoted 38 lines · Rafael J. Wysocki
From: Andrew Morton <akpm-de/[email protected]>
Quoted 4 lines
Quoted 1 line
Remind me: why can't we just allocate N pages at suspend-time?
We need half of memory free. The reason we can't "just allocate" is probably OOM killer; but my memories are quite weak :-(.
hm. You'd think that with our splendid range of
__GFP_foofalgs, there would be some combo which would suit this requirement but I can't immediately spot one.We can always add another I guess. Something like...
Signed-off-by Rafael J. Wysocki <[email protected]>--- include/linux/gfp.h | 3 ++- mm/page_alloc.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-)Index:
linux-2.6/mm/page_alloc.c
===================================================================mm/page_alloc.c +2
-1@@ -1620,7 +1620,8 @@ nofail_alloc: }/* The OOM killer will not help higher order allocs so fail */ -if (order >PAGE_ALLOC_COSTLY_ORDER ) { +if (order >PAGE_ALLOC_COSTLY_ORDER || + (gfp_mask & __GFP_NO_OOM_KILL)) {clear_zonelist_oom (zonelist, gfp_mask); goto nopage; }Index:
linux-2.6/include/linux/gfp.h
===================================================================
include/linux/gfp.h struct vm_area_struct; · line 56
Quoted 7 lines
include/linux/gfp.h +2
-1@@ -51,8 +51,9 @@ struct vm_area_struct;#define __GFP_THISNODE ((__force gfp_t)0x40000u)/* No fallback, no policies */ #define __GFP_RECLAIMABLE ((__force gfp_t)0x80000u)/* Page is reclaimable */ #define __GFP_MOVABLE ((__force gfp_t)0x100000u)/* Page is movable */ +#define __GFP_NO_OOM_KILL ((__force gfp_t)0x200000u)/* Don't invoke out_of_memory() */ -#define __GFP_BITS_SHIFT 21/* Room for 21 __GFP_FOO bits */ +#define __GFP_BITS_SHIFT 22/* Number of__GFP_FOO bits */
^ missed a white space :)
Re: [PATCH 1/4] mm: Add __GFP_NO_OOM_KILL flag
In reply to Rafael J. WysockiQuoted 38 lines · Rafael J. Wysocki
From: Andrew Morton <[email protected]>
Quoted 4 lines
Quoted 1 line
Remind me: why can't we just allocate N pages at suspend-time?
We need half of memory free. The reason we can't "just allocate" is probably OOM killer; but my memories are quite weak :-(.
hm. You'd think that with our splendid range of
__GFP_foofalgs, there would be some combo which would suit this requirement but I can't immediately spot one.We can always add another I guess. Something like...
Signed-off-by Rafael J. Wysocki <[email protected]>--- include/linux/gfp.h | 3 ++- mm/page_alloc.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-)Index:
linux-2.6/mm/page_alloc.c
===================================================================mm/page_alloc.c +2
-1@@ -1620,7 +1620,8 @@ nofail_alloc: }/* The OOM killer will not help higher order allocs so fail */ -if (order >PAGE_ALLOC_COSTLY_ORDER ) { +if (order >PAGE_ALLOC_COSTLY_ORDER || + (gfp_mask & __GFP_NO_OOM_KILL)) {clear_zonelist_oom (zonelist, gfp_mask); goto nopage; }Index:
linux-2.6/include/linux/gfp.h
===================================================================
include/linux/gfp.h struct vm_area_struct; · line 56
Quoted 7 lines
include/linux/gfp.h +2
-1@@ -51,8 +51,9 @@ struct vm_area_struct;#define __GFP_THISNODE ((__force gfp_t)0x40000u)/* No fallback, no policies */ #define __GFP_RECLAIMABLE ((__force gfp_t)0x80000u)/* Page is reclaimable */ #define __GFP_MOVABLE ((__force gfp_t)0x100000u)/* Page is movable */ +#define __GFP_NO_OOM_KILL ((__force gfp_t)0x200000u)/* Don't invoke out_of_memory() */ -#define __GFP_BITS_SHIFT 21/* Room for 21 __GFP_FOO bits */ +#define __GFP_BITS_SHIFT 22/* Number of__GFP_FOO bits */
^ missed a white space :)
PATCH 1/4 mm: Add __GFP_NO_OOM_KILL flag
In reply to Rafael J. WysockiFrom: Andrew Morton <[email protected]>
Quoted 4 lines
Quoted 1 line
Remind me: why can't we just allocate N pages at suspend-time?
We need half of memory free. The reason we can't "just allocate" is probably OOM killer; but my memories are quite weak :-(.
hm. You'd think that with our splendid range of __GFP_foo falgs, there would be some combo which would suit this requirement but I can't immediately spot one.
We can always add another I guess. Something like...
--- include/linux/gfp.h | 3 ++- mm/page_alloc.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-)
mm/page_alloc.c +2 -1
@@ -1620,7 +1620,8 @@ nofail_alloc: }/* The OOM killer will not help higher order allocs so fail */ -if (order >PAGE_ALLOC_COSTLY_ORDER ) { +if (order >PAGE_ALLOC_COSTLY_ORDER || + (gfp_mask & __GFP_NO_OOM_KILL)) {clear_zonelist_oom (zonelist, gfp_mask); goto nopage; }
include/linux/gfp.h +2 -1
@@ -51,8 +51,9 @@ struct vm_area_struct;#define __GFP_THISNODE ((__force gfp_t)0x40000u)/* No fallback, no policies */ #define __GFP_RECLAIMABLE ((__force gfp_t)0x80000u)/* Page is reclaimable */ #define __GFP_MOVABLE ((__force gfp_t)0x100000u)/* Page is movable */ +#define __GFP_NO_OOM_KILL ((__force gfp_t)0x200000u)/* Don't invoke out_of_memory() */ -#define __GFP_BITS_SHIFT 21/* Room for 21 __GFP_FOO bits */ +#define __GFP_BITS_SHIFT 22/* Number of__GFP_FOO bits */ #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))/* This equals 0, but use constants in case they ever change */
PATCH 2/4 PM/Hibernate: Move memory shrinking to snapshot.c (rev. 2)
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
The next patch is going to modify the memory shrinking code so that it will make memory allocations to free memory instead of using an artificial memory shrinking mechanism for that. For this purpose it is convenient to move swsusp_shrink_memory() from kernel/power/swsusp.c to kernel/power/snapshot.c, because the new memory-shrinking code is going to use things that are local to kernel/power/snapshot.c .
[rev. 2: Make some functions static and remove their headers from
kernel/power/power.h]
--- kernel/power/power.h | 4 -- kernel/power/snapshot.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++-- kernel/power/swsusp.c | 76 --------------------------------------------- 3 files changed, 79 insertions(+), 81 deletions(-)
kernel/power/snapshot.c +78 -2
@@ -39,6 +39,14 @@ static int swsusp_page_is_free(struct pastatic void swsusp_set_page_forbidden (struct page *);static void swsusp_unset_page_forbidden (struct page *); +/* +* Preferred image size in bytes (tunable via /sys/power/image_size). +* When it is set to N, swsusp will do its best to ensure the image +* size will not exceed N bytes, but if that is impossible, it will +* try to create the smallest image possible. +*/ +unsigned long image_size =500 *1024 *1024 ; +/* List of PBEs needed for restoring the pages that were allocated before * the suspend and included in the suspend image, but have also been * allocated by the "resume" kernel, so their contents cannot be written
@@ -840,7 +848,7 @@ static struct page *saveable_highmem_pag* pages. */ -unsigned int count_highmem_pages (void ) +static unsigned int count_highmem_pages (void ) {struct zone *zone;unsigned int n =0 ;
@@ -902,7 +910,7 @@ static struct page *saveable_page(struct* pages. */ -unsigned int count_data_pages (void ) +static unsigned int count_data_pages (void ) {struct zone *zone;unsigned long pfn, max_zone_pfn;
@@ -1058,6 +1066,74 @@ void swsusp_free(void) buffer =NULL ; } +/** +* swsusp_shrink_memory - Try to free as much memory as needed +* +* ... but do not OOM-kill anyone +* +* Notice: all userland should be stopped before it is called, or +* livelock is possible. +*/ + +#define SHRINK_BITE 10000 +static inline unsigned long __shrink_memory (long tmp) +{ +if (tmp >SHRINK_BITE ) + tmp =SHRINK_BITE ; +return shrink_all_memory (tmp); +} + +int swsusp_shrink_memory (void ) +{ +long tmp; +struct zone *zone; +unsigned long pages =0 ; +unsigned int i =0 ; +char *p ="-\\|/" ; +struct timeval start, stop; + +printk (KERN_INFO "PM: Shrinking memory... " ); +do_gettimeofday (&start); +do { +long size, highmem_size; + + highmem_size =count_highmem_pages (); + size =count_data_pages () +PAGES_FOR_IO +SPARE_PAGES ; + tmp = size; + size += highmem_size; +for_each_populated_zone (zone) { + tmp +=snapshot_additional_pages (zone); +if (is_highmem (zone)) { + highmem_size -= +zone_page_state (zone,NR_FREE_PAGES ); + }else { + tmp -=zone_page_state (zone,NR_FREE_PAGES ); + tmp += zone->lowmem_reserve[ZONE_NORMAL ]; + } + } + +if (highmem_size <0 ) + highmem_size =0 ; + + tmp += highmem_size; +if (tmp >0 ) { + tmp =__shrink_memory (tmp); +if (!tmp) +return -ENOMEM ; + pages += tmp; + }else if (size > image_size /PAGE_SIZE ) { + tmp =__shrink_memory (size - (image_size /PAGE_SIZE )); + pages += tmp; + } +printk ("\b%c" , p[i++%4 ]); + }while (tmp >0 ); +do_gettimeofday (&stop); +printk ("\bdone (%lu pages freed)\n" , pages); +swsusp_show_speed (&start, &stop, pages,"Freed" ); + +return 0 ; +} +#ifdef CONFIG_HIGHMEM /** * count_pages_for_highmem - compute the number of non-highmem pages
kernel/power/swsusp.c +0 -76
88 lines not on this page · raw message
kernel/power/power.h +1 -3
@@ -74,7 +74,7 @@ extern asmlinkage int swsusp_arch_resumeextern int create_basic_memory_bitmaps (void );extern void free_basic_memory_bitmaps (void ); -extern unsigned int count_data_pages (void ); +extern int swsusp_shrink_memory (void );/** * Auxiliary structure used for reading the snapshot image data and
@@ -149,7 +149,6 @@ extern int swsusp_swap_in_use(void);/* kernel/power/disk.c */ extern int swsusp_check (void ); -extern int swsusp_shrink_memory (void );extern void swsusp_free (void );extern int swsusp_read (unsigned int *flags_p);extern int swsusp_write (unsigned int flags);
@@ -176,7 +175,6 @@ extern int pm_notifier_call_chain(unsign#endif #ifdef CONFIG_HIGHMEM -unsigned int count_highmem_pages (void );int restore_highmem (void );#else static inline unsigned int count_highmem_pages (void ) {return 0 ; }
PATCH 2/4 PM/Hibernate: Move memory shrinking to snapshot.c (rev. 2)
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
The next patch is going to modify the memory shrinking code so that it will make memory allocations to free memory instead of using an artificial memory shrinking mechanism for that. For this purpose it is convenient to move swsusp_shrink_memory() from kernel/power/swsusp.c to kernel/power/snapshot.c, because the new memory-shrinking code is going to use things that are local to kernel/power/snapshot.c .
[rev. 2: Make some functions static and remove their headers from
kernel/power/power.h]
--- kernel/power/power.h | 4 -- kernel/power/snapshot.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++-- kernel/power/swsusp.c | 76 --------------------------------------------- 3 files changed, 79 insertions(+), 81 deletions(-)
kernel/power/snapshot.c +78 -2
@@ -39,6 +39,14 @@ static int swsusp_page_is_free(struct pastatic void swsusp_set_page_forbidden (struct page *);static void swsusp_unset_page_forbidden (struct page *); +/* +* Preferred image size in bytes (tunable via /sys/power/image_size). +* When it is set to N, swsusp will do its best to ensure the image +* size will not exceed N bytes, but if that is impossible, it will +* try to create the smallest image possible. +*/ +unsigned long image_size =500 *1024 *1024 ; +/* List of PBEs needed for restoring the pages that were allocated before * the suspend and included in the suspend image, but have also been * allocated by the "resume" kernel, so their contents cannot be written
@@ -840,7 +848,7 @@ static struct page *saveable_highmem_pag* pages. */ -unsigned int count_highmem_pages (void ) +static unsigned int count_highmem_pages (void ) {struct zone *zone;unsigned int n =0 ;
@@ -902,7 +910,7 @@ static struct page *saveable_page(struct* pages. */ -unsigned int count_data_pages (void ) +static unsigned int count_data_pages (void ) {struct zone *zone;unsigned long pfn, max_zone_pfn;
@@ -1058,6 +1066,74 @@ void swsusp_free(void) buffer =NULL ; } +/** +* swsusp_shrink_memory - Try to free as much memory as needed +* +* ... but do not OOM-kill anyone +* +* Notice: all userland should be stopped before it is called, or +* livelock is possible. +*/ + +#define SHRINK_BITE 10000 +static inline unsigned long __shrink_memory (long tmp) +{ +if (tmp >SHRINK_BITE ) + tmp =SHRINK_BITE ; +return shrink_all_memory (tmp); +} + +int swsusp_shrink_memory (void ) +{ +long tmp; +struct zone *zone; +unsigned long pages =0 ; +unsigned int i =0 ; +char *p ="-\\|/" ; +struct timeval start, stop; + +printk (KERN_INFO "PM: Shrinking memory... " ); +do_gettimeofday (&start); +do { +long size, highmem_size; + + highmem_size =count_highmem_pages (); + size =count_data_pages () +PAGES_FOR_IO +SPARE_PAGES ; + tmp = size; + size += highmem_size; +for_each_populated_zone (zone) { + tmp +=snapshot_additional_pages (zone); +if (is_highmem (zone)) { + highmem_size -= +zone_page_state (zone,NR_FREE_PAGES ); + }else { + tmp -=zone_page_state (zone,NR_FREE_PAGES ); + tmp += zone->lowmem_reserve[ZONE_NORMAL ]; + } + } + +if (highmem_size <0 ) + highmem_size =0 ; + + tmp += highmem_size; +if (tmp >0 ) { + tmp =__shrink_memory (tmp); +if (!tmp) +return -ENOMEM ; + pages += tmp; + }else if (size > image_size /PAGE_SIZE ) { + tmp =__shrink_memory (size - (image_size /PAGE_SIZE )); + pages += tmp; + } +printk ("\b%c" , p[i++%4 ]); + }while (tmp >0 ); +do_gettimeofday (&stop); +printk ("\bdone (%lu pages freed)\n" , pages); +swsusp_show_speed (&start, &stop, pages,"Freed" ); + +return 0 ; +} +#ifdef CONFIG_HIGHMEM /** * count_pages_for_highmem - compute the number of non-highmem pages
kernel/power/swsusp.c +0 -76
88 lines not on this page · raw message
kernel/power/power.h +1 -3
@@ -74,7 +74,7 @@ extern asmlinkage int swsusp_arch_resumeextern int create_basic_memory_bitmaps (void );extern void free_basic_memory_bitmaps (void ); -extern unsigned int count_data_pages (void ); +extern int swsusp_shrink_memory (void );/** * Auxiliary structure used for reading the snapshot image data and
@@ -149,7 +149,6 @@ extern int swsusp_swap_in_use(void);/* kernel/power/disk.c */ extern int swsusp_check (void ); -extern int swsusp_shrink_memory (void );extern void swsusp_free (void );extern int swsusp_read (unsigned int *flags_p);extern int swsusp_write (unsigned int flags);
@@ -176,7 +175,6 @@ extern int pm_notifier_call_chain(unsign#endif #ifdef CONFIG_HIGHMEM -unsigned int count_highmem_pages (void );int restore_highmem (void );#else static inline unsigned int count_highmem_pages (void ) {return 0 ; }
PATCH 3/4 PM/Hibernate: Use memory allocations to free memory (rev. 2)
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Modify the hibernation memory shrinking code so that it will make memory allocations to free memory instead of using an artificial memory shrinking mechanism for that. Remove the shrinking of memory from the suspend-to-RAM code, where it is not really necessary. Finally, remove the no longer used memory shrinking functions from mm/vmscan.c .
[rev. 2: Use the existing memory bitmaps for marking preallocated
image pages and use swsusp_free() from releasing them, introduce GFP_IMAGE, add comments describing the memory shrinking strategy.]
--- kernel/power/main.c | 20 ------ kernel/power/snapshot.c | 132 +++++++++++++++++++++++++++++++++----------- mm/vmscan.c | 142 ------------------------------------------------ 3 files changed, 101 insertions(+), 193 deletions(-)
kernel/power/snapshot.c +100 -32
@@ -1066,41 +1066,97 @@ void swsusp_free(void) buffer =NULL ; } +/* Helper functions used for the shrinking of memory. */ + +#ifdef CONFIG_HIGHMEM +#define GFP_IMAGE (GFP_KERNEL | __GFP_HIGHMEM | __GFP_NO_OOM_KILL) +#else +#define GFP_IMAGE (GFP_KERNEL | __GFP_NO_OOM_KILL) +#endif + +#define SHRINK_BITE 10000 +/** -* swsusp_shrink_memory - Try to free as much memory as needed +* prealloc_pages - preallocate given number of pages and mark their PFNs +* @nr_pages: Number of pages to allocate. * -* ... but do not OOM-kill anyone -* -* Notice: all userland should be stopped before it is called, or -* livelock is possible. +* Allocate given number of pages and mark their PFNs in the hibernation memory +* bitmaps, so that they can be released by swsusp_free(). +* Return value: The number of normal (ie. non-highmem) pages allocated or +* -ENOMEM on failure. */ - -#define SHRINK_BITE 10000 -static inline unsigned long __shrink_memory (long tmp) +static long prealloc_pages (long nr_pages) { -if (tmp >SHRINK_BITE ) - tmp =SHRINK_BITE ; -return shrink_all_memory (tmp); +long nr_normal =0 ; + +while (nr_pages-- >0 ) { +struct page *page; + + page =alloc_image_page (GFP_IMAGE ); +if (!page) +return -ENOMEM ; +if (!PageHighMem (page)) + nr_normal++; + } + +return nr_normal; } +/** +* swsusp_shrink_memory - Make the kernel release as much memory as needed +* +* To create a hibernation image it is necessary to make a copy of every page +* frame in use. We also need a number of page frames to be free during +* hibernation for allocations made while saving the image and for device +* drivers, in case they need to allocate memory from their hibernation +* callbacks (these two numbers are given by PAGES_FOR_IO and SPARE_PAGES, +* respectively, both of which are rough estimates). To make this happen, we +* preallocate memory in SHRINK_BITE chunks in a loop until the following +* condition is satisfied: +* +* [number of preallocated page frames] >= +* (1/2) * ([total number of page frames in use] + PAGES_FOR_IO +* + SPARE_PAGES - [number of free page frames]) +* +* because in that case, if all of the preallocated page frames are released, +* the total number of free page frames will be equal to or greater than the sum +* of the total number of page frames in use with PAGES_FOR_IO and SPARE_PAGES, +* which is what we need. +* +* If image_size is set below the number following from the above inequality, +* the preallocation of memory is continued until the total number of page +* frames in use is below the requested image size. +*/ int swsusp_shrink_memory (void ) { -long tmp; -struct zone *zone; -unsigned long pages =0 ; +unsigned long pages =0 , alloc_normal =0 , alloc_highmem =0 ;unsigned int i =0 ;char *p ="-\\|/" ;struct timeval start, stop; +int error =0 ;printk (KERN_INFO "PM: Shrinking memory... " );do_gettimeofday (&start); - do { - long size, highmem_size; - highmem_size = count_highmem_pages(); - size = count_data_pages() + PAGES_FOR_IO + SPARE_PAGES; - tmp = size; +for (;;) { +struct zone *zone; +long size, highmem_size, tmp, ret; + +/* +* Pages preallocated by this loop are not counted as data pages +* by count_data_pages() and count_highmem_pages(), so we only +* need to subtract their numbers once here to verify the +* satisfaction of the stop condition. +*/ + size =count_data_pages () - alloc_normal; + tmp = size +PAGES_FOR_IO +SPARE_PAGES ; + highmem_size =count_highmem_pages () - alloc_highmem; size += highmem_size; +/* +* Highmem is treated differently, because we prefer not to +* store copies of normal page frames in it during image +* creation. +*/ for_each_populated_zone (zone) { tmp +=snapshot_additional_pages (zone);if (is_highmem (zone)) {
@@ -1111,27 +1167,39 @@ int swsusp_shrink_memory(void) tmp += zone->lowmem_reserve[ZONE_NORMAL ]; } } -if (highmem_size <0 ) highmem_size =0 ; - tmp += highmem_size; -if (tmp >0 ) { - tmp =__shrink_memory (tmp); -if (!tmp) -return -ENOMEM ; - pages += tmp; - }else if (size > image_size /PAGE_SIZE ) { - tmp =__shrink_memory (size - (image_size /PAGE_SIZE )); - pages += tmp; + +if (tmp <=0 && size > image_size /PAGE_SIZE ) + tmp = size - (image_size /PAGE_SIZE ); + +if (tmp >SHRINK_BITE ) + tmp =SHRINK_BITE ; +else if (tmp <=0 ) +break ; + + ret =prealloc_pages (tmp); +if (ret <0 ) { + error = -ENOMEM ; + goto out; } + alloc_normal += ret; + alloc_highmem += tmp - ret; + pages += tmp; +printk ("\b%c" , p[i++%4 ]); - }while (tmp >0 ); + } +do_gettimeofday (&stop); -printk ("\bdone (%lu pages freed)\n" , pages); +printk ("\bdone (preallocated %lu free pages)\n" , pages);swsusp_show_speed (&start, &stop, pages,"Freed" ); -return 0 ; + out: +/* Release the preallocated page frames. */ +swsusp_free (); + +return error; }#ifdef CONFIG_HIGHMEM
mm/vmscan.c +0 -142
148 lines not on this page · raw message
kernel/power/main.c +1 -19
@@ -188,9 +188,6 @@ static void suspend_test_finish(const ch#endif -/* This is just an arbitrary number */ -#define FREE_PAGE_NUMBER (100) -static struct platform_suspend_ops *suspend_ops;/**
@@ -226,7 +223,6 @@ int suspend_valid_only_mem(suspend_statestatic int suspend_prepare (void ) {int error; -unsigned int free_pages;if (!suspend_ops || !suspend_ops->enter)return -EPERM ;
@@ -241,24 +237,10 @@ static int suspend_prepare(void)if (error) goto Finish; -if (suspend_freeze_processes ()) { - error = -EAGAIN ; - goto Thaw; - } - - free_pages =global_page_state (NR_FREE_PAGES ); -if (free_pages <FREE_PAGE_NUMBER ) { -pr_debug ("PM: free some memory\n" ); -shrink_all_memory (FREE_PAGE_NUMBER - free_pages); -if (nr_free_pages () <FREE_PAGE_NUMBER ) { - error = -ENOMEM ; -printk (KERN_ERR "PM: No enough memory\n" ); - } - } + error =suspend_freeze_processes ();if (!error)return 0 ; - Thaw:suspend_thaw_processes ();usermodehelper_enable (); Finish:
Re: [PATCH 3/4] PM/Hibernate: Use memory allocations to free memory (rev. 2)
Quoted 3 lines · Rafael J. Wysocki
Remove the shrinking of memory from the suspend-to-RAM code, where it is not really necessary.
Hmm. Shouldn't we do this _regardless_?
IOW, shouldn't this be a totally separate patch? It seems to be left-over from when we shared the same code-paths, and before the split of the STR and hibernate code?
IOW, shouldn't the very _first_ patch just be this part? That code doesn't make any sense anyway (that FREE_PAGE_NUMBER really _is_ totally arbitrary).
This part seems to be totally independent of all the other parts in your patch-series. No?
Linus
--- kernel/power/main.c | 19 +------------------ 1 files changed, 1 insertions(+), 18 deletions(-)
kernel/power/main.c +1 -18
@@ -188,9 +188,6 @@ static void suspend_test_finish(const char *label)#endif -/* This is just an arbitrary number */ -#define FREE_PAGE_NUMBER (100) -static struct platform_suspend_ops *suspend_ops;/**
@@ -241,24 +238,10 @@ static int suspend_prepare(void)if (error) goto Finish; -if (suspend_freeze_processes ()) { - error = -EAGAIN ; - goto Thaw; - } - - free_pages =global_page_state (NR_FREE_PAGES ); -if (free_pages <FREE_PAGE_NUMBER ) { -pr_debug ("PM: free some memory\n" ); -shrink_all_memory (FREE_PAGE_NUMBER - free_pages); -if (nr_free_pages () <FREE_PAGE_NUMBER ) { - error = -ENOMEM ; -printk (KERN_ERR "PM: No enough memory\n" ); - } - } + error =suspend_freeze_processes ();if (!error)return 0 ; - Thaw:suspend_thaw_processes ();usermodehelper_enable (); Finish:
Re: [PATCH 3/4] PM/Hibernate: Use memory allocations to free memory (rev. 2)
Hi!
Quoted 9 lines
Quoted 2 lines
Remove the shrinking of memory from the suspend-to-RAM code, where it is not really necessary.
Hmm. Shouldn't we do this _regardless_?
IOW, shouldn't this be a totally separate patch? It seems to be left-over from when we shared the same code-paths, and before the split of the STR and hibernate code?
Quoted 6 lines
IOW, shouldn't the very _first_ patch just be this part? That code doesn't make any sense anyway (that
FREE_PAGE_NUMBERreally _is_ totally arbitrary).This part seems to be totally independent of all the other parts in your patch-series. No?
I'm not sure this one is a good idea: drivers will need to allocate memory during suspend/resume, and when processes are frozen/disk driver is suspended, normal memory management will no longer work.
So, freeing 4M of memory before starting suspend seems like a good idea. That way those small alocations will not fail.
Pavel
Quoted 36 lines
kernel/power/main.c +1
-18@@ -188,9 +188,6 @@ static void suspend_test_finish(const char *label)#endif -/* This is just an arbitrary number */ -#define FREE_PAGE_NUMBER (100) -static struct platform_suspend_ops *suspend_ops;/** @@ -241,24 +238,10 @@ static int suspend_prepare(void)if (error) goto Finish; -if (suspend_freeze_processes ()) { - error = -EAGAIN ; - goto Thaw; - } - - free_pages =global_page_state (NR_FREE_PAGES ); -if (free_pages <FREE_PAGE_NUMBER ) { -pr_debug ("PM: free some memory\n" ); -shrink_all_memory (FREE_PAGE_NUMBER - free_pages); -if (nr_free_pages () <FREE_PAGE_NUMBER ) { - error = -ENOMEM ; -printk (KERN_ERR "PM: No enough memory\n" ); - } - } + error =suspend_freeze_processes ();if (!error)return 0 ; - Thaw:suspend_thaw_processes ();usermodehelper_enable (); Finish:
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: [PATCH 3/4] PM/Hibernate: Use memory allocations to free memory (rev. 2)
Quoted 1 line · Pavel Machek
Hi!
Hi,
Quoted 16 lines
Quoted 9 lines
Quoted 2 lines
Remove the shrinking of memory from the suspend-to-RAM code, where it is not really necessary.
Hmm. Shouldn't we do this _regardless_?
IOW, shouldn't this be a totally separate patch? It seems to be left-over from when we shared the same code-paths, and before the split of the STR and hibernate code?
Quoted 6 lines
IOW, shouldn't the very _first_ patch just be this part? That code doesn't make any sense anyway (that
FREE_PAGE_NUMBERreally _is_ totally arbitrary).This part seems to be totally independent of all the other parts in your patch-series. No?
Quoted 6 lines
I'm not sure this one is a good idea: drivers will need to allocate memory during suspend/resume, and when processes are frozen/disk driver is suspended, normal memory management will no longer work.
So, freeing 4M of memory before starting suspend seems like a good idea. That way those small alocations will not fail.
I don't think we've ever had problems with the drivers having too little memory to suspend.
I'm opting for removing this code and seeing if that leads to any regressions. If it does, we can still get some free memory by allocating and releasing it.
Thanks,
Rafael
Re: [PATCH 3/4] PM/Hibernate: Use memory allocations to free memory (rev. 2)
Quoted 25 lines · Rafael J. Wysocki
Quoted 1 line · Pavel Machek
Hi!
Hi,
Quoted 20 lines
Quoted 9 lines
Quoted 2 lines
Remove the shrinking of memory from the suspend-to-RAM code, where it is not really necessary.
Hmm. Shouldn't we do this _regardless_?
IOW, shouldn't this be a totally separate patch? It seems to be left-over from when we shared the same code-paths, and before the split of the STR and hibernate code?
Quoted 6 lines
IOW, shouldn't the very _first_ patch just be this part? That code doesn't make any sense anyway (that
FREE_PAGE_NUMBERreally _is_ totally arbitrary).This part seems to be totally independent of all the other parts in your patch-series. No?
I'm not sure this one is a good idea: drivers will need to allocate memory during suspend/resume, and when processes are frozen/disk driver is suspended, normal memory management will no longer work.
Quoted 5 lines
Quoted 2 lines
So, freeing 4M of memory before starting suspend seems like a good idea. That way those small alocations will not fail.
I don't think we've ever had problems with the drivers having too little memory to suspend.
Well, we had the 4MB buffer there, so it is hardly surprising.
Quoted 2 lines
I'm opting for removing this code and seeing if that leads to any regressions. If it does, we can still get some free memory by allocating and releasing it.
I believe we should. If we don't... we will not get any regression reports, because it will probably just hang with black screen :-(, and "being out of memory during suspend" is probably going to be hard to reproduce.
Perhaps we should try to _eat_ all memory available during suspend to test driver behaviour with 0 pages free?
while (kmalloc(100, GFP_ATOMIC)) ;
in suspend path should just do it for testing.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: [PATCH 3/4] PM/Hibernate: Use memory allocations to free memory (rev. 2)
In reply to Rafael J. WysockiQuoted 25 lines · Rafael J. Wysocki
Quoted 1 line · Pavel Machek
Hi!
Hi,
Quoted 20 lines
Quoted 9 lines
Quoted 2 lines
Remove the shrinking of memory from the suspend-to-RAM code, where it is not really necessary.
Hmm. Shouldn't we do this _regardless_?
IOW, shouldn't this be a totally separate patch? It seems to be left-over from when we shared the same code-paths, and before the split of the STR and hibernate code?
Quoted 6 lines
IOW, shouldn't the very _first_ patch just be this part? That code doesn't make any sense anyway (that
FREE_PAGE_NUMBERreally _is_ totally arbitrary).This part seems to be totally independent of all the other parts in your patch-series. No?
I'm not sure this one is a good idea: drivers will need to allocate memory during suspend/resume, and when processes are frozen/disk driver is suspended, normal memory management will no longer work.
Quoted 5 lines
Quoted 2 lines
So, freeing 4M of memory before starting suspend seems like a good idea. That way those small alocations will not fail.
I don't think we've ever had problems with the drivers having too little memory to suspend.
Well, we had the 4MB buffer there, so it is hardly surprising.
Quoted 2 lines
I'm opting for removing this code and seeing if that leads to any regressions. If it does, we can still get some free memory by allocating and releasing it.
I believe we should. If we don't... we will not get any regression reports, because it will probably just hang with black screen :-(, and "being out of memory during suspend" is probably going to be hard to reproduce.
Perhaps we should try to _eat_ all memory available during suspend to test driver behaviour with 0 pages free?
while (kmalloc(100, GFP_ATOMIC)) ;
in suspend path should just do it for testing.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: [PATCH 3/4] PM/Hibernate: Use memory allocations to free memory (rev. 2)
In reply to Pavel MachekQuoted 1 line · Pavel Machek
Hi!
Hi,
Quoted 16 lines
Quoted 9 lines
Quoted 2 lines
Remove the shrinking of memory from the suspend-to-RAM code, where it is not really necessary.
Hmm. Shouldn't we do this _regardless_?
IOW, shouldn't this be a totally separate patch? It seems to be left-over from when we shared the same code-paths, and before the split of the STR and hibernate code?
Quoted 6 lines
IOW, shouldn't the very _first_ patch just be this part? That code doesn't make any sense anyway (that
FREE_PAGE_NUMBERreally _is_ totally arbitrary).This part seems to be totally independent of all the other parts in your patch-series. No?
Quoted 6 lines
I'm not sure this one is a good idea: drivers will need to allocate memory during suspend/resume, and when processes are frozen/disk driver is suspended, normal memory management will no longer work.
So, freeing 4M of memory before starting suspend seems like a good idea. That way those small alocations will not fail.
I don't think we've ever had problems with the drivers having too little memory to suspend.
I'm opting for removing this code and seeing if that leads to any regressions. If it does, we can still get some free memory by allocating and releasing it.
Thanks,
Rafael
Re: [PATCH 3/4] PM/Hibernate: Use memory allocations to free memory (rev. 2)
In reply to Linus TorvaldsHi!
Quoted 9 lines
Quoted 2 lines
Remove the shrinking of memory from the suspend-to-RAM code, where it is not really necessary.
Hmm. Shouldn't we do this _regardless_?
IOW, shouldn't this be a totally separate patch? It seems to be left-over from when we shared the same code-paths, and before the split of the STR and hibernate code?
Quoted 6 lines
IOW, shouldn't the very _first_ patch just be this part? That code doesn't make any sense anyway (that
FREE_PAGE_NUMBERreally _is_ totally arbitrary).This part seems to be totally independent of all the other parts in your patch-series. No?
I'm not sure this one is a good idea: drivers will need to allocate memory during suspend/resume, and when processes are frozen/disk driver is suspended, normal memory management will no longer work.
So, freeing 4M of memory before starting suspend seems like a good idea. That way those small alocations will not fail.
Pavel
Quoted 36 lines
kernel/power/main.c +1
-18@@ -188,9 +188,6 @@ static void suspend_test_finish(const char *label)#endif -/* This is just an arbitrary number */ -#define FREE_PAGE_NUMBER (100) -static struct platform_suspend_ops *suspend_ops;/** @@ -241,24 +238,10 @@ static int suspend_prepare(void)if (error) goto Finish; -if (suspend_freeze_processes ()) { - error = -EAGAIN ; - goto Thaw; - } - - free_pages =global_page_state (NR_FREE_PAGES ); -if (free_pages <FREE_PAGE_NUMBER ) { -pr_debug ("PM: free some memory\n" ); -shrink_all_memory (FREE_PAGE_NUMBER - free_pages); -if (nr_free_pages () <FREE_PAGE_NUMBER ) { - error = -ENOMEM ; -printk (KERN_ERR "PM: No enough memory\n" ); - } - } + error =suspend_freeze_processes ();if (!error)return 0 ; - Thaw:suspend_thaw_processes ();usermodehelper_enable (); Finish:
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: [PATCH 3/4] PM/Hibernate: Use memory allocations to free memory (rev. 2)
In reply to Linus TorvaldsQuoted 12 lines · Linus Torvalds
Quoted 3 lines · Rafael J. Wysocki
Remove the shrinking of memory from the suspend-to-RAM code, where it is not really necessary.
Hmm. Shouldn't we do this _regardless_?
IOW, shouldn't this be a totally separate patch? It seems to be left-over from when we shared the same code-paths, and before the split of the STR and hibernate code?
Quoted 6 lines
IOW, shouldn't the very _first_ patch just be this part? That code doesn't make any sense anyway (that
FREE_PAGE_NUMBERreally _is_ totally arbitrary).This part seems to be totally independent of all the other parts in your patch-series. No?
I'm removing this along with shrink_all_memory() which it depends on, but I can put that into a separate patch if you prefer.
Thanks,
Rafael
Re: [PATCH 3/4] PM/Hibernate: Use memory allocations to free memory (rev. 2)
In reply to Linus TorvaldsQuoted 12 lines · Linus Torvalds
Quoted 3 lines · Rafael J. Wysocki
Remove the shrinking of memory from the suspend-to-RAM code, where it is not really necessary.
Hmm. Shouldn't we do this _regardless_?
IOW, shouldn't this be a totally separate patch? It seems to be left-over from when we shared the same code-paths, and before the split of the STR and hibernate code?
Quoted 6 lines
IOW, shouldn't the very _first_ patch just be this part? That code doesn't make any sense anyway (that
FREE_PAGE_NUMBERreally _is_ totally arbitrary).This part seems to be totally independent of all the other parts in your patch-series. No?
I'm removing this along with shrink_all_memory() which it depends on, but I can put that into a separate patch if you prefer.
Thanks,
Rafael
Re: [PATCH 3/4] PM/Hibernate: Use memory allocations to free memory (rev. 2)
In reply to Rafael J. WysockiQuoted 3 lines · Rafael J. Wysocki
Remove the shrinking of memory from the suspend-to-RAM code, where it is not really necessary.
Hmm. Shouldn't we do this _regardless_?
IOW, shouldn't this be a totally separate patch? It seems to be left-over from when we shared the same code-paths, and before the split of the STR and hibernate code?
IOW, shouldn't the very _first_ patch just be this part? That code doesn't make any sense anyway (that FREE_PAGE_NUMBER really _is_ totally arbitrary).
This part seems to be totally independent of all the other parts in your patch-series. No?
Linus
--- kernel/power/main.c | 19 +------------------ 1 files changed, 1 insertions(+), 18 deletions(-)
kernel/power/main.c +1 -18
@@ -188,9 +188,6 @@ static void suspend_test_finish(const char *label)#endif -/* This is just an arbitrary number */ -#define FREE_PAGE_NUMBER (100) -static struct platform_suspend_ops *suspend_ops;/**
@@ -241,24 +238,10 @@ static int suspend_prepare(void)if (error) goto Finish; -if (suspend_freeze_processes ()) { - error = -EAGAIN ; - goto Thaw; - } - - free_pages =global_page_state (NR_FREE_PAGES ); -if (free_pages <FREE_PAGE_NUMBER ) { -pr_debug ("PM: free some memory\n" ); -shrink_all_memory (FREE_PAGE_NUMBER - free_pages); -if (nr_free_pages () <FREE_PAGE_NUMBER ) { - error = -ENOMEM ; -printk (KERN_ERR "PM: No enough memory\n" ); - } - } + error =suspend_freeze_processes ();if (!error)return 0 ; - Thaw:suspend_thaw_processes ();usermodehelper_enable (); Finish:
Re: [PATCH 3/4] PM/Hibernate: Use memory allocations to free memory (rev. 2)
In reply to Rafael J. WysockiQuoted 25 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
Modify the hibernation memory shrinking code so that it will make memory allocations to free memory instead of using an artificial memory shrinking mechanism for that. Remove the shrinking of memory from the suspend-to-RAM code, where it is not really necessary. Finally, remove the no longer used memory shrinking functions from
mm/vmscan.c.[rev. 2: Use the existing memory bitmaps for marking preallocated
image pages and useswsusp_free()from releasing them, introduceGFP_IMAGE, add comments describing the memory shrinking strategy.]Signed-off-by Rafael J. Wysocki <[email protected]>--- kernel/power/main.c | 20 ------ kernel/power/snapshot.c | 132 +++++++++++++++++++++++++++++++++----------- mm/vmscan.c | 142 ------------------------------------------------ 3 files changed, 101 insertions(+), 193 deletions(-)Index:
linux-2.6/kernel/power/snapshot.c
===================================================================
kernel/power/snapshot.c void swsusp_free(void) · line 1075
Quoted 10 lines
kernel/power/snapshot.c +7
-0@@ -1066,41 +1066,97 @@ void swsusp_free(void) buffer =NULL ; } +/* Helper functions used for the shrinking of memory. */ + +#ifdef CONFIG_HIGHMEM +#define GFP_IMAGE (GFP_KERNEL | __GFP_HIGHMEM | __GFP_NO_OOM_KILL) +#else +#define GFP_IMAGE (GFP_KERNEL | __GFP_NO_OOM_KILL) +#endif
The CONFIG_HIGHMEM test is not necessary: __GFP_HIGHMEM is always defined.
kernel/power/snapshot.c void swsusp_free(void) · line 1077
Quoted 1 line
kernel/power/snapshot.c +1
-0+#define SHRINK_BITE 10000
This is ~40MB. A full scan of (for example) 8G pages will be time consuming, not to mention we have to do it 2*(8G-500M)/40M = 384 times!
Can we make it a LONG_MAX?
Thanks,
Fengguang
Re: [PATCH 3/4] PM/Hibernate: Use memory allocations to free memory (rev. 2)
Quoted 39 lines · Wu Fengguang
Quoted 25 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
Modify the hibernation memory shrinking code so that it will make memory allocations to free memory instead of using an artificial memory shrinking mechanism for that. Remove the shrinking of memory from the suspend-to-RAM code, where it is not really necessary. Finally, remove the no longer used memory shrinking functions from
mm/vmscan.c.[rev. 2: Use the existing memory bitmaps for marking preallocated
image pages and useswsusp_free()from releasing them, introduceGFP_IMAGE, add comments describing the memory shrinking strategy.]Signed-off-by Rafael J. Wysocki <[email protected]>--- kernel/power/main.c | 20 ------ kernel/power/snapshot.c | 132 +++++++++++++++++++++++++++++++++----------- mm/vmscan.c | 142 ------------------------------------------------ 3 files changed, 101 insertions(+), 193 deletions(-)Index:
linux-2.6/kernel/power/snapshot.c
===================================================================kernel/power/snapshot.c void swsusp_free(void) · line 1075
Quoted 10 lines
kernel/power/snapshot.c +7
-0@@ -1066,41 +1066,97 @@ void swsusp_free(void) buffer =NULL ; } +/* Helper functions used for the shrinking of memory. */ + +#ifdef CONFIG_HIGHMEM +#define GFP_IMAGE (GFP_KERNEL | __GFP_HIGHMEM | __GFP_NO_OOM_KILL) +#else +#define GFP_IMAGE (GFP_KERNEL | __GFP_NO_OOM_KILL) +#endif The
CONFIG_HIGHMEMtest is not necessary:__GFP_HIGHMEMis always defined.
Quoted 6 lines
kernel/power/snapshot.c void swsusp_free(void) · line 1077
Quoted 1 line
kernel/power/snapshot.c +1
-0+#define SHRINK_BITE 10000This is ~40MB. A full scan of (for example) 8G pages will be time consuming, not to mention we have to do it 2*(8G-500M)/40M = 384 times!
Can we make it a
LONG_MAX?
No, I don't think so. The problem is the number of pages we'll need to copy is generally shrinking as we allocate memory, so we can't do that in one shot.
We can make it a greater number, but I don't really think it would be a good idea to make it greater than 100 MB.
Thanks,
Rafael
Re: [PATCH 3/4] PM/Hibernate: Use memory allocations to free memory (rev. 2)
Quoted 45 lines · Rafael J. Wysocki
Quoted 44 lines · Wu Fengguang
Quoted 25 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
Modify the hibernation memory shrinking code so that it will make memory allocations to free memory instead of using an artificial memory shrinking mechanism for that. Remove the shrinking of memory from the suspend-to-RAM code, where it is not really necessary. Finally, remove the no longer used memory shrinking functions from
mm/vmscan.c.[rev. 2: Use the existing memory bitmaps for marking preallocated
image pages and useswsusp_free()from releasing them, introduceGFP_IMAGE, add comments describing the memory shrinking strategy.]Signed-off-by Rafael J. Wysocki <[email protected]>--- kernel/power/main.c | 20 ------ kernel/power/snapshot.c | 132 +++++++++++++++++++++++++++++++++----------- mm/vmscan.c | 142 ------------------------------------------------ 3 files changed, 101 insertions(+), 193 deletions(-)Index:
linux-2.6/kernel/power/snapshot.c
===================================================================kernel/power/snapshot.c void swsusp_free(void) · line 1075
Quoted 10 lines
kernel/power/snapshot.c +7
-0@@ -1066,41 +1066,97 @@ void swsusp_free(void) buffer =NULL ; } +/* Helper functions used for the shrinking of memory. */ + +#ifdef CONFIG_HIGHMEM +#define GFP_IMAGE (GFP_KERNEL | __GFP_HIGHMEM | __GFP_NO_OOM_KILL) +#else +#define GFP_IMAGE (GFP_KERNEL | __GFP_NO_OOM_KILL) +#endif The
CONFIG_HIGHMEMtest is not necessary:__GFP_HIGHMEMis always defined.kernel/power/snapshot.c void swsusp_free(void) · line 1077
Quoted 1 line
kernel/power/snapshot.c +1
-0+#define SHRINK_BITE 10000This is ~40MB. A full scan of (for example) 8G pages will be time consuming, not to mention we have to do it 2*(8G-500M)/40M = 384 times!
Quoted 7 lines
Quoted 1 line
Can we make it a
LONG_MAX?No, I don't think so. The problem is the number of pages we'll need to copy is generally shrinking as we allocate memory, so we can't do that in one shot.
We can make it a greater number, but I don't really think it would be a good idea to make it greater than 100 MB.
Well, even 100MB is quite big: on 128MB machine, that will probably mean freeing all the memory (instead of "as much as needed"). And that memory needs to go to disk, so it will be slow.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: [PATCH 3/4] PM/Hibernate: Use memory allocations to free memory (rev. 2)
Quoted 51 lines · Pavel Machek
Quoted 50 lines · Rafael J. Wysocki
Quoted 39 lines · Wu Fengguang
Quoted 25 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
Modify the hibernation memory shrinking code so that it will make memory allocations to free memory instead of using an artificial memory shrinking mechanism for that. Remove the shrinking of memory from the suspend-to-RAM code, where it is not really necessary. Finally, remove the no longer used memory shrinking functions from
mm/vmscan.c.[rev. 2: Use the existing memory bitmaps for marking preallocated
image pages and useswsusp_free()from releasing them, introduceGFP_IMAGE, add comments describing the memory shrinking strategy.]Signed-off-by Rafael J. Wysocki <[email protected]>--- kernel/power/main.c | 20 ------ kernel/power/snapshot.c | 132 +++++++++++++++++++++++++++++++++----------- mm/vmscan.c | 142 ------------------------------------------------ 3 files changed, 101 insertions(+), 193 deletions(-)Index:
linux-2.6/kernel/power/snapshot.c
===================================================================kernel/power/snapshot.c void swsusp_free(void) · line 1075
Quoted 10 lines
kernel/power/snapshot.c +7
-0@@ -1066,41 +1066,97 @@ void swsusp_free(void) buffer =NULL ; } +/* Helper functions used for the shrinking of memory. */ + +#ifdef CONFIG_HIGHMEM +#define GFP_IMAGE (GFP_KERNEL | __GFP_HIGHMEM | __GFP_NO_OOM_KILL) +#else +#define GFP_IMAGE (GFP_KERNEL | __GFP_NO_OOM_KILL) +#endif The
CONFIG_HIGHMEMtest is not necessary:__GFP_HIGHMEMis always defined.Quoted 6 lines
kernel/power/snapshot.c void swsusp_free(void) · line 1077
Quoted 1 line
kernel/power/snapshot.c +1
-0+#define SHRINK_BITE 10000This is ~40MB. A full scan of (for example) 8G pages will be time consuming, not to mention we have to do it 2*(8G-500M)/40M = 384 times!
Can we make it a
LONG_MAX?No, I don't think so. The problem is the number of pages we'll need to copy is generally shrinking as we allocate memory, so we can't do that in one shot.
Quoted 6 lines
Quoted 2 lines
We can make it a greater number, but I don't really think it would be a good idea to make it greater than 100 MB.
Well, even 100MB is quite big: on 128MB machine, that will probably mean freeing all the memory (instead of "as much as needed"). And that memory needs to go to disk, so it will be slow.
But we're going to free it anyway?
Rafael
Re: [PATCH 3/4] PM/Hibernate: Use memory allocations to free memory (rev. 2)
In reply to Pavel MachekQuoted 51 lines · Pavel Machek
Quoted 50 lines · Rafael J. Wysocki
Quoted 39 lines · Wu Fengguang
Quoted 25 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
Modify the hibernation memory shrinking code so that it will make memory allocations to free memory instead of using an artificial memory shrinking mechanism for that. Remove the shrinking of memory from the suspend-to-RAM code, where it is not really necessary. Finally, remove the no longer used memory shrinking functions from
mm/vmscan.c.[rev. 2: Use the existing memory bitmaps for marking preallocated
image pages and useswsusp_free()from releasing them, introduceGFP_IMAGE, add comments describing the memory shrinking strategy.]Signed-off-by Rafael J. Wysocki <[email protected]>--- kernel/power/main.c | 20 ------ kernel/power/snapshot.c | 132 +++++++++++++++++++++++++++++++++----------- mm/vmscan.c | 142 ------------------------------------------------ 3 files changed, 101 insertions(+), 193 deletions(-)Index:
linux-2.6/kernel/power/snapshot.c
===================================================================kernel/power/snapshot.c void swsusp_free(void) · line 1075
Quoted 10 lines
kernel/power/snapshot.c +7
-0@@ -1066,41 +1066,97 @@ void swsusp_free(void) buffer =NULL ; } +/* Helper functions used for the shrinking of memory. */ + +#ifdef CONFIG_HIGHMEM +#define GFP_IMAGE (GFP_KERNEL | __GFP_HIGHMEM | __GFP_NO_OOM_KILL) +#else +#define GFP_IMAGE (GFP_KERNEL | __GFP_NO_OOM_KILL) +#endif The
CONFIG_HIGHMEMtest is not necessary:__GFP_HIGHMEMis always defined.Quoted 6 lines
kernel/power/snapshot.c void swsusp_free(void) · line 1077
Quoted 1 line
kernel/power/snapshot.c +1
-0+#define SHRINK_BITE 10000This is ~40MB. A full scan of (for example) 8G pages will be time consuming, not to mention we have to do it 2*(8G-500M)/40M = 384 times!
Can we make it a
LONG_MAX?No, I don't think so. The problem is the number of pages we'll need to copy is generally shrinking as we allocate memory, so we can't do that in one shot.
Quoted 6 lines
Quoted 2 lines
We can make it a greater number, but I don't really think it would be a good idea to make it greater than 100 MB.
Well, even 100MB is quite big: on 128MB machine, that will probably mean freeing all the memory (instead of "as much as needed"). And that memory needs to go to disk, so it will be slow.
But we're going to free it anyway?
Rafael
Re: [PATCH 3/4] PM/Hibernate: Use memory allocations to free memory (rev. 2)
In reply to Rafael J. WysockiQuoted 45 lines · Rafael J. Wysocki
Quoted 44 lines · Wu Fengguang
Quoted 25 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
Modify the hibernation memory shrinking code so that it will make memory allocations to free memory instead of using an artificial memory shrinking mechanism for that. Remove the shrinking of memory from the suspend-to-RAM code, where it is not really necessary. Finally, remove the no longer used memory shrinking functions from
mm/vmscan.c.[rev. 2: Use the existing memory bitmaps for marking preallocated
image pages and useswsusp_free()from releasing them, introduceGFP_IMAGE, add comments describing the memory shrinking strategy.]Signed-off-by Rafael J. Wysocki <[email protected]>--- kernel/power/main.c | 20 ------ kernel/power/snapshot.c | 132 +++++++++++++++++++++++++++++++++----------- mm/vmscan.c | 142 ------------------------------------------------ 3 files changed, 101 insertions(+), 193 deletions(-)Index:
linux-2.6/kernel/power/snapshot.c
===================================================================kernel/power/snapshot.c void swsusp_free(void) · line 1075
Quoted 10 lines
kernel/power/snapshot.c +7
-0@@ -1066,41 +1066,97 @@ void swsusp_free(void) buffer =NULL ; } +/* Helper functions used for the shrinking of memory. */ + +#ifdef CONFIG_HIGHMEM +#define GFP_IMAGE (GFP_KERNEL | __GFP_HIGHMEM | __GFP_NO_OOM_KILL) +#else +#define GFP_IMAGE (GFP_KERNEL | __GFP_NO_OOM_KILL) +#endif The
CONFIG_HIGHMEMtest is not necessary:__GFP_HIGHMEMis always defined.kernel/power/snapshot.c void swsusp_free(void) · line 1077
Quoted 1 line
kernel/power/snapshot.c +1
-0+#define SHRINK_BITE 10000This is ~40MB. A full scan of (for example) 8G pages will be time consuming, not to mention we have to do it 2*(8G-500M)/40M = 384 times!
Quoted 7 lines
Quoted 1 line
Can we make it a
LONG_MAX?No, I don't think so. The problem is the number of pages we'll need to copy is generally shrinking as we allocate memory, so we can't do that in one shot.
We can make it a greater number, but I don't really think it would be a good idea to make it greater than 100 MB.
Well, even 100MB is quite big: on 128MB machine, that will probably mean freeing all the memory (instead of "as much as needed"). And that memory needs to go to disk, so it will be slow.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: [PATCH 3/4] PM/Hibernate: Use memory allocations to free memory (rev. 2)
In reply to Wu FengguangQuoted 39 lines · Wu Fengguang
Quoted 25 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
Modify the hibernation memory shrinking code so that it will make memory allocations to free memory instead of using an artificial memory shrinking mechanism for that. Remove the shrinking of memory from the suspend-to-RAM code, where it is not really necessary. Finally, remove the no longer used memory shrinking functions from
mm/vmscan.c.[rev. 2: Use the existing memory bitmaps for marking preallocated
image pages and useswsusp_free()from releasing them, introduceGFP_IMAGE, add comments describing the memory shrinking strategy.]Signed-off-by Rafael J. Wysocki <[email protected]>--- kernel/power/main.c | 20 ------ kernel/power/snapshot.c | 132 +++++++++++++++++++++++++++++++++----------- mm/vmscan.c | 142 ------------------------------------------------ 3 files changed, 101 insertions(+), 193 deletions(-)Index:
linux-2.6/kernel/power/snapshot.c
===================================================================kernel/power/snapshot.c void swsusp_free(void) · line 1075
Quoted 10 lines
kernel/power/snapshot.c +7
-0@@ -1066,41 +1066,97 @@ void swsusp_free(void) buffer =NULL ; } +/* Helper functions used for the shrinking of memory. */ + +#ifdef CONFIG_HIGHMEM +#define GFP_IMAGE (GFP_KERNEL | __GFP_HIGHMEM | __GFP_NO_OOM_KILL) +#else +#define GFP_IMAGE (GFP_KERNEL | __GFP_NO_OOM_KILL) +#endif The
CONFIG_HIGHMEMtest is not necessary:__GFP_HIGHMEMis always defined.
Quoted 6 lines
kernel/power/snapshot.c void swsusp_free(void) · line 1077
Quoted 1 line
kernel/power/snapshot.c +1
-0+#define SHRINK_BITE 10000This is ~40MB. A full scan of (for example) 8G pages will be time consuming, not to mention we have to do it 2*(8G-500M)/40M = 384 times!
Can we make it a
LONG_MAX?
No, I don't think so. The problem is the number of pages we'll need to copy is generally shrinking as we allocate memory, so we can't do that in one shot.
We can make it a greater number, but I don't really think it would be a good idea to make it greater than 100 MB.
Thanks,
Rafael
Re: [PATCH 3/4] PM/Hibernate: Use memory allocations to free memory (rev. 2)
In reply to Rafael J. WysockiQuoted 25 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
Modify the hibernation memory shrinking code so that it will make memory allocations to free memory instead of using an artificial memory shrinking mechanism for that. Remove the shrinking of memory from the suspend-to-RAM code, where it is not really necessary. Finally, remove the no longer used memory shrinking functions from
mm/vmscan.c.[rev. 2: Use the existing memory bitmaps for marking preallocated
image pages and useswsusp_free()from releasing them, introduceGFP_IMAGE, add comments describing the memory shrinking strategy.]Signed-off-by Rafael J. Wysocki <[email protected]>--- kernel/power/main.c | 20 ------ kernel/power/snapshot.c | 132 +++++++++++++++++++++++++++++++++----------- mm/vmscan.c | 142 ------------------------------------------------ 3 files changed, 101 insertions(+), 193 deletions(-)Index:
linux-2.6/kernel/power/snapshot.c
===================================================================
kernel/power/snapshot.c void swsusp_free(void) · line 1075
Quoted 10 lines
kernel/power/snapshot.c +7
-0@@ -1066,41 +1066,97 @@ void swsusp_free(void) buffer =NULL ; } +/* Helper functions used for the shrinking of memory. */ + +#ifdef CONFIG_HIGHMEM +#define GFP_IMAGE (GFP_KERNEL | __GFP_HIGHMEM | __GFP_NO_OOM_KILL) +#else +#define GFP_IMAGE (GFP_KERNEL | __GFP_NO_OOM_KILL) +#endif
The CONFIG_HIGHMEM test is not necessary: __GFP_HIGHMEM is always defined.
kernel/power/snapshot.c void swsusp_free(void) · line 1077
Quoted 1 line
kernel/power/snapshot.c +1
-0+#define SHRINK_BITE 10000
This is ~40MB. A full scan of (for example) 8G pages will be time consuming, not to mention we have to do it 2*(8G-500M)/40M = 384 times!
Can we make it a LONG_MAX?
Thanks,
Fengguang
PATCH 3/4 PM/Hibernate: Use memory allocations to free memory (rev. 2)
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Modify the hibernation memory shrinking code so that it will make memory allocations to free memory instead of using an artificial memory shrinking mechanism for that. Remove the shrinking of memory from the suspend-to-RAM code, where it is not really necessary. Finally, remove the no longer used memory shrinking functions from mm/vmscan.c .
[rev. 2: Use the existing memory bitmaps for marking preallocated
image pages and use swsusp_free() from releasing them, introduce GFP_IMAGE, add comments describing the memory shrinking strategy.]
--- kernel/power/main.c | 20 ------ kernel/power/snapshot.c | 132 +++++++++++++++++++++++++++++++++----------- mm/vmscan.c | 142 ------------------------------------------------ 3 files changed, 101 insertions(+), 193 deletions(-)
kernel/power/snapshot.c +100 -32
@@ -1066,41 +1066,97 @@ void swsusp_free(void) buffer =NULL ; } +/* Helper functions used for the shrinking of memory. */ + +#ifdef CONFIG_HIGHMEM +#define GFP_IMAGE (GFP_KERNEL | __GFP_HIGHMEM | __GFP_NO_OOM_KILL) +#else +#define GFP_IMAGE (GFP_KERNEL | __GFP_NO_OOM_KILL) +#endif + +#define SHRINK_BITE 10000 +/** -* swsusp_shrink_memory - Try to free as much memory as needed +* prealloc_pages - preallocate given number of pages and mark their PFNs +* @nr_pages: Number of pages to allocate. * -* ... but do not OOM-kill anyone -* -* Notice: all userland should be stopped before it is called, or -* livelock is possible. +* Allocate given number of pages and mark their PFNs in the hibernation memory +* bitmaps, so that they can be released by swsusp_free(). +* Return value: The number of normal (ie. non-highmem) pages allocated or +* -ENOMEM on failure. */ - -#define SHRINK_BITE 10000 -static inline unsigned long __shrink_memory (long tmp) +static long prealloc_pages (long nr_pages) { -if (tmp >SHRINK_BITE ) - tmp =SHRINK_BITE ; -return shrink_all_memory (tmp); +long nr_normal =0 ; + +while (nr_pages-- >0 ) { +struct page *page; + + page =alloc_image_page (GFP_IMAGE ); +if (!page) +return -ENOMEM ; +if (!PageHighMem (page)) + nr_normal++; + } + +return nr_normal; } +/** +* swsusp_shrink_memory - Make the kernel release as much memory as needed +* +* To create a hibernation image it is necessary to make a copy of every page +* frame in use. We also need a number of page frames to be free during +* hibernation for allocations made while saving the image and for device +* drivers, in case they need to allocate memory from their hibernation +* callbacks (these two numbers are given by PAGES_FOR_IO and SPARE_PAGES, +* respectively, both of which are rough estimates). To make this happen, we +* preallocate memory in SHRINK_BITE chunks in a loop until the following +* condition is satisfied: +* +* [number of preallocated page frames] >= +* (1/2) * ([total number of page frames in use] + PAGES_FOR_IO +* + SPARE_PAGES - [number of free page frames]) +* +* because in that case, if all of the preallocated page frames are released, +* the total number of free page frames will be equal to or greater than the sum +* of the total number of page frames in use with PAGES_FOR_IO and SPARE_PAGES, +* which is what we need. +* +* If image_size is set below the number following from the above inequality, +* the preallocation of memory is continued until the total number of page +* frames in use is below the requested image size. +*/ int swsusp_shrink_memory (void ) { -long tmp; -struct zone *zone; -unsigned long pages =0 ; +unsigned long pages =0 , alloc_normal =0 , alloc_highmem =0 ;unsigned int i =0 ;char *p ="-\\|/" ;struct timeval start, stop; +int error =0 ;printk (KERN_INFO "PM: Shrinking memory... " );do_gettimeofday (&start); - do { - long size, highmem_size; - highmem_size = count_highmem_pages(); - size = count_data_pages() + PAGES_FOR_IO + SPARE_PAGES; - tmp = size; +for (;;) { +struct zone *zone; +long size, highmem_size, tmp, ret; + +/* +* Pages preallocated by this loop are not counted as data pages +* by count_data_pages() and count_highmem_pages(), so we only +* need to subtract their numbers once here to verify the +* satisfaction of the stop condition. +*/ + size =count_data_pages () - alloc_normal; + tmp = size +PAGES_FOR_IO +SPARE_PAGES ; + highmem_size =count_highmem_pages () - alloc_highmem; size += highmem_size; +/* +* Highmem is treated differently, because we prefer not to +* store copies of normal page frames in it during image +* creation. +*/ for_each_populated_zone (zone) { tmp +=snapshot_additional_pages (zone);if (is_highmem (zone)) {
@@ -1111,27 +1167,39 @@ int swsusp_shrink_memory(void) tmp += zone->lowmem_reserve[ZONE_NORMAL ]; } } -if (highmem_size <0 ) highmem_size =0 ; - tmp += highmem_size; -if (tmp >0 ) { - tmp =__shrink_memory (tmp); -if (!tmp) -return -ENOMEM ; - pages += tmp; - }else if (size > image_size /PAGE_SIZE ) { - tmp =__shrink_memory (size - (image_size /PAGE_SIZE )); - pages += tmp; + +if (tmp <=0 && size > image_size /PAGE_SIZE ) + tmp = size - (image_size /PAGE_SIZE ); + +if (tmp >SHRINK_BITE ) + tmp =SHRINK_BITE ; +else if (tmp <=0 ) +break ; + + ret =prealloc_pages (tmp); +if (ret <0 ) { + error = -ENOMEM ; + goto out; } + alloc_normal += ret; + alloc_highmem += tmp - ret; + pages += tmp; +printk ("\b%c" , p[i++%4 ]); - }while (tmp >0 ); + } +do_gettimeofday (&stop); -printk ("\bdone (%lu pages freed)\n" , pages); +printk ("\bdone (preallocated %lu free pages)\n" , pages);swsusp_show_speed (&start, &stop, pages,"Freed" ); -return 0 ; + out: +/* Release the preallocated page frames. */ +swsusp_free (); + +return error; }#ifdef CONFIG_HIGHMEM
mm/vmscan.c +0 -142
148 lines not on this page · raw message
kernel/power/main.c +1 -19
@@ -188,9 +188,6 @@ static void suspend_test_finish(const ch#endif -/* This is just an arbitrary number */ -#define FREE_PAGE_NUMBER (100) -static struct platform_suspend_ops *suspend_ops;/**
@@ -226,7 +223,6 @@ int suspend_valid_only_mem(suspend_statestatic int suspend_prepare (void ) {int error; -unsigned int free_pages;if (!suspend_ops || !suspend_ops->enter)return -EPERM ;
@@ -241,24 +237,10 @@ static int suspend_prepare(void)if (error) goto Finish; -if (suspend_freeze_processes ()) { - error = -EAGAIN ; - goto Thaw; - } - - free_pages =global_page_state (NR_FREE_PAGES ); -if (free_pages <FREE_PAGE_NUMBER ) { -pr_debug ("PM: free some memory\n" ); -shrink_all_memory (FREE_PAGE_NUMBER - free_pages); -if (nr_free_pages () <FREE_PAGE_NUMBER ) { - error = -ENOMEM ; -printk (KERN_ERR "PM: No enough memory\n" ); - } - } + error =suspend_freeze_processes ();if (!error)return 0 ; - Thaw:suspend_thaw_processes ();usermodehelper_enable (); Finish:
PATCH 4/4 PM/Hibernate: Do not release preallocated memory unnecessarily
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Since the hibernation code is now going to use allocations of memory to create enough room for the image, it can also use the page frames allocated at this stage as image page frames. The low-level hibernation code needs to be rearranged for this purpose, but it allows us to avoid freeing a great number of pages and allocating these same pages once again later, so it generally is worth doing.
--- kernel/power/disk.c | 15 +++- kernel/power/power.h | 2 kernel/power/snapshot.c | 151 +++++++++++++++++++++++------------------------- 3 files changed, 87 insertions(+), 81 deletions(-)
kernel/power/snapshot.c +75 -76
@@ -783,21 +783,6 @@ void free_basic_memory_bitmaps(void)pr_debug ("PM: Basic memory bitmaps freed\n" ); } -/** -* snapshot_additional_pages - estimate the number of additional pages -* be needed for setting up the suspend image data structures for given -* zone (usually the returned value is greater than the exact number) -*/ - -unsigned int snapshot_additional_pages (struct zone *zone) -{ -unsigned int res; - - res =DIV_ROUND_UP (zone->spanned_pages,BM_BITS_PER_BLOCK ); - res +=DIV_ROUND_UP (res *sizeof (struct bm_block ),PAGE_SIZE ); -return 2 * res; -} -#ifdef CONFIG_HIGHMEM /** * count_free_highmem_pages - compute the total number of free highmem
@@ -1033,6 +1018,25 @@ copy_data_pages(struct memory_bitmap *costatic unsigned int nr_copy_pages;/* Number of pages needed for saving the original pfns of the image pages */ static unsigned int nr_meta_pages; +/* +* Numbers of normal and highmem page frames allocated for hibernation image +* before suspending devices. +*/ +unsigned int alloc_normal, alloc_highmem; +/* +* Memory bitmap used for marking saveable pages (during hibernation) or +* hibernation image pages (during restore) +*/ +static struct memory_bitmap orig_bm; +/* +* Memory bitmap used during hibernation for marking allocated page frames that +* will contain copies of saveable pages. During restore it is initially used +* for marking hibernation image pages, but then the set bits from it are +* duplicated in @orig_bm and it is released. On highmem systems it is next +* used for marking "safe" highmem pages, but it has to be reinitialized for +* this purpose. +*/ +static struct memory_bitmap copy_bm;/** * swsusp_free - free pages allocated for the suspend.
@@ -1064,6 +1068,8 @@ void swsusp_free(void) nr_meta_pages =0 ; restore_pblist =NULL ; buffer =NULL ; + alloc_normal =0 ; + alloc_highmem =0 ; }/* Helper functions used for the shrinking of memory. */
@@ -1085,7 +1091,7 @@ void swsusp_free(void)* Return value: The number of normal (ie. non-highmem) pages allocated or * -ENOMEM on failure. */ -static long prealloc_pages (long nr_pages) +static long prealloc_pages (struct memory_bitmap *bm,long nr_pages) {long nr_normal =0 ;
@@ -1095,6 +1101,7 @@ static long prealloc_pages(long nr_pages page =alloc_image_page (GFP_IMAGE );if (!page)return -ENOMEM ; +memory_bm_set_bit (bm,page_to_pfn (page));if (!PageHighMem (page)) nr_normal++; }
@@ -1103,7 +1110,7 @@ static long prealloc_pages(long nr_pages }/** -* swsusp_shrink_memory - Make the kernel release as much memory as needed +* hibernate_preallocate_memory - Preallocate memory for hibernation image * * To create a hibernation image it is necessary to make a copy of every page * frame in use. We also need a number of page frames to be free during
@@ -1127,17 +1134,29 @@ static long prealloc_pages(long nr_pages* the preallocation of memory is continued until the total number of page * frames in use is below the requested image size. */ -int swsusp_shrink_memory (void ) +int hibernate_preallocate_memory (void ) { -unsigned long pages =0 , alloc_normal =0 , alloc_highmem =0 ; +unsigned long pages =0 ;unsigned int i =0 ;char *p ="-\\|/" ;struct timeval start, stop; -int error =0 ; +int error; -printk (KERN_INFO "PM: Shrinking memory... " ); +printk (KERN_INFO "PM: Preallocating image memory ... " );do_gettimeofday (&start); + error =memory_bm_create (&orig_bm,GFP_IMAGE ,PG_ANY ); +if (error) + goto err_out; + + error =memory_bm_create (©_bm,GFP_IMAGE ,PG_ANY ); +if (error) + goto err_out; + + alloc_normal =0 ; + alloc_highmem =0 ; + error = -ENOMEM ; +for (;;) {struct zone *zone;long size, highmem_size, tmp, ret;
@@ -1158,7 +1177,6 @@ int swsusp_shrink_memory(void)* creation. */ for_each_populated_zone (zone) { - tmp +=snapshot_additional_pages (zone);if (is_highmem (zone)) { highmem_size -=zone_page_state (zone,NR_FREE_PAGES );
@@ -1179,11 +1197,9 @@ int swsusp_shrink_memory(void)else if (tmp <=0 )break ; - ret =prealloc_pages (tmp); -if (ret <0 ) { - error = -ENOMEM ; - goto out; - } + ret =prealloc_pages (©_bm, tmp); +if (ret <0 ) + goto err_out; alloc_normal += ret; alloc_highmem += tmp - ret; pages += tmp;
@@ -1192,13 +1208,13 @@ int swsusp_shrink_memory(void) }do_gettimeofday (&stop); -printk ("\bdone (preallocated %lu free pages)\n" , pages); -swsusp_show_speed (&start, &stop, pages,"Freed" ); +printk ("\bdone (allocated %lu image pages)\n" , pages); +swsusp_show_speed (&start, &stop, pages,"Allocated" ); - out: -/* Release the preallocated page frames. */ -swsusp_free (); +return 0 ; + err_out: +swsusp_free ();return error; }
@@ -1210,7 +1226,7 @@ int swsusp_shrink_memory(void)static unsigned int count_pages_for_highmem (unsigned int nr_highmem) { -unsigned int free_highmem =count_free_highmem_pages (); +unsigned int free_highmem =count_free_highmem_pages () + alloc_highmem;if (free_highmem >= nr_highmem) nr_highmem =0 ;
@@ -1232,19 +1248,17 @@ count_pages_for_highmem(unsigned int nr_static int enough_free_mem (unsigned int nr_pages,unsigned int nr_highmem) {struct zone *zone; -unsigned int free =0 , meta =0 ; +unsigned int free = alloc_normal; -for_each_zone (zone) { - meta +=snapshot_additional_pages (zone); +for_each_zone (zone)if (!is_highmem (zone)) free +=zone_page_state (zone,NR_FREE_PAGES ); - } nr_pages +=count_pages_for_highmem (nr_highmem); -pr_debug ("PM: Normal pages needed: %u + %u + %u, available pages: %u\n" , - nr_pages,PAGES_FOR_IO , meta, free); +pr_debug ("PM: Normal pages needed: %u + %u, available pages: %u\n" , + nr_pages,PAGES_FOR_IO , free); -return free > nr_pages +PAGES_FOR_IO + meta; +return free > nr_pages +PAGES_FOR_IO ; }#ifdef CONFIG_HIGHMEM
@@ -1266,7 +1280,7 @@ static inline int get_highmem_buffer(int*/ static inline unsigned int -alloc_highmem_image_pages (struct memory_bitmap *bm,unsigned int nr_highmem) +alloc_highmem_pages (struct memory_bitmap *bm,unsigned int nr_highmem) {unsigned int to_alloc =count_free_highmem_pages ();
@@ -1277,7 +1291,7 @@ alloc_highmem_image_pages(struct memory_while (to_alloc-- >0 ) {struct page *page; - page =alloc_image_page (__GFP_HIGHMEM); + page =alloc_image_page (__GFP_HIGHMEM | __GFP_NO_OOM_KILL);memory_bm_set_bit (bm,page_to_pfn (page)); }return nr_highmem;
@@ -1286,7 +1300,7 @@ alloc_highmem_image_pages(struct memory_static inline int get_highmem_buffer (int safe_needed) {return 0 ; }static inline unsigned int -alloc_highmem_image_pages (struct memory_bitmap *bm,unsigned int n) {return 0 ; } +alloc_highmem_pages (struct memory_bitmap *bm,unsigned int n) {return 0 ; }#endif /* CONFIG_HIGHMEM */ /**
@@ -1305,51 +1319,36 @@ static int swsusp_alloc(struct memory_bitmap *orig_bm, struct memory_bitmap *copy_bm, unsigned int nr_pages, unsigned int nr_highmem) { - int error; - - error =memory_bm_create (orig_bm,GFP_ATOMIC | __GFP_COLD,PG_ANY ); -if (error) - goto Free; - - error =memory_bm_create (copy_bm,GFP_ATOMIC | __GFP_COLD,PG_ANY ); -if (error) - goto Free; + int error = 0;if (nr_highmem >0 ) { error =get_highmem_buffer (PG_ANY );if (error) - goto Free; - - nr_pages +=alloc_highmem_image_pages (copy_bm, nr_highmem); + goto err_out; +if (nr_highmem > alloc_highmem) { + nr_highmem -= alloc_highmem; + nr_pages +=alloc_highmem_pages (copy_bm, nr_highmem); + } } -while (nr_pages-- >0 ) { -struct page *page =alloc_image_page (GFP_ATOMIC | __GFP_COLD); - -if (!page) - goto Free; +if (nr_pages > alloc_normal) { + nr_pages -= alloc_normal; +while (nr_pages-- >0 ) { +struct page *page; -memory_bm_set_bit (copy_bm,page_to_pfn (page)); + page =alloc_image_page (GFP_ATOMIC | __GFP_COLD); +if (!page) + goto err_out; +memory_bm_set_bit (copy_bm,page_to_pfn (page)); + } } +return 0 ; - Free: + err_out:swsusp_free (); -return -ENOMEM ; +return error; } -/* Memory bitmap used for marking saveable pages (during suspend) or the -* suspend image pages (during resume) -*/ -static struct memory_bitmap orig_bm; -/* Memory bitmap used on suspend for marking allocated pages that will contain -* the copies of saveable pages. During resume it is initially used for -* marking the suspend image pages, but then its set bits are duplicated in -* @orig_bm and it is released. Next, on systems with high memory, it may be -* used for marking "safe" highmem pages, but it has to be reinitialized for -* this purpose. -*/ -static struct memory_bitmap copy_bm; - asmlinkage int swsusp_save(void) {unsigned int nr_pages, nr_highmem;
kernel/power/power.h +1 -1
@@ -74,7 +74,7 @@ extern asmlinkage int swsusp_arch_resumeextern int create_basic_memory_bitmaps (void );extern void free_basic_memory_bitmaps (void ); -extern int swsusp_shrink_memory (void ); +extern int hibernate_preallocate_memory (void );/** * Auxiliary structure used for reading the snapshot image data and
kernel/power/disk.c +11 -4
@@ -303,8 +303,8 @@ int hibernation_snapshot(int platform_moif (error)return error; -/* Free memory before shutting down devices. */ - error =swsusp_shrink_memory (); +/* Preallocate image memory before shutting down devices. */ + error =hibernate_preallocate_memory ();if (error) goto Close;
@@ -320,6 +320,10 @@ int hibernation_snapshot(int platform_mo/* Control returns here after successful restore */ Resume_devices: +/* We may need to release the preallocated image pages here. */ +if (error || !in_suspend) +swsusp_free (); +device_resume (in_suspend ? (error ?PMSG_RECOVER :PMSG_THAW ) :PMSG_RESTORE );resume_console ();
@@ -593,7 +597,10 @@ int hibernate(void) goto Thaw; error =hibernation_snapshot (hibernation_mode ==HIBERNATION_PLATFORM ); -if (in_suspend && !error) { +if (error) + goto Thaw; + +if (in_suspend) {unsigned int flags =0 ;if (hibernation_mode ==HIBERNATION_PLATFORM )
@@ -605,8 +612,8 @@ int hibernate(void)power_down (); }else {pr_debug ("PM: Image restored successfully.\n" ); -swsusp_free (); } + Thaw:thaw_processes (); Finish:
PATCH 4/4 PM/Hibernate: Do not release preallocated memory unnecessarily
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Since the hibernation code is now going to use allocations of memory to create enough room for the image, it can also use the page frames allocated at this stage as image page frames. The low-level hibernation code needs to be rearranged for this purpose, but it allows us to avoid freeing a great number of pages and allocating these same pages once again later, so it generally is worth doing.
--- kernel/power/disk.c | 15 +++- kernel/power/power.h | 2 kernel/power/snapshot.c | 151 +++++++++++++++++++++++------------------------- 3 files changed, 87 insertions(+), 81 deletions(-)
kernel/power/snapshot.c +75 -76
@@ -783,21 +783,6 @@ void free_basic_memory_bitmaps(void)pr_debug ("PM: Basic memory bitmaps freed\n" ); } -/** -* snapshot_additional_pages - estimate the number of additional pages -* be needed for setting up the suspend image data structures for given -* zone (usually the returned value is greater than the exact number) -*/ - -unsigned int snapshot_additional_pages (struct zone *zone) -{ -unsigned int res; - - res =DIV_ROUND_UP (zone->spanned_pages,BM_BITS_PER_BLOCK ); - res +=DIV_ROUND_UP (res *sizeof (struct bm_block ),PAGE_SIZE ); -return 2 * res; -} -#ifdef CONFIG_HIGHMEM /** * count_free_highmem_pages - compute the total number of free highmem
@@ -1033,6 +1018,25 @@ copy_data_pages(struct memory_bitmap *costatic unsigned int nr_copy_pages;/* Number of pages needed for saving the original pfns of the image pages */ static unsigned int nr_meta_pages; +/* +* Numbers of normal and highmem page frames allocated for hibernation image +* before suspending devices. +*/ +unsigned int alloc_normal, alloc_highmem; +/* +* Memory bitmap used for marking saveable pages (during hibernation) or +* hibernation image pages (during restore) +*/ +static struct memory_bitmap orig_bm; +/* +* Memory bitmap used during hibernation for marking allocated page frames that +* will contain copies of saveable pages. During restore it is initially used +* for marking hibernation image pages, but then the set bits from it are +* duplicated in @orig_bm and it is released. On highmem systems it is next +* used for marking "safe" highmem pages, but it has to be reinitialized for +* this purpose. +*/ +static struct memory_bitmap copy_bm;/** * swsusp_free - free pages allocated for the suspend.
@@ -1064,6 +1068,8 @@ void swsusp_free(void) nr_meta_pages =0 ; restore_pblist =NULL ; buffer =NULL ; + alloc_normal =0 ; + alloc_highmem =0 ; }/* Helper functions used for the shrinking of memory. */
@@ -1085,7 +1091,7 @@ void swsusp_free(void)* Return value: The number of normal (ie. non-highmem) pages allocated or * -ENOMEM on failure. */ -static long prealloc_pages (long nr_pages) +static long prealloc_pages (struct memory_bitmap *bm,long nr_pages) {long nr_normal =0 ;
@@ -1095,6 +1101,7 @@ static long prealloc_pages(long nr_pages page =alloc_image_page (GFP_IMAGE );if (!page)return -ENOMEM ; +memory_bm_set_bit (bm,page_to_pfn (page));if (!PageHighMem (page)) nr_normal++; }
@@ -1103,7 +1110,7 @@ static long prealloc_pages(long nr_pages }/** -* swsusp_shrink_memory - Make the kernel release as much memory as needed +* hibernate_preallocate_memory - Preallocate memory for hibernation image * * To create a hibernation image it is necessary to make a copy of every page * frame in use. We also need a number of page frames to be free during
@@ -1127,17 +1134,29 @@ static long prealloc_pages(long nr_pages* the preallocation of memory is continued until the total number of page * frames in use is below the requested image size. */ -int swsusp_shrink_memory (void ) +int hibernate_preallocate_memory (void ) { -unsigned long pages =0 , alloc_normal =0 , alloc_highmem =0 ; +unsigned long pages =0 ;unsigned int i =0 ;char *p ="-\\|/" ;struct timeval start, stop; -int error =0 ; +int error; -printk (KERN_INFO "PM: Shrinking memory... " ); +printk (KERN_INFO "PM: Preallocating image memory ... " );do_gettimeofday (&start); + error =memory_bm_create (&orig_bm,GFP_IMAGE ,PG_ANY ); +if (error) + goto err_out; + + error =memory_bm_create (©_bm,GFP_IMAGE ,PG_ANY ); +if (error) + goto err_out; + + alloc_normal =0 ; + alloc_highmem =0 ; + error = -ENOMEM ; +for (;;) {struct zone *zone;long size, highmem_size, tmp, ret;
@@ -1158,7 +1177,6 @@ int swsusp_shrink_memory(void)* creation. */ for_each_populated_zone (zone) { - tmp +=snapshot_additional_pages (zone);if (is_highmem (zone)) { highmem_size -=zone_page_state (zone,NR_FREE_PAGES );
@@ -1179,11 +1197,9 @@ int swsusp_shrink_memory(void)else if (tmp <=0 )break ; - ret =prealloc_pages (tmp); -if (ret <0 ) { - error = -ENOMEM ; - goto out; - } + ret =prealloc_pages (©_bm, tmp); +if (ret <0 ) + goto err_out; alloc_normal += ret; alloc_highmem += tmp - ret; pages += tmp;
@@ -1192,13 +1208,13 @@ int swsusp_shrink_memory(void) }do_gettimeofday (&stop); -printk ("\bdone (preallocated %lu free pages)\n" , pages); -swsusp_show_speed (&start, &stop, pages,"Freed" ); +printk ("\bdone (allocated %lu image pages)\n" , pages); +swsusp_show_speed (&start, &stop, pages,"Allocated" ); - out: -/* Release the preallocated page frames. */ -swsusp_free (); +return 0 ; + err_out: +swsusp_free ();return error; }
@@ -1210,7 +1226,7 @@ int swsusp_shrink_memory(void)static unsigned int count_pages_for_highmem (unsigned int nr_highmem) { -unsigned int free_highmem =count_free_highmem_pages (); +unsigned int free_highmem =count_free_highmem_pages () + alloc_highmem;if (free_highmem >= nr_highmem) nr_highmem =0 ;
@@ -1232,19 +1248,17 @@ count_pages_for_highmem(unsigned int nr_static int enough_free_mem (unsigned int nr_pages,unsigned int nr_highmem) {struct zone *zone; -unsigned int free =0 , meta =0 ; +unsigned int free = alloc_normal; -for_each_zone (zone) { - meta +=snapshot_additional_pages (zone); +for_each_zone (zone)if (!is_highmem (zone)) free +=zone_page_state (zone,NR_FREE_PAGES ); - } nr_pages +=count_pages_for_highmem (nr_highmem); -pr_debug ("PM: Normal pages needed: %u + %u + %u, available pages: %u\n" , - nr_pages,PAGES_FOR_IO , meta, free); +pr_debug ("PM: Normal pages needed: %u + %u, available pages: %u\n" , + nr_pages,PAGES_FOR_IO , free); -return free > nr_pages +PAGES_FOR_IO + meta; +return free > nr_pages +PAGES_FOR_IO ; }#ifdef CONFIG_HIGHMEM
@@ -1266,7 +1280,7 @@ static inline int get_highmem_buffer(int*/ static inline unsigned int -alloc_highmem_image_pages (struct memory_bitmap *bm,unsigned int nr_highmem) +alloc_highmem_pages (struct memory_bitmap *bm,unsigned int nr_highmem) {unsigned int to_alloc =count_free_highmem_pages ();
@@ -1277,7 +1291,7 @@ alloc_highmem_image_pages(struct memory_while (to_alloc-- >0 ) {struct page *page; - page =alloc_image_page (__GFP_HIGHMEM); + page =alloc_image_page (__GFP_HIGHMEM | __GFP_NO_OOM_KILL);memory_bm_set_bit (bm,page_to_pfn (page)); }return nr_highmem;
@@ -1286,7 +1300,7 @@ alloc_highmem_image_pages(struct memory_static inline int get_highmem_buffer (int safe_needed) {return 0 ; }static inline unsigned int -alloc_highmem_image_pages (struct memory_bitmap *bm,unsigned int n) {return 0 ; } +alloc_highmem_pages (struct memory_bitmap *bm,unsigned int n) {return 0 ; }#endif /* CONFIG_HIGHMEM */ /**
@@ -1305,51 +1319,36 @@ static int swsusp_alloc(struct memory_bitmap *orig_bm, struct memory_bitmap *copy_bm, unsigned int nr_pages, unsigned int nr_highmem) { - int error; - - error =memory_bm_create (orig_bm,GFP_ATOMIC | __GFP_COLD,PG_ANY ); -if (error) - goto Free; - - error =memory_bm_create (copy_bm,GFP_ATOMIC | __GFP_COLD,PG_ANY ); -if (error) - goto Free; + int error = 0;if (nr_highmem >0 ) { error =get_highmem_buffer (PG_ANY );if (error) - goto Free; - - nr_pages +=alloc_highmem_image_pages (copy_bm, nr_highmem); + goto err_out; +if (nr_highmem > alloc_highmem) { + nr_highmem -= alloc_highmem; + nr_pages +=alloc_highmem_pages (copy_bm, nr_highmem); + } } -while (nr_pages-- >0 ) { -struct page *page =alloc_image_page (GFP_ATOMIC | __GFP_COLD); - -if (!page) - goto Free; +if (nr_pages > alloc_normal) { + nr_pages -= alloc_normal; +while (nr_pages-- >0 ) { +struct page *page; -memory_bm_set_bit (copy_bm,page_to_pfn (page)); + page =alloc_image_page (GFP_ATOMIC | __GFP_COLD); +if (!page) + goto err_out; +memory_bm_set_bit (copy_bm,page_to_pfn (page)); + } } +return 0 ; - Free: + err_out:swsusp_free (); -return -ENOMEM ; +return error; } -/* Memory bitmap used for marking saveable pages (during suspend) or the -* suspend image pages (during resume) -*/ -static struct memory_bitmap orig_bm; -/* Memory bitmap used on suspend for marking allocated pages that will contain -* the copies of saveable pages. During resume it is initially used for -* marking the suspend image pages, but then its set bits are duplicated in -* @orig_bm and it is released. Next, on systems with high memory, it may be -* used for marking "safe" highmem pages, but it has to be reinitialized for -* this purpose. -*/ -static struct memory_bitmap copy_bm; - asmlinkage int swsusp_save(void) {unsigned int nr_pages, nr_highmem;
kernel/power/power.h +1 -1
@@ -74,7 +74,7 @@ extern asmlinkage int swsusp_arch_resumeextern int create_basic_memory_bitmaps (void );extern void free_basic_memory_bitmaps (void ); -extern int swsusp_shrink_memory (void ); +extern int hibernate_preallocate_memory (void );/** * Auxiliary structure used for reading the snapshot image data and
kernel/power/disk.c +11 -4
@@ -303,8 +303,8 @@ int hibernation_snapshot(int platform_moif (error)return error; -/* Free memory before shutting down devices. */ - error =swsusp_shrink_memory (); +/* Preallocate image memory before shutting down devices. */ + error =hibernate_preallocate_memory ();if (error) goto Close;
@@ -320,6 +320,10 @@ int hibernation_snapshot(int platform_mo/* Control returns here after successful restore */ Resume_devices: +/* We may need to release the preallocated image pages here. */ +if (error || !in_suspend) +swsusp_free (); +device_resume (in_suspend ? (error ?PMSG_RECOVER :PMSG_THAW ) :PMSG_RESTORE );resume_console ();
@@ -593,7 +597,10 @@ int hibernate(void) goto Thaw; error =hibernation_snapshot (hibernation_mode ==HIBERNATION_PLATFORM ); -if (in_suspend && !error) { +if (error) + goto Thaw; + +if (in_suspend) {unsigned int flags =0 ;if (hibernation_mode ==HIBERNATION_PLATFORM )
@@ -605,8 +612,8 @@ int hibernate(void)power_down (); }else {pr_debug ("PM: Image restored successfully.\n" ); -swsusp_free (); } + Thaw:thaw_processes (); Finish:
Re: [PATCH 0/4] PM: Drop shrink_all_memory (rev. 2) (was: Re: [PATCH 3/3] PM/Hibernate: Use memory allocations to free memory)
In reply to Rafael J. WysockiHi Rafael,
I happened to be doing some benchmarks on the older shrink_all_memory(), Hopefully it can be a useful reference point for the new design.
The current swsusp_shrink_memory()/shrink_all_memory() are terribly
inefficient: it takes 7-9s to free up 1.4G memory:
[ 131.899389] PM: Freed 1413380 kbytes in 7.03 seconds (201.04 MB/s) [ 732.757916] PM: Freed 1490116 kbytes in 9.37 seconds (159.03 MB/s)
Below are the logs I collected by injecting printks. There are basically two major problems:
- swsusp_shrink_memory() scans the whole 2G memory again and again;
- shrink_all_memory() is slow. It won't reclaim pages at all with small priority values, because it's batching size is 10000 pages.
I wonder if it's possible to free up the memory within 1s at all. (Maybe the slowness is due to too much enabled debugging options...)
Thanks,
Fengguang
---
vanilla 2.6.30-rc2-next-20090417:
[ 124.516187] PM: Marking nosave pages: 0000000000001000 - 0000000000006000 [ 124.523087] PM: Marking nosave pages: 000000000009f000 - 0000000000100000 [ 124.530060] PM: Basic memory bitmaps created [ 124.534421] PM: Syncing filesystems ... done. [ 124.842282] Freezing user space processes ... (elapsed 0.00 seconds) done. [ 124.849800] Freezing remaining freezable tasks ... (elapsed 0.00 seconds) done. [ 124.857571] PM: Shrinking memory... tmp=471584, size=491906, highmem_size=0 [ 124.939103] shrink_all_memory: pages=10000 [ 125.019543] shrink_all_zones: pass=0, prio=5, lru=DMA32.2, pages=10000, reclaimed=10000 [ 125.027636]-tmp=451770, size=481986, highmem_size=0 [ 125.107571] shrink_all_memory: pages=10000 [ 125.139928] shrink_all_zones: pass=0, prio=7, lru=Normal.2, pages=10000, reclaimed=8500 [ 125.280940] shrink_all_zones: pass=0, prio=6, lru=DMA32.2, pages=1500, reclaimed=1500 [ 125.547990] shrink_all_zones: pass=0, prio=4, lru=DMA32.2, pages=10000, reclaimed=10000 [ 125.556135]\tmp=411598, size=461898, highmem_size=0 [ 125.637414] shrink_all_memory: pages=10000 [ 125.716890] shrink_all_zones: pass=0, prio=7, lru=Normal.2, pages=10000, reclaimed=10000 [ 125.725092]|tmp=391507, size=451854, highmem_size=0 [ 125.806935] shrink_all_memory: pages=10000 [ 125.886317] shrink_all_zones: pass=0, prio=5, lru=DMA32.2, pages=10000, reclaimed=10000 [ 125.894531]/tmp=371481, size=441841, highmem_size=0 [ 125.976823] shrink_all_memory: pages=10000 [ 126.104367] shrink_all_zones: pass=0, prio=6, lru=Normal.2, pages=10000, reclaimed=10000 [ 126.112572]-tmp=351715, size=431952, highmem_size=0 [ 126.195178] shrink_all_memory: pages=10000 [ 126.274586] shrink_all_zones: pass=0, prio=6, lru=DMA32.2, pages=10000, reclaimed=10000 [ 126.282698]\tmp=331949, size=422063, highmem_size=0 [ 126.365743] shrink_all_memory: pages=10000 [ 126.445851] shrink_all_zones: pass=0, prio=5, lru=DMA32.2, pages=10000, reclaimed=10000 [ 126.453968]|tmp=311858, size=412019, highmem_size=0 [ 126.537417] shrink_all_memory: pages=10000 [ 126.616980] shrink_all_zones: pass=0, prio=9, lru=Normal.2, pages=10000, reclaimed=10000 [ 126.625180]/tmp=291751, size=401975, highmem_size=0 [ 126.709066] shrink_all_memory: pages=10000 [ 126.788665] shrink_all_zones: pass=0, prio=5, lru=DMA32.2, pages=10000, reclaimed=10000 [ 126.796833]-tmp=271725, size=391962, highmem_size=0 [ 126.880997] shrink_all_memory: pages=10000 [ 127.008443] shrink_all_zones: pass=0, prio=6, lru=Normal.2, pages=10000, reclaimed=10000 [ 127.016667]\tmp=251716, size=381949, highmem_size=0 [ 127.101581] shrink_all_memory: pages=10000 [ 127.181588] shrink_all_zones: pass=0, prio=5, lru=DMA32.2, pages=10000, reclaimed=10000 [ 127.189728]|tmp=231673, size=371936, highmem_size=0 [ 127.275105] shrink_all_memory: pages=10000 [ 127.354799] shrink_all_zones: pass=0, prio=6, lru=Normal.2, pages=10000, reclaimed=10000 [ 127.363003]/tmp=211599, size=361892, highmem_size=0 [ 127.448750] shrink_all_memory: pages=10000 [ 127.528252] shrink_all_zones: pass=0, prio=5, lru=DMA32.2, pages=10000, reclaimed=10000 [ 127.536385]-tmp=191621, size=351910, highmem_size=0 [ 127.622369] shrink_all_memory: pages=10000 [ 127.750093] shrink_all_zones: pass=0, prio=6, lru=Normal.2, pages=10000, reclaimed=10000 [ 127.758295]\tmp=171539, size=341866, highmem_size=0 [ 127.844867] shrink_all_memory: pages=10000 [ 127.925614] shrink_all_zones: pass=0, prio=5, lru=DMA32.2, pages=10000, reclaimed=10000 [ 127.933758]|tmp=151465, size=331822, highmem_size=0 [ 128.020878] shrink_all_memory: pages=10000 [ 128.100580] shrink_all_zones: pass=0, prio=6, lru=Normal.2, pages=10000, reclaimed=10000 [ 128.108803]/tmp=131391, size=321778, highmem_size=0 [ 128.196312] shrink_all_memory: pages=10000 [ 128.275643] shrink_all_zones: pass=0, prio=5, lru=DMA32.2, pages=10000, reclaimed=10000 [ 128.283769]-tmp=111413, size=311796, highmem_size=0 [ 128.371814] shrink_all_memory: pages=10000 [ 128.501803] shrink_all_zones: pass=0, prio=5, lru=Normal.2, pages=10000, reclaimed=10000 [ 128.510007]\tmp=91339, size=301752, highmem_size=0 [ 128.597726] shrink_all_memory: pages=10000 [ 128.677138] shrink_all_zones: pass=0, prio=5, lru=DMA32.2, pages=10000, reclaimed=10000 [ 128.685277]|tmp=71296, size=291739, highmem_size=0 [ 128.774061] shrink_all_memory: pages=10000 [ 128.855940] shrink_all_zones: pass=0, prio=5, lru=Normal.2, pages=10000, reclaimed=10000 [ 128.864145]/tmp=51259, size=281726, highmem_size=0 [ 128.953486] shrink_all_memory: pages=10000 [ 129.033417] shrink_all_zones: pass=0, prio=5, lru=DMA32.2, pages=10000, reclaimed=10000 [ 129.041553]-tmp=31172, size=271682, highmem_size=0 [ 129.131233] shrink_all_memory: pages=10000 [ 129.210693] shrink_all_zones: pass=0, prio=5, lru=Normal.2, pages=10000, reclaimed=10000 [ 129.218994]\tmp=11146, size=261669, highmem_size=0 [ 129.309142] shrink_all_memory: pages=10000 [ 129.388523] shrink_all_zones: pass=0, prio=5, lru=DMA32.2, pages=10000, reclaimed=10000 [ 129.396648]|tmp=-8880, size=251656, highmem_size=0 [ 129.487193] shrink_all_memory: pages=10000 [ 129.614831] shrink_all_zones: pass=0, prio=5, lru=Normal.2, pages=10000, reclaimed=10000 [ 129.623059]/tmp=-28954, size=241612, highmem_size=0 [ 129.714055] shrink_all_memory: pages=10000 [ 129.794104] shrink_all_zones: pass=0, prio=4, lru=DMA32.2, pages=10000, reclaimed=10000 [ 129.802246]-tmp=-48932, size=231630, highmem_size=0 [ 129.893893] shrink_all_memory: pages=10000 [ 129.973667] shrink_all_zones: pass=0, prio=6, lru=Normal.2, pages=10000, reclaimed=10000 [ 129.981892]\tmp=-69020, size=221586, highmem_size=0 [ 130.073916] shrink_all_memory: pages=10000 [ 130.154620] shrink_all_zones: pass=0, prio=4, lru=Normal.2, pages=10000, reclaimed=10000 [ 130.162853]|tmp=-89156, size=211511, highmem_size=0 [ 130.255274] shrink_all_memory: pages=10000 [ 130.334612] shrink_all_zones: pass=0, prio=8, lru=DMA32.2, pages=10000, reclaimed=10000 [ 130.342750]/tmp=-109182, size=201498, highmem_size=0 [ 130.435551] shrink_all_memory: pages=10000 [ 130.515074] shrink_all_zones: pass=0, prio=4, lru=Normal.2, pages=10000, reclaimed=10000 [ 130.523305]-tmp=-129273, size=191454, highmem_size=0 [ 130.616714] shrink_all_memory: pages=10000 [ 130.696350] shrink_all_zones: pass=0, prio=4, lru=DMA32.2, pages=10000, reclaimed=10000 [ 130.704490]\tmp=-149299, size=181441, highmem_size=0 [ 130.798322] shrink_all_memory: pages=10000 [ 130.877834] shrink_all_zones: pass=0, prio=5, lru=Normal.2, pages=10000, reclaimed=10000 [ 130.886038]|tmp=-169325, size=171428, highmem_size=0 [ 130.980312] shrink_all_memory: pages=10000 [ 131.107844] shrink_all_zones: pass=0, prio=3, lru=DMA32.2, pages=10000, reclaimed=10000 [ 131.115982]/tmp=-189351, size=161415, highmem_size=0 [ 131.210530] shrink_all_memory: pages=10000 [ 131.291223] shrink_all_zones: pass=0, prio=7, lru=Normal.2, pages=10000, reclaimed=10000 [ 131.299433]-tmp=-209459, size=151371, highmem_size=0 [ 131.394488] shrink_all_memory: pages=10000 [ 131.474123] shrink_all_zones: pass=0, prio=3, lru=Normal.2, pages=10000, reclaimed=10000 [ 131.482344]\tmp=-229420, size=141389, highmem_size=0 [ 131.577910] shrink_all_memory: pages=10000 [ 131.657376] shrink_all_zones: pass=0, prio=5, lru=DMA32.2, pages=10000, reclaimed=10000 [ 131.665498]|tmp=-249511, size=131345, highmem_size=0 [ 131.761676] shrink_all_memory: pages=3345 [ 131.791048] shrink_all_zones: pass=0, prio=5, lru=Normal.2, pages=3345, reclaimed=3345 [ 131.799085]/tmp=-256256, size=127966, highmem_size=0 [ 131.895290]done (353345 pages freed) [ 131.899389] PM: Freed 1413380 kbytes in 7.03 seconds (201.04 MB/s)
1/30 memory being mapped, vanilla 2.6.30-rc2-next-20090417:
AnonPages: 38684 kB Mapped: 66940 kB
[ 722.944082] PM: Marking nosave pages: 0000000000001000 - 0000000000006000 [ 722.956215] PM: Marking nosave pages: 000000000009f000 - 0000000000100000 [ 722.963053] PM: Basic memory bitmaps created [ 722.967365] PM: Syncing filesystems ... done. [ 723.361274] Freezing user space processes ... (elapsed 0.00 seconds) done. [ 723.369310] Freezing remaining freezable tasks ... (elapsed 0.00 seconds) done. [ 723.377342] PM: Shrinking memory... tmp=508165, size=510179, highmem_size=0 [ 723.563602] shrink_all_memory: pages=10000 [ 723.648921] shrink_all_zones: pass=0, prio=5, lru=DMA32.2, pages=10000, reclaimed=9766 [ 723.733064] shrink_all_zones: pass=0, prio=5, lru=Normal.2, pages=10000, reclaimed=19581 [ 723.741225]-tmp=468972, size=490587, highmem_size=0 [ 723.821406] shrink_all_memory: pages=10000 [ 723.902912] shrink_all_zones: pass=0, prio=5, lru=DMA32.2, pages=10000, reclaimed=9804 [ 723.987433] shrink_all_zones: pass=0, prio=5, lru=Normal.2, pages=10000, reclaimed=19617 [ 723.995565]\tmp=429714, size=470964, highmem_size=0 [ 724.077458] shrink_all_memory: pages=10000 [ 724.160394] shrink_all_zones: pass=0, prio=5, lru=DMA32.2, pages=10000, reclaimed=9808 [ 724.261056] shrink_all_zones: pass=0, prio=5, lru=Normal.2, pages=10000, reclaimed=19610 [ 724.269482]|tmp=390489, size=451341, highmem_size=0 [ 724.353672] shrink_all_memory: pages=10000 [ 724.556153] shrink_all_zones: pass=0, prio=5, lru=DMA32.2, pages=10000, reclaimed=9806 [ 724.669591] shrink_all_zones: pass=0, prio=5, lru=Normal.2, pages=10000, reclaimed=19636 [ 724.677770]/tmp=351365, size=431780, highmem_size=0 [ 724.762188] shrink_all_memory: pages=10000 [ 724.923372] shrink_all_zones: pass=0, prio=5, lru=DMA32.2, pages=10000, reclaimed=9805 [ 725.037897] shrink_all_zones: pass=0, prio=5, lru=Normal.2, pages=10000, reclaimed=19620 [ 725.046501]-tmp=312189, size=412188, highmem_size=0 [ 725.133452] shrink_all_memory: pages=10000 [ 725.371199] shrink_all_zones: pass=0, prio=5, lru=DMA32.2, pages=10000, reclaimed=9781 [ 725.519983] shrink_all_zones: pass=0, prio=5, lru=Normal.2, pages=10000, reclaimed=19585 [ 725.528233]\tmp=273061, size=392627, highmem_size=0 [ 725.616020] shrink_all_memory: pages=10000 [ 725.801211] shrink_all_zones: pass=0, prio=4, lru=DMA32.2, pages=10000, reclaimed=9804 [ 725.954523] shrink_all_zones: pass=0, prio=4, lru=Normal.2, pages=10000, reclaimed=19617 [ 725.962685]|tmp=233885, size=373035, highmem_size=0 [ 726.051775] shrink_all_memory: pages=10000 [ 726.296589] shrink_all_zones: pass=0, prio=4, lru=DMA32.2, pages=10000, reclaimed=9804 [ 726.449150] shrink_all_zones: pass=0, prio=4, lru=Normal.2, pages=10000, reclaimed=19682 [ 726.457342]/tmp=194507, size=353350, highmem_size=0 [ 726.548053] shrink_all_memory: pages=10000 [ 726.759180] shrink_all_zones: pass=0, prio=4, lru=DMA32.2, pages=10000, reclaimed=9803 [ 726.940475] shrink_all_zones: pass=0, prio=4, lru=Normal.2, pages=10000, reclaimed=19561 [ 726.948638]-tmp=155396, size=333789, highmem_size=0 [ 727.040362] shrink_all_memory: pages=10000 [ 727.257478] shrink_all_zones: pass=0, prio=4, lru=DMA32.2, pages=10000, reclaimed=9804 [ 727.442356] shrink_all_zones: pass=0, prio=4, lru=Normal.2, pages=10000, reclaimed=19544 [ 727.450548]\tmp=116319, size=314259, highmem_size=0 [ 727.543609] shrink_all_memory: pages=10000 [ 727.755346] shrink_all_zones: pass=0, prio=4, lru=DMA32.2, pages=10000, reclaimed=9804 [ 727.894707] shrink_all_zones: pass=0, prio=4, lru=Normal.2, pages=10000, reclaimed=19555 [ 727.902910]|tmp=77256, size=294729, highmem_size=0 [ 727.997018] shrink_all_memory: pages=10000 [ 728.170973] shrink_all_zones: pass=0, prio=4, lru=DMA32.2, pages=10000, reclaimed=9799 [ 728.332426] shrink_all_zones: pass=0, prio=4, lru=Normal.2, pages=10000, reclaimed=19545 [ 728.341152]/tmp=38210, size=275199, highmem_size=0 [ 728.437625] shrink_all_memory: pages=10000 [ 728.673862] shrink_all_zones: pass=0, prio=4, lru=DMA32.2, pages=10000, reclaimed=9773 [ 728.812572] shrink_all_zones: pass=0, prio=4, lru=Normal.2, pages=10000, reclaimed=19517 [ 728.820738]-tmp=-852, size=255669, highmem_size=0 [ 728.917360] shrink_all_memory: pages=10000 [ 729.110178] shrink_all_zones: pass=0, prio=4, lru=DMA32.2, pages=10000, reclaimed=9839 [ 729.266243] shrink_all_zones: pass=0, prio=4, lru=Normal.2, pages=10000, reclaimed=19610 [ 729.274407]\tmp=-40045, size=236077, highmem_size=0 [ 729.372371] shrink_all_memory: pages=10000 [ 729.553743] shrink_all_zones: pass=0, prio=4, lru=Normal.2, pages=10000, reclaimed=9741 [ 729.673174] shrink_all_zones: pass=0, prio=3, lru=DMA.2, pages=259, reclaimed=256 [ 729.681224] shrink_all_zones: pass=0, prio=3, lru=DMA32.0, pages=259, reclaimed=256 [ 729.693997] shrink_all_zones: pass=0, prio=3, lru=DMA32.2, pages=259, reclaimed=513 [ 730.006423] shrink_all_zones: pass=0, prio=2, lru=DMA32.2, pages=9487, reclaimed=9296 [ 730.177563] shrink_all_zones: pass=0, prio=2, lru=Normal.2, pages=9487, reclaimed=18626 [ 730.185640]|tmp=-98138, size=207022, highmem_size=0 [ 730.285280] shrink_all_memory: pages=10000 [ 730.484499] shrink_all_zones: pass=0, prio=3, lru=DMA32.2, pages=10000, reclaimed=9807 [ 730.637792] shrink_all_zones: pass=0, prio=3, lru=Normal.2, pages=10000, reclaimed=19613 [ 730.645975]/tmp=-137343, size=187430, highmem_size=0 [ 730.746709] shrink_all_memory: pages=10000 [ 730.754374] shrink_all_zones: pass=0, prio=5, lru=Normal.0, pages=10000, reclaimed=0 [ 731.101101] shrink_all_zones: pass=0, prio=3, lru=DMA32.2, pages=10000, reclaimed=9777 [ 731.257243] shrink_all_zones: pass=0, prio=3, lru=Normal.2, pages=10000, reclaimed=19582 [ 731.265411]-tmp=-176567, size=167807, highmem_size=0 [ 731.367111] shrink_all_memory: pages=10000 [ 731.567779] shrink_all_zones: pass=0, prio=3, lru=DMA32.2, pages=10000, reclaimed=9811 [ 731.803019] shrink_all_zones: pass=0, prio=3, lru=Normal.2, pages=10000, reclaimed=19615 [ 731.811189]\tmp=-215837, size=148184, highmem_size=0 [ 731.913738] shrink_all_memory: pages=10000 [ 732.123893] shrink_all_zones: pass=0, prio=2, lru=DMA32.2, pages=10000, reclaimed=9808 [ 732.312075] shrink_all_zones: pass=0, prio=2, lru=Normal.2, pages=10000, reclaimed=19580 [ 732.320234]|tmp=-254948, size=128623, highmem_size=0 [ 732.423776] shrink_all_memory: pages=623 [ 732.432862] shrink_all_zones: pass=0, prio=12, lru=DMA.2, pages=623, reclaimed=617 [ 732.441782] shrink_all_zones: pass=0, prio=12, lru=Normal.0, pages=623, reclaimed=617 [ 732.453341] shrink_all_zones: pass=0, prio=11, lru=DMA.0, pages=6, reclaimed=0 [ 732.460712] shrink_all_zones: pass=0, prio=11, lru=DMA32.0, pages=6, reclaimed=0 [ 732.468390] shrink_all_zones: pass=0, prio=11, lru=DMA32.2, pages=6, reclaimed=6 [ 732.488091] shrink_all_zones: pass=0, prio=6, lru=DMA32.2, pages=623, reclaimed=617 [ 732.508256] shrink_all_zones: pass=0, prio=6, lru=Normal.2, pages=623, reclaimed=1233 [ 732.516202]/tmp=-258774, size=126704, highmem_size=0 [ 732.753869]done (372529 pages freed) [ 732.757916] PM: Freed 1490116 kbytes in 9.37 seconds (159.03 MB/s)
Re: [PATCH 0/4] PM: Drop shrink_all_memory (rev. 2) (was: Re: [PATCH 3/3] PM/Hibernate: Use memory allocations to free memory)
Quoted 2 lines · Wu Fengguang
Hi Rafael,
Hi,
Quoted 5 lines
I happened to be doing some benchmarks on the older
shrink_all_memory(), Hopefully it can be a useful reference point for the new design.The current swsusp_shrink_memory()/shrink_all_memory() are terribly
inefficient: it takes 7-9s to free up 1.4G memory:
One reason may be that it takes too many steps to do it,
Quoted 2 lines
[ 131.899389] PM: Freed 1413380 kbytes in 7.03 seconds (201.04 MB/s) [ 732.757916] PM: Freed 1490116 kbytes in 9.37 seconds (159.03 MB/s)
because the new way doesn't seem to do any better.
Quoted 5 lines
Below are the logs I collected by injecting printks. There are basically two major problems:
-swsusp_shrink_memory()scans the whole 2G memory again and again;
-shrink_all_memory()is slow. It won't reclaim pages at all with small priority values, because it's batching size is 10000 pages.
I know that swsusp_shrink_memory() has problems, that's why I'd like to get rid of it.
Quoted 1 line
I wonder if it's possible to free up the memory within 1s at all.
I'm not sure.
Apparently, the counting of saveable pages takes substantial time (0.5 s each iteration on my 64-bit test box), so we can improve that by limiting the number of iterations.
Well, perhaps we can do it all in one shot after all, I'll think how to do that.
Thanks,
Rafael
cover PM: Drop shrink_all_memory (rev. 3)
Quoted 30 lines · Rafael J. Wysocki
Quoted 2 lines · Wu Fengguang
Hi Rafael,
Hi,
Quoted 5 lines
I happened to be doing some benchmarks on the older
shrink_all_memory(), Hopefully it can be a useful reference point for the new design.The current swsusp_shrink_memory()/shrink_all_memory() are terribly
inefficient: it takes 7-9s to free up 1.4G memory:One reason may be that it takes too many steps to do it,
Quoted 2 lines
[ 131.899389] PM: Freed 1413380 kbytes in 7.03 seconds (201.04 MB/s) [ 732.757916] PM: Freed 1490116 kbytes in 9.37 seconds (159.03 MB/s)because the new way doesn't seem to do any better.
Quoted 5 lines
Below are the logs I collected by injecting printks. There are basically two major problems:
-swsusp_shrink_memory()scans the whole 2G memory again and again;
-shrink_all_memory()is slow. It won't reclaim pages at all with small priority values, because it's batching size is 10000 pages.I know that
swsusp_shrink_memory()has problems, that's why I'd like to get rid of it.Quoted 1 line
I wonder if it's possible to free up the memory within 1s at all.
Quoted 7 lines
I'm not sure.
Apparently, the counting of saveable pages takes substantial time (0.5 s each iteration on my 64-bit test box), so we can improve that by limiting the number of iterations.
Well, perhaps we can do it all in one shot after all, I'll think how to do that.
I've changed swsusp_shrink_memory() to preallocate all of the pages in one iteration. Although it doesn't seem to improve the speed of memory shrinking, the function is simpler in this form.
Anyway, updated patch series follows:
[1/5] - the Andrew's patch introducing __GFP_NO_OOM_KILL (I decided it would be
better do it this way in this particular case. The fact that the OOM killer is not going to work after tasks have been frozen is a different issue.)
[2/5] - move swsusp_shrink_memory to snapshot.c, no major changes
[3/5] - remove the shrinking of memory from suspend code (in a separate patch
as requested by Linus)
[4/5] - use memory allocations to for making the room for the image
[5/5] - do not release all memory allocated by [4/5] and use it for
creating the image directly (some allocated memory is released).
Thanks,
Rafael
PATCH 1/5 mm: Add __GFP_NO_OOM_KILL flag
From: Andrew Morton <akpm-de/[email protected]>
Quoted 4 lines
Quoted 1 line
Remind me: why can't we just allocate N pages at suspend-time?
We need half of memory free. The reason we can't "just allocate" is probably OOM killer; but my memories are quite weak :-(.
hm. You'd think that with our splendid range of __GFP_foo falgs, there would be some combo which would suit this requirement but I can't immediately spot one.
We can always add another I guess. Something like...
[rjw: fixed white space]
--- include/linux/gfp.h | 3 ++- mm/page_alloc.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-)
mm/page_alloc.c +2 -1
@@ -1620,7 +1620,8 @@ nofail_alloc: }/* The OOM killer will not help higher order allocs so fail */ -if (order >PAGE_ALLOC_COSTLY_ORDER ) { +if (order >PAGE_ALLOC_COSTLY_ORDER || + (gfp_mask & __GFP_NO_OOM_KILL)) {clear_zonelist_oom (zonelist, gfp_mask); goto nopage; }
include/linux/gfp.h +2 -1
@@ -51,8 +51,9 @@ struct vm_area_struct;#define __GFP_THISNODE ((__force gfp_t)0x40000u)/* No fallback, no policies */ #define __GFP_RECLAIMABLE ((__force gfp_t)0x80000u)/* Page is reclaimable */ #define __GFP_MOVABLE ((__force gfp_t)0x100000u)/* Page is movable */ +#define __GFP_NO_OOM_KILL ((__force gfp_t)0x200000u)/* Don't invoke out_of_memory() */ -#define __GFP_BITS_SHIFT 21/* Room for 21 __GFP_FOO bits */ +#define __GFP_BITS_SHIFT 22/* Number of __GFP_FOO bits */ #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))/* This equals 0, but use constants in case they ever change */
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
Quoted 5 lines · Rafael J. Wysocki
Index:
linux-2.6/mm/page_alloc.c
===================================================================
mm/page_alloc.c nofail_alloc: · line 1627
Quoted 9 lines
mm/page_alloc.c +2
-1@@ -1620,7 +1620,8 @@ nofail_alloc: }/* The OOM killer will not help higher order allocs so fail */ -if (order >PAGE_ALLOC_COSTLY_ORDER ) { +if (order >PAGE_ALLOC_COSTLY_ORDER || + (gfp_mask & __GFP_NO_OOM_KILL)) {clear_zonelist_oom (zonelist, gfp_mask); goto nopage; }
This is inconsistent because __GFP_NO_OOM_KILL now implies __GFP_NORETRY (the "goto nopage" above), but only for allocations with __GFP_FS set and __GFP_NORETRY clear.
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
Quoted 9 lines · David Rientjes
Quoted 7 lines · Rafael J. Wysocki
Index:
linux-2.6/mm/page_alloc.c
===================================================================mm/page_alloc.c +0
-0@@ -1620,7 +1620,8 @@ nofail_alloc: }
Quoted 11 lines
mm/page_alloc.c nofail_alloc: · line 1627
Quoted 7 lines
mm/page_alloc.c +2
-1/* The OOM killer will not help higher order allocs so fail */ -if (order >PAGE_ALLOC_COSTLY_ORDER ) { +if (order >PAGE_ALLOC_COSTLY_ORDER || + (gfp_mask & __GFP_NO_OOM_KILL)) {clear_zonelist_oom (zonelist, gfp_mask); goto nopage; }This is inconsistent because
__GFP_NO_OOM_KILLnow implies__GFP_NORETRY(the "goto nopage" above), but only for allocations with__GFP_FSset and__GFP_NORETRYclear.
Well, what would you suggest?
Rafael
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
Quoted 19 lines · Rafael J. Wysocki
Quoted 7 lines
Quoted 7 lines
Index:
linux-2.6/mm/page_alloc.c
===================================================================mm/page_alloc.c +0
-0@@ -1620,7 +1620,8 @@ nofail_alloc: }Quoted 11 lines
mm/page_alloc.c nofail_alloc: · line 1627
Quoted 7 lines
mm/page_alloc.c +2
-1/* The OOM killer will not help higher order allocs so fail */ -if (order >PAGE_ALLOC_COSTLY_ORDER ) { +if (order >PAGE_ALLOC_COSTLY_ORDER || + (gfp_mask & __GFP_NO_OOM_KILL)) {clear_zonelist_oom (zonelist, gfp_mask); goto nopage; }This is inconsistent because
__GFP_NO_OOM_KILLnow implies__GFP_NORETRY(the "goto nopage" above), but only for allocations with__GFP_FSset and__GFP_NORETRYclear.
Quoted 2 lines
Well, what would you suggest?
A couple things:
- rebase this on mmotm so that it doesn't conflict with Mel Gorman's page allocator speedup changes, and
- avoid the final call to get_page_from_freelist() for !(gfp_mask & __GFP_NO_OOM_KILL) by adding a check for it alongside (gfp_mask & __GFP_FS) and !(gfp_mask & __GFP_NORETRY) because it should really only catch parallel oom killings which won't happen in your suspend case since it uses ALLOC_WMARK_HIGH.
The latter is important to avoid unnecessary dependencies among low-level __GFP_* flags (although all __GFP_NO_OOM_KILL allocations should really all be passing __GFP_NORETRY too to avoid relying too heavily on direct reclaim).
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
Quoted 21 lines · David Rientjes
Quoted 19 lines · Rafael J. Wysocki
Quoted 18 lines
Quoted 5 lines
Index:
linux-2.6/mm/page_alloc.c
===================================================================mm/page_alloc.c nofail_alloc: · line 1627
Quoted 9 lines
mm/page_alloc.c +2
-1@@ -1620,7 +1620,8 @@ nofail_alloc: }/* The OOM killer will not help higher order allocs so fail */ -if (order >PAGE_ALLOC_COSTLY_ORDER ) { +if (order >PAGE_ALLOC_COSTLY_ORDER || + (gfp_mask & __GFP_NO_OOM_KILL)) {clear_zonelist_oom (zonelist, gfp_mask); goto nopage; }This is inconsistent because
__GFP_NO_OOM_KILLnow implies__GFP_NORETRY(the "goto nopage" above), but only for allocations with__GFP_FSset and__GFP_NORETRYclear.
Quoted 7 lines
Quoted 2 lines
Well, what would you suggest?
A couple things:
- rebase this on mmotm so that it doesn't conflict with Mel Gorman's page allocator speedup changes, and
I'm going to rebase the patchset on top of linux-next eventually.
Quoted 10 lines
- avoid the final call to
get_page_from_freelist()for !(gfp_mask &__GFP_NO_OOM_KILL) by adding a check for it alongside (gfp_mask&__GFP_FS) and !(gfp_mask &__GFP_NORETRY) because it should really only catch parallel oom killings which won't happen in your suspend case since it usesALLOC_WMARK_HIGH.The latter is important to avoid unnecessary dependencies among low-level __GFP_* flags (although all
__GFP_NO_OOM_KILLallocations should really all be passing__GFP_NORETRYtoo to avoid relying too heavily on direct reclaim).
OK, thanks.
Something like this?
--- include/linux/gfp.h | 3 ++- mm/page_alloc.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-)
mm/page_alloc.c +2 -1
@@ -1599,7 +1599,8 @@ nofail_alloc: zonelist, high_zoneidx, alloc_flags);if (page) goto got_pg; - }else if ((gfp_mask & __GFP_FS) && !(gfp_mask & __GFP_NORETRY)) { + }else if ((gfp_mask & __GFP_FS) && !(gfp_mask & __GFP_NORETRY) + && !(gfp_mask & __GFP_NO_OOM_KILL)) {if (!try_set_zone_oom (zonelist, gfp_mask)) {schedule_timeout_uninterruptible (1 ); goto restart;
include/linux/gfp.h +2 -1
@@ -51,8 +51,9 @@ struct vm_area_struct;#define __GFP_THISNODE ((__force gfp_t)0x40000u)/* No fallback, no policies */ #define __GFP_RECLAIMABLE ((__force gfp_t)0x80000u)/* Page is reclaimable */ #define __GFP_MOVABLE ((__force gfp_t)0x100000u)/* Page is movable */ +#define __GFP_NO_OOM_KILL ((__force gfp_t)0x200000u)/* Don't invoke out_of_memory() */ -#define __GFP_BITS_SHIFT 21/* Room for 21 __GFP_FOO bits */ +#define __GFP_BITS_SHIFT 22/* Number of __GFP_FOO bits */ #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))/* This equals 0, but use constants in case they ever change */
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
Quoted 20 lines · Rafael J. Wysocki
Index:
linux-2.6/mm/page_alloc.c
===================================================================mm/page_alloc.c +2
-1@@ -1599,7 +1599,8 @@ nofail_alloc: zonelist, high_zoneidx, alloc_flags);if (page) goto got_pg; - }else if ((gfp_mask & __GFP_FS) && !(gfp_mask & __GFP_NORETRY)) { + }else if ((gfp_mask & __GFP_FS) && !(gfp_mask & __GFP_NORETRY) + && !(gfp_mask & __GFP_NO_OOM_KILL)) {if (!try_set_zone_oom (zonelist, gfp_mask)) {schedule_timeout_uninterruptible (1 ); goto restart;Index:
linux-2.6/include/linux/gfp.h
===================================================================
include/linux/gfp.h struct vm_area_struct; · line 59
Quoted 10 lines
include/linux/gfp.h +2
-1@@ -51,8 +51,9 @@ struct vm_area_struct;#define __GFP_THISNODE ((__force gfp_t)0x40000u)/* No fallback, no policies */ #define __GFP_RECLAIMABLE ((__force gfp_t)0x80000u)/* Page is reclaimable */ #define __GFP_MOVABLE ((__force gfp_t)0x100000u)/* Page is movable */ +#define __GFP_NO_OOM_KILL ((__force gfp_t)0x200000u)/* Don't invoke out_of_memory() */ -#define __GFP_BITS_SHIFT 21/* Room for 21 __GFP_FOO bits */ +#define __GFP_BITS_SHIFT 22/* Number of __GFP_FOO bits */ #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))/* This equals 0, but use constants in case they ever change */
Yeah, that's much better, thanks. There's currently concerns about adding a new gfp flag in another thread (__GFP_PANIC), though, so you might find some resistance in adding a flag with a very specific and limited use cae.
I think you might have better luck in doing
struct zone *z; for_each_populated_zone(z) zone_set_flag(z, ZONE_OOM_LOCKED);
if all other tasks are really in D state at this point since oom killer serialization is done with try locks in the page allocator. This is equivalent to __GFP_NO_OOM_KILL.
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
Quoted 30 lines · David Rientjes
Quoted 28 lines · Rafael J. Wysocki
Index:
linux-2.6/mm/page_alloc.c
===================================================================mm/page_alloc.c +2
-1@@ -1599,7 +1599,8 @@ nofail_alloc: zonelist, high_zoneidx, alloc_flags);if (page) goto got_pg; - }else if ((gfp_mask & __GFP_FS) && !(gfp_mask & __GFP_NORETRY)) { + }else if ((gfp_mask & __GFP_FS) && !(gfp_mask & __GFP_NORETRY) + && !(gfp_mask & __GFP_NO_OOM_KILL)) {if (!try_set_zone_oom (zonelist, gfp_mask)) {schedule_timeout_uninterruptible (1 ); goto restart;Index:
linux-2.6/include/linux/gfp.h
===================================================================include/linux/gfp.h +2
-1@@ -51,8 +51,9 @@ struct vm_area_struct;#define __GFP_THISNODE ((__force gfp_t)0x40000u)/* No fallback, no policies */ #define __GFP_RECLAIMABLE ((__force gfp_t)0x80000u)/* Page is reclaimable */ #define __GFP_MOVABLE ((__force gfp_t)0x100000u)/* Page is movable */ +#define __GFP_NO_OOM_KILL ((__force gfp_t)0x200000u)/* Don't invoke out_of_memory() */ -#define __GFP_BITS_SHIFT 21/* Room for 21 __GFP_FOO bits */ +#define __GFP_BITS_SHIFT 22/* Number of __GFP_FOO bits */ #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
Quoted 6 lines
include/linux/gfp.h struct vm_area_struct; · line 59
Quoted 2 lines
include/linux/gfp.h +0
-0/* This equals 0, but use constants in case they ever change */ Yeah, that's much better, thanks. There's currently concerns about adding a new gfp flag in another thread (
__GFP_PANIC), though, so you might find some resistance in adding a flag with a very specific and limited use cae.
Oh great. Andrew, what's your opinion?
Quoted 9 lines
I think you might have better luck in doing
struct zone *z; for_each_populated_zone(z) zone_set_flag(z, ZONE_OOM_LOCKED);if all other tasks are really in D state at this point since oom killer serialization is done with try locks in the page allocator.
Not all of them, actually. Some kernel threads are not freezable.
Quoted 1 line
This is equivalent to
__GFP_NO_OOM_KILL.
In that case I think I'd go back to my initial idea with disabling the OOM killer after freezing tasks.
Roughly, this. [The idea is that the OOM killer is not really going to work while tasks are frozen, so we can just give up calling it in that case.]
--- include/linux/freezer.h | 2 ++ kernel/power/process.c | 12 ++++++++++++ mm/page_alloc.c | 4 +++- 3 files changed, 17 insertions(+), 1 deletion(-)
kernel/power/process.c +12 -0
@@ -19,6 +19,8 @@*/ #define TIMEOUT (20 * HZ) +static bool tasks_frozen; +static inline int freezeable (struct task_struct * p) { if ((p == current) ||
@@ -120,6 +122,10 @@ int freeze_processes(void) Exit:BUG_ON (in_atomic ());printk ("\n" ); + +if (!error) + tasks_frozen = true; +return error; }
@@ -145,6 +151,8 @@ static void thaw_tasks(bool nosig_only)void thaw_processes (void ) { + tasks_frozen = false; +printk ("Restarting tasks ... " );thaw_tasks (true);thaw_tasks (false);
@@ -152,3 +160,7 @@ void thaw_processes(void)printk ("done.\n" ); } +bool processes_are_frozen (void ) +{ +return tasks_frozen; +}
include/linux/freezer.h +2 -0
@@ -50,6 +50,7 @@ extern int thaw_process(struct task_struextern void refrigerator (void );extern int freeze_processes (void );extern void thaw_processes (void ); +extern bool processes_are_frozen (void );static inline int try_to_freeze (void ) {
@@ -170,6 +171,7 @@ static inline int thaw_process(struct tastatic inline void refrigerator (void ) {}static inline int freeze_processes (void ) {BUG ();return 0 ; }static inline void thaw_processes (void ) {} +static inline bool processes_are_frozen (void ) {return false; }static inline int try_to_freeze (void ) {return 0 ; }
mm/page_alloc.c +3 -1
@@ -46,6 +46,7 @@#include <linux/page-isolation.h> #include <linux/page_cgroup.h> #include <linux/debugobjects.h> +#include <linux/freezer.h> #include <asm/tlbflush.h> #include <asm/div64.h>
@@ -1599,7 +1600,8 @@ nofail_alloc: zonelist, high_zoneidx, alloc_flags);if (page) goto got_pg; - }else if ((gfp_mask & __GFP_FS) && !(gfp_mask & __GFP_NORETRY)) { + }else if ((gfp_mask & __GFP_FS) && !(gfp_mask & __GFP_NORETRY) + && !processes_are_frozen ()) {if (!try_set_zone_oom (zonelist, gfp_mask)) {schedule_timeout_uninterruptible (1 ); goto restart;
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
Quoted 74 lines · Rafael J. Wysocki
Index:
linux-2.6/kernel/power/process.c
===================================================================kernel/power/process.c +12
-0@@ -19,6 +19,8 @@*/ #define TIMEOUT (20 * HZ) +static bool tasks_frozen; +static inline int freezeable (struct task_struct * p) { if ((p == current) ||@@ -120,6 +122,10 @@ int freeze_processes(void) Exit:BUG_ON (in_atomic ());printk ("\n" ); + +if (!error) + tasks_frozen = true; +return error; }@@ -145,6 +151,8 @@ static void thaw_tasks(bool nosig_only)void thaw_processes (void ) { + tasks_frozen = false; +printk ("Restarting tasks ... " );thaw_tasks (true);thaw_tasks (false);@@ -152,3 +160,7 @@ void thaw_processes(void)printk ("done.\n" ); } +bool processes_are_frozen (void ) +{ +return tasks_frozen; +}Index:
linux-2.6/include/linux/freezer.h
===================================================================include/linux/freezer.h +2
-0@@ -50,6 +50,7 @@ extern int thaw_process(struct task_struextern void refrigerator (void );extern int freeze_processes (void );extern void thaw_processes (void ); +extern bool processes_are_frozen (void );static inline int try_to_freeze (void ) {@@ -170,6 +171,7 @@ static inline int thaw_process(struct tastatic inline void refrigerator (void ) {}static inline int freeze_processes (void ) {BUG ();return 0 ; }static inline void thaw_processes (void ) {} +static inline bool processes_are_frozen (void ) {return false; }static inline int try_to_freeze (void ) {return 0 ; }Index:
linux-2.6/mm/page_alloc.c
===================================================================mm/page_alloc.c +1
-0@@ -46,6 +46,7 @@#include <linux/page-isolation.h> #include <linux/page_cgroup.h> #include <linux/debugobjects.h> +#include <linux/freezer.h> #include <asm/tlbflush.h> #include <asm/div64.h>
mm/page_alloc.c nofail_alloc: · line 1607
Quoted 9 lines
mm/page_alloc.c +2
-1@@ -1599,7 +1600,8 @@ nofail_alloc: zonelist, high_zoneidx, alloc_flags);if (page) goto got_pg; - }else if ((gfp_mask & __GFP_FS) && !(gfp_mask & __GFP_NORETRY)) { + }else if ((gfp_mask & __GFP_FS) && !(gfp_mask & __GFP_NORETRY) + && !processes_are_frozen ()) {if (!try_set_zone_oom (zonelist, gfp_mask)) {schedule_timeout_uninterruptible (1 ); goto restart;
Cool, that looks like the semantics of __GFP_NO_OOM_KILL without requiring a new gfp flag. Thanks.
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
Quoted 73 lines · David Rientjes
Quoted 71 lines · Rafael J. Wysocki
Index:
linux-2.6/kernel/power/process.c
===================================================================kernel/power/process.c +12
-0@@ -19,6 +19,8 @@*/ #define TIMEOUT (20 * HZ) +static bool tasks_frozen; +static inline int freezeable (struct task_struct * p) { if ((p == current) ||@@ -120,6 +122,10 @@ int freeze_processes(void) Exit:BUG_ON (in_atomic ());printk ("\n" ); + +if (!error) + tasks_frozen = true; +return error; }@@ -145,6 +151,8 @@ static void thaw_tasks(bool nosig_only)void thaw_processes (void ) { + tasks_frozen = false; +printk ("Restarting tasks ... " );thaw_tasks (true);thaw_tasks (false);@@ -152,3 +160,7 @@ void thaw_processes(void)printk ("done.\n" ); } +bool processes_are_frozen (void ) +{ +return tasks_frozen; +}Index:
linux-2.6/include/linux/freezer.h
===================================================================include/linux/freezer.h +2
-0@@ -50,6 +50,7 @@ extern int thaw_process(struct task_struextern void refrigerator (void );extern int freeze_processes (void );extern void thaw_processes (void ); +extern bool processes_are_frozen (void );static inline int try_to_freeze (void ) {@@ -170,6 +171,7 @@ static inline int thaw_process(struct tastatic inline void refrigerator (void ) {}static inline int freeze_processes (void ) {BUG ();return 0 ; }static inline void thaw_processes (void ) {} +static inline bool processes_are_frozen (void ) {return false; }static inline int try_to_freeze (void ) {return 0 ; }Index:
linux-2.6/mm/page_alloc.c
===================================================================mm/page_alloc.c +1
-0@@ -46,6 +46,7 @@#include <linux/page-isolation.h> #include <linux/page_cgroup.h> #include <linux/debugobjects.h> +#include <linux/freezer.h>
Quoted 15 lines
mm/page_alloc.c nofail_alloc: · line 1607
Quoted 12 lines
mm/page_alloc.c +2
-1#include <asm/tlbflush.h> #include <asm/div64.h> @@ -1599,7 +1600,8 @@ nofail_alloc: zonelist, high_zoneidx, alloc_flags);if (page) goto got_pg; - }else if ((gfp_mask & __GFP_FS) && !(gfp_mask & __GFP_NORETRY)) { + }else if ((gfp_mask & __GFP_FS) && !(gfp_mask & __GFP_NORETRY) + && !processes_are_frozen ()) {if (!try_set_zone_oom (zonelist, gfp_mask)) {schedule_timeout_uninterruptible (1 ); goto restart;Cool, that looks like the semantics of
__GFP_NO_OOM_KILLwithout requiring a new gfp flag. Thanks.
Well, you're welcome.
BTW, I think that Andrew was actually right when he asked if I checked whether the existing __GFP_NORETRY would work as-is for __GFP_FS set and __GFP_NORETRY unset. Namely, in that case we never reach the code before
nopage: that checks __GFP_NORETRY, do we?
So I think we shouldn't modify the 'else if' condition above and check for !processes_are_frozen() at the beginning of the block below.
Thanks,
Rafael
Andrew Morton
maintainerRe: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
Quoted 10 lines · On Wed, 6 May 2009 00:19:35 +0200 "Rafael J. Wysocki"…
Quoted 7 lines
mm/page_alloc.c nofail_alloc: · line 1607
Quoted 4 lines
mm/page_alloc.c +1
-0+ && !processes_are_frozen()) {if (!try_set_zone_oom (zonelist, gfp_mask)) {schedule_timeout_uninterruptible (1 ); goto restart;Cool, that looks like the semantics of
__GFP_NO_OOM_KILLwithout requiring a new gfp flag. Thanks.Well, you're welcome.
Quoted 7 lines
BTW, I think that Andrew was actually right when he asked if I checked whether the existing
__GFP_NORETRYwould work as-is for__GFP_FSset and__GFP_NORETRYunset. Namely, in that case we never reach the code before
nopage: that checks__GFP_NORETRY, do we?So I think we shouldn't modify the 'else if' condition above and check for !processes_are_frozen() at the beginning of the block below.
Confused.
I'm suspecting that hibernation can allocate its pages with __GFP_FS|__GFP_WAIT|__GFP_NORETRY|__GFP_NOWARN, and the page allocator will dtrt: no oom-killings.
In which case, processes_are_frozen() is not needed at all?
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
Quoted 21 lines · Andrew Morton
Quoted 10 lines · On Wed, 6 May 2009 00:19:35 +0200 "Rafael J. Wysocki"…
Quoted 7 lines
mm/page_alloc.c nofail_alloc: · line 1607
Quoted 4 lines
mm/page_alloc.c +1
-0+ && !processes_are_frozen()) {if (!try_set_zone_oom (zonelist, gfp_mask)) {schedule_timeout_uninterruptible (1 ); goto restart;Cool, that looks like the semantics of
__GFP_NO_OOM_KILLwithout requiring a new gfp flag. Thanks.Well, you're welcome.
Quoted 7 lines
BTW, I think that Andrew was actually right when he asked if I checked whether the existing
__GFP_NORETRYwould work as-is for__GFP_FSset and__GFP_NORETRYunset. Namely, in that case we never reach the code before
nopage: that checks__GFP_NORETRY, do we?So I think we shouldn't modify the 'else if' condition above and check for !processes_are_frozen() at the beginning of the block below.
Quoted 7 lines
Confused.
I'm suspecting that hibernation can allocate its pages with __GFP_FS|__GFP_WAIT|__GFP_NORETRY|__GFP_NOWARN, and the page allocator will dtrt: no oom-killings.
In which case,
processes_are_frozen()is not needed at all?
__GFP_NORETRY alone causes it to fail relatively quickly, but I'll try with the combination.
Anyway, even if the hibernation code itself doesn't trigger the OOM killer, but anyone else allocates memory in parallel or after we've preallocated the image memory, that may still trigger it. So it seems processes_are_frozen() may still be useful?
Andrew Morton
maintainerRe: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
Quoted 24 lines · On Wed, 6 May 2009 01:20:34 +0200 "Rafael J. Wysocki"…
Quoted 23 lines · Andrew Morton
Quoted 10 lines · On Wed, 6 May 2009 00:19:35 +0200 "Rafael J. Wysocki"…
Quoted 7 lines
mm/page_alloc.c nofail_alloc: · line 1607
Quoted 4 lines
mm/page_alloc.c +1
-0+ && !processes_are_frozen()) {if (!try_set_zone_oom (zonelist, gfp_mask)) {schedule_timeout_uninterruptible (1 ); goto restart;Cool, that looks like the semantics of
__GFP_NO_OOM_KILLwithout requiring a new gfp flag. Thanks.Well, you're welcome.
Quoted 7 lines
BTW, I think that Andrew was actually right when he asked if I checked whether the existing
__GFP_NORETRYwould work as-is for__GFP_FSset and__GFP_NORETRYunset. Namely, in that case we never reach the code before
nopage: that checks__GFP_NORETRY, do we?So I think we shouldn't modify the 'else if' condition above and check for !processes_are_frozen() at the beginning of the block below.
Confused.
Quoted 8 lines
Quoted 5 lines
I'm suspecting that hibernation can allocate its pages with __GFP_FS|__GFP_WAIT|__GFP_NORETRY|__GFP_NOWARN, and the page allocator will dtrt: no oom-killings.
In which case,
processes_are_frozen()is not needed at all?
__GFP_NORETRYalone causes it to fail relatively quickly, but I'll try with the combination.
OK. __GFP_WAIT is the big hammer.
Quoted 4 lines
Anyway, even if the hibernation code itself doesn't trigger the OOM killer, but anyone else allocates memory in parallel or after we've preallocated the image memory, that may still trigger it. So it seems
processes_are_frozen()may still be useful?
Could be. But only kernel threads are active at this time (yes?), and they won't have much work to do because userspace is asleep.
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
Quoted 31 lines · Andrew Morton
Quoted 28 lines · On Wed, 6 May 2009 01:20:34 +0200 "Rafael J. Wysocki"…
Quoted 27 lines · Andrew Morton
Quoted 10 lines · On Wed, 6 May 2009 00:19:35 +0200 "Rafael J. Wysocki"…
Quoted 7 lines
mm/page_alloc.c nofail_alloc: · line 1607
Quoted 4 lines
mm/page_alloc.c +1
-0+ && !processes_are_frozen()) {if (!try_set_zone_oom (zonelist, gfp_mask)) {schedule_timeout_uninterruptible (1 ); goto restart;Cool, that looks like the semantics of
__GFP_NO_OOM_KILLwithout requiring a new gfp flag. Thanks.Well, you're welcome.
Quoted 7 lines
BTW, I think that Andrew was actually right when he asked if I checked whether the existing
__GFP_NORETRYwould work as-is for__GFP_FSset and__GFP_NORETRYunset. Namely, in that case we never reach the code before
nopage: that checks__GFP_NORETRY, do we?So I think we shouldn't modify the 'else if' condition above and check for !processes_are_frozen() at the beginning of the block below.
Confused.
I'm suspecting that hibernation can allocate its pages with __GFP_FS|__GFP_WAIT|__GFP_NORETRY|__GFP_NOWARN, and the page allocator will dtrt: no oom-killings.
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
In which case,
processes_are_frozen()is not needed at all?
__GFP_NORETRYalone causes it to fail relatively quickly, but I'll try with the combination.OK.
__GFP_WAITis the big hammer.
Unfortunately it fails too quickly with the combination as well, so it looks like we can't use __GFP_NORETRY during hibernation.
Andrew Morton
maintainerRe: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
Quoted 6 lines · On Thu, 7 May 2009 20:09:52 +0200 "Rafael J. Wysocki"…
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
I'm suspecting that hibernation can allocate its pages with __GFP_FS|__GFP_WAIT|__GFP_NORETRY|__GFP_NOWARN, and the page allocator will dtrt: no oom-killings.
In which case,
processes_are_frozen()is not needed at all?
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
__GFP_NORETRYalone causes it to fail relatively quickly, but I'll try with the combination.OK.
__GFP_WAITis the big hammer.Unfortunately it fails too quickly with the combination as well, so it looks like we can't use
__GFP_NORETRYduring hibernation.
hm.
So where do we stand now?
I'm not a big fan of the global application-specific state change thing. Something like __GFP_NO_OOM_KILL has a better chance of being reused by other subsystems in the future, which is a good indicator.
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
Quoted 17 lines · Andrew Morton
Quoted 6 lines · On Thu, 7 May 2009 20:09:52 +0200 "Rafael J. Wysocki"…
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
I'm suspecting that hibernation can allocate its pages with __GFP_FS|__GFP_WAIT|__GFP_NORETRY|__GFP_NOWARN, and the page allocator will dtrt: no oom-killings.
In which case,
processes_are_frozen()is not needed at all?Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
__GFP_NORETRYalone causes it to fail relatively quickly, but I'll try with the combination.OK.
__GFP_WAITis the big hammer.Unfortunately it fails too quickly with the combination as well, so it looks like we can't use
__GFP_NORETRYduring hibernation.
Quoted 7 lines
hm.
So where do we stand now?
I'm not a big fan of the global application-specific state change thing. Something like
__GFP_NO_OOM_KILLhas a better chance of being reused by other subsystems in the future, which is a good indicator.
I'm not against __GFP_NO_OOM_KILL, but there's been some strong resistance to adding new _GPF _FOO flags recently. Is there any likelihood anyone else we'll really need it any time soon?
The advantage of the freezer-based approach is that it disables the OOM killer when it's not going to work anyway, so it looks like a reasonable thing to do regardless. IMHO.
Andrew Morton
maintainerRe: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
Quoted 20 lines · On Thu, 7 May 2009 21:33:47 +0200 "Rafael J. Wysocki"…
Quoted 19 lines · Andrew Morton
Quoted 6 lines · On Thu, 7 May 2009 20:09:52 +0200 "Rafael J. Wysocki"…
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
I'm suspecting that hibernation can allocate its pages with __GFP_FS|__GFP_WAIT|__GFP_NORETRY|__GFP_NOWARN, and the page allocator will dtrt: no oom-killings.
In which case,
processes_are_frozen()is not needed at all?Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
__GFP_NORETRYalone causes it to fail relatively quickly, but I'll try with the combination.OK.
__GFP_WAITis the big hammer.Unfortunately it fails too quickly with the combination as well, so it looks like we can't use
__GFP_NORETRYduring hibernation.hm.
Quoted 8 lines
Quoted 5 lines
So where do we stand now?
I'm not a big fan of the global application-specific state change thing. Something like
__GFP_NO_OOM_KILLhas a better chance of being reused by other subsystems in the future, which is a good indicator.I'm not against
__GFP_NO_OOM_KILL, but there's been some strong resistance to adding new_GPF_FOOflags recently.
We have six or seven left - hardly a crisis.
Quoted 2 lines
Is there any likelihood anyone else we'll
really need it any time soon?
Dunno - people do all sorts of crazy things. But it's more likely to be reused than a PM-specific global!
I have no strong feelings really, but slotting into the existing technique with something which might be reusable is quite a bit tidier.
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
Quoted 34 lines · Andrew Morton
Quoted 20 lines · On Thu, 7 May 2009 21:33:47 +0200 "Rafael J. Wysocki"…
Quoted 19 lines · Andrew Morton
Quoted 6 lines · On Thu, 7 May 2009 20:09:52 +0200 "Rafael J. Wysocki"…
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
I'm suspecting that hibernation can allocate its pages with __GFP_FS|__GFP_WAIT|__GFP_NORETRY|__GFP_NOWARN, and the page allocator will dtrt: no oom-killings.
In which case,
processes_are_frozen()is not needed at all?Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
__GFP_NORETRYalone causes it to fail relatively quickly, but I'll try with the combination.OK.
__GFP_WAITis the big hammer.Unfortunately it fails too quickly with the combination as well, so it looks like we can't use
__GFP_NORETRYduring hibernation.hm.
Quoted 8 lines
Quoted 5 lines
So where do we stand now?
I'm not a big fan of the global application-specific state change thing. Something like
__GFP_NO_OOM_KILLhas a better chance of being reused by other subsystems in the future, which is a good indicator.I'm not against
__GFP_NO_OOM_KILL, but there's been some strong resistance to adding new_GPF_FOOflags recently.We have six or seven left - hardly a crisis.
Quoted 8 lines
Quoted 2 lines
Is there any likelihood anyone else we'll
really need it any time soon?Dunno - people do all sorts of crazy things. But it's more likely to be reused than a PM-specific global!
I have no strong feelings really, but slotting into the existing technique with something which might be reusable is quite a bit tidier.
OK, let's try with __GFP_NO_OOM_KILL first. If there's too much disagreement, I'll use the freezer-based approach instead.
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
Quoted 3 lines · Rafael J. Wysocki
OK, let's try with
__GFP_NO_OOM_KILLfirst. If there's too much disagreement, I'll use the freezer-based approach instead.
Third time I'm going to suggest this, and I'd like a response on why it's not possible instead of being ignored.
All of your tasks are in D state other than kthreads, right? That means they won't be in the oom killer (thus no zones are oom locked), so you can easily do this
struct zone *z; for_each_populated_zone(z) zone_set_flag(z, ZONE_OOM_LOCKED);
and then
for_each_populated_zone(z) zone_clear_flag(z, ZONE_OOM_LOCKED);
The serialization is done with trylocks so this will never invoke the oom killer because all zones in the allocator's zonelist will be oom locked.
Why does this not work for you?
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
Quoted 6 lines · David Rientjes
Quoted 3 lines · Rafael J. Wysocki
OK, let's try with
__GFP_NO_OOM_KILLfirst. If there's too much disagreement, I'll use the freezer-based approach instead.
Quoted 6 lines
Third time I'm going to suggest this, and I'd like a response on why it's not possible instead of being ignored.
All of your tasks are in D state other than kthreads, right? That means they won't be in the oom killer (thus no zones are oom locked), so you can easily do this
Well, OOM killer may be running on behalf of some kthread at that point....? Quite unlikely, but possible AFAICT.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
Quoted 9 lines · Pavel Machek
Quoted 6 lines
Third time I'm going to suggest this, and I'd like a response on why it's not possible instead of being ignored.
All of your tasks are in D state other than kthreads, right? That means they won't be in the oom killer (thus no zones are oom locked), so you can easily do this
Well, OOM killer may be running on behalf of some kthread at that point....? Quite unlikely, but possible AFAICT.
The oom killer doesn't care about the task's state, so this will be a genuine oom situation where it will kill a task (one in D state since kthreads are inherently immune) which will die when unfrozen. That would have had to happen anyway when all tasks wake up since the system is completely out of memory (except for kswapd that is given access to memory reserves because of PF_MEMALLOC) so you're not worried about completely blocking out the oom killer anymore because the next kthread to invoke it in such a situation will end up being a no-op because it finds a task with TIF_MEMDIE set.
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
In reply to Pavel MachekQuoted 9 lines · Pavel Machek
Quoted 6 lines
Third time I'm going to suggest this, and I'd like a response on why it's not possible instead of being ignored.
All of your tasks are in D state other than kthreads, right? That means they won't be in the oom killer (thus no zones are oom locked), so you can easily do this
Well, OOM killer may be running on behalf of some kthread at that point....? Quite unlikely, but possible AFAICT.
The oom killer doesn't care about the task's state, so this will be a genuine oom situation where it will kill a task (one in D state since kthreads are inherently immune) which will die when unfrozen. That would have had to happen anyway when all tasks wake up since the system is completely out of memory (except for kswapd that is given access to memory reserves because of PF_MEMALLOC) so you're not worried about completely blocking out the oom killer anymore because the next kthread to invoke it in such a situation will end up being a no-op because it finds a task with TIF_MEMDIE set.
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
In reply to David RientjesQuoted 6 lines · David Rientjes
Quoted 3 lines · Rafael J. Wysocki
OK, let's try with
__GFP_NO_OOM_KILLfirst. If there's too much disagreement, I'll use the freezer-based approach instead.
Quoted 6 lines
Third time I'm going to suggest this, and I'd like a response on why it's not possible instead of being ignored.
All of your tasks are in D state other than kthreads, right? That means they won't be in the oom killer (thus no zones are oom locked), so you can easily do this
Well, OOM killer may be running on behalf of some kthread at that point....? Quite unlikely, but possible AFAICT.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
In reply to David RientjesQuoted 19 lines · David Rientjes
Quoted 3 lines · Rafael J. Wysocki
OK, let's try with
__GFP_NO_OOM_KILLfirst. If there's too much disagreement, I'll use the freezer-based approach instead.Third time I'm going to suggest this, and I'd like a response on why it's not possible instead of being ignored.
All of your tasks are in D state other than kthreads, right? That means they won't be in the oom killer (thus no zones are oom locked), so you can easily do this
struct zone *z; for_each_populated_zone(z) zone_set_flag(z, ZONE_OOM_LOCKED);and then
Quoted 7 lines
for_each_populated_zone(z) zone_clear_flag(z, ZONE_OOM_LOCKED);The serialization is done with trylocks so this will never invoke the oom killer because all zones in the allocator's zonelist will be oom locked.
Why does this not work for you?
Well, it might work too, but why are you insisting? How's it better than __GFP_NO_OOM_KILL, actually?
Andrew, what do you think about this?
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
Quoted 16 lines · Rafael J. Wysocki
Quoted 16 lines
Third time I'm going to suggest this, and I'd like a response on why it's not possible instead of being ignored.
All of your tasks are in D state other than kthreads, right? That means they won't be in the oom killer (thus no zones are oom locked), so you can easily do this
struct zone *z; for_each_populated_zone(z) zone_set_flag(z, ZONE_OOM_LOCKED);and then
for_each_populated_zone(z) zone_clear_flag(z, ZONE_OOM_LOCKED);
Quoted 8 lines
Quoted 4 lines
The serialization is done with trylocks so this will never invoke the oom killer because all zones in the allocator's zonelist will be oom locked.
Why does this not work for you?
Well, it might work too, but why are you insisting? How's it better than
__GFP_NO_OOM_KILL, actually?
Because I agree with Christoph's concerns about needlessly adding additional gfp flags; he was responding to the proposed addition of __GFP_PANIC which could be handled in other much simpler ways just like this flag can as I've shown.
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
In reply to Rafael J. WysockiQuoted 16 lines · Rafael J. Wysocki
Quoted 16 lines
Third time I'm going to suggest this, and I'd like a response on why it's not possible instead of being ignored.
All of your tasks are in D state other than kthreads, right? That means they won't be in the oom killer (thus no zones are oom locked), so you can easily do this
struct zone *z; for_each_populated_zone(z) zone_set_flag(z, ZONE_OOM_LOCKED);and then
for_each_populated_zone(z) zone_clear_flag(z, ZONE_OOM_LOCKED);
Quoted 8 lines
Quoted 4 lines
The serialization is done with trylocks so this will never invoke the oom killer because all zones in the allocator's zonelist will be oom locked.
Why does this not work for you?
Well, it might work too, but why are you insisting? How's it better than
__GFP_NO_OOM_KILL, actually?
Because I agree with Christoph's concerns about needlessly adding additional gfp flags; he was responding to the proposed addition of __GFP_PANIC which could be handled in other much simpler ways just like this flag can as I've shown.
Andrew Morton
maintainerRe: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
In reply to Rafael J. WysockiQuoted 26 lines · On Thu, 7 May 2009 22:38:13 +0200 "Rafael J. Wysocki"…
Quoted 25 lines · David Rientjes
Quoted 3 lines · Rafael J. Wysocki
OK, let's try with
__GFP_NO_OOM_KILLfirst. If there's too much disagreement, I'll use the freezer-based approach instead.Third time I'm going to suggest this, and I'd like a response on why it's not possible instead of being ignored.
All of your tasks are in D state other than kthreads, right? That means they won't be in the oom killer (thus no zones are oom locked), so you can easily do this
struct zone *z; for_each_populated_zone(z) zone_set_flag(z, ZONE_OOM_LOCKED);and then
for_each_populated_zone(z) zone_clear_flag(z, ZONE_OOM_LOCKED);The serialization is done with trylocks so this will never invoke the oom killer because all zones in the allocator's zonelist will be oom locked.
Quoted 6 lines
Quoted 1 line
Why does this not work for you?
Well, it might work too, but why are you insisting? How's it better than
__GFP_NO_OOM_KILL, actually?Andrew, what do you think about this?
I don't think I understand the proposal. Is it to provide a means by which PM can go in and set a state bit against each and every zone? If so, that's still a global boolean, only messier.
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
Quoted 18 lines · Andrew Morton
Quoted 18 lines
Quoted 17 lines
All of your tasks are in D state other than kthreads, right? That means they won't be in the oom killer (thus no zones are oom locked), so you can easily do this
struct zone *z; for_each_populated_zone(z) zone_set_flag(z, ZONE_OOM_LOCKED);and then
for_each_populated_zone(z) zone_clear_flag(z, ZONE_OOM_LOCKED);The serialization is done with trylocks so this will never invoke the oom killer because all zones in the allocator's zonelist will be oom locked.
Why does this not work for you?
Quoted 9 lines
Quoted 4 lines
Well, it might work too, but why are you insisting? How's it better than
__GFP_NO_OOM_KILL, actually?Andrew, what do you think about this?
I don't think I understand the proposal. Is it to provide a means by which PM can go in and set a state bit against each and every zone? If so, that's still a global boolean, only messier.
Why can't it be global while preallocating memory for hibernation since nothing but kthreads could allocate at this point and if the system is oom then the oom killer wouldn't be able to do anything anyway since it can't kill them?
The fact is that _all_ allocations here are implicitly __GFP_NO_OOM_KILL whether it specifies it or not since the oom killer would simply kill a task in D state which can't exit or free memory and subsequent allocations would make the oom killer a no-op because there's an eligible task with TIF_MEMDIE set. The only thing you're saving with __GFP_NO_OOM_KILL is calling the oom killer in a first place and killing an unresponsive task but that would have to happen anyway when thawed since the system is oom (or otherwise lockup for GFP_KERNEL with order < PAGE_ALLOC_COSTLY_ORDER).
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
Quoted 35 lines · David Rientjes
Quoted 18 lines · Andrew Morton
Quoted 18 lines
Quoted 17 lines
All of your tasks are in D state other than kthreads, right? That means they won't be in the oom killer (thus no zones are oom locked), so you can easily do this
struct zone *z; for_each_populated_zone(z) zone_set_flag(z, ZONE_OOM_LOCKED);and then
for_each_populated_zone(z) zone_clear_flag(z, ZONE_OOM_LOCKED);The serialization is done with trylocks so this will never invoke the oom killer because all zones in the allocator's zonelist will be oom locked.
Why does this not work for you?
Quoted 9 lines
Quoted 4 lines
Well, it might work too, but why are you insisting? How's it better than
__GFP_NO_OOM_KILL, actually?Andrew, what do you think about this?
I don't think I understand the proposal. Is it to provide a means by which PM can go in and set a state bit against each and every zone? If so, that's still a global boolean, only messier.
Why can't it be global while preallocating memory for hibernation since nothing but kthreads could allocate at this point and if the system is oom then the oom killer wouldn't be able to do anything anyway since it can't kill them?
Quoted 6 lines
The fact is that _all_ allocations here are implicitly
__GFP_NO_OOM_KILLwhether it specifies it or not since the oom killer would simply kill a task in D state which can't exit or free memory and subsequent allocations would make the oom killer a no-op because there's an eligible task withTIF_MEMDIEset. The only thing you're saving with__GFP_NO_OOM_KILLis calling the oom killer in a first place and killing an unresponsive task
That's exactly what we're trying to do. We don't want tasks to get killed just because we're freeing memory for hibernation image.
Quoted 2 lines
but that would have to happen anyway when thawed since the system is oom (or otherwise lockup for
GFP_KERNELwith order <PAGE_ALLOC_COSTLY_ORDER).
Are you sure? The image memory is freed before thawing tasks.
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
Quoted 10 lines · Rafael J. Wysocki
Quoted 6 lines
The fact is that _all_ allocations here are implicitly
__GFP_NO_OOM_KILLwhether it specifies it or not since the oom killer would simply kill a task in D state which can't exit or free memory and subsequent allocations would make the oom killer a no-op because there's an eligible task withTIF_MEMDIEset. The only thing you're saving with__GFP_NO_OOM_KILLis calling the oom killer in a first place and killing an unresponsive taskThat's exactly what we're trying to do. We don't want tasks to get killed just because we're freeing memory for hibernation image.
Then, again, why can't you just lock out the oom killer as I suggested if __GFP_NO_OOM_KILL is actually implied for all allocations when preallocating? It prevents adding an unnecessary gfp flag, sprinkling it around in the hibernation code, and a comment would actually explain why it's the right thing to do (i.e. no other threads other than kthreads could possibly be executing the oom killer and if they are oom then we'll have to kill a userspace task anyway when thawed).
Quoted 5 lines
Quoted 2 lines
but that would have to happen anyway when thawed since the system is oom (or otherwise lockup for
GFP_KERNELwith order <PAGE_ALLOC_COSTLY_ORDER).Are you sure? The image memory is freed before thawing tasks.
If you try to allocate any non-__GFP_NORETRY memory such as GFP_KERNEL with order < PAGE_ALLOC_COSTLY_ORDER and direct reclaim cannot free memory (and the oom killer is implicitly a no-op whether you specify __GFP_NO_OOM_KILL or not), then you could loop endlessly in the page allocator. When allocating GFP_IMAGE you need to ensure that can't happen and __GFP_NORETRY may not be your best option because it could fail unnecessarily when reclaim could have helped.
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
Quoted 9 lines · David Rientjes
Quoted 7 lines · Rafael J. Wysocki
Quoted 6 lines
The fact is that _all_ allocations here are implicitly
__GFP_NO_OOM_KILLwhether it specifies it or not since the oom killer would simply kill a task in D state which can't exit or free memory and subsequent allocations would make the oom killer a no-op because there's an eligible task withTIF_MEMDIEset. The only thing you're saving with__GFP_NO_OOM_KILLis calling the oom killer in a first place and killing an unresponsive task
Quoted 8 lines
Quoted 3 lines
That's exactly what we're trying to do. We don't want tasks to get killed just because we're freeing memory for hibernation image.
Then, again, why can't you just lock out the oom killer as I suggested if
__GFP_NO_OOM_KILLis actually implied for all allocations when preallocating? It prevents adding an unnecessary gfp flag, sprinkling it around in the hibernation code,
In one place really.
Quoted 4 lines
and a comment would actually explain why it's the right thing to do (i.e. no other threads other than kthreads could possibly be executing the oom killer and if they are oom then we'll have to kill a userspace task anyway when thawed).
Quite frankly, I prefer my freezer-based patch to this. I'm not really inclined to fiddle with the mm internals from within snapshot.c .
Still, I trust the Andrew's experience and that's why I'm going to try the __GFP_NO_OOM_KILL first, as I already said. If there is a problem with it, I'm going to use the freezer-based approach.
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines
but that would have to happen anyway when thawed since the system is oom (or otherwise lockup for
GFP_KERNELwith order <PAGE_ALLOC_COSTLY_ORDER).Are you sure? The image memory is freed before thawing tasks.
Quoted 7 lines
If you try to allocate any non-__GFP_NORETRY memory such as
GFP_KERNELwith order <PAGE_ALLOC_COSTLY_ORDERand direct reclaim cannot free memory (and the oom killer is implicitly a no-op whether you specify__GFP_NO_OOM_KILLor not), then you could loop endlessly in the page allocator. When allocatingGFP_IMAGEyou need to ensure that can't happen and__GFP_NORETRYmay not be your best option because it could fail unnecessarily when reclaim could have helped.
I'm really unsure what you mean and how that is related to your previous remark about what's going to happen after the thawing of tasks.
Thanks,
Rafael
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
In reply to David RientjesQuoted 9 lines · David Rientjes
Quoted 7 lines · Rafael J. Wysocki
Quoted 6 lines
The fact is that _all_ allocations here are implicitly
__GFP_NO_OOM_KILLwhether it specifies it or not since the oom killer would simply kill a task in D state which can't exit or free memory and subsequent allocations would make the oom killer a no-op because there's an eligible task withTIF_MEMDIEset. The only thing you're saving with__GFP_NO_OOM_KILLis calling the oom killer in a first place and killing an unresponsive task
Quoted 8 lines
Quoted 3 lines
That's exactly what we're trying to do. We don't want tasks to get killed just because we're freeing memory for hibernation image.
Then, again, why can't you just lock out the oom killer as I suggested if
__GFP_NO_OOM_KILLis actually implied for all allocations when preallocating? It prevents adding an unnecessary gfp flag, sprinkling it around in the hibernation code,
In one place really.
Quoted 4 lines
and a comment would actually explain why it's the right thing to do (i.e. no other threads other than kthreads could possibly be executing the oom killer and if they are oom then we'll have to kill a userspace task anyway when thawed).
Quite frankly, I prefer my freezer-based patch to this. I'm not really inclined to fiddle with the mm internals from within snapshot.c .
Still, I trust the Andrew's experience and that's why I'm going to try the __GFP_NO_OOM_KILL first, as I already said. If there is a problem with it, I'm going to use the freezer-based approach.
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines
but that would have to happen anyway when thawed since the system is oom (or otherwise lockup for
GFP_KERNELwith order <PAGE_ALLOC_COSTLY_ORDER).Are you sure? The image memory is freed before thawing tasks.
Quoted 7 lines
If you try to allocate any non-__GFP_NORETRY memory such as
GFP_KERNELwith order <PAGE_ALLOC_COSTLY_ORDERand direct reclaim cannot free memory (and the oom killer is implicitly a no-op whether you specify__GFP_NO_OOM_KILLor not), then you could loop endlessly in the page allocator. When allocatingGFP_IMAGEyou need to ensure that can't happen and__GFP_NORETRYmay not be your best option because it could fail unnecessarily when reclaim could have helped.
I'm really unsure what you mean and how that is related to your previous remark about what's going to happen after the thawing of tasks.
Thanks,
Rafael
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
In reply to Rafael J. WysockiQuoted 10 lines · Rafael J. Wysocki
Quoted 6 lines
The fact is that _all_ allocations here are implicitly
__GFP_NO_OOM_KILLwhether it specifies it or not since the oom killer would simply kill a task in D state which can't exit or free memory and subsequent allocations would make the oom killer a no-op because there's an eligible task withTIF_MEMDIEset. The only thing you're saving with__GFP_NO_OOM_KILLis calling the oom killer in a first place and killing an unresponsive taskThat's exactly what we're trying to do. We don't want tasks to get killed just because we're freeing memory for hibernation image.
Then, again, why can't you just lock out the oom killer as I suggested if __GFP_NO_OOM_KILL is actually implied for all allocations when preallocating? It prevents adding an unnecessary gfp flag, sprinkling it around in the hibernation code, and a comment would actually explain why it's the right thing to do (i.e. no other threads other than kthreads could possibly be executing the oom killer and if they are oom then we'll have to kill a userspace task anyway when thawed).
Quoted 5 lines
Quoted 2 lines
but that would have to happen anyway when thawed since the system is oom (or otherwise lockup for
GFP_KERNELwith order <PAGE_ALLOC_COSTLY_ORDER).Are you sure? The image memory is freed before thawing tasks.
If you try to allocate any non-__GFP_NORETRY memory such as GFP_KERNEL with order < PAGE_ALLOC_COSTLY_ORDER and direct reclaim cannot free memory (and the oom killer is implicitly a no-op whether you specify __GFP_NO_OOM_KILL or not), then you could loop endlessly in the page allocator. When allocating GFP_IMAGE you need to ensure that can't happen and __GFP_NORETRY may not be your best option because it could fail unnecessarily when reclaim could have helped.
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
In reply to David RientjesQuoted 35 lines · David Rientjes
Quoted 18 lines · Andrew Morton
Quoted 18 lines
Quoted 17 lines
All of your tasks are in D state other than kthreads, right? That means they won't be in the oom killer (thus no zones are oom locked), so you can easily do this
struct zone *z; for_each_populated_zone(z) zone_set_flag(z, ZONE_OOM_LOCKED);and then
for_each_populated_zone(z) zone_clear_flag(z, ZONE_OOM_LOCKED);The serialization is done with trylocks so this will never invoke the oom killer because all zones in the allocator's zonelist will be oom locked.
Why does this not work for you?
Quoted 9 lines
Quoted 4 lines
Well, it might work too, but why are you insisting? How's it better than
__GFP_NO_OOM_KILL, actually?Andrew, what do you think about this?
I don't think I understand the proposal. Is it to provide a means by which PM can go in and set a state bit against each and every zone? If so, that's still a global boolean, only messier.
Why can't it be global while preallocating memory for hibernation since nothing but kthreads could allocate at this point and if the system is oom then the oom killer wouldn't be able to do anything anyway since it can't kill them?
Quoted 6 lines
The fact is that _all_ allocations here are implicitly
__GFP_NO_OOM_KILLwhether it specifies it or not since the oom killer would simply kill a task in D state which can't exit or free memory and subsequent allocations would make the oom killer a no-op because there's an eligible task withTIF_MEMDIEset. The only thing you're saving with__GFP_NO_OOM_KILLis calling the oom killer in a first place and killing an unresponsive task
That's exactly what we're trying to do. We don't want tasks to get killed just because we're freeing memory for hibernation image.
Quoted 2 lines
but that would have to happen anyway when thawed since the system is oom (or otherwise lockup for
GFP_KERNELwith order <PAGE_ALLOC_COSTLY_ORDER).
Are you sure? The image memory is freed before thawing tasks.
Andrew Morton
maintainerRe: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
In reply to David RientjesQuoted 30 lines · On Thu, 7 May 2009 14:25:23 -0700 (PDT) David Rientjes…
Quoted 18 lines · Andrew Morton
Quoted 18 lines
Quoted 17 lines
All of your tasks are in D state other than kthreads, right? That means they won't be in the oom killer (thus no zones are oom locked), so you can easily do this
struct zone *z; for_each_populated_zone(z) zone_set_flag(z, ZONE_OOM_LOCKED);and then
for_each_populated_zone(z) zone_clear_flag(z, ZONE_OOM_LOCKED);The serialization is done with trylocks so this will never invoke the oom killer because all zones in the allocator's zonelist will be oom locked.
Why does this not work for you?
Quoted 9 lines
Quoted 4 lines
Well, it might work too, but why are you insisting? How's it better than
__GFP_NO_OOM_KILL, actually?Andrew, what do you think about this?
I don't think I understand the proposal. Is it to provide a means by which PM can go in and set a state bit against each and every zone? If so, that's still a global boolean, only messier.
Quoted 4 lines
Why can't it be global while preallocating memory for hibernation since nothing but kthreads could allocate at this point and if the system is oom then the oom killer wouldn't be able to do anything anyway since it can't kill them?
- globals are bad
- the standard way of controlling memory allocator behaviour is via the gfp_t. Bypassing that is an unusual step and needs a higher level of justification, which I'm not seeing here.
- if we do this via an unusual global, we reduce the chances that another subsytem could use the new feature.
I don't know what subsytem that might be, but I bet they're out there. checkpoint-restart, virtual machines, ballooning memory drivers, kexec loading, etc.
Quoted 8 lines
The fact is that _all_ allocations here are implicitly
__GFP_NO_OOM_KILLwhether it specifies it or not since the oom killer would simply kill a task in D state which can't exit or free memory and subsequent allocations would make the oom killer a no-op because there's an eligible task withTIF_MEMDIEset. The only thing you're saving with__GFP_NO_OOM_KILLis calling the oom killer in a first place and killing an unresponsive task but that would have to happen anyway when thawed since the system is oom (or otherwise lockup forGFP_KERNELwith order <PAGE_ALLOC_COSTLY_ORDER).
All the above is specific to the PM application only, when userspace tasks are stopped.
It might well end up that stopping userspace (beforehand or before oom-killing) is a hard requirement for reliably disabling the oom-killer. Because the __GFP_NO_OOM_KILL user will be safe, but random other allocations from other tasks will not be. So perhaps we _do_ need a global, and random userspace processes should test and sleep upon that global if they're heading in the direction of the oom-killer.
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
Quoted 60 lines · Andrew Morton
Quoted 30 lines · On Thu, 7 May 2009 14:25:23 -0700 (PDT) David Rientjes…
Quoted 18 lines · Andrew Morton
Quoted 18 lines
Quoted 17 lines
All of your tasks are in D state other than kthreads, right? That means they won't be in the oom killer (thus no zones are oom locked), so you can easily do this
struct zone *z; for_each_populated_zone(z) zone_set_flag(z, ZONE_OOM_LOCKED);and then
for_each_populated_zone(z) zone_clear_flag(z, ZONE_OOM_LOCKED);The serialization is done with trylocks so this will never invoke the oom killer because all zones in the allocator's zonelist will be oom locked.
Why does this not work for you?
Quoted 9 lines
Quoted 4 lines
Well, it might work too, but why are you insisting? How's it better than
__GFP_NO_OOM_KILL, actually?Andrew, what do you think about this?
I don't think I understand the proposal. Is it to provide a means by which PM can go in and set a state bit against each and every zone? If so, that's still a global boolean, only messier.
Quoted 4 lines
Why can't it be global while preallocating memory for hibernation since nothing but kthreads could allocate at this point and if the system is oom then the oom killer wouldn't be able to do anything anyway since it can't kill them?
- globals are bad
- the standard way of controlling memory allocator behaviour is via the
gfp_t. Bypassing that is an unusual step and needs a higher level of justification, which I'm not seeing here.- if we do this via an unusual global, we reduce the chances that another subsytem could use the new feature.
I don't know what subsytem that might be, but I bet they're out there. checkpoint-restart, virtual machines, ballooning memory drivers, kexec loading, etc.
Quoted 8 lines
The fact is that _all_ allocations here are implicitly
__GFP_NO_OOM_KILLwhether it specifies it or not since the oom killer would simply kill a task in D state which can't exit or free memory and subsequent allocations would make the oom killer a no-op because there's an eligible task withTIF_MEMDIEset. The only thing you're saving with__GFP_NO_OOM_KILLis calling the oom killer in a first place and killing an unresponsive task but that would have to happen anyway when thawed since the system is oom (or otherwise lockup forGFP_KERNELwith order <PAGE_ALLOC_COSTLY_ORDER).
Quoted 7 lines
All the above is specific to the PM application only, when userspace tasks are stopped.
It might well end up that stopping userspace (beforehand or before oom-killing) is a hard requirement for reliably disabling the oom-killer.
In fact I think it is and that's why I wanted to make that freezer-dependent.
IOW, you need to freeze the user space totally before trying to disable the OOM killer. Reversely, if you _have_ frozen the user space totally, the OOM killer won't really help, so why let it run at all in that situation?
FWIW, I've just posted updated patchset with the first patch replaced with the one introducing __GFP_NO_OOM_KILL, but perhaps I should use the freezer-based one after all?
Andrew Morton
maintainerRe: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
Quoted 2 lines · On Fri, 8 May 2009 00:14:48 +0200 "Rafael J. Wysocki" <[email protected]> wrote:
IOW, you need to freeze the user space totally before trying to disable the OOM killer.
Not necessarily. We only need to take action if a task is about to start oom-killing - presumably by taking a nap.
If a process is sitting there happily computing pi then we can leave it running.
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
Quoted 11 lines · Andrew Morton
Quoted 2 lines · On Fri, 8 May 2009 00:14:48 +0200 "Rafael J. Wysocki" <[email protected]> wrote:
IOW, you need to freeze the user space totally before trying to disable the OOM killer.
Not necessarily. We only need to take action if a task is about to start oom-killing - presumably by taking a nap.
If a process is sitting there happily computing pi then we can leave it running.
Well, the point is we don't really know what the task is going to do next. Is it going to continue computing pi, or is it going to execl(huge_binary), for example?
If we knew what tasks were going to do in advance, the whole freezing wouldn't really be necessary. :-)
Andrew Morton
maintainerRe: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
Quoted 13 lines · On Fri, 8 May 2009 00:50:41 +0200 "Rafael J. Wysocki"…
Quoted 11 lines · Andrew Morton
Quoted 2 lines · On Fri, 8 May 2009 00:14:48 +0200 "Rafael J. Wysocki"…
IOW, you need to freeze the user space totally before trying to disable the OOM killer.
Not necessarily. We only need to take action if a task is about to start oom-killing - presumably by taking a nap.
If a process is sitting there happily computing pi then we can leave it running.
Quoted 6 lines
Well, the point is we don't really know what the task is going to do next. Is it going to continue computing pi, or is it going to
execl(huge_binary), for example?If we knew what tasks were going to do in advance, the whole freezing wouldn't really be necessary. :-)
argh. Third time:
- if the task is computing pi, let it do so.
- if the task tries to allocate memory and succeeds, let it proceed.
- if the task tries to allocate memory and fails and then tries to invoke the oom-killer, stop the task.
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
Quoted 23 lines · Andrew Morton
Quoted 13 lines · On Fri, 8 May 2009 00:50:41 +0200 "Rafael J. Wysocki"…
Quoted 11 lines · Andrew Morton
Quoted 2 lines · On Fri, 8 May 2009 00:14:48 +0200 "Rafael J. Wysocki"…
IOW, you need to freeze the user space totally before trying to disable the OOM killer.
Not necessarily. We only need to take action if a task is about to start oom-killing - presumably by taking a nap.
If a process is sitting there happily computing pi then we can leave it running.
Quoted 6 lines
Well, the point is we don't really know what the task is going to do next. Is it going to continue computing pi, or is it going to
execl(huge_binary), for example?If we knew what tasks were going to do in advance, the whole freezing wouldn't really be necessary. :-)
Quoted 8 lines
argh. Third time:
- if the task is computing pi, let it do so.
- if the task tries to allocate memory and succeeds, let it proceed.
- if the task tries to allocate memory and fails and then tries to invoke the oom-killer, stop the task.
Understood.
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
In reply to Andrew MortonQuoted 23 lines · Andrew Morton
Quoted 13 lines · On Fri, 8 May 2009 00:50:41 +0200 "Rafael J. Wysocki" <[email protected]> wrote:
Quoted 11 lines · Andrew Morton
Quoted 2 lines · On Fri, 8 May 2009 00:14:48 +0200 "Rafael J. Wysocki" <[email protected]> wrote:
IOW, you need to freeze the user space totally before trying to disable the OOM killer.
Not necessarily. We only need to take action if a task is about to start oom-killing - presumably by taking a nap.
If a process is sitting there happily computing pi then we can leave it running.
Quoted 6 lines
Well, the point is we don't really know what the task is going to do next. Is it going to continue computing pi, or is it going to
execl(huge_binary), for example?If we knew what tasks were going to do in advance, the whole freezing wouldn't really be necessary. :-)
Quoted 8 lines
argh. Third time:
- if the task is computing pi, let it do so.
- if the task tries to allocate memory and succeeds, let it proceed.
- if the task tries to allocate memory and fails and then tries to invoke the oom-killer, stop the task.
Understood.
Andrew Morton
maintainerRe: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
In reply to Rafael J. WysockiQuoted 13 lines · On Fri, 8 May 2009 00:50:41 +0200 "Rafael J. Wysocki" <[email protected]> wrote:
Quoted 11 lines · Andrew Morton
Quoted 2 lines · On Fri, 8 May 2009 00:14:48 +0200 "Rafael J. Wysocki" <[email protected]> wrote:
IOW, you need to freeze the user space totally before trying to disable the OOM killer.
Not necessarily. We only need to take action if a task is about to start oom-killing - presumably by taking a nap.
If a process is sitting there happily computing pi then we can leave it running.
Quoted 6 lines
Well, the point is we don't really know what the task is going to do next. Is it going to continue computing pi, or is it going to
execl(huge_binary), for example?If we knew what tasks were going to do in advance, the whole freezing wouldn't really be necessary. :-)
argh. Third time:
- if the task is computing pi, let it do so.
- if the task tries to allocate memory and succeeds, let it proceed.
- if the task tries to allocate memory and fails and then tries to invoke the oom-killer, stop the task.
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
In reply to Andrew MortonQuoted 11 lines · Andrew Morton
Quoted 2 lines · On Fri, 8 May 2009 00:14:48 +0200 "Rafael J. Wysocki" <[email protected]> wrote:
IOW, you need to freeze the user space totally before trying to disable the OOM killer.
Not necessarily. We only need to take action if a task is about to start oom-killing - presumably by taking a nap.
If a process is sitting there happily computing pi then we can leave it running.
Well, the point is we don't really know what the task is going to do next. Is it going to continue computing pi, or is it going to execl(huge_binary), for example?
If we knew what tasks were going to do in advance, the whole freezing wouldn't really be necessary. :-)
Andrew Morton
maintainerRe: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
In reply to Rafael J. WysockiQuoted 2 lines · On Fri, 8 May 2009 00:14:48 +0200 "Rafael J. Wysocki" <[email protected]> wrote:
IOW, you need to freeze the user space totally before trying to disable the OOM killer.
Not necessarily. We only need to take action if a task is about to start oom-killing - presumably by taking a nap.
If a process is sitting there happily computing pi then we can leave it running.
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
In reply to Andrew MortonQuoted 60 lines · Andrew Morton
Quoted 30 lines · On Thu, 7 May 2009 14:25:23 -0700 (PDT) David Rientjes <[email protected]>…
Quoted 18 lines · Andrew Morton
Quoted 18 lines
Quoted 17 lines
All of your tasks are in D state other than kthreads, right? That means they won't be in the oom killer (thus no zones are oom locked), so you can easily do this
struct zone *z; for_each_populated_zone(z) zone_set_flag(z, ZONE_OOM_LOCKED);and then
for_each_populated_zone(z) zone_clear_flag(z, ZONE_OOM_LOCKED);The serialization is done with trylocks so this will never invoke the oom killer because all zones in the allocator's zonelist will be oom locked.
Why does this not work for you?
Quoted 9 lines
Quoted 4 lines
Well, it might work too, but why are you insisting? How's it better than
__GFP_NO_OOM_KILL, actually?Andrew, what do you think about this?
I don't think I understand the proposal. Is it to provide a means by which PM can go in and set a state bit against each and every zone? If so, that's still a global boolean, only messier.
Quoted 4 lines
Why can't it be global while preallocating memory for hibernation since nothing but kthreads could allocate at this point and if the system is oom then the oom killer wouldn't be able to do anything anyway since it can't kill them?
- globals are bad
- the standard way of controlling memory allocator behaviour is via the
gfp_t. Bypassing that is an unusual step and needs a higher level of justification, which I'm not seeing here.- if we do this via an unusual global, we reduce the chances that another subsytem could use the new feature.
I don't know what subsytem that might be, but I bet they're out there. checkpoint-restart, virtual machines, ballooning memory drivers, kexec loading, etc.
Quoted 8 lines
The fact is that _all_ allocations here are implicitly
__GFP_NO_OOM_KILLwhether it specifies it or not since the oom killer would simply kill a task in D state which can't exit or free memory and subsequent allocations would make the oom killer a no-op because there's an eligible task withTIF_MEMDIEset. The only thing you're saving with__GFP_NO_OOM_KILLis calling the oom killer in a first place and killing an unresponsive task but that would have to happen anyway when thawed since the system is oom (or otherwise lockup forGFP_KERNELwith order <PAGE_ALLOC_COSTLY_ORDER).
Quoted 7 lines
All the above is specific to the PM application only, when userspace tasks are stopped.
It might well end up that stopping userspace (beforehand or before oom-killing) is a hard requirement for reliably disabling the oom-killer.
In fact I think it is and that's why I wanted to make that freezer-dependent.
IOW, you need to freeze the user space totally before trying to disable the OOM killer. Reversely, if you _have_ frozen the user space totally, the OOM killer won't really help, so why let it run at all in that situation?
FWIW, I've just posted updated patchset with the first patch replaced with the one introducing __GFP_NO_OOM_KILL, but perhaps I should use the freezer-based one after all?
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
In reply to Andrew MortonQuoted 4 lines · Andrew Morton
- the standard way of controlling memory allocator behaviour is via the
gfp_t. Bypassing that is an unusual step and needs a higher level of justification, which I'm not seeing here.
The standard way of controlling the oom killer behavior for a zone is via the ZONE_OOM_LOCKED bit.
Quoted 7 lines
- if we do this via an unusual global, we reduce the chances that another subsytem could use the new feature.
I don't know what subsytem that might be, but I bet they're out there. checkpoint-restart, virtual machines, ballooning memory drivers, kexec loading, etc.
There's two separate issues here: the use of ZONE_OOM_LOCKED to control whether or not to invoke the oom killer for a specific zone (which is already its only function), and the fact that in this case we're doing it for all zones. It seems like you're concerned with the latter, but the distinction in the hibernation case is that no memory freeing would be possible as the result of the oom killer for _all_ zones, so it makes sense to lock them all out.
Quoted 9 lines
Quoted 8 lines
The fact is that _all_ allocations here are implicitly
__GFP_NO_OOM_KILLwhether it specifies it or not since the oom killer would simply kill a task in D state which can't exit or free memory and subsequent allocations would make the oom killer a no-op because there's an eligible task withTIF_MEMDIEset. The only thing you're saving with__GFP_NO_OOM_KILLis calling the oom killer in a first place and killing an unresponsive task but that would have to happen anyway when thawed since the system is oom (or otherwise lockup forGFP_KERNELwith order <PAGE_ALLOC_COSTLY_ORDER).
Quoted 3 lines
All the above is specific to the PM application only, when userspace tasks are stopped.
I'm not arguing that the only way we can ever implement __GFP_NO_OOM_KILL is for the entire system: we can set ZONE_OOM_LOCKED for only the zones in the zonelist that are passed to the page allocator. For this particular purpose, that is naturally all zones; for other future use cases it may be chosen only to lock out the zones we're allowed to allocate from in that context.
Quoted 3 lines
It might well end up that stopping userspace (beforehand or before oom-killing) is a hard requirement for reliably disabling the oom-killer.
Yes, globally, but future use cases may disable only specific zones such as with memory hot-remove.
Andrew Morton
maintainerRe: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
Quoted 9 lines · On Thu, 7 May 2009 15:16:17 -0700 (PDT) David Rientjes…
Quoted 4 lines · Andrew Morton
- the standard way of controlling memory allocator behaviour is via the
gfp_t. Bypassing that is an unusual step and needs a higher level of justification, which I'm not seeing here.The standard way of controlling the oom killer behavior for a zone is via the
ZONE_OOM_LOCKEDbit.
oop, I didn't remember/realise that ZONE_OOM_LOCKED already exists.
Quoted 8 lines
Quoted 7 lines
- if we do this via an unusual global, we reduce the chances that another subsytem could use the new feature.
I don't know what subsytem that might be, but I bet they're out there. checkpoint-restart, virtual machines, ballooning memory drivers, kexec loading, etc.
Quoted 7 lines
There's two separate issues here: the use of
ZONE_OOM_LOCKEDto control whether or not to invoke the oom killer for a specific zone (which is already its only function), and the fact that in this case we're doing it for all zones. It seems like you're concerned with the latter, but the distinction in the hibernation case is that no memory freeing would be possible as the result of the oom killer for _all_ zones, so it makes sense to lock them all out.
OK.
Quoted 13 lines
Quoted 9 lines
Quoted 8 lines
The fact is that _all_ allocations here are implicitly
__GFP_NO_OOM_KILLwhether it specifies it or not since the oom killer would simply kill a task in D state which can't exit or free memory and subsequent allocations would make the oom killer a no-op because there's an eligible task withTIF_MEMDIEset. The only thing you're saving with__GFP_NO_OOM_KILLis calling the oom killer in a first place and killing an unresponsive task but that would have to happen anyway when thawed since the system is oom (or otherwise lockup forGFP_KERNELwith order <PAGE_ALLOC_COSTLY_ORDER).Quoted 3 lines
All the above is specific to the PM application only, when userspace tasks are stopped.
Quoted 6 lines
I'm not arguing that the only way we can ever implement
__GFP_NO_OOM_KILLis for the entire system: we can setZONE_OOM_LOCKEDfor only the zones in the zonelist that are passed to the page allocator. For this particular purpose, that is naturally all zones; for other future use cases it may be chosen only to lock out the zones we're allowed to allocate from in that context.
OK.
Quoted 6 lines
Quoted 3 lines
It might well end up that stopping userspace (beforehand or before oom-killing) is a hard requirement for reliably disabling the oom-killer.
Yes, globally, but future use cases may disable only specific zones such as with memory hot-remove.
<goes off to find out what ZONE_OOM_LOCKED does>
That took remarkably longer than one would have expected..
Yes, OK, I agree, globally setting ZONE_OOM_LOCKED would produce a decent result.
The setting and clearing of that thing looks gruesomely racy..
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
Quoted 2 lines · Andrew Morton
The setting and clearing of that thing looks gruesomely racy..
It's not racy currently because zone_scan_lock ensures ZONE_OOM_LOCKED gets test/set and cleared atomically for the entire zonelist (the clear happens for the same zonelist that was test/set).
Using it for hibernation in the way I've proposed will open it up to the race I earlier described: when a kthread is in the oom killer and subsequently clears its zonelist of ZONE_OOM_LOCKED (all other tasks are frozen so they can't be in the oom killer). That's perfectly acceptable, however, since the system is by definition already oom if kthreads can't get memory so it will end up killing a user task even though it's stuck in D state and will exit on thaw; we aren't concerned about killing needlessly because the oom killer becomes a no-op when it finds a task that has already been killed but hasn't exited by way of TIF_MEMDIE.
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
Quoted 9 lines · David Rientjes
Quoted 2 lines · Andrew Morton
The setting and clearing of that thing looks gruesomely racy..
It's not racy currently because
zone_scan_lockensuresZONE_OOM_LOCKEDgets test/set and cleared atomically for the entire zonelist (the clear happens for the same zonelist that was test/set).
Quoted 9 lines
Using it for hibernation in the way I've proposed will open it up to the race I earlier described: when a kthread is in the oom killer and subsequently clears its zonelist of
ZONE_OOM_LOCKED(all other tasks are frozen so they can't be in the oom killer). That's perfectly acceptable, however, since the system is by definition already oom if kthreads can't get memory so it will end up killing a user task even though it's stuck in D state and will exit on thaw; we aren't concerned about killing needlessly because the oom killer becomes a no-op when it finds a task that has already been killed but hasn't exited by way ofTIF_MEMDIE.
OK there.
So everyone seems to agree we can do something like in the patch below?
---
From: Rafael J. Wysocki <[email protected]>
Subject: PM/Hibernate: Rework shrinking of memory
Rework swsusp_shrink_memory() so that it calls shrink_all_memory() just once to make some room for the image and then allocates memory to apply more pressure to the memory management subsystem, if necessary.
Unfortunately, we don't seem to be able to drop shrink_all_memory() entirely just yet, because that would lead to huge performance regressions in some test cases.
--- kernel/power/snapshot.c | 151 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 104 insertions(+), 47 deletions(-)
kernel/power/snapshot.c +104 -47
@@ -1066,69 +1066,126 @@ void swsusp_free(void) buffer =NULL ; } +/* Helper functions used for the shrinking of memory. */ +/** -* swsusp_shrink_memory - Try to free as much memory as needed -* -* ... but do not OOM-kill anyone +* preallocate_image_memory - Allocate given number of page frames +* @nr_pages: Number of page frames to allocate * -* Notice: all userland should be stopped before it is called, or -* livelock is possible. +* Return value: Number of page frames actually allocated */ - -#define SHRINK_BITE 10000 -static inline unsigned long __shrink_memory (long tmp) +static unsigned long preallocate_image_memory (unsigned long nr_pages) { -if (tmp >SHRINK_BITE ) - tmp =SHRINK_BITE ; -return shrink_all_memory (tmp); +unsigned long nr_alloc =0 ; + +while (nr_pages >0 ) { +if (!alloc_image_page (GFP_KERNEL | __GFP_NOWARN)) +break ; + nr_pages--; + nr_alloc++; + } + +return nr_alloc; } +/** +* swsusp_shrink_memory - Make the kernel release as much memory as needed +* +* To create a hibernation image it is necessary to make a copy of every page +* frame in use. We also need a number of page frames to be free during +* hibernation for allocations made while saving the image and for device +* drivers, in case they need to allocate memory from their hibernation +* callbacks (these two numbers are given by PAGES_FOR_IO and SPARE_PAGES, +* respectively, both of which are rough estimates). To make this happen, we +* compute the total number of available page frames and allocate at least +* +* ([page frames total] + PAGES_FOR_IO + [metadata pages]) / 2 + 2 * SPARE_PAGES +* +* of them, which corresponds to the maximum size of a hibernation image. +* +* If image_size is set below the number following from the above formula, +* the preallocation of memory is continued until the total number of page +* frames in use is below the requested image size or it is impossible to +* allocate more memory, whichever happens first. +*/ int swsusp_shrink_memory (void ) { -long tmp;struct zone *zone; -unsigned long pages =0 ; -unsigned int i =0 ; -char *p ="-\\|/" ; +unsigned long saveable, size, max_size, count, pages =0 ;struct timeval start, stop; +int error =0 ; -printk (KERN_INFO "PM: Shrinking memory... " ); +printk (KERN_INFO "PM: Shrinking memory ... " );do_gettimeofday (&start); -do { -long size, highmem_size; - highmem_size =count_highmem_pages (); - size =count_data_pages () +PAGES_FOR_IO +SPARE_PAGES ; - tmp = size; - size += highmem_size; -for_each_populated_zone (zone) { - tmp +=snapshot_additional_pages (zone); -if (is_highmem (zone)) { - highmem_size -= -zone_page_state (zone,NR_FREE_PAGES ); - }else { - tmp -=zone_page_state (zone,NR_FREE_PAGES ); - tmp += zone->lowmem_reserve[ZONE_NORMAL ]; - } - } +/* Count the number of saveable data pages. */ + saveable =count_data_pages () +count_highmem_pages (); -if (highmem_size <0 ) - highmem_size =0 ; +/* +* Compute the total number of page frames we can use (count) and the +* number of pages needed for image metadata (size). +*/ + count = saveable; + size =0 ; +for_each_populated_zone (zone) { + size +=snapshot_additional_pages (zone); + count +=zone_page_state (zone,NR_FREE_PAGES ); + count -= zone->pages_min; + } - tmp += highmem_size; -if (tmp >0 ) { - tmp =__shrink_memory (tmp); -if (!tmp) -return -ENOMEM ; - pages += tmp; - }else if (size > image_size /PAGE_SIZE ) { - tmp =__shrink_memory (size - (image_size /PAGE_SIZE )); - pages += tmp; - } -printk ("\b%c" , p[i++%4 ]); - }while (tmp >0 ); +/* Compute the maximum number of saveable pages to leave in memory. */ + max_size = (count - (size +PAGES_FOR_IO )) /2 -2 *SPARE_PAGES ; + size =DIV_ROUND_UP (image_size,PAGE_SIZE ); +if (size > max_size) + size = max_size; +/* +* If the maximum is not less than the current number of saveable pages +* in memory, we don't need to do anything more. +*/ +if (size >= saveable) + goto out; + +/* +* Let the memory management subsystem know that we're going to need a +* large number of page frames to allocate and make it free some memory. +* NOTE: If this is not done, performance is heavily affected in some +* test cases. +*/ +shrink_all_memory (saveable - size); + +/* +* Prevent the OOM killer from triggering while we're allocating image +* memory. +*/ +for_each_populated_zone (zone) +zone_set_flag (zone,ZONE_OOM_LOCKED ); +/* +* The number of saveable pages in memory was too high, so apply some +* pressure to decrease it. First, make room for the largest possible +* image and fail if that doesn't work. Next, try to decrease the size +* of the image as much as indicated by image_size. +*/ + count -= max_size; + pages =preallocate_image_memory (count); +if (pages < count) + error = -ENOMEM ; +else + pages +=preallocate_image_memory (max_size - size); + +for_each_populated_zone (zone) +zone_clear_flag (zone,ZONE_OOM_LOCKED ); + +/* Release all of the preallocated page frames. */ +swsusp_free (); + +if (error) { +printk (KERN_CONT "\n" ); +return error; + } + + out:do_gettimeofday (&stop); -printk ("\bdone (%lu pages freed)\n" , pages); +printk (KERN_CONT "done (preallocated %lu free pages)\n" , pages);swsusp_show_speed (&start, &stop, pages,"Freed" );return 0 ;
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
kernel/power/snapshot.c void swsusp_free(void) · line 1177
Quoted 6 lines · On Fri, 8 May 2009 01:11:30 +0200 "Rafael J. Wysocki"…
kernel/power/snapshot.c +5
-0+for_each_populated_zone (zone) +zone_set_flag (zone,ZONE_OOM_LOCKED ); +for_each_populated_zone (zone) +zone_clear_flag (zone,ZONE_OOM_LOCKED ); +
Isn't it better to make above 2 be functions and move to mm/oom_kill.c ?
Thanks,
-Kame
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
Quoted 11 lines · KAMEZAWA Hiroyuki
kernel/power/snapshot.c void swsusp_free(void) · line 1177
Quoted 6 lines · On Fri, 8 May 2009 01:11:30 +0200 "Rafael J. Wysocki"…
kernel/power/snapshot.c +5
-0+for_each_populated_zone (zone) +zone_set_flag (zone,ZONE_OOM_LOCKED ); +for_each_populated_zone (zone) +zone_clear_flag (zone,ZONE_OOM_LOCKED ); +Isn't it better to make above 2 be functions and move to
mm/oom_kill.c?
Hmm, OK. I'll do it.
Well, in fact snapshot.c is all about memory management, so perhaps it's a good idea to move it into mm as a whole. ;-)
Best,
Rafael
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
In reply to KAMEZAWA HiroyukiQuoted 11 lines · KAMEZAWA Hiroyuki
kernel/power/snapshot.c void swsusp_free(void) · line 1177
Quoted 6 lines · On Fri, 8 May 2009 01:11:30 +0200 "Rafael J. Wysocki" <[email protected]> wrote:
kernel/power/snapshot.c +5
-0+for_each_populated_zone (zone) +zone_set_flag (zone,ZONE_OOM_LOCKED ); +for_each_populated_zone (zone) +zone_clear_flag (zone,ZONE_OOM_LOCKED ); +Isn't it better to make above 2 be functions and move to
mm/oom_kill.c?
Hmm, OK. I'll do it.
Well, in fact snapshot.c is all about memory management, so perhaps it's a good idea to move it into mm as a whole. ;-)
Best,
Rafael
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
In reply to Rafael J. Wysockikernel/power/snapshot.c void swsusp_free(void) · line 1177
Quoted 6 lines · On Fri, 8 May 2009 01:11:30 +0200 "Rafael J. Wysocki" <[email protected]> wrote:
kernel/power/snapshot.c +5
-0+for_each_populated_zone (zone) +zone_set_flag (zone,ZONE_OOM_LOCKED ); +for_each_populated_zone (zone) +zone_clear_flag (zone,ZONE_OOM_LOCKED ); +
Isn't it better to make above 2 be functions and move to mm/oom_kill.c ?
Thanks,
-Kame
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
In reply to Rafael J. WysockiQuoted 24 lines · Rafael J. Wysocki
Quoted 9 lines · David Rientjes
Quoted 2 lines · Andrew Morton
The setting and clearing of that thing looks gruesomely racy..
It's not racy currently because
zone_scan_lockensuresZONE_OOM_LOCKEDgets test/set and cleared atomically for the entire zonelist (the clear happens for the same zonelist that was test/set).Quoted 9 lines
Using it for hibernation in the way I've proposed will open it up to the race I earlier described: when a kthread is in the oom killer and subsequently clears its zonelist of
ZONE_OOM_LOCKED(all other tasks are frozen so they can't be in the oom killer). That's perfectly acceptable, however, since the system is by definition already oom if kthreads can't get memory so it will end up killing a user task even though it's stuck in D state and will exit on thaw; we aren't concerned about killing needlessly because the oom killer becomes a no-op when it finds a task that has already been killed but hasn't exited by way ofTIF_MEMDIE.OK there.
So everyone seems to agree we can do something like in the patch below?
Quoted 8 lines
---
From: Rafael J. Wysocki <[email protected]>
Subject: PM/Hibernate: Rework shrinking of memoryRework
swsusp_shrink_memory()so that it callsshrink_all_memory()just once to make some room for the image and then allocates memory to apply more pressure to the memory management subsystem, if necessary.
Thanks! Reducing to single-pass helps memory bounty laptops considerably :)
Quoted 3 lines
Unfortunately, we don't seem to be able to drop
shrink_all_memory()entirely just yet, because that would lead to huge performance regressions in some test cases.
Yes, but it's not the fault of this patch. In fact some regressions may even be positive pressures to the page allocate/reclaim code ;)
Quoted 102 lines
Signed-off-by Rafael J. Wysocki <[email protected]>--- kernel/power/snapshot.c | 151 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 104 insertions(+), 47 deletions(-)Index:
linux-2.6/kernel/power/snapshot.c
===================================================================kernel/power/snapshot.c +41
-34@@ -1066,69 +1066,126 @@ void swsusp_free(void) buffer =NULL ; } +/* Helper functions used for the shrinking of memory. */ +/** -* swsusp_shrink_memory - Try to free as much memory as needed -* -* ... but do not OOM-kill anyone +* preallocate_image_memory - Allocate given number of page frames +* @nr_pages: Number of page frames to allocate * -* Notice: all userland should be stopped before it is called, or -* livelock is possible. +* Return value: Number of page frames actually allocated */ - -#define SHRINK_BITE 10000 -static inline unsigned long __shrink_memory (long tmp) +static unsigned long preallocate_image_memory (unsigned long nr_pages) { -if (tmp >SHRINK_BITE ) - tmp =SHRINK_BITE ; -return shrink_all_memory (tmp); +unsigned long nr_alloc =0 ; + +while (nr_pages >0 ) { +if (!alloc_image_page (GFP_KERNEL | __GFP_NOWARN)) +break ; + nr_pages--; + nr_alloc++; + } + +return nr_alloc; } +/** +* swsusp_shrink_memory - Make the kernel release as much memory as needed +* +* To create a hibernation image it is necessary to make a copy of every page +* frame in use. We also need a number of page frames to be free during +* hibernation for allocations made while saving the image and for device +* drivers, in case they need to allocate memory from their hibernation +* callbacks (these two numbers are given by PAGES_FOR_IO and SPARE_PAGES, +* respectively, both of which are rough estimates). To make this happen, we +* compute the total number of available page frames and allocate at least +* +* ([page frames total] + PAGES_FOR_IO + [metadata pages]) / 2 + 2 * SPARE_PAGES +* +* of them, which corresponds to the maximum size of a hibernation image. +* +* If image_size is set below the number following from the above formula, +* the preallocation of memory is continued until the total number of page +* frames in use is below the requested image size or it is impossible to +* allocate more memory, whichever happens first. +*/ int swsusp_shrink_memory (void ) { -long tmp;struct zone *zone; -unsigned long pages =0 ; -unsigned int i =0 ; -char *p ="-\\|/" ; +unsigned long saveable, size, max_size, count, pages =0 ;struct timeval start, stop; +int error =0 ; -printk (KERN_INFO "PM: Shrinking memory... " ); +printk (KERN_INFO "PM: Shrinking memory ... " );do_gettimeofday (&start); - do { - long size, highmem_size; - highmem_size = count_highmem_pages(); - size = count_data_pages() + PAGES_FOR_IO + SPARE_PAGES; - tmp = size; - size += highmem_size; - for_each_populated_zone(zone) { - tmp += snapshot_additional_pages(zone); - if (is_highmem(zone)) { - highmem_size -= - zone_page_state(zone, NR_FREE_PAGES); - } else { - tmp -= zone_page_state(zone, NR_FREE_PAGES); - tmp += zone->lowmem_reserve[ZONE_NORMAL]; - } - } +/* Count the number of saveable data pages. */ + saveable =count_data_pages () +count_highmem_pages (); - if (highmem_size < 0) - highmem_size = 0;
kernel/power/snapshot.c void swsusp_free(void) · line 1133
Quoted 10 lines
kernel/power/snapshot.c +10
-0+/* +* Compute the total number of page frames we can use (count) and the +* number of pages needed for image metadata (size). +*/ + count = saveable; + size =0 ; +for_each_populated_zone (zone) { + size +=snapshot_additional_pages (zone); + count +=zone_page_state (zone,NR_FREE_PAGES ); + count -= zone->pages_min;
I'd prefer to be more safe, by removing the above line...
kernel/power/snapshot.c void swsusp_free(void) · line 1134
Quoted 1 line
kernel/power/snapshot.c +1
-0+ }
...and add another line here:
count -= totalreserve_pages;
But hey, that 'count' counts "savable+free" memory.
We don't have a counter for an estimation of "free+freeable" memory, ie. we are sure we cannot preallocate above that threshold.
One applicable situation is, when there are 800M anonymous memory, but only 500M image_size and no swap space.
In that case we will otherwise goto the oom code path. Sure oom is (and shall be) reliably disabled in hibernation, but still we shall be cautious enough not to create a low memory situation, which will hurt:
- hibernation speed
(vmscan goes mad trying to squeeze the last free page)
- user experiences after resume
(all *active* file data and metadata have to reloaded)
The current code simply tries *too hard* to meet image_size. I'd rather take that as a mild advice, and to only free "free+freeable-margin" pages when image_size is not approachable.
The safety margin can be totalreserve_pages, plus enough pages for retaining the "hard core working set".
Thanks,
Fengguang
Quoted 69 lines
kernel/power/snapshot.c +52
-13- tmp += highmem_size; -if (tmp >0 ) { - tmp =__shrink_memory (tmp); -if (!tmp) -return -ENOMEM ; - pages += tmp; - }else if (size > image_size /PAGE_SIZE ) { - tmp =__shrink_memory (size - (image_size /PAGE_SIZE )); - pages += tmp; - } -printk ("\b%c" , p[i++%4 ]); - }while (tmp >0 ); +/* Compute the maximum number of saveable pages to leave in memory. */ + max_size = (count - (size +PAGES_FOR_IO )) /2 -2 *SPARE_PAGES ; + size =DIV_ROUND_UP (image_size,PAGE_SIZE ); +if (size > max_size) + size = max_size; +/* +* If the maximum is not less than the current number of saveable pages +* in memory, we don't need to do anything more. +*/ +if (size >= saveable) + goto out; + +/* +* Let the memory management subsystem know that we're going to need a +* large number of page frames to allocate and make it free some memory. +* NOTE: If this is not done, performance is heavily affected in some +* test cases. +*/ +shrink_all_memory (saveable - size); + +/* +* Prevent the OOM killer from triggering while we're allocating image +* memory. +*/ +for_each_populated_zone (zone) +zone_set_flag (zone,ZONE_OOM_LOCKED ); +/* +* The number of saveable pages in memory was too high, so apply some +* pressure to decrease it. First, make room for the largest possible +* image and fail if that doesn't work. Next, try to decrease the size +* of the image as much as indicated by image_size. +*/ + count -= max_size; + pages =preallocate_image_memory (count); +if (pages < count) + error = -ENOMEM ; +else + pages +=preallocate_image_memory (max_size - size); + +for_each_populated_zone (zone) +zone_clear_flag (zone,ZONE_OOM_LOCKED ); + +/* Release all of the preallocated page frames. */ +swsusp_free (); + +if (error) { +printk (KERN_CONT "\n" ); +return error; + } + + out:do_gettimeofday (&stop); -printk ("\bdone (%lu pages freed)\n" , pages); +printk (KERN_CONT "done (preallocated %lu free pages)\n" , pages);swsusp_show_speed (&start, &stop, pages,"Freed" );return 0 ;
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
Quoted 158 lines · Wu Fengguang
Quoted 24 lines · Rafael J. Wysocki
Quoted 9 lines · David Rientjes
Quoted 2 lines · Andrew Morton
The setting and clearing of that thing looks gruesomely racy..
It's not racy currently because
zone_scan_lockensuresZONE_OOM_LOCKEDgets test/set and cleared atomically for the entire zonelist (the clear happens for the same zonelist that was test/set).Quoted 9 lines
Using it for hibernation in the way I've proposed will open it up to the race I earlier described: when a kthread is in the oom killer and subsequently clears its zonelist of
ZONE_OOM_LOCKED(all other tasks are frozen so they can't be in the oom killer). That's perfectly acceptable, however, since the system is by definition already oom if kthreads can't get memory so it will end up killing a user task even though it's stuck in D state and will exit on thaw; we aren't concerned about killing needlessly because the oom killer becomes a no-op when it finds a task that has already been killed but hasn't exited by way ofTIF_MEMDIE.OK there.
So everyone seems to agree we can do something like in the patch below?
Quoted 8 lines
---
From: Rafael J. Wysocki <[email protected]>
Subject: PM/Hibernate: Rework shrinking of memoryRework
swsusp_shrink_memory()so that it callsshrink_all_memory()just once to make some room for the image and then allocates memory to apply more pressure to the memory management subsystem, if necessary.Thanks! Reducing to single-pass helps memory bounty laptops considerably :)
Quoted 3 lines
Unfortunately, we don't seem to be able to drop
shrink_all_memory()entirely just yet, because that would lead to huge performance regressions in some test cases.Yes, but it's not the fault of this patch. In fact some regressions may even be positive pressures to the page allocate/reclaim code ;)
Quoted 102 lines
Signed-off-by Rafael J. Wysocki <[email protected]>--- kernel/power/snapshot.c | 151 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 104 insertions(+), 47 deletions(-)Index:
linux-2.6/kernel/power/snapshot.c
===================================================================kernel/power/snapshot.c +41
-34@@ -1066,69 +1066,126 @@ void swsusp_free(void) buffer =NULL ; } +/* Helper functions used for the shrinking of memory. */ +/** -* swsusp_shrink_memory - Try to free as much memory as needed -* -* ... but do not OOM-kill anyone +* preallocate_image_memory - Allocate given number of page frames +* @nr_pages: Number of page frames to allocate * -* Notice: all userland should be stopped before it is called, or -* livelock is possible. +* Return value: Number of page frames actually allocated */ - -#define SHRINK_BITE 10000 -static inline unsigned long __shrink_memory (long tmp) +static unsigned long preallocate_image_memory (unsigned long nr_pages) { -if (tmp >SHRINK_BITE ) - tmp =SHRINK_BITE ; -return shrink_all_memory (tmp); +unsigned long nr_alloc =0 ; + +while (nr_pages >0 ) { +if (!alloc_image_page (GFP_KERNEL | __GFP_NOWARN)) +break ; + nr_pages--; + nr_alloc++; + } + +return nr_alloc; } +/** +* swsusp_shrink_memory - Make the kernel release as much memory as needed +* +* To create a hibernation image it is necessary to make a copy of every page +* frame in use. We also need a number of page frames to be free during +* hibernation for allocations made while saving the image and for device +* drivers, in case they need to allocate memory from their hibernation +* callbacks (these two numbers are given by PAGES_FOR_IO and SPARE_PAGES, +* respectively, both of which are rough estimates). To make this happen, we +* compute the total number of available page frames and allocate at least +* +* ([page frames total] + PAGES_FOR_IO + [metadata pages]) / 2 + 2 * SPARE_PAGES +* +* of them, which corresponds to the maximum size of a hibernation image. +* +* If image_size is set below the number following from the above formula, +* the preallocation of memory is continued until the total number of page +* frames in use is below the requested image size or it is impossible to +* allocate more memory, whichever happens first. +*/ int swsusp_shrink_memory (void ) { -long tmp;struct zone *zone; -unsigned long pages =0 ; -unsigned int i =0 ; -char *p ="-\\|/" ; +unsigned long saveable, size, max_size, count, pages =0 ;struct timeval start, stop; +int error =0 ; -printk (KERN_INFO "PM: Shrinking memory... " ); +printk (KERN_INFO "PM: Shrinking memory ... " );do_gettimeofday (&start); - do { - long size, highmem_size; - highmem_size = count_highmem_pages(); - size = count_data_pages() + PAGES_FOR_IO + SPARE_PAGES; - tmp = size; - size += highmem_size; - for_each_populated_zone(zone) { - tmp += snapshot_additional_pages(zone); - if (is_highmem(zone)) { - highmem_size -= - zone_page_state(zone, NR_FREE_PAGES); - } else { - tmp -= zone_page_state(zone, NR_FREE_PAGES); - tmp += zone->lowmem_reserve[ZONE_NORMAL]; - } - } +/* Count the number of saveable data pages. */ + saveable =count_data_pages () +count_highmem_pages (); - if (highmem_size < 0) - highmem_size = 0;kernel/power/snapshot.c void swsusp_free(void) · line 1133
Quoted 10 lines
kernel/power/snapshot.c +10
-0+/* +* Compute the total number of page frames we can use (count) and the +* number of pages needed for image metadata (size). +*/ + count = saveable; + size =0 ; +for_each_populated_zone (zone) { + size +=snapshot_additional_pages (zone); + count +=zone_page_state (zone,NR_FREE_PAGES ); + count -= zone->pages_min;I'd prefer to be more safe, by removing the above line...
Quoted 5 lines
kernel/power/snapshot.c void swsusp_free(void) · line 1134
Quoted 1 line
kernel/power/snapshot.c +1
-0+ }...and add another line here:
count -= totalreserve_pages;
OK
Quoted 7 lines
But hey, that 'count' counts "savable+free" memory.
We don't have a counter for an estimation of "free+freeable" memory, ie. we are sure we cannot preallocate above that threshold.One applicable situation is, when there are 800M anonymous memory, but only 500M
image_sizeand no swap space.
Quoted 7 lines
In that case we will otherwise goto the oom code path. Sure oom is (and shall be) reliably disabled in hibernation, but still we shall be cautious enough not to create a low memory situation, which will hurt:
- hibernation speed
(vmscan goes mad trying to squeeze the last free page)
- user experiences after resume
(all *active* file data and metadata have to reloaded)
Strangely enough, my recent testing with this patch doesn't confirm the theory. :-) Namely, I set image_size too low on purpose and it only caused preallocate_image_memory() to return NULL at one point and that was it.
It didn't even took too much time.
I'll carry out more testing to verify this observation.
Quoted 6 lines
The current code simply tries *too hard* to meet
image_size. I'd rather take that as a mild advice, and to only free "free+freeable-margin" pages whenimage_sizeis not approachable.The safety margin can be
totalreserve_pages, plus enough pages for retaining the "hard core working set".
How to compute the size of the "hard core working set", then?
Rafael
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
Quoted 1 line · Rafael J. Wysocki
On Friday 08 May 2009, Wu Fengguang wrote:
[--snip--]
Quoted 15 lines
Quoted 7 lines
But hey, that 'count' counts "savable+free" memory.
We don't have a counter for an estimation of "free+freeable" memory, ie. we are sure we cannot preallocate above that threshold.One applicable situation is, when there are 800M anonymous memory, but only 500M
image_sizeand no swap space.Quoted 7 lines
In that case we will otherwise goto the oom code path. Sure oom is (and shall be) reliably disabled in hibernation, but still we shall be cautious enough not to create a low memory situation, which will hurt:
- hibernation speed
(vmscan goes mad trying to squeeze the last free page)
- user experiences after resume
(all *active* file data and metadata have to reloaded)
Quoted 7 lines
Strangely enough, my recent testing with this patch doesn't confirm the theory. :-) Namely, I set
image_sizetoo low on purpose and it only causedpreallocate_image_memory()to return NULL at one point and that was it.It didn't even took too much time.
I'll carry out more testing to verify this observation.
I can confirm that even if image_size is below the minimum we can get, the second preallocate_image_memory() just returns after allocating fewer pages that it's been asked for (that's with the original __GFP_NO_OOM_KILL-based approach, as I wrote in the previous message in this thread) and nothing bad happens.
That may be because we freeze the mm kernel threads, but I've also tested without freezing them and it's still worked the same way.
Quoted 8 lines
Quoted 6 lines
The current code simply tries *too hard* to meet
image_size. I'd rather take that as a mild advice, and to only free "free+freeable-margin" pages whenimage_sizeis not approachable.The safety margin can be
totalreserve_pages, plus enough pages for retaining the "hard core working set".How to compute the size of the "hard core working set", then?
Well, I'm still interested in the answer here. ;-)
Best,
Rafael
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
Quoted 22 lines · Rafael J. Wysocki
Quoted 1 line · Rafael J. Wysocki
On Friday 08 May 2009, Wu Fengguang wrote:
[--snip--]
Quoted 19 lines
Quoted 7 lines
But hey, that 'count' counts "savable+free" memory.
We don't have a counter for an estimation of "free+freeable" memory, ie. we are sure we cannot preallocate above that threshold.One applicable situation is, when there are 800M anonymous memory, but only 500M
image_sizeand no swap space.Quoted 7 lines
In that case we will otherwise goto the oom code path. Sure oom is (and shall be) reliably disabled in hibernation, but still we shall be cautious enough not to create a low memory situation, which will hurt:
- hibernation speed
(vmscan goes mad trying to squeeze the last free page)
- user experiences after resume
(all *active* file data and metadata have to reloaded)Strangely enough, my recent testing with this patch doesn't confirm the theory. :-) Namely, I set
image_sizetoo low on purpose and it only causedpreallocate_image_memory()to return NULL at one point and that was it.
Quoted 5 lines
Quoted 3 lines
It didn't even took too much time.
I'll carry out more testing to verify this observation.
I can confirm that even if
image_sizeis below the minimum we can get,
Which minimum please?
Quoted 12 lines
the second
preallocate_image_memory()just returns after allocating fewer pages that it's been asked for (that's with the original __GFP_NO_OOM_KILL-based approach, as I wrote in the previous message in this thread) and nothing bad happens.That may be because we freeze the mm kernel threads, but I've also tested without freezing them and it's still worked the same way.
Quoted 4 lines
Quoted 4 lines
The current code simply tries *too hard* to meet
image_size. I'd rather take that as a mild advice, and to only free "free+freeable-margin" pages whenimage_sizeis not approachable.
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
The safety margin can be
totalreserve_pages, plus enough pages for retaining the "hard core working set".How to compute the size of the "hard core working set", then?
Well, I'm still interested in the answer here. ;-)
A tough question ;-)
We can start with the following formula, this should be called *after* the initial memory shrinking.
/* a typical desktop do not have more than 100MB mapped pages */ #define MAX_MMAP_PAGES (100 << (20 - PAGE_SHIFT)) unsigned long hard_core_working_set(void)
{
unsigned long nr;
/*
* mapped pages are normally small and precious,
* but shall be bounded for safety.
*/
nr = global_page_state(NR_FILE_MAPPED);
nr = min_t(unsigned long, nr, MAX_MMAP_PAGES);
/*
* if no swap space, this is a hard request;
* otherwise this is an optimization.
* (the disk image IO can be much faster than swap IO)
*/
nr += global_page_state(NR_ACTIVE_ANON);
nr += global_page_state(NR_INACTIVE_ANON);
/* hard (but normally small) memory requests */
nr += global_page_state(NR_SLAB_UNRECLAIMABLE);
nr += global_page_state(NR_UNEVICTABLE);
nr += global_page_state(NR_PAGETABLE);
return nr;
}Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
Quoted 23 lines · Wu Fengguang
Quoted 22 lines · Rafael J. Wysocki
Quoted 1 line · Rafael J. Wysocki
On Friday 08 May 2009, Wu Fengguang wrote:
[--snip--]
Quoted 19 lines
Quoted 7 lines
But hey, that 'count' counts "savable+free" memory.
We don't have a counter for an estimation of "free+freeable" memory, ie. we are sure we cannot preallocate above that threshold.One applicable situation is, when there are 800M anonymous memory, but only 500M
image_sizeand no swap space.Quoted 7 lines
In that case we will otherwise goto the oom code path. Sure oom is (and shall be) reliably disabled in hibernation, but still we shall be cautious enough not to create a low memory situation, which will hurt:
- hibernation speed
(vmscan goes mad trying to squeeze the last free page)
- user experiences after resume
(all *active* file data and metadata have to reloaded)Strangely enough, my recent testing with this patch doesn't confirm the theory. :-) Namely, I set
image_sizetoo low on purpose and it only causedpreallocate_image_memory()to return NULL at one point and that was it.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
It didn't even took too much time.
I'll carry out more testing to verify this observation.
I can confirm that even if
image_sizeis below the minimum we can get,Which minimum please?
That was supposed to be an alternative way of saying "below any reasonable value", but it wasn't very precise indeed.
I should have said that for given system there was a minimum number of saveable pages that hibernate_preallocate_memory() leaved in memory and it just couldn't go below that limit. If image_size is set below this number, the preallocate_image_memory(max_size - size) call returns fewer pages that it's been requested to allocate and that's it. No disasters, no anything wrong.
Quoted 15 lines
Quoted 15 lines
the second
preallocate_image_memory()just returns after allocating fewer pages that it's been asked for (that's with the original __GFP_NO_OOM_KILL-based approach, as I wrote in the previous message in this thread) and nothing bad happens.That may be because we freeze the mm kernel threads, but I've also tested without freezing them and it's still worked the same way.
Quoted 7 lines
Quoted 6 lines
The current code simply tries *too hard* to meet
image_size. I'd rather take that as a mild advice, and to only free "free+freeable-margin" pages whenimage_sizeis not approachable.The safety margin can be
totalreserve_pages, plus enough pages for retaining the "hard core working set".
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
How to compute the size of the "hard core working set", then?
Well, I'm still interested in the answer here. ;-)
A tough question ;-)
We can start with the following formula, this should be called *after* the initial memory shrinking.
OK
Quoted 17 lines
/* a typical desktop do not have more than 100MB mapped pages */ #define
MAX_MMAP_PAGES(100 << (20 -PAGE_SHIFT)) unsigned longhard_core_working_set(void){ unsigned long nr; /* * mapped pages are normally small and precious, * but shall be bounded for safety. */ nr = global_page_state(NR_FILE_MAPPED); nr = min_t(unsigned long, nr, MAX_MMAP_PAGES); /* * if no swap space, this is a hard request; * otherwise this is an optimization. * (the disk image IO can be much faster than swap IO)
Well, if there's no swap space at this point, we won't be able to save the image anyway, so this always is an optimization IMO. :-)
Quoted 11 lines
*/
nr += global_page_state(NR_ACTIVE_ANON);
nr += global_page_state(NR_INACTIVE_ANON);
/* hard (but normally small) memory requests */
nr += global_page_state(NR_SLAB_UNRECLAIMABLE);
nr += global_page_state(NR_UNEVICTABLE);
nr += global_page_state(NR_PAGETABLE);
return nr;
}OK, thanks.
I'll create a separate patch adding this function and we'll see how it works.
Best,
Rafael
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
Quoted 32 lines · Rafael J. Wysocki
Quoted 23 lines · Wu Fengguang
Quoted 22 lines · Rafael J. Wysocki
Quoted 1 line · Rafael J. Wysocki
On Friday 08 May 2009, Wu Fengguang wrote:
[--snip--]
Quoted 19 lines
Quoted 7 lines
But hey, that 'count' counts "savable+free" memory.
We don't have a counter for an estimation of "free+freeable" memory, ie. we are sure we cannot preallocate above that threshold.One applicable situation is, when there are 800M anonymous memory, but only 500M
image_sizeand no swap space.Quoted 7 lines
In that case we will otherwise goto the oom code path. Sure oom is (and shall be) reliably disabled in hibernation, but still we shall be cautious enough not to create a low memory situation, which will hurt:
- hibernation speed
(vmscan goes mad trying to squeeze the last free page)
- user experiences after resume
(all *active* file data and metadata have to reloaded)Strangely enough, my recent testing with this patch doesn't confirm the theory. :-) Namely, I set
image_sizetoo low on purpose and it only causedpreallocate_image_memory()to return NULL at one point and that was it.Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
It didn't even took too much time.
I'll carry out more testing to verify this observation.
I can confirm that even if
image_sizeis below the minimum we can get,Which minimum please?
Quoted 8 lines
That was supposed to be an alternative way of saying "below any reasonable value", but it wasn't very precise indeed.
I should have said that for given system there was a minimum number of saveable pages that
hibernate_preallocate_memory()leaved in memory and it just couldn't go below that limit. Ifimage_sizeis set below this number, thepreallocate_image_memory(max_size - size)call returns fewer pages that it's been requested to allocate and that's it. No disasters, no anything wrong.
"preallocate_image_memory(max_size - size) returning fewer pages" would better be avoided, and possibly can be avoided by checking hard_core_working_set(), right?
Quoted 39 lines
Quoted 15 lines
Quoted 15 lines
the second
preallocate_image_memory()just returns after allocating fewer pages that it's been asked for (that's with the original __GFP_NO_OOM_KILL-based approach, as I wrote in the previous message in this thread) and nothing bad happens.That may be because we freeze the mm kernel threads, but I've also tested without freezing them and it's still worked the same way.
Quoted 7 lines
Quoted 6 lines
The current code simply tries *too hard* to meet
image_size. I'd rather take that as a mild advice, and to only free "free+freeable-margin" pages whenimage_sizeis not approachable.The safety margin can be
totalreserve_pages, plus enough pages for retaining the "hard core working set".Quoted 8 lines
Quoted 3 lines
Quoted 1 line
How to compute the size of the "hard core working set", then?
Well, I'm still interested in the answer here. ;-)
A tough question ;-)
We can start with the following formula, this should be called *after* the initial memory shrinking.
OK
Quoted 13 lines
/* a typical desktop do not have more than 100MB mapped pages */ #define
MAX_MMAP_PAGES(100 << (20 -PAGE_SHIFT)) unsigned longhard_core_working_set(void){ unsigned long nr; /* * mapped pages are normally small and precious, * but shall be bounded for safety. */ nr = global_page_state(NR_FILE_MAPPED); nr = min_t(unsigned long, nr, MAX_MMAP_PAGES);
Quoted 7 lines
Quoted 4 lines
/*
* if no swap space, this is a hard request;
* otherwise this is an optimization.
* (the disk image IO can be much faster than swap IO)Well, if there's no swap space at this point, we won't be able to save the image anyway, so this always is an optimization IMO. :-)
Ah OK. Do you think the anonymous pages optimization should be limited?
My desktop normally consumes 200-400MB anonymous pages, but when some virtual machine is running, the anonymous pages can go beyond 1GB, with mapped file pages go slightly beyond 100MB.
The image-write vs. swapout-write speeds should be equal, however the hibernate tool may be able to compress the dataset.
The image-read will be much faster than swapin-read for *rotational* disks. It may take more time to resume, however the user experiences after completion will be much better.
I don't think "populating memory with useless data" would be a major concern, since we already freed up half of the total memory. It's all about the speed one can get back to work.
Quoted 10 lines
Quoted 10 lines
*/ nr += global_page_state(NR_ACTIVE_ANON); nr += global_page_state(NR_INACTIVE_ANON); /* hard (but normally small) memory requests */ nr += global_page_state(NR_SLAB_UNRECLAIMABLE); nr += global_page_state(NR_UNEVICTABLE); nr += global_page_state(NR_PAGETABLE);
Quoted 6 lines
Quoted 2 lines
return nr; }OK, thanks.
I'll create a separate patch adding this function and we'll see how it works.
OK, thanks!
btw, if the shrink_all_memory() functions cannot go away because of performance problems, I can help clean it up. (FYI: I happen to be doing so just before you submitted this patchset.:)
Thanks,
Fengguang
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
Quoted 42 lines · Wu Fengguang
Quoted 32 lines · Rafael J. Wysocki
Quoted 23 lines · Wu Fengguang
Quoted 22 lines · Rafael J. Wysocki
Quoted 1 line · Rafael J. Wysocki
On Friday 08 May 2009, Wu Fengguang wrote:
[--snip--]
Quoted 19 lines
Quoted 7 lines
But hey, that 'count' counts "savable+free" memory.
We don't have a counter for an estimation of "free+freeable" memory, ie. we are sure we cannot preallocate above that threshold.One applicable situation is, when there are 800M anonymous memory, but only 500M
image_sizeand no swap space.Quoted 7 lines
In that case we will otherwise goto the oom code path. Sure oom is (and shall be) reliably disabled in hibernation, but still we shall be cautious enough not to create a low memory situation, which will hurt:
- hibernation speed
(vmscan goes mad trying to squeeze the last free page)
- user experiences after resume
(all *active* file data and metadata have to reloaded)Strangely enough, my recent testing with this patch doesn't confirm the theory. :-) Namely, I set
image_sizetoo low on purpose and it only causedpreallocate_image_memory()to return NULL at one point and that was it.Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
It didn't even took too much time.
I'll carry out more testing to verify this observation.
I can confirm that even if
image_sizeis below the minimum we can get,Which minimum please?
Quoted 8 lines
That was supposed to be an alternative way of saying "below any reasonable value", but it wasn't very precise indeed.
I should have said that for given system there was a minimum number of saveable pages that
hibernate_preallocate_memory()leaved in memory and it just couldn't go below that limit. Ifimage_sizeis set below this number, thepreallocate_image_memory(max_size - size)call returns fewer pages that it's been requested to allocate and that's it. No disasters, no anything wrong.
Quoted 3 lines
"
preallocate_image_memory(max_size - size)returning fewer pages" would better be avoided, and possibly can be avoided by checkinghard_core_working_set(), right?
Yes, but your formula doesn't seem to be suitable for that, because the number it returns it too low.
On an x86_64 test box the minimum image size I can get (by setting image_size=1000) is about 24000 pages, while the formula for the hard core working set size returns about 12000, so it is not very useful.
On an i386 test box it's even worse, as the minimum image size I can get is about 48000 pages.
Besides, while testing this I noticed that on i386 preallocate_image_memory() didn't allocate from highmem, so I changed it to do so. As a result of this I had to change the patches, so I'm going to post the new patchset shortly.
Quoted 44 lines
Quoted 44 lines
Quoted 15 lines
Quoted 15 lines
the second
preallocate_image_memory()just returns after allocating fewer pages that it's been asked for (that's with the original __GFP_NO_OOM_KILL-based approach, as I wrote in the previous message in this thread) and nothing bad happens.That may be because we freeze the mm kernel threads, but I've also tested without freezing them and it's still worked the same way.
Quoted 7 lines
Quoted 6 lines
The current code simply tries *too hard* to meet
image_size. I'd rather take that as a mild advice, and to only free "free+freeable-margin" pages whenimage_sizeis not approachable.The safety margin can be
totalreserve_pages, plus enough pages for retaining the "hard core working set".Quoted 8 lines
Quoted 3 lines
Quoted 1 line
How to compute the size of the "hard core working set", then?
Well, I'm still interested in the answer here. ;-)
A tough question ;-)
We can start with the following formula, this should be called *after* the initial memory shrinking.
OK
Quoted 17 lines
/* a typical desktop do not have more than 100MB mapped pages */ #define
MAX_MMAP_PAGES(100 << (20 -PAGE_SHIFT)) unsigned longhard_core_working_set(void){ unsigned long nr; /* * mapped pages are normally small and precious, * but shall be bounded for safety. */ nr = global_page_state(NR_FILE_MAPPED); nr = min_t(unsigned long, nr, MAX_MMAP_PAGES); /* * if no swap space, this is a hard request; * otherwise this is an optimization. * (the disk image IO can be much faster than swap IO)
Quoted 4 lines
Quoted 2 lines
Well, if there's no swap space at this point, we won't be able to save the image anyway, so this always is an optimization IMO. :-)
Ah OK. Do you think the anonymous pages optimization should be limited?
That depends.
Quoted 2 lines
My desktop normally consumes 200-400MB anonymous pages, but when some virtual machine is running, the anonymous pages can go beyond 1GB,
That's too much IMO, so there should be a limit.
Quoted 3 lines
with mapped file pages go slightly beyond 100MB.
The image-write vs. swapout-write speeds should be equal,
They aren't, really. Image write is way faster, even without compression.
Quoted 1 line
however the hibernate tool may be able to compress the dataset.
Sure.
Quoted 3 lines
The image-read will be much faster than swapin-read for *rotational* disks. It may take more time to resume, however the user experiences after completion will be much better.
Agreed.
Quoted 3 lines
I don't think "populating memory with useless data" would be a major concern, since we already freed up half of the total memory. It's all about the speed one can get back to work.
Agreed again.
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
*/ nr += global_page_state(NR_ACTIVE_ANON); nr += global_page_state(NR_INACTIVE_ANON); /* hard (but normally small) memory requests */ nr += global_page_state(NR_SLAB_UNRECLAIMABLE); nr += global_page_state(NR_UNEVICTABLE); nr += global_page_state(NR_PAGETABLE);
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
return nr; }OK, thanks.
I'll create a separate patch adding this function and we'll see how it works.
OK, thanks!
Actually it doesn't work too well as I said above. Arguably that's because the number of anonymous pages was probably lower than average in my test cases, but I also think that our hard core working set formula should be suitable for all test cases.
Quoted 3 lines
btw, if the
shrink_all_memory()functions cannot go away because of performance problems, I can help clean it up. (FYI: I happen to be doing so just before you submitted this patchset.:)
That would be great, thanks a lot!
I'm going to post updated patchset in a while, let's move the discussion to the new thread.
Best,
Rafael
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
In reply to Wu FengguangQuoted 42 lines · Wu Fengguang
Quoted 32 lines · Rafael J. Wysocki
Quoted 23 lines · Wu Fengguang
Quoted 22 lines · Rafael J. Wysocki
Quoted 1 line · Rafael J. Wysocki
On Friday 08 May 2009, Wu Fengguang wrote:
[--snip--]
Quoted 19 lines
Quoted 7 lines
But hey, that 'count' counts "savable+free" memory.
We don't have a counter for an estimation of "free+freeable" memory, ie. we are sure we cannot preallocate above that threshold.One applicable situation is, when there are 800M anonymous memory, but only 500M
image_sizeand no swap space.Quoted 7 lines
In that case we will otherwise goto the oom code path. Sure oom is (and shall be) reliably disabled in hibernation, but still we shall be cautious enough not to create a low memory situation, which will hurt:
- hibernation speed
(vmscan goes mad trying to squeeze the last free page)
- user experiences after resume
(all *active* file data and metadata have to reloaded)Strangely enough, my recent testing with this patch doesn't confirm the theory. :-) Namely, I set
image_sizetoo low on purpose and it only causedpreallocate_image_memory()to return NULL at one point and that was it.Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
It didn't even took too much time.
I'll carry out more testing to verify this observation.
I can confirm that even if
image_sizeis below the minimum we can get,Which minimum please?
Quoted 8 lines
That was supposed to be an alternative way of saying "below any reasonable value", but it wasn't very precise indeed.
I should have said that for given system there was a minimum number of saveable pages that
hibernate_preallocate_memory()leaved in memory and it just couldn't go below that limit. Ifimage_sizeis set below this number, thepreallocate_image_memory(max_size - size)call returns fewer pages that it's been requested to allocate and that's it. No disasters, no anything wrong.
Quoted 3 lines
"
preallocate_image_memory(max_size - size)returning fewer pages" would better be avoided, and possibly can be avoided by checkinghard_core_working_set(), right?
Yes, but your formula doesn't seem to be suitable for that, because the number it returns it too low.
On an x86_64 test box the minimum image size I can get (by setting image_size=1000) is about 24000 pages, while the formula for the hard core working set size returns about 12000, so it is not very useful.
On an i386 test box it's even worse, as the minimum image size I can get is about 48000 pages.
Besides, while testing this I noticed that on i386 preallocate_image_memory() didn't allocate from highmem, so I changed it to do so. As a result of this I had to change the patches, so I'm going to post the new patchset shortly.
Quoted 44 lines
Quoted 44 lines
Quoted 15 lines
Quoted 15 lines
the second
preallocate_image_memory()just returns after allocating fewer pages that it's been asked for (that's with the original __GFP_NO_OOM_KILL-based approach, as I wrote in the previous message in this thread) and nothing bad happens.That may be because we freeze the mm kernel threads, but I've also tested without freezing them and it's still worked the same way.
Quoted 7 lines
Quoted 6 lines
The current code simply tries *too hard* to meet
image_size. I'd rather take that as a mild advice, and to only free "free+freeable-margin" pages whenimage_sizeis not approachable.The safety margin can be
totalreserve_pages, plus enough pages for retaining the "hard core working set".Quoted 8 lines
Quoted 3 lines
Quoted 1 line
How to compute the size of the "hard core working set", then?
Well, I'm still interested in the answer here. ;-)
A tough question ;-)
We can start with the following formula, this should be called *after* the initial memory shrinking.
OK
Quoted 17 lines
/* a typical desktop do not have more than 100MB mapped pages */ #define
MAX_MMAP_PAGES(100 << (20 -PAGE_SHIFT)) unsigned longhard_core_working_set(void){ unsigned long nr; /* * mapped pages are normally small and precious, * but shall be bounded for safety. */ nr = global_page_state(NR_FILE_MAPPED); nr = min_t(unsigned long, nr, MAX_MMAP_PAGES); /* * if no swap space, this is a hard request; * otherwise this is an optimization. * (the disk image IO can be much faster than swap IO)
Quoted 4 lines
Quoted 2 lines
Well, if there's no swap space at this point, we won't be able to save the image anyway, so this always is an optimization IMO. :-)
Ah OK. Do you think the anonymous pages optimization should be limited?
That depends.
Quoted 2 lines
My desktop normally consumes 200-400MB anonymous pages, but when some virtual machine is running, the anonymous pages can go beyond 1GB,
That's too much IMO, so there should be a limit.
Quoted 3 lines
with mapped file pages go slightly beyond 100MB.
The image-write vs. swapout-write speeds should be equal,
They aren't, really. Image write is way faster, even without compression.
Quoted 1 line
however the hibernate tool may be able to compress the dataset.
Sure.
Quoted 3 lines
The image-read will be much faster than swapin-read for *rotational* disks. It may take more time to resume, however the user experiences after completion will be much better.
Agreed.
Quoted 3 lines
I don't think "populating memory with useless data" would be a major concern, since we already freed up half of the total memory. It's all about the speed one can get back to work.
Agreed again.
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
*/ nr += global_page_state(NR_ACTIVE_ANON); nr += global_page_state(NR_INACTIVE_ANON); /* hard (but normally small) memory requests */ nr += global_page_state(NR_SLAB_UNRECLAIMABLE); nr += global_page_state(NR_UNEVICTABLE); nr += global_page_state(NR_PAGETABLE);
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
return nr; }OK, thanks.
I'll create a separate patch adding this function and we'll see how it works.
OK, thanks!
Actually it doesn't work too well as I said above. Arguably that's because the number of anonymous pages was probably lower than average in my test cases, but I also think that our hard core working set formula should be suitable for all test cases.
Quoted 3 lines
btw, if the
shrink_all_memory()functions cannot go away because of performance problems, I can help clean it up. (FYI: I happen to be doing so just before you submitted this patchset.:)
That would be great, thanks a lot!
I'm going to post updated patchset in a while, let's move the discussion to the new thread.
Best,
Rafael
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
In reply to Rafael J. WysockiQuoted 32 lines · Rafael J. Wysocki
Quoted 23 lines · Wu Fengguang
Quoted 22 lines · Rafael J. Wysocki
Quoted 1 line · Rafael J. Wysocki
On Friday 08 May 2009, Wu Fengguang wrote:
[--snip--]
Quoted 19 lines
Quoted 7 lines
But hey, that 'count' counts "savable+free" memory.
We don't have a counter for an estimation of "free+freeable" memory, ie. we are sure we cannot preallocate above that threshold.One applicable situation is, when there are 800M anonymous memory, but only 500M
image_sizeand no swap space.Quoted 7 lines
In that case we will otherwise goto the oom code path. Sure oom is (and shall be) reliably disabled in hibernation, but still we shall be cautious enough not to create a low memory situation, which will hurt:
- hibernation speed
(vmscan goes mad trying to squeeze the last free page)
- user experiences after resume
(all *active* file data and metadata have to reloaded)Strangely enough, my recent testing with this patch doesn't confirm the theory. :-) Namely, I set
image_sizetoo low on purpose and it only causedpreallocate_image_memory()to return NULL at one point and that was it.Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
It didn't even took too much time.
I'll carry out more testing to verify this observation.
I can confirm that even if
image_sizeis below the minimum we can get,Which minimum please?
Quoted 8 lines
That was supposed to be an alternative way of saying "below any reasonable value", but it wasn't very precise indeed.
I should have said that for given system there was a minimum number of saveable pages that
hibernate_preallocate_memory()leaved in memory and it just couldn't go below that limit. Ifimage_sizeis set below this number, thepreallocate_image_memory(max_size - size)call returns fewer pages that it's been requested to allocate and that's it. No disasters, no anything wrong.
"preallocate_image_memory(max_size - size) returning fewer pages" would better be avoided, and possibly can be avoided by checking hard_core_working_set(), right?
Quoted 39 lines
Quoted 15 lines
Quoted 15 lines
the second
preallocate_image_memory()just returns after allocating fewer pages that it's been asked for (that's with the original __GFP_NO_OOM_KILL-based approach, as I wrote in the previous message in this thread) and nothing bad happens.That may be because we freeze the mm kernel threads, but I've also tested without freezing them and it's still worked the same way.
Quoted 7 lines
Quoted 6 lines
The current code simply tries *too hard* to meet
image_size. I'd rather take that as a mild advice, and to only free "free+freeable-margin" pages whenimage_sizeis not approachable.The safety margin can be
totalreserve_pages, plus enough pages for retaining the "hard core working set".Quoted 8 lines
Quoted 3 lines
Quoted 1 line
How to compute the size of the "hard core working set", then?
Well, I'm still interested in the answer here. ;-)
A tough question ;-)
We can start with the following formula, this should be called *after* the initial memory shrinking.
OK
Quoted 13 lines
/* a typical desktop do not have more than 100MB mapped pages */ #define
MAX_MMAP_PAGES(100 << (20 -PAGE_SHIFT)) unsigned longhard_core_working_set(void){ unsigned long nr; /* * mapped pages are normally small and precious, * but shall be bounded for safety. */ nr = global_page_state(NR_FILE_MAPPED); nr = min_t(unsigned long, nr, MAX_MMAP_PAGES);
Quoted 7 lines
Quoted 4 lines
/*
* if no swap space, this is a hard request;
* otherwise this is an optimization.
* (the disk image IO can be much faster than swap IO)Well, if there's no swap space at this point, we won't be able to save the image anyway, so this always is an optimization IMO. :-)
Ah OK. Do you think the anonymous pages optimization should be limited?
My desktop normally consumes 200-400MB anonymous pages, but when some virtual machine is running, the anonymous pages can go beyond 1GB, with mapped file pages go slightly beyond 100MB.
The image-write vs. swapout-write speeds should be equal, however the hibernate tool may be able to compress the dataset.
The image-read will be much faster than swapin-read for *rotational* disks. It may take more time to resume, however the user experiences after completion will be much better.
I don't think "populating memory with useless data" would be a major concern, since we already freed up half of the total memory. It's all about the speed one can get back to work.
Quoted 10 lines
Quoted 10 lines
*/ nr += global_page_state(NR_ACTIVE_ANON); nr += global_page_state(NR_INACTIVE_ANON); /* hard (but normally small) memory requests */ nr += global_page_state(NR_SLAB_UNRECLAIMABLE); nr += global_page_state(NR_UNEVICTABLE); nr += global_page_state(NR_PAGETABLE);
Quoted 6 lines
Quoted 2 lines
return nr; }OK, thanks.
I'll create a separate patch adding this function and we'll see how it works.
OK, thanks!
btw, if the shrink_all_memory() functions cannot go away because of performance problems, I can help clean it up. (FYI: I happen to be doing so just before you submitted this patchset.:)
Thanks,
Fengguang
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
In reply to Wu FengguangQuoted 23 lines · Wu Fengguang
Quoted 22 lines · Rafael J. Wysocki
Quoted 1 line · Rafael J. Wysocki
On Friday 08 May 2009, Wu Fengguang wrote:
[--snip--]
Quoted 19 lines
Quoted 7 lines
But hey, that 'count' counts "savable+free" memory.
We don't have a counter for an estimation of "free+freeable" memory, ie. we are sure we cannot preallocate above that threshold.One applicable situation is, when there are 800M anonymous memory, but only 500M
image_sizeand no swap space.Quoted 7 lines
In that case we will otherwise goto the oom code path. Sure oom is (and shall be) reliably disabled in hibernation, but still we shall be cautious enough not to create a low memory situation, which will hurt:
- hibernation speed
(vmscan goes mad trying to squeeze the last free page)
- user experiences after resume
(all *active* file data and metadata have to reloaded)Strangely enough, my recent testing with this patch doesn't confirm the theory. :-) Namely, I set
image_sizetoo low on purpose and it only causedpreallocate_image_memory()to return NULL at one point and that was it.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
It didn't even took too much time.
I'll carry out more testing to verify this observation.
I can confirm that even if
image_sizeis below the minimum we can get,Which minimum please?
That was supposed to be an alternative way of saying "below any reasonable value", but it wasn't very precise indeed.
I should have said that for given system there was a minimum number of saveable pages that hibernate_preallocate_memory() leaved in memory and it just couldn't go below that limit. If image_size is set below this number, the preallocate_image_memory(max_size - size) call returns fewer pages that it's been requested to allocate and that's it. No disasters, no anything wrong.
Quoted 15 lines
Quoted 15 lines
the second
preallocate_image_memory()just returns after allocating fewer pages that it's been asked for (that's with the original __GFP_NO_OOM_KILL-based approach, as I wrote in the previous message in this thread) and nothing bad happens.That may be because we freeze the mm kernel threads, but I've also tested without freezing them and it's still worked the same way.
Quoted 7 lines
Quoted 6 lines
The current code simply tries *too hard* to meet
image_size. I'd rather take that as a mild advice, and to only free "free+freeable-margin" pages whenimage_sizeis not approachable.The safety margin can be
totalreserve_pages, plus enough pages for retaining the "hard core working set".
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
How to compute the size of the "hard core working set", then?
Well, I'm still interested in the answer here. ;-)
A tough question ;-)
We can start with the following formula, this should be called *after* the initial memory shrinking.
OK
Quoted 17 lines
/* a typical desktop do not have more than 100MB mapped pages */ #define
MAX_MMAP_PAGES(100 << (20 -PAGE_SHIFT)) unsigned longhard_core_working_set(void){ unsigned long nr; /* * mapped pages are normally small and precious, * but shall be bounded for safety. */ nr = global_page_state(NR_FILE_MAPPED); nr = min_t(unsigned long, nr, MAX_MMAP_PAGES); /* * if no swap space, this is a hard request; * otherwise this is an optimization. * (the disk image IO can be much faster than swap IO)
Well, if there's no swap space at this point, we won't be able to save the image anyway, so this always is an optimization IMO. :-)
Quoted 11 lines
*/
nr += global_page_state(NR_ACTIVE_ANON);
nr += global_page_state(NR_INACTIVE_ANON);
/* hard (but normally small) memory requests */
nr += global_page_state(NR_SLAB_UNRECLAIMABLE);
nr += global_page_state(NR_UNEVICTABLE);
nr += global_page_state(NR_PAGETABLE);
return nr;
}OK, thanks.
I'll create a separate patch adding this function and we'll see how it works.
Best,
Rafael
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
In reply to Rafael J. WysockiQuoted 22 lines · Rafael J. Wysocki
Quoted 1 line · Rafael J. Wysocki
On Friday 08 May 2009, Wu Fengguang wrote:
[--snip--]
Quoted 19 lines
Quoted 7 lines
But hey, that 'count' counts "savable+free" memory.
We don't have a counter for an estimation of "free+freeable" memory, ie. we are sure we cannot preallocate above that threshold.One applicable situation is, when there are 800M anonymous memory, but only 500M
image_sizeand no swap space.Quoted 7 lines
In that case we will otherwise goto the oom code path. Sure oom is (and shall be) reliably disabled in hibernation, but still we shall be cautious enough not to create a low memory situation, which will hurt:
- hibernation speed
(vmscan goes mad trying to squeeze the last free page)
- user experiences after resume
(all *active* file data and metadata have to reloaded)Strangely enough, my recent testing with this patch doesn't confirm the theory. :-) Namely, I set
image_sizetoo low on purpose and it only causedpreallocate_image_memory()to return NULL at one point and that was it.
Quoted 5 lines
Quoted 3 lines
It didn't even took too much time.
I'll carry out more testing to verify this observation.
I can confirm that even if
image_sizeis below the minimum we can get,
Which minimum please?
Quoted 12 lines
the second
preallocate_image_memory()just returns after allocating fewer pages that it's been asked for (that's with the original __GFP_NO_OOM_KILL-based approach, as I wrote in the previous message in this thread) and nothing bad happens.That may be because we freeze the mm kernel threads, but I've also tested without freezing them and it's still worked the same way.
Quoted 4 lines
Quoted 4 lines
The current code simply tries *too hard* to meet
image_size. I'd rather take that as a mild advice, and to only free "free+freeable-margin" pages whenimage_sizeis not approachable.
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
The safety margin can be
totalreserve_pages, plus enough pages for retaining the "hard core working set".How to compute the size of the "hard core working set", then?
Well, I'm still interested in the answer here. ;-)
A tough question ;-)
We can start with the following formula, this should be called *after* the initial memory shrinking.
/* a typical desktop do not have more than 100MB mapped pages */ #define MAX_MMAP_PAGES (100 << (20 - PAGE_SHIFT)) unsigned long hard_core_working_set(void)
{
unsigned long nr;
/*
* mapped pages are normally small and precious,
* but shall be bounded for safety.
*/
nr = global_page_state(NR_FILE_MAPPED);
nr = min_t(unsigned long, nr, MAX_MMAP_PAGES);
/*
* if no swap space, this is a hard request;
* otherwise this is an optimization.
* (the disk image IO can be much faster than swap IO)
*/
nr += global_page_state(NR_ACTIVE_ANON);
nr += global_page_state(NR_INACTIVE_ANON);
/* hard (but normally small) memory requests */
nr += global_page_state(NR_SLAB_UNRECLAIMABLE);
nr += global_page_state(NR_UNEVICTABLE);
nr += global_page_state(NR_PAGETABLE);
return nr;
}Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
In reply to Wu FengguangQuoted 158 lines · Wu Fengguang
Quoted 24 lines · Rafael J. Wysocki
Quoted 9 lines · David Rientjes
Quoted 2 lines · Andrew Morton
The setting and clearing of that thing looks gruesomely racy..
It's not racy currently because
zone_scan_lockensuresZONE_OOM_LOCKEDgets test/set and cleared atomically for the entire zonelist (the clear happens for the same zonelist that was test/set).Quoted 9 lines
Using it for hibernation in the way I've proposed will open it up to the race I earlier described: when a kthread is in the oom killer and subsequently clears its zonelist of
ZONE_OOM_LOCKED(all other tasks are frozen so they can't be in the oom killer). That's perfectly acceptable, however, since the system is by definition already oom if kthreads can't get memory so it will end up killing a user task even though it's stuck in D state and will exit on thaw; we aren't concerned about killing needlessly because the oom killer becomes a no-op when it finds a task that has already been killed but hasn't exited by way ofTIF_MEMDIE.OK there.
So everyone seems to agree we can do something like in the patch below?
Quoted 8 lines
---
From: Rafael J. Wysocki <[email protected]>
Subject: PM/Hibernate: Rework shrinking of memoryRework
swsusp_shrink_memory()so that it callsshrink_all_memory()just once to make some room for the image and then allocates memory to apply more pressure to the memory management subsystem, if necessary.Thanks! Reducing to single-pass helps memory bounty laptops considerably :)
Quoted 3 lines
Unfortunately, we don't seem to be able to drop
shrink_all_memory()entirely just yet, because that would lead to huge performance regressions in some test cases.Yes, but it's not the fault of this patch. In fact some regressions may even be positive pressures to the page allocate/reclaim code ;)
Quoted 102 lines
Signed-off-by Rafael J. Wysocki <[email protected]>--- kernel/power/snapshot.c | 151 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 104 insertions(+), 47 deletions(-)Index:
linux-2.6/kernel/power/snapshot.c
===================================================================kernel/power/snapshot.c +41
-34@@ -1066,69 +1066,126 @@ void swsusp_free(void) buffer =NULL ; } +/* Helper functions used for the shrinking of memory. */ +/** -* swsusp_shrink_memory - Try to free as much memory as needed -* -* ... but do not OOM-kill anyone +* preallocate_image_memory - Allocate given number of page frames +* @nr_pages: Number of page frames to allocate * -* Notice: all userland should be stopped before it is called, or -* livelock is possible. +* Return value: Number of page frames actually allocated */ - -#define SHRINK_BITE 10000 -static inline unsigned long __shrink_memory (long tmp) +static unsigned long preallocate_image_memory (unsigned long nr_pages) { -if (tmp >SHRINK_BITE ) - tmp =SHRINK_BITE ; -return shrink_all_memory (tmp); +unsigned long nr_alloc =0 ; + +while (nr_pages >0 ) { +if (!alloc_image_page (GFP_KERNEL | __GFP_NOWARN)) +break ; + nr_pages--; + nr_alloc++; + } + +return nr_alloc; } +/** +* swsusp_shrink_memory - Make the kernel release as much memory as needed +* +* To create a hibernation image it is necessary to make a copy of every page +* frame in use. We also need a number of page frames to be free during +* hibernation for allocations made while saving the image and for device +* drivers, in case they need to allocate memory from their hibernation +* callbacks (these two numbers are given by PAGES_FOR_IO and SPARE_PAGES, +* respectively, both of which are rough estimates). To make this happen, we +* compute the total number of available page frames and allocate at least +* +* ([page frames total] + PAGES_FOR_IO + [metadata pages]) / 2 + 2 * SPARE_PAGES +* +* of them, which corresponds to the maximum size of a hibernation image. +* +* If image_size is set below the number following from the above formula, +* the preallocation of memory is continued until the total number of page +* frames in use is below the requested image size or it is impossible to +* allocate more memory, whichever happens first. +*/ int swsusp_shrink_memory (void ) { -long tmp;struct zone *zone; -unsigned long pages =0 ; -unsigned int i =0 ; -char *p ="-\\|/" ; +unsigned long saveable, size, max_size, count, pages =0 ;struct timeval start, stop; +int error =0 ; -printk (KERN_INFO "PM: Shrinking memory... " ); +printk (KERN_INFO "PM: Shrinking memory ... " );do_gettimeofday (&start); - do { - long size, highmem_size; - highmem_size = count_highmem_pages(); - size = count_data_pages() + PAGES_FOR_IO + SPARE_PAGES; - tmp = size; - size += highmem_size; - for_each_populated_zone(zone) { - tmp += snapshot_additional_pages(zone); - if (is_highmem(zone)) { - highmem_size -= - zone_page_state(zone, NR_FREE_PAGES); - } else { - tmp -= zone_page_state(zone, NR_FREE_PAGES); - tmp += zone->lowmem_reserve[ZONE_NORMAL]; - } - } +/* Count the number of saveable data pages. */ + saveable =count_data_pages () +count_highmem_pages (); - if (highmem_size < 0) - highmem_size = 0;kernel/power/snapshot.c void swsusp_free(void) · line 1133
Quoted 10 lines
kernel/power/snapshot.c +10
-0+/* +* Compute the total number of page frames we can use (count) and the +* number of pages needed for image metadata (size). +*/ + count = saveable; + size =0 ; +for_each_populated_zone (zone) { + size +=snapshot_additional_pages (zone); + count +=zone_page_state (zone,NR_FREE_PAGES ); + count -= zone->pages_min;I'd prefer to be more safe, by removing the above line...
Quoted 5 lines
kernel/power/snapshot.c void swsusp_free(void) · line 1134
Quoted 1 line
kernel/power/snapshot.c +1
-0+ }...and add another line here:
count -= totalreserve_pages;
OK
Quoted 7 lines
But hey, that 'count' counts "savable+free" memory.
We don't have a counter for an estimation of "free+freeable" memory, ie. we are sure we cannot preallocate above that threshold.One applicable situation is, when there are 800M anonymous memory, but only 500M
image_sizeand no swap space.
Quoted 7 lines
In that case we will otherwise goto the oom code path. Sure oom is (and shall be) reliably disabled in hibernation, but still we shall be cautious enough not to create a low memory situation, which will hurt:
- hibernation speed
(vmscan goes mad trying to squeeze the last free page)
- user experiences after resume
(all *active* file data and metadata have to reloaded)
Strangely enough, my recent testing with this patch doesn't confirm the theory. :-) Namely, I set image_size too low on purpose and it only caused preallocate_image_memory() to return NULL at one point and that was it.
It didn't even took too much time.
I'll carry out more testing to verify this observation.
Quoted 6 lines
The current code simply tries *too hard* to meet
image_size. I'd rather take that as a mild advice, and to only free "free+freeable-margin" pages whenimage_sizeis not approachable.The safety margin can be
totalreserve_pages, plus enough pages for retaining the "hard core working set".
How to compute the size of the "hard core working set", then?
Rafael
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
In reply to Rafael J. WysockiQuoted 24 lines · Rafael J. Wysocki
Quoted 9 lines · David Rientjes
Quoted 2 lines · Andrew Morton
The setting and clearing of that thing looks gruesomely racy..
It's not racy currently because
zone_scan_lockensuresZONE_OOM_LOCKEDgets test/set and cleared atomically for the entire zonelist (the clear happens for the same zonelist that was test/set).Quoted 9 lines
Using it for hibernation in the way I've proposed will open it up to the race I earlier described: when a kthread is in the oom killer and subsequently clears its zonelist of
ZONE_OOM_LOCKED(all other tasks are frozen so they can't be in the oom killer). That's perfectly acceptable, however, since the system is by definition already oom if kthreads can't get memory so it will end up killing a user task even though it's stuck in D state and will exit on thaw; we aren't concerned about killing needlessly because the oom killer becomes a no-op when it finds a task that has already been killed but hasn't exited by way ofTIF_MEMDIE.OK there.
So everyone seems to agree we can do something like in the patch below?
Quoted 8 lines
---
From: Rafael J. Wysocki <[email protected]>
Subject: PM/Hibernate: Rework shrinking of memoryRework
swsusp_shrink_memory()so that it callsshrink_all_memory()just once to make some room for the image and then allocates memory to apply more pressure to the memory management subsystem, if necessary.
Thanks! Reducing to single-pass helps memory bounty laptops considerably :)
Quoted 3 lines
Unfortunately, we don't seem to be able to drop
shrink_all_memory()entirely just yet, because that would lead to huge performance regressions in some test cases.
Yes, but it's not the fault of this patch. In fact some regressions may even be positive pressures to the page allocate/reclaim code ;)
Quoted 102 lines
Signed-off-by Rafael J. Wysocki <[email protected]>--- kernel/power/snapshot.c | 151 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 104 insertions(+), 47 deletions(-)Index:
linux-2.6/kernel/power/snapshot.c
===================================================================kernel/power/snapshot.c +41
-34@@ -1066,69 +1066,126 @@ void swsusp_free(void) buffer =NULL ; } +/* Helper functions used for the shrinking of memory. */ +/** -* swsusp_shrink_memory - Try to free as much memory as needed -* -* ... but do not OOM-kill anyone +* preallocate_image_memory - Allocate given number of page frames +* @nr_pages: Number of page frames to allocate * -* Notice: all userland should be stopped before it is called, or -* livelock is possible. +* Return value: Number of page frames actually allocated */ - -#define SHRINK_BITE 10000 -static inline unsigned long __shrink_memory (long tmp) +static unsigned long preallocate_image_memory (unsigned long nr_pages) { -if (tmp >SHRINK_BITE ) - tmp =SHRINK_BITE ; -return shrink_all_memory (tmp); +unsigned long nr_alloc =0 ; + +while (nr_pages >0 ) { +if (!alloc_image_page (GFP_KERNEL | __GFP_NOWARN)) +break ; + nr_pages--; + nr_alloc++; + } + +return nr_alloc; } +/** +* swsusp_shrink_memory - Make the kernel release as much memory as needed +* +* To create a hibernation image it is necessary to make a copy of every page +* frame in use. We also need a number of page frames to be free during +* hibernation for allocations made while saving the image and for device +* drivers, in case they need to allocate memory from their hibernation +* callbacks (these two numbers are given by PAGES_FOR_IO and SPARE_PAGES, +* respectively, both of which are rough estimates). To make this happen, we +* compute the total number of available page frames and allocate at least +* +* ([page frames total] + PAGES_FOR_IO + [metadata pages]) / 2 + 2 * SPARE_PAGES +* +* of them, which corresponds to the maximum size of a hibernation image. +* +* If image_size is set below the number following from the above formula, +* the preallocation of memory is continued until the total number of page +* frames in use is below the requested image size or it is impossible to +* allocate more memory, whichever happens first. +*/ int swsusp_shrink_memory (void ) { -long tmp;struct zone *zone; -unsigned long pages =0 ; -unsigned int i =0 ; -char *p ="-\\|/" ; +unsigned long saveable, size, max_size, count, pages =0 ;struct timeval start, stop; +int error =0 ; -printk (KERN_INFO "PM: Shrinking memory... " ); +printk (KERN_INFO "PM: Shrinking memory ... " );do_gettimeofday (&start); - do { - long size, highmem_size; - highmem_size = count_highmem_pages(); - size = count_data_pages() + PAGES_FOR_IO + SPARE_PAGES; - tmp = size; - size += highmem_size; - for_each_populated_zone(zone) { - tmp += snapshot_additional_pages(zone); - if (is_highmem(zone)) { - highmem_size -= - zone_page_state(zone, NR_FREE_PAGES); - } else { - tmp -= zone_page_state(zone, NR_FREE_PAGES); - tmp += zone->lowmem_reserve[ZONE_NORMAL]; - } - } +/* Count the number of saveable data pages. */ + saveable =count_data_pages () +count_highmem_pages (); - if (highmem_size < 0) - highmem_size = 0;
kernel/power/snapshot.c void swsusp_free(void) · line 1133
Quoted 10 lines
kernel/power/snapshot.c +10
-0+/* +* Compute the total number of page frames we can use (count) and the +* number of pages needed for image metadata (size). +*/ + count = saveable; + size =0 ; +for_each_populated_zone (zone) { + size +=snapshot_additional_pages (zone); + count +=zone_page_state (zone,NR_FREE_PAGES ); + count -= zone->pages_min;
I'd prefer to be more safe, by removing the above line...
kernel/power/snapshot.c void swsusp_free(void) · line 1134
Quoted 1 line
kernel/power/snapshot.c +1
-0+ }
...and add another line here:
count -= totalreserve_pages;
But hey, that 'count' counts "savable+free" memory.
We don't have a counter for an estimation of "free+freeable" memory, ie. we are sure we cannot preallocate above that threshold.
One applicable situation is, when there are 800M anonymous memory, but only 500M image_size and no swap space.
In that case we will otherwise goto the oom code path. Sure oom is (and shall be) reliably disabled in hibernation, but still we shall be cautious enough not to create a low memory situation, which will hurt:
- hibernation speed
(vmscan goes mad trying to squeeze the last free page)
- user experiences after resume
(all *active* file data and metadata have to reloaded)
The current code simply tries *too hard* to meet image_size. I'd rather take that as a mild advice, and to only free "free+freeable-margin" pages when image_size is not approachable.
The safety margin can be totalreserve_pages, plus enough pages for retaining the "hard core working set".
Thanks,
Fengguang
Quoted 69 lines
kernel/power/snapshot.c +52
-13- tmp += highmem_size; -if (tmp >0 ) { - tmp =__shrink_memory (tmp); -if (!tmp) -return -ENOMEM ; - pages += tmp; - }else if (size > image_size /PAGE_SIZE ) { - tmp =__shrink_memory (size - (image_size /PAGE_SIZE )); - pages += tmp; - } -printk ("\b%c" , p[i++%4 ]); - }while (tmp >0 ); +/* Compute the maximum number of saveable pages to leave in memory. */ + max_size = (count - (size +PAGES_FOR_IO )) /2 -2 *SPARE_PAGES ; + size =DIV_ROUND_UP (image_size,PAGE_SIZE ); +if (size > max_size) + size = max_size; +/* +* If the maximum is not less than the current number of saveable pages +* in memory, we don't need to do anything more. +*/ +if (size >= saveable) + goto out; + +/* +* Let the memory management subsystem know that we're going to need a +* large number of page frames to allocate and make it free some memory. +* NOTE: If this is not done, performance is heavily affected in some +* test cases. +*/ +shrink_all_memory (saveable - size); + +/* +* Prevent the OOM killer from triggering while we're allocating image +* memory. +*/ +for_each_populated_zone (zone) +zone_set_flag (zone,ZONE_OOM_LOCKED ); +/* +* The number of saveable pages in memory was too high, so apply some +* pressure to decrease it. First, make room for the largest possible +* image and fail if that doesn't work. Next, try to decrease the size +* of the image as much as indicated by image_size. +*/ + count -= max_size; + pages =preallocate_image_memory (count); +if (pages < count) + error = -ENOMEM ; +else + pages +=preallocate_image_memory (max_size - size); + +for_each_populated_zone (zone) +zone_clear_flag (zone,ZONE_OOM_LOCKED ); + +/* Release all of the preallocated page frames. */ +swsusp_free (); + +if (error) { +printk (KERN_CONT "\n" ); +return error; + } + + out:do_gettimeofday (&stop); -printk ("\bdone (%lu pages freed)\n" , pages); +printk (KERN_CONT "done (preallocated %lu free pages)\n" , pages);swsusp_show_speed (&start, &stop, pages,"Freed" );return 0 ;
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
In reply to David RientjesQuoted 9 lines · David Rientjes
Quoted 2 lines · Andrew Morton
The setting and clearing of that thing looks gruesomely racy..
It's not racy currently because
zone_scan_lockensuresZONE_OOM_LOCKEDgets test/set and cleared atomically for the entire zonelist (the clear happens for the same zonelist that was test/set).
Quoted 9 lines
Using it for hibernation in the way I've proposed will open it up to the race I earlier described: when a kthread is in the oom killer and subsequently clears its zonelist of
ZONE_OOM_LOCKED(all other tasks are frozen so they can't be in the oom killer). That's perfectly acceptable, however, since the system is by definition already oom if kthreads can't get memory so it will end up killing a user task even though it's stuck in D state and will exit on thaw; we aren't concerned about killing needlessly because the oom killer becomes a no-op when it finds a task that has already been killed but hasn't exited by way ofTIF_MEMDIE.
OK there.
So everyone seems to agree we can do something like in the patch below?
---
From: Rafael J. Wysocki <[email protected]>
Subject: PM/Hibernate: Rework shrinking of memory
Rework swsusp_shrink_memory() so that it calls shrink_all_memory() just once to make some room for the image and then allocates memory to apply more pressure to the memory management subsystem, if necessary.
Unfortunately, we don't seem to be able to drop shrink_all_memory() entirely just yet, because that would lead to huge performance regressions in some test cases.
--- kernel/power/snapshot.c | 151 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 104 insertions(+), 47 deletions(-)
kernel/power/snapshot.c +104 -47
@@ -1066,69 +1066,126 @@ void swsusp_free(void) buffer =NULL ; } +/* Helper functions used for the shrinking of memory. */ +/** -* swsusp_shrink_memory - Try to free as much memory as needed -* -* ... but do not OOM-kill anyone +* preallocate_image_memory - Allocate given number of page frames +* @nr_pages: Number of page frames to allocate * -* Notice: all userland should be stopped before it is called, or -* livelock is possible. +* Return value: Number of page frames actually allocated */ - -#define SHRINK_BITE 10000 -static inline unsigned long __shrink_memory (long tmp) +static unsigned long preallocate_image_memory (unsigned long nr_pages) { -if (tmp >SHRINK_BITE ) - tmp =SHRINK_BITE ; -return shrink_all_memory (tmp); +unsigned long nr_alloc =0 ; + +while (nr_pages >0 ) { +if (!alloc_image_page (GFP_KERNEL | __GFP_NOWARN)) +break ; + nr_pages--; + nr_alloc++; + } + +return nr_alloc; } +/** +* swsusp_shrink_memory - Make the kernel release as much memory as needed +* +* To create a hibernation image it is necessary to make a copy of every page +* frame in use. We also need a number of page frames to be free during +* hibernation for allocations made while saving the image and for device +* drivers, in case they need to allocate memory from their hibernation +* callbacks (these two numbers are given by PAGES_FOR_IO and SPARE_PAGES, +* respectively, both of which are rough estimates). To make this happen, we +* compute the total number of available page frames and allocate at least +* +* ([page frames total] + PAGES_FOR_IO + [metadata pages]) / 2 + 2 * SPARE_PAGES +* +* of them, which corresponds to the maximum size of a hibernation image. +* +* If image_size is set below the number following from the above formula, +* the preallocation of memory is continued until the total number of page +* frames in use is below the requested image size or it is impossible to +* allocate more memory, whichever happens first. +*/ int swsusp_shrink_memory (void ) { -long tmp;struct zone *zone; -unsigned long pages =0 ; -unsigned int i =0 ; -char *p ="-\\|/" ; +unsigned long saveable, size, max_size, count, pages =0 ;struct timeval start, stop; +int error =0 ; -printk (KERN_INFO "PM: Shrinking memory... " ); +printk (KERN_INFO "PM: Shrinking memory ... " );do_gettimeofday (&start); -do { -long size, highmem_size; - highmem_size =count_highmem_pages (); - size =count_data_pages () +PAGES_FOR_IO +SPARE_PAGES ; - tmp = size; - size += highmem_size; -for_each_populated_zone (zone) { - tmp +=snapshot_additional_pages (zone); -if (is_highmem (zone)) { - highmem_size -= -zone_page_state (zone,NR_FREE_PAGES ); - }else { - tmp -=zone_page_state (zone,NR_FREE_PAGES ); - tmp += zone->lowmem_reserve[ZONE_NORMAL ]; - } - } +/* Count the number of saveable data pages. */ + saveable =count_data_pages () +count_highmem_pages (); -if (highmem_size <0 ) - highmem_size =0 ; +/* +* Compute the total number of page frames we can use (count) and the +* number of pages needed for image metadata (size). +*/ + count = saveable; + size =0 ; +for_each_populated_zone (zone) { + size +=snapshot_additional_pages (zone); + count +=zone_page_state (zone,NR_FREE_PAGES ); + count -= zone->pages_min; + } - tmp += highmem_size; -if (tmp >0 ) { - tmp =__shrink_memory (tmp); -if (!tmp) -return -ENOMEM ; - pages += tmp; - }else if (size > image_size /PAGE_SIZE ) { - tmp =__shrink_memory (size - (image_size /PAGE_SIZE )); - pages += tmp; - } -printk ("\b%c" , p[i++%4 ]); - }while (tmp >0 ); +/* Compute the maximum number of saveable pages to leave in memory. */ + max_size = (count - (size +PAGES_FOR_IO )) /2 -2 *SPARE_PAGES ; + size =DIV_ROUND_UP (image_size,PAGE_SIZE ); +if (size > max_size) + size = max_size; +/* +* If the maximum is not less than the current number of saveable pages +* in memory, we don't need to do anything more. +*/ +if (size >= saveable) + goto out; + +/* +* Let the memory management subsystem know that we're going to need a +* large number of page frames to allocate and make it free some memory. +* NOTE: If this is not done, performance is heavily affected in some +* test cases. +*/ +shrink_all_memory (saveable - size); + +/* +* Prevent the OOM killer from triggering while we're allocating image +* memory. +*/ +for_each_populated_zone (zone) +zone_set_flag (zone,ZONE_OOM_LOCKED ); +/* +* The number of saveable pages in memory was too high, so apply some +* pressure to decrease it. First, make room for the largest possible +* image and fail if that doesn't work. Next, try to decrease the size +* of the image as much as indicated by image_size. +*/ + count -= max_size; + pages =preallocate_image_memory (count); +if (pages < count) + error = -ENOMEM ; +else + pages +=preallocate_image_memory (max_size - size); + +for_each_populated_zone (zone) +zone_clear_flag (zone,ZONE_OOM_LOCKED ); + +/* Release all of the preallocated page frames. */ +swsusp_free (); + +if (error) { +printk (KERN_CONT "\n" ); +return error; + } + + out:do_gettimeofday (&stop); -printk ("\bdone (%lu pages freed)\n" , pages); +printk (KERN_CONT "done (preallocated %lu free pages)\n" , pages);swsusp_show_speed (&start, &stop, pages,"Freed" );return 0 ;
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
In reply to Andrew MortonQuoted 2 lines · Andrew Morton
The setting and clearing of that thing looks gruesomely racy..
It's not racy currently because zone_scan_lock ensures ZONE_OOM_LOCKED gets test/set and cleared atomically for the entire zonelist (the clear happens for the same zonelist that was test/set).
Using it for hibernation in the way I've proposed will open it up to the race I earlier described: when a kthread is in the oom killer and subsequently clears its zonelist of ZONE_OOM_LOCKED (all other tasks are frozen so they can't be in the oom killer). That's perfectly acceptable, however, since the system is by definition already oom if kthreads can't get memory so it will end up killing a user task even though it's stuck in D state and will exit on thaw; we aren't concerned about killing needlessly because the oom killer becomes a no-op when it finds a task that has already been killed but hasn't exited by way of TIF_MEMDIE.
Andrew Morton
maintainerRe: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
In reply to David RientjesQuoted 9 lines · On Thu, 7 May 2009 15:16:17 -0700 (PDT) David Rientjes <[email protected]>…
Quoted 4 lines · Andrew Morton
- the standard way of controlling memory allocator behaviour is via the
gfp_t. Bypassing that is an unusual step and needs a higher level of justification, which I'm not seeing here.The standard way of controlling the oom killer behavior for a zone is via the
ZONE_OOM_LOCKEDbit.
oop, I didn't remember/realise that ZONE_OOM_LOCKED already exists.
Quoted 8 lines
Quoted 7 lines
- if we do this via an unusual global, we reduce the chances that another subsytem could use the new feature.
I don't know what subsytem that might be, but I bet they're out there. checkpoint-restart, virtual machines, ballooning memory drivers, kexec loading, etc.
Quoted 7 lines
There's two separate issues here: the use of
ZONE_OOM_LOCKEDto control whether or not to invoke the oom killer for a specific zone (which is already its only function), and the fact that in this case we're doing it for all zones. It seems like you're concerned with the latter, but the distinction in the hibernation case is that no memory freeing would be possible as the result of the oom killer for _all_ zones, so it makes sense to lock them all out.
OK.
Quoted 13 lines
Quoted 9 lines
Quoted 8 lines
The fact is that _all_ allocations here are implicitly
__GFP_NO_OOM_KILLwhether it specifies it or not since the oom killer would simply kill a task in D state which can't exit or free memory and subsequent allocations would make the oom killer a no-op because there's an eligible task withTIF_MEMDIEset. The only thing you're saving with__GFP_NO_OOM_KILLis calling the oom killer in a first place and killing an unresponsive task but that would have to happen anyway when thawed since the system is oom (or otherwise lockup forGFP_KERNELwith order <PAGE_ALLOC_COSTLY_ORDER).Quoted 3 lines
All the above is specific to the PM application only, when userspace tasks are stopped.
Quoted 6 lines
I'm not arguing that the only way we can ever implement
__GFP_NO_OOM_KILLis for the entire system: we can setZONE_OOM_LOCKEDfor only the zones in the zonelist that are passed to the page allocator. For this particular purpose, that is naturally all zones; for other future use cases it may be chosen only to lock out the zones we're allowed to allocate from in that context.
OK.
Quoted 6 lines
Quoted 3 lines
It might well end up that stopping userspace (beforehand or before oom-killing) is a hard requirement for reliably disabling the oom-killer.
Yes, globally, but future use cases may disable only specific zones such as with memory hot-remove.
<goes off to find out what ZONE_OOM_LOCKED does>
That took remarkably longer than one would have expected..
Yes, OK, I agree, globally setting ZONE_OOM_LOCKED would produce a decent result.
The setting and clearing of that thing looks gruesomely racy..
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
In reply to Andrew MortonQuoted 4 lines · Andrew Morton
- the standard way of controlling memory allocator behaviour is via the
gfp_t. Bypassing that is an unusual step and needs a higher level of justification, which I'm not seeing here.
The standard way of controlling the oom killer behavior for a zone is via the ZONE_OOM_LOCKED bit.
Quoted 7 lines
- if we do this via an unusual global, we reduce the chances that another subsytem could use the new feature.
I don't know what subsytem that might be, but I bet they're out there. checkpoint-restart, virtual machines, ballooning memory drivers, kexec loading, etc.
There's two separate issues here: the use of ZONE_OOM_LOCKED to control whether or not to invoke the oom killer for a specific zone (which is already its only function), and the fact that in this case we're doing it for all zones. It seems like you're concerned with the latter, but the distinction in the hibernation case is that no memory freeing would be possible as the result of the oom killer for _all_ zones, so it makes sense to lock them all out.
Quoted 9 lines
Quoted 8 lines
The fact is that _all_ allocations here are implicitly
__GFP_NO_OOM_KILLwhether it specifies it or not since the oom killer would simply kill a task in D state which can't exit or free memory and subsequent allocations would make the oom killer a no-op because there's an eligible task withTIF_MEMDIEset. The only thing you're saving with__GFP_NO_OOM_KILLis calling the oom killer in a first place and killing an unresponsive task but that would have to happen anyway when thawed since the system is oom (or otherwise lockup forGFP_KERNELwith order <PAGE_ALLOC_COSTLY_ORDER).
Quoted 3 lines
All the above is specific to the PM application only, when userspace tasks are stopped.
I'm not arguing that the only way we can ever implement __GFP_NO_OOM_KILL is for the entire system: we can set ZONE_OOM_LOCKED for only the zones in the zonelist that are passed to the page allocator. For this particular purpose, that is naturally all zones; for other future use cases it may be chosen only to lock out the zones we're allowed to allocate from in that context.
Quoted 3 lines
It might well end up that stopping userspace (beforehand or before oom-killing) is a hard requirement for reliably disabling the oom-killer.
Yes, globally, but future use cases may disable only specific zones such as with memory hot-remove.
Andrew Morton
maintainerRe: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
In reply to David RientjesQuoted 30 lines · On Thu, 7 May 2009 14:25:23 -0700 (PDT) David Rientjes <[email protected]>…
Quoted 18 lines · Andrew Morton
Quoted 18 lines
Quoted 17 lines
All of your tasks are in D state other than kthreads, right? That means they won't be in the oom killer (thus no zones are oom locked), so you can easily do this
struct zone *z; for_each_populated_zone(z) zone_set_flag(z, ZONE_OOM_LOCKED);and then
for_each_populated_zone(z) zone_clear_flag(z, ZONE_OOM_LOCKED);The serialization is done with trylocks so this will never invoke the oom killer because all zones in the allocator's zonelist will be oom locked.
Why does this not work for you?
Quoted 9 lines
Quoted 4 lines
Well, it might work too, but why are you insisting? How's it better than
__GFP_NO_OOM_KILL, actually?Andrew, what do you think about this?
I don't think I understand the proposal. Is it to provide a means by which PM can go in and set a state bit against each and every zone? If so, that's still a global boolean, only messier.
Quoted 4 lines
Why can't it be global while preallocating memory for hibernation since nothing but kthreads could allocate at this point and if the system is oom then the oom killer wouldn't be able to do anything anyway since it can't kill them?
- globals are bad
- the standard way of controlling memory allocator behaviour is via the gfp_t. Bypassing that is an unusual step and needs a higher level of justification, which I'm not seeing here.
- if we do this via an unusual global, we reduce the chances that another subsytem could use the new feature.
I don't know what subsytem that might be, but I bet they're out there. checkpoint-restart, virtual machines, ballooning memory drivers, kexec loading, etc.
Quoted 8 lines
The fact is that _all_ allocations here are implicitly
__GFP_NO_OOM_KILLwhether it specifies it or not since the oom killer would simply kill a task in D state which can't exit or free memory and subsequent allocations would make the oom killer a no-op because there's an eligible task withTIF_MEMDIEset. The only thing you're saving with__GFP_NO_OOM_KILLis calling the oom killer in a first place and killing an unresponsive task but that would have to happen anyway when thawed since the system is oom (or otherwise lockup forGFP_KERNELwith order <PAGE_ALLOC_COSTLY_ORDER).
All the above is specific to the PM application only, when userspace tasks are stopped.
It might well end up that stopping userspace (beforehand or before oom-killing) is a hard requirement for reliably disabling the oom-killer. Because the __GFP_NO_OOM_KILL user will be safe, but random other allocations from other tasks will not be. So perhaps we _do_ need a global, and random userspace processes should test and sleep upon that global if they're heading in the direction of the oom-killer.
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
In reply to Andrew MortonQuoted 18 lines · Andrew Morton
Quoted 18 lines
Quoted 17 lines
All of your tasks are in D state other than kthreads, right? That means they won't be in the oom killer (thus no zones are oom locked), so you can easily do this
struct zone *z; for_each_populated_zone(z) zone_set_flag(z, ZONE_OOM_LOCKED);and then
for_each_populated_zone(z) zone_clear_flag(z, ZONE_OOM_LOCKED);The serialization is done with trylocks so this will never invoke the oom killer because all zones in the allocator's zonelist will be oom locked.
Why does this not work for you?
Quoted 9 lines
Quoted 4 lines
Well, it might work too, but why are you insisting? How's it better than
__GFP_NO_OOM_KILL, actually?Andrew, what do you think about this?
I don't think I understand the proposal. Is it to provide a means by which PM can go in and set a state bit against each and every zone? If so, that's still a global boolean, only messier.
Why can't it be global while preallocating memory for hibernation since nothing but kthreads could allocate at this point and if the system is oom then the oom killer wouldn't be able to do anything anyway since it can't kill them?
The fact is that _all_ allocations here are implicitly __GFP_NO_OOM_KILL whether it specifies it or not since the oom killer would simply kill a task in D state which can't exit or free memory and subsequent allocations would make the oom killer a no-op because there's an eligible task with TIF_MEMDIE set. The only thing you're saving with __GFP_NO_OOM_KILL is calling the oom killer in a first place and killing an unresponsive task but that would have to happen anyway when thawed since the system is oom (or otherwise lockup for GFP_KERNEL with order < PAGE_ALLOC_COSTLY_ORDER).
Andrew Morton
maintainerRe: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
In reply to Rafael J. WysockiQuoted 26 lines · On Thu, 7 May 2009 22:38:13 +0200 "Rafael J. Wysocki" <[email protected]> wrote:
Quoted 25 lines · David Rientjes
Quoted 3 lines · Rafael J. Wysocki
OK, let's try with
__GFP_NO_OOM_KILLfirst. If there's too much disagreement, I'll use the freezer-based approach instead.Third time I'm going to suggest this, and I'd like a response on why it's not possible instead of being ignored.
All of your tasks are in D state other than kthreads, right? That means they won't be in the oom killer (thus no zones are oom locked), so you can easily do this
struct zone *z; for_each_populated_zone(z) zone_set_flag(z, ZONE_OOM_LOCKED);and then
for_each_populated_zone(z) zone_clear_flag(z, ZONE_OOM_LOCKED);The serialization is done with trylocks so this will never invoke the oom killer because all zones in the allocator's zonelist will be oom locked.
Quoted 6 lines
Quoted 1 line
Why does this not work for you?
Well, it might work too, but why are you insisting? How's it better than
__GFP_NO_OOM_KILL, actually?Andrew, what do you think about this?
I don't think I understand the proposal. Is it to provide a means by which PM can go in and set a state bit against each and every zone? If so, that's still a global boolean, only messier.
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
In reply to David RientjesQuoted 19 lines · David Rientjes
Quoted 3 lines · Rafael J. Wysocki
OK, let's try with
__GFP_NO_OOM_KILLfirst. If there's too much disagreement, I'll use the freezer-based approach instead.Third time I'm going to suggest this, and I'd like a response on why it's not possible instead of being ignored.
All of your tasks are in D state other than kthreads, right? That means they won't be in the oom killer (thus no zones are oom locked), so you can easily do this
struct zone *z; for_each_populated_zone(z) zone_set_flag(z, ZONE_OOM_LOCKED);and then
Quoted 7 lines
for_each_populated_zone(z) zone_clear_flag(z, ZONE_OOM_LOCKED);The serialization is done with trylocks so this will never invoke the oom killer because all zones in the allocator's zonelist will be oom locked.
Why does this not work for you?
Well, it might work too, but why are you insisting? How's it better than __GFP_NO_OOM_KILL, actually?
Andrew, what do you think about this?
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
In reply to David RientjesQuoted 17 lines · David Rientjes
Quoted 3 lines · Rafael J. Wysocki
OK, let's try with
__GFP_NO_OOM_KILLfirst. If there's too much disagreement, I'll use the freezer-based approach instead.Third time I'm going to suggest this, and I'd like a response on why it's not possible instead of being ignored.
All of your tasks are in D state other than kthreads, right? That means they won't be in the oom killer (thus no zones are oom locked), so you can easily do this
struct zone *z; for_each_populated_zone(z) zone_set_flag(z, ZONE_OOM_LOCKED);
Quoted 7 lines
and then
for_each_populated_zone(z) zone_clear_flag(z, ZONE_OOM_LOCKED);The serialization is done with trylocks so this will never invoke the oom killer because all zones in the allocator's zonelist will be oom locked.
Well, that might have been a good idea if it actually had worked. :-(
Quoted 1 line
Why does this not work for you?
If I set image_size to something below "hard core working set" + totalreserve_pages, preallocate_image_memory() hangs the box (please refer to the last patch I sent,
http://patchwork.kernel.org/patch/22423/).
However, with the freezer-based disabling of the OOM killer it doesn't hang under the same test conditions.
The difference appears to be that using your approach makes __alloc_pages_internal() loop forever between the !try_set_zone_oom() test and restart:, while it should go to nopage: in that situation.
So, I think I'll stick to the Andrew's approach with using __GFP_NO_OOM_KILL.
Thanks,
Rafael
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
Quoted 16 lines · Rafael J. Wysocki
Quoted 8 lines
All of your tasks are in D state other than kthreads, right? That means they won't be in the oom killer (thus no zones are oom locked), so you can easily do this
struct zone *z; for_each_populated_zone(z) zone_set_flag(z, ZONE_OOM_LOCKED);Quoted 7 lines
and then
for_each_populated_zone(z) zone_clear_flag(z, ZONE_OOM_LOCKED);The serialization is done with trylocks so this will never invoke the oom killer because all zones in the allocator's zonelist will be oom locked.
Quoted 9 lines
Well, that might have been a good idea if it actually had worked. :-(
Quoted 1 line
Why does this not work for you?
If I set
image_sizeto something below "hard core working set" +totalreserve_pages,preallocate_image_memory()hangs the box (please refer to the last patch I sent,
http://patchwork.kernel.org/patch/22423/).
This has been changed in the latest mmotm with Mel's page alloactor patches (and I think yours should be based on mmotm). Specifically, page-allocator-break-up-the-allocator-entry-point-into-fast-and-slow-paths.patch.
Before his patchset, zonelists that had ZONE_OOM_LOCKED set for at least one of their zones would unconditionally goto restart. Now, if order > PAGE_ALLOC_COSTLY_ORDER, it gives up and returns NULL. Otherwise, it does goto restart.
So if your allocation has order > PAGE_ALLOC_COSTLY_ORDER, using the ZONE_OOM_LOCKED approach to locking out the oom killer will work just fine in mmotm.
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
Quoted 32 lines · David Rientjes
Quoted 16 lines · Rafael J. Wysocki
Quoted 8 lines
All of your tasks are in D state other than kthreads, right? That means they won't be in the oom killer (thus no zones are oom locked), so you can easily do this
struct zone *z; for_each_populated_zone(z) zone_set_flag(z, ZONE_OOM_LOCKED);Quoted 7 lines
and then
for_each_populated_zone(z) zone_clear_flag(z, ZONE_OOM_LOCKED);The serialization is done with trylocks so this will never invoke the oom killer because all zones in the allocator's zonelist will be oom locked.
Quoted 9 lines
Well, that might have been a good idea if it actually had worked. :-(
Quoted 1 line
Why does this not work for you?
If I set
image_sizeto something below "hard core working set" +totalreserve_pages,preallocate_image_memory()hangs the box (please refer to the last patch I sent,
http://patchwork.kernel.org/patch/22423/).This has been changed in the latest mmotm with Mel's page alloactor patches (and I think yours should be based on mmotm). Specifically, page-allocator-break-up-the-allocator-entry-point-into-fast-and-slow-paths.patch.
Quoted 6 lines
Before his patchset, zonelists that had
ZONE_OOM_LOCKEDset for at least one of their zones would unconditionally goto restart. Now, if order >PAGE_ALLOC_COSTLY_ORDER, it gives up and returns NULL. Otherwise, it does goto restart.So if your allocation has order >
PAGE_ALLOC_COSTLY_ORDER,
It doesn't. All of my allocations are of order 0.
Quoted 2 lines
using the
ZONE_OOM_LOCKEDapproach to locking out the oom killer will work just fine in mmotm.
No, it won't, AFAICT.
Best,
Rafael
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
Quoted 4 lines · Rafael J. Wysocki
Quoted 4 lines
This has been changed in the latest mmotm with Mel's page alloactor patches (and I think yours should be based on mmotm). Specifically, page-allocator-break-up-the-allocator-entry-point-into-fast-and-slow-paths.patch.
Quoted 9 lines
Quoted 6 lines
Before his patchset, zonelists that had
ZONE_OOM_LOCKEDset for at least one of their zones would unconditionally goto restart. Now, if order >PAGE_ALLOC_COSTLY_ORDER, it gives up and returns NULL. Otherwise, it does goto restart.So if your allocation has order >
PAGE_ALLOC_COSTLY_ORDER,It doesn't. All of my allocations are of order 0.
All order 0 allocations are implicitly __GFP_NOFAIL and will loop endlessly unless they can't block. So if you want to simply prohibit the oom killer from being invoked and not change the retry behavior, setting ZONE_OOM_LOCKED for all zones will do that. If your machine hangs, it means nothing can be reclaimed and you can't free memory via oom killing, so there's nothing else the page allocator can do.
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
Quoted 16 lines · David Rientjes
Quoted 4 lines · Rafael J. Wysocki
Quoted 4 lines
This has been changed in the latest mmotm with Mel's page alloactor patches (and I think yours should be based on mmotm). Specifically, page-allocator-break-up-the-allocator-entry-point-into-fast-and-slow-paths.patch.
Quoted 9 lines
Quoted 6 lines
Before his patchset, zonelists that had
ZONE_OOM_LOCKEDset for at least one of their zones would unconditionally goto restart. Now, if order >PAGE_ALLOC_COSTLY_ORDER, it gives up and returns NULL. Otherwise, it does goto restart.So if your allocation has order >
PAGE_ALLOC_COSTLY_ORDER,It doesn't. All of my allocations are of order 0.
Quoted 6 lines
All order 0 allocations are implicitly
__GFP_NOFAILand will loop endlessly unless they can't block. So if you want to simply prohibit the oom killer from being invoked and not change the retry behavior, settingZONE_OOM_LOCKEDfor all zones will do that. If your machine hangs, it means nothing can be reclaimed and you can't free memory via oom killing, so there's nothing else the page allocator can do.
But I want it to give up in this case instead of looping forever.
Look. I have a specific problem at hand that I want to solve and the approach you suggested _clearly_ _doesn't_ _work_. I have also tried to explain to you why it doesn't work, but you're ingnoring it, so I really don't know what else I can say.
OTOH, the approach suggested by Andrew _does_ _work_ regardless of your opinion about it. It's been tested and it's done the job 100% of the time. Go figure. And please stop beating the dead horse.
Thanks,
Rafael
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
Quoted 9 lines · Rafael J. Wysocki
Quoted 6 lines
All order 0 allocations are implicitly
__GFP_NOFAILand will loop endlessly unless they can't block. So if you want to simply prohibit the oom killer from being invoked and not change the retry behavior, settingZONE_OOM_LOCKEDfor all zones will do that. If your machine hangs, it means nothing can be reclaimed and you can't free memory via oom killing, so there's nothing else the page allocator can do.But I want it to give up in this case instead of looping forever.
Quoted 9 lines
Look. I have a specific problem at hand that I want to solve and the approach you suggested _clearly_ _doesn't_ _work_. I have also tried to explain to you why it doesn't work, but you're ingnoring it, so I really don't know what else I can say.
OTOH, the approach suggested by Andrew _does_ _work_ regardless of your opinion about it. It's been tested and it's done the job 100% of the time. Go figure. And please stop beating the dead horse.
Which implementation are you talking about? You've had several:
http://marc.info/?l=linux-kernel&m=124121728429113 http://marc.info/?l=linux-kernel&m=124131049223733 http://marc.info/?l=linux-kernel&m=124165031723627 http://marc.info/?l=linux-kernel&m=124146681311494
The issue with your approach is that it doesn't address the problem; the problem is _not_ specific to individual page allocations it is specific to the STATE OF THE MACHINE.
If all userspace tasks are uninterruptible when trying to reserve this memory and, thus, oom killing is negligent and not going to help, that needs to be addressed in the page allocator. It is a bug for the allocator to continuously retry the allocation unless __GFP_NOFAIL is set if oom killing will not free memory.
Adding a new __GFP_NO_OOM_KILL flag to address that isn't helpful since it has nothing at all to do with the specific allocation. It may certainly be the easiest way to implement your patchset without doing VM work, but it's not going to fix the problem for others.
I just posted a patch series[*] that would fix this problem for you without even locking out the oom killer or adding any unnecessary gfp flags. It is based on mmotm since it has Mel's page allocator speedups. Any change you do to the allocator at this point should be based on that to avoid nasty merge conflicts later, so try my series out and see how it works.
Now, I won't engage in your personal attacks because (i) nobody else cares, and (ii) it's not going to be productive. I'll let my code do the talking.
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
Quoted 21 lines · David Rientjes
Quoted 9 lines · Rafael J. Wysocki
Quoted 6 lines
All order 0 allocations are implicitly
__GFP_NOFAILand will loop endlessly unless they can't block. So if you want to simply prohibit the oom killer from being invoked and not change the retry behavior, settingZONE_OOM_LOCKEDfor all zones will do that. If your machine hangs, it means nothing can be reclaimed and you can't free memory via oom killing, so there's nothing else the page allocator can do.But I want it to give up in this case instead of looping forever.
Quoted 9 lines
Look. I have a specific problem at hand that I want to solve and the approach you suggested _clearly_ _doesn't_ _work_. I have also tried to explain to you why it doesn't work, but you're ingnoring it, so I really don't know what else I can say.
OTOH, the approach suggested by Andrew _does_ _work_ regardless of your opinion about it. It's been tested and it's done the job 100% of the time. Go figure. And please stop beating the dead horse.
Quoted 6 lines
Which implementation are you talking about? You've had several:
http://marc.info/?l=linux-kernel&m=124121728429113 http://marc.info/?l=linux-kernel&m=124131049223733 http://marc.info/?l=linux-kernel&m=124165031723627 http://marc.info/?l=linux-kernel&m=124146681311494
The second one. The first one was too much code, the third one was not the Andrew's favourite and the last one is wrong, because it changes the behaviour related to __GFP_NORETRY incorrectly.
Quoted 3 lines
The issue with your approach is that it doesn't address the problem; the problem is _not_ specific to individual page allocations it is specific to the STATE OF THE MACHINE.
Yes, it is, but have you followed my discussion with Andrew?
Quoted 5 lines
If all userspace tasks are uninterruptible when trying to reserve this memory and, thus, oom killing is negligent and not going to help, that needs to be addressed in the page allocator. It is a bug for the allocator to continuously retry the allocation unless
__GFP_NOFAILis set if oom killing will not free memory.
That was my argument in the discussion with Andrew, actually.
Quoted 4 lines
Adding a new
__GFP_NO_OOM_KILLflag to address that isn't helpful since it has nothing at all to do with the specific allocation. It may certainly be the easiest way to implement your patchset without doing VM work, but it's not going to fix the problem for others.
I agree, but I didn't even want to fix the problem with OOM killing after freezing tasks.
Quoted 9 lines
I just posted a patch series[*] that would fix this problem for you without even locking out the oom killer or adding any unnecessary gfp flags. It is based on mmotm since it has Mel's page allocator speedups. Any change you do to the allocator at this point should be based on that to avoid nasty merge conflicts later, so try my series out and see how it works.
Now, I won't engage in your personal attacks because (i) nobody else cares, and (ii) it's not going to be productive.
My previous message wasn't meant to be personal, so I'm sorry if it sounded like it was.
Quoted 3 lines
I'll let my code do the talking.
OK, so the patch is http://lkml.org/lkml/2009/5/10/127, isn't it? I'm not sure it will fly, given the Andrew's reply.
In fact the problem is that processes in D state are only legitimately going to stay in this state when they are _frozen_. So, the right approach seems to be to avoid calling the OOM killer at all after freezing processes and instead fail the allocations that would have triggered it. Which means this patch:
http://marc.info/?l=linux-kernel&m=124165031723627 (it also is my favourite one).
But Andrew says that it's better to have a __GFP_NO_OOM_KILL flag instead, because someone else might presumably use it in future for something (I have no idea who that might be, but whatever) and _surely_ no one else will use a global switch related to the freezer.
Still _I_ think that since the freezer is the source of the problematic situation (all tasks are persistently unkillable), using it should change the behaviour of the page allocator, so that the OOM killer is not activated while processes are frozen. And in fact that should not depend on what flags are used by whoever tries to allocate memory.
Thanks,
Rafael
Andrew Morton
maintainerRe: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
Quoted 3 lines · On Tue, 12 May 2009 00:44:36 +0200 "Rafael J. Wysocki"…
Which means this patch:
http://marc.info/?l=linux-kernel&m=124165031723627 (it also is my favourite one).
ho hum, I could live with that ;)
Would it make sense to turn it into something more general? Instead of "tasks_frozen/processes_are_frozen()", present it as "oom_killer_disabled/oom_killer_is_disabled()"?
That would invite other subsystems to use it, if they want to. Which might well be a bad thing on their behalf, hard to say..
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
Quoted 7 lines · Andrew Morton
Quoted 3 lines · On Tue, 12 May 2009 00:44:36 +0200 "Rafael J. Wysocki"…
Which means this patch:
http://marc.info/?l=linux-kernel&m=124165031723627 (it also is my favourite one).
Quoted 8 lines
ho hum, I could live with that ;)
Would it make sense to turn it into something more general? Instead of "tasks_frozen/processes_are_frozen()", present it as "oom_killer_disabled/oom_killer_is_disabled()"?
That would invite other subsystems to use it, if they want to. Which might well be a bad thing on their behalf, hard to say..
I chose the names this way because the variable is defined in the freezer code.
Alternatively, I can define one in page_alloc.c, add [disable|enable]_oom_killer() for manipulating it and call them from the freezer code. Do you think that would be better?
Andrew Morton
maintainerRe: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
Quoted 14 lines · On Tue, 12 May 2009 01:28:15 +0200 "Rafael J. Wysocki"…
Quoted 13 lines · Andrew Morton
Quoted 3 lines · On Tue, 12 May 2009 00:44:36 +0200 "Rafael J. Wysocki"…
Which means this patch:
http://marc.info/?l=linux-kernel&m=124165031723627 (it also is my favourite one).ho hum, I could live with that ;)
Would it make sense to turn it into something more general? Instead of "tasks_frozen/processes_are_frozen()", present it as "oom_killer_disabled/oom_killer_is_disabled()"?
Quoted 8 lines
Quoted 2 lines
That would invite other subsystems to use it, if they want to. Which might well be a bad thing on their behalf, hard to say..
I chose the names this way because the variable is defined in the freezer code.
Alternatively, I can define one in
page_alloc.c, add [disable|enable]_oom_killer() for manipulating it and call them from the freezer code. Do you think that would be better?
The choice is:
a) put a general oom-killer interface function into the oom-killer code, call that from swsusp.
b) put a swsusp-specific change into the oom-killer, call that from swsusp.
From a cleanliess POV, a) is way better. But it does need to be a general function! If there's some hidden requirement which only makes the function applicable to swsusp, such as "all tasks must be frozen" then we'd be kidding ourselves by making it general-looking.
I have a bad feeling that after one week and 12^17 emails, we're back to your original patch :)
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
Quoted 31 lines · Andrew Morton
Quoted 14 lines · On Tue, 12 May 2009 01:28:15 +0200 "Rafael J. Wysocki"…
Quoted 13 lines · Andrew Morton
Quoted 3 lines · On Tue, 12 May 2009 00:44:36 +0200 "Rafael J. Wysocki"…
Which means this patch:
http://marc.info/?l=linux-kernel&m=124165031723627 (it also is my favourite one).ho hum, I could live with that ;)
Would it make sense to turn it into something more general? Instead of "tasks_frozen/processes_are_frozen()", present it as "oom_killer_disabled/oom_killer_is_disabled()"?
Quoted 8 lines
Quoted 2 lines
That would invite other subsystems to use it, if they want to. Which might well be a bad thing on their behalf, hard to say..
I chose the names this way because the variable is defined in the freezer code.
Alternatively, I can define one in
page_alloc.c, add [disable|enable]_oom_killer() for manipulating it and call them from the freezer code. Do you think that would be better?The choice is:
a) put a general oom-killer interface function into the oom-killer code, call that from swsusp.
Quoted 7 lines
b) put a swsusp-specific change into the oom-killer, call that from swsusp.
From a cleanliess POV, a) is way better. But it does need to be a general function! If there's some hidden requirement which only makes the function applicable to swsusp, such as "all tasks must be frozen" then we'd be kidding ourselves by making it general-looking.
Hmm. I guess there may be other situations in which it's better to fail memory allocations than to kill tasks.
Quoted 2 lines
I have a bad feeling that after one week and 12^17 emails, we're back to your original patch :)
Well, what about the following?
---
From: Rafael J. Wysocki <[email protected]>
Subject: mm, PM/Freezer: Disable OOM killer when tasks are frozen
Currently, the following scenario appears to be possible in theory:
* Tasks are frozen for hibernation or suspend.
* Free pages are almost exhausted.
* Certain piece of code in the suspend code path attempts to allocate some memory using GFP_KERNEL and allocation order less than or equal to PAGE_ALLOC_COSTLY_ORDER.
* __alloc_pages_internal() cannot find a free page so it invokes the OOM killer.
* The OOM killer attempts to kill a task, but the task is frozen, so it doesn't die immediately.
* __alloc_pages_internal() jumps to 'restart', unsuccessfully tries to find a free page and invokes the OOM killer.
* No progress can be made.
Although it is now hard to trigger during hibernation due to the memory shrinking carried out by the hibernation code, it is theoretically possible to trigger during suspend after the memory shrinking has been removed from that code path. Moreover, since memory allocations are going to be used for the hibernation memory shrinking, it will be even more likely to happen during hibernation.
To prevent it from happening, introduce the oom_killer_disabled switch that will cause __alloc_pages_internal() to fail in the situations in which the OOM killer would have been called and make the freezer set this switch after tasks have been successfully frozen.
--- include/linux/gfp.h | 12 ++++++++++++ kernel/power/process.c | 5 +++++ mm/page_alloc.c | 5 +++++ 3 files changed, 22 insertions(+)
mm/page_alloc.c +5 -0
@@ -175,6 +175,8 @@ static void set_pageblock_migratetype(st PB_migrate, PB_migrate_end); } +bool oom_killer_disabled__read_mostly ; +#ifdef CONFIG_DEBUG_VM static int page_outside_zone_boundaries (struct zone *zone,struct page *page) {
@@ -1600,6 +1602,9 @@ nofail_alloc:if (page) goto got_pg; }else if ((gfp_mask & __GFP_FS) && !(gfp_mask & __GFP_NORETRY)) { +if (oom_killer_disabled) + goto nopage; +if (!try_set_zone_oom (zonelist, gfp_mask)) {schedule_timeout_uninterruptible (1 ); goto restart;
include/linux/gfp.h +12 -0
@@ -245,4 +245,16 @@ void drain_zone_pages(struct zone *zone,void drain_all_pages (void );void drain_local_pages (void *dummy); +extern bool oom_killer_disabled; + +static inline void disable_oom_killer (void ) +{ + oom_killer_disabled = true; +} + +static inline void enable_oom_killer (void ) +{ + oom_killer_disabled = false; +} +#endif /* __LINUX_GFP_H */
kernel/power/process.c +5 -0
@@ -117,9 +117,12 @@ int freeze_processes(void)if (error) goto Exit;printk ("done." ); + +disable_oom_killer (); Exit:BUG_ON (in_atomic ());printk ("\n" ); +return error; }
@@ -145,6 +148,8 @@ static void thaw_tasks(bool nosig_only)void thaw_processes (void ) { +enable_oom_killer (); +printk ("Restarting tasks ... " );thaw_tasks (true);thaw_tasks (false);
Andrew Morton
maintainerRe: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
Quoted 1 line · On Tue, 12 May 2009 18:52:36 +0200 "Rafael J. Wysocki" <[email protected]> wrote:
Well, what about the following?
It has the virtue of simplicity.
include/linux/gfp.h void drain_zone_pages(struct zone *zone, · line 258
Quoted 9 lines
include/linux/gfp.h +9
-0+static inline void disable_oom_killer (void ) +{ + oom_killer_disabled = true; +} + +static inline void enable_oom_killer (void ) +{ + oom_killer_disabled = false; +}
I'll change these to oom_killer_disable() and oom_killer_enable(), OK?
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
Quoted 6 lines · Andrew Morton
Quoted 1 line · On Tue, 12 May 2009 18:52:36 +0200 "Rafael J. Wysocki"…
Well, what about the following?
It has the virtue of simplicity.
Quoted 11 lines
include/linux/gfp.h void drain_zone_pages(struct zone *zone, · line 258
Quoted 9 lines
include/linux/gfp.h +9
-0+static inline void disable_oom_killer (void ) +{ + oom_killer_disabled = true; +} + +static inline void enable_oom_killer (void ) +{ + oom_killer_disabled = false; +}I'll change these to
oom_killer_disable()andoom_killer_enable(), OK?
Works for me, thanks!
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
In reply to Andrew MortonQuoted 6 lines · Andrew Morton
Quoted 1 line · On Tue, 12 May 2009 18:52:36 +0200 "Rafael J. Wysocki" <[email protected]> wrote:
Well, what about the following?
It has the virtue of simplicity.
Quoted 11 lines
include/linux/gfp.h void drain_zone_pages(struct zone *zone, · line 258
Quoted 9 lines
include/linux/gfp.h +9
-0+static inline void disable_oom_killer (void ) +{ + oom_killer_disabled = true; +} + +static inline void enable_oom_killer (void ) +{ + oom_killer_disabled = false; +}I'll change these to
oom_killer_disable()andoom_killer_enable(), OK?
Works for me, thanks!
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
In reply to Andrew MortonQuoted 31 lines · Andrew Morton
Quoted 14 lines · On Tue, 12 May 2009 01:28:15 +0200 "Rafael J. Wysocki" <[email protected]> wrote:
Quoted 13 lines · Andrew Morton
Quoted 3 lines · On Tue, 12 May 2009 00:44:36 +0200 "Rafael J. Wysocki" <[email protected]> wrote:
Which means this patch:
http://marc.info/?l=linux-kernel&m=124165031723627 (it also is my favourite one).ho hum, I could live with that ;)
Would it make sense to turn it into something more general? Instead of "tasks_frozen/processes_are_frozen()", present it as "oom_killer_disabled/oom_killer_is_disabled()"?
Quoted 8 lines
Quoted 2 lines
That would invite other subsystems to use it, if they want to. Which might well be a bad thing on their behalf, hard to say..
I chose the names this way because the variable is defined in the freezer code.
Alternatively, I can define one in
page_alloc.c, add [disable|enable]_oom_killer() for manipulating it and call them from the freezer code. Do you think that would be better?The choice is:
a) put a general oom-killer interface function into the oom-killer code, call that from swsusp.
Quoted 7 lines
b) put a swsusp-specific change into the oom-killer, call that from swsusp.
From a cleanliess POV, a) is way better. But it does need to be a general function! If there's some hidden requirement which only makes the function applicable to swsusp, such as "all tasks must be frozen" then we'd be kidding ourselves by making it general-looking.
Hmm. I guess there may be other situations in which it's better to fail memory allocations than to kill tasks.
Quoted 2 lines
I have a bad feeling that after one week and 12^17 emails, we're back to your original patch :)
Well, what about the following?
---
From: Rafael J. Wysocki <[email protected]>
Subject: mm, PM/Freezer: Disable OOM killer when tasks are frozen
Currently, the following scenario appears to be possible in theory:
* Tasks are frozen for hibernation or suspend.
* Free pages are almost exhausted.
* Certain piece of code in the suspend code path attempts to allocate some memory using GFP_KERNEL and allocation order less than or equal to PAGE_ALLOC_COSTLY_ORDER.
* __alloc_pages_internal() cannot find a free page so it invokes the OOM killer.
* The OOM killer attempts to kill a task, but the task is frozen, so it doesn't die immediately.
* __alloc_pages_internal() jumps to 'restart', unsuccessfully tries to find a free page and invokes the OOM killer.
* No progress can be made.
Although it is now hard to trigger during hibernation due to the memory shrinking carried out by the hibernation code, it is theoretically possible to trigger during suspend after the memory shrinking has been removed from that code path. Moreover, since memory allocations are going to be used for the hibernation memory shrinking, it will be even more likely to happen during hibernation.
To prevent it from happening, introduce the oom_killer_disabled switch that will cause __alloc_pages_internal() to fail in the situations in which the OOM killer would have been called and make the freezer set this switch after tasks have been successfully frozen.
--- include/linux/gfp.h | 12 ++++++++++++ kernel/power/process.c | 5 +++++ mm/page_alloc.c | 5 +++++ 3 files changed, 22 insertions(+)
mm/page_alloc.c +5 -0
@@ -175,6 +175,8 @@ static void set_pageblock_migratetype(st PB_migrate, PB_migrate_end); } +bool oom_killer_disabled__read_mostly ; +#ifdef CONFIG_DEBUG_VM static int page_outside_zone_boundaries (struct zone *zone,struct page *page) {
@@ -1600,6 +1602,9 @@ nofail_alloc:if (page) goto got_pg; }else if ((gfp_mask & __GFP_FS) && !(gfp_mask & __GFP_NORETRY)) { +if (oom_killer_disabled) + goto nopage; +if (!try_set_zone_oom (zonelist, gfp_mask)) {schedule_timeout_uninterruptible (1 ); goto restart;
include/linux/gfp.h +12 -0
@@ -245,4 +245,16 @@ void drain_zone_pages(struct zone *zone,void drain_all_pages (void );void drain_local_pages (void *dummy); +extern bool oom_killer_disabled; + +static inline void disable_oom_killer (void ) +{ + oom_killer_disabled = true; +} + +static inline void enable_oom_killer (void ) +{ + oom_killer_disabled = false; +} +#endif /* __LINUX_GFP_H */
kernel/power/process.c +5 -0
@@ -117,9 +117,12 @@ int freeze_processes(void)if (error) goto Exit;printk ("done." ); + +disable_oom_killer (); Exit:BUG_ON (in_atomic ());printk ("\n" ); +return error; }
@@ -145,6 +148,8 @@ static void thaw_tasks(bool nosig_only)void thaw_processes (void ) { +enable_oom_killer (); +printk ("Restarting tasks ... " );thaw_tasks (true);thaw_tasks (false);
Andrew Morton
maintainerRe: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
In reply to Rafael J. WysockiQuoted 14 lines · On Tue, 12 May 2009 01:28:15 +0200 "Rafael J. Wysocki" <[email protected]> wrote:
Quoted 13 lines · Andrew Morton
Quoted 3 lines · On Tue, 12 May 2009 00:44:36 +0200 "Rafael J. Wysocki" <[email protected]> wrote:
Which means this patch:
http://marc.info/?l=linux-kernel&m=124165031723627 (it also is my favourite one).ho hum, I could live with that ;)
Would it make sense to turn it into something more general? Instead of "tasks_frozen/processes_are_frozen()", present it as "oom_killer_disabled/oom_killer_is_disabled()"?
Quoted 8 lines
Quoted 2 lines
That would invite other subsystems to use it, if they want to. Which might well be a bad thing on their behalf, hard to say..
I chose the names this way because the variable is defined in the freezer code.
Alternatively, I can define one in
page_alloc.c, add [disable|enable]_oom_killer() for manipulating it and call them from the freezer code. Do you think that would be better?
The choice is:
a) put a general oom-killer interface function into the oom-killer code, call that from swsusp.
b) put a swsusp-specific change into the oom-killer, call that from swsusp.
Quoted 1 line
From a cleanliess POV, a) is way better. But it does need to be a
general function! If there's some hidden requirement which only makes the function applicable to swsusp, such as "all tasks must be frozen" then we'd be kidding ourselves by making it general-looking.
I have a bad feeling that after one week and 12^17 emails, we're back to your original patch :)
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
In reply to Andrew MortonQuoted 7 lines · Andrew Morton
Quoted 3 lines · On Tue, 12 May 2009 00:44:36 +0200 "Rafael J. Wysocki" <[email protected]> wrote:
Which means this patch:
http://marc.info/?l=linux-kernel&m=124165031723627 (it also is my favourite one).
Quoted 8 lines
ho hum, I could live with that ;)
Would it make sense to turn it into something more general? Instead of "tasks_frozen/processes_are_frozen()", present it as "oom_killer_disabled/oom_killer_is_disabled()"?
That would invite other subsystems to use it, if they want to. Which might well be a bad thing on their behalf, hard to say..
I chose the names this way because the variable is defined in the freezer code.
Alternatively, I can define one in page_alloc.c, add [disable|enable]_oom_killer() for manipulating it and call them from the freezer code. Do you think that would be better?
Andrew Morton
maintainerRe: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
In reply to Rafael J. WysockiQuoted 3 lines · On Tue, 12 May 2009 00:44:36 +0200 "Rafael J. Wysocki" <[email protected]> wrote:
Which means this patch:
http://marc.info/?l=linux-kernel&m=124165031723627 (it also is my favourite one).
ho hum, I could live with that ;)
Would it make sense to turn it into something more general? Instead of "tasks_frozen/processes_are_frozen()", present it as "oom_killer_disabled/oom_killer_is_disabled()"?
That would invite other subsystems to use it, if they want to. Which might well be a bad thing on their behalf, hard to say..
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
In reply to David RientjesQuoted 21 lines · David Rientjes
Quoted 9 lines · Rafael J. Wysocki
Quoted 6 lines
All order 0 allocations are implicitly
__GFP_NOFAILand will loop endlessly unless they can't block. So if you want to simply prohibit the oom killer from being invoked and not change the retry behavior, settingZONE_OOM_LOCKEDfor all zones will do that. If your machine hangs, it means nothing can be reclaimed and you can't free memory via oom killing, so there's nothing else the page allocator can do.But I want it to give up in this case instead of looping forever.
Quoted 9 lines
Look. I have a specific problem at hand that I want to solve and the approach you suggested _clearly_ _doesn't_ _work_. I have also tried to explain to you why it doesn't work, but you're ingnoring it, so I really don't know what else I can say.
OTOH, the approach suggested by Andrew _does_ _work_ regardless of your opinion about it. It's been tested and it's done the job 100% of the time. Go figure. And please stop beating the dead horse.
Quoted 6 lines
Which implementation are you talking about? You've had several:
http://marc.info/?l=linux-kernel&m=124121728429113 http://marc.info/?l=linux-kernel&m=124131049223733 http://marc.info/?l=linux-kernel&m=124165031723627 http://marc.info/?l=linux-kernel&m=124146681311494
The second one. The first one was too much code, the third one was not the Andrew's favourite and the last one is wrong, because it changes the behaviour related to __GFP_NORETRY incorrectly.
Quoted 3 lines
The issue with your approach is that it doesn't address the problem; the problem is _not_ specific to individual page allocations it is specific to the STATE OF THE MACHINE.
Yes, it is, but have you followed my discussion with Andrew?
Quoted 5 lines
If all userspace tasks are uninterruptible when trying to reserve this memory and, thus, oom killing is negligent and not going to help, that needs to be addressed in the page allocator. It is a bug for the allocator to continuously retry the allocation unless
__GFP_NOFAILis set if oom killing will not free memory.
That was my argument in the discussion with Andrew, actually.
Quoted 4 lines
Adding a new
__GFP_NO_OOM_KILLflag to address that isn't helpful since it has nothing at all to do with the specific allocation. It may certainly be the easiest way to implement your patchset without doing VM work, but it's not going to fix the problem for others.
I agree, but I didn't even want to fix the problem with OOM killing after freezing tasks.
Quoted 9 lines
I just posted a patch series[*] that would fix this problem for you without even locking out the oom killer or adding any unnecessary gfp flags. It is based on mmotm since it has Mel's page allocator speedups. Any change you do to the allocator at this point should be based on that to avoid nasty merge conflicts later, so try my series out and see how it works.
Now, I won't engage in your personal attacks because (i) nobody else cares, and (ii) it's not going to be productive.
My previous message wasn't meant to be personal, so I'm sorry if it sounded like it was.
Quoted 3 lines
I'll let my code do the talking.
OK, so the patch is http://lkml.org/lkml/2009/5/10/127, isn't it? I'm not sure it will fly, given the Andrew's reply.
In fact the problem is that processes in D state are only legitimately going to stay in this state when they are _frozen_. So, the right approach seems to be to avoid calling the OOM killer at all after freezing processes and instead fail the allocations that would have triggered it. Which means this patch:
http://marc.info/?l=linux-kernel&m=124165031723627 (it also is my favourite one).
But Andrew says that it's better to have a __GFP_NO_OOM_KILL flag instead, because someone else might presumably use it in future for something (I have no idea who that might be, but whatever) and _surely_ no one else will use a global switch related to the freezer.
Still _I_ think that since the freezer is the source of the problematic situation (all tasks are persistently unkillable), using it should change the behaviour of the page allocator, so that the OOM killer is not activated while processes are frozen. And in fact that should not depend on what flags are used by whoever tries to allocate memory.
Thanks,
Rafael
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
In reply to Rafael J. WysockiQuoted 9 lines · Rafael J. Wysocki
Quoted 6 lines
All order 0 allocations are implicitly
__GFP_NOFAILand will loop endlessly unless they can't block. So if you want to simply prohibit the oom killer from being invoked and not change the retry behavior, settingZONE_OOM_LOCKEDfor all zones will do that. If your machine hangs, it means nothing can be reclaimed and you can't free memory via oom killing, so there's nothing else the page allocator can do.But I want it to give up in this case instead of looping forever.
Quoted 9 lines
Look. I have a specific problem at hand that I want to solve and the approach you suggested _clearly_ _doesn't_ _work_. I have also tried to explain to you why it doesn't work, but you're ingnoring it, so I really don't know what else I can say.
OTOH, the approach suggested by Andrew _does_ _work_ regardless of your opinion about it. It's been tested and it's done the job 100% of the time. Go figure. And please stop beating the dead horse.
Which implementation are you talking about? You've had several:
http://marc.info/?l=linux-kernel&m=124121728429113 http://marc.info/?l=linux-kernel&m=124131049223733 http://marc.info/?l=linux-kernel&m=124165031723627 http://marc.info/?l=linux-kernel&m=124146681311494
The issue with your approach is that it doesn't address the problem; the problem is _not_ specific to individual page allocations it is specific to the STATE OF THE MACHINE.
If all userspace tasks are uninterruptible when trying to reserve this memory and, thus, oom killing is negligent and not going to help, that needs to be addressed in the page allocator. It is a bug for the allocator to continuously retry the allocation unless __GFP_NOFAIL is set if oom killing will not free memory.
Adding a new __GFP_NO_OOM_KILL flag to address that isn't helpful since it has nothing at all to do with the specific allocation. It may certainly be the easiest way to implement your patchset without doing VM work, but it's not going to fix the problem for others.
I just posted a patch series[*] that would fix this problem for you without even locking out the oom killer or adding any unnecessary gfp flags. It is based on mmotm since it has Mel's page allocator speedups. Any change you do to the allocator at this point should be based on that to avoid nasty merge conflicts later, so try my series out and see how it works.
Now, I won't engage in your personal attacks because (i) nobody else cares, and (ii) it's not going to be productive. I'll let my code do the talking.
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
In reply to David RientjesQuoted 16 lines · David Rientjes
Quoted 4 lines · Rafael J. Wysocki
Quoted 4 lines
This has been changed in the latest mmotm with Mel's page alloactor patches (and I think yours should be based on mmotm). Specifically, page-allocator-break-up-the-allocator-entry-point-into-fast-and-slow-paths.patch.
Quoted 9 lines
Quoted 6 lines
Before his patchset, zonelists that had
ZONE_OOM_LOCKEDset for at least one of their zones would unconditionally goto restart. Now, if order >PAGE_ALLOC_COSTLY_ORDER, it gives up and returns NULL. Otherwise, it does goto restart.So if your allocation has order >
PAGE_ALLOC_COSTLY_ORDER,It doesn't. All of my allocations are of order 0.
Quoted 6 lines
All order 0 allocations are implicitly
__GFP_NOFAILand will loop endlessly unless they can't block. So if you want to simply prohibit the oom killer from being invoked and not change the retry behavior, settingZONE_OOM_LOCKEDfor all zones will do that. If your machine hangs, it means nothing can be reclaimed and you can't free memory via oom killing, so there's nothing else the page allocator can do.
But I want it to give up in this case instead of looping forever.
Look. I have a specific problem at hand that I want to solve and the approach you suggested _clearly_ _doesn't_ _work_. I have also tried to explain to you why it doesn't work, but you're ingnoring it, so I really don't know what else I can say.
OTOH, the approach suggested by Andrew _does_ _work_ regardless of your opinion about it. It's been tested and it's done the job 100% of the time. Go figure. And please stop beating the dead horse.
Thanks,
Rafael
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
In reply to Rafael J. WysockiQuoted 4 lines · Rafael J. Wysocki
Quoted 4 lines
This has been changed in the latest mmotm with Mel's page alloactor patches (and I think yours should be based on mmotm). Specifically, page-allocator-break-up-the-allocator-entry-point-into-fast-and-slow-paths.patch.
Quoted 9 lines
Quoted 6 lines
Before his patchset, zonelists that had
ZONE_OOM_LOCKEDset for at least one of their zones would unconditionally goto restart. Now, if order >PAGE_ALLOC_COSTLY_ORDER, it gives up and returns NULL. Otherwise, it does goto restart.So if your allocation has order >
PAGE_ALLOC_COSTLY_ORDER,It doesn't. All of my allocations are of order 0.
All order 0 allocations are implicitly __GFP_NOFAIL and will loop endlessly unless they can't block. So if you want to simply prohibit the oom killer from being invoked and not change the retry behavior, setting ZONE_OOM_LOCKED for all zones will do that. If your machine hangs, it means nothing can be reclaimed and you can't free memory via oom killing, so there's nothing else the page allocator can do.
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
In reply to David RientjesQuoted 32 lines · David Rientjes
Quoted 16 lines · Rafael J. Wysocki
Quoted 8 lines
All of your tasks are in D state other than kthreads, right? That means they won't be in the oom killer (thus no zones are oom locked), so you can easily do this
struct zone *z; for_each_populated_zone(z) zone_set_flag(z, ZONE_OOM_LOCKED);Quoted 7 lines
and then
for_each_populated_zone(z) zone_clear_flag(z, ZONE_OOM_LOCKED);The serialization is done with trylocks so this will never invoke the oom killer because all zones in the allocator's zonelist will be oom locked.
Quoted 9 lines
Well, that might have been a good idea if it actually had worked. :-(
Quoted 1 line
Why does this not work for you?
If I set
image_sizeto something below "hard core working set" +totalreserve_pages,preallocate_image_memory()hangs the box (please refer to the last patch I sent,
http://patchwork.kernel.org/patch/22423/).This has been changed in the latest mmotm with Mel's page alloactor patches (and I think yours should be based on mmotm). Specifically, page-allocator-break-up-the-allocator-entry-point-into-fast-and-slow-paths.patch.
Quoted 6 lines
Before his patchset, zonelists that had
ZONE_OOM_LOCKEDset for at least one of their zones would unconditionally goto restart. Now, if order >PAGE_ALLOC_COSTLY_ORDER, it gives up and returns NULL. Otherwise, it does goto restart.So if your allocation has order >
PAGE_ALLOC_COSTLY_ORDER,
It doesn't. All of my allocations are of order 0.
Quoted 2 lines
using the
ZONE_OOM_LOCKEDapproach to locking out the oom killer will work just fine in mmotm.
No, it won't, AFAICT.
Best,
Rafael
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
In reply to Rafael J. WysockiQuoted 16 lines · Rafael J. Wysocki
Quoted 8 lines
All of your tasks are in D state other than kthreads, right? That means they won't be in the oom killer (thus no zones are oom locked), so you can easily do this
struct zone *z; for_each_populated_zone(z) zone_set_flag(z, ZONE_OOM_LOCKED);Quoted 7 lines
and then
for_each_populated_zone(z) zone_clear_flag(z, ZONE_OOM_LOCKED);The serialization is done with trylocks so this will never invoke the oom killer because all zones in the allocator's zonelist will be oom locked.
Quoted 9 lines
Well, that might have been a good idea if it actually had worked. :-(
Quoted 1 line
Why does this not work for you?
If I set
image_sizeto something below "hard core working set" +totalreserve_pages,preallocate_image_memory()hangs the box (please refer to the last patch I sent,
http://patchwork.kernel.org/patch/22423/).
This has been changed in the latest mmotm with Mel's page alloactor patches (and I think yours should be based on mmotm). Specifically, page-allocator-break-up-the-allocator-entry-point-into-fast-and-slow-paths.patch.
Before his patchset, zonelists that had ZONE_OOM_LOCKED set for at least one of their zones would unconditionally goto restart. Now, if order > PAGE_ALLOC_COSTLY_ORDER, it gives up and returns NULL. Otherwise, it does goto restart.
So if your allocation has order > PAGE_ALLOC_COSTLY_ORDER, using the ZONE_OOM_LOCKED approach to locking out the oom killer will work just fine in mmotm.
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
In reply to David RientjesQuoted 17 lines · David Rientjes
Quoted 3 lines · Rafael J. Wysocki
OK, let's try with
__GFP_NO_OOM_KILLfirst. If there's too much disagreement, I'll use the freezer-based approach instead.Third time I'm going to suggest this, and I'd like a response on why it's not possible instead of being ignored.
All of your tasks are in D state other than kthreads, right? That means they won't be in the oom killer (thus no zones are oom locked), so you can easily do this
struct zone *z; for_each_populated_zone(z) zone_set_flag(z, ZONE_OOM_LOCKED);
Quoted 7 lines
and then
for_each_populated_zone(z) zone_clear_flag(z, ZONE_OOM_LOCKED);The serialization is done with trylocks so this will never invoke the oom killer because all zones in the allocator's zonelist will be oom locked.
Well, that might have been a good idea if it actually had worked. :-(
Quoted 1 line
Why does this not work for you?
If I set image_size to something below "hard core working set" + totalreserve_pages, preallocate_image_memory() hangs the box (please refer to the last patch I sent,
http://patchwork.kernel.org/patch/22423/).
However, with the freezer-based disabling of the OOM killer it doesn't hang under the same test conditions.
The difference appears to be that using your approach makes __alloc_pages_internal() loop forever between the !try_set_zone_oom() test and restart:, while it should go to nopage: in that situation.
So, I think I'll stick to the Andrew's approach with using __GFP_NO_OOM_KILL.
Thanks,
Rafael
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
In reply to Rafael J. WysockiQuoted 3 lines · Rafael J. Wysocki
OK, let's try with
__GFP_NO_OOM_KILLfirst. If there's too much disagreement, I'll use the freezer-based approach instead.
Third time I'm going to suggest this, and I'd like a response on why it's not possible instead of being ignored.
All of your tasks are in D state other than kthreads, right? That means they won't be in the oom killer (thus no zones are oom locked), so you can easily do this
struct zone *z; for_each_populated_zone(z) zone_set_flag(z, ZONE_OOM_LOCKED);
and then
for_each_populated_zone(z) zone_clear_flag(z, ZONE_OOM_LOCKED);
The serialization is done with trylocks so this will never invoke the oom killer because all zones in the allocator's zonelist will be oom locked.
Why does this not work for you?
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
In reply to Andrew MortonQuoted 34 lines · Andrew Morton
Quoted 20 lines · On Thu, 7 May 2009 21:33:47 +0200 "Rafael J. Wysocki" <[email protected]> wrote:
Quoted 19 lines · Andrew Morton
Quoted 6 lines · On Thu, 7 May 2009 20:09:52 +0200 "Rafael J. Wysocki" <[email protected]> wrote:
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
I'm suspecting that hibernation can allocate its pages with __GFP_FS|__GFP_WAIT|__GFP_NORETRY|__GFP_NOWARN, and the page allocator will dtrt: no oom-killings.
In which case,
processes_are_frozen()is not needed at all?Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
__GFP_NORETRYalone causes it to fail relatively quickly, but I'll try with the combination.OK.
__GFP_WAITis the big hammer.Unfortunately it fails too quickly with the combination as well, so it looks like we can't use
__GFP_NORETRYduring hibernation.hm.
Quoted 8 lines
Quoted 5 lines
So where do we stand now?
I'm not a big fan of the global application-specific state change thing. Something like
__GFP_NO_OOM_KILLhas a better chance of being reused by other subsystems in the future, which is a good indicator.I'm not against
__GFP_NO_OOM_KILL, but there's been some strong resistance to adding new_GPF_FOOflags recently.We have six or seven left - hardly a crisis.
Quoted 8 lines
Quoted 2 lines
Is there any likelihood anyone else we'll
really need it any time soon?Dunno - people do all sorts of crazy things. But it's more likely to be reused than a PM-specific global!
I have no strong feelings really, but slotting into the existing technique with something which might be reusable is quite a bit tidier.
OK, let's try with __GFP_NO_OOM_KILL first. If there's too much disagreement, I'll use the freezer-based approach instead.
Andrew Morton
maintainerRe: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
In reply to Rafael J. WysockiQuoted 20 lines · On Thu, 7 May 2009 21:33:47 +0200 "Rafael J. Wysocki" <[email protected]> wrote:
Quoted 19 lines · Andrew Morton
Quoted 6 lines · On Thu, 7 May 2009 20:09:52 +0200 "Rafael J. Wysocki" <[email protected]> wrote:
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
I'm suspecting that hibernation can allocate its pages with __GFP_FS|__GFP_WAIT|__GFP_NORETRY|__GFP_NOWARN, and the page allocator will dtrt: no oom-killings.
In which case,
processes_are_frozen()is not needed at all?Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
__GFP_NORETRYalone causes it to fail relatively quickly, but I'll try with the combination.OK.
__GFP_WAITis the big hammer.Unfortunately it fails too quickly with the combination as well, so it looks like we can't use
__GFP_NORETRYduring hibernation.hm.
Quoted 8 lines
Quoted 5 lines
So where do we stand now?
I'm not a big fan of the global application-specific state change thing. Something like
__GFP_NO_OOM_KILLhas a better chance of being reused by other subsystems in the future, which is a good indicator.I'm not against
__GFP_NO_OOM_KILL, but there's been some strong resistance to adding new_GPF_FOOflags recently.
We have six or seven left - hardly a crisis.
Quoted 2 lines
Is there any likelihood anyone else we'll
really need it any time soon?
Dunno - people do all sorts of crazy things. But it's more likely to be reused than a PM-specific global!
I have no strong feelings really, but slotting into the existing technique with something which might be reusable is quite a bit tidier.
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
In reply to Andrew MortonQuoted 17 lines · Andrew Morton
Quoted 6 lines · On Thu, 7 May 2009 20:09:52 +0200 "Rafael J. Wysocki" <[email protected]> wrote:
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
I'm suspecting that hibernation can allocate its pages with __GFP_FS|__GFP_WAIT|__GFP_NORETRY|__GFP_NOWARN, and the page allocator will dtrt: no oom-killings.
In which case,
processes_are_frozen()is not needed at all?Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
__GFP_NORETRYalone causes it to fail relatively quickly, but I'll try with the combination.OK.
__GFP_WAITis the big hammer.Unfortunately it fails too quickly with the combination as well, so it looks like we can't use
__GFP_NORETRYduring hibernation.
Quoted 7 lines
hm.
So where do we stand now?
I'm not a big fan of the global application-specific state change thing. Something like
__GFP_NO_OOM_KILLhas a better chance of being reused by other subsystems in the future, which is a good indicator.
I'm not against __GFP_NO_OOM_KILL, but there's been some strong resistance to adding new _GPF _FOO flags recently. Is there any likelihood anyone else we'll really need it any time soon?
The advantage of the freezer-based approach is that it disables the OOM killer when it's not going to work anyway, so it looks like a reasonable thing to do regardless. IMHO.
Andrew Morton
maintainerRe: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
In reply to Rafael J. WysockiQuoted 6 lines · On Thu, 7 May 2009 20:09:52 +0200 "Rafael J. Wysocki" <[email protected]> wrote:
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
I'm suspecting that hibernation can allocate its pages with __GFP_FS|__GFP_WAIT|__GFP_NORETRY|__GFP_NOWARN, and the page allocator will dtrt: no oom-killings.
In which case,
processes_are_frozen()is not needed at all?
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
__GFP_NORETRYalone causes it to fail relatively quickly, but I'll try with the combination.OK.
__GFP_WAITis the big hammer.Unfortunately it fails too quickly with the combination as well, so it looks like we can't use
__GFP_NORETRYduring hibernation.
hm.
So where do we stand now?
I'm not a big fan of the global application-specific state change thing. Something like __GFP_NO_OOM_KILL has a better chance of being reused by other subsystems in the future, which is a good indicator.
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
In reply to Rafael J. WysockiQuoted 3 lines · Rafael J. Wysocki
Unfortunately it fails too quickly with the combination as well, so it looks like we can't use
__GFP_NORETRYduring hibernation.
If you know that no other tasks are in the oom killer at suspend time, you can do what I mentioned earlier:
struct zone *z; for_each_populated_zone(z) zone_set_flag(z, ZONE_OOM_LOCKED);
and then later
for_each_populated_zone(z) zone_clear_flag(z, ZONE_OOM_LOCKED);
The only race there is if a task is currently in the oom killer and will subsequently clear ZONE_OOM_LOCKED for its zonelist.
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
In reply to Rafael J. WysockiQuoted 3 lines · Rafael J. Wysocki
Unfortunately it fails too quickly with the combination as well, so it looks like we can't use
__GFP_NORETRYduring hibernation.
If you know that no other tasks are in the oom killer at suspend time, you can do what I mentioned earlier:
struct zone *z; for_each_populated_zone(z) zone_set_flag(z, ZONE_OOM_LOCKED);
and then later
for_each_populated_zone(z) zone_clear_flag(z, ZONE_OOM_LOCKED);
The only race there is if a task is currently in the oom killer and will subsequently clear ZONE_OOM_LOCKED for its zonelist.
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
In reply to Andrew MortonQuoted 31 lines · Andrew Morton
Quoted 28 lines · On Wed, 6 May 2009 01:20:34 +0200 "Rafael J. Wysocki" <[email protected]> wrote:
Quoted 27 lines · Andrew Morton
Quoted 10 lines · On Wed, 6 May 2009 00:19:35 +0200 "Rafael J. Wysocki" <[email protected]> wrote:
Quoted 7 lines
mm/page_alloc.c nofail_alloc: · line 1607
Quoted 4 lines
mm/page_alloc.c +1
-0+ && !processes_are_frozen()) {if (!try_set_zone_oom (zonelist, gfp_mask)) {schedule_timeout_uninterruptible (1 ); goto restart;Cool, that looks like the semantics of
__GFP_NO_OOM_KILLwithout requiring a new gfp flag. Thanks.Well, you're welcome.
Quoted 7 lines
BTW, I think that Andrew was actually right when he asked if I checked whether the existing
__GFP_NORETRYwould work as-is for__GFP_FSset and__GFP_NORETRYunset. Namely, in that case we never reach the code before
nopage: that checks__GFP_NORETRY, do we?So I think we shouldn't modify the 'else if' condition above and check for !processes_are_frozen() at the beginning of the block below.
Confused.
I'm suspecting that hibernation can allocate its pages with __GFP_FS|__GFP_WAIT|__GFP_NORETRY|__GFP_NOWARN, and the page allocator will dtrt: no oom-killings.
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
In which case,
processes_are_frozen()is not needed at all?
__GFP_NORETRYalone causes it to fail relatively quickly, but I'll try with the combination.OK.
__GFP_WAITis the big hammer.
Unfortunately it fails too quickly with the combination as well, so it looks like we can't use __GFP_NORETRY during hibernation.
Andrew Morton
maintainerRe: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
In reply to Rafael J. WysockiQuoted 24 lines · On Wed, 6 May 2009 01:20:34 +0200 "Rafael J. Wysocki" <[email protected]> wrote:
Quoted 23 lines · Andrew Morton
Quoted 10 lines · On Wed, 6 May 2009 00:19:35 +0200 "Rafael J. Wysocki" <[email protected]> wrote:
Quoted 7 lines
mm/page_alloc.c nofail_alloc: · line 1607
Quoted 4 lines
mm/page_alloc.c +1
-0+ && !processes_are_frozen()) {if (!try_set_zone_oom (zonelist, gfp_mask)) {schedule_timeout_uninterruptible (1 ); goto restart;Cool, that looks like the semantics of
__GFP_NO_OOM_KILLwithout requiring a new gfp flag. Thanks.Well, you're welcome.
Quoted 7 lines
BTW, I think that Andrew was actually right when he asked if I checked whether the existing
__GFP_NORETRYwould work as-is for__GFP_FSset and__GFP_NORETRYunset. Namely, in that case we never reach the code before
nopage: that checks__GFP_NORETRY, do we?So I think we shouldn't modify the 'else if' condition above and check for !processes_are_frozen() at the beginning of the block below.
Confused.
Quoted 8 lines
Quoted 5 lines
I'm suspecting that hibernation can allocate its pages with __GFP_FS|__GFP_WAIT|__GFP_NORETRY|__GFP_NOWARN, and the page allocator will dtrt: no oom-killings.
In which case,
processes_are_frozen()is not needed at all?
__GFP_NORETRYalone causes it to fail relatively quickly, but I'll try with the combination.
OK. __GFP_WAIT is the big hammer.
Quoted 4 lines
Anyway, even if the hibernation code itself doesn't trigger the OOM killer, but anyone else allocates memory in parallel or after we've preallocated the image memory, that may still trigger it. So it seems
processes_are_frozen()may still be useful?
Could be. But only kernel threads are active at this time (yes?), and they won't have much work to do because userspace is asleep.
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
In reply to Andrew MortonQuoted 21 lines · Andrew Morton
Quoted 10 lines · On Wed, 6 May 2009 00:19:35 +0200 "Rafael J. Wysocki" <[email protected]> wrote:
Quoted 7 lines
mm/page_alloc.c nofail_alloc: · line 1607
Quoted 4 lines
mm/page_alloc.c +1
-0+ && !processes_are_frozen()) {if (!try_set_zone_oom (zonelist, gfp_mask)) {schedule_timeout_uninterruptible (1 ); goto restart;Cool, that looks like the semantics of
__GFP_NO_OOM_KILLwithout requiring a new gfp flag. Thanks.Well, you're welcome.
Quoted 7 lines
BTW, I think that Andrew was actually right when he asked if I checked whether the existing
__GFP_NORETRYwould work as-is for__GFP_FSset and__GFP_NORETRYunset. Namely, in that case we never reach the code before
nopage: that checks__GFP_NORETRY, do we?So I think we shouldn't modify the 'else if' condition above and check for !processes_are_frozen() at the beginning of the block below.
Quoted 7 lines
Confused.
I'm suspecting that hibernation can allocate its pages with __GFP_FS|__GFP_WAIT|__GFP_NORETRY|__GFP_NOWARN, and the page allocator will dtrt: no oom-killings.
In which case,
processes_are_frozen()is not needed at all?
__GFP_NORETRY alone causes it to fail relatively quickly, but I'll try with the combination.
Anyway, even if the hibernation code itself doesn't trigger the OOM killer, but anyone else allocates memory in parallel or after we've preallocated the image memory, that may still trigger it. So it seems processes_are_frozen() may still be useful?
Andrew Morton
maintainerRe: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
In reply to Rafael J. WysockiQuoted 10 lines · On Wed, 6 May 2009 00:19:35 +0200 "Rafael J. Wysocki" <[email protected]> wrote:
Quoted 7 lines
mm/page_alloc.c nofail_alloc: · line 1607
Quoted 4 lines
mm/page_alloc.c +1
-0+ && !processes_are_frozen()) {if (!try_set_zone_oom (zonelist, gfp_mask)) {schedule_timeout_uninterruptible (1 ); goto restart;Cool, that looks like the semantics of
__GFP_NO_OOM_KILLwithout requiring a new gfp flag. Thanks.Well, you're welcome.
Quoted 7 lines
BTW, I think that Andrew was actually right when he asked if I checked whether the existing
__GFP_NORETRYwould work as-is for__GFP_FSset and__GFP_NORETRYunset. Namely, in that case we never reach the code before
nopage: that checks__GFP_NORETRY, do we?So I think we shouldn't modify the 'else if' condition above and check for !processes_are_frozen() at the beginning of the block below.
Confused.
I'm suspecting that hibernation can allocate its pages with __GFP_FS|__GFP_WAIT|__GFP_NORETRY|__GFP_NOWARN, and the page allocator will dtrt: no oom-killings.
In which case, processes_are_frozen() is not needed at all?
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
In reply to David RientjesQuoted 73 lines · David Rientjes
Quoted 71 lines · Rafael J. Wysocki
Index:
linux-2.6/kernel/power/process.c
===================================================================kernel/power/process.c +12
-0@@ -19,6 +19,8 @@*/ #define TIMEOUT (20 * HZ) +static bool tasks_frozen; +static inline int freezeable (struct task_struct * p) { if ((p == current) ||@@ -120,6 +122,10 @@ int freeze_processes(void) Exit:BUG_ON (in_atomic ());printk ("\n" ); + +if (!error) + tasks_frozen = true; +return error; }@@ -145,6 +151,8 @@ static void thaw_tasks(bool nosig_only)void thaw_processes (void ) { + tasks_frozen = false; +printk ("Restarting tasks ... " );thaw_tasks (true);thaw_tasks (false);@@ -152,3 +160,7 @@ void thaw_processes(void)printk ("done.\n" ); } +bool processes_are_frozen (void ) +{ +return tasks_frozen; +}Index:
linux-2.6/include/linux/freezer.h
===================================================================include/linux/freezer.h +2
-0@@ -50,6 +50,7 @@ extern int thaw_process(struct task_struextern void refrigerator (void );extern int freeze_processes (void );extern void thaw_processes (void ); +extern bool processes_are_frozen (void );static inline int try_to_freeze (void ) {@@ -170,6 +171,7 @@ static inline int thaw_process(struct tastatic inline void refrigerator (void ) {}static inline int freeze_processes (void ) {BUG ();return 0 ; }static inline void thaw_processes (void ) {} +static inline bool processes_are_frozen (void ) {return false; }static inline int try_to_freeze (void ) {return 0 ; }Index:
linux-2.6/mm/page_alloc.c
===================================================================mm/page_alloc.c +1
-0@@ -46,6 +46,7 @@#include <linux/page-isolation.h> #include <linux/page_cgroup.h> #include <linux/debugobjects.h> +#include <linux/freezer.h>
Quoted 15 lines
mm/page_alloc.c nofail_alloc: · line 1607
Quoted 12 lines
mm/page_alloc.c +2
-1#include <asm/tlbflush.h> #include <asm/div64.h> @@ -1599,7 +1600,8 @@ nofail_alloc: zonelist, high_zoneidx, alloc_flags);if (page) goto got_pg; - }else if ((gfp_mask & __GFP_FS) && !(gfp_mask & __GFP_NORETRY)) { + }else if ((gfp_mask & __GFP_FS) && !(gfp_mask & __GFP_NORETRY) + && !processes_are_frozen ()) {if (!try_set_zone_oom (zonelist, gfp_mask)) {schedule_timeout_uninterruptible (1 ); goto restart;Cool, that looks like the semantics of
__GFP_NO_OOM_KILLwithout requiring a new gfp flag. Thanks.
Well, you're welcome.
BTW, I think that Andrew was actually right when he asked if I checked whether the existing __GFP_NORETRY would work as-is for __GFP_FS set and __GFP_NORETRY unset. Namely, in that case we never reach the code before
nopage: that checks __GFP_NORETRY, do we?
So I think we shouldn't modify the 'else if' condition above and check for !processes_are_frozen() at the beginning of the block below.
Thanks,
Rafael
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
In reply to Rafael J. WysockiQuoted 74 lines · Rafael J. Wysocki
Index:
linux-2.6/kernel/power/process.c
===================================================================kernel/power/process.c +12
-0@@ -19,6 +19,8 @@*/ #define TIMEOUT (20 * HZ) +static bool tasks_frozen; +static inline int freezeable (struct task_struct * p) { if ((p == current) ||@@ -120,6 +122,10 @@ int freeze_processes(void) Exit:BUG_ON (in_atomic ());printk ("\n" ); + +if (!error) + tasks_frozen = true; +return error; }@@ -145,6 +151,8 @@ static void thaw_tasks(bool nosig_only)void thaw_processes (void ) { + tasks_frozen = false; +printk ("Restarting tasks ... " );thaw_tasks (true);thaw_tasks (false);@@ -152,3 +160,7 @@ void thaw_processes(void)printk ("done.\n" ); } +bool processes_are_frozen (void ) +{ +return tasks_frozen; +}Index:
linux-2.6/include/linux/freezer.h
===================================================================include/linux/freezer.h +2
-0@@ -50,6 +50,7 @@ extern int thaw_process(struct task_struextern void refrigerator (void );extern int freeze_processes (void );extern void thaw_processes (void ); +extern bool processes_are_frozen (void );static inline int try_to_freeze (void ) {@@ -170,6 +171,7 @@ static inline int thaw_process(struct tastatic inline void refrigerator (void ) {}static inline int freeze_processes (void ) {BUG ();return 0 ; }static inline void thaw_processes (void ) {} +static inline bool processes_are_frozen (void ) {return false; }static inline int try_to_freeze (void ) {return 0 ; }Index:
linux-2.6/mm/page_alloc.c
===================================================================mm/page_alloc.c +1
-0@@ -46,6 +46,7 @@#include <linux/page-isolation.h> #include <linux/page_cgroup.h> #include <linux/debugobjects.h> +#include <linux/freezer.h> #include <asm/tlbflush.h> #include <asm/div64.h>
mm/page_alloc.c nofail_alloc: · line 1607
Quoted 9 lines
mm/page_alloc.c +2
-1@@ -1599,7 +1600,8 @@ nofail_alloc: zonelist, high_zoneidx, alloc_flags);if (page) goto got_pg; - }else if ((gfp_mask & __GFP_FS) && !(gfp_mask & __GFP_NORETRY)) { + }else if ((gfp_mask & __GFP_FS) && !(gfp_mask & __GFP_NORETRY) + && !processes_are_frozen ()) {if (!try_set_zone_oom (zonelist, gfp_mask)) {schedule_timeout_uninterruptible (1 ); goto restart;
Cool, that looks like the semantics of __GFP_NO_OOM_KILL without requiring a new gfp flag. Thanks.
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
In reply to David RientjesQuoted 30 lines · David Rientjes
Quoted 28 lines · Rafael J. Wysocki
Index:
linux-2.6/mm/page_alloc.c
===================================================================mm/page_alloc.c +2
-1@@ -1599,7 +1599,8 @@ nofail_alloc: zonelist, high_zoneidx, alloc_flags);if (page) goto got_pg; - }else if ((gfp_mask & __GFP_FS) && !(gfp_mask & __GFP_NORETRY)) { + }else if ((gfp_mask & __GFP_FS) && !(gfp_mask & __GFP_NORETRY) + && !(gfp_mask & __GFP_NO_OOM_KILL)) {if (!try_set_zone_oom (zonelist, gfp_mask)) {schedule_timeout_uninterruptible (1 ); goto restart;Index:
linux-2.6/include/linux/gfp.h
===================================================================include/linux/gfp.h +2
-1@@ -51,8 +51,9 @@ struct vm_area_struct;#define __GFP_THISNODE ((__force gfp_t)0x40000u)/* No fallback, no policies */ #define __GFP_RECLAIMABLE ((__force gfp_t)0x80000u)/* Page is reclaimable */ #define __GFP_MOVABLE ((__force gfp_t)0x100000u)/* Page is movable */ +#define __GFP_NO_OOM_KILL ((__force gfp_t)0x200000u)/* Don't invoke out_of_memory() */ -#define __GFP_BITS_SHIFT 21/* Room for 21 __GFP_FOO bits */ +#define __GFP_BITS_SHIFT 22/* Number of __GFP_FOO bits */ #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
Quoted 6 lines
include/linux/gfp.h struct vm_area_struct; · line 59
Quoted 2 lines
include/linux/gfp.h +0
-0/* This equals 0, but use constants in case they ever change */ Yeah, that's much better, thanks. There's currently concerns about adding a new gfp flag in another thread (
__GFP_PANIC), though, so you might find some resistance in adding a flag with a very specific and limited use cae.
Oh great. Andrew, what's your opinion?
Quoted 9 lines
I think you might have better luck in doing
struct zone *z; for_each_populated_zone(z) zone_set_flag(z, ZONE_OOM_LOCKED);if all other tasks are really in D state at this point since oom killer serialization is done with try locks in the page allocator.
Not all of them, actually. Some kernel threads are not freezable.
Quoted 1 line
This is equivalent to
__GFP_NO_OOM_KILL.
In that case I think I'd go back to my initial idea with disabling the OOM killer after freezing tasks.
Roughly, this. [The idea is that the OOM killer is not really going to work while tasks are frozen, so we can just give up calling it in that case.]
--- include/linux/freezer.h | 2 ++ kernel/power/process.c | 12 ++++++++++++ mm/page_alloc.c | 4 +++- 3 files changed, 17 insertions(+), 1 deletion(-)
kernel/power/process.c +12 -0
@@ -19,6 +19,8 @@*/ #define TIMEOUT (20 * HZ) +static bool tasks_frozen; +static inline int freezeable (struct task_struct * p) { if ((p == current) ||
@@ -120,6 +122,10 @@ int freeze_processes(void) Exit:BUG_ON (in_atomic ());printk ("\n" ); + +if (!error) + tasks_frozen = true; +return error; }
@@ -145,6 +151,8 @@ static void thaw_tasks(bool nosig_only)void thaw_processes (void ) { + tasks_frozen = false; +printk ("Restarting tasks ... " );thaw_tasks (true);thaw_tasks (false);
@@ -152,3 +160,7 @@ void thaw_processes(void)printk ("done.\n" ); } +bool processes_are_frozen (void ) +{ +return tasks_frozen; +}
include/linux/freezer.h +2 -0
@@ -50,6 +50,7 @@ extern int thaw_process(struct task_struextern void refrigerator (void );extern int freeze_processes (void );extern void thaw_processes (void ); +extern bool processes_are_frozen (void );static inline int try_to_freeze (void ) {
@@ -170,6 +171,7 @@ static inline int thaw_process(struct tastatic inline void refrigerator (void ) {}static inline int freeze_processes (void ) {BUG ();return 0 ; }static inline void thaw_processes (void ) {} +static inline bool processes_are_frozen (void ) {return false; }static inline int try_to_freeze (void ) {return 0 ; }
mm/page_alloc.c +3 -1
@@ -46,6 +46,7 @@#include <linux/page-isolation.h> #include <linux/page_cgroup.h> #include <linux/debugobjects.h> +#include <linux/freezer.h> #include <asm/tlbflush.h> #include <asm/div64.h>
@@ -1599,7 +1600,8 @@ nofail_alloc: zonelist, high_zoneidx, alloc_flags);if (page) goto got_pg; - }else if ((gfp_mask & __GFP_FS) && !(gfp_mask & __GFP_NORETRY)) { + }else if ((gfp_mask & __GFP_FS) && !(gfp_mask & __GFP_NORETRY) + && !processes_are_frozen ()) {if (!try_set_zone_oom (zonelist, gfp_mask)) {schedule_timeout_uninterruptible (1 ); goto restart;
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
In reply to Rafael J. WysockiQuoted 20 lines · Rafael J. Wysocki
Index:
linux-2.6/mm/page_alloc.c
===================================================================mm/page_alloc.c +2
-1@@ -1599,7 +1599,8 @@ nofail_alloc: zonelist, high_zoneidx, alloc_flags);if (page) goto got_pg; - }else if ((gfp_mask & __GFP_FS) && !(gfp_mask & __GFP_NORETRY)) { + }else if ((gfp_mask & __GFP_FS) && !(gfp_mask & __GFP_NORETRY) + && !(gfp_mask & __GFP_NO_OOM_KILL)) {if (!try_set_zone_oom (zonelist, gfp_mask)) {schedule_timeout_uninterruptible (1 ); goto restart;Index:
linux-2.6/include/linux/gfp.h
===================================================================
include/linux/gfp.h struct vm_area_struct; · line 59
Quoted 10 lines
include/linux/gfp.h +2
-1@@ -51,8 +51,9 @@ struct vm_area_struct;#define __GFP_THISNODE ((__force gfp_t)0x40000u)/* No fallback, no policies */ #define __GFP_RECLAIMABLE ((__force gfp_t)0x80000u)/* Page is reclaimable */ #define __GFP_MOVABLE ((__force gfp_t)0x100000u)/* Page is movable */ +#define __GFP_NO_OOM_KILL ((__force gfp_t)0x200000u)/* Don't invoke out_of_memory() */ -#define __GFP_BITS_SHIFT 21/* Room for 21 __GFP_FOO bits */ +#define __GFP_BITS_SHIFT 22/* Number of __GFP_FOO bits */ #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))/* This equals 0, but use constants in case they ever change */
Yeah, that's much better, thanks. There's currently concerns about adding a new gfp flag in another thread (__GFP_PANIC), though, so you might find some resistance in adding a flag with a very specific and limited use cae.
I think you might have better luck in doing
struct zone *z; for_each_populated_zone(z) zone_set_flag(z, ZONE_OOM_LOCKED);
if all other tasks are really in D state at this point since oom killer serialization is done with try locks in the page allocator. This is equivalent to __GFP_NO_OOM_KILL.
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
In reply to David RientjesQuoted 21 lines · David Rientjes
Quoted 19 lines · Rafael J. Wysocki
Quoted 18 lines
Quoted 5 lines
Index:
linux-2.6/mm/page_alloc.c
===================================================================mm/page_alloc.c nofail_alloc: · line 1627
Quoted 9 lines
mm/page_alloc.c +2
-1@@ -1620,7 +1620,8 @@ nofail_alloc: }/* The OOM killer will not help higher order allocs so fail */ -if (order >PAGE_ALLOC_COSTLY_ORDER ) { +if (order >PAGE_ALLOC_COSTLY_ORDER || + (gfp_mask & __GFP_NO_OOM_KILL)) {clear_zonelist_oom (zonelist, gfp_mask); goto nopage; }This is inconsistent because
__GFP_NO_OOM_KILLnow implies__GFP_NORETRY(the "goto nopage" above), but only for allocations with__GFP_FSset and__GFP_NORETRYclear.
Quoted 7 lines
Quoted 2 lines
Well, what would you suggest?
A couple things:
- rebase this on mmotm so that it doesn't conflict with Mel Gorman's page allocator speedup changes, and
I'm going to rebase the patchset on top of linux-next eventually.
Quoted 10 lines
- avoid the final call to
get_page_from_freelist()for !(gfp_mask &__GFP_NO_OOM_KILL) by adding a check for it alongside (gfp_mask&__GFP_FS) and !(gfp_mask &__GFP_NORETRY) because it should really only catch parallel oom killings which won't happen in your suspend case since it usesALLOC_WMARK_HIGH.The latter is important to avoid unnecessary dependencies among low-level __GFP_* flags (although all
__GFP_NO_OOM_KILLallocations should really all be passing__GFP_NORETRYtoo to avoid relying too heavily on direct reclaim).
OK, thanks.
Something like this?
--- include/linux/gfp.h | 3 ++- mm/page_alloc.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-)
mm/page_alloc.c +2 -1
@@ -1599,7 +1599,8 @@ nofail_alloc: zonelist, high_zoneidx, alloc_flags);if (page) goto got_pg; - }else if ((gfp_mask & __GFP_FS) && !(gfp_mask & __GFP_NORETRY)) { + }else if ((gfp_mask & __GFP_FS) && !(gfp_mask & __GFP_NORETRY) + && !(gfp_mask & __GFP_NO_OOM_KILL)) {if (!try_set_zone_oom (zonelist, gfp_mask)) {schedule_timeout_uninterruptible (1 ); goto restart;
include/linux/gfp.h +2 -1
@@ -51,8 +51,9 @@ struct vm_area_struct;#define __GFP_THISNODE ((__force gfp_t)0x40000u)/* No fallback, no policies */ #define __GFP_RECLAIMABLE ((__force gfp_t)0x80000u)/* Page is reclaimable */ #define __GFP_MOVABLE ((__force gfp_t)0x100000u)/* Page is movable */ +#define __GFP_NO_OOM_KILL ((__force gfp_t)0x200000u)/* Don't invoke out_of_memory() */ -#define __GFP_BITS_SHIFT 21/* Room for 21 __GFP_FOO bits */ +#define __GFP_BITS_SHIFT 22/* Number of __GFP_FOO bits */ #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))/* This equals 0, but use constants in case they ever change */
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
In reply to Rafael J. WysockiQuoted 19 lines · Rafael J. Wysocki
Quoted 7 lines
Quoted 7 lines
Index:
linux-2.6/mm/page_alloc.c
===================================================================mm/page_alloc.c +0
-0@@ -1620,7 +1620,8 @@ nofail_alloc: }Quoted 11 lines
mm/page_alloc.c nofail_alloc: · line 1627
Quoted 7 lines
mm/page_alloc.c +2
-1/* The OOM killer will not help higher order allocs so fail */ -if (order >PAGE_ALLOC_COSTLY_ORDER ) { +if (order >PAGE_ALLOC_COSTLY_ORDER || + (gfp_mask & __GFP_NO_OOM_KILL)) {clear_zonelist_oom (zonelist, gfp_mask); goto nopage; }This is inconsistent because
__GFP_NO_OOM_KILLnow implies__GFP_NORETRY(the "goto nopage" above), but only for allocations with__GFP_FSset and__GFP_NORETRYclear.
Quoted 2 lines
Well, what would you suggest?
A couple things:
- rebase this on mmotm so that it doesn't conflict with Mel Gorman's page allocator speedup changes, and
- avoid the final call to get_page_from_freelist() for !(gfp_mask & __GFP_NO_OOM_KILL) by adding a check for it alongside (gfp_mask & __GFP_FS) and !(gfp_mask & __GFP_NORETRY) because it should really only catch parallel oom killings which won't happen in your suspend case since it uses ALLOC_WMARK_HIGH.
The latter is important to avoid unnecessary dependencies among low-level __GFP_* flags (although all __GFP_NO_OOM_KILL allocations should really all be passing __GFP_NORETRY too to avoid relying too heavily on direct reclaim).
Andrew Morton
maintainerRe: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
In reply to Rafael J. WysockiQuoted 22 lines · On Mon, 4 May 2009 17:02:22 +0200 "Rafael J. Wysocki"…
Quoted 9 lines · David Rientjes
Quoted 7 lines · Rafael J. Wysocki
Index:
linux-2.6/mm/page_alloc.c
===================================================================mm/page_alloc.c +0
-0@@ -1620,7 +1620,8 @@ nofail_alloc: }Quoted 11 lines
mm/page_alloc.c nofail_alloc: · line 1627
Quoted 7 lines
mm/page_alloc.c +2
-1/* The OOM killer will not help higher order allocs so fail */ -if (order >PAGE_ALLOC_COSTLY_ORDER ) { +if (order >PAGE_ALLOC_COSTLY_ORDER || + (gfp_mask & __GFP_NO_OOM_KILL)) {clear_zonelist_oom (zonelist, gfp_mask); goto nopage; }This is inconsistent because
__GFP_NO_OOM_KILLnow implies__GFP_NORETRY(the "goto nopage" above), but only for allocations with__GFP_FSset and__GFP_NORETRYclear.
Quoted 2 lines
Well, what would you suggest?
Did you check whether the existing __GFP_NORETRY will work as-is for this requirement?
Andrew Morton
maintainerRe: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
In reply to Rafael J. WysockiQuoted 22 lines · On Mon, 4 May 2009 17:02:22 +0200 "Rafael J. Wysocki" <[email protected]> wrote:
Quoted 9 lines · David Rientjes
Quoted 7 lines · Rafael J. Wysocki
Index:
linux-2.6/mm/page_alloc.c
===================================================================mm/page_alloc.c +0
-0@@ -1620,7 +1620,8 @@ nofail_alloc: }Quoted 11 lines
mm/page_alloc.c nofail_alloc: · line 1627
Quoted 7 lines
mm/page_alloc.c +2
-1/* The OOM killer will not help higher order allocs so fail */ -if (order >PAGE_ALLOC_COSTLY_ORDER ) { +if (order >PAGE_ALLOC_COSTLY_ORDER || + (gfp_mask & __GFP_NO_OOM_KILL)) {clear_zonelist_oom (zonelist, gfp_mask); goto nopage; }This is inconsistent because
__GFP_NO_OOM_KILLnow implies__GFP_NORETRY(the "goto nopage" above), but only for allocations with__GFP_FSset and__GFP_NORETRYclear.
Quoted 2 lines
Well, what would you suggest?
Did you check whether the existing __GFP_NORETRY will work as-is for this requirement?
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
In reply to David RientjesQuoted 9 lines · David Rientjes
Quoted 7 lines · Rafael J. Wysocki
Index:
linux-2.6/mm/page_alloc.c
===================================================================mm/page_alloc.c +0
-0@@ -1620,7 +1620,8 @@ nofail_alloc: }
Quoted 11 lines
mm/page_alloc.c nofail_alloc: · line 1627
Quoted 7 lines
mm/page_alloc.c +2
-1/* The OOM killer will not help higher order allocs so fail */ -if (order >PAGE_ALLOC_COSTLY_ORDER ) { +if (order >PAGE_ALLOC_COSTLY_ORDER || + (gfp_mask & __GFP_NO_OOM_KILL)) {clear_zonelist_oom (zonelist, gfp_mask); goto nopage; }This is inconsistent because
__GFP_NO_OOM_KILLnow implies__GFP_NORETRY(the "goto nopage" above), but only for allocations with__GFP_FSset and__GFP_NORETRYclear.
Well, what would you suggest?
Rafael
Re: [PATCH 1/5] mm: Add __GFP_NO_OOM_KILL flag
In reply to Rafael J. WysockiQuoted 5 lines · Rafael J. Wysocki
Index:
linux-2.6/mm/page_alloc.c
===================================================================
mm/page_alloc.c nofail_alloc: · line 1627
Quoted 9 lines
mm/page_alloc.c +2
-1@@ -1620,7 +1620,8 @@ nofail_alloc: }/* The OOM killer will not help higher order allocs so fail */ -if (order >PAGE_ALLOC_COSTLY_ORDER ) { +if (order >PAGE_ALLOC_COSTLY_ORDER || + (gfp_mask & __GFP_NO_OOM_KILL)) {clear_zonelist_oom (zonelist, gfp_mask); goto nopage; }
This is inconsistent because __GFP_NO_OOM_KILL now implies __GFP_NORETRY (the "goto nopage" above), but only for allocations with __GFP_FS set and __GFP_NORETRY clear.
PATCH 1/5 mm: Add __GFP_NO_OOM_KILL flag
In reply to Rafael J. WysockiFrom: Andrew Morton <[email protected]>
Quoted 4 lines
Quoted 1 line
Remind me: why can't we just allocate N pages at suspend-time?
We need half of memory free. The reason we can't "just allocate" is probably OOM killer; but my memories are quite weak :-(.
hm. You'd think that with our splendid range of __GFP_foo falgs, there would be some combo which would suit this requirement but I can't immediately spot one.
We can always add another I guess. Something like...
[rjw: fixed white space]
--- include/linux/gfp.h | 3 ++- mm/page_alloc.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-)
mm/page_alloc.c +2 -1
@@ -1620,7 +1620,8 @@ nofail_alloc: }/* The OOM killer will not help higher order allocs so fail */ -if (order >PAGE_ALLOC_COSTLY_ORDER ) { +if (order >PAGE_ALLOC_COSTLY_ORDER || + (gfp_mask & __GFP_NO_OOM_KILL)) {clear_zonelist_oom (zonelist, gfp_mask); goto nopage; }
include/linux/gfp.h +2 -1
@@ -51,8 +51,9 @@ struct vm_area_struct;#define __GFP_THISNODE ((__force gfp_t)0x40000u)/* No fallback, no policies */ #define __GFP_RECLAIMABLE ((__force gfp_t)0x80000u)/* Page is reclaimable */ #define __GFP_MOVABLE ((__force gfp_t)0x100000u)/* Page is movable */ +#define __GFP_NO_OOM_KILL ((__force gfp_t)0x200000u)/* Don't invoke out_of_memory() */ -#define __GFP_BITS_SHIFT 21/* Room for 21 __GFP_FOO bits */ +#define __GFP_BITS_SHIFT 22/* Number of __GFP_FOO bits */ #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))/* This equals 0, but use constants in case they ever change */