Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751804AbcDUGuy (ORCPT ); Thu, 21 Apr 2016 02:50:54 -0400 Received: from out4440.biz.mail.alibaba.com ([47.88.44.40]:47923 "EHLO out4440.biz.mail.alibaba.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751010AbcDUGux (ORCPT ); Thu, 21 Apr 2016 02:50:53 -0400 X-Greylist: delayed 11873 seconds by postgrey-1.27 at vger.kernel.org; Thu, 21 Apr 2016 02:50:53 EDT X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R211e4;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e02c03292;MF=hillf.zj@alibaba-inc.com;NM=1;PH=DS;RN=12;SR=0;TI=SMTPD_----4j1ExlU_1461221408; Reply-To: "Hillf Danton" From: "Hillf Danton" To: "'Michal Hocko'" , "'Andrew Morton'" Cc: "'Linus Torvalds'" , "'Johannes Weiner'" , "'Mel Gorman'" , "'David Rientjes'" , "'Tetsuo Handa'" , "'Joonsoo Kim'" , "'Vlastimil Babka'" , , "'LKML'" , "'Michal Hocko'" References: <1461181647-8039-1-git-send-email-mhocko@kernel.org> <1461181647-8039-8-git-send-email-mhocko@kernel.org> In-Reply-To: <1461181647-8039-8-git-send-email-mhocko@kernel.org> Subject: Re: [PATCH 07/14] mm, compaction: Simplify __alloc_pages_direct_compact feedback interface Date: Thu, 21 Apr 2016 14:50:08 +0800 Message-ID: <02cd01d19b9a$0b676790$223636b0$@alibaba-inc.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Outlook 14.0 Thread-Index: AQG1HgS+iScJ1ld6BkmHPkLx52RrNAJawq32n7ohpsA= Content-Language: zh-cn Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 5659 Lines: 162 > > From: Michal Hocko > > __alloc_pages_direct_compact communicates potential back off by two > variables: > - deferred_compaction tells that the compaction returned > COMPACT_DEFERRED > - contended_compaction is set when there is a contention on > zone->lock resp. zone->lru_lock locks > > __alloc_pages_slowpath then backs of for THP allocation requests to > prevent from long stalls. This is rather messy and it would be much > cleaner to return a single compact result value and hide all the nasty > details into __alloc_pages_direct_compact. > > This patch shouldn't introduce any functional changes. > > Acked-by: Vlastimil Babka > Signed-off-by: Michal Hocko > --- Acked-by: Hillf Danton > mm/page_alloc.c | 67 ++++++++++++++++++++++++++------------------------------- > 1 file changed, 31 insertions(+), 36 deletions(-) > > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > index 06af8a757d52..350d13f3709b 100644 > --- a/mm/page_alloc.c > +++ b/mm/page_alloc.c > @@ -2944,29 +2944,21 @@ __alloc_pages_may_oom(gfp_t gfp_mask, unsigned int order, > 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) > + enum migrate_mode mode, enum compact_result *compact_result) > { > - enum compact_result compact_result; > struct page *page; > + int contended_compaction; > > if (!order) > return NULL; > > current->flags |= PF_MEMALLOC; > - compact_result = try_to_compact_pages(gfp_mask, order, alloc_flags, ac, > - mode, contended_compaction); > + *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_INACTIVE) > return NULL; > - default: > - break; > - } > > /* > * At least in one zone compaction wasn't deferred or skipped, so let's > @@ -2992,6 +2984,24 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order, > */ > count_vm_event(COMPACTFAIL); > > + /* > + * In all zones where compaction was attempted (and not > + * deferred or skipped), lock contention has been detected. > + * For THP allocation we do not want to disrupt the others > + * so we fallback to base pages instead. > + */ > + if (contended_compaction == COMPACT_CONTENDED_LOCK) > + *compact_result = COMPACT_CONTENDED; > + > + /* > + * If compaction was aborted due to need_resched(), we do not > + * want to further increase allocation latency, unless it is > + * khugepaged trying to collapse. > + */ > + if (contended_compaction == COMPACT_CONTENDED_SCHED > + && !(current->flags & PF_KTHREAD)) > + *compact_result = COMPACT_CONTENDED; > + > cond_resched(); > > return NULL; > @@ -3000,8 +3010,7 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order, > static inline 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) > + enum migrate_mode mode, enum compact_result *compact_result) > { > return NULL; > } > @@ -3146,8 +3155,7 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order, > unsigned long pages_reclaimed = 0; > unsigned long did_some_progress; > enum migrate_mode migration_mode = MIGRATE_ASYNC; > - bool deferred_compaction = false; > - int contended_compaction = COMPACT_CONTENDED_NONE; > + enum compact_result compact_result; > > /* > * In the slowpath, we sanity check order to avoid ever trying to > @@ -3245,8 +3253,7 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order, > */ > page = __alloc_pages_direct_compact(gfp_mask, order, alloc_flags, ac, > migration_mode, > - &contended_compaction, > - &deferred_compaction); > + &compact_result); > if (page) > goto got_pg; > > @@ -3259,25 +3266,14 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order, > * to heavily disrupt the system, so we fail the allocation > * instead of entering direct reclaim. > */ > - if (deferred_compaction) > - goto nopage; > - > - /* > - * In all zones where compaction was attempted (and not > - * deferred or skipped), lock contention has been detected. > - * For THP allocation we do not want to disrupt the others > - * so we fallback to base pages instead. > - */ > - if (contended_compaction == COMPACT_CONTENDED_LOCK) > + if (compact_result == COMPACT_DEFERRED) > goto nopage; > > /* > - * If compaction was aborted due to need_resched(), we do not > - * want to further increase allocation latency, unless it is > - * khugepaged trying to collapse. > + * Compaction is contended so rather back off than cause > + * excessive stalls. > */ > - if (contended_compaction == COMPACT_CONTENDED_SCHED > - && !(current->flags & PF_KTHREAD)) > + if(compact_result == COMPACT_CONTENDED) > goto nopage; > } > > @@ -3325,8 +3321,7 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order, > */ > page = __alloc_pages_direct_compact(gfp_mask, order, alloc_flags, > ac, migration_mode, > - &contended_compaction, > - &deferred_compaction); > + &compact_result); > if (page) > goto got_pg; > nopage: > -- > 2.8.0.rc3