Skip to contentSkip to conversation

Memory allocations in .suspend became very unreliable

RFC PATCH In review Maxim Levitsky 11 participants 125 messages Jan 15, 2010 – Feb 1, 2010

Subsystems (7)
lore
Share & tools
lore
#0 lore raw

Hi,

I know that this is very controversial, because here I want to describe a problem in a proprietary driver that happens now in 2.6.33-rc3 I am taking about nvidia driver.

Some time ago I did very long hibernate test and found no errors after more that 200 cycles.

Now I update to 2.6.33 and notice that system will hand when nvidia driver allocates memory is their .suspend functions. This could fail in 2.6.32 if I would run many memory hungry applications, but now this happens with most of memory free.

I added some printks to function used to allocate memory in nvidia driver and found out that contrary to my belief, they don't allocate much memory there.

Here is the log:

<4>[  412.022746] Freezing user space processes ... (elapsed 0.01 seconds) done.
<4>[  412.042872] Freezing remaining freezable tasks ... (elapsed 0.01 seconds) done.
<6>[  412.062979] PM: Preallocating image memory... done (allocated 326858 pages)
<6>[  412.302822] PM: Allocated 1307432 kbytes in 0.23 seconds (5684.48 MB/s)
<5>[  412.342974] sd 0:0:0:0: [sda] Synchronizing SCSI cache
<7>[  412.361201] ACPI handle has no context!
<6>[  412.361315] sdhci-pci 0000:07:00.1: PCI INT B disabled
<7>[  412.361434] ACPI handle has no context!
<4>[  412.441488] NVM: allocating 7576 bytes of memory
<4>[  412.441597] NVM: allocating 72 bytes of memory
<4>[  412.441732] NVM: allocating 208 bytes of memory
<4>[  412.441836] NVM: allocating 72 bytes of memory
<4>[  412.442531] NVM: allocating 200 bytes of memory
<4>[  412.442639] NVM: allocating 72 bytes of memory
<4>[  412.442786] NVM: allocating 328 bytes of memory
<4>[  412.442888] NVM: allocating 72 bytes of memory
<4>[  412.442990] NVM: allocating 200 bytes of memory
<4>[  412.443111] NVM: allocating 376 bytes of memory
<4>[  412.443229] NVM: allocating 328 bytes of memory
<4>[  412.443330] NVM: allocating 72 bytes of memory
<4>[  412.443430] NVM: allocating 144 bytes of memory
<4>[  412.443546] NVM: allocating 376 bytes of memory
<4>[  412.443689] NVM: allocating 136 bytes of memory
<4>[  412.443791] NVM: allocating 136 bytes of memory
<4>[  412.443893] NVM: allocating 136 bytes of memory
<4>[  412.444002] NVM: allocating 96 bytes of memory
<4>[  412.444104] NVM: allocating 176 bytes of memory
<4>[  412.444210] NVM: allocating 200 bytes of memory
<4>[  412.444317] NVM: allocating 96 bytes of memory
<4>[  412.444418] NVM: allocating 176 bytes of memory
<4>[  412.444520] NVM: allocating 200 bytes of memory
<4>[  412.444624] NVM: allocating 96 bytes of memory
<4>[  412.444725] NVM: allocating 176 bytes of memory
<4>[  412.444828] NVM: allocating 200 bytes of memory
<4>[  412.444932] NVM: allocating 2048 bytes of memory
<4>[  412.445037] NVM: allocating 384 bytes of memory
<4>[  412.445140] NVM: allocating 136 bytes of memory
<4>[  412.445240] NVM: allocating 136 bytes of memory
<4>[  412.445425] NVM: allocating 328 bytes of memory
<4>[  412.445529] NVM: allocating 136 bytes of memory
<4>[  412.445653] NVM: allocating 136 bytes of memory
<4>[  412.445757] NVM: allocating 148 bytes of memory
<4>[  412.445922] NVM: allocating 1296 bytes of memory
<4>[  412.446039] NVM: allocating 37888 bytes of memory
<4>[  412.446156] NVM: allocating 72 bytes of memory
<4>[  412.446280] NVM: allocating 328 bytes of memory
<4>[  412.446383] NVM: allocating 72 bytes of memory
<4>[  412.446483] NVM: allocating 144 bytes of memory
<4>[  412.446600] NVM: allocating 376 bytes of memory
<4>[  412.446749] NVM: allocating 136 bytes of memory
<4>[  412.446853] NVM: allocating 148 bytes of memory
<4>[  412.447026] NVM: allocating 136 bytes of memory
<4>[  412.447130] NVM: allocating 148 bytes of memory
<4>[  412.447304] NVM: allocating 872 bytes of memory
<4>[  412.447408] NVM: allocating 96 bytes of memory
<4>[  412.447510] NVM: allocating 176 bytes of memory
<4>[  412.447614] NVM: allocating 200 bytes of memory
<4>[  412.447721] NVM: allocating 148 bytes of memory
<4>[  412.447826] NVM: allocating 148 bytes of memory
<4>[  412.447974] NVM: allocating 328 bytes of memory
<4>[  412.448078] NVM: allocating 136 bytes of memory
<4>[  412.448503] NVM: allocating 72 bytes of memory
<4>[  412.448625] NVM: allocating 328 bytes of memory
<4>[  412.448728] NVM: allocating 136 bytes of memory
<4>[  412.448863] NVM: allocating 72 bytes of memory
<4>[  412.448996] NVM: allocating 200 bytes of memory
<4>[  412.449097] NVM: allocating 136 bytes of memory
<4>[  412.449198] NVM: allocating 72 bytes of memory
<4>[  412.449485] NVM: allocating 1296 bytes of memory
<4>[  412.449587] NVM: allocating 1296 bytes of memory
<4>[  412.449727] NVM: allocating 1552 bytes of memory
<4>[  412.449829] NVM: allocating 1416 bytes of memory
<4>[  412.450607] NVM: allocating 200 bytes of memory
<4>[  412.450717] NVM: allocating 72 bytes of memory
<4>[  412.450855] NVM: allocating 328 bytes of memory
<4>[  412.450957] NVM: allocating 72 bytes of memory
<4>[  412.451058] NVM: allocating 1544 bytes of memory
<4>[  412.451176] NVM: allocating 376 bytes of memory
<4>[  412.451309] NVM: allocating 136 bytes of memory
<4>[  412.451416] NVM: allocating 148 bytes of memory
<4>[  412.451637] NVM: allocating 200 bytes of memory
<4>[  412.451741] NVM: allocating 136 bytes of memory
<4>[  412.451844] NVM: allocating 72 bytes of memory
<4>[  412.451974] NVM: allocating 328 bytes of memory
<4>[  412.452075] NVM: allocating 72 bytes of memory
<4>[  412.452176] NVM: allocating 136 bytes of memory
<4>[  412.452292] NVM: allocating 376 bytes of memory
<4>[  412.452411] NVM: allocating 136 bytes of memory
<4>[  412.452606] NVM: allocating 64 bytes of memory
<4>[  412.452708] NVM: allocating 136 bytes of memory
<4>[  412.452812] NVM: allocating 148 bytes of memory
<4>[  412.452974] NVM: allocating 56 bytes of memory
<4>[  412.453075] NVM: allocating 56 bytes of memory
<4>[  412.454466] NVM: allocating 120 bytes of memory
<4>[  412.454568] NVM: allocating 15 bytes of memory
<4>[  412.454688] NVM: allocating 2192 bytes of memory
<4>[  412.454791] NVM: allocating 2056 bytes of memory
<4>[  412.455715] NVM: allocating 200 bytes of memory
<4>[  412.455823] NVM: allocating 72 bytes of memory
<4>[  412.455963] NVM: allocating 328 bytes of memory
<4>[  412.456065] NVM: allocating 72 bytes of memory
<4>[  412.456167] NVM: allocating 2184 bytes of memory
<4>[  412.456287] NVM: allocating 376 bytes of memory
<4>[  412.456420] NVM: allocating 136 bytes of memory
<4>[  412.456527] NVM: allocating 148 bytes of memory
<4>[  412.456761] NVM: allocating 200 bytes of memory
<4>[  412.456864] NVM: allocating 136 bytes of memory
<4>[  412.456964] NVM: allocating 72 bytes of memory
<4>[  412.457095] NVM: allocating 328 bytes of memory
<4>[  412.457197] NVM: allocating 72 bytes of memory
<4>[  412.457298] NVM: allocating 136 bytes of memory
<4>[  412.457415] NVM: allocating 376 bytes of memory
<4>[  412.457534] NVM: allocating 136 bytes of memory
<4>[  412.457686] NVM: allocating 64 bytes of memory
<4>[  412.457787] NVM: allocating 136 bytes of memory
<4>[  412.457890] NVM: allocating 148 bytes of memory
<4>[  412.458057] NVM: allocating 56 bytes of memory
<4>[  412.458158] NVM: allocating 56 bytes of memory
<4>[  412.459509] NVM: allocating 2192 bytes of memory
<4>[  412.459614] NVM: allocating 2056 bytes of memory
<4>[  412.460464] NVM: allocating 200 bytes of memory
<4>[  412.460574] NVM: allocating 72 bytes of memory
<4>[  412.460713] NVM: allocating 328 bytes of memory
<4>[  412.460818] NVM: allocating 72 bytes of memory
<4>[  412.460919] NVM: allocating 2184 bytes of memory
<4>[  412.461040] NVM: allocating 376 bytes of memory
<4>[  412.461172] NVM: allocating 136 bytes of memory
<4>[  412.461278] NVM: allocating 148 bytes of memory
<4>[  412.461511] NVM: allocating 200 bytes of memory
<4>[  412.461615] NVM: allocating 136 bytes of memory
<4>[  412.461717] NVM: allocating 72 bytes of memory
<4>[  412.461848] NVM: allocating 328 bytes of memory
<4>[  412.461950] NVM: allocating 72 bytes of memory
<4>[  412.462051] NVM: allocating 136 bytes of memory
<4>[  412.462167] NVM: allocating 376 bytes of memory
<4>[  412.462286] NVM: allocating 136 bytes of memory
<4>[  412.462437] NVM: allocating 64 bytes of memory
<4>[  412.462580] NVM: allocating 136 bytes of memory
<4>[  412.462683] NVM: allocating 148 bytes of memory
<4>[  412.462852] NVM: allocating 56 bytes of memory
<4>[  412.462952] NVM: allocating 56 bytes of memory
<4>[  412.464271] NVM: allocating 272 bytes of memory
<4>[  412.464374] NVM: allocating 136 bytes of memory
<4>[  412.465035] NVM: allocating 200 bytes of memory
<4>[  412.465145] NVM: allocating 72 bytes of memory
<4>[  412.465285] NVM: allocating 328 bytes of memory
<4>[  412.465389] NVM: allocating 72 bytes of memory
<4>[  412.465490] NVM: allocating 264 bytes of memory
<4>[  412.465610] NVM: allocating 376 bytes of memory
<4>[  412.465741] NVM: allocating 136 bytes of memory
<4>[  412.465847] NVM: allocating 148 bytes of memory
<4>[  412.466053] NVM: allocating 200 bytes of memory
<4>[  412.466156] NVM: allocating 136 bytes of memory
<4>[  412.466258] NVM: allocating 72 bytes of memory
<4>[  412.466390] NVM: allocating 328 bytes of memory
<4>[  412.466493] NVM: allocating 72 bytes of memory
<4>[  412.466594] NVM: allocating 136 bytes of memory
<4>[  412.466711] NVM: allocating 376 bytes of memory
<4>[  412.466831] NVM: allocating 136 bytes of memory
<4>[  412.466982] NVM: allocating 64 bytes of memory
<4>[  412.467083] NVM: allocating 136 bytes of memory
<4>[  412.467186] NVM: allocating 148 bytes of memory
<4>[  412.467327] NVM: allocating 56 bytes of memory
<4>[  412.467429] NVM: allocating 56 bytes of memory
<4>[  412.468793] NVM: allocating 880 bytes of memory
<4>[  412.468896] NVM: allocating 744 bytes of memory
<4>[  412.470051] NVM: allocating 200 bytes of memory
<4>[  412.470173] NVM: allocating 72 bytes of memory
<4>[  412.470312] NVM: allocating 328 bytes of memory
<4>[  412.470415] NVM: allocating 72 bytes of memory
<4>[  412.470517] NVM: allocating 872 bytes of memory
<4>[  412.470636] NVM: allocating 376 bytes of memory
<4>[  412.470767] NVM: allocating 136 bytes of memory
<4>[  412.471862] NVM: allocating 148 bytes of memory
<4>[  412.472078] NVM: allocating 200 bytes of memory
<4>[  412.472180] NVM: allocating 136 bytes of memory
<4>[  412.472282] NVM: allocating 72 bytes of memory
<4>[  412.472413] NVM: allocating 328 bytes of memory
<4>[  412.472549] NVM: allocating 72 bytes of memory
<4>[  412.472651] NVM: allocating 136 bytes of memory
<4>[  412.472767] NVM: allocating 376 bytes of memory
<4>[  412.472887] NVM: allocating 136 bytes of memory
<4>[  412.473038] NVM: allocating 64 bytes of memory
<4>[  412.473138] NVM: allocating 136 bytes of memory
<4>[  412.473241] NVM: allocating 148 bytes of memory
<4>[  412.473393] NVM: allocating 56 bytes of memory
<4>[  412.473495] NVM: allocating 56 bytes of memory
<4>[  412.474798] NVM: allocating 256 bytes of memory
<4>[  412.475005] NVM: allocating 152 bytes of memory
<4>[  412.475108] NVM: allocating 16 bytes of memory
<4>[  412.475744] NVM: allocating 200 bytes of memory
<4>[  412.475853] NVM: allocating 72 bytes of memory
<4>[  412.475993] NVM: allocating 328 bytes of memory
<4>[  412.476096] NVM: allocating 72 bytes of memory
<4>[  412.476198] NVM: allocating 144 bytes of memory
<4>[  412.476318] NVM: allocating 376 bytes of memory
<4>[  412.476451] NVM: allocating 136 bytes of memory
<4>[  412.476556] NVM: allocating 148 bytes of memory
<4>[  412.476761] NVM: allocating 200 bytes of memory
<4>[  412.476862] NVM: allocating 136 bytes of memory
<4>[  412.476964] NVM: allocating 72 bytes of memory
<4>[  412.477095] NVM: allocating 328 bytes of memory
<4>[  412.477198] NVM: allocating 72 bytes of memory
<4>[  412.477300] NVM: allocating 136 bytes of memory
<4>[  412.477417] NVM: allocating 376 bytes of memory
<4>[  412.477536] NVM: allocating 136 bytes of memory
<4>[  412.477686] NVM: allocating 64 bytes of memory
<4>[  412.477787] NVM: allocating 136 bytes of memory
<4>[  412.477890] NVM: allocating 148 bytes of memory
<4>[  412.478031] NVM: allocating 56 bytes of memory
<4>[  412.478133] NVM: allocating 56 bytes of memory
<4>[  412.479449] NVM: allocating 192 bytes of memory
<4>[  412.479550] NVM: allocating 56 bytes of memory
<4>[  412.480202] NVM: allocating 200 bytes of memory
<4>[  412.480310] NVM: allocating 72 bytes of memory
<4>[  412.480448] NVM: allocating 328 bytes of memory
<4>[  412.480551] NVM: allocating 72 bytes of memory
<4>[  412.480653] NVM: allocating 184 bytes of memory
<4>[  412.480770] NVM: allocating 376 bytes of memory
<4>[  412.480903] NVM: allocating 136 bytes of memory
<4>[  412.481008] NVM: allocating 148 bytes of memory
<4>[  412.481211] NVM: allocating 200 bytes of memory
<4>[  412.481313] NVM: allocating 136 bytes of memory
<4>[  412.481416] NVM: allocating 72 bytes of memory
<4>[  412.481548] NVM: allocating 328 bytes of memory
<4>[  412.481651] NVM: allocating 72 bytes of memory
<4>[  412.481752] NVM: allocating 136 bytes of memory
<4>[  412.481868] NVM: allocating 376 bytes of memory
<4>[  412.481986] NVM: allocating 136 bytes of memory
<4>[  412.482135] NVM: allocating 64 bytes of memory
<4>[  412.482237] NVM: allocating 136 bytes of memory
<4>[  412.482339] NVM: allocating 148 bytes of memory
<4>[  412.482481] NVM: allocating 56 bytes of memory
<4>[  412.482626] NVM: allocating 56 bytes of memory
<4>[  412.483945] NVM: allocating 880 bytes of memory
<4>[  412.484047] NVM: allocating 744 bytes of memory
<4>[  412.485181] NVM: allocating 200 bytes of memory
<4>[  412.485291] NVM: allocating 72 bytes of memory
<4>[  412.485431] NVM: allocating 328 bytes of memory
<4>[  412.485535] NVM: allocating 72 bytes of memory
<4>[  412.485637] NVM: allocating 872 bytes of memory
<4>[  412.485756] NVM: allocating 376 bytes of memory
<4>[  412.485888] NVM: allocating 136 bytes of memory
<4>[  412.485995] NVM: allocating 148 bytes of memory
<4>[  412.486213] NVM: allocating 200 bytes of memory
<4>[  412.486315] NVM: allocating 136 bytes of memory
<4>[  412.486417] NVM: allocating 72 bytes of memory
<4>[  412.486548] NVM: allocating 328 bytes of memory
<4>[  412.486650] NVM: allocating 72 bytes of memory
<4>[  412.486751] NVM: allocating 136 bytes of memory
<4>[  412.486868] NVM: allocating 376 bytes of memory
<4>[  412.486988] NVM: allocating 136 bytes of memory
<4>[  412.487138] NVM: allocating 64 bytes of memory
<4>[  412.487240] NVM: allocating 136 bytes of memory
<4>[  412.487342] NVM: allocating 148 bytes of memory
<4>[  412.487493] NVM: allocating 56 bytes of memory
<4>[  412.487594] NVM: allocating 56 bytes of memory
<4>[  412.488897] NVM: allocating 256 bytes of memory
<4>[  412.489103] NVM: allocating 152 bytes of memory
<4>[  412.489206] NVM: allocating 16 bytes of memory
<4>[  412.489851] NVM: allocating 200 bytes of memory
<4>[  412.489960] NVM: allocating 72 bytes of memory
<4>[  412.490125] NVM: allocating 328 bytes of memory
<4>[  412.490229] NVM: allocating 72 bytes of memory
<4>[  412.490329] NVM: allocating 144 bytes of memory
<4>[  412.490448] NVM: allocating 376 bytes of memory
<4>[  412.490580] NVM: allocating 136 bytes of memory
<4>[  412.490686] NVM: allocating 148 bytes of memory
<4>[  412.490888] NVM: allocating 200 bytes of memory
<4>[  412.490991] NVM: allocating 136 bytes of memory
<4>[  412.491092] NVM: allocating 72 bytes of memory
<4>[  412.491224] NVM: allocating 328 bytes of memory
<4>[  412.491325] NVM: allocating 72 bytes of memory
<4>[  412.491426] NVM: allocating 136 bytes of memory
<4>[  412.491543] NVM: allocating 376 bytes of memory
<4>[  412.491664] NVM: allocating 136 bytes of memory
<4>[  412.491814] NVM: allocating 64 bytes of memory
<4>[  412.491916] NVM: allocating 136 bytes of memory
<4>[  412.492020] NVM: allocating 148 bytes of memory
<4>[  412.492160] NVM: allocating 56 bytes of memory
<4>[  412.492262] NVM: allocating 56 bytes of memory
<4>[  412.493588] NVM: allocating 192 bytes of memory
<4>[  412.493692] NVM: allocating 56 bytes of memory
<4>[  412.513530] NVM: allocating 200 bytes of memory
<4>[  412.513642] NVM: allocating 72 bytes of memory
<4>[  412.513782] NVM: allocating 328 bytes of memory
<4>[  412.513887] NVM: allocating 72 bytes of memory
<4>[  412.513990] NVM: allocating 184 bytes of memory
<4>[  412.514111] NVM: allocating 376 bytes of memory
<4>[  412.514246] NVM: allocating 136 bytes of memory
<4>[  412.514353] NVM: allocating 148 bytes of memory
<4>[  412.514559] NVM: allocating 200 bytes of memory
<4>[  412.514663] NVM: allocating 136 bytes of memory
<4>[  412.514767] NVM: allocating 72 bytes of memory
<4>[  412.514900] NVM: allocating 328 bytes of memory
<4>[  412.515003] NVM: allocating 72 bytes of memory
<4>[  412.515107] NVM: allocating 136 bytes of memory
<4>[  412.515225] NVM: allocating 376 bytes of memory
<4>[  412.515346] NVM: allocating 136 bytes of memory
<4>[  412.515498] NVM: allocating 64 bytes of memory
<4>[  412.515601] NVM: allocating 136 bytes of memory
<4>[  412.515704] NVM: allocating 148 bytes of memory
<4>[  412.515847] NVM: allocating 56 bytes of memory
<4>[  412.515949] NVM: allocating 56 bytes of memory
<4>[  412.517272] NVM: allocating 880 bytes of memory
<4>[  412.517378] NVM: allocating 744 bytes of memory
<4>[  412.533382] NVM: allocating 200 bytes of memory
<4>[  412.533493] NVM: allocating 72 bytes of memory
<4>[  412.533634] NVM: allocating 328 bytes of memory
<4>[  412.533737] NVM: allocating 72 bytes of memory
<4>[  412.533839] NVM: allocating 872 bytes of memory
<4>[  412.533956] NVM: allocating 376 bytes of memory
<4>[  412.534088] NVM: allocating 136 bytes of memory
<4>[  412.534196] NVM: allocating 148 bytes of memory
<4>[  412.534414] NVM: allocating 200 bytes of memory
<4>[  412.534516] NVM: allocating 136 bytes of memory
<4>[  412.534619] NVM: allocating 72 bytes of memory
<4>[  412.534750] NVM: allocating 328 bytes of memory
<4>[  412.534851] NVM: allocating 72 bytes of memory
<4>[  412.534951] NVM: allocating 136 bytes of memory
<4>[  412.535067] NVM: allocating 376 bytes of memory
<4>[  412.535187] NVM: allocating 136 bytes of memory
<4>[  412.535338] NVM: allocating 64 bytes of memory
<4>[  412.535439] NVM: allocating 136 bytes of memory
<4>[  412.535543] NVM: allocating 148 bytes of memory
<4>[  412.535693] NVM: allocating 56 bytes of memory
<4>[  412.535794] NVM: allocating 56 bytes of memory
<4>[  412.537098] NVM: allocating 256 bytes of memory
<4>[  412.537305] NVM: allocating 152 bytes of memory
<4>[  412.537406] NVM: allocating 16 bytes of memory
<4>[  412.538050] NVM: allocating 200 bytes of memory
<4>[  412.538160] NVM: allocating 72 bytes of memory
<4>[  412.538300] NVM: allocating 328 bytes of memory
<4>[  412.538403] NVM: allocating 72 bytes of memory
<4>[  412.538506] NVM: allocating 144 bytes of memory
<4>[  412.538625] NVM: allocating 376 bytes of memory
<4>[  412.538758] NVM: allocating 136 bytes of memory
<4>[  412.538865] NVM: allocating 148 bytes of memory
<4>[  412.539069] NVM: allocating 200 bytes of memory
<4>[  412.539171] NVM: allocating 136 bytes of memory
<4>[  412.539274] NVM: allocating 72 bytes of memory
<4>[  412.539403] NVM: allocating 328 bytes of memory
<4>[  412.539506] NVM: allocating 72 bytes of memory
<4>[  412.539608] NVM: allocating 136 bytes of memory
<4>[  412.539724] NVM: allocating 376 bytes of memory
<4>[  412.539842] NVM: allocating 136 bytes of memory
<4>[  412.539994] NVM: allocating 64 bytes of memory
<4>[  412.540129] NVM: allocating 136 bytes of memory
<4>[  412.540232] NVM: allocating 148 bytes of memory
<4>[  412.540372] NVM: allocating 56 bytes of memory
<4>[  412.540473] NVM: allocating 56 bytes of memory
<4>[  412.541792] NVM: allocating 192 bytes of memory
<4>[  412.541895] NVM: allocating 56 bytes of memory
<4>[  412.543645] NVM: allocating 200 bytes of memory
<4>[  412.543756] NVM: allocating 72 bytes of memory
<4>[  412.543897] NVM: allocating 328 bytes of memory
<4>[  412.544001] NVM: allocating 72 bytes of memory
<4>[  412.544103] NVM: allocating 184 bytes of memory
<4>[  412.544223] NVM: allocating 376 bytes of memory
<4>[  412.544355] NVM: allocating 136 bytes of memory
<4>[  412.544460] NVM: allocating 148 bytes of memory
<4>[  412.544663] NVM: allocating 200 bytes of memory
<4>[  412.544764] NVM: allocating 136 bytes of memory
<4>[  412.544866] NVM: allocating 72 bytes of memory
<4>[  412.544997] NVM: allocating 328 bytes of memory
<4>[  412.545099] NVM: allocating 72 bytes of memory
<4>[  412.545200] NVM: allocating 136 bytes of memory
<4>[  412.545315] NVM: allocating 376 bytes of memory
<4>[  412.545434] NVM: allocating 136 bytes of memory
<4>[  412.545585] NVM: allocating 64 bytes of memory
<4>[  412.545687] NVM: allocating 136 bytes of memory
<4>[  412.545790] NVM: allocating 148 bytes of memory
<4>[  412.545929] NVM: allocating 56 bytes of memory
<4>[  412.546030] NVM: allocating 56 bytes of memory
<4>[  412.547329] NVM: allocating 65536 bytes of memory
<6>[  463.045135] SysRq : Emergency Sync
<4>[  463.045433] Emergency Sync complete
<6>[  464.056489] SysRq : Emergency Remount R/O
<6>[  467.569124] SysRq : Resetting

I have even tried to increase SPARE_PAGES to 32 MB, but no luck.

Best regards,
Maxim Levitsky

#1 lore raw
Quoted 9 lines · Maxim Levitsky

Hi,

I know that this is very controversial, because here I want to describe a problem in a proprietary driver that happens now in 2.6.33-rc3 I am taking about nvidia driver.

Some time ago I did very long hibernate test and found no errors after more that 200 cycles.

Quoted 8 lines

Now I update to 2.6.33 and notice that system will hand when nvidia driver allocates memory is their .suspend functions. This could fail in 2.6.32 if I would run many memory hungry applications, but now this happens with most of memory free.

I added some printks to function used to allocate memory in nvidia driver and found out that contrary to my belief, they don't allocate much memory there.

Hello Maxim,
Do you hit the error early if you reduce your memory (by passing
'mem= ' bootargs)? The hibernation routine allocates memory for creating its own bitmaps, so I was wondering if it is really a memory issue or bug in the nvidia driver.

Thanks,
-Romit

#2 lore raw
Quoted 15 lines · Romit Dasgupta
Quoted 14 lines · Maxim Levitsky

Hi,

I know that this is very controversial, because here I want to describe a problem in a proprietary driver that happens now in 2.6.33-rc3 I am taking about nvidia driver.

Some time ago I did very long hibernate test and found no errors after more that 200 cycles.

Now I update to 2.6.33 and notice that system will hand when nvidia driver allocates memory is their .suspend functions. This could fail in 2.6.32 if I would run many memory hungry applications, but now this happens with most of memory free.

Quoted 8 lines
Quoted 3 lines

I added some printks to function used to allocate memory in nvidia driver and found out that contrary to my belief, they don't allocate much memory there.

Hello Maxim,
Do you hit the error early if you reduce your memory (by passing
'mem= ' bootargs)? The hibernation routine allocates memory for creating its own bitmaps, so I was wondering if it is really a memory issue or bug in the nvidia driver.

I know that kmalloc is to blame here, here is the backtrace:

<6>[ 3775.469811] pm-hibernate  D 0000000000000000     0  6890   5630 0x00000000
<4>[ 3775.469811]  ffff880037c7b4f8 0000000000000046 0000000000000000 ffffffff812db456
<4>[ 3775.469811]  ffff880037c7b438 0000000000000000 00000001000525fc ffff880004214e58
<4>[ 3775.469811]  ffff88000420f008 ffff880037c7a000 ffff88006fbec1f8 ffff880037c7bfd8
<4>[ 3775.469811] Call Trace:
<4>[ 3775.469811]  [<ffffffff812db456>] ? scsi_request_fn+0xb6/0x400
<4>[ 3775.469811]  [<ffffffff8122fc69>] ? __up_read+0x99/0xc0
<4>[ 3775.469811]  [<ffffffff810c7790>] ? sync_page+0x0/0x60
<4>[ 3775.469811]  [<ffffffff81400923>] io_schedule+0x73/0xc0
<4>[ 3775.469811]  [<ffffffff810c77d5>] sync_page+0x45/0x60
<4>[ 3775.469811]  [<ffffffff814010bf>] __wait_on_bit+0x5f/0x90
<4>[ 3775.469811]  [<ffffffff810c7a23>] wait_on_page_bit+0x73/0x80
<4>[ 3775.469811]  [<ffffffff81065e10>] ? wake_bit_function+0x0/0x40
<4>[ 3775.469811]  [<ffffffff810d40dc>] shrink_page_list+0x18c/0x600
<4>[ 3775.469811]  [<ffffffff81078c4d>] ? trace_hardirqs_on+0xd/0x10
<4>[ 3775.469811]  [<ffffffff81403c52>] ? _raw_spin_unlock_irqrestore+0x42/0x80
<4>[ 3775.469811]  [<ffffffff81065f67>] ? finish_wait+0x67/0x90
<4>[ 3775.469811]  [<ffffffff810d2d0a>] ? isolate_pages_global+0x15a/0x230
<4>[ 3775.469811]  [<ffffffff810df6fd>] ? congestion_wait+0x7d/0x90
<4>[ 3775.469811]  [<ffffffff81065dd0>] ? autoremove_wake_function+0x0/0x40
<4>[ 3775.469811]  [<ffffffff810d4bd9>] shrink_inactive_list+0x689/0x710
<4>[ 3775.469811]  [<ffffffff8122fbf3>] ? __up_read+0x23/0xc0
<4>[ 3775.469811]  [<ffffffff810d4edf>] shrink_zone+0x27f/0x490
<4>[ 3775.469811]  [<ffffffff810d525a>] ? shrink_slab+0x16a/0x1a0
<4>[ 3775.469811]  [<ffffffff810d5dbf>] do_try_to_free_pages+0x1bf/0x310
<4>[ 3775.469811]  [<ffffffff810d6040>] try_to_free_pages+0x70/0x80
<4>[ 3775.469811]  [<ffffffff810d2bb0>] ? isolate_pages_global+0x0/0x230
<4>[ 3775.469811]  [<ffffffff810ce480>] __alloc_pages_nodemask+0x3e0/0x740
<4>[ 3775.469811]  [<ffffffff810ce7f7>] __get_free_pages+0x17/0x60
<4>[ 3775.469811]  [<ffffffff810ff759>] __kmalloc+0x1d9/0x270
<4>[ 3775.469811]  [<ffffffffa05a1ff0>] os_alloc_mem+0xa0/0xf0 [nvidia]
<4>[ 3775.469811]  [<ffffffffa04b70e4>] _nv005422rm+0x12/0x21 [nvidia]
<4>[ 3775.469811]  [<ffffffffa029bc39>] ? _nv014333rm+0xac8/0xc0a [nvidia]
<4>[ 3775.469811]  [<ffffffffa04f18e6>] ? _nv012492rm+0x12e/0x217 [nvidia]
<4>[ 3775.469811]  [<ffffffffa04b9e0e>] ? _nv003813rm+0x176/0x372 [nvidia]
<4>[ 3775.469811]  [<ffffffffa04bf115>] ? rm_power_management+0x170/0x209 [nvidia]
<4>[ 3775.469811]  [<ffffffffa059bb9c>] ? nv_power_management+0x1fc/0x250 [nvidia]
<4>[ 3775.469811]  [<ffffffffa059bcbc>] ? nv_kern_suspend+0x2c/0xb0 [nvidia]
<4>[ 3775.469811]  [<ffffffff81246856>] ? pci_legacy_suspend+0x46/0xe0
<4>[ 3775.469811]  [<ffffffff812ce526>] ? dpm_suspend_start+0x446/0x4b0
<4>[ 3775.469811]  [<ffffffff8124712d>] ? pci_pm_freeze+0x9d/0xb0
<4>[ 3775.469811]  [<ffffffff812cdf6e>] ? pm_op+0x14e/0x1c0
<4>[ 3775.469811]  [<ffffffff812ce446>] ? dpm_suspend_start+0x366/0x4b0
<4>[ 3775.469811]  [<ffffffff8108bb1f>] ? hibernation_snapshot+0x7f/0x280
<4>[ 3775.469811]  [<ffffffff8108be1d>] ? hibernate+0xfd/0x200
<4>[ 3775.469811]  [<ffffffff8108a70c>] ? state_store+0xec/0x100
<4>[ 3775.469811]  [<ffffffff811710b7>] ? sysfs_get_active_two+0x27/0x60
<4>[ 3775.469811]  [<ffffffff8122ba27>] ? kobj_attr_store+0x17/0x20
<4>[ 3775.469811]  [<ffffffff8116f3c6>] ? sysfs_write_file+0xe6/0x170
<4>[ 3775.469811]  [<ffffffff81107da8>] ? vfs_write+0xb8/0x1a0
<4>[ 3775.469811]  [<ffffffff814030e5>] ? lockdep_sys_exit_thunk+0x35/0x67
<4>[ 3775.469811]  [<ffffffff81107f81>] ? sys_write+0x51/0x90
<4>[ 3775.469811]  [<ffffffff8100305b>] ? system_call_fastpath+0x16/0x1b

Best regards,
Maxim Levitsky

#3 lore raw
In reply to Maxim Levitsky
Quoted 1 line · Maxim Levitsky

Hi,

Hi,

Quoted 9 lines

I know that this is very controversial, because here I want to describe a problem in a proprietary driver that happens now in 2.6.33-rc3 I am taking about nvidia driver.

Some time ago I did very long hibernate test and found no errors after more that 200 cycles.

Now I update to 2.6.33 and notice that system will hand when nvidia driver allocates memory is their .suspend functions.

They shouldn't do that, there's no guarantee that's going to work at all.

Quoted 2 lines

This could fail in 2.6.32 if I would run many memory hungry applications, but now this happens with most of memory free.

This sounds a little strange. What's the requested size of the image?

Rafael

#4 lore raw
Quoted 15 lines · Rafael J. Wysocki
Quoted 1 line · Maxim Levitsky

Hi,

Hi,

Quoted 9 lines

I know that this is very controversial, because here I want to describe a problem in a proprietary driver that happens now in 2.6.33-rc3 I am taking about nvidia driver.

Some time ago I did very long hibernate test and found no errors after more that 200 cycles.

Now I update to 2.6.33 and notice that system will hand when nvidia driver allocates memory is their .suspend functions.

Quoted 6 lines

They shouldn't do that, there's no guarantee that's going to work at all.

Quoted 2 lines

This could fail in 2.6.32 if I would run many memory hungry applications, but now this happens with most of memory free.

This sounds a little strange. What's the requested size of the image?

Don't know, but system has to be very tight on memory.

Here is the same problem, now happens within non-propertary path:

