From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BEC1AC433DB for ; Wed, 17 Mar 2021 14:12:10 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 356FA64F6C for ; Wed, 17 Mar 2021 14:12:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 356FA64F6C Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id CC5258D0001; Wed, 17 Mar 2021 10:12:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C75D06B0071; Wed, 17 Mar 2021 10:12:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B160C8D0001; Wed, 17 Mar 2021 10:12:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0144.hostedemail.com [216.40.44.144]) by kanga.kvack.org (Postfix) with ESMTP id 9843F6B0070 for ; Wed, 17 Mar 2021 10:12:07 -0400 (EDT) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 39D123AA1 for ; Wed, 17 Mar 2021 14:12:07 +0000 (UTC) X-FDA: 77929555494.16.22C6D48 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf02.hostedemail.com (Postfix) with ESMTP id 3B83C400C9A0 for ; Wed, 17 Mar 2021 14:05:58 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1615989956; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=cIltC9g3eI67AJ6l+RPM3xTSrdo/DzkDrTkj42+kPZI=; b=IwirpRnNtZ039Az7dJVxJaJ53Qk+nMsIIr+VfDUJxpVTVbOmuhulHKuLZOBXPZjwuf+fIC yeS0SNi/OxxZof6fMbDpxLHIj45y0xC/PMPGgcuXTOn+/r2qMKh2oLtCRsmXdiSBnqNEWp yDLyZ6nM2ufCYPk4G7Xdlb33V2MuiIw= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id A21ABAC47; Wed, 17 Mar 2021 14:05:56 +0000 (UTC) Date: Wed, 17 Mar 2021 15:05:40 +0100 From: Michal Hocko To: Oscar Salvador Cc: Andrew Morton , Vlastimil Babka , David Hildenbrand , Muchun Song , Mike Kravetz , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v5 1/5] mm,page_alloc: Bail out earlier on -ENOMEM in alloc_contig_migrate_range Message-ID: References: <20210317111251.17808-1-osalvador@suse.de> <20210317111251.17808-2-osalvador@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210317111251.17808-2-osalvador@suse.de> X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 3B83C400C9A0 X-Stat-Signature: iuieh376du7bp1isapyjqc79tsoykpm6 Received-SPF: none (suse.com>: No applicable sender policy available) receiver=imf02; identity=mailfrom; envelope-from=""; helo=mx2.suse.de; client-ip=195.135.220.15 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1615989958-153791 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Wed 17-03-21 12:12:47, Oscar Salvador wrote: > Currently, __alloc_contig_migrate_range can generate -EINTR, -ENOMEM or -EBUSY, > and report them down the chain. > The problem is that when migrate_pages() reports -ENOMEM, we keep going till we > exhaust all the try-attempts (5 at the moment) instead of bailing out. > > migrate_pages() bails out right away on -ENOMEM because it is considered a fatal > error. Do the same here instead of keep going and retrying. I suspect this is not really a real life problem, right? The allocation would be more costly in the end but this is to be expected under a heavy memory pressure. That being said, bailing out early makes sense to me. But now that you've made me look into the migrate_pages excellent error state reporting I suspect we have a bug here. Note the "Returns the number of pages that were not migrated, or an error code." but I do not see putback_movable_pages for ret > 0 so it seems we might leak some pages. That aside. Now looking at other callers of migrate_pages most of them do not care about the number of failed pages. The only one which cares is migrate_pages syscall (do_migrate_pages). I think it would be much more reasonable to have migrate_pages (kernel function) return error or 0 and make the only caller which cares to count number of failed pages (e.g. by returning the number of pages from putback_movable_pages). > Signed-off-by: Oscar Salvador > Acked-by: Vlastimil Babka > Reviewed-by: David Hildenbrand The patch itself looks reasonable but make sure to mention this is mere cosmetic change unless there is a real problem fixed by this. Acked-by: Michal Hocko > --- > mm/page_alloc.c | 8 +++++++- > 1 file changed, 7 insertions(+), 1 deletion(-) > > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > index cfc72873961d..a4f67063b85f 100644 > --- a/mm/page_alloc.c > +++ b/mm/page_alloc.c > @@ -8481,7 +8481,7 @@ static int __alloc_contig_migrate_range(struct compact_control *cc, > } > tries = 0; > } else if (++tries == 5) { > - ret = ret < 0 ? ret : -EBUSY; > + ret = -EBUSY; > break; > } > > @@ -8491,6 +8491,12 @@ static int __alloc_contig_migrate_range(struct compact_control *cc, > > ret = migrate_pages(&cc->migratepages, alloc_migration_target, > NULL, (unsigned long)&mtc, cc->mode, MR_CONTIG_RANGE); > + /* > + * On -ENOMEM, migrate_pages() bails out right away. It is pointless > + * to retry again over this error, so do the same here. > + */ > + if (ret == -ENOMEM) > + break; > } > if (ret < 0) { > putback_movable_pages(&cc->migratepages); > -- > 2.16.3 -- Michal Hocko SUSE Labs