Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933826AbdDELjb (ORCPT ); Wed, 5 Apr 2017 07:39:31 -0400 Received: from mail-db5eur01on0092.outbound.protection.outlook.com ([104.47.2.92]:45420 "EHLO EUR01-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S933452AbdDELjZ (ORCPT ); Wed, 5 Apr 2017 07:39:25 -0400 Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=virtuozzo.com; Subject: Re: [PATCH 1/4] mm: prevent potential recursive reclaim due to clearing PF_MEMALLOC To: Vlastimil Babka , Andrew Morton References: <20170405074700.29871-1-vbabka@suse.cz> <20170405074700.29871-2-vbabka@suse.cz> CC: , , Michal Hocko , Mel Gorman , Johannes Weiner , , , , , , From: Andrey Ryabinin Message-ID: <1f26f654-abaf-3878-6abb-5e27ff3a289e@virtuozzo.com> Date: Wed, 5 Apr 2017 14:40:43 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: <20170405074700.29871-2-vbabka@suse.cz> Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 7bit X-Originating-IP: [195.214.232.6] X-ClientProxiedBy: HE1P190CA0024.EURP190.PROD.OUTLOOK.COM (10.172.123.34) To VI1PR0801MB2735.eurprd08.prod.outlook.com (10.166.198.28) X-MS-Office365-Filtering-Correlation-Id: a42e742d-cbef-4465-74bc-08d47c186667 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001)(201703131423075)(201703031133081);SRVR:VI1PR0801MB2735; X-Microsoft-Exchange-Diagnostics: 1;VI1PR0801MB2735;3:esu24coA/zJu78z4n8L+3BhNliCPEg0F8596CVdY74gXPCvddGE0Ckqu19Mft7yhJ/kfMpcc5nxty973pH3dwtAAnIOob4nkWiqQrW9qHiuAKeGJ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ZzMdTvrcqtWdAE6+NdMSKz8y0khgqbDYQA3PJv/3BxlYXSGR3lm2Nz7+3yH0zu3Siam4pngp478E1yGLIq/eC+VQynS/3eWsEOyxx7l4FAEsN2wsOeDp5fxYf/aMWje4g/H08AUhNTuTQ1ilcXOPq2Q/uxXlFTflu2MMZ/bsVctS6RvkbpUog4IxkKj+fDpvyzMiIDjo8DPMsHj+uzMUpKkMx/nQVTiohhs5/Bqm/oBifOPqJyOMEl1oiRAaoz7tpR+qm7YernpNG4WRNP9To7vIXALwFCGWo5F9aFMRUj9cleyh64k9xK6uLWFYFTRSAEI7wCHV5bikQWS53IgarNwYB9aI9aA4EYxmM27vCuHuOcSgWi6OCDZn+27zQqigsAtDvfs4= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(9452136761055); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040450)(601004)(2401047)(8121501046)(5005006)(93006095)(93001095)(10201501046)(3002001)(6041248)(20161123555025)(201703131423075)(201702281528075)(201703061421075)(20161123564025)(20161123562025)(20161123560025)(6072148);SRVR:VI1PR0801MB2735;BCL:0;PCL:0;RULEID:;SRVR:VI1PR0801MB2735; X-Microsoft-Exchange-Diagnostics: 1;VI1PR0801MB2735;4:xy6N5Ul2qDlJNMYzrZiQnI1b0kAj83yIqIOw9GTCfAjeJeiTCvRaJCthw5nYYWpvziQgXeaVx6JDkntN42NufJDanip9srdYP/sq2Vml53dkhA6+Sn3/tZloO12NY8bDgwBf2bWgQgobEvi2skJiLeOICaf5xJBHL/R5xFvCW24MkgUI532rAFg0n+r143Jzkmv0uD1d8NItIWgmJQ1Ks610tEkyqWDVgCabuHWrVBCV0WGopGmepwkdjVGyG8fkxiyfADTQ6Lsm+DNIHGmgsuanvVVbT2DNjrpx7ZMDTdkbEIzdmpFxLUdwqQg13pZftPygS2Bmg8atlMGcPsZHRZXqFqNYtcwheoCjxD3aXZ440rq/4Gl+ahfUG6ZZHs3sBE8H6VJF/06Rv6ZY6/ejZ9mmcCHFlItyhszxaDeupPsedZXenr8Gj7hIBj+zXYdZW/sjX79SkhkTtiWOvdv78uI6KB5KCJclcSdJzn06vYN72ujgKSVgX6XX6rJ08U8XhfS3LzJvMN+xun+xkJTZg8IM6J85f7rFDkeY72IpSTzDkUGLnBZTDr/GyG9E68HBx2XZOw3XlYPRjBg0hGgPS4Ah+bxHgTJVVgo/QkJ11GSTdMzRqyrqqBKJDSqxsrcKwjoRZ3vTKSqRQL0JjX7/AZH97GhUJM34re0GMdbpWidFyDuBZ9xq4kgFNOySMWCd4R/lEtGLV3RIBGASOz5yfL0Cs3/FOJqUzdlzb6LFQB67z9BpqK2OsFB7S7lgYVIt X-Forefront-PRVS: 0268246AE7 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(4630300001)(6009001)(6049001)(39450400003)(39400400002)(39410400002)(39840400002)(377454003)(24454002)(90366009)(65826007)(6486002)(77096006)(65956001)(65806001)(66066001)(3846002)(6116002)(38730400002)(31696002)(86362001)(229853002)(305945005)(7736002)(53936002)(6246003)(230700001)(64126003)(7416002)(47776003)(81166006)(54906002)(50466002)(8676002)(54356999)(76176999)(50986999)(2950100002)(23746002)(6666003)(36756003)(42186005)(53546009)(33646002)(189998001)(25786009)(4326008)(4001350100001);DIR:OUT;SFP:1102;SCL:1;SRVR:VI1PR0801MB2735;H:[172.16.25.12];FPR:;SPF:None;MLV:sfv;LANG:en; X-Microsoft-Exchange-Diagnostics: =?Windows-1252?Q?1;VI1PR0801MB2735;23:LoZ36ihTvAoV8g4N0HVjcd5Zv2xsxgiNEsN?= =?Windows-1252?Q?7GsFJti3SUdzTAZZLCAGyEGnraaKh6tGR8jV1TsQMIsblk2nY0F5MUqi?= =?Windows-1252?Q?eSSNGbSwWSs5WnMoDAGfpeJ88LDsNM+64cZ5iV4ulXoaYQAL+hnqvO4j?= =?Windows-1252?Q?sOMk/PSv+mhBI603oUen4C17cM/5s9CFj/c53bRfVLDbiKPxf89k+1+e?= =?Windows-1252?Q?ajw4F58db0E4b3f9CtmdxVP/44wzwiQ9+Gb6GXxuIbEWy1fCq/nEOFF8?= =?Windows-1252?Q?gPhd4K3LkYj38bkr482qTwf9LnD4bG4pUYE8iaC3KZ2BdGuKG3LanWFE?= =?Windows-1252?Q?QfQ8cZshfUt1xOIsdek1tuVauQ1s7XalYh8y12Wx9f40jWcGvpHeyO+d?= =?Windows-1252?Q?v9/y7vlGH/3pLJZEyJgNzzDvhYQngsreAx/UgeAaU0RS8c1i5nHyTiGP?= =?Windows-1252?Q?r3Ry90mXbR/qxSSNVHlL4deoIQHSOMNsWTsio2uC51D0DBZFb5XGRxRI?= =?Windows-1252?Q?Hg9qCMAsPSfUls4PeXIx76PPBDXRP9Xab2h744WXKdOxLQFSLF6MCDjn?= =?Windows-1252?Q?XyHGEJKqQQSeZm4Sjw0Ojf2TNUkwPtTWGL+NxFLBJ6YOWoL2Yfj0TI79?= =?Windows-1252?Q?jSntMvqrlwzzL8vv7HJP/C5rwrGyVMe7MYGhAdS/2h+f2/AF0+wdqhAF?= =?Windows-1252?Q?HXkCQGqZNy4Vp+iXfmKk52f7HNONPZIT1htqxzujV0FZDor3Tf6ahG+O?= =?Windows-1252?Q?qkAIhufwhJlehfRf+wKSbgGa7L/e9UvCX+zAqPJEV3lP7qWdu8L4/ml7?= =?Windows-1252?Q?ZKdDJC7p3kC5JNbFemRQtRCEUU8NQeAjmxb+6CczlV+Loxtnns166JTc?= =?Windows-1252?Q?hNa8UHUtj2itUTBGKX1TR3PbRWduZAFxdnEZL22ENsKEsbbdaIXeAA/0?= =?Windows-1252?Q?7zLsGT3d47jfW+nFBxNMVsyZ9kRnXzXnfrfbZSj0d5oeOqB9mZ+65rFo?= =?Windows-1252?Q?blDJUjvW1GuteCCjqYZICq4HcQ5XJwSUKYaNkNvDbULoPJqq1sebKwee?= =?Windows-1252?Q?I5sClKPR4vrGHaqDF790w/UbwPOJuNrbRf7WnQqY7OteqKGSbiDdmpBf?= =?Windows-1252?Q?TPTXtjLi1sYh1Jd3MnYcf1VJOt9hVLrhSr1mi6IWh7o4u8eY+p6Tivkh?= =?Windows-1252?Q?KqlScyMpWElhboQDTFsfpneOcp6n2lPk1byc3q6W+BXDqOgQXA0hExts?= =?Windows-1252?Q?5LiIi6Wc1dvAA8J71JOLrGHOqPTxupa3BbPz61iQ=3D?= X-Microsoft-Exchange-Diagnostics: 1;VI1PR0801MB2735;6:q9f5WC/Bjqf7sEfK6KXOg/WJG/ChTGu/3JmS8aJRyvj4sn8rPLhRcsUDdAhh9rP89/anlym2fvymWvAtnGxwQavC4oIj4cjEydUlcvAnRHYLaRgxEUfmr87WqjCrpT7OsJIZ9o2MNTErYMBynTz5IKlpv7DmV66K59B2dZD5543F82qiKqezLVk7ZDIUjHd1/cr6fIEjscE5RtVUNiE/pvsxIrQcd9D+H4ujU3NRvT+a+F2FlCJMLyOEC/zM1fKP9Cd3hSFInb1MPRSxbDCVavM8HaefXg7Y3JQwNuNH90R7nvrHTpPA8an/JJWiQ43pvkR6Sm+gKBAsa0g3MM4tEGWfXBuqhThX9pWgJlNIt1yCMqJ8trjc4Fm44JBM6UKWja0ss87PAUK8mexIYQYO7w==;5:Qh3hyCDFsj9F8zxAF88fad1/ZlKHILv96/+VwJaaNebLsyDH4rnd79pmpM4W9WVOVOszY6xAbtqw6lpVwdYOOiNyjBkw6Xl2Div5ZbdGYvGrBjdTbscmFujVa/QMfXyteraHALKHsZ6axSPwXXXkwg==;24:mMLGIFMIBoPthEO0QQovRwm5Jr6WK9KmWEE1ioK7cizDago/v9HkRKDiDmep6D4DLCF7Ko0+c7ky6PTRqt201B3aObM/yUa1rL75i9rPcIg= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;VI1PR0801MB2735;7:aWM8hmWa8lKHrJ4aExqYeduzsqf+9Bc40w7TJvquOdg8bcU89+afMXRIXEibCpz1sC4hCpMsVO54Jij9+5QLZn+ld866wHAWjQu0bHKdc6R+qLNEjWf7ICDzxwg4+kmecttvI1Ml93M6FN/ziMI3aABRzPPAQKKh36SIrg8SQ7C7EpH1Tc5H5FquZxBGPAnLm+Q6MT9Ey4U+iWvMnkmK2QFBAUEGV0eS8qDzy3zX3djkKopxQ75Bh+lWTR+Dz68H5yZFOpwbB24mc78r6s+PP6u7pxdC7mfX/kFUDW9OlDZEOREhNFKzmpqEAsTP70qDbWJ66a0h1mnnWzQ/RfRavw==;20:iQYd0VQ/rPGdbPkPte9OIj+bh0PK4NksImh0nvH43U4rsC/9O/cl2zqF6I9k50ua9nO/fRXbP3DhMhBKAL2D+wBqR2MWXxuI6yRPztL7QE4ddSaxrksPNi/ek0quXIeVCrLz/PmXw6K32QwEm9GdWpBiXR/rQJxsHgnZPeG8ojU= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Apr 2017 11:39:19.2072 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0801MB2735 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2263 Lines: 54 On 04/05/2017 10:46 AM, Vlastimil Babka wrote: > The function __alloc_pages_direct_compact() sets PF_MEMALLOC to prevent > deadlock during page migration by lock_page() (see the comment in > __unmap_and_move()). Then it unconditionally clears the flag, which can clear a > pre-existing PF_MEMALLOC flag and result in recursive reclaim. This was not a > problem until commit a8161d1ed609 ("mm, page_alloc: restructure direct > compaction handling in slowpath"), because direct compation was called only > after direct reclaim, which was skipped when PF_MEMALLOC flag was set. > > Even now it's only a theoretical issue, as the new callsite of > __alloc_pages_direct_compact() is reached only for costly orders and when > gfp_pfmemalloc_allowed() is true, which means either __GFP_NOMEMALLOC is in is false > gfp_flags or in_interrupt() is true. There is no such known context, but let's > play it safe and make __alloc_pages_direct_compact() robust for cases where > PF_MEMALLOC is already set. > > Fixes: a8161d1ed609 ("mm, page_alloc: restructure direct compaction handling in slowpath") > Reported-by: Andrey Ryabinin > Signed-off-by: Vlastimil Babka > Cc: > --- > mm/page_alloc.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > index 3589f8be53be..b84e6ffbe756 100644 > --- a/mm/page_alloc.c > +++ b/mm/page_alloc.c > @@ -3288,6 +3288,7 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order, > enum compact_priority prio, enum compact_result *compact_result) > { > struct page *page; > + unsigned int noreclaim_flag = current->flags & PF_MEMALLOC; > > if (!order) > return NULL; > @@ -3295,7 +3296,7 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order, > current->flags |= PF_MEMALLOC; > *compact_result = try_to_compact_pages(gfp_mask, order, alloc_flags, ac, > prio); > - current->flags &= ~PF_MEMALLOC; > + current->flags = (current->flags & ~PF_MEMALLOC) | noreclaim_flag; Perhaps this would look better: tsk_restore_flags(current, noreclaim_flag, PF_MEMALLOC); ? > if (*compact_result <= COMPACT_INACTIVE) > return NULL; >