<6>[  961.740712] ata_piix 0000:00:1f.1: PCI INT A disabled
<6>[  961.740867] HDA Intel 0000:00:1b.0: PCI INT A disabled
<6>[  961.760386] PM: freeze of devices complete after 335.113 msecs
<6>[  961.761952] PM: late freeze of devices complete after 1.465 msecs
<6>[  961.762296] ACPI: Preparing to enter system sleep state S4 
<6>[  961.771997] PM: Saving platform NVS memory
<3>[ 1201.052518] INFO: task kthreadd:2 blocked for more than 120 seconds.
<3>[ 1201.052619] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
<6>[ 1201.052724] kthreadd      D 0000000000000000     0     2      0 0x00000000
<4>[ 1201.052979]  ffff88006f8a55e0 0000000000000046 0000000000000000 ffffffff812db476
<4>[ 1201.053385]  ffff88006f8a5520 0000000000000000 0000000100010281 ffff880004214e58
<4>[ 1201.053790]  ffff88000420f008 ffff88006f8a4000 ffff88006f899288 ffff88006f8a5fd8
<4>[ 1201.054196] Call Trace:
<4>[ 1201.054296]  [<ffffffff812db476>] ? scsi_request_fn+0xb6/0x400
<4>[ 1201.054406]  [<ffffffff8122fc89>] ? __up_read+0x99/0xc0
<4>[ 1201.054511]  [<ffffffff810c77b0>] ? sync_page+0x0/0x60
<4>[ 1201.054617]  [<ffffffff81400943>] io_schedule+0x73/0xc0
<4>[ 1201.054720]  [<ffffffff810c77f5>] sync_page+0x45/0x60
<4>[ 1201.054824]  [<ffffffff814010df>] __wait_on_bit+0x5f/0x90
<4>[ 1201.054929]  [<ffffffff810c7a43>] wait_on_page_bit+0x73/0x80
<4>[ 1201.055037]  [<ffffffff81065e30>] ? wake_bit_function+0x0/0x40
<4>[ 1201.055145]  [<ffffffff810d3939>] pageout+0x209/0x280
<4>[ 1201.055249]  [<ffffffff810edc3b>] ? page_unlock_anon_vma+0x2b/0x30
<4>[ 1201.055358]  [<ffffffff810d41ef>] shrink_page_list+0x27f/0x600
<4>[ 1201.055467]  [<ffffffff81078c6d>] ? trace_hardirqs_on+0xd/0x10
<4>[ 1201.055575]  [<ffffffff81403c72>] ? _raw_spin_unlock_irqrestore+0x42/0x80
<4>[ 1201.055688]  [<ffffffff81065f87>] ? finish_wait+0x67/0x90
<4>[ 1201.055795]  [<ffffffff810df71d>] ? congestion_wait+0x7d/0x90
<4>[ 1201.055902]  [<ffffffff81065df0>] ? autoremove_wake_function+0x0/0x40
<4>[ 1201.056012]  [<ffffffff810d4bf9>] shrink_inactive_list+0x689/0x710
<4>[ 1201.056121]  [<ffffffff8122fc13>] ? __up_read+0x23/0xc0
<4>[ 1201.056227]  [<ffffffff810d4eff>] shrink_zone+0x27f/0x490
<4>[ 1201.056333]  [<ffffffff810d527a>] ? shrink_slab+0x16a/0x1a0
<4>[ 1201.056440]  [<ffffffff810d5ddf>] do_try_to_free_pages+0x1bf/0x310
<4>[ 1201.056549]  [<ffffffff810d6060>] try_to_free_pages+0x70/0x80
<4>[ 1201.056657]  [<ffffffff810d2bd0>] ? isolate_pages_global+0x0/0x230
<4>[ 1201.056767]  [<ffffffff810ce4a0>] __alloc_pages_nodemask+0x3e0/0x740
<4>[ 1201.056878]  [<ffffffff81041ce9>] ? copy_process+0xb9/0x15a0
<4>[ 1201.056985]  [<ffffffff810ce817>] __get_free_pages+0x17/0x60
<4>[ 1201.057091]  [<ffffffff81041d04>] copy_process+0xd4/0x15a0
<4>[ 1201.057196]  [<ffffffff8103ef5a>] ? wake_up_new_task+0x9a/0x110
<4>[ 1201.057303]  [<ffffffff81062470>] ? __task_pid_nr_ns+0x0/0x100
<4>[ 1201.057409]  [<ffffffff81043267>] do_fork+0x97/0x480
<4>[ 1201.057514]  [<ffffffff81403bfb>] ? _raw_spin_unlock_irq+0x3b/0x70
<4>[ 1201.057623]  [<ffffffff8103966f>] ? finish_task_switch+0x7f/0xe0
<4>[ 1201.057730]  [<ffffffff810395f0>] ? finish_task_switch+0x0/0xe0
<4>[ 1201.057840]  [<ffffffff8100c7f9>] kernel_thread+0x69/0x70
<4>[ 1201.057946]  [<ffffffff810657e0>] ? kthread+0x0/0xb0
<4>[ 1201.058050]  [<ffffffff81003e10>] ? kernel_thread_helper+0x0/0x10
<4>[ 1201.058159]  [<ffffffff81065968>] kthreadd+0xd8/0x110
<4>[ 1201.058263]  [<ffffffff81078c15>] ? trace_hardirqs_on_caller+0x145/0x190
<4>[ 1201.058374]  [<ffffffff81003e14>] kernel_thread_helper+0x4/0x10
<4>[ 1201.058480]  [<ffffffff81404240>] ? restore_args+0x0/0x30
<4>[ 1201.058586]  [<ffffffff81065890>] ? kthreadd+0x0/0x110
<4>[ 1201.058690]  [<ffffffff81003e10>] ? kernel_thread_helper+0x0/0x10
<4>[ 1201.058797] INFO: lockdep is turned off.

Best regards,
Maxim Levitsky

#5 lore raw
Quoted 16 lines · Maxim Levitsky
Quoted 15 lines · Rafael J. Wysocki
Quoted 1 line · Maxim Levitsky

Hi,

Hi,

Quoted 9 lines

I know that this is very controversial, because here I want to describe a problem in a proprietary driver that happens now in 2.6.33-rc3 I am taking about nvidia driver.

Some time ago I did very long hibernate test and found no errors after more that 200 cycles.

Now I update to 2.6.33 and notice that system will hand when nvidia driver allocates memory is their .suspend functions.

Quoted 7 lines
Quoted 6 lines

They shouldn't do that, there's no guarantee that's going to work at all.

Quoted 2 lines

This could fail in 2.6.32 if I would run many memory hungry applications, but now this happens with most of memory free.

This sounds a little strange. What's the requested size of the image?

Don't know, but system has to be very tight on memory.

Can you send full dmesg, please?

Rafael

#6 lore raw
Quoted 19 lines · Rafael J. Wysocki
Quoted 18 lines · Maxim Levitsky
Quoted 17 lines · Rafael J. Wysocki
Quoted 1 line · Maxim Levitsky

Hi,

Hi,

Quoted 9 lines

I know that this is very controversial, because here I want to describe a problem in a proprietary driver that happens now in 2.6.33-rc3 I am taking about nvidia driver.

Some time ago I did very long hibernate test and found no errors after more that 200 cycles.

Now I update to 2.6.33 and notice that system will hand when nvidia driver allocates memory is their .suspend functions.

They shouldn't do that, there's no guarantee that's going to work at all.

Quoted 7 lines
Quoted 5 lines
Quoted 4 lines
Quoted 2 lines

This could fail in 2.6.32 if I would run many memory hungry applications, but now this happens with most of memory free.

This sounds a little strange. What's the requested size of the image?

Don't know, but system has to be very tight on memory.

Can you send full dmesg, please?

I deleted it, but for this case I think that hang was somewhere else. This task was hand on doing forking, which probably happened even before the freezer.

Anyway, the problem is clear. Now __get_free_pages blocks more often, and can block in .suspend even if there is plenty of memory free.

I now patched nvidia to use GFP_ATOMIC _always_, and problem disappear. It isn't such great solution when memory is tight though....

This is going to hit hard all nvidia users...

Best regards,
Maxim Levitsky

#7 lore raw
Quoted 32 lines · Maxim Levitsky
Quoted 19 lines · Rafael J. Wysocki
Quoted 18 lines · Maxim Levitsky
Quoted 17 lines · Rafael J. Wysocki
Quoted 1 line · Maxim Levitsky

Hi,

Hi,

Quoted 9 lines

I know that this is very controversial, because here I want to describe a problem in a proprietary driver that happens now in 2.6.33-rc3 I am taking about nvidia driver.

Some time ago I did very long hibernate test and found no errors after more that 200 cycles.

Now I update to 2.6.33 and notice that system will hand when nvidia driver allocates memory is their .suspend functions.

They shouldn't do that, there's no guarantee that's going to work at all.

Quoted 7 lines
Quoted 5 lines
Quoted 4 lines
Quoted 2 lines

This could fail in 2.6.32 if I would run many memory hungry applications, but now this happens with most of memory free.

This sounds a little strange. What's the requested size of the image?

Don't know, but system has to be very tight on memory.

Can you send full dmesg, please?

I deleted it, but for this case I think that hang was somewhere else. This task was hand on doing forking, which probably happened even before the freezer.

Quoted 7 lines

Anyway, the problem is clear. Now __get_free_pages blocks more often, and can block in .suspend even if there is plenty of memory free.

I now patched nvidia to use GFP_ATOMIC _always_, and problem disappear. It isn't such great solution when memory is tight though....

This is going to hit hard all nvidia users...

Well, generally speaking, no driver should ever allocate memory using GFP_KERNEL in its .suspend() routine, because that's not going to work, as you can readily see. So this is a NVidia bug, hands down.

Now having said that, we've been considering a change that will turn all GFP_KERNEL allocations into GFP_NOIO during suspend/resume, so perhaps I'll prepare a patch to do that and let's see what people think.

Rafael

#8 lore raw

RFC PATCH 1/1 PM: Force GFP_NOIO during suspend/resume (was: Re: [linux-pm] Memory allocations in .suspend became very unreliable)

Hi,

I thing the snippet below is a good summary of what this is about.

Quoted 27 lines · Rafael J. Wysocki
Quoted 26 lines · Maxim Levitsky
Quoted 25 lines · Rafael J. Wysocki
Quoted 23 lines · Maxim Levitsky
Quoted 15 lines · Rafael J. Wysocki
Quoted 1 line · Maxim Levitsky

Hi,

Hi,

Quoted 9 lines

I know that this is very controversial, because here I want to describe a problem in a proprietary driver that happens now in 2.6.33-rc3 I am taking about nvidia driver.

Some time ago I did very long hibernate test and found no errors after more that 200 cycles.

Now I update to 2.6.33 and notice that system will hand when nvidia driver allocates memory is their .suspend functions.

Quoted 6 lines

They shouldn't do that, there's no guarantee that's going to work at all.

Quoted 2 lines

This could fail in 2.6.32 if I would run many memory hungry applications, but now this happens with most of memory free.

This sounds a little strange. What's the requested size of the image?

Don't know, but system has to be very tight on memory.

Quoted 8 lines
Quoted 8 lines
Quoted 1 line

Can you send full dmesg, please?

I deleted it, but for this case I think that hang was somewhere else. This task was hand on doing forking, which probably happened even before the freezer.

Anyway, the problem is clear. Now __get_free_pages blocks more often, and can block in .suspend even if there is plenty of memory free.

This is suspicious, but I leave it to the MM people for consideration.

Quoted 5 lines
Quoted 4 lines

I now patched nvidia to use GFP_ATOMIC _always_, and problem disappear. It isn't such great solution when memory is tight though....

This is going to hit hard all nvidia users...

Quoted 7 lines

Well, generally speaking, no driver should ever allocate memory using GFP_KERNEL in its .suspend() routine, because that's not going to work, as you can readily see. So this is a NVidia bug, hands down.

Now having said that, we've been considering a change that will turn all GFP_KERNEL allocations into GFP_NOIO during suspend/resume, so perhaps I'll prepare a patch to do that and let's see what people think.

If I didn't confuse anything (which is likely, because it's a bit late here now), the patch below should do the trick. I have only checked that it doesn't break compilation, so please take it with a grain of salt.

Comments welcome.

Rafael

---
 include/linux/gfp.h      |    5 +++++
 kernel/power/hibernate.c |    6 ++++++
 kernel/power/main.c      |   30 ++++++++++++++++++++++++++++++
 kernel/power/power.h     |    2 ++
 kernel/power/suspend.c   |    2 ++
 5 files changed, 45 insertions(+)
include/linux/gfp.h +5 -0
Index: linux-2.6/include/linux/gfp.h
===================================================================
@@ -342,4 +342,9 @@ static inline void set_gfp_allowed_mask(
 	gfp_allowed_mask = mask;
 }
 
+static inline gfp_t get_gfp_allowed_mask(void)
+{
+	return gfp_allowed_mask;
+}
+
 #endif /* __LINUX_GFP_H */
kernel/power/hibernate.c +6 -0
Index: linux-2.6/kernel/power/hibernate.c
===================================================================
@@ -334,6 +334,7 @@ int hibernation_snapshot(int platform_mo
 		goto Close;
 
 	suspend_console();
+	pm_force_noio_allocations();
 	error = dpm_suspend_start(PMSG_FREEZE);
 	if (error)
 		goto Recover_platform;
@@ -351,6 +352,7 @@ int hibernation_snapshot(int platform_mo
 
 	dpm_resume_end(in_suspend ?
 		(error ? PMSG_RECOVER : PMSG_THAW) : PMSG_RESTORE);
+	pm_allow_io_allocations();
 	resume_console();
  Close:
 	platform_end(platform_mode);
@@ -448,11 +450,13 @@ int hibernation_restore(int platform_mod
 
 	pm_prepare_console();
 	suspend_console();
+	pm_force_noio_allocations();
 	error = dpm_suspend_start(PMSG_QUIESCE);
 	if (!error) {
 		error = resume_target_kernel(platform_mode);
 		dpm_resume_end(PMSG_RECOVER);
 	}
+	pm_allow_io_allocations();
 	resume_console();
 	pm_restore_console();
 	return error;
@@ -481,6 +485,7 @@ int hibernation_platform_enter(void)
 
 	entering_platform_hibernation = true;
 	suspend_console();
+	pm_force_noio_allocations();
 	error = dpm_suspend_start(PMSG_HIBERNATE);
 	if (error) {
 		if (hibernation_ops->recover)
@@ -518,6 +523,7 @@ int hibernation_platform_enter(void)
  Resume_devices:
 	entering_platform_hibernation = false;
 	dpm_resume_end(PMSG_RESTORE);
+	pm_allow_io_allocations();
 	resume_console();
 
  Close:
kernel/power/power.h +2 -0
Index: linux-2.6/kernel/power/power.h
===================================================================
@@ -187,6 +187,8 @@ static inline void suspend_test_finish(c
 #ifdef CONFIG_PM_SLEEP
 /* kernel/power/main.c */
 extern int pm_notifier_call_chain(unsigned long val);
+extern void pm_force_noio_allocations(void);
+extern void pm_allow_io_allocations(void);
 #endif
 
 #ifdef CONFIG_HIGHMEM
kernel/power/suspend.c +2 -0
Index: linux-2.6/kernel/power/suspend.c
===================================================================
@@ -208,6 +208,7 @@ int suspend_devices_and_enter(suspend_st
 			goto Close;
 	}
 	suspend_console();
+	pm_force_noio_allocations();
 	suspend_test_start();
 	error = dpm_suspend_start(PMSG_SUSPEND);
 	if (error) {
@@ -224,6 +225,7 @@ int suspend_devices_and_enter(suspend_st
 	suspend_test_start();
 	dpm_resume_end(PMSG_RESUME);
 	suspend_test_finish("resume devices");
+	pm_allow_io_allocations();
 	resume_console();
  Close:
 	if (suspend_ops->end)
kernel/power/main.c +30 -0
Index: linux-2.6/kernel/power/main.c
===================================================================
@@ -12,6 +12,7 @@
 #include <linux/string.h>
 #include <linux/resume-trace.h>
 #include <linux/workqueue.h>
+#include <linux/gfp.h>
 
 #include "power.h"
 
@@ -22,6 +23,35 @@ EXPORT_SYMBOL(pm_flags);
 
 #ifdef CONFIG_PM_SLEEP
 
+static gfp_t saved_gfp_allowed_mask;
+
+/**
+ * pm_force_noio_allocations - Modify gfp_allowed_mask to disable IO allocations
+ *
+ * Change gfp_allowed_mask by unsetting __GFP_IO and __GFP_FS in it and save the
+ * old value.
+ */
+void pm_force_noio_allocations(void)
+{
+	saved_gfp_allowed_mask = get_gfp_allowed_mask();
+	set_gfp_allowed_mask(saved_gfp_allowed_mask & ~(__GFP_IO | __GFP_FS));
+}
+
+/**
+ * pm_allow_io_allocations - Modify gfp_allowed_mask to allow IO allocations
+ *
+ * If the saved value of gfp_allowed_mask has __GFP_IO set, modify the current
+ * gfp_allowed_mask by setting this bit and anlogously for __GFP_FS.
+ */
+void pm_allow_io_allocations(void)
+{
+	gfp_t gfp_mask;
+
+	gfp_mask = get_gfp_allowed_mask();
+	gfp_mask |= saved_gfp_allowed_mask & (__GFP_IO | __GFP_FS);
+	set_gfp_allowed_mask(gfp_mask);
+}
+
 /* Routines for PM-transition notifications */
 
 static BLOCKING_NOTIFIER_HEAD(pm_chain_head);

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#9 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: [linux-pm] Memory allocations in .suspend became very unreliable)

Am Sonntag, 17. Januar 2010 01:38:37 schrieb Rafael J. Wysocki:

Quoted 9 lines
Quoted 3 lines

Now having said that, we've been considering a change that will turn all GFP_KERNEL allocations into GFP_NOIO during suspend/resume, so perhaps I'll prepare a patch to do that and let's see what people think.

If I didn't confuse anything (which is likely, because it's a bit late here now), the patch below should do the trick. I have only checked that it doesn't break compilation, so please take it with a grain of salt.

Comments welcome.

I think this is a bad idea as it makes the mm subsystem behave differently in the runtime and in the whole system cases. What's so hard about telling people that they need to use GFP_NOIO in suspend() and resume()?

Regards
Oliver

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#10 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: [linux-pm] Memory allocations in .suspend became very unreliable)

Quoted 5 lines · Oliver Neukum

Am Sonntag, 17. Januar 2010 01:38:37 schrieb Rafael J. Wysocki:

Quoted 4 lines
Quoted 3 lines

Now having said that, we've been considering a change that will turn all GFP_KERNEL allocations into GFP_NOIO during suspend/resume, so perhaps I'll prepare a patch to do that and let's see what people think.

Quoted 8 lines
Quoted 5 lines

If I didn't confuse anything (which is likely, because it's a bit late here now), the patch below should do the trick. I have only checked that it doesn't break compilation, so please take it with a grain of salt.

Comments welcome.

I think this is a bad idea as it makes the mm subsystem behave differently in the runtime and in the whole system cases.

s/runtime/suspend/ ?

Yes it will, but why exactly shouldn't it? System suspend/resume _is_ a special situation anyway.

Quoted 2 lines

What's so hard about telling people that they need to use GFP_NOIO in suspend() and resume()?

Memory allocations are made for other purposes during suspend/resume too. For example, new kernel threads may be created (for async suspend/resume among other things).

Besides, the fact that you tell people to do something doesn't necessary imply that they will listen. :-)

I have discussed that with Ben for a couple of times and we have generally agreed that memory allocation problems during suspend/resume are not avoidable in general unless we disable __GFP_FS and __GFP_IO at the high level.

Rafael

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#11 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: [linux-pm] Memory allocations in .suspend became very unreliable)

Quoted 12 lines · Rafael J. Wysocki
Quoted 11 lines · Oliver Neukum

Am Sonntag, 17. Januar 2010 01:38:37 schrieb Rafael J. Wysocki:

Quoted 9 lines
Quoted 3 lines

Now having said that, we've been considering a change that will turn all GFP_KERNEL allocations into GFP_NOIO during suspend/resume, so perhaps I'll prepare a patch to do that and let's see what people think.

If I didn't confuse anything (which is likely, because it's a bit late here now), the patch below should do the trick. I have only checked that it doesn't break compilation, so please take it with a grain of salt.

Comments welcome.

Quoted 7 lines
Quoted 2 lines

I think this is a bad idea as it makes the mm subsystem behave differently in the runtime and in the whole system cases.

s/runtime/suspend/ ?

Yes it will, but why exactly shouldn't it? System suspend/resume _is_ a special situation anyway.

Moreover, as the Maxim's report indicates, the mm subsystem already behaves differently during suspend/resume and this behavior is erroneous, because it causes the system to hang.

Rafael

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#12 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: Memory allocations in .suspend became very unreliable)

In reply to Rafael J. Wysocki
Quoted 12 lines · Rafael J. Wysocki
Quoted 11 lines · Oliver Neukum

Am Sonntag, 17. Januar 2010 01:38:37 schrieb Rafael J. Wysocki:

Quoted 9 lines
Quoted 3 lines

Now having said that, we've been considering a change that will turn all GFP_KERNEL allocations into GFP_NOIO during suspend/resume, so perhaps I'll prepare a patch to do that and let's see what people think.

If I didn't confuse anything (which is likely, because it's a bit late here now), the patch below should do the trick. I have only checked that it doesn't break compilation, so please take it with a grain of salt.

Comments welcome.

Quoted 7 lines
Quoted 2 lines

I think this is a bad idea as it makes the mm subsystem behave differently in the runtime and in the whole system cases.

s/runtime/suspend/ ?

Yes it will, but why exactly shouldn't it? System suspend/resume _is_ a special situation anyway.

Moreover, as the Maxim's report indicates, the mm subsystem already behaves differently during suspend/resume and this behavior is erroneous, because it causes the system to hang.

Rafael

#13 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: Memory allocations in .suspend became very unreliable)

In reply to Rafael J. Wysocki
Quoted 2 lines · Rafael J. Wysocki

Yes it will, but why exactly shouldn't it? System suspend/resume _is_ a special situation anyway.

To some extent this is similar to the boot time allocation problem for which it was decided to bury the logic in the allocator as well.

Quoted 3 lines

Memory allocations are made for other purposes during suspend/resume too. For example, new kernel threads may be created (for async suspend/resume among other things).

Right. Well, I would add in fact that this isn't even the main issue I see. If it was just a matter of changing a kmalloc() call in a driver suspend() routine, I would agree with Oliver.

However, there are two categories of allocations that make this extremely difficult:

- One is implicit allocations. IE. suspend() is a normal task context,
it's expected that any function can be called that might itself call a function etc... that does an allocation. There is simply no way all of these code path can be identified and the allocation "flags" pushed up all the way to the API in every case.

- There's a more subtle issue at play here. The moment the core starts
calling driver's suspend() routines, all allocations can potentially hang since a device with dirty pages might have been suspended and the VM can stall trying to swap out to it. (I don't think Rafael proposed patch handles this in a race free way btw, but that's hard, especially for allocations already blocked waiting for a write back ...). That means that a driver that has -not- been suspended yet (and thus doesn't necessarily know the suspend process has been started) might be blocked in an allocation somewhere, holding a mutex or similar, which will then cause a deadlock when that same driver's suspend() routine is called which tries to take the same mutex.

Overall, it's a can of worms. The only way out I can see that is reasonably sane and doesn't impose API changes thorough the kernel and unreasonable expectations from driver writers is to deal with it at the allocator level.

However, it's hard to deal with the case of allocations that have already started waiting for IOs. It might be possible to have some VM hook to make them wakeup, re-evaluate the situation and get out of that code path but in any case it would be tricky.

So Rafael's proposed patch is a first step toward fixing that problem but isn't, I believe, enough.

Quoted 7 lines

Besides, the fact that you tell people to do something doesn't necessary imply that they will listen. :-)

I have discussed that with Ben for a couple of times and we have generally agreed that memory allocation problems during suspend/resume are not avoidable in general unless we disable __GFP_FS and __GFP_IO at the high level.

Cheers,
Ben.

#14 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: [linux-pm] Memory allocations in .suspend became very unreliable)

In reply to Rafael J. Wysocki
Quoted 2 lines · Rafael J. Wysocki

Yes it will, but why exactly shouldn't it? System suspend/resume _is_ a special situation anyway.

To some extent this is similar to the boot time allocation problem for which it was decided to bury the logic in the allocator as well.

Quoted 3 lines

Memory allocations are made for other purposes during suspend/resume too. For example, new kernel threads may be created (for async suspend/resume among other things).

Right. Well, I would add in fact that this isn't even the main issue I see. If it was just a matter of changing a kmalloc() call in a driver suspend() routine, I would agree with Oliver.

However, there are two categories of allocations that make this extremely difficult:

- One is implicit allocations. IE. suspend() is a normal task context,
it's expected that any function can be called that might itself call a function etc... that does an allocation. There is simply no way all of these code path can be identified and the allocation "flags" pushed up all the way to the API in every case.

- There's a more subtle issue at play here. The moment the core starts
calling driver's suspend() routines, all allocations can potentially hang since a device with dirty pages might have been suspended and the VM can stall trying to swap out to it. (I don't think Rafael proposed patch handles this in a race free way btw, but that's hard, especially for allocations already blocked waiting for a write back ...). That means that a driver that has -not- been suspended yet (and thus doesn't necessarily know the suspend process has been started) might be blocked in an allocation somewhere, holding a mutex or similar, which will then cause a deadlock when that same driver's suspend() routine is called which tries to take the same mutex.

Overall, it's a can of worms. The only way out I can see that is reasonably sane and doesn't impose API changes thorough the kernel and unreasonable expectations from driver writers is to deal with it at the allocator level.

However, it's hard to deal with the case of allocations that have already started waiting for IOs. It might be possible to have some VM hook to make them wakeup, re-evaluate the situation and get out of that code path but in any case it would be tricky.

So Rafael's proposed patch is a first step toward fixing that problem but isn't, I believe, enough.

Quoted 7 lines

Besides, the fact that you tell people to do something doesn't necessary imply that they will listen. :-)

I have discussed that with Ben for a couple of times and we have generally agreed that memory allocation problems during suspend/resume are not avoidable in general unless we disable __GFP_FS and __GFP_IO at the high level.

Cheers,
Ben.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#15 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: [linux-pm] Memory allocations in .suspend became very unreliable)

Quoted 1 line · Benjamin Herrenschmidt

On Sun, 2010-01-17 at 14:27 +0100, Rafael J. Wysocki wrote:

...

Quoted 4 lines

However, it's hard to deal with the case of allocations that have already started waiting for IOs. It might be possible to have some VM hook to make them wakeup, re-evaluate the situation and get out of that code path but in any case it would be tricky.

In the second version of the patch I used an rwsem that made us wait for these allocations to complete before we changed gfp_allowed_mask.

[This is kinda buggy in the version I sent, but I'm going to send an update in a minute.]

Rafael

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#16 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: [linux-pm] Memory allocations in .suspend became very unreliable)

Am Montag, 18. Januar 2010 00:00:23 schrieb Rafael J. Wysocki:

Quoted 10 lines · Benjamin Herrenschmidt
Quoted 1 line · Rafael J. Wysocki

...

Quoted 4 lines

However, it's hard to deal with the case of allocations that have already started waiting for IOs. It might be possible to have some VM hook to make them wakeup, re-evaluate the situation and get out of that code path but in any case it would be tricky.

In the second version of the patch I used an rwsem that made us wait for these allocations to complete before we changed gfp_allowed_mask.

This will be a very, very hot semaphore. What's the impact on performance?

Regards
Oliver

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#17 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: Memory allocations in .suspend became very unreliable)

Quoted 9 lines · Oliver Neukum

Am Montag, 18. Januar 2010 00:00:23 schrieb Rafael J. Wysocki:

Quoted 8 lines · Benjamin Herrenschmidt
Quoted 1 line · Rafael J. Wysocki

...

Quoted 4 lines

However, it's hard to deal with the case of allocations that have already started waiting for IOs. It might be possible to have some VM hook to make them wakeup, re-evaluate the situation and get out of that code path but in any case it would be tricky.

Quoted 4 lines
Quoted 2 lines

In the second version of the patch I used an rwsem that made us wait for these allocations to complete before we changed gfp_allowed_mask.

This will be a very, very hot semaphore. What's the impact on performance?

Can it be replaced with something having lower overhead, such as SRCU?

Alan Stern

#18 lore raw

Re: [linux-pm] [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: Memory allocations in .suspend became very unreliable)

In reply to Oliver Neukum
Quoted 9 lines · Oliver Neukum

Am Montag, 18. Januar 2010 00:00:23 schrieb Rafael J. Wysocki:

Quoted 8 lines · Benjamin Herrenschmidt
Quoted 1 line · Rafael J. Wysocki

...

Quoted 4 lines

However, it's hard to deal with the case of allocations that have already started waiting for IOs. It might be possible to have some VM hook to make them wakeup, re-evaluate the situation and get out of that code path but in any case it would be tricky.

Quoted 4 lines
Quoted 2 lines

In the second version of the patch I used an rwsem that made us wait for these allocations to complete before we changed gfp_allowed_mask.

This will be a very, very hot semaphore. What's the impact on performance?

Can it be replaced with something having lower overhead, such as SRCU?

Alan Stern

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#19 lore raw

Re: [linux-pm] [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: Memory allocations in .suspend became very unreliable)

Quoted 11 lines · Alan Stern
Quoted 9 lines · Oliver Neukum

Am Montag, 18. Januar 2010 00:00:23 schrieb Rafael J. Wysocki:

Quoted 8 lines · Benjamin Herrenschmidt
Quoted 1 line · Rafael J. Wysocki

...

Quoted 4 lines

However, it's hard to deal with the case of allocations that have already started waiting for IOs. It might be possible to have some VM hook to make them wakeup, re-evaluate the situation and get out of that code path but in any case it would be tricky.

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

In the second version of the patch I used an rwsem that made us wait for these allocations to complete before we changed gfp_allowed_mask.

This will be a very, very hot semaphore. What's the impact on performance?

Can it be replaced with something having lower overhead, such as SRCU?

I'm not sure about that. In principle SRCU shouldn't be used if the reader can sleep unpredictably long and the memory allocation sutiation is one of these.

Rafael

#20 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: Memory allocations in .suspend became very unreliable)

Quoted 15 lines · Rafael J. Wysocki
Quoted 14 lines · Alan Stern
Quoted 12 lines · Oliver Neukum

Am Montag, 18. Januar 2010 00:00:23 schrieb Rafael J. Wysocki:

Quoted 10 lines · Benjamin Herrenschmidt
Quoted 1 line · Rafael J. Wysocki

...

Quoted 4 lines

However, it's hard to deal with the case of allocations that have already started waiting for IOs. It might be possible to have some VM hook to make them wakeup, re-evaluate the situation and get out of that code path but in any case it would be tricky.

In the second version of the patch I used an rwsem that made us wait for these allocations to complete before we changed gfp_allowed_mask.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

This will be a very, very hot semaphore. What's the impact on performance?

Can it be replaced with something having lower overhead, such as SRCU?

I'm not sure about that. In principle SRCU shouldn't be used if the reader can sleep unpredictably long and the memory allocation sutiation is one of these.

I don't think this matters. Each SRCU usage has its own domain, and different domains don't affect one another. So the only thing that would be blocked by a long-sleeping reader would be the suspend process itself, and obviously you won't mind that.

Alan Stern

#21 lore raw

Re: [linux-pm] [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: Memory allocations in .suspend became very unreliable)

In reply to Rafael J. Wysocki
Quoted 15 lines · Rafael J. Wysocki
Quoted 14 lines · Alan Stern
Quoted 12 lines · Oliver Neukum

Am Montag, 18. Januar 2010 00:00:23 schrieb Rafael J. Wysocki:

Quoted 10 lines · Benjamin Herrenschmidt
Quoted 1 line · Rafael J. Wysocki

...

Quoted 4 lines

However, it's hard to deal with the case of allocations that have already started waiting for IOs. It might be possible to have some VM hook to make them wakeup, re-evaluate the situation and get out of that code path but in any case it would be tricky.

In the second version of the patch I used an rwsem that made us wait for these allocations to complete before we changed gfp_allowed_mask.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

This will be a very, very hot semaphore. What's the impact on performance?

Can it be replaced with something having lower overhead, such as SRCU?

I'm not sure about that. In principle SRCU shouldn't be used if the reader can sleep unpredictably long and the memory allocation sutiation is one of these.

I don't think this matters. Each SRCU usage has its own domain, and different domains don't affect one another. So the only thing that would be blocked by a long-sleeping reader would be the suspend process itself, and obviously you won't mind that.

Alan Stern

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#22 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: Memory allocations in .suspend became very unreliable)

In reply to Alan Stern
Quoted 11 lines · Alan Stern
Quoted 9 lines · Oliver Neukum

Am Montag, 18. Januar 2010 00:00:23 schrieb Rafael J. Wysocki:

Quoted 8 lines · Benjamin Herrenschmidt
Quoted 1 line · Rafael J. Wysocki

...

Quoted 4 lines

However, it's hard to deal with the case of allocations that have already started waiting for IOs. It might be possible to have some VM hook to make them wakeup, re-evaluate the situation and get out of that code path but in any case it would be tricky.

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

In the second version of the patch I used an rwsem that made us wait for these allocations to complete before we changed gfp_allowed_mask.

This will be a very, very hot semaphore. What's the impact on performance?

Can it be replaced with something having lower overhead, such as SRCU?

I'm not sure about that. In principle SRCU shouldn't be used if the reader can sleep unpredictably long and the memory allocation sutiation is one of these.

Rafael

#23 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: [linux-pm] Memory allocations in .suspend became very unreliable)

In reply to Oliver Neukum
Quoted 9 lines · Oliver Neukum

Am Montag, 18. Januar 2010 00:00:23 schrieb Rafael J. Wysocki:

Quoted 8 lines · Benjamin Herrenschmidt
Quoted 1 line · Rafael J. Wysocki

...

Quoted 4 lines

However, it's hard to deal with the case of allocations that have already started waiting for IOs. It might be possible to have some VM hook to make them wakeup, re-evaluate the situation and get out of that code path but in any case it would be tricky.

Quoted 4 lines
Quoted 2 lines

In the second version of the patch I used an rwsem that made us wait for these allocations to complete before we changed gfp_allowed_mask.

This will be a very, very hot semaphore. What's the impact on performance?

rwsems are highly optimized AFAICT, but this is a good question of course.

I have no data at the moment.

Rafael

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#24 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: Memory allocations in .suspend became very unreliable)

In reply to Oliver Neukum
Quoted 9 lines · Oliver Neukum

Am Montag, 18. Januar 2010 00:00:23 schrieb Rafael J. Wysocki:

Quoted 8 lines · Benjamin Herrenschmidt
Quoted 1 line · Rafael J. Wysocki

...

Quoted 4 lines

However, it's hard to deal with the case of allocations that have already started waiting for IOs. It might be possible to have some VM hook to make them wakeup, re-evaluate the situation and get out of that code path but in any case it would be tricky.

Quoted 4 lines
Quoted 2 lines

In the second version of the patch I used an rwsem that made us wait for these allocations to complete before we changed gfp_allowed_mask.

This will be a very, very hot semaphore. What's the impact on performance?

rwsems are highly optimized AFAICT, but this is a good question of course.

I have no data at the moment.

Rafael

#25 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: Memory allocations in .suspend became very unreliable)

In reply to Rafael J. Wysocki

Am Montag, 18. Januar 2010 00:00:23 schrieb Rafael J. Wysocki:

Quoted 10 lines · Benjamin Herrenschmidt
Quoted 1 line · Rafael J. Wysocki

...

Quoted 4 lines

However, it's hard to deal with the case of allocations that have already started waiting for IOs. It might be possible to have some VM hook to make them wakeup, re-evaluate the situation and get out of that code path but in any case it would be tricky.

In the second version of the patch I used an rwsem that made us wait for these allocations to complete before we changed gfp_allowed_mask.

This will be a very, very hot semaphore. What's the impact on performance?

Regards
Oliver

#26 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: Memory allocations in .suspend became very unreliable)

In reply to Rafael J. Wysocki
Quoted 8 lines · Rafael J. Wysocki
Quoted 1 line · Benjamin Herrenschmidt

On Sun, 2010-01-17 at 14:27 +0100, Rafael J. Wysocki wrote:

...

Quoted 4 lines

However, it's hard to deal with the case of allocations that have already started waiting for IOs. It might be possible to have some VM hook to make them wakeup, re-evaluate the situation and get out of that code path but in any case it would be tricky.

Quoted 5 lines

In the second version of the patch I used an rwsem that made us wait for these allocations to complete before we changed gfp_allowed_mask.

[This is kinda buggy in the version I sent, but I'm going to send an update in a minute.]

And nobody screamed due to cache line ping pong caused by this in the fast path ? :-)

We might want to look at something a bit smarter for that sort of read-mostly-really-really-mostly construct, though in this case I don't think RCU is the answer since we are happily scheduling.

I wonder if something per-cpu would do, it's thus the responsibility of the "writer" to take them all in order for all CPUs.

Cheers,
Ben.

#27 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: [linux-pm] Memory allocations in .suspend became very unreliable)

In reply to Rafael J. Wysocki
Quoted 8 lines · Rafael J. Wysocki
Quoted 1 line · Benjamin Herrenschmidt

On Sun, 2010-01-17 at 14:27 +0100, Rafael J. Wysocki wrote:

...

Quoted 4 lines

However, it's hard to deal with the case of allocations that have already started waiting for IOs. It might be possible to have some VM hook to make them wakeup, re-evaluate the situation and get out of that code path but in any case it would be tricky.

Quoted 5 lines

In the second version of the patch I used an rwsem that made us wait for these allocations to complete before we changed gfp_allowed_mask.

[This is kinda buggy in the version I sent, but I'm going to send an update in a minute.]

And nobody screamed due to cache line ping pong caused by this in the fast path ? :-)

We might want to look at something a bit smarter for that sort of read-mostly-really-really-mostly construct, though in this case I don't think RCU is the answer since we are happily scheduling.

I wonder if something per-cpu would do, it's thus the responsibility of the "writer" to take them all in order for all CPUs.

Cheers,
Ben.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#28 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: [linux-pm] Memory allocations in .suspend became very unreliable)

Quoted 9 lines · Benjamin Herrenschmidt
Quoted 8 lines · Rafael J. Wysocki
Quoted 1 line · Benjamin Herrenschmidt

On Sun, 2010-01-17 at 14:27 +0100, Rafael J. Wysocki wrote:

...

Quoted 4 lines

However, it's hard to deal with the case of allocations that have already started waiting for IOs. It might be possible to have some VM hook to make them wakeup, re-evaluate the situation and get out of that code path but in any case it would be tricky.

Quoted 8 lines
Quoted 5 lines

In the second version of the patch I used an rwsem that made us wait for these allocations to complete before we changed gfp_allowed_mask.

[This is kinda buggy in the version I sent, but I'm going to send an update in a minute.]

And nobody screamed due to cache line ping pong caused by this in the fast path ? :-)

Apparently not. :-)

Quoted 6 lines

We might want to look at something a bit smarter for that sort of read-mostly-really-really-mostly construct, though in this case I don't think RCU is the answer since we are happily scheduling.

I wonder if something per-cpu would do, it's thus the responsibility of the "writer" to take them all in order for all CPUs.

I think I'll get back to the first version of the patch which I think is not going to have side effects (as long as no one will change gfp_allowed_mask in parallel with suspend/resume), for now.

We can add more complicated things on top of it, then.

Rafael

#29 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: Memory allocations in .suspend became very unreliable)

In reply to Benjamin Herrenschmidt
Quoted 9 lines · Benjamin Herrenschmidt
Quoted 8 lines · Rafael J. Wysocki
Quoted 1 line · Benjamin Herrenschmidt

On Sun, 2010-01-17 at 14:27 +0100, Rafael J. Wysocki wrote:

...

Quoted 4 lines

However, it's hard to deal with the case of allocations that have already started waiting for IOs. It might be possible to have some VM hook to make them wakeup, re-evaluate the situation and get out of that code path but in any case it would be tricky.

Quoted 8 lines
Quoted 5 lines

In the second version of the patch I used an rwsem that made us wait for these allocations to complete before we changed gfp_allowed_mask.

[This is kinda buggy in the version I sent, but I'm going to send an update in a minute.]

And nobody screamed due to cache line ping pong caused by this in the fast path ? :-)

Apparently not. :-)

