Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932618AbcCHJwZ (ORCPT ); Tue, 8 Mar 2016 04:52:25 -0500 Received: from mx2.suse.de ([195.135.220.15]:45976 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932084AbcCHJwT (ORCPT ); Tue, 8 Mar 2016 04:52:19 -0500 Subject: Re: [PATCH] mm, oom: protect !costly allocations some more To: Michal Hocko References: <1450203586-10959-1-git-send-email-mhocko@kernel.org> <20160203132718.GI6757@dhcp22.suse.cz> <20160225092315.GD17573@dhcp22.suse.cz> <20160229210213.GX16930@dhcp22.suse.cz> <20160307160838.GB5028@dhcp22.suse.cz> <56DE9A68.2010301@suse.cz> <20160308094612.GB13542@dhcp22.suse.cz> Cc: Hugh Dickins , Sergey Senozhatsky , Andrew Morton , Linus Torvalds , Johannes Weiner , Mel Gorman , David Rientjes , Tetsuo Handa , Hillf Danton , KAMEZAWA Hiroyuki , linux-mm@kvack.org, LKML , Joonsoo Kim From: Vlastimil Babka Message-ID: <56DEA0CF.2070902@suse.cz> Date: Tue, 8 Mar 2016 10:52:15 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 MIME-Version: 1.0 In-Reply-To: <20160308094612.GB13542@dhcp22.suse.cz> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2413 Lines: 71 On 03/08/2016 10:46 AM, Michal Hocko wrote: > On Tue 08-03-16 10:24:56, Vlastimil Babka wrote: > [...] >>> @@ -2819,28 +2819,22 @@ static struct page * >>> __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order, >>> int alloc_flags, const struct alloc_context *ac, >>> enum migrate_mode mode, int *contended_compaction, >>> - bool *deferred_compaction) >>> + unsigned long *compact_result) >>> { >>> - unsigned long compact_result; >>> struct page *page; >>> >>> - if (!order) >>> + if (!order) { >>> + *compact_result = COMPACT_NONE; >>> return NULL; >>> + } >>> >>> current->flags |= PF_MEMALLOC; >>> - compact_result = try_to_compact_pages(gfp_mask, order, alloc_flags, ac, >>> + *compact_result = try_to_compact_pages(gfp_mask, order, alloc_flags, ac, >>> mode, contended_compaction); >>> current->flags &= ~PF_MEMALLOC; >>> >>> - switch (compact_result) { >>> - case COMPACT_DEFERRED: >>> - *deferred_compaction = true; >>> - /* fall-through */ >>> - case COMPACT_SKIPPED: >>> + if (*compact_result <= COMPACT_SKIPPED) >> >> COMPACT_NONE is -1 and compact_result is unsigned long, so this won't >> work as expected. > > Well, COMPACT_NONE is documented as /* compaction disabled */ so we > should never get it from try_to_compact_pages. Right. > > [...] >>> @@ -3294,6 +3289,18 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order, >>> did_some_progress > 0, no_progress_loops)) >>> goto retry; >>> >>> + /* >>> + * !costly allocations are really important and we have to make sure >>> + * the compaction wasn't deferred or didn't bail out early due to locks >>> + * contention before we go OOM. >>> + */ >>> + if (order && order <= PAGE_ALLOC_COSTLY_ORDER) { >>> + if (compact_result <= COMPACT_CONTINUE) >> >> Same here. >> I was going to say that this didn't have effect on Sergey's test, but >> turns out it did :) > > This should work as expected because compact_result is unsigned long > and so this is the unsigned arithmetic. I can make > #define COMPACT_NONE -1UL > > to make the intention more obvious if you prefer, though. Well, what wasn't obvious to me is actually that here (unlike in the test above) it was actually intended that COMPACT_NONE doesn't result in a retry. But it makes sense, otherwise we would retry endlessly if reclaim couldn't form a higher-order page, right. > Thanks for the review. >