From patchwork Fri Aug 14 17:31:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Minchan Kim X-Patchwork-Id: 11715065 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 23691739 for ; Fri, 14 Aug 2020 17:31:57 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D6C7C20768 for ; Fri, 14 Aug 2020 17:31:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BPRDYjHM" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D6C7C20768 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id EEECC8D0008; Fri, 14 Aug 2020 13:31:49 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id E54E68D0003; Fri, 14 Aug 2020 13:31:49 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B733A8D0008; Fri, 14 Aug 2020 13:31:49 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0082.hostedemail.com [216.40.44.82]) by kanga.kvack.org (Postfix) with ESMTP id 841F18D0003 for ; Fri, 14 Aug 2020 13:31:49 -0400 (EDT) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 4B472181AEF23 for ; Fri, 14 Aug 2020 17:31:49 +0000 (UTC) X-FDA: 77149866738.21.hat54_160ab3b26ffe Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin21.hostedemail.com (Postfix) with ESMTP id 102BA180442C0 for ; Fri, 14 Aug 2020 17:31:49 +0000 (UTC) X-Spam-Summary: 1,0,0,43e15af2c80e2492,d41d8cd98f00b204,minchan.kim@gmail.com,,RULES_HIT:1:2:41:355:379:541:800:960:966:973:988:989:1260:1311:1314:1345:1359:1437:1515:1605:1730:1747:1777:1792:2194:2196:2198:2199:2200:2201:2393:2559:2562:2693:2731:2739:2898:2899:3138:3139:3140:3141:3142:3865:3866:3867:3868:3870:3871:3872:4050:4321:4385:4605:5007:6117:6119:6120:6261:6653:7875:7903:8957:9108:10004:11026:11473:11658:11914:12043:12219:12291:12294:12296:12297:12438:12517:12519:12555:12683:12895:12986:13894:14096:21080:21094:21323:21324:21433:21444:21451:21627:21740:21990:30054:30070:30074,0,RBL:209.85.214.193:@gmail.com:.lbl8.mailshell.net-62.50.0.100 66.100.201.100;04yfknfg67h46y1umij1d5dm3iynmopkoa6eu9zekssj4zrjkwhnf4pncuhe4sg.crmqds1jt3cgzokut7thmcadzb95r1q3w4r78pf6b69xbddnug6iyx8nonyrzj6.k-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: hat54_160ab3b26ffe X-Filterd-Recvd-Size: 10428 Received: from mail-pl1-f193.google.com (mail-pl1-f193.google.com [209.85.214.193]) by imf12.hostedemail.com (Postfix) with ESMTP for ; Fri, 14 Aug 2020 17:31:48 +0000 (UTC) Received: by mail-pl1-f193.google.com with SMTP id y6so4482737plt.3 for ; Fri, 14 Aug 2020 10:31:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=03psx5ZOedEdpxuYD/LdYYTJpY1uy6XJwUcDuinG3Cc=; b=BPRDYjHM6cKVpglbeF2tnlLtTehthioMQFUigruftZU7xygDMGcbCggu6qsKbHiwl3 NUyZtccHnAhZoFXYBvObuH5l0S6hAj0nAdLIdPw8JVTqFzBKWSXSCQiOx5/V3n1LFMvh CM3xogZRBYOpVMOHp3MgLdys7ampiJFUW2Mp6XN91WSphqfwfQ8/Ie8r8BmDf11BC1i2 bO3jumGwa67BT7bCWVVV7FmQe0+p842bzJUbM2HvMRUu3okJ5Cu2kmEamsOe3A6PnV6t RPzeBoShUfZaxXKxwGPcDdjyxxASSYFWWvMRnWKzjNBHHJp8ndRqVuqzfTZQLgfhxsIS 5R0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=03psx5ZOedEdpxuYD/LdYYTJpY1uy6XJwUcDuinG3Cc=; b=nuu5QdOemg3BPOTvK+zdg5kLZKA1pqF1xxw9pozcth6LPsKzSx3lCTKUOK9arKEcgs t/OAPYBm6bRcy2QfWy2Sess+1DWfDSYNLsYR7HT1ZkRvUPx8wyShxxdOa5s5SlGrs5oZ d6n4DtFYNMperr0Mvbsm0tBD38DiZXHBYTnu1p6lbZZGsCUfxPF5CxN+1byn2l3DoAO9 0M5zaxX7CEcz4U+SVkFl0UFFspwTt0+4dPdAZ0k79SITh1WLqppO1jxdpgQZ4gE4LD/G ERT/S0rGxZAUS0peTj1y72dj2Ium650PyhBG3xz0aAW9RyS/HZOdPHOGui8p2U9t27xg oZNA== X-Gm-Message-State: AOAM533CG5y2CClKveO5H+Uuvp4XWEdIKFULgDG8HOQ0lt3QZTdUMfXG yWsKJE7x7Xb5cWaQYcRbjQQ= X-Google-Smtp-Source: ABdhPJwVx8zHzA6/MAdAGM/g3uPg2tQ+jbdGavkz5sRl5XY4E2wA1MLYnu2wfsmqkf9rvzjcd2zZaw== X-Received: by 2002:a17:902:8ecb:: with SMTP id x11mr2657884plo.13.1597426307637; Fri, 14 Aug 2020 10:31:47 -0700 (PDT) Received: from bbox-1.mtv.corp.google.com ([2620:15c:211:1:7220:84ff:fe09:5e58]) by smtp.gmail.com with ESMTPSA id n22sm8522973pjq.25.2020.08.14.10.31.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Aug 2020 10:31:46 -0700 (PDT) From: Minchan Kim To: Andrew Morton Cc: linux-mm , Joonsoo Kim , Vlastimil Babka , John Dias , Suren Baghdasaryan , pullip.cho@samsung.com, Minchan Kim Subject: [RFC 6/7] mm: make alloc_pages_bulk best effort Date: Fri, 14 Aug 2020 10:31:30 -0700 Message-Id: <20200814173131.2803002-7-minchan@kernel.org> X-Mailer: git-send-email 2.28.0.220.ged08abb693-goog In-Reply-To: <20200814173131.2803002-1-minchan@kernel.org> References: <20200814173131.2803002-1-minchan@kernel.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 102BA180442C0 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam03 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: alloc_pages_bulk takes best effort approach to make high order pages so it should keep going with further range even though it encounters non-movable pages. To achieve it, this patch introduces ALLOW_ISOLATE_FAILURE flags for start_isolate_page_range and alloc_bulk in compact_control so it could proceed with further range although some failures happen from isolation/migration/ free page isolation. What it does with new flag are * skip the pageblock if it's not affordable for changing the block MIGRATE_ISOLATE * skip the pageblock if it couldn't migrate a page by some reasons * skip the pageblock if it couldn't isolate free pages by some reasons Signed-off-by: Minchan Kim --- include/linux/page-isolation.h | 1 + mm/compaction.c | 17 +++++++++++++---- mm/internal.h | 1 + mm/page_alloc.c | 32 +++++++++++++++++++++++--------- mm/page_isolation.c | 4 ++++ 5 files changed, 42 insertions(+), 13 deletions(-) diff --git a/include/linux/page-isolation.h b/include/linux/page-isolation.h index 572458016331..b8b6789d2bd9 100644 --- a/include/linux/page-isolation.h +++ b/include/linux/page-isolation.h @@ -32,6 +32,7 @@ static inline bool is_migrate_isolate(int migratetype) #define MEMORY_OFFLINE 0x1 #define REPORT_FAILURE 0x2 +#define ALLOW_ISOLATE_FAILURE 0x4 struct page *has_unmovable_pages(struct zone *zone, struct page *page, int migratetype, int flags); diff --git a/mm/compaction.c b/mm/compaction.c index 1e4392f6fec3..94dee139ce0d 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -748,15 +748,24 @@ isolate_freepages_range(struct compact_control *cc, break; isolated = isolate_freepages_block(cc, &isolate_start_pfn, - block_end_pfn, freepage_list, 0, true); + block_end_pfn, freepage_list, + cc->alloc_bulk ? 1 : 0, + cc->alloc_bulk ? false : true); /* * In strict mode, isolate_freepages_block() returns 0 if * there are any holes in the block (ie. invalid PFNs or - * non-free pages). + * non-free pages) so just stop the isolation in the case. + * However, in alloc_bulk mode, we could check further range + * to find affordable high order free pages so keep going + * with next pageblock. */ - if (!isolated) - break; + if (!isolated) { + if (!cc->alloc_bulk) + break; + pfn = block_end_pfn; + continue; + } /* * If we managed to isolate pages, it is always (1 << n) * diff --git a/mm/internal.h b/mm/internal.h index f9b86257fae2..71f00284326e 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -244,6 +244,7 @@ struct compact_control { bool contended; /* Signal lock or sched contention */ bool rescan; /* Rescanning the same pageblock */ bool alloc_contig; /* alloc_contig_range allocation */ + bool alloc_bulk; /* alloc_pages_bulk allocation */ int isolate_order; /* minimum order isolated from buddy */ }; diff --git a/mm/page_alloc.c b/mm/page_alloc.c index cdf956feae80..66cea47ae2b6 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -8359,8 +8359,8 @@ static int __alloc_contig_migrate_range(struct compact_control *cc, /* This function is based on compact_zone() from compaction.c. */ unsigned int nr_reclaimed; unsigned long pfn = start; - unsigned int tries = 0; - int ret = 0; + unsigned int tries; + int ret; struct migration_target_control mtc = { .nid = zone_to_nid(cc->zone), .gfp_mask = GFP_USER | __GFP_MOVABLE | __GFP_RETRY_MAYFAIL, @@ -8368,6 +8368,8 @@ static int __alloc_contig_migrate_range(struct compact_control *cc, migrate_prep(); +next: + tries = ret = 0; while (pfn < end || !list_empty(&cc->migratepages)) { if (fatal_signal_pending(current)) { ret = -EINTR; @@ -8396,15 +8398,25 @@ static int __alloc_contig_migrate_range(struct compact_control *cc, } if (ret < 0) { putback_movable_pages(&cc->migratepages); - return ret; + if (cc->alloc_bulk && pfn < end) { + /* + * -EINTR means current process has fatal signal. + * -ENOMEM means there is no free memory. + * In these cases, stop the effort to work with + * next blocks. + */ + if (ret != -EINTR && ret != -ENOMEM) + goto next; + } } - return 0; + return ret; } static int __alloc_contig_range(unsigned long start, unsigned long end, unsigned int migratetype, gfp_t gfp_mask, unsigned int alloc_order, - struct list_head *freepage_list) + struct list_head *freepage_list, + bool alloc_bulk) { unsigned long outer_start, outer_end; unsigned int order; @@ -8422,6 +8434,7 @@ static int __alloc_contig_range(unsigned long start, unsigned long end, .gfp_mask = current_gfp_context(gfp_mask), .alloc_contig = true, .isolate_order = alloc_order, + .alloc_bulk = alloc_bulk, }; INIT_LIST_HEAD(&cc.migratepages); @@ -8450,7 +8463,8 @@ static int __alloc_contig_range(unsigned long start, unsigned long end, */ ret = start_isolate_page_range(pfn_max_align_down(start), - pfn_max_align_up(end), migratetype, 0); + pfn_max_align_up(end), migratetype, + alloc_bulk ? ALLOW_ISOLATE_FAILURE : 0); if (ret < 0) return ret; @@ -8512,7 +8526,7 @@ static int __alloc_contig_range(unsigned long start, unsigned long end, } /* Make sure the range is really isolated. */ - if (test_pages_isolated(outer_start, end, 0)) { + if (!alloc_bulk && test_pages_isolated(outer_start, end, 0)) { pr_info_ratelimited("%s: [%lx, %lx) PFNs busy\n", __func__, outer_start, end); ret = -EBUSY; @@ -8591,7 +8605,7 @@ int alloc_contig_range(unsigned long start, unsigned long end, LIST_HEAD(freepage_list); return __alloc_contig_range(start, end, migratetype, - gfp_mask, 0, &freepage_list); + gfp_mask, 0, &freepage_list, false); } /** @@ -8628,7 +8642,7 @@ int alloc_pages_bulk(unsigned long start, unsigned long end, return -EINVAL; ret = __alloc_contig_range(start, end, migratetype, - gfp_mask, order, &freepage_list); + gfp_mask, order, &freepage_list, true); if (ret) return ret; diff --git a/mm/page_isolation.c b/mm/page_isolation.c index 242c03121d73..6208db89a31b 100644 --- a/mm/page_isolation.c +++ b/mm/page_isolation.c @@ -154,6 +154,8 @@ __first_valid_page(unsigned long pfn, unsigned long nr_pages) * and PageOffline() pages. * REPORT_FAILURE - report details about the failure to * isolate the range + * ALLOW_ISOLATE_FAILURE - skip the pageblock of the range + * whenever we fail to set MIGRATE_ISOLATE * * Making page-allocation-type to be MIGRATE_ISOLATE means free pages in * the range will never be allocated. Any free pages and pages freed in the @@ -190,6 +192,8 @@ int start_isolate_page_range(unsigned long start_pfn, unsigned long end_pfn, page = __first_valid_page(pfn, pageblock_nr_pages); if (page) { if (set_migratetype_isolate(page, migratetype, flags)) { + if (flags & ALLOW_ISOLATE_FAILURE) + continue; undo_pfn = pfn; goto undo; }