WARNINGs in set_task_reclaim_state with memory cgroup and fullmemory usage
Subsystems (4)
Quoted 93 lines · On Sat, 24 Aug 2019 11:36:31 +0800 Yafang Shao wrote:
Quoted 88 lines · Hillf Danton
Quoted 7 lines · On Fri, 23 Aug 2019 18:00:15 -0400 Adric Blake wrote:
Synopsis:
AWARN_ON_ONCEis hit twice inset_task_reclaim_stateunder the following conditions:
- a memory cgroup has been created and a task assigned it it
- memory.limit_in_bytes has been set
- memory has filled up, likely from cacheThanks for report.
Quoted 69 lines
In my usage, I create a cgroup under the current session scope and assign a task to it. I then set memory.limit_in_bytes and memory.soft_limit_in_bytes for the cgroup to reasonable values, say 1G/512M. The program accesses large files frequently and gradually fills memory with the page cache. The warnings appears when the entirety of the system memory is filled, presumably from other programs.
If I wait until the program has filled the entirety of system memory with cache and then assign a memory limit, the warnings appear immediately.
I am building the linux git. I first noticed this issue with the drm-tip 5.3rc3 and 5.3rc4 kernels, and tested linux master after 5.3rc5 to confirm the bug more resoundingly.
Here are the warnings.
[38491.963105] WARNING: CPU: 7 PID: 175 at mm/vmscan.c:245 set_task_reclaim_state+0x1e/0x40 [38491.963106] Modules linked in: iwlmvm mac80211 libarc4 iwlwificfg80211
xt_commentnls_iso8859_1nls_cp437vfat fat xfs jfs btrfs xorraid6_pqlibcrc32c ccm tun rfcomm fusext_tcpudpip6t_REJECTnf_reject_ipv6ipt_REJECTnf_reject_ipv4xt_multiportxt_ownersnd_hda_codec_hdmiip6table_filterip6_tablesiptable_filterbnep ext4crc32c_genericmbcache jbd2snd_hda_codec_realteksnd_hda_codec_genericsnd_soc_sklsnd_soc_hdac_hdasnd_hda_ext_coresnd_soc_skl_ipcx86_pkg_temp_thermalintel_powerclampsnd_soc_sst_ipccoretempsnd_soc_sst_dspsnd_soc_acpi_intel_matchkvm_intelsnd_soc_acpii915snd_soc_corekvmsnd_compressac97_bussnd_pcm_dmaenginesnd_hda_inteli2c_algo_bitbtusb irqbypassdrm_kms_helperbtrtlsnd_hda_codecdell_laptopbtbcmcrct10dif_pclmulsnd_hda_corecrc32c_intelbtinteliTCO_wdtghash_clmulni_inteldrmledtrig_audioaesni_inteliTCO_vendor_supportsnd_hwdepdell_wmirtsx_usb_msr8169dell_smbiosaes_x86_64mei_hdcpcrypto_simdintel_gttbluetoothsnd_pcmcryptd dcdbas[38491.963155] wmi_bmof dell_wmi_descriptor intel_rapl_msr
glue_helpersnd_timerjoydevintel_cstatesnd realtek memstickdell_smm_hwmonmousedev psmouseinput_ledslibphyintel_uncoreecdh_genericecc crc16 rfkillintel_rapl_perfsoundcorei2c_i801agpgartmei_metpm_crbsyscopyarea sysfillrect sysimgblt meiintel_xhci_usb_role_switchfb_sys_fopsidma64tpm_tisrolesprocessor_thermal_deviceintel_rapl_commoni2c_hidtpm_tis_coreint3403_thermalintel_soc_dts_iosfbattery wmiintel_lpss_pciintel_lpssintel_pch_thermaltpmint3400_thermalint3402_thermalacpi_thermal_relint340x_thermal_zonerng_coreintel_hidacsparse_keymapevdevmac_hidcrypto_userip_tablesx_tableshid_multitouchrtsx_usb_sdmmcmmc_corertsx_usbhid_logitech_hidppsr_modcdromsd_moduasusb_storagehid_logitech_djhid_genericusbhid hid ahciserio_rawlibahci atkbd libps2 libataxhci_pciscsi_modxhci_hcdcrc32_pclmuli8042 serio f2fs [last unloaded: cfg80211][38491.963221] CPU: 7 PID: 175 Comm: kswapd0 Not tainted 5.3.0-rc5+149+gbb7ba8069de9 #1 [38491.963222] Hardware name: Dell Inc. Inspiron 5570/09YTN7, BIOS 1.2.3 05/15/2019 [38491.963226] RIP: 0010:set_task_reclaim_state+0x1e/0x40 [38491.963228] Code: 78 a9 e7 ff 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 55 48 89 f5 53 48 89 fb 48 85 ed 48 8b 83 08 08 00 00 74 11 48 85 c0 74 02 <0f> 0b 48 89 ab 08 08 00 00 5b 5d c3 48 85 c0 75 f1 0f 0b 48 89 ab [38491.963229] RSP: 0018:ffff8c898031fc60 EFLAGS: 00010286 [38491.963230] RAX: ffff8c898031fe28 RBX: ffff892aa04ddc40 RCX: 0000000000000000 [38491.963231] RDX: ffff8c898031fc60 RSI: ffff8c898031fcd0 RDI: ffff892aa04ddc40 [38491.963233] RBP: ffff8c898031fcd0 R08: ffff8c898031fd48 R09: ffff89279674b800 [38491.963234] R10: 00000000ffffffff R11: 0000000000000000 R12: ffff8c898031fd48 [38491.963235] R13: ffff892a842ef000 R14: ffff892aaf7fc000 R15: 0000000000000000 [38491.963236] FS: 0000000000000000(0000) GS:ffff892aa33c0000(0000) knlGS:0000000000000000 [38491.963238] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [38491.963239] CR2: 00007f90628fa000 CR3: 000000027ee0a002 CR4: 00000000003606e0 [38491.963239] Call Trace: [38491.963246] mem_cgroup_shrink_node+0x9b/0x1d0 [38491.963250] mem_cgroup_soft_limit_reclaim+0x10c/0x3a0Quoted 8 lines
[38491.963254] balance_pgdat+0x276/0x540 [38491.963258] kswapd+0x200/0x3f0 [38491.963261] ? wait_woken+0x80/0x80 [38491.963265] kthread+0xfd/0x130 [38491.963267] ? balance_pgdat+0x540/0x540 [38491.963269] ? kthread_park+0x80/0x80 [38491.963273] ret_from_fork+0x35/0x40 [38491.963276] ---[ end trace 727343df67b2398a ]---Quoted 3 lines
Save and restore reclaim state for global reclaimer as it can be clobbered by memcg.
Quoted 5 lines
Hi Hillf,
Thanks for your patch. It could fix this issue.
But I'm wondering if it is proper to place a newscan_controlinmem_cgroup_shrink_node().
Hi Yafang
Good point.
Quoted 6 lines
Because the page alloction context is stored in the original
scan_control, but this newscan_controlbeaks it at all. For example, the sc.nodemask is the page allocation preferred node, but it is override by the newscan_control, that may cause extra useless page reclaim, especially in the direct reclaim path.
We can fix that break in concern that it will not make MH grumpy, see below for detail.
Quoted 40 lines
Thanks
YafangQuoted 38 lines
bb/vmscan.c renamed from mm/vmscan.c +18
-0@@ -253,6 +253,22 @@ static void set_task_reclaim_state(struc task->reclaim_state =3D rs; } +static struct reclaim_state * +save_task_reclaim_state (struct task_struct *task) +{ + struct reclaim_state *rs =3D task->reclaim_state; +if (rs) +set_task_reclaim_state (task,NULL ); +return rs; +} + +static void restore_task_reclaim_state (struct task_struct *task, +struct reclaim_state *rs) +{ +if (rs) +set_task_reclaim_state (task, rs); +} +#ifdef CONFIG_MEMCG static bool global_reclaim (struct scan_control *sc) {@@ -3241,7 +3257,9 @@ unsigned long mem_cgroup_shrink_node(str .may_shrinkslab =3D 1, };unsigned long lru_pages; +struct reclaim_state *rs; + rs =3D save_task_reclaim_state(current);set_task_reclaim_state (current, &sc.reclaim_state); sc.gfp_mask =3D (gfp_mask &GFP_RECLAIM_MASK ) | (GFP_HIGHUSER_MOVABLE & ~GFP_RECLAIM_MASK );@@ -3261,6 +3279,7 @@ unsigned long mem_cgroup_shrink_node(strtrace_mm_vmscan_memcg_softlimit_reclaim_end (sc.nr_reclaimed);
Quoted 6 lines
bb/vmscan.c unsigned long mem_cgroup_shrink_node(str
Quoted 6 lines
bb/vmscan.c renamed from mm/vmscan.c +1
-1set_task_reclaim_state (current,NULL ); +restore_task_reclaim_state (current, rs); *nr_scanned =3D sc.nr_scanned;return sc.nr_reclaimed; --
mm/vmscan.c +19 -0
@@ -3260,6 +3260,25 @@ unsigned long mem_cgroup_shrink_node(strstruct reclaim_state *rs; rs =save_task_reclaim_state (current); +if (rs) { +struct scan_control *save_sc =container_of (rs, + struct scan_control, reclaim_state); + + sc.may_writepage = save_sc->may_writepage; + sc.may_unmap = save_sc->may_unmap; + sc.reclaim_idx = save_sc->reclaim_idx; + sc.may_swap = save_sc->may_swap; + sc.may_shrinkslab = save_sc->may_shrinkslab; +/* +sc.order = save_sc->order; +sc.nr_to_reclaim = save_sc->nr_to_reclaim; + +or simply duplicate it as memcg reclaiming is smart enough;) + +sc = *save_sc; +sc.target_mem_cgroup = memcg; +*/ + }set_task_reclaim_state (current, &sc.reclaim_state); sc.gfp_mask = (gfp_mask &GFP_RECLAIM_MASK ) | (GFP_HIGHUSER_MOVABLE & ~GFP_RECLAIM_MASK );
--
And then make memcg soft-limit reclaiming forget reclaiming order.
mm/memcontrol.c +0 -3
@@ -2984,9 +2984,6 @@ unsigned long mem_cgroup_soft_limit_reclunsigned long excess;unsigned long nr_scanned; -if (order >0 ) -return 0 ; - mctz =soft_limit_tree_node (pgdat->node_id);/*
--
Quoted 182 lines · Hillf Danton
Quoted 93 lines · On Sat, 24 Aug 2019 11:36:31 +0800 Yafang Shao wrote:
Quoted 88 lines · Hillf Danton
Quoted 7 lines · On Fri, 23 Aug 2019 18:00:15 -0400 Adric Blake wrote:
Synopsis:
AWARN_ON_ONCEis hit twice inset_task_reclaim_stateunder the following conditions:
- a memory cgroup has been created and a task assigned it it
- memory.limit_in_bytes has been set
- memory has filled up, likely from cacheThanks for report.
Quoted 69 lines
In my usage, I create a cgroup under the current session scope and assign a task to it. I then set memory.limit_in_bytes and memory.soft_limit_in_bytes for the cgroup to reasonable values, say 1G/512M. The program accesses large files frequently and gradually fills memory with the page cache. The warnings appears when the entirety of the system memory is filled, presumably from other programs.
If I wait until the program has filled the entirety of system memory with cache and then assign a memory limit, the warnings appear immediately.
I am building the linux git. I first noticed this issue with the drm-tip 5.3rc3 and 5.3rc4 kernels, and tested linux master after 5.3rc5 to confirm the bug more resoundingly.
Here are the warnings.
[38491.963105] WARNING: CPU: 7 PID: 175 at mm/vmscan.c:245 set_task_reclaim_state+0x1e/0x40 [38491.963106] Modules linked in: iwlmvm mac80211 libarc4 iwlwificfg80211
xt_commentnls_iso8859_1nls_cp437vfat fat xfs jfs btrfs xorraid6_pqlibcrc32c ccm tun rfcomm fusext_tcpudpip6t_REJECTnf_reject_ipv6ipt_REJECTnf_reject_ipv4xt_multiportxt_ownersnd_hda_codec_hdmiip6table_filterip6_tablesiptable_filterbnep ext4crc32c_genericmbcache jbd2snd_hda_codec_realteksnd_hda_codec_genericsnd_soc_sklsnd_soc_hdac_hdasnd_hda_ext_coresnd_soc_skl_ipcx86_pkg_temp_thermalintel_powerclampsnd_soc_sst_ipccoretempsnd_soc_sst_dspsnd_soc_acpi_intel_matchkvm_intelsnd_soc_acpii915snd_soc_corekvmsnd_compressac97_bussnd_pcm_dmaenginesnd_hda_inteli2c_algo_bitbtusb irqbypassdrm_kms_helperbtrtlsnd_hda_codecdell_laptopbtbcmcrct10dif_pclmulsnd_hda_corecrc32c_intelbtinteliTCO_wdtghash_clmulni_inteldrmledtrig_audioaesni_inteliTCO_vendor_supportsnd_hwdepdell_wmirtsx_usb_msr8169dell_smbiosaes_x86_64mei_hdcpcrypto_simdintel_gttbluetoothsnd_pcmcryptd dcdbas[38491.963155] wmi_bmof dell_wmi_descriptor intel_rapl_msr
glue_helpersnd_timerjoydevintel_cstatesnd realtek memstickdell_smm_hwmonmousedev psmouseinput_ledslibphyintel_uncoreecdh_genericecc crc16 rfkillintel_rapl_perfsoundcorei2c_i801agpgartmei_metpm_crbsyscopyarea sysfillrect sysimgblt meiintel_xhci_usb_role_switchfb_sys_fopsidma64tpm_tisrolesprocessor_thermal_deviceintel_rapl_commoni2c_hidtpm_tis_coreint3403_thermalintel_soc_dts_iosfbattery wmiintel_lpss_pciintel_lpssintel_pch_thermaltpmint3400_thermalint3402_thermalacpi_thermal_relint340x_thermal_zonerng_coreintel_hidacsparse_keymapevdevmac_hidcrypto_userip_tablesx_tableshid_multitouchrtsx_usb_sdmmcmmc_corertsx_usbhid_logitech_hidppsr_modcdromsd_moduasusb_storagehid_logitech_djhid_genericusbhid hid ahciserio_rawlibahci atkbd libps2 libataxhci_pciscsi_modxhci_hcdcrc32_pclmuli8042 serio f2fs [last unloaded: cfg80211][38491.963221] CPU: 7 PID: 175 Comm: kswapd0 Not tainted 5.3.0-rc5+149+gbb7ba8069de9 #1 [38491.963222] Hardware name: Dell Inc. Inspiron 5570/09YTN7, BIOS 1.2.3 05/15/2019 [38491.963226] RIP: 0010:set_task_reclaim_state+0x1e/0x40 [38491.963228] Code: 78 a9 e7 ff 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 55 48 89 f5 53 48 89 fb 48 85 ed 48 8b 83 08 08 00 00 74 11 48 85 c0 74 02 <0f> 0b 48 89 ab 08 08 00 00 5b 5d c3 48 85 c0 75 f1 0f 0b 48 89 ab [38491.963229] RSP: 0018:ffff8c898031fc60 EFLAGS: 00010286 [38491.963230] RAX: ffff8c898031fe28 RBX: ffff892aa04ddc40 RCX: 0000000000000000 [38491.963231] RDX: ffff8c898031fc60 RSI: ffff8c898031fcd0 RDI: ffff892aa04ddc40 [38491.963233] RBP: ffff8c898031fcd0 R08: ffff8c898031fd48 R09: ffff89279674b800 [38491.963234] R10: 00000000ffffffff R11: 0000000000000000 R12: ffff8c898031fd48 [38491.963235] R13: ffff892a842ef000 R14: ffff892aaf7fc000 R15: 0000000000000000 [38491.963236] FS: 0000000000000000(0000) GS:ffff892aa33c0000(0000) knlGS:0000000000000000 [38491.963238] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [38491.963239] CR2: 00007f90628fa000 CR3: 000000027ee0a002 CR4: 00000000003606e0 [38491.963239] Call Trace: [38491.963246] mem_cgroup_shrink_node+0x9b/0x1d0 [38491.963250] mem_cgroup_soft_limit_reclaim+0x10c/0x3a0Quoted 8 lines
[38491.963254] balance_pgdat+0x276/0x540 [38491.963258] kswapd+0x200/0x3f0 [38491.963261] ? wait_woken+0x80/0x80 [38491.963265] kthread+0xfd/0x130 [38491.963267] ? balance_pgdat+0x540/0x540 [38491.963269] ? kthread_park+0x80/0x80 [38491.963273] ret_from_fork+0x35/0x40 [38491.963276] ---[ end trace 727343df67b2398a ]---Quoted 3 lines
Save and restore reclaim state for global reclaimer as it can be clobbered by memcg.
Quoted 5 lines
Hi Hillf,
Thanks for your patch. It could fix this issue.
But I'm wondering if it is proper to place a newscan_controlinmem_cgroup_shrink_node().Hi Yafang
Good point.
Quoted 6 lines
Because the page alloction context is stored in the original
scan_control, but this newscan_controlbeaks it at all. For example, the sc.nodemask is the page allocation preferred node, but it is override by the newscan_control, that may cause extra useless page reclaim, especially in the direct reclaim path.We can fix that break in concern that it will not make MH grumpy, see below for detail.
Quoted 46 lines
Thanks
YafangQuoted 44 lines
bb/vmscan.c renamed from mm/vmscan.c +19
-1@@ -253,6 +253,22 @@ static void set_task_reclaim_state(struc task->reclaim_state =3D rs; } +static struct reclaim_state * +save_task_reclaim_state (struct task_struct *task) +{ + struct reclaim_state *rs =3D task->reclaim_state; +if (rs) +set_task_reclaim_state (task,NULL ); +return rs; +} + +static void restore_task_reclaim_state (struct task_struct *task, +struct reclaim_state *rs) +{ +if (rs) +set_task_reclaim_state (task, rs); +} +#ifdef CONFIG_MEMCG static bool global_reclaim (struct scan_control *sc) {@@ -3241,7 +3257,9 @@ unsigned long mem_cgroup_shrink_node(str .may_shrinkslab =3D 1, };unsigned long lru_pages; +struct reclaim_state *rs; + rs =3D save_task_reclaim_state(current);set_task_reclaim_state (current, &sc.reclaim_state); sc.gfp_mask =3D (gfp_mask &GFP_RECLAIM_MASK ) | (GFP_HIGHUSER_MOVABLE & ~GFP_RECLAIM_MASK );@@ -3261,6 +3279,7 @@ unsigned long mem_cgroup_shrink_node(strtrace_mm_vmscan_memcg_softlimit_reclaim_end (sc.nr_reclaimed);set_task_reclaim_state (current,NULL ); +restore_task_reclaim_state (current, rs); *nr_scanned =3D sc.nr_scanned;return sc.nr_reclaimed; --mm/vmscan.c +13
-0@@ -3260,6 +3260,25 @@ unsigned long mem_cgroup_shrink_node(strstruct reclaim_state *rs; rs =save_task_reclaim_state (current); +if (rs) { +struct scan_control *save_sc =container_of (rs, + struct scan_control, reclaim_state); + + sc.may_writepage = save_sc->may_writepage; + sc.may_unmap = save_sc->may_unmap; + sc.reclaim_idx = save_sc->reclaim_idx; + sc.may_swap = save_sc->may_swap; + sc.may_shrinkslab = save_sc->may_shrinkslab; +/* +sc.order = save_sc->order; +sc.nr_to_reclaim = save_sc->nr_to_reclaim; +
mm/vmscan.c unsigned long mem_cgroup_shrink_node(str
Quoted 10 lines
mm/vmscan.c +6
-1+or simply duplicate it as memcg reclaiming is smart enough;) + +sc = *save_sc; +sc.target_mem_cgroup = memcg; +*/ + }set_task_reclaim_state (current, &sc.reclaim_state); sc.gfp_mask = (gfp_mask &GFP_RECLAIM_MASK ) | (GFP_HIGHUSER_MOVABLE & ~GFP_RECLAIM_MASK ); --
The memcg soft reclaim is called from kswapd reclam path and direct reclaim path,
so why not pass the scan_control from the callsite in these two reclaim paths and use it in memcg soft reclaim ?
Seems there's no specially reason that we must introduce a new scan_control here.
mm/memcontrol.c unsigned long mem_cgroup_soft_limit_recl · line 2989
Quoted 11 lines
And then make memcg soft-limit reclaiming forget reclaiming order.
mm/memcontrol.c +0
-3@@ -2984,9 +2984,6 @@ unsigned long mem_cgroup_soft_limit_reclunsigned long excess;unsigned long nr_scanned; -if (order >0 ) -return 0 ; -
I have checked the hisotry why this order check is introduced here. The first commit is 4e41695356fb ("memory controller: soft limit reclaim on contention"),
but it didn't explained why.
At the first glance it is reasonable to remove it, but we should understand why it was introduced at the first place.
Quoted 5 lines
mm/memcontrol.c +0
-1mctz =soft_limit_tree_node (pgdat->node_id);/* --