Quoted 6 lines

We might want to look at something a bit smarter for that sort of read-mostly-really-really-mostly construct, though in this case I don't think RCU is the answer since we are happily scheduling.

I wonder if something per-cpu would do, it's thus the responsibility of the "writer" to take them all in order for all CPUs.

I think I'll get back to the first version of the patch which I think is not going to have side effects (as long as no one will change gfp_allowed_mask in parallel with suspend/resume), for now.

We can add more complicated things on top of it, then.

Rafael

#30 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: Memory allocations in .suspend became very unreliable)

In reply to Benjamin Herrenschmidt
Quoted 1 line · Benjamin Herrenschmidt

On Sun, 2010-01-17 at 14:27 +0100, Rafael J. Wysocki wrote:

...

Quoted 4 lines

However, it's hard to deal with the case of allocations that have already started waiting for IOs. It might be possible to have some VM hook to make them wakeup, re-evaluate the situation and get out of that code path but in any case it would be tricky.

In the second version of the patch I used an rwsem that made us wait for these allocations to complete before we changed gfp_allowed_mask.

[This is kinda buggy in the version I sent, but I'm going to send an update in a minute.]

Rafael

#31 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: Memory allocations in .suspend became very unreliable)

In reply to Oliver Neukum
Quoted 5 lines · Oliver Neukum

Am Sonntag, 17. Januar 2010 01:38:37 schrieb Rafael J. Wysocki:

Quoted 4 lines
Quoted 3 lines

Now having said that, we've been considering a change that will turn all GFP_KERNEL allocations into GFP_NOIO during suspend/resume, so perhaps I'll prepare a patch to do that and let's see what people think.

Quoted 8 lines
Quoted 5 lines

If I didn't confuse anything (which is likely, because it's a bit late here now), the patch below should do the trick. I have only checked that it doesn't break compilation, so please take it with a grain of salt.

Comments welcome.

I think this is a bad idea as it makes the mm subsystem behave differently in the runtime and in the whole system cases.

s/runtime/suspend/ ?

Yes it will, but why exactly shouldn't it? System suspend/resume _is_ a special situation anyway.

Quoted 2 lines

What's so hard about telling people that they need to use GFP_NOIO in suspend() and resume()?

Memory allocations are made for other purposes during suspend/resume too. For example, new kernel threads may be created (for async suspend/resume among other things).

Besides, the fact that you tell people to do something doesn't necessary imply that they will listen. :-)

I have discussed that with Ben for a couple of times and we have generally agreed that memory allocation problems during suspend/resume are not avoidable in general unless we disable __GFP_FS and __GFP_IO at the high level.

Rafael

#32 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: Memory allocations in .suspend became very unreliable)

In reply to Rafael J. Wysocki

Am Sonntag, 17. Januar 2010 01:38:37 schrieb Rafael J. Wysocki:

Quoted 9 lines
Quoted 3 lines

Now having said that, we've been considering a change that will turn all GFP_KERNEL allocations into GFP_NOIO during suspend/resume, so perhaps I'll prepare a patch to do that and let's see what people think.

If I didn't confuse anything (which is likely, because it's a bit late here now), the patch below should do the trick. I have only checked that it doesn't break compilation, so please take it with a grain of salt.

Comments welcome.

I think this is a bad idea as it makes the mm subsystem behave differently in the runtime and in the whole system cases. What's so hard about telling people that they need to use GFP_NOIO in suspend() and resume()?

Regards
Oliver

#33 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: [linux-pm] Memory allocations in .suspend became very unreliable)

In reply to Rafael J. Wysocki
Quoted 52 lines · Rafael J. Wysocki

Hi,

I thing the snippet below is a good summary of what this is about.

Quoted 27 lines · Rafael J. Wysocki
Quoted 26 lines · Maxim Levitsky
Quoted 25 lines · Rafael J. Wysocki
Quoted 23 lines · Maxim Levitsky
Quoted 15 lines · Rafael J. Wysocki
Quoted 1 line · Maxim Levitsky

Hi,

Hi,

Quoted 9 lines

I know that this is very controversial, because here I want to describe a problem in a proprietary driver that happens now in 2.6.33-rc3 I am taking about nvidia driver.

Some time ago I did very long hibernate test and found no errors after more that 200 cycles.

Now I update to 2.6.33 and notice that system will hand when nvidia driver allocates memory is their .suspend functions.

Quoted 6 lines

They shouldn't do that, there's no guarantee that's going to work at all.

Quoted 2 lines

This could fail in 2.6.32 if I would run many memory hungry applications, but now this happens with most of memory free.

This sounds a little strange. What's the requested size of the image?

Don't know, but system has to be very tight on memory.

Quoted 8 lines
Quoted 8 lines
Quoted 1 line

Can you send full dmesg, please?

I deleted it, but for this case I think that hang was somewhere else. This task was hand on doing forking, which probably happened even before the freezer.

Anyway, the problem is clear. Now __get_free_pages blocks more often, and can block in .suspend even if there is plenty of memory free.

This is suspicious, but I leave it to the MM people for consideration.

Quoted 9 lines
Quoted 4 lines

I now patched nvidia to use GFP_ATOMIC _always_, and problem disappear. It isn't such great solution when memory is tight though....

This is going to hit hard all nvidia users...

Well, generally speaking, no driver should ever allocate memory using GFP_KERNEL in its .suspend() routine, because that's not going to work, as you can readily see. So this is a NVidia bug, hands down.

Quoted 7 lines
Quoted 3 lines

Now having said that, we've been considering a change that will turn all GFP_KERNEL allocations into GFP_NOIO during suspend/resume, so perhaps I'll prepare a patch to do that and let's see what people think.

If I didn't confuse anything (which is likely, because it's a bit late here now), the patch below should do the trick. I have only checked that it doesn't break compilation, so please take it with a grain of salt.

Appended is another version that attempts to remove some possible races. It's been tested a little too.

Rafael

---
 include/linux/gfp.h      |    5 +----
 kernel/power/hibernate.c |    6 ++++++
 kernel/power/main.c      |    1 +
 kernel/power/power.h     |    3 +++
 kernel/power/suspend.c   |    2 ++
 mm/Makefile              |    1 +
 mm/internal.h            |    3 +++
 mm/page_alloc.c          |   16 +++++++++++++++-
 mm/pm.c                  |   34 ++++++++++++++++++++++++++++++++++
 9 files changed, 66 insertions(+), 5 deletions(-)
include/linux/gfp.h +1 -4
Index: linux-2.6/include/linux/gfp.h
===================================================================
@@ -337,9 +337,6 @@ void drain_local_pages(void *dummy);
 
 extern gfp_t gfp_allowed_mask;
 
-static inline void set_gfp_allowed_mask(gfp_t mask)
-{
-	gfp_allowed_mask = mask;
-}
+extern void set_gfp_allowed_mask(gfp_t mask);
 
 #endif /* __LINUX_GFP_H */
kernel/power/hibernate.c +6 -0
Index: linux-2.6/kernel/power/hibernate.c
===================================================================
@@ -334,6 +334,7 @@ int hibernation_snapshot(int platform_mo
 		goto Close;
 
 	suspend_console();
+	mm_force_noio_allocations();
 	error = dpm_suspend_start(PMSG_FREEZE);
 	if (error)
 		goto Recover_platform;
@@ -351,6 +352,7 @@ int hibernation_snapshot(int platform_mo
 
 	dpm_resume_end(in_suspend ?
 		(error ? PMSG_RECOVER : PMSG_THAW) : PMSG_RESTORE);
+	mm_allow_io_allocations();
 	resume_console();
  Close:
 	platform_end(platform_mode);
@@ -448,11 +450,13 @@ int hibernation_restore(int platform_mod
 
 	pm_prepare_console();
 	suspend_console();
+	mm_force_noio_allocations();
 	error = dpm_suspend_start(PMSG_QUIESCE);
 	if (!error) {
 		error = resume_target_kernel(platform_mode);
 		dpm_resume_end(PMSG_RECOVER);
 	}
+	mm_allow_io_allocations();
 	resume_console();
 	pm_restore_console();
 	return error;
@@ -481,6 +485,7 @@ int hibernation_platform_enter(void)
 
 	entering_platform_hibernation = true;
 	suspend_console();
+	mm_force_noio_allocations();
 	error = dpm_suspend_start(PMSG_HIBERNATE);
 	if (error) {
 		if (hibernation_ops->recover)
@@ -518,6 +523,7 @@ int hibernation_platform_enter(void)
  Resume_devices:
 	entering_platform_hibernation = false;
 	dpm_resume_end(PMSG_RESTORE);
+	mm_allow_io_allocations();
 	resume_console();
 
  Close:
kernel/power/power.h +3 -0
Index: linux-2.6/kernel/power/power.h
===================================================================
@@ -187,6 +187,9 @@ static inline void suspend_test_finish(c
 #ifdef CONFIG_PM_SLEEP
 /* kernel/power/main.c */
 extern int pm_notifier_call_chain(unsigned long val);
+/* mm/pm.c */
+extern void mm_force_noio_allocations(void);
+extern void mm_allow_io_allocations(void);
 #endif
 
 #ifdef CONFIG_HIGHMEM
kernel/power/suspend.c +2 -0
Index: linux-2.6/kernel/power/suspend.c
===================================================================
@@ -208,6 +208,7 @@ int suspend_devices_and_enter(suspend_st
 			goto Close;
 	}
 	suspend_console();
+	mm_force_noio_allocations();
 	suspend_test_start();
 	error = dpm_suspend_start(PMSG_SUSPEND);
 	if (error) {
@@ -224,6 +225,7 @@ int suspend_devices_and_enter(suspend_st
 	suspend_test_start();
 	dpm_resume_end(PMSG_RESUME);
 	suspend_test_finish("resume devices");
+	mm_allow_io_allocations();
 	resume_console();
  Close:
 	if (suspend_ops->end)
kernel/power/main.c +1 -0
Index: linux-2.6/kernel/power/main.c
===================================================================
@@ -12,6 +12,7 @@
 #include <linux/string.h>
 #include <linux/resume-trace.h>
 #include <linux/workqueue.h>
+#include <linux/gfp.h>
 
 #include "power.h"
 
mm/page_alloc.c +15 -1
Index: linux-2.6/mm/page_alloc.c
===================================================================
@@ -76,6 +76,17 @@ unsigned long totalreserve_pages __read_
 int percpu_pagelist_fraction;
 gfp_t gfp_allowed_mask __read_mostly = GFP_BOOT_MASK;
 
+DECLARE_RWSEM(gfp_allowed_mask_sem);
+
+void set_gfp_allowed_mask(gfp_t mask)
+{
+	/* Wait for all slowpath allocations using the old mask to complete */
+	down_write(&gfp_allowed_mask_sem);
+	gfp_allowed_mask = mask;
+	up_write(&gfp_allowed_mask_sem);
+}
+
+
 #ifdef CONFIG_HUGETLB_PAGE_SIZE_VARIABLE
 int pageblock_order __read_mostly;
 #endif
@@ -1963,10 +1974,13 @@ __alloc_pages_nodemask(gfp_t gfp_mask, u
 	page = get_page_from_freelist(gfp_mask|__GFP_HARDWALL, nodemask, order,
 			zonelist, high_zoneidx, ALLOC_WMARK_LOW|ALLOC_CPUSET,
 			preferred_zone, migratetype);
-	if (unlikely(!page))
+	if (unlikely(!page)) {
+		down_read(&gfp_allowed_mask_sem);
 		page = __alloc_pages_slowpath(gfp_mask, order,
 				zonelist, high_zoneidx, nodemask,
 				preferred_zone, migratetype);
+		up_read(&gfp_allowed_mask_sem);
+	}
 
 	trace_mm_page_alloc(page, order, gfp_mask, migratetype);
 	return page;
mm/Makefile +1 -0
Index: linux-2.6/mm/Makefile
===================================================================
@@ -40,3 +40,4 @@ obj-$(CONFIG_MEMORY_FAILURE) += memory-f
 obj-$(CONFIG_HWPOISON_INJECT) += hwpoison-inject.o
 obj-$(CONFIG_DEBUG_KMEMLEAK) += kmemleak.o
 obj-$(CONFIG_DEBUG_KMEMLEAK_TEST) += kmemleak-test.o
+obj-$(CONFIG_PM_SLEEP) += pm.o
mm/pm.c new file +34 -0
Index: linux-2.6/mm/pm.c
===================================================================
@@ -0,0 +1,34 @@
+#include "internal.h"
+
+static gfp_t saved_gfp_allowed_mask;
+
+/**
+ * mm_force_noio_allocations - Modify gfp_allowed_mask to disable IO allocations
+ *
+ * Change gfp_allowed_mask by unsetting __GFP_IO and __GFP_FS in it and save the
+ * old value.
+ */
+void mm_force_noio_allocations(void)
+{
+	/* Wait for all slowpath allocations using the old mask to complete */
+	down_write(&gfp_allowed_mask_sem);
+	saved_gfp_allowed_mask = gfp_allowed_mask;
+	gfp_allowed_mask &= ~(__GFP_IO | __GFP_FS);
+	up_write(&gfp_allowed_mask_sem);
+}
+
+/**
+ * mm_allow_io_allocations - Modify gfp_allowed_mask to allow IO allocations
+ *
+ * If the saved value of gfp_allowed_mask has __GFP_IO set, modify the current
+ * gfp_allowed_mask by setting this bit and anlogously for __GFP_FS.
+ */
+void mm_allow_io_allocations(void)
+{
+	gfp_t gfp_mask = saved_gfp_allowed_mask & (__GFP_IO | __GFP_FS);
+
+	/* Wait for all slowpath allocations using the old mask to complete */
+	down_write(&gfp_allowed_mask_sem);
+	gfp_allowed_mask |= gfp_mask;
+	up_write(&gfp_allowed_mask_sem);
+}
mm/internal.h +3 -0
Index: linux-2.6/mm/internal.h
===================================================================
@@ -12,6 +12,7 @@
 #define __MM_INTERNAL_H
 
 #include <linux/mm.h>
+#include <linux/rwsem.h>
 
 void free_pgtables(struct mmu_gather *tlb, struct vm_area_struct *start_vma,
 		unsigned long floor, unsigned long ceiling);
@@ -259,3 +260,5 @@ extern u64 hwpoison_filter_flags_mask;
 extern u64 hwpoison_filter_flags_value;
 extern u64 hwpoison_filter_memcg;
 extern u32 hwpoison_filter_enable;
+
+extern struct rw_semaphore gfp_allowed_mask_sem;

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#34 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: Memory allocations in .suspend became very unreliable)

Hi, Rafael.

Quoted 194 lines · Rafael J. Wysocki
Quoted 52 lines · Rafael J. Wysocki

Hi,

I thing the snippet below is a good summary of what this is about.

Quoted 27 lines · Rafael J. Wysocki
Quoted 26 lines · Maxim Levitsky
Quoted 25 lines · Rafael J. Wysocki
Quoted 23 lines · Maxim Levitsky
Quoted 15 lines · Rafael J. Wysocki
Quoted 1 line · Maxim Levitsky

Hi,

Hi,

Quoted 9 lines

I know that this is very controversial, because here I want to describe a problem in a proprietary driver that happens now in 2.6.33-rc3 I am taking about nvidia driver.

Some time ago I did very long hibernate test and found no errors after more that 200 cycles.

Now I update to 2.6.33 and notice that system will hand when nvidia driver allocates memory is their .suspend functions.

Quoted 6 lines

They shouldn't do that, there's no guarantee that's going to work at all.

Quoted 2 lines

This could fail in 2.6.32 if I would run many memory hungry applications, but now this happens with most of memory free.

This sounds a little strange. What's the requested size of the image?

Don't know, but system has to be very tight on memory.

Quoted 8 lines
Quoted 8 lines
Quoted 1 line

Can you send full dmesg, please?

I deleted it, but for this case I think that hang was somewhere else. This task was hand on doing forking, which probably happened even before the freezer.

Anyway, the problem is clear. Now __get_free_pages blocks more often, and can block in .suspend even if there is plenty of memory free.

This is suspicious, but I leave it to the MM people for consideration.

Quoted 9 lines
Quoted 4 lines

I now patched nvidia to use GFP_ATOMIC _always_, and problem disappear. It isn't such great solution when memory is tight though....

This is going to hit hard all nvidia users...

Well, generally speaking, no driver should ever allocate memory using GFP_KERNEL in its .suspend() routine, because that's not going to work, as you can readily see. So this is a NVidia bug, hands down.

Quoted 7 lines
Quoted 3 lines

Now having said that, we've been considering a change that will turn all GFP_KERNEL allocations into GFP_NOIO during suspend/resume, so perhaps I'll prepare a patch to do that and let's see what people think.

If I didn't confuse anything (which is likely, because it's a bit late here now), the patch below should do the trick. I have only checked that it doesn't break compilation, so please take it with a grain of salt.

Appended is another version that attempts to remove some possible races. It's been tested a little too.

Rafael

---
 include/linux/gfp.h      |    5 +----
 kernel/power/hibernate.c |    6 ++++++
 kernel/power/main.c      |    1 +
 kernel/power/power.h     |    3 +++
 kernel/power/suspend.c   |    2 ++
 mm/Makefile              |    1 +
 mm/internal.h            |    3 +++
 mm/page_alloc.c          |   16 +++++++++++++++-
 mm/pm.c                  |   34 ++++++++++++++++++++++++++++++++++
 9 files changed, 66 insertions(+), 5 deletions(-)

Index: linux-2.6/include/linux/gfp.h
===================================================================

include/linux/gfp.h +1 -4
@@ -337,9 +337,6 @@ void drain_local_pages(void *dummy);
 
 extern gfp_t gfp_allowed_mask;
 
-static inline void set_gfp_allowed_mask(gfp_t mask)
-{
-	gfp_allowed_mask = mask;
-}
+extern void set_gfp_allowed_mask(gfp_t mask);
 
 #endif /* __LINUX_GFP_H */

Index: linux-2.6/kernel/power/hibernate.c
===================================================================

kernel/power/hibernate.c +6 -0
@@ -334,6 +334,7 @@ int hibernation_snapshot(int platform_mo
 		goto Close;
 
 	suspend_console();
+	mm_force_noio_allocations();
 	error = dpm_suspend_start(PMSG_FREEZE);
 	if (error)
 		goto Recover_platform;
@@ -351,6 +352,7 @@ int hibernation_snapshot(int platform_mo
 
 	dpm_resume_end(in_suspend ?
 		(error ? PMSG_RECOVER : PMSG_THAW) : PMSG_RESTORE);
+	mm_allow_io_allocations();
 	resume_console();
  Close:
 	platform_end(platform_mode);
@@ -448,11 +450,13 @@ int hibernation_restore(int platform_mod
 
 	pm_prepare_console();
 	suspend_console();
+	mm_force_noio_allocations();
 	error = dpm_suspend_start(PMSG_QUIESCE);
 	if (!error) {
 		error = resume_target_kernel(platform_mode);
 		dpm_resume_end(PMSG_RECOVER);
 	}
+	mm_allow_io_allocations();
 	resume_console();
 	pm_restore_console();
 	return error;
@@ -481,6 +485,7 @@ int hibernation_platform_enter(void)
 
 	entering_platform_hibernation = true;
 	suspend_console();
+	mm_force_noio_allocations();
 	error = dpm_suspend_start(PMSG_HIBERNATE);
 	if (error) {
 		if (hibernation_ops->recover)
@@ -518,6 +523,7 @@ int hibernation_platform_enter(void)
  Resume_devices:
 	entering_platform_hibernation = false;
 	dpm_resume_end(PMSG_RESTORE);
+	mm_allow_io_allocations();
 	resume_console();
 
  Close:

Index: linux-2.6/kernel/power/power.h
===================================================================

kernel/power/power.h +3 -0
@@ -187,6 +187,9 @@ static inline void suspend_test_finish(c
 #ifdef CONFIG_PM_SLEEP
 /* kernel/power/main.c */
 extern int pm_notifier_call_chain(unsigned long val);
+/* mm/pm.c */
+extern void mm_force_noio_allocations(void);
+extern void mm_allow_io_allocations(void);
 #endif
 
 #ifdef CONFIG_HIGHMEM

Index: linux-2.6/kernel/power/suspend.c
===================================================================

kernel/power/suspend.c +2 -0
@@ -208,6 +208,7 @@ int suspend_devices_and_enter(suspend_st
 			goto Close;
 	}
 	suspend_console();
+	mm_force_noio_allocations();
 	suspend_test_start();
 	error = dpm_suspend_start(PMSG_SUSPEND);
 	if (error) {
@@ -224,6 +225,7 @@ int suspend_devices_and_enter(suspend_st
 	suspend_test_start();
 	dpm_resume_end(PMSG_RESUME);
 	suspend_test_finish("resume devices");
+	mm_allow_io_allocations();
 	resume_console();
  Close:
 	if (suspend_ops->end)

Index: linux-2.6/kernel/power/main.c
===================================================================

kernel/power/main.c +1 -0
@@ -12,6 +12,7 @@
 #include <linux/string.h>
 #include <linux/resume-trace.h>
 #include <linux/workqueue.h>
+#include <linux/gfp.h>
 
 #include "power.h"
 

Index: linux-2.6/mm/page_alloc.c
===================================================================

mm/page_alloc.c unsigned long totalreserve_pages __read_ · line 83

Quoted 8 lines
mm/page_alloc.c +5 -0
@@ -76,6 +76,17 @@ unsigned long totalreserve_pages __read_
 int percpu_pagelist_fraction;
 gfp_t gfp_allowed_mask __read_mostly = GFP_BOOT_MASK;
 
+DECLARE_RWSEM(gfp_allowed_mask_sem);
+
+void set_gfp_allowed_mask(gfp_t mask)
+{
+	/* Wait for all slowpath allocations using the old mask to complete */

We used gfp_allowed_mask in fast path.
Why did you consider only slow path?

Quoted 45 lines
mm/page_alloc.c +10 -1
+	down_write(&gfp_allowed_mask_sem);
+	gfp_allowed_mask = mask;
+	up_write(&gfp_allowed_mask_sem);
+}
+
+
 #ifdef CONFIG_HUGETLB_PAGE_SIZE_VARIABLE
 int pageblock_order __read_mostly;
 #endif
@@ -1963,10 +1974,13 @@ __alloc_pages_nodemask(gfp_t gfp_mask, u
 	page = get_page_from_freelist(gfp_mask|__GFP_HARDWALL, nodemask, order,
 			zonelist, high_zoneidx, ALLOC_WMARK_LOW|ALLOC_CPUSET,
 			preferred_zone, migratetype);
-	if (unlikely(!page))
+	if (unlikely(!page)) {
+		down_read(&gfp_allowed_mask_sem);
 		page = __alloc_pages_slowpath(gfp_mask, order,
 				zonelist, high_zoneidx, nodemask,
 				preferred_zone, migratetype);
+		up_read(&gfp_allowed_mask_sem);
+	}
 
 	trace_mm_page_alloc(page, order, gfp_mask, migratetype);
 	return page;

Index: linux-2.6/mm/Makefile
===================================================================

mm/Makefile +1 -0
@@ -40,3 +40,4 @@ obj-$(CONFIG_MEMORY_FAILURE) += memory-f
 obj-$(CONFIG_HWPOISON_INJECT) += hwpoison-inject.o
 obj-$(CONFIG_DEBUG_KMEMLEAK) += kmemleak.o
 obj-$(CONFIG_DEBUG_KMEMLEAK_TEST) += kmemleak-test.o
+obj-$(CONFIG_PM_SLEEP) += pm.o

Index: linux-2.6/mm/pm.c
===================================================================

mm/pm.c new file +7 -0
@@ -0,0 +1,34 @@
+#include "internal.h"
+
+static gfp_t saved_gfp_allowed_mask;
+
+/**
+ * mm_force_noio_allocations - Modify gfp_allowed_mask to disable IO allocations
+ *

mm/pm.c line 17

Quoted 10 lines
mm/pm.c new file +10 -0
+ * Change gfp_allowed_mask by unsetting __GFP_IO and __GFP_FS in it and save the
+ * old value.
+ */
+void mm_force_noio_allocations(void)
+{
+	/* Wait for all slowpath allocations using the old mask to complete */
+	down_write(&gfp_allowed_mask_sem);
+	saved_gfp_allowed_mask = gfp_allowed_mask;
+	gfp_allowed_mask &= ~(__GFP_IO | __GFP_FS);
+	up_write(&gfp_allowed_mask_sem);

How about using set_gfp_allowed_mask?
Let's return old mask in set_gfp_allowed_mask.

Quoted 6 lines
mm/pm.c new file +6 -0
+}
+
+/**
+ * mm_allow_io_allocations - Modify gfp_allowed_mask to allow IO allocations
+ *
+ * If the saved value of gfp_allowed_mask has __GFP_IO set, modify the current

mm/pm.c line 33

Quoted 10 lines
mm/pm.c new file +10 -0
+ * gfp_allowed_mask by setting this bit and anlogously for __GFP_FS.
+ */
+void mm_allow_io_allocations(void)
+{
+	gfp_t gfp_mask = saved_gfp_allowed_mask & (__GFP_IO | __GFP_FS);
+
+	/* Wait for all slowpath allocations using the old mask to complete */
+	down_write(&gfp_allowed_mask_sem);
+	gfp_allowed_mask |= gfp_mask;
+	up_write(&gfp_allowed_mask_sem);

Ditto

Quoted 14 lines
mm/pm.c new file +1 -0
+}

Index: linux-2.6/mm/internal.h
===================================================================

mm/internal.h +1 -0
@@ -12,6 +12,7 @@
 #define __MM_INTERNAL_H
 
 #include <linux/mm.h>
+#include <linux/rwsem.h>
 
 void free_pgtables(struct mmu_gather *tlb, struct vm_area_struct *start_vma,
 		unsigned long floor, unsigned long ceiling);

mm/internal.h extern u64 hwpoison_filter_flags_mask; · line 264

Quoted 5 lines
mm/internal.h +2 -0
@@ -259,3 +260,5 @@ extern u64 hwpoison_filter_flags_mask;
 extern u64 hwpoison_filter_flags_value;
 extern u64 hwpoison_filter_memcg;
 extern u32 hwpoison_filter_enable;
+
+extern struct rw_semaphore gfp_allowed_mask_sem;

I think we can use lockdep annotation, too. but it's overkill. That's because suspend/resume is rare event so that I want to add the cost in lockdep. so I like this idea. But, I have a concern. You are adding a little bit cost in alloc path although it's slow one.

Really really do we need this?
Can't we remove the wrong usage in review or test process before merge?

I don't have many experience at suspend/resume. I depends on your experience about this patch's value. :)

Thanks.

Signature · 2 lines
Kind regards,
Minchan Kim
#35 lore raw

Re: [linux-pm] [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: Memory allocations in .suspend became very unreliable)

In reply to Rafael J. Wysocki

Hi, Rafael.

Quoted 194 lines · Rafael J. Wysocki
Quoted 52 lines · Rafael J. Wysocki

Hi,

I thing the snippet below is a good summary of what this is about.

Quoted 27 lines · Rafael J. Wysocki
Quoted 26 lines · Maxim Levitsky
Quoted 25 lines · Rafael J. Wysocki
Quoted 23 lines · Maxim Levitsky
Quoted 15 lines · Rafael J. Wysocki
Quoted 1 line · Maxim Levitsky

Hi,

Hi,

Quoted 9 lines

I know that this is very controversial, because here I want to describe a problem in a proprietary driver that happens now in 2.6.33-rc3 I am taking about nvidia driver.

Some time ago I did very long hibernate test and found no errors after more that 200 cycles.

Now I update to 2.6.33 and notice that system will hand when nvidia driver allocates memory is their .suspend functions.

Quoted 6 lines

They shouldn't do that, there's no guarantee that's going to work at all.

Quoted 2 lines

This could fail in 2.6.32 if I would run many memory hungry applications, but now this happens with most of memory free.

This sounds a little strange. What's the requested size of the image?

Don't know, but system has to be very tight on memory.

Quoted 8 lines
Quoted 8 lines
Quoted 1 line

Can you send full dmesg, please?

I deleted it, but for this case I think that hang was somewhere else. This task was hand on doing forking, which probably happened even before the freezer.

Anyway, the problem is clear. Now __get_free_pages blocks more often, and can block in .suspend even if there is plenty of memory free.

This is suspicious, but I leave it to the MM people for consideration.

Quoted 9 lines
Quoted 4 lines

I now patched nvidia to use GFP_ATOMIC _always_, and problem disappear. It isn't such great solution when memory is tight though....

This is going to hit hard all nvidia users...

Well, generally speaking, no driver should ever allocate memory using GFP_KERNEL in its .suspend() routine, because that's not going to work, as you can readily see. So this is a NVidia bug, hands down.

Quoted 7 lines
Quoted 3 lines

Now having said that, we've been considering a change that will turn all GFP_KERNEL allocations into GFP_NOIO during suspend/resume, so perhaps I'll prepare a patch to do that and let's see what people think.

If I didn't confuse anything (which is likely, because it's a bit late here now), the patch below should do the trick. I have only checked that it doesn't break compilation, so please take it with a grain of salt.

Appended is another version that attempts to remove some possible races. It's been tested a little too.

Rafael

---
 include/linux/gfp.h      |    5 +----
 kernel/power/hibernate.c |    6 ++++++
 kernel/power/main.c      |    1 +
 kernel/power/power.h     |    3 +++
 kernel/power/suspend.c   |    2 ++
 mm/Makefile              |    1 +
 mm/internal.h            |    3 +++
 mm/page_alloc.c          |   16 +++++++++++++++-
 mm/pm.c                  |   34 ++++++++++++++++++++++++++++++++++
 9 files changed, 66 insertions(+), 5 deletions(-)

Index: linux-2.6/include/linux/gfp.h
===================================================================

include/linux/gfp.h +1 -4
@@ -337,9 +337,6 @@ void drain_local_pages(void *dummy);
 
 extern gfp_t gfp_allowed_mask;
 
-static inline void set_gfp_allowed_mask(gfp_t mask)
-{
-	gfp_allowed_mask = mask;
-}
+extern void set_gfp_allowed_mask(gfp_t mask);
 
 #endif /* __LINUX_GFP_H */

Index: linux-2.6/kernel/power/hibernate.c
===================================================================

kernel/power/hibernate.c +6 -0
@@ -334,6 +334,7 @@ int hibernation_snapshot(int platform_mo
 		goto Close;
 
 	suspend_console();
+	mm_force_noio_allocations();
 	error = dpm_suspend_start(PMSG_FREEZE);
 	if (error)
 		goto Recover_platform;
@@ -351,6 +352,7 @@ int hibernation_snapshot(int platform_mo
 
 	dpm_resume_end(in_suspend ?
 		(error ? PMSG_RECOVER : PMSG_THAW) : PMSG_RESTORE);
+	mm_allow_io_allocations();
 	resume_console();
  Close:
 	platform_end(platform_mode);
@@ -448,11 +450,13 @@ int hibernation_restore(int platform_mod
 
 	pm_prepare_console();
 	suspend_console();
+	mm_force_noio_allocations();
 	error = dpm_suspend_start(PMSG_QUIESCE);
 	if (!error) {
 		error = resume_target_kernel(platform_mode);
 		dpm_resume_end(PMSG_RECOVER);
 	}
+	mm_allow_io_allocations();
 	resume_console();
 	pm_restore_console();
 	return error;
@@ -481,6 +485,7 @@ int hibernation_platform_enter(void)
 
 	entering_platform_hibernation = true;
 	suspend_console();
+	mm_force_noio_allocations();
 	error = dpm_suspend_start(PMSG_HIBERNATE);
 	if (error) {
 		if (hibernation_ops->recover)
@@ -518,6 +523,7 @@ int hibernation_platform_enter(void)
  Resume_devices:
 	entering_platform_hibernation = false;
 	dpm_resume_end(PMSG_RESTORE);
+	mm_allow_io_allocations();
 	resume_console();
 
  Close:

Index: linux-2.6/kernel/power/power.h
===================================================================

kernel/power/power.h +3 -0
@@ -187,6 +187,9 @@ static inline void suspend_test_finish(c
 #ifdef CONFIG_PM_SLEEP
 /* kernel/power/main.c */
 extern int pm_notifier_call_chain(unsigned long val);
+/* mm/pm.c */
+extern void mm_force_noio_allocations(void);
+extern void mm_allow_io_allocations(void);
 #endif
 
 #ifdef CONFIG_HIGHMEM

Index: linux-2.6/kernel/power/suspend.c
===================================================================

kernel/power/suspend.c +2 -0
@@ -208,6 +208,7 @@ int suspend_devices_and_enter(suspend_st
 			goto Close;
 	}
 	suspend_console();
+	mm_force_noio_allocations();
 	suspend_test_start();
 	error = dpm_suspend_start(PMSG_SUSPEND);
 	if (error) {
@@ -224,6 +225,7 @@ int suspend_devices_and_enter(suspend_st
 	suspend_test_start();
 	dpm_resume_end(PMSG_RESUME);
 	suspend_test_finish("resume devices");
+	mm_allow_io_allocations();
 	resume_console();
  Close:
 	if (suspend_ops->end)

Index: linux-2.6/kernel/power/main.c
===================================================================

kernel/power/main.c +1 -0
@@ -12,6 +12,7 @@
 #include <linux/string.h>
 #include <linux/resume-trace.h>
 #include <linux/workqueue.h>
+#include <linux/gfp.h>
 
 #include "power.h"
 

Index: linux-2.6/mm/page_alloc.c
===================================================================

mm/page_alloc.c unsigned long totalreserve_pages __read_ · line 83

Quoted 8 lines
mm/page_alloc.c +5 -0
@@ -76,6 +76,17 @@ unsigned long totalreserve_pages __read_
 int percpu_pagelist_fraction;
 gfp_t gfp_allowed_mask __read_mostly = GFP_BOOT_MASK;
 
+DECLARE_RWSEM(gfp_allowed_mask_sem);
+
+void set_gfp_allowed_mask(gfp_t mask)
+{
+	/* Wait for all slowpath allocations using the old mask to complete */

We used gfp_allowed_mask in fast path.
Why did you consider only slow path?

Quoted 45 lines
mm/page_alloc.c +10 -1
+	down_write(&gfp_allowed_mask_sem);
+	gfp_allowed_mask = mask;
+	up_write(&gfp_allowed_mask_sem);
+}
+
+
 #ifdef CONFIG_HUGETLB_PAGE_SIZE_VARIABLE
 int pageblock_order __read_mostly;
 #endif
@@ -1963,10 +1974,13 @@ __alloc_pages_nodemask(gfp_t gfp_mask, u
 	page = get_page_from_freelist(gfp_mask|__GFP_HARDWALL, nodemask, order,
 			zonelist, high_zoneidx, ALLOC_WMARK_LOW|ALLOC_CPUSET,
 			preferred_zone, migratetype);
-	if (unlikely(!page))
+	if (unlikely(!page)) {
+		down_read(&gfp_allowed_mask_sem);
 		page = __alloc_pages_slowpath(gfp_mask, order,
 				zonelist, high_zoneidx, nodemask,
 				preferred_zone, migratetype);
+		up_read(&gfp_allowed_mask_sem);
+	}
 
 	trace_mm_page_alloc(page, order, gfp_mask, migratetype);
 	return page;

Index: linux-2.6/mm/Makefile
===================================================================

mm/Makefile +1 -0
@@ -40,3 +40,4 @@ obj-$(CONFIG_MEMORY_FAILURE) += memory-f
 obj-$(CONFIG_HWPOISON_INJECT) += hwpoison-inject.o
 obj-$(CONFIG_DEBUG_KMEMLEAK) += kmemleak.o
 obj-$(CONFIG_DEBUG_KMEMLEAK_TEST) += kmemleak-test.o
+obj-$(CONFIG_PM_SLEEP) += pm.o

Index: linux-2.6/mm/pm.c
===================================================================

mm/pm.c new file +7 -0
@@ -0,0 +1,34 @@
+#include "internal.h"
+
+static gfp_t saved_gfp_allowed_mask;
+
+/**
+ * mm_force_noio_allocations - Modify gfp_allowed_mask to disable IO allocations
+ *

mm/pm.c line 17

Quoted 10 lines
mm/pm.c new file +10 -0
+ * Change gfp_allowed_mask by unsetting __GFP_IO and __GFP_FS in it and save the
+ * old value.
+ */
+void mm_force_noio_allocations(void)
+{
+	/* Wait for all slowpath allocations using the old mask to complete */
+	down_write(&gfp_allowed_mask_sem);
+	saved_gfp_allowed_mask = gfp_allowed_mask;
+	gfp_allowed_mask &= ~(__GFP_IO | __GFP_FS);
+	up_write(&gfp_allowed_mask_sem);

How about using set_gfp_allowed_mask?
Let's return old mask in set_gfp_allowed_mask.

Quoted 6 lines
mm/pm.c new file +6 -0
+}
+
+/**
+ * mm_allow_io_allocations - Modify gfp_allowed_mask to allow IO allocations
+ *
+ * If the saved value of gfp_allowed_mask has __GFP_IO set, modify the current

mm/pm.c line 33

Quoted 10 lines
mm/pm.c new file +10 -0
+ * gfp_allowed_mask by setting this bit and anlogously for __GFP_FS.
+ */
+void mm_allow_io_allocations(void)
+{
+	gfp_t gfp_mask = saved_gfp_allowed_mask & (__GFP_IO | __GFP_FS);
+
+	/* Wait for all slowpath allocations using the old mask to complete */
+	down_write(&gfp_allowed_mask_sem);
+	gfp_allowed_mask |= gfp_mask;
+	up_write(&gfp_allowed_mask_sem);

Ditto

Quoted 14 lines
mm/pm.c new file +1 -0
+}

Index: linux-2.6/mm/internal.h
===================================================================

mm/internal.h +1 -0
@@ -12,6 +12,7 @@
 #define __MM_INTERNAL_H
 
 #include <linux/mm.h>
+#include <linux/rwsem.h>
 
 void free_pgtables(struct mmu_gather *tlb, struct vm_area_struct *start_vma,
 		unsigned long floor, unsigned long ceiling);

mm/internal.h extern u64 hwpoison_filter_flags_mask; · line 264

Quoted 5 lines
mm/internal.h +2 -0
@@ -259,3 +260,5 @@ extern u64 hwpoison_filter_flags_mask;
 extern u64 hwpoison_filter_flags_value;
 extern u64 hwpoison_filter_memcg;
 extern u32 hwpoison_filter_enable;
+
+extern struct rw_semaphore gfp_allowed_mask_sem;

I think we can use lockdep annotation, too. but it's overkill. That's because suspend/resume is rare event so that I want to add the cost in lockdep. so I like this idea. But, I have a concern. You are adding a little bit cost in alloc path although it's slow one.

Really really do we need this?
Can't we remove the wrong usage in review or test process before merge?

I don't have many experience at suspend/resume. I depends on your experience about this patch's value. :)

Thanks.

Signature · 8 lines
Kind regards,
Minchan Kim

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#36 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: Memory allocations in .suspend became very unreliable)

Quoted 2 lines

I think we can use lockdep annotation, too. but it's overkill. That's because suspend/resume is rare event so that I want to add

so that I don't want to add

Sorry for the typo.

Signature · 2 lines
Kind regards,
Minchan Kim
#37 lore raw

Re: [linux-pm] [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: Memory allocations in .suspend became very unreliable)

In reply to Minchan Kim
Quoted 2 lines

I think we can use lockdep annotation, too. but it's overkill. That's because suspend/resume is rare event so that I want to add

so that I don't want to add

Sorry for the typo.

Signature · 8 lines
Kind regards,
Minchan Kim

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#38 lore raw

Re: [linux-pm] [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: Memory allocations in .suspend became very unreliable)

In reply to Minchan Kim
Quoted 66 lines · Minchan Kim

Hi, Rafael.

Quoted 63 lines · Rafael J. Wysocki
Quoted 52 lines · Rafael J. Wysocki

Hi,

I thing the snippet below is a good summary of what this is about.

Quoted 27 lines · Rafael J. Wysocki
Quoted 26 lines · Maxim Levitsky
Quoted 25 lines · Rafael J. Wysocki
Quoted 23 lines · Maxim Levitsky
Quoted 15 lines · Rafael J. Wysocki
Quoted 1 line · Maxim Levitsky

Hi,

Hi,

Quoted 9 lines

I know that this is very controversial, because here I want to describe a problem in a proprietary driver that happens now in 2.6.33-rc3 I am taking about nvidia driver.

Some time ago I did very long hibernate test and found no errors after more that 200 cycles.

Now I update to 2.6.33 and notice that system will hand when nvidia driver allocates memory is their .suspend functions.

Quoted 6 lines

They shouldn't do that, there's no guarantee that's going to work at all.

Quoted 2 lines

This could fail in 2.6.32 if I would run many memory hungry applications, but now this happens with most of memory free.

This sounds a little strange. What's the requested size of the image?

Don't know, but system has to be very tight on memory.

Quoted 8 lines
Quoted 8 lines
Quoted 1 line

Can you send full dmesg, please?

I deleted it, but for this case I think that hang was somewhere else. This task was hand on doing forking, which probably happened even before the freezer.

Anyway, the problem is clear. Now __get_free_pages blocks more often, and can block in .suspend even if there is plenty of memory free.

This is suspicious, but I leave it to the MM people for consideration.

Quoted 9 lines
Quoted 4 lines

I now patched nvidia to use GFP_ATOMIC _always_, and problem disappear. It isn't such great solution when memory is tight though....

This is going to hit hard all nvidia users...

Well, generally speaking, no driver should ever allocate memory using GFP_KERNEL in its .suspend() routine, because that's not going to work, as you can readily see. So this is a NVidia bug, hands down.

Quoted 7 lines
Quoted 3 lines

Now having said that, we've been considering a change that will turn all GFP_KERNEL allocations into GFP_NOIO during suspend/resume, so perhaps I'll prepare a patch to do that and let's see what people think.

If I didn't confuse anything (which is likely, because it's a bit late here now), the patch below should do the trick. I have only checked that it doesn't break compilation, so please take it with a grain of salt.

Appended is another version that attempts to remove some possible races. It's been tested a little too.

...

Quoted 3 lines

Review

Quoted 3 lines
(quoted diff) +2 -1
-	if (unlikely(!page))
+	if (unlikely(!page)) {
+		down_read(&gfp_allowed_mask_sem);

This obviously is going too far, because it would change atomic allocations into non-atomic in general (kinda embarassing ...).

However, I think it would be sufficient to acquire the lock only in the (__GFP_IO | __GFP_FS) case. Appended is an updated patch doing this.

Quoted 5 lines
Quoted 5 lines
(quoted diff) +2 -0
 		page = __alloc_pages_slowpath(gfp_mask, order,
 				zonelist, high_zoneidx, nodemask,
 				preferred_zone, migratetype);
+		up_read(&gfp_allowed_mask_sem);
+	}

...

Quoted 7 lines

I think we can use lockdep annotation, too. but it's overkill. That's because suspend/resume is rare event so that I want to add the cost in lockdep. so I like this idea. But, I have a concern. You are adding a little bit cost in alloc path although it's slow one.

Really really do we need this?

Without it, we would have to duplicate every piece of code that normally uses GFP_KERNEL allocations and that may be called during suspend/resume. I don't really think that would be practical.

Quoted 1 line

Can't we remove the wrong usage in review or test process before merge?

That's not so simple. The Ben's message in this thread described the possible issues quite well (http://lkml.org/lkml/2010/1/17/120).

I think the suspend process should wait for all the already started allocations using I/O, because otherwise it might disturb them. So this also is a matter of correctness in general.

Quoted 2 lines

I don't have many experience at suspend/resume. I depends on your experience about this patch's value. :)

OK :-)

Rafael

---
 kernel/power/hibernate.c |    6 +++++
 kernel/power/power.h     |    3 ++
 kernel/power/suspend.c   |    2 +
 mm/Makefile              |    1 
 mm/internal.h            |    3 ++
 mm/page_alloc.c          |    5 +++-
 mm/pm.c                  |   56 +++++++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 75 insertions(+), 1 deletion(-)
kernel/power/hibernate.c +6 -0
Index: linux-2.6/kernel/power/hibernate.c
===================================================================
@@ -334,6 +334,7 @@ int hibernation_snapshot(int platform_mo
 		goto Close;
 
 	suspend_console();
+	mm_force_noio_allocations();
 	error = dpm_suspend_start(PMSG_FREEZE);
 	if (error)
 		goto Recover_platform;
@@ -351,6 +352,7 @@ int hibernation_snapshot(int platform_mo
 
 	dpm_resume_end(in_suspend ?
 		(error ? PMSG_RECOVER : PMSG_THAW) : PMSG_RESTORE);
+	mm_allow_io_allocations();
 	resume_console();
  Close:
 	platform_end(platform_mode);
@@ -448,11 +450,13 @@ int hibernation_restore(int platform_mod
 
 	pm_prepare_console();
 	suspend_console();
+	mm_force_noio_allocations();
 	error = dpm_suspend_start(PMSG_QUIESCE);
 	if (!error) {
 		error = resume_target_kernel(platform_mode);
 		dpm_resume_end(PMSG_RECOVER);
 	}
+	mm_allow_io_allocations();
 	resume_console();
 	pm_restore_console();
 	return error;
@@ -481,6 +485,7 @@ int hibernation_platform_enter(void)
 
 	entering_platform_hibernation = true;
 	suspend_console();
+	mm_force_noio_allocations();
 	error = dpm_suspend_start(PMSG_HIBERNATE);
 	if (error) {
 		if (hibernation_ops->recover)
@@ -518,6 +523,7 @@ int hibernation_platform_enter(void)
  Resume_devices:
 	entering_platform_hibernation = false;
 	dpm_resume_end(PMSG_RESTORE);
+	mm_allow_io_allocations();
 	resume_console();
 
  Close:
kernel/power/power.h +3 -0
Index: linux-2.6/kernel/power/power.h
===================================================================
@@ -187,6 +187,9 @@ static inline void suspend_test_finish(c
 #ifdef CONFIG_PM_SLEEP
 /* kernel/power/main.c */
 extern int pm_notifier_call_chain(unsigned long val);
+/* mm/pm.c */
+extern void mm_force_noio_allocations(void);
+extern void mm_allow_io_allocations(void);
 #endif
 
 #ifdef CONFIG_HIGHMEM
kernel/power/suspend.c +2 -0
Index: linux-2.6/kernel/power/suspend.c
===================================================================
@@ -208,6 +208,7 @@ int suspend_devices_and_enter(suspend_st
 			goto Close;
 	}
 	suspend_console();
+	mm_force_noio_allocations();
 	suspend_test_start();
 	error = dpm_suspend_start(PMSG_SUSPEND);
 	if (error) {
@@ -224,6 +225,7 @@ int suspend_devices_and_enter(suspend_st
 	suspend_test_start();
 	dpm_resume_end(PMSG_RESUME);
 	suspend_test_finish("resume devices");
+	mm_allow_io_allocations();
 	resume_console();
  Close:
 	if (suspend_ops->end)
mm/page_alloc.c +4 -1
Index: linux-2.6/mm/page_alloc.c
===================================================================
@@ -1963,10 +1963,13 @@ __alloc_pages_nodemask(gfp_t gfp_mask, u
 	page = get_page_from_freelist(gfp_mask|__GFP_HARDWALL, nodemask, order,
 			zonelist, high_zoneidx, ALLOC_WMARK_LOW|ALLOC_CPUSET,
 			preferred_zone, migratetype);
-	if (unlikely(!page))
+	if (unlikely(!page)) {
+		mm_lock_suspend(gfp_mask);
 		page = __alloc_pages_slowpath(gfp_mask, order,
 				zonelist, high_zoneidx, nodemask,
 				preferred_zone, migratetype);
+		mm_unlock_suspend(gfp_mask);
+	}
 
 	trace_mm_page_alloc(page, order, gfp_mask, migratetype);
 	return page;
mm/Makefile +1 -0
Index: linux-2.6/mm/Makefile
===================================================================
@@ -40,3 +40,4 @@ obj-$(CONFIG_MEMORY_FAILURE) += memory-f
 obj-$(CONFIG_HWPOISON_INJECT) += hwpoison-inject.o
 obj-$(CONFIG_DEBUG_KMEMLEAK) += kmemleak.o
 obj-$(CONFIG_DEBUG_KMEMLEAK_TEST) += kmemleak-test.o
+obj-$(CONFIG_PM_SLEEP) += pm.o
mm/pm.c new file +56 -0

56 lines not on this page · raw message

mm/internal.h +3 -0
Index: linux-2.6/mm/internal.h
===================================================================
@@ -259,3 +259,6 @@ extern u64 hwpoison_filter_flags_mask;
 extern u64 hwpoison_filter_flags_value;
 extern u64 hwpoison_filter_memcg;
 extern u32 hwpoison_filter_enable;
+
+extern void mm_lock_suspend(gfp_t gfp_mask);
+extern void mm_unlock_suspend(gfp_t gfp_mask);

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#39 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: Memory allocations in .suspend became very unreliable)

Quoted 9 lines

Index: linux-2.6/mm/page_alloc.c
===================================================================

mm/page_alloc.c +0 -1
@@ -1963,10 +1963,13 @@ __alloc_pages_nodemask(gfp_t gfp_mask, u
 	page = get_page_from_freelist(gfp_mask|__GFP_HARDWALL, nodemask, order,
 			zonelist, high_zoneidx, ALLOC_WMARK_LOW|ALLOC_CPUSET,
 			preferred_zone, migratetype);
-	if (unlikely(!page))

mm/page_alloc.c __alloc_pages_nodemask(gfp_t gfp_mask, u · line 1975

Quoted 10 lines
mm/page_alloc.c +4 -0
+	if (unlikely(!page)) {
+		mm_lock_suspend(gfp_mask);
 		page = __alloc_pages_slowpath(gfp_mask, order,
 				zonelist, high_zoneidx, nodemask,
 				preferred_zone, migratetype);
+		mm_unlock_suspend(gfp_mask);
+	}
 
 	trace_mm_page_alloc(page, order, gfp_mask, migratetype);
 	return page;

I think we don't need read side lock at all. generally, no lock might makes race. But in this case, changing gfp_allowed_mask and nvidia suspend method should be serialized higher level. Why the above two code need to run concurrently?

#40 lore raw

Re: [linux-pm] [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: Memory allocations in .suspend became very unreliable)

In reply to Rafael J. Wysocki
Quoted 9 lines

Index: linux-2.6/mm/page_alloc.c
===================================================================

mm/page_alloc.c +0 -1
@@ -1963,10 +1963,13 @@ __alloc_pages_nodemask(gfp_t gfp_mask, u
 	page = get_page_from_freelist(gfp_mask|__GFP_HARDWALL, nodemask, order,
 			zonelist, high_zoneidx, ALLOC_WMARK_LOW|ALLOC_CPUSET,
 			preferred_zone, migratetype);
-	if (unlikely(!page))

mm/page_alloc.c __alloc_pages_nodemask(gfp_t gfp_mask, u · line 1975

Quoted 10 lines
mm/page_alloc.c +4 -0
+	if (unlikely(!page)) {
+		mm_lock_suspend(gfp_mask);
 		page = __alloc_pages_slowpath(gfp_mask, order,
 				zonelist, high_zoneidx, nodemask,
 				preferred_zone, migratetype);
+		mm_unlock_suspend(gfp_mask);
+	}
 
 	trace_mm_page_alloc(page, order, gfp_mask, migratetype);
 	return page;

I think we don't need read side lock at all. generally, no lock might makes race. But in this case, changing gfp_allowed_mask and nvidia suspend method should be serialized higher level. Why the above two code need to run concurrently?

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#41 lore raw

Re: [linux-pm] [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: Memory allocations in .suspend became very unreliable)

Quoted 17 lines · KOSAKI Motohiro
Quoted 17 lines

Index: linux-2.6/mm/page_alloc.c
===================================================================

mm/page_alloc.c +4 -1
@@ -1963,10 +1963,13 @@ __alloc_pages_nodemask(gfp_t gfp_mask, u
 	page = get_page_from_freelist(gfp_mask|__GFP_HARDWALL, nodemask, order,
 			zonelist, high_zoneidx, ALLOC_WMARK_LOW|ALLOC_CPUSET,
 			preferred_zone, migratetype);
-	if (unlikely(!page))
+	if (unlikely(!page)) {
+		mm_lock_suspend(gfp_mask);
 		page = __alloc_pages_slowpath(gfp_mask, order,
 				zonelist, high_zoneidx, nodemask,
 				preferred_zone, migratetype);
+		mm_unlock_suspend(gfp_mask);
+	}
 
Quoted 6 lines

mm/page_alloc.c __alloc_pages_nodemask(gfp_t gfp_mask, u · line 1975

Quoted 2 lines
mm/page_alloc.c +0 -0
 	trace_mm_page_alloc(page, order, gfp_mask, migratetype);
 	return page;

I think we don't need read side lock at all. generally, no lock might makes race. But in this case, changing gfp_allowed_mask and nvidia suspend method should be serialized higher level. Why the above two code need to run concurrently?

The changing of gfp_allowed_mask is serialized with the suspend of devices, so there's no concurrency here.

I was concerned about another problem, though, which is what happens if the suspend process runs in parallel with a memory allocation that started earlier and happens to do some I/O. I that case the suspend process doesn't know about the I/O done by the mm subsystem and may disturb it in principle.

That said, perhaps that should be a concern for the block devices subsystem to prevent such situations from happening.

So, perhaps I'll remove the reader-side lock altogether and go back to something like the first version of the patch.

Rafael

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#42 lore raw

Re: [linux-pm] [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: Memory allocations in .suspend became very unreliable)

Am Montag, 18. Januar 2010 22:06:36 schrieb Rafael J. Wysocki:

Quoted 4 lines

I was concerned about another problem, though, which is what happens if the suspend process runs in parallel with a memory allocation that started earlier and happens to do some I/O. I that case the suspend process doesn't know about the I/O done by the mm subsystem and may disturb it in principle.

How could this happen? Who would allocate that memory? Tasks won't be frozen while they are allocating memory.

Regards
Oliver

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#43 lore raw

Re: [linux-pm] [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: Memory allocations in .suspend became very unreliable)

Quoted 8 lines · Oliver Neukum

Am Montag, 18. Januar 2010 22:06:36 schrieb Rafael J. Wysocki:

Quoted 4 lines

I was concerned about another problem, though, which is what happens if the suspend process runs in parallel with a memory allocation that started earlier and happens to do some I/O. I that case the suspend process doesn't know about the I/O done by the mm subsystem and may disturb it in principle.

How could this happen? Who would allocate that memory? Tasks won't be frozen while they are allocating memory.

The majority of kernel threads are not freezable, but I agree it's rather low risk.

Rafael

#44 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: Memory allocations in .suspend became very unreliable)

In reply to Oliver Neukum
Quoted 8 lines · Oliver Neukum

Am Montag, 18. Januar 2010 22:06:36 schrieb Rafael J. Wysocki:

Quoted 4 lines

I was concerned about another problem, though, which is what happens if the suspend process runs in parallel with a memory allocation that started earlier and happens to do some I/O. I that case the suspend process doesn't know about the I/O done by the mm subsystem and may disturb it in principle.

How could this happen? Who would allocate that memory? Tasks won't be frozen while they are allocating memory.

The majority of kernel threads are not freezable, but I agree it's rather low risk.

Rafael

#45 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: Memory allocations in .suspend became very unreliable)

In reply to Rafael J. Wysocki

Am Montag, 18. Januar 2010 22:06:36 schrieb Rafael J. Wysocki:

Quoted 4 lines

I was concerned about another problem, though, which is what happens if the suspend process runs in parallel with a memory allocation that started earlier and happens to do some I/O. I that case the suspend process doesn't know about the I/O done by the mm subsystem and may disturb it in principle.

How could this happen? Who would allocate that memory? Tasks won't be frozen while they are allocating memory.

Regards
Oliver

#46 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: Memory allocations in .suspend became very unreliable)

In reply to KOSAKI Motohiro
Quoted 17 lines · KOSAKI Motohiro
Quoted 17 lines

Index: linux-2.6/mm/page_alloc.c
===================================================================

mm/page_alloc.c +4 -1
@@ -1963,10 +1963,13 @@ __alloc_pages_nodemask(gfp_t gfp_mask, u
 	page = get_page_from_freelist(gfp_mask|__GFP_HARDWALL, nodemask, order,
 			zonelist, high_zoneidx, ALLOC_WMARK_LOW|ALLOC_CPUSET,
 			preferred_zone, migratetype);
-	if (unlikely(!page))
+	if (unlikely(!page)) {
+		mm_lock_suspend(gfp_mask);
 		page = __alloc_pages_slowpath(gfp_mask, order,
 				zonelist, high_zoneidx, nodemask,
 				preferred_zone, migratetype);
+		mm_unlock_suspend(gfp_mask);
+	}
 
Quoted 6 lines

mm/page_alloc.c __alloc_pages_nodemask(gfp_t gfp_mask, u · line 1975

Quoted 2 lines
mm/page_alloc.c +0 -0
 	trace_mm_page_alloc(page, order, gfp_mask, migratetype);
 	return page;

I think we don't need read side lock at all. generally, no lock might makes race. But in this case, changing gfp_allowed_mask and nvidia suspend method should be serialized higher level. Why the above two code need to run concurrently?

The changing of gfp_allowed_mask is serialized with the suspend of devices, so there's no concurrency here.

I was concerned about another problem, though, which is what happens if the suspend process runs in parallel with a memory allocation that started earlier and happens to do some I/O. I that case the suspend process doesn't know about the I/O done by the mm subsystem and may disturb it in principle.

That said, perhaps that should be a concern for the block devices subsystem to prevent such situations from happening.

So, perhaps I'll remove the reader-side lock altogether and go back to something like the first version of the patch.

Rafael

#47 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: Memory allocations in .suspend became very unreliable)

In reply to Minchan Kim
Quoted 66 lines · Minchan Kim

Hi, Rafael.

Quoted 63 lines · Rafael J. Wysocki
Quoted 52 lines · Rafael J. Wysocki

Hi,

I thing the snippet below is a good summary of what this is about.

Quoted 27 lines · Rafael J. Wysocki
Quoted 26 lines · Maxim Levitsky
Quoted 25 lines · Rafael J. Wysocki
Quoted 23 lines · Maxim Levitsky
Quoted 15 lines · Rafael J. Wysocki
Quoted 1 line · Maxim Levitsky

Hi,

Hi,

Quoted 9 lines

I know that this is very controversial, because here I want to describe a problem in a proprietary driver that happens now in 2.6.33-rc3 I am taking about nvidia driver.

Some time ago I did very long hibernate test and found no errors after more that 200 cycles.

Now I update to 2.6.33 and notice that system will hand when nvidia driver allocates memory is their .suspend functions.

Quoted 6 lines

They shouldn't do that, there's no guarantee that's going to work at all.

Quoted 2 lines

This could fail in 2.6.32 if I would run many memory hungry applications, but now this happens with most of memory free.

This sounds a little strange. What's the requested size of the image?

Don't know, but system has to be very tight on memory.

Quoted 8 lines
Quoted 8 lines
Quoted 1 line

Can you send full dmesg, please?

I deleted it, but for this case I think that hang was somewhere else. This task was hand on doing forking, which probably happened even before the freezer.

Anyway, the problem is clear. Now __get_free_pages blocks more often, and can block in .suspend even if there is plenty of memory free.

This is suspicious, but I leave it to the MM people for consideration.

Quoted 9 lines
Quoted 4 lines

I now patched nvidia to use GFP_ATOMIC _always_, and problem disappear. It isn't such great solution when memory is tight though....

This is going to hit hard all nvidia users...

Well, generally speaking, no driver should ever allocate memory using GFP_KERNEL in its .suspend() routine, because that's not going to work, as you can readily see. So this is a NVidia bug, hands down.

Quoted 7 lines
Quoted 3 lines

Now having said that, we've been considering a change that will turn all GFP_KERNEL allocations into GFP_NOIO during suspend/resume, so perhaps I'll prepare a patch to do that and let's see what people think.

If I didn't confuse anything (which is likely, because it's a bit late here now), the patch below should do the trick. I have only checked that it doesn't break compilation, so please take it with a grain of salt.

Appended is another version that attempts to remove some possible races. It's been tested a little too.

...

Quoted 3 lines

Review

Quoted 3 lines
(quoted diff) +2 -1
-	if (unlikely(!page))
+	if (unlikely(!page)) {
+		down_read(&gfp_allowed_mask_sem);

This obviously is going too far, because it would change atomic allocations into non-atomic in general (kinda embarassing ...).

However, I think it would be sufficient to acquire the lock only in the (__GFP_IO | __GFP_FS) case. Appended is an updated patch doing this.

Quoted 5 lines
Quoted 5 lines
(quoted diff) +2 -0
 		page = __alloc_pages_slowpath(gfp_mask, order,
 				zonelist, high_zoneidx, nodemask,
 				preferred_zone, migratetype);
+		up_read(&gfp_allowed_mask_sem);
+	}

...

Quoted 7 lines

I think we can use lockdep annotation, too. but it's overkill. That's because suspend/resume is rare event so that I want to add the cost in lockdep. so I like this idea. But, I have a concern. You are adding a little bit cost in alloc path although it's slow one.

Really really do we need this?

Without it, we would have to duplicate every piece of code that normally uses GFP_KERNEL allocations and that may be called during suspend/resume. I don't really think that would be practical.

Quoted 1 line

Can't we remove the wrong usage in review or test process before merge?

That's not so simple. The Ben's message in this thread described the possible issues quite well (http://lkml.org/lkml/2010/1/17/120).

I think the suspend process should wait for all the already started allocations using I/O, because otherwise it might disturb them. So this also is a matter of correctness in general.

Quoted 2 lines

I don't have many experience at suspend/resume. I depends on your experience about this patch's value. :)

OK :-)

Rafael

---
 kernel/power/hibernate.c |    6 +++++
 kernel/power/power.h     |    3 ++
 kernel/power/suspend.c   |    2 +
 mm/Makefile              |    1 
 mm/internal.h            |    3 ++
 mm/page_alloc.c          |    5 +++-
 mm/pm.c                  |   56 +++++++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 75 insertions(+), 1 deletion(-)
kernel/power/hibernate.c +6 -0
Index: linux-2.6/kernel/power/hibernate.c
===================================================================
@@ -334,6 +334,7 @@ int hibernation_snapshot(int platform_mo
 		goto Close;
 
 	suspend_console();
+	mm_force_noio_allocations();
 	error = dpm_suspend_start(PMSG_FREEZE);
 	if (error)
 		goto Recover_platform;
@@ -351,6 +352,7 @@ int hibernation_snapshot(int platform_mo
 
 	dpm_resume_end(in_suspend ?
 		(error ? PMSG_RECOVER : PMSG_THAW) : PMSG_RESTORE);
+	mm_allow_io_allocations();
 	resume_console();
  Close:
 	platform_end(platform_mode);
@@ -448,11 +450,13 @@ int hibernation_restore(int platform_mod
 
 	pm_prepare_console();
 	suspend_console();
+	mm_force_noio_allocations();
 	error = dpm_suspend_start(PMSG_QUIESCE);
 	if (!error) {
 		error = resume_target_kernel(platform_mode);
 		dpm_resume_end(PMSG_RECOVER);
 	}
+	mm_allow_io_allocations();
 	resume_console();
 	pm_restore_console();
 	return error;
@@ -481,6 +485,7 @@ int hibernation_platform_enter(void)
 
 	entering_platform_hibernation = true;
 	suspend_console();
+	mm_force_noio_allocations();
 	error = dpm_suspend_start(PMSG_HIBERNATE);
 	if (error) {
 		if (hibernation_ops->recover)
@@ -518,6 +523,7 @@ int hibernation_platform_enter(void)
  Resume_devices:
 	entering_platform_hibernation = false;
 	dpm_resume_end(PMSG_RESTORE);
+	mm_allow_io_allocations();
 	resume_console();
 
  Close:
kernel/power/power.h +3 -0
Index: linux-2.6/kernel/power/power.h
===================================================================
@@ -187,6 +187,9 @@ static inline void suspend_test_finish(c
 #ifdef CONFIG_PM_SLEEP
 /* kernel/power/main.c */
 extern int pm_notifier_call_chain(unsigned long val);
+/* mm/pm.c */
+extern void mm_force_noio_allocations(void);
+extern void mm_allow_io_allocations(void);
 #endif
 
 #ifdef CONFIG_HIGHMEM
kernel/power/suspend.c +2 -0
Index: linux-2.6/kernel/power/suspend.c
===================================================================
@@ -208,6 +208,7 @@ int suspend_devices_and_enter(suspend_st
 			goto Close;
 	}
 	suspend_console();
+	mm_force_noio_allocations();
 	suspend_test_start();
 	error = dpm_suspend_start(PMSG_SUSPEND);
 	if (error) {
@@ -224,6 +225,7 @@ int suspend_devices_and_enter(suspend_st
 	suspend_test_start();
 	dpm_resume_end(PMSG_RESUME);
 	suspend_test_finish("resume devices");
+	mm_allow_io_allocations();
 	resume_console();
  Close:
 	if (suspend_ops->end)
mm/page_alloc.c +4 -1
Index: linux-2.6/mm/page_alloc.c
===================================================================
@@ -1963,10 +1963,13 @@ __alloc_pages_nodemask(gfp_t gfp_mask, u
 	page = get_page_from_freelist(gfp_mask|__GFP_HARDWALL, nodemask, order,
 			zonelist, high_zoneidx, ALLOC_WMARK_LOW|ALLOC_CPUSET,
 			preferred_zone, migratetype);
-	if (unlikely(!page))
+	if (unlikely(!page)) {
+		mm_lock_suspend(gfp_mask);
 		page = __alloc_pages_slowpath(gfp_mask, order,
 				zonelist, high_zoneidx, nodemask,
 				preferred_zone, migratetype);
+		mm_unlock_suspend(gfp_mask);
+	}
 
 	trace_mm_page_alloc(page, order, gfp_mask, migratetype);
 	return page;
mm/Makefile +1 -0
Index: linux-2.6/mm/Makefile
===================================================================
@@ -40,3 +40,4 @@ obj-$(CONFIG_MEMORY_FAILURE) += memory-f
 obj-$(CONFIG_HWPOISON_INJECT) += hwpoison-inject.o
 obj-$(CONFIG_DEBUG_KMEMLEAK) += kmemleak.o
 obj-$(CONFIG_DEBUG_KMEMLEAK_TEST) += kmemleak-test.o
+obj-$(CONFIG_PM_SLEEP) += pm.o
mm/pm.c new file +56 -0

56 lines not on this page · raw message

mm/internal.h +3 -0
Index: linux-2.6/mm/internal.h
===================================================================
@@ -259,3 +259,6 @@ extern u64 hwpoison_filter_flags_mask;
 extern u64 hwpoison_filter_flags_value;
 extern u64 hwpoison_filter_memcg;
 extern u32 hwpoison_filter_enable;
+
+extern void mm_lock_suspend(gfp_t gfp_mask);
+extern void mm_unlock_suspend(gfp_t gfp_mask);
#48 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: [linux-pm] Memory allocations in .suspend became very unreliable)

In reply to Rafael J. Wysocki

Am Sonntag, 17. Januar 2010 14:55:55 schrieb Rafael J. Wysocki:

mm/pm.c line 18

Quoted 8 lines
mm/pm.c new file +8 -0
+void mm_force_noio_allocations(void)
+{
+       /* Wait for all slowpath allocations using the old mask to complete */
+       down_write(&gfp_allowed_mask_sem);
+       saved_gfp_allowed_mask = gfp_allowed_mask;
+       gfp_allowed_mask &= ~(__GFP_IO | __GFP_FS);
+       up_write(&gfp_allowed_mask_sem);
+}

In addition to this you probably want to exhaust all memory reserves before you fail a memory allocation and forbid the OOM killer to run.

Regards
Oliver

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#49 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: [linux-pm] Memory allocations in .suspend became very unreliable)

Quoted 12 lines · Oliver Neukum

Am Sonntag, 17. Januar 2010 14:55:55 schrieb Rafael J. Wysocki:

mm/pm.c line 18

Quoted 8 lines
mm/pm.c new file +8 -0
+void mm_force_noio_allocations(void)
+{
+       /* Wait for all slowpath allocations using the old mask to complete */
+       down_write(&gfp_allowed_mask_sem);
+       saved_gfp_allowed_mask = gfp_allowed_mask;
+       gfp_allowed_mask &= ~(__GFP_IO | __GFP_FS);
+       up_write(&gfp_allowed_mask_sem);
+}

In addition to this you probably want to exhaust all memory reserves before you fail a memory allocation

I'm not really sure what you mean.

Quoted 1 line

and forbid the OOM killer to run.

The OOM killer has already been disabled at this point, by the freezer.

Rafael

#50 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: [linux-pm] Memory allocations in .suspend became very unreliable)

Am Montag, 18. Januar 2010 21:41:49 schrieb Rafael J. Wysocki:

Quoted 14 lines · Oliver Neukum
Quoted 12 lines

Am Sonntag, 17. Januar 2010 14:55:55 schrieb Rafael J. Wysocki:

mm/pm.c line 18

Quoted 8 lines
mm/pm.c new file +8 -0
+void mm_force_noio_allocations(void)
+{
+       /* Wait for all slowpath allocations using the old mask to complete */
+       down_write(&gfp_allowed_mask_sem);
+       saved_gfp_allowed_mask = gfp_allowed_mask;
+       gfp_allowed_mask &= ~(__GFP_IO | __GFP_FS);
+       up_write(&gfp_allowed_mask_sem);
+}

In addition to this you probably want to exhaust all memory reserves before you fail a memory allocation

Quoted 1 line

I'm not really sure what you mean.

Forget it, it was foolish. Instead there's a different problem. Suppose we are tight on memory. The problem is that we must not exhaust all memory. If we are really out of memory we may be unable to satisfy memory allocations in resume()

Regards
Oliver

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#51 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: [linux-pm] Memory allocations in .suspend became very unreliable)

Quoted 15 lines · Oliver Neukum

Am Montag, 18. Januar 2010 21:41:49 schrieb Rafael J. Wysocki:

Quoted 14 lines · Oliver Neukum
Quoted 12 lines

Am Sonntag, 17. Januar 2010 14:55:55 schrieb Rafael J. Wysocki:

mm/pm.c line 18

Quoted 8 lines
mm/pm.c new file +8 -0
+void mm_force_noio_allocations(void)
+{
+       /* Wait for all slowpath allocations using the old mask to complete */
+       down_write(&gfp_allowed_mask_sem);
+       saved_gfp_allowed_mask = gfp_allowed_mask;
+       gfp_allowed_mask &= ~(__GFP_IO | __GFP_FS);
+       up_write(&gfp_allowed_mask_sem);
+}

In addition to this you probably want to exhaust all memory reserves before you fail a memory allocation

Quoted 6 lines
Quoted 1 line

I'm not really sure what you mean.

Forget it, it was foolish. Instead there's a different problem. Suppose we are tight on memory. The problem is that we must not exhaust all memory. If we are really out of memory we may be unable to satisfy memory allocations in resume()

That doesn't make things any worse than the are already. If we block on I/O forever during resume, the gross result is pretty much the same.

That said, Maxim reported that in his test case the mm subsystem apparently attempted to use I/O even if there was a plenty of free memory available and I'd like prevent _that_ from happening.

Rafael

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#52 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: Memory allocations in .suspend became very unreliable)

Am Dienstag, 19. Januar 2010 21:37:35 schrieb Rafael J. Wysocki:

Quoted 3 lines

That said, Maxim reported that in his test case the mm subsystem apparently attempted to use I/O even if there was a plenty of free memory available and I'd like prevent that from happening.

Hi,

it seems to me that this is caused by the mm subsytem maintaing a share of clean pages precisely so that GFP_NOIO will work. Perhaps it is a good idea to
a) launder a number of pages if the system is about to be suspended between the freezer and notifying drivers
b) set the ration of clean pages to dirty pages to 0 while suspending the system.

Regards
Oliver

#53 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: [linux-pm] Memory allocations in .suspend became very unreliable)

In reply to Rafael J. Wysocki

Am Dienstag, 19. Januar 2010 21:37:35 schrieb Rafael J. Wysocki:

Quoted 3 lines

That said, Maxim reported that in his test case the mm subsystem apparently attempted to use I/O even if there was a plenty of free memory available and I'd like prevent that from happening.

Hi,

it seems to me that this is caused by the mm subsytem maintaing a share of clean pages precisely so that GFP_NOIO will work. Perhaps it is a good idea to
a) launder a number of pages if the system is about to be suspended between the freezer and notifying drivers
b) set the ration of clean pages to dirty pages to 0 while suspending the system.

Regards
Oliver

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#54 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: [linux-pm] Memory allocations in .suspend became very unreliable)

Quoted 5 lines · Oliver Neukum

Am Dienstag, 19. Januar 2010 21:37:35 schrieb Rafael J. Wysocki:

Quoted 3 lines

That said, Maxim reported that in his test case the mm subsystem apparently attempted to use I/O even if there was a plenty of free memory available and I'd like prevent that from happening.

Quoted 7 lines

Hi,

it seems to me that this is caused by the mm subsytem maintaing a share of clean pages precisely so that GFP_NOIO will work. Perhaps it is a good idea to
a) launder a number of pages if the system is about to be suspended between the freezer and notifying drivers

That was tried, didn't work.

Quoted 2 lines

b) set the ration of clean pages to dirty pages to 0 while suspending the system.

Patch, please?

Rafael

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#55 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: Memory allocations in .suspend became very unreliable)

In reply to Oliver Neukum
Quoted 5 lines · Oliver Neukum

Am Dienstag, 19. Januar 2010 21:37:35 schrieb Rafael J. Wysocki:

Quoted 3 lines

That said, Maxim reported that in his test case the mm subsystem apparently attempted to use I/O even if there was a plenty of free memory available and I'd like prevent that from happening.

Quoted 7 lines

Hi,

it seems to me that this is caused by the mm subsytem maintaing a share of clean pages precisely so that GFP_NOIO will work. Perhaps it is a good idea to
a) launder a number of pages if the system is about to be suspended between the freezer and notifying drivers

That was tried, didn't work.

Quoted 2 lines

b) set the ration of clean pages to dirty pages to 0 while suspending the system.

Patch, please?

Rafael

#56 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: Memory allocations in .suspend became very unreliable)

In reply to Oliver Neukum
Quoted 15 lines · Oliver Neukum

Am Montag, 18. Januar 2010 21:41:49 schrieb Rafael J. Wysocki:

Quoted 14 lines · Oliver Neukum
Quoted 12 lines

Am Sonntag, 17. Januar 2010 14:55:55 schrieb Rafael J. Wysocki:

mm/pm.c line 18

Quoted 8 lines
mm/pm.c new file +8 -0
+void mm_force_noio_allocations(void)
+{
+       /* Wait for all slowpath allocations using the old mask to complete */
+       down_write(&gfp_allowed_mask_sem);
+       saved_gfp_allowed_mask = gfp_allowed_mask;
+       gfp_allowed_mask &= ~(__GFP_IO | __GFP_FS);
+       up_write(&gfp_allowed_mask_sem);
+}

In addition to this you probably want to exhaust all memory reserves before you fail a memory allocation

Quoted 6 lines
Quoted 1 line

I'm not really sure what you mean.

Forget it, it was foolish. Instead there's a different problem. Suppose we are tight on memory. The problem is that we must not exhaust all memory. If we are really out of memory we may be unable to satisfy memory allocations in resume()

That doesn't make things any worse than the are already. If we block on I/O forever during resume, the gross result is pretty much the same.

That said, Maxim reported that in his test case the mm subsystem apparently attempted to use I/O even if there was a plenty of free memory available and I'd like prevent _that_ from happening.

Rafael

#57 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: Memory allocations in .suspend became very unreliable)

In reply to Rafael J. Wysocki

Am Montag, 18. Januar 2010 21:41:49 schrieb Rafael J. Wysocki:

Quoted 14 lines · Oliver Neukum
Quoted 12 lines

Am Sonntag, 17. Januar 2010 14:55:55 schrieb Rafael J. Wysocki:

mm/pm.c line 18

Quoted 8 lines
mm/pm.c new file +8 -0
+void mm_force_noio_allocations(void)
+{
+       /* Wait for all slowpath allocations using the old mask to complete */
+       down_write(&gfp_allowed_mask_sem);
+       saved_gfp_allowed_mask = gfp_allowed_mask;
+       gfp_allowed_mask &= ~(__GFP_IO | __GFP_FS);
+       up_write(&gfp_allowed_mask_sem);
+}

In addition to this you probably want to exhaust all memory reserves before you fail a memory allocation

Quoted 1 line

I'm not really sure what you mean.

Forget it, it was foolish. Instead there's a different problem. Suppose we are tight on memory. The problem is that we must not exhaust all memory. If we are really out of memory we may be unable to satisfy memory allocations in resume()

Regards
Oliver

#58 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: Memory allocations in .suspend became very unreliable)

In reply to Oliver Neukum
Quoted 12 lines · Oliver Neukum

Am Sonntag, 17. Januar 2010 14:55:55 schrieb Rafael J. Wysocki:

mm/pm.c line 18

Quoted 8 lines
mm/pm.c new file +8 -0
+void mm_force_noio_allocations(void)
+{
+       /* Wait for all slowpath allocations using the old mask to complete */
+       down_write(&gfp_allowed_mask_sem);
+       saved_gfp_allowed_mask = gfp_allowed_mask;
+       gfp_allowed_mask &= ~(__GFP_IO | __GFP_FS);
+       up_write(&gfp_allowed_mask_sem);
+}

In addition to this you probably want to exhaust all memory reserves before you fail a memory allocation

I'm not really sure what you mean.

Quoted 1 line

and forbid the OOM killer to run.

The OOM killer has already been disabled at this point, by the freezer.

Rafael

#59 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: Memory allocations in .suspend became very unreliable)

In reply to Rafael J. Wysocki

Am Sonntag, 17. Januar 2010 14:55:55 schrieb Rafael J. Wysocki:

mm/pm.c line 18

Quoted 8 lines
mm/pm.c new file +8 -0
+void mm_force_noio_allocations(void)
+{
+       /* Wait for all slowpath allocations using the old mask to complete */
+       down_write(&gfp_allowed_mask_sem);
+       saved_gfp_allowed_mask = gfp_allowed_mask;
+       gfp_allowed_mask &= ~(__GFP_IO | __GFP_FS);
+       up_write(&gfp_allowed_mask_sem);
+}

In addition to this you probably want to exhaust all memory reserves before you fail a memory allocation and forbid the OOM killer to run.

Regards
Oliver

#60 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: Memory allocations in .suspend became very unreliable)

In reply to Rafael J. Wysocki
Quoted 52 lines · Rafael J. Wysocki

Hi,

I thing the snippet below is a good summary of what this is about.

Quoted 27 lines · Rafael J. Wysocki
Quoted 26 lines · Maxim Levitsky
Quoted 25 lines · Rafael J. Wysocki
Quoted 23 lines · Maxim Levitsky
Quoted 15 lines · Rafael J. Wysocki
Quoted 1 line · Maxim Levitsky

Hi,

Hi,

Quoted 9 lines

I know that this is very controversial, because here I want to describe a problem in a proprietary driver that happens now in 2.6.33-rc3 I am taking about nvidia driver.

Some time ago I did very long hibernate test and found no errors after more that 200 cycles.

Now I update to 2.6.33 and notice that system will hand when nvidia driver allocates memory is their .suspend functions.

Quoted 6 lines

They shouldn't do that, there's no guarantee that's going to work at all.

Quoted 2 lines

This could fail in 2.6.32 if I would run many memory hungry applications, but now this happens with most of memory free.

This sounds a little strange. What's the requested size of the image?

Don't know, but system has to be very tight on memory.

Quoted 8 lines
Quoted 8 lines
Quoted 1 line

Can you send full dmesg, please?

I deleted it, but for this case I think that hang was somewhere else. This task was hand on doing forking, which probably happened even before the freezer.

Anyway, the problem is clear. Now __get_free_pages blocks more often, and can block in .suspend even if there is plenty of memory free.

This is suspicious, but I leave it to the MM people for consideration.

Quoted 9 lines
Quoted 4 lines

I now patched nvidia to use GFP_ATOMIC _always_, and problem disappear. It isn't such great solution when memory is tight though....

This is going to hit hard all nvidia users...

Well, generally speaking, no driver should ever allocate memory using GFP_KERNEL in its .suspend() routine, because that's not going to work, as you can readily see. So this is a NVidia bug, hands down.

Quoted 7 lines
Quoted 3 lines

Now having said that, we've been considering a change that will turn all GFP_KERNEL allocations into GFP_NOIO during suspend/resume, so perhaps I'll prepare a patch to do that and let's see what people think.

If I didn't confuse anything (which is likely, because it's a bit late here now), the patch below should do the trick. I have only checked that it doesn't break compilation, so please take it with a grain of salt.

Appended is another version that attempts to remove some possible races. It's been tested a little too.

Rafael

---
 include/linux/gfp.h      |    5 +----
 kernel/power/hibernate.c |    6 ++++++
 kernel/power/main.c      |    1 +
 kernel/power/power.h     |    3 +++
 kernel/power/suspend.c   |    2 ++
 mm/Makefile              |    1 +
 mm/internal.h            |    3 +++
 mm/page_alloc.c          |   16 +++++++++++++++-
 mm/pm.c                  |   34 ++++++++++++++++++++++++++++++++++
 9 files changed, 66 insertions(+), 5 deletions(-)
include/linux/gfp.h +1 -4
Index: linux-2.6/include/linux/gfp.h
===================================================================
@@ -337,9 +337,6 @@ void drain_local_pages(void *dummy);
 
 extern gfp_t gfp_allowed_mask;
 
-static inline void set_gfp_allowed_mask(gfp_t mask)
-{
-	gfp_allowed_mask = mask;
-}
+extern void set_gfp_allowed_mask(gfp_t mask);
 
 #endif /* __LINUX_GFP_H */
kernel/power/hibernate.c +6 -0
Index: linux-2.6/kernel/power/hibernate.c
===================================================================
@@ -334,6 +334,7 @@ int hibernation_snapshot(int platform_mo
 		goto Close;
 
 	suspend_console();
+	mm_force_noio_allocations();
 	error = dpm_suspend_start(PMSG_FREEZE);
 	if (error)
 		goto Recover_platform;
@@ -351,6 +352,7 @@ int hibernation_snapshot(int platform_mo
 
 	dpm_resume_end(in_suspend ?
 		(error ? PMSG_RECOVER : PMSG_THAW) : PMSG_RESTORE);
+	mm_allow_io_allocations();
 	resume_console();
  Close:
 	platform_end(platform_mode);
@@ -448,11 +450,13 @@ int hibernation_restore(int platform_mod
 
 	pm_prepare_console();
 	suspend_console();
+	mm_force_noio_allocations();
 	error = dpm_suspend_start(PMSG_QUIESCE);
 	if (!error) {
 		error = resume_target_kernel(platform_mode);
 		dpm_resume_end(PMSG_RECOVER);
 	}
+	mm_allow_io_allocations();
 	resume_console();
 	pm_restore_console();
 	return error;
@@ -481,6 +485,7 @@ int hibernation_platform_enter(void)
 
 	entering_platform_hibernation = true;
 	suspend_console();
+	mm_force_noio_allocations();
 	error = dpm_suspend_start(PMSG_HIBERNATE);
 	if (error) {
 		if (hibernation_ops->recover)
@@ -518,6 +523,7 @@ int hibernation_platform_enter(void)
  Resume_devices:
 	entering_platform_hibernation = false;
 	dpm_resume_end(PMSG_RESTORE);
+	mm_allow_io_allocations();
 	resume_console();
 
  Close:
kernel/power/power.h +3 -0
Index: linux-2.6/kernel/power/power.h
===================================================================
@@ -187,6 +187,9 @@ static inline void suspend_test_finish(c
 #ifdef CONFIG_PM_SLEEP
 /* kernel/power/main.c */
 extern int pm_notifier_call_chain(unsigned long val);
+/* mm/pm.c */
+extern void mm_force_noio_allocations(void);
+extern void mm_allow_io_allocations(void);
 #endif
 
 #ifdef CONFIG_HIGHMEM
kernel/power/suspend.c +2 -0
Index: linux-2.6/kernel/power/suspend.c
===================================================================
@@ -208,6 +208,7 @@ int suspend_devices_and_enter(suspend_st
 			goto Close;
 	}
 	suspend_console();
+	mm_force_noio_allocations();
 	suspend_test_start();
 	error = dpm_suspend_start(PMSG_SUSPEND);
 	if (error) {
@@ -224,6 +225,7 @@ int suspend_devices_and_enter(suspend_st
 	suspend_test_start();
 	dpm_resume_end(PMSG_RESUME);
 	suspend_test_finish("resume devices");
+	mm_allow_io_allocations();
 	resume_console();
  Close:
 	if (suspend_ops->end)
kernel/power/main.c +1 -0
Index: linux-2.6/kernel/power/main.c
===================================================================
@@ -12,6 +12,7 @@
 #include <linux/string.h>
 #include <linux/resume-trace.h>
 #include <linux/workqueue.h>
+#include <linux/gfp.h>
 
 #include "power.h"
 
mm/page_alloc.c +15 -1
Index: linux-2.6/mm/page_alloc.c
===================================================================
@@ -76,6 +76,17 @@ unsigned long totalreserve_pages __read_
 int percpu_pagelist_fraction;
 gfp_t gfp_allowed_mask __read_mostly = GFP_BOOT_MASK;
 
+DECLARE_RWSEM(gfp_allowed_mask_sem);
+
+void set_gfp_allowed_mask(gfp_t mask)
+{
+	/* Wait for all slowpath allocations using the old mask to complete */
+	down_write(&gfp_allowed_mask_sem);
+	gfp_allowed_mask = mask;
+	up_write(&gfp_allowed_mask_sem);
+}
+
+
 #ifdef CONFIG_HUGETLB_PAGE_SIZE_VARIABLE
 int pageblock_order __read_mostly;
 #endif
@@ -1963,10 +1974,13 @@ __alloc_pages_nodemask(gfp_t gfp_mask, u
 	page = get_page_from_freelist(gfp_mask|__GFP_HARDWALL, nodemask, order,
 			zonelist, high_zoneidx, ALLOC_WMARK_LOW|ALLOC_CPUSET,
 			preferred_zone, migratetype);
-	if (unlikely(!page))
+	if (unlikely(!page)) {
+		down_read(&gfp_allowed_mask_sem);
 		page = __alloc_pages_slowpath(gfp_mask, order,
 				zonelist, high_zoneidx, nodemask,
 				preferred_zone, migratetype);
+		up_read(&gfp_allowed_mask_sem);
+	}
 
 	trace_mm_page_alloc(page, order, gfp_mask, migratetype);
 	return page;
mm/Makefile +1 -0
Index: linux-2.6/mm/Makefile
===================================================================
@@ -40,3 +40,4 @@ obj-$(CONFIG_MEMORY_FAILURE) += memory-f
 obj-$(CONFIG_HWPOISON_INJECT) += hwpoison-inject.o
 obj-$(CONFIG_DEBUG_KMEMLEAK) += kmemleak.o
 obj-$(CONFIG_DEBUG_KMEMLEAK_TEST) += kmemleak-test.o
+obj-$(CONFIG_PM_SLEEP) += pm.o
mm/pm.c new file +34 -0
Index: linux-2.6/mm/pm.c
===================================================================
@@ -0,0 +1,34 @@
+#include "internal.h"
+
+static gfp_t saved_gfp_allowed_mask;
+
+/**
+ * mm_force_noio_allocations - Modify gfp_allowed_mask to disable IO allocations
+ *
+ * Change gfp_allowed_mask by unsetting __GFP_IO and __GFP_FS in it and save the
+ * old value.
+ */
+void mm_force_noio_allocations(void)
+{
+	/* Wait for all slowpath allocations using the old mask to complete */
+	down_write(&gfp_allowed_mask_sem);
+	saved_gfp_allowed_mask = gfp_allowed_mask;
+	gfp_allowed_mask &= ~(__GFP_IO | __GFP_FS);
+	up_write(&gfp_allowed_mask_sem);
+}
+
+/**
+ * mm_allow_io_allocations - Modify gfp_allowed_mask to allow IO allocations
+ *
+ * If the saved value of gfp_allowed_mask has __GFP_IO set, modify the current
+ * gfp_allowed_mask by setting this bit and anlogously for __GFP_FS.
+ */
+void mm_allow_io_allocations(void)
+{
+	gfp_t gfp_mask = saved_gfp_allowed_mask & (__GFP_IO | __GFP_FS);
+
+	/* Wait for all slowpath allocations using the old mask to complete */
+	down_write(&gfp_allowed_mask_sem);
+	gfp_allowed_mask |= gfp_mask;
+	up_write(&gfp_allowed_mask_sem);
+}
mm/internal.h +3 -0
Index: linux-2.6/mm/internal.h
===================================================================
@@ -12,6 +12,7 @@
 #define __MM_INTERNAL_H
 
 #include <linux/mm.h>
+#include <linux/rwsem.h>
 
 void free_pgtables(struct mmu_gather *tlb, struct vm_area_struct *start_vma,
 		unsigned long floor, unsigned long ceiling);
@@ -259,3 +260,5 @@ extern u64 hwpoison_filter_flags_mask;
 extern u64 hwpoison_filter_flags_value;
 extern u64 hwpoison_filter_memcg;
 extern u32 hwpoison_filter_enable;
+
+extern struct rw_semaphore gfp_allowed_mask_sem;
#61 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: Memory allocations in .suspend became very unreliable)

In reply to Rafael J. Wysocki
Quoted 56 lines

Hi,

I thing the snippet below is a good summary of what this is about.

Quoted 27 lines · Rafael J. Wysocki
Quoted 26 lines · Maxim Levitsky
Quoted 25 lines · Rafael J. Wysocki
Quoted 23 lines · Maxim Levitsky
Quoted 15 lines · Rafael J. Wysocki
Quoted 1 line · Maxim Levitsky

Hi,

Hi,

Quoted 9 lines

I know that this is very controversial, because here I want to describe a problem in a proprietary driver that happens now in 2.6.33-rc3 I am taking about nvidia driver.

Some time ago I did very long hibernate test and found no errors after more that 200 cycles.

Now I update to 2.6.33 and notice that system will hand when nvidia driver allocates memory is their .suspend functions.

Quoted 6 lines

They shouldn't do that, there's no guarantee that's going to work at all.

Quoted 2 lines

This could fail in 2.6.32 if I would run many memory hungry applications, but now this happens with most of memory free.

This sounds a little strange. What's the requested size of the image?

Don't know, but system has to be very tight on memory.

Quoted 8 lines
Quoted 8 lines
Quoted 1 line

Can you send full dmesg, please?

I deleted it, but for this case I think that hang was somewhere else. This task was hand on doing forking, which probably happened even before the freezer.

Anyway, the problem is clear. Now __get_free_pages blocks more often, and can block in .suspend even if there is plenty of memory free.

This is suspicious, but I leave it to the MM people for consideration.

Quoted 5 lines
Quoted 4 lines

I now patched nvidia to use GFP_ATOMIC _always_, and problem disappear. It isn't such great solution when memory is tight though....

This is going to hit hard all nvidia users...

Quoted 7 lines

Well, generally speaking, no driver should ever allocate memory using GFP_KERNEL in its .suspend() routine, because that's not going to work, as you can readily see. So this is a NVidia bug, hands down.

Now having said that, we've been considering a change that will turn all GFP_KERNEL allocations into GFP_NOIO during suspend/resume, so perhaps I'll prepare a patch to do that and let's see what people think.

Quoted 5 lines

If I didn't confuse anything (which is likely, because it's a bit late here now), the patch below should do the trick. I have only checked that it doesn't break compilation, so please take it with a grain of salt.

Comments welcome.

Hmm..
I don't think this is good idea.

GFP_NOIO mean "Please don't reclaim if the page is dirty". It mean the system have lots dirty pages, this patch might makes hung up.

If suspend need lots memory, we need to make free memory before starting IO suspending, I think.

#62 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: [linux-pm] Memory allocations in .suspend became very unreliable)

In reply to Rafael J. Wysocki
Quoted 56 lines

Hi,

I thing the snippet below is a good summary of what this is about.

Quoted 27 lines · Rafael J. Wysocki
Quoted 26 lines · Maxim Levitsky
Quoted 25 lines · Rafael J. Wysocki
Quoted 23 lines · Maxim Levitsky
Quoted 15 lines · Rafael J. Wysocki
Quoted 1 line · Maxim Levitsky

Hi,

Hi,

Quoted 9 lines

I know that this is very controversial, because here I want to describe a problem in a proprietary driver that happens now in 2.6.33-rc3 I am taking about nvidia driver.

Some time ago I did very long hibernate test and found no errors after more that 200 cycles.

Now I update to 2.6.33 and notice that system will hand when nvidia driver allocates memory is their .suspend functions.

Quoted 6 lines

They shouldn't do that, there's no guarantee that's going to work at all.

Quoted 2 lines

This could fail in 2.6.32 if I would run many memory hungry applications, but now this happens with most of memory free.

This sounds a little strange. What's the requested size of the image?

Don't know, but system has to be very tight on memory.

Quoted 8 lines
Quoted 8 lines
Quoted 1 line

Can you send full dmesg, please?

I deleted it, but for this case I think that hang was somewhere else. This task was hand on doing forking, which probably happened even before the freezer.

Anyway, the problem is clear. Now __get_free_pages blocks more often, and can block in .suspend even if there is plenty of memory free.

This is suspicious, but I leave it to the MM people for consideration.

Quoted 5 lines
Quoted 4 lines

I now patched nvidia to use GFP_ATOMIC _always_, and problem disappear. It isn't such great solution when memory is tight though....

This is going to hit hard all nvidia users...

Quoted 7 lines

Well, generally speaking, no driver should ever allocate memory using GFP_KERNEL in its .suspend() routine, because that's not going to work, as you can readily see. So this is a NVidia bug, hands down.

Now having said that, we've been considering a change that will turn all GFP_KERNEL allocations into GFP_NOIO during suspend/resume, so perhaps I'll prepare a patch to do that and let's see what people think.

Quoted 5 lines

If I didn't confuse anything (which is likely, because it's a bit late here now), the patch below should do the trick. I have only checked that it doesn't break compilation, so please take it with a grain of salt.

Comments welcome.

Hmm..
I don't think this is good idea.

GFP_NOIO mean "Please don't reclaim if the page is dirty". It mean the system have lots dirty pages, this patch might makes hung up.

If suspend need lots memory, we need to make free memory before starting IO suspending, I think.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#63 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: [linux-pm] Memory allocations in .suspend became very unreliable)

Quoted 60 lines · KOSAKI Motohiro
Quoted 60 lines

Hi,

I thing the snippet below is a good summary of what this is about.

Quoted 27 lines · Rafael J. Wysocki
Quoted 26 lines · Maxim Levitsky
Quoted 25 lines · Rafael J. Wysocki
Quoted 23 lines · Maxim Levitsky
Quoted 15 lines · Rafael J. Wysocki
Quoted 1 line · Maxim Levitsky

Hi,

Hi,

Quoted 9 lines

I know that this is very controversial, because here I want to describe a problem in a proprietary driver that happens now in 2.6.33-rc3 I am taking about nvidia driver.

Some time ago I did very long hibernate test and found no errors after more that 200 cycles.

Now I update to 2.6.33 and notice that system will hand when nvidia driver allocates memory is their .suspend functions.

Quoted 6 lines

They shouldn't do that, there's no guarantee that's going to work at all.

Quoted 2 lines

This could fail in 2.6.32 if I would run many memory hungry applications, but now this happens with most of memory free.

This sounds a little strange. What's the requested size of the image?

Don't know, but system has to be very tight on memory.

Quoted 8 lines
Quoted 8 lines
Quoted 1 line

Can you send full dmesg, please?

I deleted it, but for this case I think that hang was somewhere else. This task was hand on doing forking, which probably happened even before the freezer.

Anyway, the problem is clear. Now __get_free_pages blocks more often, and can block in .suspend even if there is plenty of memory free.

This is suspicious, but I leave it to the MM people for consideration.

Quoted 5 lines
Quoted 4 lines

I now patched nvidia to use GFP_ATOMIC _always_, and problem disappear. It isn't such great solution when memory is tight though....

This is going to hit hard all nvidia users...

Quoted 7 lines

Well, generally speaking, no driver should ever allocate memory using GFP_KERNEL in its .suspend() routine, because that's not going to work, as you can readily see. So this is a NVidia bug, hands down.

Now having said that, we've been considering a change that will turn all GFP_KERNEL allocations into GFP_NOIO during suspend/resume, so perhaps I'll prepare a patch to do that and let's see what people think.

If I didn't confuse anything (which is likely, because it's a bit late here now), the patch below should do the trick. I have only checked that it doesn't break compilation, so please take it with a grain of salt.

Quoted 7 lines
Quoted 1 line

Comments welcome.

Hmm..
I don't think this is good idea.

GFP_NOIO mean "Please don't reclaim if the page is dirty". It mean the system have lots dirty pages, this patch might makes hung up.

The point is to prevent the mm subsystem from using I/O. If there's a better way, please tell me. :-)

Quoted 2 lines

If suspend need lots memory, we need to make free memory before starting IO suspending, I think.

Suspend as such doesn't need a lot of memory, except for some drivers doing things they shouldn't do.

However, there are a few problems that need to be addressed in general.

First, we can't really guarantee that there's a lot of free memory available during suspend and some memory allocations are done indirectly, using GFP_KERNEL (for example, when new kernel threads are started). If one of these is done during suspend and it happens to cause the mm subsystem to start I/O on a suspended devices, the kernel will lock up.

Second, there may be a memory allocation in progress when suspend is started that causes I/O to happen and races with the suspend process. If the latter wins the race, the I/O may be attempted on a suspended device and the kernel will lock up.

My patch attempts to avoid these two problems as well as the problem with drivers using GFP_KERNEL allocations during suspend which I admit might be solved by reworking the drivers.

Thanks,
Rafael

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#64 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: Memory allocations in .suspend became very unreliable)

Hi

Quoted 14 lines
Quoted 2 lines

If suspend need lots memory, we need to make free memory before starting IO suspending, I think.

Suspend as such doesn't need a lot of memory, except for some drivers doing things they shouldn't do.

However, there are a few problems that need to be addressed in general.

First, we can't really guarantee that there's a lot of free memory available during suspend and some memory allocations are done indirectly, using GFP_KERNEL (for example, when new kernel threads are started). If one of these is done during suspend and it happens to cause the mm subsystem to start I/O on a suspended devices, the kernel will lock up.

Quoted 4 lines

Second, there may be a memory allocation in progress when suspend is started that causes I/O to happen and races with the suspend process. If the latter wins the race, the I/O may be attempted on a suspended device and the kernel will lock up.

I think the race happen itself is bad. memory and I/O subsystem can't solve such race elegantly. These doesn't know enough suspend state knowlege. I think the practical solution is that higher level design prevent the race happen.

Quoted 3 lines

My patch attempts to avoid these two problems as well as the problem with drivers using GFP_KERNEL allocations during suspend which I admit might be solved by reworking the drivers.

Agreed. In this case, only drivers change can solve the issue.

#65 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: [linux-pm] Memory allocations in .suspend became very unreliable)

In reply to Rafael J. Wysocki

Hi

Quoted 14 lines
Quoted 2 lines

If suspend need lots memory, we need to make free memory before starting IO suspending, I think.

Suspend as such doesn't need a lot of memory, except for some drivers doing things they shouldn't do.

However, there are a few problems that need to be addressed in general.

First, we can't really guarantee that there's a lot of free memory available during suspend and some memory allocations are done indirectly, using GFP_KERNEL (for example, when new kernel threads are started). If one of these is done during suspend and it happens to cause the mm subsystem to start I/O on a suspended devices, the kernel will lock up.

Quoted 4 lines

Second, there may be a memory allocation in progress when suspend is started that causes I/O to happen and races with the suspend process. If the latter wins the race, the I/O may be attempted on a suspended device and the kernel will lock up.

I think the race happen itself is bad. memory and I/O subsystem can't solve such race elegantly. These doesn't know enough suspend state knowlege. I think the practical solution is that higher level design prevent the race happen.

Quoted 3 lines

My patch attempts to avoid these two problems as well as the problem with drivers using GFP_KERNEL allocations during suspend which I admit might be solved by reworking the drivers.

Agreed. In this case, only drivers change can solve the issue.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#66 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: Memory allocations in .suspend became very unreliable)

Quoted 10 lines · KOSAKI Motohiro

I think the race happen itself is bad. memory and I/O subsystem can't solve such race elegantly. These doesn't know enough suspend state knowlege. I think the practical solution is that higher level design prevent the race happen.

Quoted 3 lines

My patch attempts to avoid these two problems as well as the problem with drivers using GFP_KERNEL allocations during suspend which I admit might be solved by reworking the drivers.

Agreed. In this case, only drivers change can solve the issue.

As I explained earlier, this is near to impossible since the allocations are too often burried deep down the call stack or simply because the driver doesn't know that we started suspending -another- driver...

I don't think trying to solve those problems at the driver level is realistic to be honest. This is one of those things where we really just need to make allocators 'just work' from a driver perspective.

It can't be perfect of course, as mentioned earlier, there will be a problem if too little free memory is really available due to lots of dirty pages around, but most of this can be somewhat alleviated in practice, for example by pushing things out a bit at suspend time, making some more memory free etc... But yeah, nothing replaces proper error handling in drivers for allocation failures even with GFP_KERNEL :-)

Cheers,
Ben.

#67 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: [linux-pm] Memory allocations in .suspend became very unreliable)

In reply to KOSAKI Motohiro
Quoted 10 lines · KOSAKI Motohiro

I think the race happen itself is bad. memory and I/O subsystem can't solve such race elegantly. These doesn't know enough suspend state knowlege. I think the practical solution is that higher level design prevent the race happen.

Quoted 3 lines

My patch attempts to avoid these two problems as well as the problem with drivers using GFP_KERNEL allocations during suspend which I admit might be solved by reworking the drivers.

Agreed. In this case, only drivers change can solve the issue.

As I explained earlier, this is near to impossible since the allocations are too often burried deep down the call stack or simply because the driver doesn't know that we started suspending -another- driver...

I don't think trying to solve those problems at the driver level is realistic to be honest. This is one of those things where we really just need to make allocators 'just work' from a driver perspective.

It can't be perfect of course, as mentioned earlier, there will be a problem if too little free memory is really available due to lots of dirty pages around, but most of this can be somewhat alleviated in practice, for example by pushing things out a bit at suspend time, making some more memory free etc... But yeah, nothing replaces proper error handling in drivers for allocation failures even with GFP_KERNEL :-)

Cheers,
Ben.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#68 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: Memory allocations in .suspend became very unreliable)

Quoted 12 lines · Benjamin Herrenschmidt
Quoted 10 lines · KOSAKI Motohiro

I think the race happen itself is bad. memory and I/O subsystem can't solve such race elegantly. These doesn't know enough suspend state knowlege. I think the practical solution is that higher level design prevent the race happen.

Quoted 3 lines

My patch attempts to avoid these two problems as well as the problem with drivers using GFP_KERNEL allocations during suspend which I admit might be solved by reworking the drivers.

Agreed. In this case, only drivers change can solve the issue.

Quoted 7 lines

As I explained earlier, this is near to impossible since the allocations are too often burried deep down the call stack or simply because the driver doesn't know that we started suspending -another- driver...

I don't think trying to solve those problems at the driver level is realistic to be honest. This is one of those things where we really just need to make allocators 'just work' from a driver perspective.

Instead of masking bit could we only check if incompatible flags are used during suspend, and warm deeply. Call stack will be therefore identified, and we could have some metrics about such problem.

It will be a debug option like lockdep but pretty low cost.

My 2 cents.

Bastien

#69 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: [linux-pm] Memory allocations in .suspend became very unreliable)

In reply to Benjamin Herrenschmidt
Quoted 12 lines · Benjamin Herrenschmidt
Quoted 10 lines · KOSAKI Motohiro

I think the race happen itself is bad. memory and I/O subsystem can't solve such race elegantly. These doesn't know enough suspend state knowlege. I think the practical solution is that higher level design prevent the race happen.

Quoted 3 lines

My patch attempts to avoid these two problems as well as the problem with drivers using GFP_KERNEL allocations during suspend which I admit might be solved by reworking the drivers.

Agreed. In this case, only drivers change can solve the issue.

Quoted 7 lines

As I explained earlier, this is near to impossible since the allocations are too often burried deep down the call stack or simply because the driver doesn't know that we started suspending -another- driver...

I don't think trying to solve those problems at the driver level is realistic to be honest. This is one of those things where we really just need to make allocators 'just work' from a driver perspective.

Instead of masking bit could we only check if incompatible flags are used during suspend, and warm deeply. Call stack will be therefore identified, and we could have some metrics about such problem.

It will be a debug option like lockdep but pretty low cost.

My 2 cents.

Bastien

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#70 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: Memory allocations in .suspend became very unreliable)

Quoted 5 lines · Bastien ROUCARIES

Instead of masking bit could we only check if incompatible flags are used during suspend, and warm deeply. Call stack will be therefore identified, and we could have some metrics about such problem.

It will be a debug option like lockdep but pretty low cost.

I still believe it would just be a giant can of worms to require every call site of memory allocators to "know" whether suspend has been started or not.... Along the same reasons why we added that stuff for boot time allocs.

Cheers,
Ben.

#71 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: [linux-pm] Memory allocations in .suspend became very unreliable)

In reply to Bastien ROUCARIES
Quoted 5 lines · Bastien ROUCARIES

Instead of masking bit could we only check if incompatible flags are used during suspend, and warm deeply. Call stack will be therefore identified, and we could have some metrics about such problem.

It will be a debug option like lockdep but pretty low cost.

I still believe it would just be a giant can of worms to require every call site of memory allocators to "know" whether suspend has been started or not.... Along the same reasons why we added that stuff for boot time allocs.

Cheers,
Ben.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#72 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: Memory allocations in .suspend became very unreliable)

Am Mittwoch, 20. Januar 2010 00:17:51 schrieb Benjamin Herrenschmidt:

Quoted 11 lines · Bastien ROUCARIES
Quoted 5 lines

Instead of masking bit could we only check if incompatible flags are used during suspend, and warm deeply. Call stack will be therefore identified, and we could have some metrics about such problem.

It will be a debug option like lockdep but pretty low cost.

I still believe it would just be a giant can of worms to require every call site of memory allocators to "know" whether suspend has been started or not.... Along the same reasons why we added that stuff for boot time allocs.

But we have the freezer. So generally we don't require that knowledge. We can expect no normal IO to happen.
The question is in the suspend paths. We never may use anything but GFP_NOIO (and GFP_ATOMIC) in the suspend() path. We can take care of that requirement in the allocator only if the whole system is suspended. As soon as a driver does runtime power management, it is on its own.

Regards
Oliver

#73 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: [linux-pm] Memory allocations in .suspend became very unreliable)

In reply to Benjamin Herrenschmidt

Am Mittwoch, 20. Januar 2010 00:17:51 schrieb Benjamin Herrenschmidt:

Quoted 11 lines · Bastien ROUCARIES
Quoted 5 lines

Instead of masking bit could we only check if incompatible flags are used during suspend, and warm deeply. Call stack will be therefore identified, and we could have some metrics about such problem.

It will be a debug option like lockdep but pretty low cost.

I still believe it would just be a giant can of worms to require every call site of memory allocators to "know" whether suspend has been started or not.... Along the same reasons why we added that stuff for boot time allocs.

But we have the freezer. So generally we don't require that knowledge. We can expect no normal IO to happen.
The question is in the suspend paths. We never may use anything but GFP_NOIO (and GFP_ATOMIC) in the suspend() path. We can take care of that requirement in the allocator only if the whole system is suspended. As soon as a driver does runtime power management, it is on its own.

Regards
Oliver

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#74 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: Memory allocations in .suspend became very unreliable)

Quoted 3 lines · Oliver Neukum

But we have the freezer. So generally we don't require that knowledge. We can expect no normal IO to happen.

That came before and it's just not a safe assumption :-) The freezer to some extent protects drivers against ioctl's and that sort of stuff but really that's about it. There's plenty of things in the kernel that can kick IOs on their own for a reason or another, or do memory allocations which in turn will try to push something out and do IOs etc... even when "frozen".

Quoted 6 lines

The question is in the suspend paths. We never may use anything but GFP_NOIO (and GFP_ATOMIC) in the suspend() path. We can take care of that requirement in the allocator only if the whole system
is suspended. As soon as a driver does runtime power management, it is on its own.

I'm not sure I understand what you are trying to say here :-)

First of all, the problem goes beyond what a driver does in its own suspend() path. If it was just that, we might be able to some extent to push enough stuff up for the driver to specify the right GFP flags (though even that could be nasty).

The problem with system suspend also happens when your driver has not been suspended yet, but another one, which happens to be a block device with dirty pages for example, has.

Your not-yet-suspended driver might well be blocked somewhere in an allocation or about to make one with some kind of internal mutex held, that sort of thing, as part of it's normal operations, and -that- can hang, causing problems when subsequently that same driver suspend() gets called and tries to synchronize with the driver operations, for example by trying to acquire that same mutex.

There's more of similarily nasty scenario. The fact is that it's going to hit rarely, probably without a bakctrace or a crash, and so will basically cause one of those rare "my laptop didn't suspend" cases that may not even be reported, and just contribute to the general unreliability of suspend/resume.

Cheers,
Ben.

#75 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: [linux-pm] Memory allocations in .suspend became very unreliable)

In reply to Oliver Neukum
Quoted 3 lines · Oliver Neukum

But we have the freezer. So generally we don't require that knowledge. We can expect no normal IO to happen.

That came before and it's just not a safe assumption :-) The freezer to some extent protects drivers against ioctl's and that sort of stuff but really that's about it. There's plenty of things in the kernel that can kick IOs on their own for a reason or another, or do memory allocations which in turn will try to push something out and do IOs etc... even when "frozen".

Quoted 6 lines

The question is in the suspend paths. We never may use anything but GFP_NOIO (and GFP_ATOMIC) in the suspend() path. We can take care of that requirement in the allocator only if the whole system
is suspended. As soon as a driver does runtime power management, it is on its own.

I'm not sure I understand what you are trying to say here :-)

First of all, the problem goes beyond what a driver does in its own suspend() path. If it was just that, we might be able to some extent to push enough stuff up for the driver to specify the right GFP flags (though even that could be nasty).

The problem with system suspend also happens when your driver has not been suspended yet, but another one, which happens to be a block device with dirty pages for example, has.

Your not-yet-suspended driver might well be blocked somewhere in an allocation or about to make one with some kind of internal mutex held, that sort of thing, as part of it's normal operations, and -that- can hang, causing problems when subsequently that same driver suspend() gets called and tries to synchronize with the driver operations, for example by trying to acquire that same mutex.

There's more of similarily nasty scenario. The fact is that it's going to hit rarely, probably without a bakctrace or a crash, and so will basically cause one of those rare "my laptop didn't suspend" cases that may not even be reported, and just contribute to the general unreliability of suspend/resume.

Cheers,
Ben.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#76 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: [linux-pm] Memory allocations in .suspend became very unreliable)

In reply to Oliver Neukum
Quoted 13 lines · Oliver Neukum

Am Mittwoch, 20. Januar 2010 00:17:51 schrieb Benjamin Herrenschmidt:

Quoted 11 lines · Bastien ROUCARIES
Quoted 5 lines

Instead of masking bit could we only check if incompatible flags are used during suspend, and warm deeply. Call stack will be therefore identified, and we could have some metrics about such problem.

It will be a debug option like lockdep but pretty low cost.

I still believe it would just be a giant can of worms to require every call site of memory allocators to "know" whether suspend has been started or not.... Along the same reasons why we added that stuff for boot time allocs.

Quoted 7 lines

But we have the freezer. So generally we don't require that knowledge. We can expect no normal IO to happen.
The question is in the suspend paths. We never may use anything but GFP_NOIO (and GFP_ATOMIC) in the suspend() path. We can take care of that requirement in the allocator only if the whole system is suspended. As soon as a driver does runtime power management, it is on its own.

If you start new kernel threads using the async framework, for example, GFP_KERNEL allocations are going to be used.

As I said before, IMnshO , duplicating every piece of code that allocates memory and can be run during suspend/resume as well as in other circumstances doesn't make sense.

Rafael

#77 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: Memory allocations in .suspend became very unreliable)

In reply to Oliver Neukum
Quoted 13 lines · Oliver Neukum

Am Mittwoch, 20. Januar 2010 00:17:51 schrieb Benjamin Herrenschmidt:

Quoted 11 lines · Bastien ROUCARIES
Quoted 5 lines

Instead of masking bit could we only check if incompatible flags are used during suspend, and warm deeply. Call stack will be therefore identified, and we could have some metrics about such problem.

It will be a debug option like lockdep but pretty low cost.

I still believe it would just be a giant can of worms to require every call site of memory allocators to "know" whether suspend has been started or not.... Along the same reasons why we added that stuff for boot time allocs.

Quoted 7 lines

But we have the freezer. So generally we don't require that knowledge. We can expect no normal IO to happen.
The question is in the suspend paths. We never may use anything but GFP_NOIO (and GFP_ATOMIC) in the suspend() path. We can take care of that requirement in the allocator only if the whole system is suspended. As soon as a driver does runtime power management, it is on its own.

If you start new kernel threads using the async framework, for example, GFP_KERNEL allocations are going to be used.

As I said before, IMnshO , duplicating every piece of code that allocates memory and can be run during suspend/resume as well as in other circumstances doesn't make sense.

Rafael

#78 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: [linux-pm] Memory allocations in .suspend became very unreliable)

In reply to Benjamin Herrenschmidt
Quoted 20 lines · Benjamin Herrenschmidt
Quoted 10 lines · KOSAKI Motohiro

I think the race happen itself is bad. memory and I/O subsystem can't solve such race elegantly. These doesn't know enough suspend state knowlege. I think the practical solution is that higher level design prevent the race happen.

Quoted 3 lines

My patch attempts to avoid these two problems as well as the problem with drivers using GFP_KERNEL allocations during suspend which I admit might be solved by reworking the drivers.

Agreed. In this case, only drivers change can solve the issue.

As I explained earlier, this is near to impossible since the allocations are too often burried deep down the call stack or simply because the driver doesn't know that we started suspending -another- driver...

I don't think trying to solve those problems at the driver level is realistic to be honest. This is one of those things where we really just need to make allocators 'just work' from a driver perspective.

Quoted 7 lines

It can't be perfect of course, as mentioned earlier, there will be a problem if too little free memory is really available due to lots of dirty pages around, but most of this can be somewhat alleviated in practice, for example by pushing things out a bit at suspend time, making some more memory free etc... But yeah, nothing replaces proper error handling in drivers for allocation failures even with GFP_KERNEL :-)

Agreed.

Moreover, I didn't try to do anything about that before, because memory allocation problems during suspend/resume just didn't happen. We kind of knew they were possible, but since they didn't show up, it wasn't immediately necessary to address them.

Now, however, people started to see these problems in testing and I'm quite confident that this is a result of recent changes in the mm subsystem. Namely, if you read the Maxim's report carefully, you'll notice that in his test case the mm subsystem apparently attempted to use I/O even though there was free memory available in the system. This is the case I want to prevent from happening in the first place.

Rafael

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#79 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: Memory allocations in .suspend became very unreliable)

Quoted 36 lines · Benjamin Herrenschmidt
Quoted 20 lines · KOSAKI Motohiro
Quoted 10 lines

I think the race happen itself is bad. memory and I/O subsystem can't solve such race elegantly. These doesn't know enough suspend state knowlege. I think the practical solution is that higher level design prevent the race happen.

Quoted 3 lines

My patch attempts to avoid these two problems as well as the problem with drivers using GFP_KERNEL allocations during suspend which I admit might be solved by reworking the drivers.

Agreed. In this case, only drivers change can solve the issue.

As I explained earlier, this is near to impossible since the allocations are too often burried deep down the call stack or simply because the driver doesn't know that we started suspending -another- driver...

I don't think trying to solve those problems at the driver level is realistic to be honest. This is one of those things where we really just need to make allocators 'just work' from a driver perspective.

Quoted 7 lines

It can't be perfect of course, as mentioned earlier, there will be a problem if too little free memory is really available due to lots of dirty pages around, but most of this can be somewhat alleviated in practice, for example by pushing things out a bit at suspend time, making some more memory free etc... But yeah, nothing replaces proper error handling in drivers for allocation failures even with GFP_KERNEL :-)

Agreed.

Moreover, I didn't try to do anything about that before, because memory allocation problems during suspend/resume just didn't happen. We kind of knew they were possible, but since they didn't show up, it wasn't immediately necessary to address them.

Quoted 6 lines

Now, however, people started to see these problems in testing and I'm quite confident that this is a result of recent changes in the mm subsystem. Namely, if you read the Maxim's report carefully, you'll notice that in his test case the mm subsystem apparently attempted to use I/O even though there was free memory available in the system. This is the case I want to prevent from happening in the first place.

Hi Rafael,

Do you mean this is the unrelated issue of nVidia bug? Probably I haven't catch your point. I don't find Maxim's original bug report. Can we share the test-case and your analysis detail?

#80 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: [linux-pm] Memory allocations in .suspend became very unreliable)

In reply to Rafael J. Wysocki
Quoted 36 lines · Benjamin Herrenschmidt
Quoted 20 lines · KOSAKI Motohiro
Quoted 10 lines

I think the race happen itself is bad. memory and I/O subsystem can't solve such race elegantly. These doesn't know enough suspend state knowlege. I think the practical solution is that higher level design prevent the race happen.

Quoted 3 lines

My patch attempts to avoid these two problems as well as the problem with drivers using GFP_KERNEL allocations during suspend which I admit might be solved by reworking the drivers.

Agreed. In this case, only drivers change can solve the issue.

As I explained earlier, this is near to impossible since the allocations are too often burried deep down the call stack or simply because the driver doesn't know that we started suspending -another- driver...

I don't think trying to solve those problems at the driver level is realistic to be honest. This is one of those things where we really just need to make allocators 'just work' from a driver perspective.

Quoted 7 lines

It can't be perfect of course, as mentioned earlier, there will be a problem if too little free memory is really available due to lots of dirty pages around, but most of this can be somewhat alleviated in practice, for example by pushing things out a bit at suspend time, making some more memory free etc... But yeah, nothing replaces proper error handling in drivers for allocation failures even with GFP_KERNEL :-)

Agreed.

Moreover, I didn't try to do anything about that before, because memory allocation problems during suspend/resume just didn't happen. We kind of knew they were possible, but since they didn't show up, it wasn't immediately necessary to address them.

Quoted 6 lines

Now, however, people started to see these problems in testing and I'm quite confident that this is a result of recent changes in the mm subsystem. Namely, if you read the Maxim's report carefully, you'll notice that in his test case the mm subsystem apparently attempted to use I/O even though there was free memory available in the system. This is the case I want to prevent from happening in the first place.

Hi Rafael,

Do you mean this is the unrelated issue of nVidia bug? Probably I haven't catch your point. I don't find Maxim's original bug report. Can we share the test-case and your analysis detail?

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#81 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: [linux-pm] Memory allocations in .suspend became very unreliable)

Quoted 43 lines · KOSAKI Motohiro
Quoted 36 lines · Benjamin Herrenschmidt
Quoted 20 lines · KOSAKI Motohiro
Quoted 10 lines

I think the race happen itself is bad. memory and I/O subsystem can't solve such race elegantly. These doesn't know enough suspend state knowlege. I think the practical solution is that higher level design prevent the race happen.

Quoted 3 lines

My patch attempts to avoid these two problems as well as the problem with drivers using GFP_KERNEL allocations during suspend which I admit might be solved by reworking the drivers.

Agreed. In this case, only drivers change can solve the issue.

As I explained earlier, this is near to impossible since the allocations are too often burried deep down the call stack or simply because the driver doesn't know that we started suspending -another- driver...

I don't think trying to solve those problems at the driver level is realistic to be honest. This is one of those things where we really just need to make allocators 'just work' from a driver perspective.

Quoted 7 lines

It can't be perfect of course, as mentioned earlier, there will be a problem if too little free memory is really available due to lots of dirty pages around, but most of this can be somewhat alleviated in practice, for example by pushing things out a bit at suspend time, making some more memory free etc... But yeah, nothing replaces proper error handling in drivers for allocation failures even with GFP_KERNEL :-)

Agreed.

Moreover, I didn't try to do anything about that before, because memory allocation problems during suspend/resume just didn't happen. We kind of knew they were possible, but since they didn't show up, it wasn't immediately necessary to address them.

Quoted 6 lines

Now, however, people started to see these problems in testing and I'm quite confident that this is a result of recent changes in the mm subsystem. Namely, if you read the Maxim's report carefully, you'll notice that in his test case the mm subsystem apparently attempted to use I/O even though there was free memory available in the system. This is the case I want to prevent from happening in the first place.

Quoted 3 lines

Hi Rafael,

Do you mean this is the unrelated issue of nVidia bug?

The nvidia driver _is_ buggy, but Maxim said he couldn't reproduce the problem if all the allocations made by the nvidia driver during suspend were changed to GFP_ATOMIC.

Quoted 2 lines

Probably I haven't catch your point. I don't find Maxim's original bug report. Can we share the test-case and your analysis detail?

The Maxim's original report is here:
https://lists.linux-foundation.org/pipermail/linux-pm/2010-January/023982.html

and the message I'm referring to is at:
https://lists.linux-foundation.org/pipermail/linux-pm/2010-January/023990.html

Thanks,
Rafael

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#82 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: Memory allocations in .suspend became very unreliable)

Quoted 8 lines
Quoted 3 lines

Hi Rafael,

Do you mean this is the unrelated issue of nVidia bug?

The nvidia driver _is_ buggy, but Maxim said he couldn't reproduce the problem if all the allocations made by the nvidia driver during suspend were changed to GFP_ATOMIC.

Quoted 8 lines
Quoted 2 lines

Probably I haven't catch your point. I don't find Maxim's original bug report. Can we share the test-case and your analysis detail?

The Maxim's original report is here:
https://lists.linux-foundation.org/pipermail/linux-pm/2010-January/023982.html

and the message I'm referring to is at:
https://lists.linux-foundation.org/pipermail/linux-pm/2010-January/023990.html

Hmmm...

Usually, Increasing I/O isn't caused MM change. either subsystem change memory alloc/free pattern and another subsystem receive such effect ;) I don't think this message indicate MM fault.

And, 2.6.33 MM change is not much. if the fault is in MM change (note: my guess is no), The most doubtful patch is my "killing shrink_all_zones" patch. If old shrink_all_zones reclaimed memory much rather than required. The patch fixed it. IOW, the patch can reduce available free memory to be used buggy .suspend of the driver. but I don't think it is MM fault.

As I said, drivers can't use memory freely as their demand in suspend method. It's obvious. They should stop such unrealistic assumption. but How should we fix this?
- Gurantee suspend I/O device at last?
- Make much much free memory before calling .suspend method? even though typical drivers don't need.
- Ask all drivers how much they require memory before starting suspend and Make enough free memory at first?
- Or, do we have an alternative way?

Probably we have multiple option. but I don't think GFP_NOIO is good option. It assume the system have lots non-dirty cache memory and it isn't guranteed.

#83 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: [linux-pm] Memory allocations in .suspend became very unreliable)

In reply to Rafael J. Wysocki
Quoted 8 lines
Quoted 3 lines

Hi Rafael,

Do you mean this is the unrelated issue of nVidia bug?

The nvidia driver _is_ buggy, but Maxim said he couldn't reproduce the problem if all the allocations made by the nvidia driver during suspend were changed to GFP_ATOMIC.

Quoted 8 lines
Quoted 2 lines

Probably I haven't catch your point. I don't find Maxim's original bug report. Can we share the test-case and your analysis detail?

The Maxim's original report is here:
https://lists.linux-foundation.org/pipermail/linux-pm/2010-January/023982.html

and the message I'm referring to is at:
https://lists.linux-foundation.org/pipermail/linux-pm/2010-January/023990.html

Hmmm...

Usually, Increasing I/O isn't caused MM change. either subsystem change memory alloc/free pattern and another subsystem receive such effect ;) I don't think this message indicate MM fault.

And, 2.6.33 MM change is not much. if the fault is in MM change (note: my guess is no), The most doubtful patch is my "killing shrink_all_zones" patch. If old shrink_all_zones reclaimed memory much rather than required. The patch fixed it. IOW, the patch can reduce available free memory to be used buggy .suspend of the driver. but I don't think it is MM fault.

As I said, drivers can't use memory freely as their demand in suspend method. It's obvious. They should stop such unrealistic assumption. but How should we fix this?
- Gurantee suspend I/O device at last?
- Make much much free memory before calling .suspend method? even though typical drivers don't need.
- Ask all drivers how much they require memory before starting suspend and Make enough free memory at first?
- Or, do we have an alternative way?

Probably we have multiple option. but I don't think GFP_NOIO is good option. It assume the system have lots non-dirty cache memory and it isn't guranteed.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#84 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: [linux-pm] Memory allocations in .suspend became very unreliable)

Quoted 29 lines · KOSAKI Motohiro
Quoted 8 lines
Quoted 3 lines

Hi Rafael,

Do you mean this is the unrelated issue of nVidia bug?

The nvidia driver _is_ buggy, but Maxim said he couldn't reproduce the problem if all the allocations made by the nvidia driver during suspend were changed to GFP_ATOMIC.

Quoted 8 lines
Quoted 2 lines

Probably I haven't catch your point. I don't find Maxim's original bug report. Can we share the test-case and your analysis detail?

The Maxim's original report is here:
https://lists.linux-foundation.org/pipermail/linux-pm/2010-January/023982.html

and the message I'm referring to is at:
https://lists.linux-foundation.org/pipermail/linux-pm/2010-January/023990.html

Hmmm...

Usually, Increasing I/O isn't caused MM change. either subsystem change memory alloc/free pattern and another subsystem receive such effect ;) I don't think this message indicate MM fault.

And, 2.6.33 MM change is not much. if the fault is in MM change (note: my guess is no), The most doubtful patch is my "killing shrink_all_zones" patch. If old shrink_all_zones reclaimed memory much rather than required. The patch fixed it. IOW, the patch can reduce available free memory to be used buggy .suspend of the driver. but I don't think it is MM fault.

Quoted 6 lines

As I said, drivers can't use memory freely as their demand in suspend method. It's obvious. They should stop such unrealistic assumption. but How should we fix this?
- Gurantee suspend I/O device at last?
- Make much much free memory before calling .suspend method? even though typical drivers don't need.

That doesn't help already. Maxim tried to increase SPARE_PAGES (in kernel/power/power.h) and that had no effect.

Quoted 2 lines

- Ask all drivers how much they require memory before starting suspend and Make enough free memory at first?

That's equivalent to reworking all drivers to allocate memory before suspend eg. with the help of PM notifiers. Which IMHO is unrealistic.

Quoted 1 line

- Or, do we have an alternative way?

The $subject patch?

Quoted 3 lines

Probably we have multiple option. but I don't think GFP_NOIO is good option. It assume the system have lots non-dirty cache memory and it isn't guranteed.

Basically nothing is guaranteed in this case. However, does it actually make things _worse_? What _exactly_ does happen without the $subject patch if the system doesn't have non-dirty cache memory and someone makes a GFP_KERNEL allocation during suspend?

Rafael

#85 lore raw

Re: [linux-pm] [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: Memory allocations in .suspend became very unreliable)

Hi.

Quoted 6 lines · Rafael J. Wysocki
Quoted 2 lines · KOSAKI Motohiro

- Ask all drivers how much they require memory before starting suspend and Make enough free memory at first?

That's equivalent to reworking all drivers to allocate memory before suspend eg. with the help of PM notifiers. Which IMHO is unrealistic.

What's unrealistic about it? I can see that it would be a lot of work, but unrealistic? To me, at this stage, it sounds like the ideal solution.

Regards,

Nigel

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#86 lore raw

Re: [linux-pm] [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: Memory allocations in .suspend became very unreliable)

Quoted 4 lines · Nigel Cunningham

Hi.

Quoted 1 line · Rafael J. Wysocki

On Thursday 21 January 2010, KOSAKI Motohiro wrote:

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

- Ask all drivers how much they require memory before starting suspend and Make enough free memory at first?

That's equivalent to reworking all drivers to allocate memory before suspend eg. with the help of PM notifiers. Which IMHO is unrealistic.

What's unrealistic about it? I can see that it would be a lot of work, but unrealistic? To me, at this stage, it sounds like the ideal solution.

First, we'd need to audit the drivers which is quite a task by itself. Second, we'd need to make changes, preferably test them or find someone with suitable hardware to do that for us and propagate them upstream.

I don't really think we have the time to do it.

Rafael

#87 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: Memory allocations in .suspend became very unreliable)

In reply to Nigel Cunningham
Quoted 4 lines · Nigel Cunningham

Hi.

Quoted 1 line · Rafael J. Wysocki

On Thursday 21 January 2010, KOSAKI Motohiro wrote:

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

- Ask all drivers how much they require memory before starting suspend and Make enough free memory at first?

That's equivalent to reworking all drivers to allocate memory before suspend eg. with the help of PM notifiers. Which IMHO is unrealistic.

What's unrealistic about it? I can see that it would be a lot of work, but unrealistic? To me, at this stage, it sounds like the ideal solution.

First, we'd need to audit the drivers which is quite a task by itself. Second, we'd need to make changes, preferably test them or find someone with suitable hardware to do that for us and propagate them upstream.

I don't really think we have the time to do it.

Rafael

#88 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: Memory allocations in .suspend became very unreliable)

In reply to Rafael J. Wysocki

Hi.

Quoted 6 lines · Rafael J. Wysocki
Quoted 2 lines · KOSAKI Motohiro

- Ask all drivers how much they require memory before starting suspend and Make enough free memory at first?

That's equivalent to reworking all drivers to allocate memory before suspend eg. with the help of PM notifiers. Which IMHO is unrealistic.

What's unrealistic about it? I can see that it would be a lot of work, but unrealistic? To me, at this stage, it sounds like the ideal solution.

Regards,

Nigel

#89 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: Memory allocations in .suspend became very unreliable)

In reply to Rafael J. Wysocki
Quoted 6 lines
Quoted 3 lines

Probably we have multiple option. but I don't think GFP_NOIO is good option. It assume the system have lots non-dirty cache memory and it isn't guranteed.

Basically nothing is guaranteed in this case. However, does it actually make things _worse_?

Hmm..
Do you mean we don't need to prevent accidental suspend failure? Perhaps, I did misunderstand your intention. If you think your patch solve this this issue, I still disagree. but If you think your patch mitigate the pain of this issue, I agree it. I don't have any reason to oppose your first patch.

Quoted 3 lines

What _exactly_ does happen without the $subject patch if the system doesn't have non-dirty cache memory and someone makes a GFP_KERNEL allocation during suspend?

Page allocator prefer to spent lots time for reclaimable memory searching than returning NULL. IOW, it can spent time few second if it doesn't have reclaimable memory.
In typical case, OOM killer forcely make enough free memory if the system don't have any memory. But under suspending time, oom killer is disabled. So, if the caller (probably drivers) call alloc >1000times, the system spent lots seconds.

In this case, GFP_NOIO doesn't help. slowness behavior is caused by freeable memory search, not slow i/o.

However, if strange i/o device makes any i/o slowness, GFP_NOIO might help. In this case, please don't ask me about i/o thing. I don't know ;)

#90 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: [linux-pm] Memory allocations in .suspend became very unreliable)

In reply to Rafael J. Wysocki
Quoted 6 lines
Quoted 3 lines

Probably we have multiple option. but I don't think GFP_NOIO is good option. It assume the system have lots non-dirty cache memory and it isn't guranteed.

Basically nothing is guaranteed in this case. However, does it actually make things _worse_?

Hmm..
Do you mean we don't need to prevent accidental suspend failure? Perhaps, I did misunderstand your intention. If you think your patch solve this this issue, I still disagree. but If you think your patch mitigate the pain of this issue, I agree it. I don't have any reason to oppose your first patch.

Quoted 3 lines

What _exactly_ does happen without the $subject patch if the system doesn't have non-dirty cache memory and someone makes a GFP_KERNEL allocation during suspend?

Page allocator prefer to spent lots time for reclaimable memory searching than returning NULL. IOW, it can spent time few second if it doesn't have reclaimable memory.
In typical case, OOM killer forcely make enough free memory if the system don't have any memory. But under suspending time, oom killer is disabled. So, if the caller (probably drivers) call alloc >1000times, the system spent lots seconds.

In this case, GFP_NOIO doesn't help. slowness behavior is caused by freeable memory search, not slow i/o.

However, if strange i/o device makes any i/o slowness, GFP_NOIO might help. In this case, please don't ask me about i/o thing. I don't know ;)

#91 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: Memory allocations in .suspend became very unreliable)

Quoted 7 lines
Quoted 6 lines
Quoted 3 lines

Probably we have multiple option. but I don't think GFP_NOIO is good option. It assume the system have lots non-dirty cache memory and it isn't guranteed.

Basically nothing is guaranteed in this case. However, does it actually make things _worse_?

Quoted 6 lines

Hmm..
Do you mean we don't need to prevent accidental suspend failure? Perhaps, I did misunderstand your intention. If you think your patch solve this this issue, I still disagree. but If you think your patch mitigate the pain of this issue, I agree it. I don't have any reason to oppose your first patch.

One question. Have anyone tested Rafael's $subject patch? Please post test result. if the issue disapper by the patch, we can suppose the slowness is caused by i/o layer.

#92 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: [linux-pm] Memory allocations in .suspend became very unreliable)

In reply to KOSAKI Motohiro
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines

Probably we have multiple option. but I don't think GFP_NOIO is good option. It assume the system have lots non-dirty cache memory and it isn't guranteed.

Basically nothing is guaranteed in this case. However, does it actually make things _worse_?

Quoted 6 lines

Hmm..
Do you mean we don't need to prevent accidental suspend failure? Perhaps, I did misunderstand your intention. If you think your patch solve this this issue, I still disagree. but If you think your patch mitigate the pain of this issue, I agree it. I don't have any reason to oppose your first patch.

One question. Have anyone tested Rafael's $subject patch? Please post test result. if the issue disapper by the patch, we can suppose the slowness is caused by i/o layer.

#93 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: Memory allocations in .suspend became very unreliable)

Quoted 14 lines · KOSAKI Motohiro
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines

Probably we have multiple option. but I don't think GFP_NOIO is good option. It assume the system have lots non-dirty cache memory and it isn't guranteed.

Basically nothing is guaranteed in this case. However, does it actually make things _worse_?

Quoted 6 lines

Hmm..
Do you mean we don't need to prevent accidental suspend failure? Perhaps, I did misunderstand your intention. If you think your patch solve this this issue, I still disagree. but If you think your patch mitigate the pain of this issue, I agree it. I don't have any reason to oppose your first patch.

Quoted 3 lines

One question. Have anyone tested Rafael's $subject patch? Please post test result. if the issue disapper by the patch, we can suppose the slowness is caused by i/o layer.

I did.

As far as I could see, patch does solve the problem I described.

Does it affect speed of suspend? I can't say for sure. It seems to be the same.

Best regards,
Maxim Levitsky

#94 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: [linux-pm] Memory allocations in .suspend became very unreliable)

In reply to KOSAKI Motohiro
Quoted 14 lines · KOSAKI Motohiro
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines

Probably we have multiple option. but I don't think GFP_NOIO is good option. It assume the system have lots non-dirty cache memory and it isn't guranteed.

Basically nothing is guaranteed in this case. However, does it actually make things _worse_?

Quoted 6 lines

Hmm..
Do you mean we don't need to prevent accidental suspend failure? Perhaps, I did misunderstand your intention. If you think your patch solve this this issue, I still disagree. but If you think your patch mitigate the pain of this issue, I agree it. I don't have any reason to oppose your first patch.

Quoted 3 lines

One question. Have anyone tested Rafael's $subject patch? Please post test result. if the issue disapper by the patch, we can suppose the slowness is caused by i/o layer.

I did.

As far as I could see, patch does solve the problem I described.

Does it affect speed of suspend? I can't say for sure. It seems to be the same.

Best regards,
Maxim Levitsky

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#95 lore raw

PATCH 1/1 MM / PM: Force GFP_NOIO during suspend/hibernation and resume

Quoted 19 lines · Maxim Levitsky
Quoted 14 lines · KOSAKI Motohiro
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines

Probably we have multiple option. but I don't think GFP_NOIO is good option. It assume the system have lots non-dirty cache memory and it isn't guranteed.

Basically nothing is guaranteed in this case. However, does it actually make things _worse_?

Quoted 6 lines

Hmm..
Do you mean we don't need to prevent accidental suspend failure? Perhaps, I did misunderstand your intention. If you think your patch solve this this issue, I still disagree. but If you think your patch mitigate the pain of this issue, I agree it. I don't have any reason to oppose your first patch.

Quoted 3 lines

One question. Have anyone tested Rafael's $subject patch? Please post test result. if the issue disapper by the patch, we can suppose the slowness is caused by i/o layer.

Quoted 6 lines

I did.

As far as I could see, patch does solve the problem I described.

Does it affect speed of suspend? I can't say for sure. It seems to be the same.

Thanks for testing.

Below is a slightly different version of that patch. Can you please give it a try?

Rafael

---
From: Rafael J. Wysocki <[email protected]>
Subject: MM / PM: Force GFP_NOIO during suspend/hibernation and resume

There are quite a few GFP_KERNEL memory allocations made during suspend/hibernation and resume that may cause the system to hang, because the I/O operations they depend on cannot be completed due to the underlying devices being suspended.

Mitigate this problem by clearing the __GFP_IO and __GFP_FS bits in gfp_allowed_mask before suspend/hibernation and restoring the original values of these bits in gfp_allowed_mask durig the subsequent resume.

---
 kernel/power/hibernate.c |    6 ++++++
 kernel/power/power.h     |    3 +++
 kernel/power/suspend.c   |    2 ++
 mm/Makefile              |    1 +
 mm/pm.c                  |   28 ++++++++++++++++++++++++++++
 5 files changed, 40 insertions(+)
kernel/power/hibernate.c +6 -0
Index: linux-2.6/kernel/power/hibernate.c
===================================================================
@@ -334,6 +334,7 @@ int hibernation_snapshot(int platform_mo
 		goto Close;
 
 	suspend_console();
+	mm_force_noio_allocations();
 	error = dpm_suspend_start(PMSG_FREEZE);
 	if (error)
 		goto Recover_platform;
@@ -351,6 +352,7 @@ int hibernation_snapshot(int platform_mo
 
 	dpm_resume_end(in_suspend ?
 		(error ? PMSG_RECOVER : PMSG_THAW) : PMSG_RESTORE);
+	mm_allow_io_allocations();
 	resume_console();
  Close:
 	platform_end(platform_mode);
@@ -448,11 +450,13 @@ int hibernation_restore(int platform_mod
 
 	pm_prepare_console();
 	suspend_console();
+	mm_force_noio_allocations();
 	error = dpm_suspend_start(PMSG_QUIESCE);
 	if (!error) {
 		error = resume_target_kernel(platform_mode);
 		dpm_resume_end(PMSG_RECOVER);
 	}
+	mm_allow_io_allocations();
 	resume_console();
 	pm_restore_console();
 	return error;
@@ -481,6 +485,7 @@ int hibernation_platform_enter(void)
 
 	entering_platform_hibernation = true;
 	suspend_console();
+	mm_force_noio_allocations();
 	error = dpm_suspend_start(PMSG_HIBERNATE);
 	if (error) {
 		if (hibernation_ops->recover)
@@ -518,6 +523,7 @@ int hibernation_platform_enter(void)
  Resume_devices:
 	entering_platform_hibernation = false;
 	dpm_resume_end(PMSG_RESTORE);
+	mm_allow_io_allocations();
 	resume_console();
 
  Close:
kernel/power/power.h +3 -0
Index: linux-2.6/kernel/power/power.h
===================================================================
@@ -187,6 +187,9 @@ static inline void suspend_test_finish(c
 #ifdef CONFIG_PM_SLEEP
 /* kernel/power/main.c */
 extern int pm_notifier_call_chain(unsigned long val);
+/* mm/pm.c */
+extern void mm_force_noio_allocations(void);
+extern void mm_allow_io_allocations(void);
 #endif
 
 #ifdef CONFIG_HIGHMEM
kernel/power/suspend.c +2 -0
Index: linux-2.6/kernel/power/suspend.c
===================================================================
@@ -208,6 +208,7 @@ int suspend_devices_and_enter(suspend_st
 			goto Close;
 	}
 	suspend_console();
+	mm_force_noio_allocations();
 	suspend_test_start();
 	error = dpm_suspend_start(PMSG_SUSPEND);
 	if (error) {
@@ -224,6 +225,7 @@ int suspend_devices_and_enter(suspend_st
 	suspend_test_start();
 	dpm_resume_end(PMSG_RESUME);
 	suspend_test_finish("resume devices");
+	mm_allow_io_allocations();
 	resume_console();
  Close:
 	if (suspend_ops->end)
mm/Makefile +1 -0
Index: linux-2.6/mm/Makefile
===================================================================
@@ -40,3 +40,4 @@ obj-$(CONFIG_MEMORY_FAILURE) += memory-f
 obj-$(CONFIG_HWPOISON_INJECT) += hwpoison-inject.o
 obj-$(CONFIG_DEBUG_KMEMLEAK) += kmemleak.o
 obj-$(CONFIG_DEBUG_KMEMLEAK_TEST) += kmemleak-test.o
+obj-$(CONFIG_PM_SLEEP) += pm.o
mm/pm.c new file +28 -0
Index: linux-2.6/mm/pm.c
===================================================================
@@ -0,0 +1,28 @@
+#include <linux/gfp.h>
+
+static gfp_t saved_gfp_allowed_mask;
+
+#define GFP_IOFS (__GFP_IO | __GFP_FS)
+
+/**
+ * mm_force_noio_allocations - Modify gfp_allowed_mask to disable IO allocations
+ *
+ * Change gfp_allowed_mask by unsetting __GFP_IO and __GFP_FS in it and save the
+ * old value.
+ */
+void mm_force_noio_allocations(void)
+{
+	saved_gfp_allowed_mask = gfp_allowed_mask;
+	gfp_allowed_mask &= ~GFP_IOFS;
+}
+
+/**
+ * mm_allow_io_allocations - Modify gfp_allowed_mask to allow IO allocations
+ *
+ * If the saved value of gfp_allowed_mask has __GFP_IO set, modify the current
+ * gfp_allowed_mask by setting this bit and anlogously for __GFP_FS.
+ */
+void mm_allow_io_allocations(void)
+{
+	gfp_allowed_mask |= saved_gfp_allowed_mask & GFP_IOFS;
+}

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#96 lore raw

Re: [Update][PATCH] MM / PM: Force GFP_NOIO during suspend/hibernation and resume

Quoted 20 lines · Rafael J. Wysocki
Quoted 19 lines · Maxim Levitsky
Quoted 17 lines · KOSAKI Motohiro
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines

Probably we have multiple option. but I don't think GFP_NOIO is good option. It assume the system have lots non-dirty cache memory and it isn't guranteed.

Basically nothing is guaranteed in this case. However, does it actually make things _worse_?

Quoted 6 lines

Hmm..
Do you mean we don't need to prevent accidental suspend failure? Perhaps, I did misunderstand your intention. If you think your patch solve this this issue, I still disagree. but If you think your patch mitigate the pain of this issue, I agree it. I don't have any reason to oppose your first patch.

One question. Have anyone tested Rafael's $subject patch? Please post test result. if the issue disapper by the patch, we can suppose the slowness is caused by i/o layer.

Quoted 8 lines
Quoted 6 lines

I did.

As far as I could see, patch does solve the problem I described.

Does it affect speed of suspend? I can't say for sure. It seems to be the same.

Thanks for testing.

I'll test that too, soon.
Just to note that I left my hibernate loop run overnight, and now I am posting from my notebook after it did 590 hibernate cycles.

Offtopic, but Note that to achieve that I had to stop using global acpi hardware lock. I tried all kinds of things, but for now it just hands from time to time.
See http://bugzilla.kernel.org/show_bug.cgi?id=14668

Best regards,
Maxim Levitsky

#97 lore raw

Re: [Update][PATCH] MM / PM: Force GFP_NOIO during suspend/hibernation and resume

In reply to Rafael J. Wysocki
Quoted 20 lines · Rafael J. Wysocki
Quoted 19 lines · Maxim Levitsky
Quoted 17 lines · KOSAKI Motohiro
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines

Probably we have multiple option. but I don't think GFP_NOIO is good option. It assume the system have lots non-dirty cache memory and it isn't guranteed.

Basically nothing is guaranteed in this case. However, does it actually make things _worse_?

Quoted 6 lines

Hmm..
Do you mean we don't need to prevent accidental suspend failure? Perhaps, I did misunderstand your intention. If you think your patch solve this this issue, I still disagree. but If you think your patch mitigate the pain of this issue, I agree it. I don't have any reason to oppose your first patch.

One question. Have anyone tested Rafael's $subject patch? Please post test result. if the issue disapper by the patch, we can suppose the slowness is caused by i/o layer.

Quoted 8 lines
Quoted 6 lines

I did.

As far as I could see, patch does solve the problem I described.

Does it affect speed of suspend? I can't say for sure. It seems to be the same.

Thanks for testing.

I'll test that too, soon.
Just to note that I left my hibernate loop run overnight, and now I am posting from my notebook after it did 590 hibernate cycles.

Offtopic, but Note that to achieve that I had to stop using global acpi hardware lock. I tried all kinds of things, but for now it just hands from time to time.
See http://bugzilla.kernel.org/show_bug.cgi?id=14668

Best regards,
Maxim Levitsky

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#98 lore raw

Re: [Update][PATCH] MM / PM: Force GFP_NOIO during suspend/hibernation and resume

Quoted 25 lines · Maxim Levitsky
Quoted 24 lines · Rafael J. Wysocki
Quoted 23 lines · Maxim Levitsky
Quoted 14 lines · KOSAKI Motohiro
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines

Probably we have multiple option. but I don't think GFP_NOIO is good option. It assume the system have lots non-dirty cache memory and it isn't guranteed.

Basically nothing is guaranteed in this case. However, does it actually make things _worse_?

Quoted 6 lines

Hmm..
Do you mean we don't need to prevent accidental suspend failure? Perhaps, I did misunderstand your intention. If you think your patch solve this this issue, I still disagree. but If you think your patch mitigate the pain of this issue, I agree it. I don't have any reason to oppose your first patch.

Quoted 3 lines

One question. Have anyone tested Rafael's $subject patch? Please post test result. if the issue disapper by the patch, we can suppose the slowness is caused by i/o layer.

I did.

As far as I could see, patch does solve the problem I described.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Does it affect speed of suspend? I can't say for sure. It seems to be the same.

Thanks for testing.

I'll test that too, soon.
Just to note that I left my hibernate loop run overnight, and now I am posting from my notebook after it did 590 hibernate cycles.

Did you have a chance to test it?

Quoted 4 lines

Offtopic, but Note that to achieve that I had to stop using global acpi hardware lock. I tried all kinds of things, but for now it just hands from time to time.
See http://bugzilla.kernel.org/show_bug.cgi?id=14668

I'm going to look at that later this week, although I'm not sure I can do more than Alex about that.

Rafael

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#99 lore raw

Re: [Update][PATCH] MM / PM: Force GFP_NOIO during suspend/hibernation and resume

Rafael J. Wysocki пишет:

Quoted 36 lines · Maxim Levitsky
Quoted 19 lines · Rafael J. Wysocki
Quoted 18 lines · Maxim Levitsky
Quoted 17 lines · KOSAKI Motohiro
Quoted 11 lines
Quoted 11 lines
Quoted 5 lines
Quoted 3 lines

Probably we have multiple option. but I don't think GFP_NOIO is good option. It assume the system have lots non-dirty cache memory and it isn't guranteed.

Basically nothing is guaranteed in this case. However, does it actually make things _worse_?

Hmm..
Do you mean we don't need to prevent accidental suspend failure? Perhaps, I did misunderstand your intention. If you think your patch solve this this issue, I still disagree. but If you think your patch mitigate the pain of this issue, I agree it. I don't have any reason to oppose your first patch.

Quoted 3 lines

One question. Have anyone tested Rafael's $subject patch? Please post test result. if the issue disapper by the patch, we can suppose the slowness is caused by i/o layer.

I did.

Quoted 8 lines
Quoted 5 lines
Quoted 4 lines

As far as I could see, patch does solve the problem I described.

Does it affect speed of suspend? I can't say for sure. It seems to be the same.

Thanks for testing.

I'll test that too, soon.
Just to note that I left my hibernate loop run overnight, and now I am posting from my notebook after it did 590 hibernate cycles.

Did you have a chance to test it?

Quoted 4 lines

Offtopic, but Note that to achieve that I had to stop using global acpi hardware lock. I tried all kinds of things, but for now it just hands from time to time.
See http://bugzilla.kernel.org/show_bug.cgi?id=14668

Quoted 4 lines

I'm going to look at that later this week, although I'm not sure I can do more than Alex about that.

Rafael

Rafael,
If you can point to where one may insert callback to be called just before handing control to resume kernel, it may help...

Regards,
Alex.

_______________________________________________
linux-pm mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/linux-pm

#100 lore raw

Re: [Update][PATCH] MM / PM: Force GFP_NOIO during suspend/hibernation and resume

In reply to Rafael J. Wysocki

Rafael J. Wysocki пишет:

Quoted 36 lines · Maxim Levitsky
Quoted 19 lines · Rafael J. Wysocki
Quoted 18 lines · Maxim Levitsky
Quoted 17 lines · KOSAKI Motohiro
Quoted 11 lines
Quoted 11 lines
Quoted 5 lines
Quoted 3 lines

Probably we have multiple option. but I don't think GFP_NOIO is good option. It assume the system have lots non-dirty cache memory and it isn't guranteed.

Basically nothing is guaranteed in this case. However, does it actually make things _worse_?

Hmm..
Do you mean we don't need to prevent accidental suspend failure? Perhaps, I did misunderstand your intention. If you think your patch solve this this issue, I still disagree. but If you think your patch mitigate the pain of this issue, I agree it. I don't have any reason to oppose your first patch.

Quoted 3 lines

One question. Have anyone tested Rafael's $subject patch? Please post test result. if the issue disapper by the patch, we can suppose the slowness is caused by i/o layer.

I did.

Quoted 8 lines
Quoted 5 lines
Quoted 4 lines

As far as I could see, patch does solve the problem I described.

Does it affect speed of suspend? I can't say for sure. It seems to be the same.

Thanks for testing.

I'll test that too, soon.
Just to note that I left my hibernate loop run overnight, and now I am posting from my notebook after it did 590 hibernate cycles.

Did you have a chance to test it?

Quoted 4 lines

Offtopic, but Note that to achieve that I had to stop using global acpi hardware lock. I tried all kinds of things, but for now it just hands from time to time.
See http://bugzilla.kernel.org/show_bug.cgi?id=14668

Quoted 4 lines

I'm going to look at that later this week, although I'm not sure I can do more than Alex about that.

Rafael

Rafael,
If you can point to where one may insert callback to be called just before handing control to resume kernel, it may help...

Regards,
Alex.

#101 lore raw

Re: [Update][PATCH] MM / PM: Force GFP_NOIO during suspend/hibernation and resume

Quoted 37 lines · Alexey Starikovskiy

Rafael J. Wysocki пишет:

Quoted 36 lines · Maxim Levitsky
Quoted 19 lines · Rafael J. Wysocki
Quoted 18 lines · Maxim Levitsky
Quoted 17 lines · KOSAKI Motohiro
Quoted 11 lines
Quoted 11 lines
Quoted 5 lines
Quoted 3 lines

Probably we have multiple option. but I don't think GFP_NOIO is good option. It assume the system have lots non-dirty cache memory and it isn't guranteed.

Basically nothing is guaranteed in this case. However, does it actually make things _worse_?

Hmm..
Do you mean we don't need to prevent accidental suspend failure? Perhaps, I did misunderstand your intention. If you think your patch solve this this issue, I still disagree. but If you think your patch mitigate the pain of this issue, I agree it. I don't have any reason to oppose your first patch.

Quoted 3 lines

One question. Have anyone tested Rafael's $subject patch? Please post test result. if the issue disapper by the patch, we can suppose the slowness is caused by i/o layer.

I did.

Quoted 8 lines
Quoted 5 lines
Quoted 4 lines

As far as I could see, patch does solve the problem I described.

Does it affect speed of suspend? I can't say for sure. It seems to be the same.

Thanks for testing.

I'll test that too, soon.
Just to note that I left my hibernate loop run overnight, and now I am posting from my notebook after it did 590 hibernate cycles.

Did you have a chance to test it?

Quoted 4 lines

Offtopic, but Note that to achieve that I had to stop using global acpi hardware lock. I tried all kinds of things, but for now it just hands from time to time.
See http://bugzilla.kernel.org/show_bug.cgi?id=14668

Quoted 7 lines
Quoted 4 lines

I'm going to look at that later this week, although I'm not sure I can do more than Alex about that.

Rafael

Rafael,
If you can point to where one may insert callback to be called just before handing control to resume kernel, it may help...

Generally speaking, I'd do that in a .suspend() callback of one of devices.

If that's inconvenient, you can also place it in the .pre_restore() platform hibernate callback (drivers/acpi/sleep.c). It only disables GPEs right now, it might release the global lock as well.

The .pre_restore() callback is executed after all devices have been suspended, so there's no danger any driver would re-acquire the global lock after that.

Rafael

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#102 lore raw

Re: [Update][PATCH] MM / PM: Force GFP_NOIO during suspend/hibernation and resume

Quoted 46 lines · Rafael J. Wysocki
Quoted 37 lines · Alexey Starikovskiy

Rafael J. Wysocki пишет:

Quoted 36 lines · Maxim Levitsky
Quoted 19 lines · Rafael J. Wysocki
Quoted 18 lines · Maxim Levitsky
Quoted 17 lines · KOSAKI Motohiro
Quoted 11 lines
Quoted 11 lines
Quoted 5 lines
Quoted 3 lines

Probably we have multiple option. but I don't think GFP_NOIO is good option. It assume the system have lots non-dirty cache memory and it isn't guranteed.

Basically nothing is guaranteed in this case. However, does it actually make things _worse_?

Hmm..
Do you mean we don't need to prevent accidental suspend failure? Perhaps, I did misunderstand your intention. If you think your patch solve this this issue, I still disagree. but If you think your patch mitigate the pain of this issue, I agree it. I don't have any reason to oppose your first patch.

Quoted 3 lines

One question. Have anyone tested Rafael's $subject patch? Please post test result. if the issue disapper by the patch, we can suppose the slowness is caused by i/o layer.

I did.

Quoted 8 lines
Quoted 5 lines
Quoted 4 lines

As far as I could see, patch does solve the problem I described.

Does it affect speed of suspend? I can't say for sure. It seems to be the same.

Thanks for testing.

I'll test that too, soon.
Just to note that I left my hibernate loop run overnight, and now I am posting from my notebook after it did 590 hibernate cycles.

Did you have a chance to test it?

Quoted 4 lines

Offtopic, but Note that to achieve that I had to stop using global acpi hardware lock. I tried all kinds of things, but for now it just hands from time to time.
See http://bugzilla.kernel.org/show_bug.cgi?id=14668

Quoted 7 lines
Quoted 4 lines

I'm going to look at that later this week, although I'm not sure I can do more than Alex about that.

Rafael

Rafael,
If you can point to where one may insert callback to be called just before handing control to resume kernel, it may help...

Quoted 8 lines

Generally speaking, I'd do that in a .suspend() callback of one of devices.

If that's inconvenient, you can also place it in the .pre_restore() platform hibernate callback (drivers/acpi/sleep.c). It only disables GPEs right now, it might release the global lock as well.

The .pre_restore() callback is executed after all devices have been suspended, so there's no danger any driver would re-acquire the global lock after that.

Well, I did that very late, very close to image restore. Still, it didn't work (It hung after the resume, in the kernel that was just restored, on access to the hardware lock, or in other words in same way)

Here is what I did:

commit 71e0be39531ac01b99020ea139ef3c23aa6de415

Author: Maxim Levitsky <[email protected]>
Date:   Wed Jan 20 21:52:21 2010 +0200

Kernel that does the resume from disk can take global hardware
acpi lock, but not release it (for example if it is in middle of access to locked field) Always release it before passing control to resumed kernel

drivers/acpi/acpica/acglobal.h +1 -0
index 29ba66d..29e1be0 100644
@@ -195,6 +195,7 @@ ACPI_EXTERN acpi_semaphore acpi_gbl_global_lock_semaphore;
 ACPI_EXTERN u16 acpi_gbl_global_lock_handle;
 ACPI_EXTERN u8 acpi_gbl_global_lock_acquired;
 ACPI_EXTERN u8 acpi_gbl_global_lock_present;
+ACPI_EXTERN u8 acpi_gbl_global_lock_suspended;
 
 /*
  * Spinlocks are used for interfaces that can be possibly called at
drivers/acpi/acpica/evmisc.c +1 -1
index ce224e1..f3569db 100644
@@ -456,7 +456,7 @@ acpi_status acpi_ev_acquire_global_lock(u16 timeout)
 	 * Make sure that a global lock actually exists. If not, just treat the
 	 * lock as a standard mutex.
 	 */
-	if (!acpi_gbl_global_lock_present) {
+	if (!acpi_gbl_global_lock_present || acpi_gbl_global_lock_suspended) {
 		acpi_gbl_global_lock_acquired = TRUE;
 		return_ACPI_STATUS(AE_OK);
 	}
drivers/acpi/acpica/evxface.c +26 -0
index 2fe0809..b27904e 100644
@@ -820,3 +820,29 @@ acpi_status acpi_release_global_lock(u32 handle)
 }
 
 ACPI_EXPORT_SYMBOL(acpi_release_global_lock)
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    acpi_bust_global_lock
+ *
+ * PARAMETERS:  None
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Release global lock and ignore it from now on
+ *
+ ******************************************************************************/
+
+acpi_status acpi_bust_global_lock(void)
+{
+	acpi_status status;
+
+	status = acpi_ex_acquire_mutex_object(ACPI_WAIT_FOREVER,
+					      acpi_gbl_global_lock_mutex,
+					      acpi_os_get_thread_id());
+
+	acpi_gbl_global_lock_suspended = TRUE;
+
+	status = acpi_ex_release_mutex_object(acpi_gbl_global_lock_mutex);
+}
drivers/acpi/acpica/utglobal.c +1 -0
index 3f2c68f..e4cafea 100644
@@ -782,6 +782,7 @@ acpi_status acpi_ut_init_globals(void)
 	acpi_gbl_global_lock_acquired = FALSE;
 	acpi_gbl_global_lock_handle = 0;
 	acpi_gbl_global_lock_present = FALSE;
+	acpi_gbl_global_lock_suspended = FALSE;
 
 	/* Miscellaneous variables */
 
drivers/acpi/sleep.c +18 -1
index 79d33d9..6e41954 100644
@@ -119,6 +119,23 @@ static int acpi_pm_disable_gpes(void)
 }
 
 /**
+ *	acpi_pm_pre_restore - called just before the restore
+ */
+
+static int acpi_pm_pre_restore(void)
+{
+	u32 glk;
+
+	acpi_pm_disable_gpes();
+
+	/* We can't let the resuming kernel see the global
+		lock locked, so bust it */
+
+	acpi_bust_global_lock();
+	return 0;
+}
+
+/**
  *	__acpi_pm_prepare - Prepare the platform to enter the target state.
  *
  *	If necessary, set the firmware waking vector and do arch-specific
@@ -565,7 +582,7 @@ static struct platform_hibernation_ops acpi_hibernation_ops = {
 	.prepare = acpi_pm_prepare,
 	.enter = acpi_hibernation_enter,
 	.leave = acpi_hibernation_leave,
-	.pre_restore = acpi_pm_disable_gpes,
+	.pre_restore = acpi_pm_pre_restore,
 	.restore_cleanup = acpi_pm_enable_gpes,
 };
 
include/acpi/acpixf.h +2 -0
index 86e9735..63132b0 100644
@@ -270,6 +270,8 @@ acpi_status acpi_acquire_global_lock(u16 timeout, u32 * handle);
 
 acpi_status acpi_release_global_lock(u32 handle);
 
+acpi_status acpi_bust_global_lock(void);
+
 acpi_status acpi_enable_event(u32 event, u32 flags);
 
 acpi_status acpi_disable_event(u32 event, u32 flags);

_______________________________________________
linux-pm mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/linux-pm

#103 lore raw

Re: [Update][PATCH] MM / PM: Force GFP_NOIO during suspend/hibernation and resume

In reply to Rafael J. Wysocki
Quoted 46 lines · Rafael J. Wysocki
Quoted 37 lines · Alexey Starikovskiy

Rafael J. Wysocki D?D,N?DuN?:

Quoted 36 lines · Maxim Levitsky
Quoted 19 lines · Rafael J. Wysocki
Quoted 18 lines · Maxim Levitsky
Quoted 17 lines · KOSAKI Motohiro
Quoted 11 lines
Quoted 11 lines
Quoted 5 lines
Quoted 3 lines

Probably we have multiple option. but I don't think GFP_NOIO is good option. It assume the system have lots non-dirty cache memory and it isn't guranteed.

Basically nothing is guaranteed in this case. However, does it actually make things _worse_?

Hmm..
Do you mean we don't need to prevent accidental suspend failure? Perhaps, I did misunderstand your intention. If you think your patch solve this this issue, I still disagree. but If you think your patch mitigate the pain of this issue, I agree it. I don't have any reason to oppose your first patch.

Quoted 3 lines

One question. Have anyone tested Rafael's $subject patch? Please post test result. if the issue disapper by the patch, we can suppose the slowness is caused by i/o layer.

I did.

Quoted 8 lines
Quoted 5 lines
Quoted 4 lines

As far as I could see, patch does solve the problem I described.

Does it affect speed of suspend? I can't say for sure. It seems to be the same.

Thanks for testing.

I'll test that too, soon.
Just to note that I left my hibernate loop run overnight, and now I am posting from my notebook after it did 590 hibernate cycles.

Did you have a chance to test it?

Quoted 4 lines

Offtopic, but Note that to achieve that I had to stop using global acpi hardware lock. I tried all kinds of things, but for now it just hands from time to time.
See http://bugzilla.kernel.org/show_bug.cgi?id=14668

Quoted 7 lines
Quoted 4 lines

I'm going to look at that later this week, although I'm not sure I can do more than Alex about that.

Rafael

Rafael,
If you can point to where one may insert callback to be called just before handing control to resume kernel, it may help...

Quoted 8 lines

Generally speaking, I'd do that in a .suspend() callback of one of devices.

If that's inconvenient, you can also place it in the .pre_restore() platform hibernate callback (drivers/acpi/sleep.c). It only disables GPEs right now, it might release the global lock as well.

The .pre_restore() callback is executed after all devices have been suspended, so there's no danger any driver would re-acquire the global lock after that.

Well, I did that very late, very close to image restore. Still, it didn't work (It hung after the resume, in the kernel that was just restored, on access to the hardware lock, or in other words in same way)

Here is what I did:

commit 71e0be39531ac01b99020ea139ef3c23aa6de415

Author: Maxim Levitsky <[email protected]>
Date:   Wed Jan 20 21:52:21 2010 +0200

Kernel that does the resume from disk can take global hardware
acpi lock, but not release it (for example if it is in middle of access to locked field) Always release it before passing control to resumed kernel

drivers/acpi/acpica/acglobal.h +1 -0
index 29ba66d..29e1be0 100644
@@ -195,6 +195,7 @@ ACPI_EXTERN acpi_semaphore acpi_gbl_global_lock_semaphore;
 ACPI_EXTERN u16 acpi_gbl_global_lock_handle;
 ACPI_EXTERN u8 acpi_gbl_global_lock_acquired;
 ACPI_EXTERN u8 acpi_gbl_global_lock_present;
+ACPI_EXTERN u8 acpi_gbl_global_lock_suspended;
 
 /*
  * Spinlocks are used for interfaces that can be possibly called at
drivers/acpi/acpica/evmisc.c +1 -1
index ce224e1..f3569db 100644
@@ -456,7 +456,7 @@ acpi_status acpi_ev_acquire_global_lock(u16 timeout)
 	 * Make sure that a global lock actually exists. If not, just treat the
 	 * lock as a standard mutex.
 	 */
-	if (!acpi_gbl_global_lock_present) {
+	if (!acpi_gbl_global_lock_present || acpi_gbl_global_lock_suspended) {
 		acpi_gbl_global_lock_acquired = TRUE;
 		return_ACPI_STATUS(AE_OK);
 	}
drivers/acpi/acpica/evxface.c +26 -0
index 2fe0809..b27904e 100644
@@ -820,3 +820,29 @@ acpi_status acpi_release_global_lock(u32 handle)
 }
 
 ACPI_EXPORT_SYMBOL(acpi_release_global_lock)
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    acpi_bust_global_lock
+ *
+ * PARAMETERS:  None
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Release global lock and ignore it from now on
+ *
+ ******************************************************************************/
+
+acpi_status acpi_bust_global_lock(void)
+{
+	acpi_status status;
+
+	status = acpi_ex_acquire_mutex_object(ACPI_WAIT_FOREVER,
+					      acpi_gbl_global_lock_mutex,
+					      acpi_os_get_thread_id());
+
+	acpi_gbl_global_lock_suspended = TRUE;
+
+	status = acpi_ex_release_mutex_object(acpi_gbl_global_lock_mutex);
+}
drivers/acpi/acpica/utglobal.c +1 -0
index 3f2c68f..e4cafea 100644
@@ -782,6 +782,7 @@ acpi_status acpi_ut_init_globals(void)
 	acpi_gbl_global_lock_acquired = FALSE;
 	acpi_gbl_global_lock_handle = 0;
 	acpi_gbl_global_lock_present = FALSE;
+	acpi_gbl_global_lock_suspended = FALSE;
 
 	/* Miscellaneous variables */
 
drivers/acpi/sleep.c +18 -1
index 79d33d9..6e41954 100644
@@ -119,6 +119,23 @@ static int acpi_pm_disable_gpes(void)
 }
 
 /**
+ *	acpi_pm_pre_restore - called just before the restore
+ */
+
+static int acpi_pm_pre_restore(void)
+{
+	u32 glk;
+
+	acpi_pm_disable_gpes();
+
+	/* We can't let the resuming kernel see the global
+		lock locked, so bust it */
+
+	acpi_bust_global_lock();
+	return 0;
+}
+
+/**
  *	__acpi_pm_prepare - Prepare the platform to enter the target state.
  *
  *	If necessary, set the firmware waking vector and do arch-specific
@@ -565,7 +582,7 @@ static struct platform_hibernation_ops acpi_hibernation_ops = {
 	.prepare = acpi_pm_prepare,
 	.enter = acpi_hibernation_enter,
 	.leave = acpi_hibernation_leave,
-	.pre_restore = acpi_pm_disable_gpes,
+	.pre_restore = acpi_pm_pre_restore,
 	.restore_cleanup = acpi_pm_enable_gpes,
 };
 
include/acpi/acpixf.h +2 -0
index 86e9735..63132b0 100644
@@ -270,6 +270,8 @@ acpi_status acpi_acquire_global_lock(u16 timeout, u32 * handle);
 
 acpi_status acpi_release_global_lock(u32 handle);
 
+acpi_status acpi_bust_global_lock(void);
+
 acpi_status acpi_enable_event(u32 event, u32 flags);
 
 acpi_status acpi_disable_event(u32 event, u32 flags);

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#104 lore raw

Re: [Update][PATCH] MM / PM: Force GFP_NOIO during suspend/hibernation and resume

Quoted 57 lines · Maxim Levitsky
Quoted 46 lines · Rafael J. Wysocki
Quoted 37 lines · Alexey Starikovskiy

Rafael J. Wysocki пишет:

Quoted 36 lines · Maxim Levitsky
Quoted 19 lines · Rafael J. Wysocki
Quoted 18 lines · Maxim Levitsky
Quoted 17 lines · KOSAKI Motohiro
Quoted 11 lines
Quoted 11 lines
Quoted 5 lines
Quoted 3 lines

Probably we have multiple option. but I don't think GFP_NOIO is good option. It assume the system have lots non-dirty cache memory and it isn't guranteed.

Basically nothing is guaranteed in this case. However, does it actually make things _worse_?

Hmm..
Do you mean we don't need to prevent accidental suspend failure? Perhaps, I did misunderstand your intention. If you think your patch solve this this issue, I still disagree. but If you think your patch mitigate the pain of this issue, I agree it. I don't have any reason to oppose your first patch.

Quoted 3 lines

One question. Have anyone tested Rafael's $subject patch? Please post test result. if the issue disapper by the patch, we can suppose the slowness is caused by i/o layer.

I did.

Quoted 8 lines
Quoted 5 lines
Quoted 4 lines

As far as I could see, patch does solve the problem I described.

Does it affect speed of suspend? I can't say for sure. It seems to be the same.

Thanks for testing.

I'll test that too, soon.
Just to note that I left my hibernate loop run overnight, and now I am posting from my notebook after it did 590 hibernate cycles.

Did you have a chance to test it?

Quoted 4 lines

Offtopic, but Note that to achieve that I had to stop using global acpi hardware lock. I tried all kinds of things, but for now it just hands from time to time.
See http://bugzilla.kernel.org/show_bug.cgi?id=14668

Quoted 7 lines
Quoted 4 lines

I'm going to look at that later this week, although I'm not sure I can do more than Alex about that.

Rafael

Rafael,
If you can point to where one may insert callback to be called just before handing control to resume kernel, it may help...

Quoted 8 lines

Generally speaking, I'd do that in a .suspend() callback of one of devices.

If that's inconvenient, you can also place it in the .pre_restore() platform hibernate callback (drivers/acpi/sleep.c). It only disables GPEs right now, it might release the global lock as well.

The .pre_restore() callback is executed after all devices have been suspended, so there's no danger any driver would re-acquire the global lock after that.

Quoted 6 lines

Well, I did that very late, very close to image restore. Still, it didn't work (It hung after the resume, in the kernel that was just restored, on access to the hardware lock, or in other words in same way)

Here is what I did:

I saw the patch in the bug entry
(http://bugzilla.kernel.org/show_bug.cgi?id=14668).
Please see the comments in there.

Please also test the patch I attached and let's use the bug entry for the tracking of this issue from now on.

Rafael

#105 lore raw

Re: [Update][PATCH] MM / PM: Force GFP_NOIO during suspend/hibernation and resume

In reply to Maxim Levitsky
Quoted 57 lines · Maxim Levitsky
Quoted 46 lines · Rafael J. Wysocki
Quoted 37 lines · Alexey Starikovskiy

Rafael J. Wysocki пишет:

Quoted 36 lines · Maxim Levitsky
Quoted 19 lines · Rafael J. Wysocki
Quoted 18 lines · Maxim Levitsky
Quoted 17 lines · KOSAKI Motohiro
Quoted 11 lines
Quoted 11 lines
Quoted 5 lines
Quoted 3 lines

Probably we have multiple option. but I don't think GFP_NOIO is good option. It assume the system have lots non-dirty cache memory and it isn't guranteed.

Basically nothing is guaranteed in this case. However, does it actually make things _worse_?

Hmm..
Do you mean we don't need to prevent accidental suspend failure? Perhaps, I did misunderstand your intention. If you think your patch solve this this issue, I still disagree. but If you think your patch mitigate the pain of this issue, I agree it. I don't have any reason to oppose your first patch.

Quoted 3 lines

One question. Have anyone tested Rafael's $subject patch? Please post test result. if the issue disapper by the patch, we can suppose the slowness is caused by i/o layer.

I did.

Quoted 8 lines
Quoted 5 lines
Quoted 4 lines

As far as I could see, patch does solve the problem I described.

Does it affect speed of suspend? I can't say for sure. It seems to be the same.

Thanks for testing.

I'll test that too, soon.
Just to note that I left my hibernate loop run overnight, and now I am posting from my notebook after it did 590 hibernate cycles.

Did you have a chance to test it?

Quoted 4 lines

Offtopic, but Note that to achieve that I had to stop using global acpi hardware lock. I tried all kinds of things, but for now it just hands from time to time.
See http://bugzilla.kernel.org/show_bug.cgi?id=14668

Quoted 7 lines
Quoted 4 lines

I'm going to look at that later this week, although I'm not sure I can do more than Alex about that.

Rafael

Rafael,
If you can point to where one may insert callback to be called just before handing control to resume kernel, it may help...

Quoted 8 lines

Generally speaking, I'd do that in a .suspend() callback of one of devices.

If that's inconvenient, you can also place it in the .pre_restore() platform hibernate callback (drivers/acpi/sleep.c). It only disables GPEs right now, it might release the global lock as well.

The .pre_restore() callback is executed after all devices have been suspended, so there's no danger any driver would re-acquire the global lock after that.

Quoted 6 lines

Well, I did that very late, very close to image restore. Still, it didn't work (It hung after the resume, in the kernel that was just restored, on access to the hardware lock, or in other words in same way)

Here is what I did:

I saw the patch in the bug entry
(http://bugzilla.kernel.org/show_bug.cgi?id=14668).
Please see the comments in there.

Please also test the patch I attached and let's use the bug entry for the tracking of this issue from now on.

Rafael
_______________________________________________
linux-pm mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/linux-pm

#106 lore raw

Re: [Update][PATCH] MM / PM: Force GFP_NOIO during suspend/hibernation and resume

In reply to Alexey Starikovskiy
Quoted 37 lines · Alexey Starikovskiy

Rafael J. Wysocki пишет:

Quoted 36 lines · Maxim Levitsky
Quoted 19 lines · Rafael J. Wysocki
Quoted 18 lines · Maxim Levitsky
Quoted 17 lines · KOSAKI Motohiro
Quoted 11 lines
Quoted 11 lines
Quoted 5 lines
Quoted 3 lines

Probably we have multiple option. but I don't think GFP_NOIO is good option. It assume the system have lots non-dirty cache memory and it isn't guranteed.

Basically nothing is guaranteed in this case. However, does it actually make things _worse_?

Hmm..
Do you mean we don't need to prevent accidental suspend failure? Perhaps, I did misunderstand your intention. If you think your patch solve this this issue, I still disagree. but If you think your patch mitigate the pain of this issue, I agree it. I don't have any reason to oppose your first patch.

Quoted 3 lines

One question. Have anyone tested Rafael's $subject patch? Please post test result. if the issue disapper by the patch, we can suppose the slowness is caused by i/o layer.

I did.

Quoted 8 lines
Quoted 5 lines
Quoted 4 lines

As far as I could see, patch does solve the problem I described.

Does it affect speed of suspend? I can't say for sure. It seems to be the same.

Thanks for testing.

I'll test that too, soon.
Just to note that I left my hibernate loop run overnight, and now I am posting from my notebook after it did 590 hibernate cycles.

Did you have a chance to test it?

Quoted 4 lines

Offtopic, but Note that to achieve that I had to stop using global acpi hardware lock. I tried all kinds of things, but for now it just hands from time to time.
See http://bugzilla.kernel.org/show_bug.cgi?id=14668

Quoted 7 lines
Quoted 4 lines

I'm going to look at that later this week, although I'm not sure I can do more than Alex about that.

Rafael

Rafael,
If you can point to where one may insert callback to be called just before handing control to resume kernel, it may help...

Generally speaking, I'd do that in a .suspend() callback of one of devices.

If that's inconvenient, you can also place it in the .pre_restore() platform hibernate callback (drivers/acpi/sleep.c). It only disables GPEs right now, it might release the global lock as well.

The .pre_restore() callback is executed after all devices have been suspended, so there's no danger any driver would re-acquire the global lock after that.

Rafael
_______________________________________________
linux-pm mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/linux-pm

#107 lore raw

Re: [Update][PATCH] MM / PM: Force GFP_NOIO during suspend/hibernation and resume

In reply to Maxim Levitsky
Quoted 25 lines · Maxim Levitsky
Quoted 24 lines · Rafael J. Wysocki
Quoted 23 lines · Maxim Levitsky
Quoted 14 lines · KOSAKI Motohiro
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines

Probably we have multiple option. but I don't think GFP_NOIO is good option. It assume the system have lots non-dirty cache memory and it isn't guranteed.

Basically nothing is guaranteed in this case. However, does it actually make things _worse_?

Quoted 6 lines

Hmm..
Do you mean we don't need to prevent accidental suspend failure? Perhaps, I did misunderstand your intention. If you think your patch solve this this issue, I still disagree. but If you think your patch mitigate the pain of this issue, I agree it. I don't have any reason to oppose your first patch.

Quoted 3 lines

One question. Have anyone tested Rafael's $subject patch? Please post test result. if the issue disapper by the patch, we can suppose the slowness is caused by i/o layer.

I did.

As far as I could see, patch does solve the problem I described.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Does it affect speed of suspend? I can't say for sure. It seems to be the same.

Thanks for testing.

I'll test that too, soon.
Just to note that I left my hibernate loop run overnight, and now I am posting from my notebook after it did 590 hibernate cycles.

Did you have a chance to test it?

Quoted 4 lines

Offtopic, but Note that to achieve that I had to stop using global acpi hardware lock. I tried all kinds of things, but for now it just hands from time to time.
See http://bugzilla.kernel.org/show_bug.cgi?id=14668

I'm going to look at that later this week, although I'm not sure I can do more than Alex about that.

Rafael

#108 lore raw

PATCH 1/1 MM / PM: Force GFP_NOIO during suspend/hibernation and resume

In reply to Maxim Levitsky
Quoted 19 lines · Maxim Levitsky
Quoted 14 lines · KOSAKI Motohiro
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines

Probably we have multiple option. but I don't think GFP_NOIO is good option. It assume the system have lots non-dirty cache memory and it isn't guranteed.

Basically nothing is guaranteed in this case. However, does it actually make things _worse_?

Quoted 6 lines

Hmm..
Do you mean we don't need to prevent accidental suspend failure? Perhaps, I did misunderstand your intention. If you think your patch solve this this issue, I still disagree. but If you think your patch mitigate the pain of this issue, I agree it. I don't have any reason to oppose your first patch.

Quoted 3 lines

One question. Have anyone tested Rafael's $subject patch? Please post test result. if the issue disapper by the patch, we can suppose the slowness is caused by i/o layer.

Quoted 6 lines

I did.

As far as I could see, patch does solve the problem I described.

Does it affect speed of suspend? I can't say for sure. It seems to be the same.

Thanks for testing.

Below is a slightly different version of that patch. Can you please give it a try?

Rafael

---
From: Rafael J. Wysocki <[email protected]>
Subject: MM / PM: Force GFP_NOIO during suspend/hibernation and resume

There are quite a few GFP_KERNEL memory allocations made during suspend/hibernation and resume that may cause the system to hang, because the I/O operations they depend on cannot be completed due to the underlying devices being suspended.

Mitigate this problem by clearing the __GFP_IO and __GFP_FS bits in gfp_allowed_mask before suspend/hibernation and restoring the original values of these bits in gfp_allowed_mask durig the subsequent resume.

---
 kernel/power/hibernate.c |    6 ++++++
 kernel/power/power.h     |    3 +++
 kernel/power/suspend.c   |    2 ++
 mm/Makefile              |    1 +
 mm/pm.c                  |   28 ++++++++++++++++++++++++++++
 5 files changed, 40 insertions(+)
kernel/power/hibernate.c +6 -0
Index: linux-2.6/kernel/power/hibernate.c
===================================================================
@@ -334,6 +334,7 @@ int hibernation_snapshot(int platform_mo
 		goto Close;
 
 	suspend_console();
+	mm_force_noio_allocations();
 	error = dpm_suspend_start(PMSG_FREEZE);
 	if (error)
 		goto Recover_platform;
@@ -351,6 +352,7 @@ int hibernation_snapshot(int platform_mo
 
 	dpm_resume_end(in_suspend ?
 		(error ? PMSG_RECOVER : PMSG_THAW) : PMSG_RESTORE);
+	mm_allow_io_allocations();
 	resume_console();
  Close:
 	platform_end(platform_mode);
@@ -448,11 +450,13 @@ int hibernation_restore(int platform_mod
 
 	pm_prepare_console();
 	suspend_console();
+	mm_force_noio_allocations();
 	error = dpm_suspend_start(PMSG_QUIESCE);
 	if (!error) {
 		error = resume_target_kernel(platform_mode);
 		dpm_resume_end(PMSG_RECOVER);
 	}
+	mm_allow_io_allocations();
 	resume_console();
 	pm_restore_console();
 	return error;
@@ -481,6 +485,7 @@ int hibernation_platform_enter(void)
 
 	entering_platform_hibernation = true;
 	suspend_console();
+	mm_force_noio_allocations();
 	error = dpm_suspend_start(PMSG_HIBERNATE);
 	if (error) {
 		if (hibernation_ops->recover)
@@ -518,6 +523,7 @@ int hibernation_platform_enter(void)
  Resume_devices:
 	entering_platform_hibernation = false;
 	dpm_resume_end(PMSG_RESTORE);
+	mm_allow_io_allocations();
 	resume_console();
 
  Close:
kernel/power/power.h +3 -0
Index: linux-2.6/kernel/power/power.h
===================================================================
@@ -187,6 +187,9 @@ static inline void suspend_test_finish(c
 #ifdef CONFIG_PM_SLEEP
 /* kernel/power/main.c */
 extern int pm_notifier_call_chain(unsigned long val);
+/* mm/pm.c */
+extern void mm_force_noio_allocations(void);
+extern void mm_allow_io_allocations(void);
 #endif
 
 #ifdef CONFIG_HIGHMEM
kernel/power/suspend.c +2 -0
Index: linux-2.6/kernel/power/suspend.c
===================================================================
@@ -208,6 +208,7 @@ int suspend_devices_and_enter(suspend_st
 			goto Close;
 	}
 	suspend_console();
+	mm_force_noio_allocations();
 	suspend_test_start();
 	error = dpm_suspend_start(PMSG_SUSPEND);
 	if (error) {
@@ -224,6 +225,7 @@ int suspend_devices_and_enter(suspend_st
 	suspend_test_start();
 	dpm_resume_end(PMSG_RESUME);
 	suspend_test_finish("resume devices");
+	mm_allow_io_allocations();
 	resume_console();
  Close:
 	if (suspend_ops->end)
mm/Makefile +1 -0
Index: linux-2.6/mm/Makefile
===================================================================
@@ -40,3 +40,4 @@ obj-$(CONFIG_MEMORY_FAILURE) += memory-f
 obj-$(CONFIG_HWPOISON_INJECT) += hwpoison-inject.o
 obj-$(CONFIG_DEBUG_KMEMLEAK) += kmemleak.o
 obj-$(CONFIG_DEBUG_KMEMLEAK_TEST) += kmemleak-test.o
+obj-$(CONFIG_PM_SLEEP) += pm.o
mm/pm.c new file +28 -0
Index: linux-2.6/mm/pm.c
===================================================================
@@ -0,0 +1,28 @@
+#include <linux/gfp.h>
+
+static gfp_t saved_gfp_allowed_mask;
+
+#define GFP_IOFS (__GFP_IO | __GFP_FS)
+
+/**
+ * mm_force_noio_allocations - Modify gfp_allowed_mask to disable IO allocations
+ *
+ * Change gfp_allowed_mask by unsetting __GFP_IO and __GFP_FS in it and save the
+ * old value.
+ */
+void mm_force_noio_allocations(void)
+{
+	saved_gfp_allowed_mask = gfp_allowed_mask;
+	gfp_allowed_mask &= ~GFP_IOFS;
+}
+
+/**
+ * mm_allow_io_allocations - Modify gfp_allowed_mask to allow IO allocations
+ *
+ * If the saved value of gfp_allowed_mask has __GFP_IO set, modify the current
+ * gfp_allowed_mask by setting this bit and anlogously for __GFP_FS.
+ */
+void mm_allow_io_allocations(void)
+{
+	gfp_allowed_mask |= saved_gfp_allowed_mask & GFP_IOFS;
+}
#109 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: [linux-pm] Memory allocations in .suspend became very unreliable)

In reply to KOSAKI Motohiro
Quoted 11 lines · KOSAKI Motohiro
Quoted 6 lines
Quoted 3 lines

Probably we have multiple option. but I don't think GFP_NOIO is good option. It assume the system have lots non-dirty cache memory and it isn't guranteed.

Basically nothing is guaranteed in this case. However, does it actually make things _worse_?

Hmm..
Do you mean we don't need to prevent accidental suspend failure? Perhaps, I did misunderstand your intention. If you think your patch solve this this issue, I still disagree.

No, I don't.

Quoted 1 line

but If you think your patch mitigate the pain of this issue, I agree it.

That's what I wanted to say really.

Quoted 1 line

I don't have any reason to oppose your first patch.

Great!

Quoted 12 lines
Quoted 3 lines

What _exactly_ does happen without the $subject patch if the system doesn't have non-dirty cache memory and someone makes a GFP_KERNEL allocation during suspend?

Page allocator prefer to spent lots time for reclaimable memory searching than returning NULL. IOW, it can spent time few second if it doesn't have reclaimable memory.
In typical case, OOM killer forcely make enough free memory if the system don't have any memory. But under suspending time, oom killer is disabled. So, if the caller (probably drivers) call alloc >1000times, the system spent lots seconds.

Quoted 5 lines

In this case, GFP_NOIO doesn't help. slowness behavior is caused by freeable memory search, not slow i/o.

However, if strange i/o device makes any i/o slowness, GFP_NOIO might help. In this case, please don't ask me about i/o thing. I don't know ;)

OK, thanks for the explanation.

Rafael

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#110 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: Memory allocations in .suspend became very unreliable)

In reply to KOSAKI Motohiro
Quoted 11 lines · KOSAKI Motohiro
Quoted 6 lines
Quoted 3 lines

Probably we have multiple option. but I don't think GFP_NOIO is good option. It assume the system have lots non-dirty cache memory and it isn't guranteed.

Basically nothing is guaranteed in this case. However, does it actually make things _worse_?

Hmm..
Do you mean we don't need to prevent accidental suspend failure? Perhaps, I did misunderstand your intention. If you think your patch solve this this issue, I still disagree.

No, I don't.

Quoted 1 line

but If you think your patch mitigate the pain of this issue, I agree it.

That's what I wanted to say really.

Quoted 1 line

I don't have any reason to oppose your first patch.

Great!

Quoted 12 lines
Quoted 3 lines

What _exactly_ does happen without the $subject patch if the system doesn't have non-dirty cache memory and someone makes a GFP_KERNEL allocation during suspend?

Page allocator prefer to spent lots time for reclaimable memory searching than returning NULL. IOW, it can spent time few second if it doesn't have reclaimable memory.
In typical case, OOM killer forcely make enough free memory if the system don't have any memory. But under suspending time, oom killer is disabled. So, if the caller (probably drivers) call alloc >1000times, the system spent lots seconds.

Quoted 5 lines

In this case, GFP_NOIO doesn't help. slowness behavior is caused by freeable memory search, not slow i/o.

However, if strange i/o device makes any i/o slowness, GFP_NOIO might help. In this case, please don't ask me about i/o thing. I don't know ;)

OK, thanks for the explanation.

Rafael

#111 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: Memory allocations in .suspend became very unreliable)

In reply to KOSAKI Motohiro
Quoted 29 lines · KOSAKI Motohiro
Quoted 8 lines
Quoted 3 lines

Hi Rafael,

Do you mean this is the unrelated issue of nVidia bug?

The nvidia driver _is_ buggy, but Maxim said he couldn't reproduce the problem if all the allocations made by the nvidia driver during suspend were changed to GFP_ATOMIC.

Quoted 8 lines
Quoted 2 lines

Probably I haven't catch your point. I don't find Maxim's original bug report. Can we share the test-case and your analysis detail?

The Maxim's original report is here:
https://lists.linux-foundation.org/pipermail/linux-pm/2010-January/023982.html

and the message I'm referring to is at:
https://lists.linux-foundation.org/pipermail/linux-pm/2010-January/023990.html

Hmmm...

Usually, Increasing I/O isn't caused MM change. either subsystem change memory alloc/free pattern and another subsystem receive such effect ;) I don't think this message indicate MM fault.

And, 2.6.33 MM change is not much. if the fault is in MM change (note: my guess is no), The most doubtful patch is my "killing shrink_all_zones" patch. If old shrink_all_zones reclaimed memory much rather than required. The patch fixed it. IOW, the patch can reduce available free memory to be used buggy .suspend of the driver. but I don't think it is MM fault.

Quoted 6 lines

As I said, drivers can't use memory freely as their demand in suspend method. It's obvious. They should stop such unrealistic assumption. but How should we fix this?
- Gurantee suspend I/O device at last?
- Make much much free memory before calling .suspend method? even though typical drivers don't need.

That doesn't help already. Maxim tried to increase SPARE_PAGES (in kernel/power/power.h) and that had no effect.

Quoted 2 lines

- Ask all drivers how much they require memory before starting suspend and Make enough free memory at first?

That's equivalent to reworking all drivers to allocate memory before suspend eg. with the help of PM notifiers. Which IMHO is unrealistic.

Quoted 1 line

- Or, do we have an alternative way?

The $subject patch?

Quoted 3 lines

Probably we have multiple option. but I don't think GFP_NOIO is good option. It assume the system have lots non-dirty cache memory and it isn't guranteed.

Basically nothing is guaranteed in this case. However, does it actually make things _worse_? What _exactly_ does happen without the $subject patch if the system doesn't have non-dirty cache memory and someone makes a GFP_KERNEL allocation during suspend?

Rafael

#112 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: Memory allocations in .suspend became very unreliable)

In reply to KOSAKI Motohiro
Quoted 43 lines · KOSAKI Motohiro
Quoted 36 lines · Benjamin Herrenschmidt
Quoted 20 lines · KOSAKI Motohiro
Quoted 10 lines

I think the race happen itself is bad. memory and I/O subsystem can't solve such race elegantly. These doesn't know enough suspend state knowlege. I think the practical solution is that higher level design prevent the race happen.

Quoted 3 lines

My patch attempts to avoid these two problems as well as the problem with drivers using GFP_KERNEL allocations during suspend which I admit might be solved by reworking the drivers.

Agreed. In this case, only drivers change can solve the issue.

As I explained earlier, this is near to impossible since the allocations are too often burried deep down the call stack or simply because the driver doesn't know that we started suspending -another- driver...

I don't think trying to solve those problems at the driver level is realistic to be honest. This is one of those things where we really just need to make allocators 'just work' from a driver perspective.

Quoted 7 lines

It can't be perfect of course, as mentioned earlier, there will be a problem if too little free memory is really available due to lots of dirty pages around, but most of this can be somewhat alleviated in practice, for example by pushing things out a bit at suspend time, making some more memory free etc... But yeah, nothing replaces proper error handling in drivers for allocation failures even with GFP_KERNEL :-)

Agreed.

Moreover, I didn't try to do anything about that before, because memory allocation problems during suspend/resume just didn't happen. We kind of knew they were possible, but since they didn't show up, it wasn't immediately necessary to address them.

Quoted 6 lines

Now, however, people started to see these problems in testing and I'm quite confident that this is a result of recent changes in the mm subsystem. Namely, if you read the Maxim's report carefully, you'll notice that in his test case the mm subsystem apparently attempted to use I/O even though there was free memory available in the system. This is the case I want to prevent from happening in the first place.

Quoted 3 lines

Hi Rafael,

Do you mean this is the unrelated issue of nVidia bug?

The nvidia driver _is_ buggy, but Maxim said he couldn't reproduce the problem if all the allocations made by the nvidia driver during suspend were changed to GFP_ATOMIC.

Quoted 2 lines

Probably I haven't catch your point. I don't find Maxim's original bug report. Can we share the test-case and your analysis detail?

The Maxim's original report is here:
https://lists.linux-foundation.org/pipermail/linux-pm/2010-January/023982.html

and the message I'm referring to is at:
https://lists.linux-foundation.org/pipermail/linux-pm/2010-January/023990.html

Thanks,
Rafael

#113 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: Memory allocations in .suspend became very unreliable)

In reply to KOSAKI Motohiro
Quoted 43 lines · KOSAKI Motohiro
Quoted 36 lines · Benjamin Herrenschmidt
Quoted 20 lines · KOSAKI Motohiro
Quoted 10 lines

I think the race happen itself is bad. memory and I/O subsystem can't solve such race elegantly. These doesn't know enough suspend state knowlege. I think the practical solution is that higher level design prevent the race happen.

Quoted 3 lines

My patch attempts to avoid these two problems as well as the problem with drivers using GFP_KERNEL allocations during suspend which I admit might be solved by reworking the drivers.

Agreed. In this case, only drivers change can solve the issue.

As I explained earlier, this is near to impossible since the allocations are too often burried deep down the call stack or simply because the driver doesn't know that we started suspending -another- driver...

I don't think trying to solve those problems at the driver level is realistic to be honest. This is one of those things where we really just need to make allocators 'just work' from a driver perspective.

Quoted 7 lines

It can't be perfect of course, as mentioned earlier, there will be a problem if too little free memory is really available due to lots of dirty pages around, but most of this can be somewhat alleviated in practice, for example by pushing things out a bit at suspend time, making some more memory free etc... But yeah, nothing replaces proper error handling in drivers for allocation failures even with GFP_KERNEL :-)

Agreed.

Moreover, I didn't try to do anything about that before, because memory allocation problems during suspend/resume just didn't happen. We kind of knew they were possible, but since they didn't show up, it wasn't immediately necessary to address them.

Quoted 6 lines

Now, however, people started to see these problems in testing and I'm quite confident that this is a result of recent changes in the mm subsystem. Namely, if you read the Maxim's report carefully, you'll notice that in his test case the mm subsystem apparently attempted to use I/O even though there was free memory available in the system. This is the case I want to prevent from happening in the first place.

Quoted 3 lines

Hi Rafael,

Do you mean this is the unrelated issue of nVidia bug?

The nvidia driver _is_ buggy, but Maxim said he couldn't reproduce the problem if all the allocations made by the nvidia driver during suspend were changed to GFP_ATOMIC.

Quoted 2 lines

Probably I haven't catch your point. I don't find Maxim's original bug report. Can we share the test-case and your analysis detail?

The Maxim's original report is here:
https://lists.linux-foundation.org/pipermail/linux-pm/2010-January/023982.html

and the message I'm referring to is at:
https://lists.linux-foundation.org/pipermail/linux-pm/2010-January/023990.html

Thanks,
Rafael

#114 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: Memory allocations in .suspend became very unreliable)

In reply to Benjamin Herrenschmidt
Quoted 20 lines · Benjamin Herrenschmidt
Quoted 10 lines · KOSAKI Motohiro

I think the race happen itself is bad. memory and I/O subsystem can't solve such race elegantly. These doesn't know enough suspend state knowlege. I think the practical solution is that higher level design prevent the race happen.

Quoted 3 lines

My patch attempts to avoid these two problems as well as the problem with drivers using GFP_KERNEL allocations during suspend which I admit might be solved by reworking the drivers.

Agreed. In this case, only drivers change can solve the issue.

As I explained earlier, this is near to impossible since the allocations are too often burried deep down the call stack or simply because the driver doesn't know that we started suspending -another- driver...

I don't think trying to solve those problems at the driver level is realistic to be honest. This is one of those things where we really just need to make allocators 'just work' from a driver perspective.

Quoted 7 lines

It can't be perfect of course, as mentioned earlier, there will be a problem if too little free memory is really available due to lots of dirty pages around, but most of this can be somewhat alleviated in practice, for example by pushing things out a bit at suspend time, making some more memory free etc... But yeah, nothing replaces proper error handling in drivers for allocation failures even with GFP_KERNEL :-)

Agreed.

Moreover, I didn't try to do anything about that before, because memory allocation problems during suspend/resume just didn't happen. We kind of knew they were possible, but since they didn't show up, it wasn't immediately necessary to address them.

Now, however, people started to see these problems in testing and I'm quite confident that this is a result of recent changes in the mm subsystem. Namely, if you read the Maxim's report carefully, you'll notice that in his test case the mm subsystem apparently attempted to use I/O even though there was free memory available in the system. This is the case I want to prevent from happening in the first place.

Rafael

#115 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: Memory allocations in .suspend became very unreliable)

In reply to KOSAKI Motohiro
Quoted 60 lines · KOSAKI Motohiro
Quoted 60 lines

Hi,

I thing the snippet below is a good summary of what this is about.

Quoted 27 lines · Rafael J. Wysocki
Quoted 26 lines · Maxim Levitsky
Quoted 25 lines · Rafael J. Wysocki
Quoted 23 lines · Maxim Levitsky
Quoted 15 lines · Rafael J. Wysocki
Quoted 1 line · Maxim Levitsky

Hi,

Hi,

Quoted 9 lines

I know that this is very controversial, because here I want to describe a problem in a proprietary driver that happens now in 2.6.33-rc3 I am taking about nvidia driver.

Some time ago I did very long hibernate test and found no errors after more that 200 cycles.

Now I update to 2.6.33 and notice that system will hand when nvidia driver allocates memory is their .suspend functions.

Quoted 6 lines

They shouldn't do that, there's no guarantee that's going to work at all.

Quoted 2 lines

This could fail in 2.6.32 if I would run many memory hungry applications, but now this happens with most of memory free.

This sounds a little strange. What's the requested size of the image?

Don't know, but system has to be very tight on memory.

Quoted 8 lines
Quoted 8 lines
Quoted 1 line

Can you send full dmesg, please?

I deleted it, but for this case I think that hang was somewhere else. This task was hand on doing forking, which probably happened even before the freezer.

Anyway, the problem is clear. Now __get_free_pages blocks more often, and can block in .suspend even if there is plenty of memory free.

This is suspicious, but I leave it to the MM people for consideration.

Quoted 5 lines
Quoted 4 lines

I now patched nvidia to use GFP_ATOMIC _always_, and problem disappear. It isn't such great solution when memory is tight though....

This is going to hit hard all nvidia users...

Quoted 7 lines

Well, generally speaking, no driver should ever allocate memory using GFP_KERNEL in its .suspend() routine, because that's not going to work, as you can readily see. So this is a NVidia bug, hands down.

Now having said that, we've been considering a change that will turn all GFP_KERNEL allocations into GFP_NOIO during suspend/resume, so perhaps I'll prepare a patch to do that and let's see what people think.

If I didn't confuse anything (which is likely, because it's a bit late here now), the patch below should do the trick. I have only checked that it doesn't break compilation, so please take it with a grain of salt.

Quoted 7 lines
Quoted 1 line

Comments welcome.

Hmm..
I don't think this is good idea.

GFP_NOIO mean "Please don't reclaim if the page is dirty". It mean the system have lots dirty pages, this patch might makes hung up.

The point is to prevent the mm subsystem from using I/O. If there's a better way, please tell me. :-)

Quoted 2 lines

If suspend need lots memory, we need to make free memory before starting IO suspending, I think.

Suspend as such doesn't need a lot of memory, except for some drivers doing things they shouldn't do.

However, there are a few problems that need to be addressed in general.

First, we can't really guarantee that there's a lot of free memory available during suspend and some memory allocations are done indirectly, using GFP_KERNEL (for example, when new kernel threads are started). If one of these is done during suspend and it happens to cause the mm subsystem to start I/O on a suspended devices, the kernel will lock up.

Second, there may be a memory allocation in progress when suspend is started that causes I/O to happen and races with the suspend process. If the latter wins the race, the I/O may be attempted on a suspended device and the kernel will lock up.

My patch attempts to avoid these two problems as well as the problem with drivers using GFP_KERNEL allocations during suspend which I admit might be solved by reworking the drivers.

Thanks,
Rafael

#116 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: Memory allocations in .suspend became very unreliable)

In reply to Rafael J. Wysocki
Quoted 3 lines · Rafael J. Wysocki

Hi,

I thing the snippet below is a good summary of what this is about.

Any progress on that?

Best regards,
Maxim Levitsky

#117 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: [linux-pm] Memory allocations in .suspend became very unreliable)

In reply to Rafael J. Wysocki
Quoted 3 lines · Rafael J. Wysocki

Hi,

I thing the snippet below is a good summary of what this is about.

Any progress on that?

Best regards,
Maxim Levitsky

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#118 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: [linux-pm] Memory allocations in .suspend became very unreliable)

Quoted 6 lines · Maxim Levitsky
Quoted 3 lines · Rafael J. Wysocki

Hi,

I thing the snippet below is a good summary of what this is about.

Any progress on that?

Well, I'm waiting for you to report back:
http://patchwork.kernel.org/patch/74740/

The patch is appended once again for convenience.

Rafael

---
From: Rafael J. Wysocki <[email protected]>
Subject: MM / PM: Force GFP_NOIO during suspend/hibernation and resume

There are quite a few GFP_KERNEL memory allocations made during suspend/hibernation and resume that may cause the system to hang, because the I/O operations they depend on cannot be completed due to the underlying devices being suspended.

Avoid this problem by clearing the __GFP_IO and __GFP_FS bits in gfp_allowed_mask before suspend/hibernation and restoring the original values of these bits in gfp_allowed_mask durig the subsequent resume.

---
 kernel/power/hibernate.c |    6 ++++++
 kernel/power/power.h     |    3 +++
 kernel/power/suspend.c   |    2 ++
 mm/Makefile              |    1 +
 mm/pm.c                  |   28 ++++++++++++++++++++++++++++
 5 files changed, 40 insertions(+)
kernel/power/hibernate.c +6 -0
Index: linux-2.6/kernel/power/hibernate.c
===================================================================
@@ -334,6 +334,7 @@ int hibernation_snapshot(int platform_mo
 		goto Close;
 
 	suspend_console();
+	mm_force_noio_allocations();
 	error = dpm_suspend_start(PMSG_FREEZE);
 	if (error)
 		goto Recover_platform;
@@ -351,6 +352,7 @@ int hibernation_snapshot(int platform_mo
 
 	dpm_resume_end(in_suspend ?
 		(error ? PMSG_RECOVER : PMSG_THAW) : PMSG_RESTORE);
+	mm_allow_io_allocations();
 	resume_console();
  Close:
 	platform_end(platform_mode);
@@ -448,11 +450,13 @@ int hibernation_restore(int platform_mod
 
 	pm_prepare_console();
 	suspend_console();
+	mm_force_noio_allocations();
 	error = dpm_suspend_start(PMSG_QUIESCE);
 	if (!error) {
 		error = resume_target_kernel(platform_mode);
 		dpm_resume_end(PMSG_RECOVER);
 	}
+	mm_allow_io_allocations();
 	resume_console();
 	pm_restore_console();
 	return error;
@@ -481,6 +485,7 @@ int hibernation_platform_enter(void)
 
 	entering_platform_hibernation = true;
 	suspend_console();
+	mm_force_noio_allocations();
 	error = dpm_suspend_start(PMSG_HIBERNATE);
 	if (error) {
 		if (hibernation_ops->recover)
@@ -518,6 +523,7 @@ int hibernation_platform_enter(void)
  Resume_devices:
 	entering_platform_hibernation = false;
 	dpm_resume_end(PMSG_RESTORE);
+	mm_allow_io_allocations();
 	resume_console();
 
  Close:
kernel/power/power.h +3 -0
Index: linux-2.6/kernel/power/power.h
===================================================================
@@ -187,6 +187,9 @@ static inline void suspend_test_finish(c
 #ifdef CONFIG_PM_SLEEP
 /* kernel/power/main.c */
 extern int pm_notifier_call_chain(unsigned long val);
+/* mm/pm.c */
+extern void mm_force_noio_allocations(void);
+extern void mm_allow_io_allocations(void);
 #endif
 
 #ifdef CONFIG_HIGHMEM
kernel/power/suspend.c +2 -0
Index: linux-2.6/kernel/power/suspend.c
===================================================================
@@ -208,6 +208,7 @@ int suspend_devices_and_enter(suspend_st
 			goto Close;
 	}
 	suspend_console();
+	mm_force_noio_allocations();
 	suspend_test_start();
 	error = dpm_suspend_start(PMSG_SUSPEND);
 	if (error) {
@@ -224,6 +225,7 @@ int suspend_devices_and_enter(suspend_st
 	suspend_test_start();
 	dpm_resume_end(PMSG_RESUME);
 	suspend_test_finish("resume devices");
+	mm_allow_io_allocations();
 	resume_console();
  Close:
 	if (suspend_ops->end)
mm/Makefile +1 -0
Index: linux-2.6/mm/Makefile
===================================================================
@@ -40,3 +40,4 @@ obj-$(CONFIG_MEMORY_FAILURE) += memory-f
 obj-$(CONFIG_HWPOISON_INJECT) += hwpoison-inject.o
 obj-$(CONFIG_DEBUG_KMEMLEAK) += kmemleak.o
 obj-$(CONFIG_DEBUG_KMEMLEAK_TEST) += kmemleak-test.o
+obj-$(CONFIG_PM_SLEEP) += pm.o
mm/pm.c new file +28 -0
Index: linux-2.6/mm/pm.c
===================================================================
@@ -0,0 +1,28 @@
+#include <linux/gfp.h>
+
+static gfp_t saved_gfp_allowed_mask;
+
+#define GFP_IOFS (__GFP_IO | __GFP_FS)
+
+/**
+ * mm_force_noio_allocations - Modify gfp_allowed_mask to disable IO allocations
+ *
+ * Change gfp_allowed_mask by unsetting __GFP_IO and __GFP_FS in it and save the
+ * old value.
+ */
+void mm_force_noio_allocations(void)
+{
+	saved_gfp_allowed_mask = gfp_allowed_mask;
+	gfp_allowed_mask &= ~GFP_IOFS;
+}
+
+/**
+ * mm_allow_io_allocations - Modify gfp_allowed_mask to allow IO allocations
+ *
+ * If the saved value of gfp_allowed_mask has __GFP_IO set, modify the current
+ * gfp_allowed_mask by setting this bit and anlogously for __GFP_FS.
+ */
+void mm_allow_io_allocations(void)
+{
+	gfp_allowed_mask |= saved_gfp_allowed_mask & GFP_IOFS;
+}
#119 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: Memory allocations in .suspend became very unreliable)

Quoted 4 lines · Rafael J. Wysocki
Quoted 3 lines · Maxim Levitsky
Quoted 2 lines · Rafael J. Wysocki

Hi,

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

I thing the snippet below is a good summary of what this is about.

Any progress on that?

Well, I'm waiting for you to report back:
http://patchwork.kernel.org/patch/74740/

The patch is appended once again for convenience.

Ah, sorry!

I used the second version (with the locks) and it works for sure (~500 cycles)

However, as I discovered today, it takes the lock also for GFP_ATOMIC, and thats why I see several backtraces in the kernel log. Anyway this isn't important.

I forgot all about this patch, and I am compiling the kernel right away. Will put the kernel through the hibernate loop tonight.

Best regards,
Maxim Levitsky

#120 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: [linux-pm] Memory allocations in .suspend became very unreliable)

In reply to Rafael J. Wysocki
Quoted 4 lines · Rafael J. Wysocki
Quoted 3 lines · Maxim Levitsky
Quoted 2 lines · Rafael J. Wysocki

Hi,

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

I thing the snippet below is a good summary of what this is about.

Any progress on that?

Well, I'm waiting for you to report back:
http://patchwork.kernel.org/patch/74740/

The patch is appended once again for convenience.

Ah, sorry!

I used the second version (with the locks) and it works for sure (~500 cycles)

However, as I discovered today, it takes the lock also for GFP_ATOMIC, and thats why I see several backtraces in the kernel log. Anyway this isn't important.

I forgot all about this patch, and I am compiling the kernel right away. Will put the kernel through the hibernate loop tonight.

Best regards,
Maxim Levitsky

#121 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: Memory allocations in .suspend became very unreliable)

Quoted 19 lines · Maxim Levitsky
Quoted 4 lines · Rafael J. Wysocki
Quoted 3 lines · Maxim Levitsky
Quoted 2 lines · Rafael J. Wysocki

Hi,

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

I thing the snippet below is a good summary of what this is about.

Any progress on that?

Well, I'm waiting for you to report back:
http://patchwork.kernel.org/patch/74740/

The patch is appended once again for convenience.

Ah, sorry!

I used the second version (with the locks) and it works for sure (~500 cycles)

Quoted 6 lines

However, as I discovered today, it takes the lock also for GFP_ATOMIC, and thats why I see several backtraces in the kernel log. Anyway this isn't important.

I forgot all about this patch, and I am compiling the kernel right away. Will put the kernel through the hibernate loop tonight.

I did 123 hibernate cycles on my notebook. Everything is fine. This patch very very likely is working.

Best regards,
Maxim Levitsky

#122 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: [linux-pm] Memory allocations in .suspend became very unreliable)

In reply to Maxim Levitsky
Quoted 19 lines · Maxim Levitsky
Quoted 4 lines · Rafael J. Wysocki
Quoted 3 lines · Maxim Levitsky
Quoted 2 lines · Rafael J. Wysocki

Hi,

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

I thing the snippet below is a good summary of what this is about.

Any progress on that?

Well, I'm waiting for you to report back:
http://patchwork.kernel.org/patch/74740/

The patch is appended once again for convenience.

Ah, sorry!

I used the second version (with the locks) and it works for sure (~500 cycles)

Quoted 6 lines

However, as I discovered today, it takes the lock also for GFP_ATOMIC, and thats why I see several backtraces in the kernel log. Anyway this isn't important.

I forgot all about this patch, and I am compiling the kernel right away. Will put the kernel through the hibernate loop tonight.

I did 123 hibernate cycles on my notebook. Everything is fine. This patch very very likely is working.

Best regards,
Maxim Levitsky

#123 lore raw

Re: [RFC][PATCH] PM: Force GFP_NOIO during suspend/resume (was: Re: Memory allocations in .suspend became very unreliable)

In reply to Maxim Levitsky
Quoted 6 lines · Maxim Levitsky
Quoted 3 lines · Rafael J. Wysocki

Hi,

I thing the snippet below is a good summary of what this is about.

Any progress on that?

Well, I'm waiting for you to report back:
http://patchwork.kernel.org/patch/74740/

The patch is appended once again for convenience.

Rafael

---
From: Rafael J. Wysocki <[email protected]>
Subject: MM / PM: Force GFP_NOIO during suspend/hibernation and resume

There are quite a few GFP_KERNEL memory allocations made during suspend/hibernation and resume that may cause the system to hang, because the I/O operations they depend on cannot be completed due to the underlying devices being suspended.

Avoid this problem by clearing the __GFP_IO and __GFP_FS bits in gfp_allowed_mask before suspend/hibernation and restoring the original values of these bits in gfp_allowed_mask durig the subsequent resume.

---
 kernel/power/hibernate.c |    6 ++++++
 kernel/power/power.h     |    3 +++
 kernel/power/suspend.c   |    2 ++
 mm/Makefile              |    1 +
 mm/pm.c                  |   28 ++++++++++++++++++++++++++++
 5 files changed, 40 insertions(+)
kernel/power/hibernate.c +6 -0
Index: linux-2.6/kernel/power/hibernate.c
===================================================================
@@ -334,6 +334,7 @@ int hibernation_snapshot(int platform_mo
 		goto Close;
 
 	suspend_console();
+	mm_force_noio_allocations();
 	error = dpm_suspend_start(PMSG_FREEZE);
 	if (error)
 		goto Recover_platform;
@@ -351,6 +352,7 @@ int hibernation_snapshot(int platform_mo
 
 	dpm_resume_end(in_suspend ?
 		(error ? PMSG_RECOVER : PMSG_THAW) : PMSG_RESTORE);
+	mm_allow_io_allocations();
 	resume_console();
  Close:
 	platform_end(platform_mode);
@@ -448,11 +450,13 @@ int hibernation_restore(int platform_mod
 
 	pm_prepare_console();
 	suspend_console();
+	mm_force_noio_allocations();
 	error = dpm_suspend_start(PMSG_QUIESCE);
 	if (!error) {
 		error = resume_target_kernel(platform_mode);
 		dpm_resume_end(PMSG_RECOVER);
 	}
+	mm_allow_io_allocations();
 	resume_console();
 	pm_restore_console();
 	return error;
@@ -481,6 +485,7 @@ int hibernation_platform_enter(void)
 
 	entering_platform_hibernation = true;
 	suspend_console();
+	mm_force_noio_allocations();
 	error = dpm_suspend_start(PMSG_HIBERNATE);
 	if (error) {
 		if (hibernation_ops->recover)
@@ -518,6 +523,7 @@ int hibernation_platform_enter(void)
  Resume_devices:
 	entering_platform_hibernation = false;
 	dpm_resume_end(PMSG_RESTORE);
+	mm_allow_io_allocations();
 	resume_console();
 
  Close:
kernel/power/power.h +3 -0
Index: linux-2.6/kernel/power/power.h
===================================================================
@@ -187,6 +187,9 @@ static inline void suspend_test_finish(c
 #ifdef CONFIG_PM_SLEEP
 /* kernel/power/main.c */
 extern int pm_notifier_call_chain(unsigned long val);
+/* mm/pm.c */
+extern void mm_force_noio_allocations(void);
+extern void mm_allow_io_allocations(void);
 #endif
 
 #ifdef CONFIG_HIGHMEM
kernel/power/suspend.c +2 -0
Index: linux-2.6/kernel/power/suspend.c
===================================================================
@@ -208,6 +208,7 @@ int suspend_devices_and_enter(suspend_st
 			goto Close;
 	}
 	suspend_console();
+	mm_force_noio_allocations();
 	suspend_test_start();
 	error = dpm_suspend_start(PMSG_SUSPEND);
 	if (error) {
@@ -224,6 +225,7 @@ int suspend_devices_and_enter(suspend_st
 	suspend_test_start();
 	dpm_resume_end(PMSG_RESUME);
 	suspend_test_finish("resume devices");
+	mm_allow_io_allocations();
 	resume_console();
  Close:
 	if (suspend_ops->end)
mm/Makefile +1 -0
Index: linux-2.6/mm/Makefile
===================================================================
@@ -40,3 +40,4 @@ obj-$(CONFIG_MEMORY_FAILURE) += memory-f
 obj-$(CONFIG_HWPOISON_INJECT) += hwpoison-inject.o
 obj-$(CONFIG_DEBUG_KMEMLEAK) += kmemleak.o
 obj-$(CONFIG_DEBUG_KMEMLEAK_TEST) += kmemleak-test.o
+obj-$(CONFIG_PM_SLEEP) += pm.o
mm/pm.c new file +28 -0
Index: linux-2.6/mm/pm.c
===================================================================
@@ -0,0 +1,28 @@
+#include <linux/gfp.h>
+
+static gfp_t saved_gfp_allowed_mask;
+
+#define GFP_IOFS (__GFP_IO | __GFP_FS)
+
+/**
+ * mm_force_noio_allocations - Modify gfp_allowed_mask to disable IO allocations
+ *
+ * Change gfp_allowed_mask by unsetting __GFP_IO and __GFP_FS in it and save the
+ * old value.
+ */
+void mm_force_noio_allocations(void)
+{
+	saved_gfp_allowed_mask = gfp_allowed_mask;
+	gfp_allowed_mask &= ~GFP_IOFS;
+}
+
+/**
+ * mm_allow_io_allocations - Modify gfp_allowed_mask to allow IO allocations
+ *
+ * If the saved value of gfp_allowed_mask has __GFP_IO set, modify the current
+ * gfp_allowed_mask by setting this bit and anlogously for __GFP_FS.
+ */
+void mm_allow_io_allocations(void)
+{
+	gfp_allowed_mask |= saved_gfp_allowed_mask & GFP_IOFS;
+}
#124 lore raw

RFC PATCH 1/1 PM: Force GFP_NOIO during suspend/resume (was: Re: Memory allocations in .suspend became very unreliable)

In reply to Rafael J. Wysocki

Hi,

I thing the snippet below is a good summary of what this is about.

Quoted 27 lines · Rafael J. Wysocki
Quoted 26 lines · Maxim Levitsky
Quoted 25 lines · Rafael J. Wysocki
Quoted 23 lines · Maxim Levitsky
Quoted 15 lines · Rafael J. Wysocki
Quoted 1 line · Maxim Levitsky

Hi,

Hi,

Quoted 9 lines

I know that this is very controversial, because here I want to describe a problem in a proprietary driver that happens now in 2.6.33-rc3 I am taking about nvidia driver.

Some time ago I did very long hibernate test and found no errors after more that 200 cycles.

Now I update to 2.6.33 and notice that system will hand when nvidia driver allocates memory is their .suspend functions.

Quoted 6 lines

They shouldn't do that, there's no guarantee that's going to work at all.

Quoted 2 lines

This could fail in 2.6.32 if I would run many memory hungry applications, but now this happens with most of memory free.

This sounds a little strange. What's the requested size of the image?

Don't know, but system has to be very tight on memory.

Quoted 8 lines
Quoted 8 lines
Quoted 1 line

Can you send full dmesg, please?

I deleted it, but for this case I think that hang was somewhere else. This task was hand on doing forking, which probably happened even before the freezer.

Anyway, the problem is clear. Now __get_free_pages blocks more often, and can block in .suspend even if there is plenty of memory free.

This is suspicious, but I leave it to the MM people for consideration.

Quoted 5 lines
Quoted 4 lines

I now patched nvidia to use GFP_ATOMIC _always_, and problem disappear. It isn't such great solution when memory is tight though....

This is going to hit hard all nvidia users...

Quoted 7 lines

Well, generally speaking, no driver should ever allocate memory using GFP_KERNEL in its .suspend() routine, because that's not going to work, as you can readily see. So this is a NVidia bug, hands down.

Now having said that, we've been considering a change that will turn all GFP_KERNEL allocations into GFP_NOIO during suspend/resume, so perhaps I'll prepare a patch to do that and let's see what people think.

If I didn't confuse anything (which is likely, because it's a bit late here now), the patch below should do the trick. I have only checked that it doesn't break compilation, so please take it with a grain of salt.

Comments welcome.

Rafael

---
 include/linux/gfp.h      |    5 +++++
 kernel/power/hibernate.c |    6 ++++++
 kernel/power/main.c      |   30 ++++++++++++++++++++++++++++++
 kernel/power/power.h     |    2 ++
 kernel/power/suspend.c   |    2 ++
 5 files changed, 45 insertions(+)
include/linux/gfp.h +5 -0
Index: linux-2.6/include/linux/gfp.h
===================================================================
@@ -342,4 +342,9 @@ static inline void set_gfp_allowed_mask(
 	gfp_allowed_mask = mask;
 }
 
+static inline gfp_t get_gfp_allowed_mask(void)
+{
+	return gfp_allowed_mask;
+}
+
 #endif /* __LINUX_GFP_H */
kernel/power/hibernate.c +6 -0
Index: linux-2.6/kernel/power/hibernate.c
===================================================================
@@ -334,6 +334,7 @@ int hibernation_snapshot(int platform_mo
 		goto Close;
 
 	suspend_console();
+	pm_force_noio_allocations();
 	error = dpm_suspend_start(PMSG_FREEZE);
 	if (error)
 		goto Recover_platform;
@@ -351,6 +352,7 @@ int hibernation_snapshot(int platform_mo
 
 	dpm_resume_end(in_suspend ?
 		(error ? PMSG_RECOVER : PMSG_THAW) : PMSG_RESTORE);
+	pm_allow_io_allocations();
 	resume_console();
  Close:
 	platform_end(platform_mode);
@@ -448,11 +450,13 @@ int hibernation_restore(int platform_mod
 
 	pm_prepare_console();
 	suspend_console();
+	pm_force_noio_allocations();
 	error = dpm_suspend_start(PMSG_QUIESCE);
 	if (!error) {
 		error = resume_target_kernel(platform_mode);
 		dpm_resume_end(PMSG_RECOVER);
 	}
+	pm_allow_io_allocations();
 	resume_console();
 	pm_restore_console();
 	return error;
@@ -481,6 +485,7 @@ int hibernation_platform_enter(void)
 
 	entering_platform_hibernation = true;
 	suspend_console();
+	pm_force_noio_allocations();
 	error = dpm_suspend_start(PMSG_HIBERNATE);
 	if (error) {
 		if (hibernation_ops->recover)
@@ -518,6 +523,7 @@ int hibernation_platform_enter(void)
  Resume_devices:
 	entering_platform_hibernation = false;
 	dpm_resume_end(PMSG_RESTORE);
+	pm_allow_io_allocations();
 	resume_console();
 
  Close:
kernel/power/power.h +2 -0
Index: linux-2.6/kernel/power/power.h
===================================================================
@@ -187,6 +187,8 @@ static inline void suspend_test_finish(c
 #ifdef CONFIG_PM_SLEEP
 /* kernel/power/main.c */
 extern int pm_notifier_call_chain(unsigned long val);
+extern void pm_force_noio_allocations(void);
+extern void pm_allow_io_allocations(void);
 #endif
 
 #ifdef CONFIG_HIGHMEM
kernel/power/suspend.c +2 -0
Index: linux-2.6/kernel/power/suspend.c
===================================================================
@@ -208,6 +208,7 @@ int suspend_devices_and_enter(suspend_st
 			goto Close;
 	}
 	suspend_console();
+	pm_force_noio_allocations();
 	suspend_test_start();
 	error = dpm_suspend_start(PMSG_SUSPEND);
 	if (error) {
@@ -224,6 +225,7 @@ int suspend_devices_and_enter(suspend_st
 	suspend_test_start();
 	dpm_resume_end(PMSG_RESUME);
 	suspend_test_finish("resume devices");
+	pm_allow_io_allocations();
 	resume_console();
  Close:
 	if (suspend_ops->end)
kernel/power/main.c +30 -0
Index: linux-2.6/kernel/power/main.c
===================================================================
@@ -12,6 +12,7 @@
 #include <linux/string.h>
 #include <linux/resume-trace.h>
 #include <linux/workqueue.h>
+#include <linux/gfp.h>
 
 #include "power.h"
 
@@ -22,6 +23,35 @@ EXPORT_SYMBOL(pm_flags);
 
 #ifdef CONFIG_PM_SLEEP
 
+static gfp_t saved_gfp_allowed_mask;
+
+/**
+ * pm_force_noio_allocations - Modify gfp_allowed_mask to disable IO allocations
+ *
+ * Change gfp_allowed_mask by unsetting __GFP_IO and __GFP_FS in it and save the
+ * old value.
+ */
+void pm_force_noio_allocations(void)
+{
+	saved_gfp_allowed_mask = get_gfp_allowed_mask();
+	set_gfp_allowed_mask(saved_gfp_allowed_mask & ~(__GFP_IO | __GFP_FS));
+}
+
+/**
+ * pm_allow_io_allocations - Modify gfp_allowed_mask to allow IO allocations
+ *
+ * If the saved value of gfp_allowed_mask has __GFP_IO set, modify the current
+ * gfp_allowed_mask by setting this bit and anlogously for __GFP_FS.
+ */
+void pm_allow_io_allocations(void)
+{
+	gfp_t gfp_mask;
+
+	gfp_mask = get_gfp_allowed_mask();
+	gfp_mask |= saved_gfp_allowed_mask & (__GFP_IO | __GFP_FS);
+	set_gfp_allowed_mask(gfp_mask);
+}
+
 /* Routines for PM-transition notifications */
 
 static BLOCKING_NOTIFIER_HEAD(pm_chain_head);