From patchwork Tue Dec 3 09:47:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13892062 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6BD1BD4979A for ; Tue, 3 Dec 2024 09:47:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F265B6B0092; Tue, 3 Dec 2024 04:47:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id EFD036B0093; Tue, 3 Dec 2024 04:47:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D9CFA6B0095; Tue, 3 Dec 2024 04:47:52 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id B549E6B0092 for ; Tue, 3 Dec 2024 04:47:52 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 637F140FA2 for ; Tue, 3 Dec 2024 09:47:52 +0000 (UTC) X-FDA: 82853170680.06.FF0318F Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf23.hostedemail.com (Postfix) with ESMTP id 87C2B14001B for ; Tue, 3 Dec 2024 09:47:41 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=J+8KJXlH; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf23.hostedemail.com: domain of dhildenb@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhildenb@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733219258; a=rsa-sha256; cv=none; b=a8ZArMDqSe4ihyQ3uPXK7xZBT9ecDunP4VqYyz/atC8Nsnp0l9ZXIw/V/CblfcXt0tmb5A yf2dpr0buwJH8HqKP4CB9w7eqjqT/rgX3Znrv56b8lxdYCTnI+EISYZiMPuwhRJiIJa7wc jlrm5ra5OIOD3x3/pohYLfpaEAWLlsQ= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=J+8KJXlH; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf23.hostedemail.com: domain of dhildenb@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhildenb@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733219258; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=cjBW/vjYP3nNfvObrA09IpRDh5cADITJHgvHLWqOgrU=; b=lmqOVYWZ5mTpgQx+63LkUaXKVr3S3NEliNbDjIVr4RHeAfXWZGtnxQrWuC3FUWExNWpVh6 yslWBBFc3vsbTMCEIaR0Njr7+RVv1toROacq2RNmbUlmSMN5crrK9CJFiHnmBjXZh7jz9V H1LCy4JhDvCCsFut/yVDCPeAUilzKuw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733219269; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cjBW/vjYP3nNfvObrA09IpRDh5cADITJHgvHLWqOgrU=; b=J+8KJXlHgrm+FfEQg5xMCdL1NTxTbh1oipGvqUPzLwY92UiMNa8BcAQwBXSgBO3JO5CiMD rINDRcwxazX2HBreRdAYqNMEVTE4X32S1nCc9iizwSkwidg/ipUWapAD6FJZmn/Ape65/6 M2Om14b3RSOl9LWYvR8ltabCF0kocJg= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-255-B8_a301OMD6gClRE5DW86g-1; Tue, 03 Dec 2024 04:47:48 -0500 X-MC-Unique: B8_a301OMD6gClRE5DW86g-1 X-Mimecast-MFC-AGG-ID: B8_a301OMD6gClRE5DW86g Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-385e5e3bf60so2048157f8f.1 for ; Tue, 03 Dec 2024 01:47:48 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733219267; x=1733824067; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cjBW/vjYP3nNfvObrA09IpRDh5cADITJHgvHLWqOgrU=; b=KizoiKFZyCoM2VWz0nCHSb2jUpSwKXj0mKOL60wPXHSx86cFXGBLaD9D9JoNQy7nip j+QjwhJHAC7CT4nHYfgn17tC38N4ZYcxw2yzqWl5y3QJl6E/LOxEZzf/G4T6aGxL1Q8D ya3O4HB5o3Vjv6KDcCcKiyKBkVvVut/tvg9Vodivio0xM74mnLFxYADVu/VTd1mlekVq 4IpcQ+dtFA5Avr4WJlC19F2RaYVajqPHxUhGkYnrm9Hh+LDRcOrPE4+tqTf9dx2Dt4VO gI9d0wSsdKc2/SQWZ9WLI6CZPt2b2B/fysv97kj20J5rhPxlKIlugt0M6P2b/oYPX04q 8rlg== X-Gm-Message-State: AOJu0Yz58D7INPUFH2JPw5KqMhfMnAT0wpHxU2QIAg1bjM+SGPS/Gp2/ TPGn9IaKoZhFLwduP5H+2vuQD+jJIDAiSfeso+1qPzK0hpIA3XZpd8/px7OO9UFZ4X7TgmWlkNF ZXbiFKnRuEZ9JWVFuB9Z23QA8tx9rXnhg8MMS1yIumGvkapS1 X-Gm-Gg: ASbGncsB0BumkRxkyuf8C193cM8WFhH8HVuT+sdAaD058K97MIPUop8SzoZmItZB7DP PBxgcrdTU6Hw9kqnRqLtWbVemqT4ayT0mnA7WH8QB5cQgER4kv/7L3F/tgk6Gi0xtetL8LQKzAK iaWJCTt78jqI3XPRvO7IAv0fn/+niwSXgInD8InCXhvIRNwwRR6h9oCm3/DBX0ExBWbupHe03c4 uUvMxFqHSQ1xkcRs+HoJUKB1/i7XVUGeRbzRFBperkZ4bfyssbPi485Q0aB8YoT9EBaCAnyygFp +Obz5yu+YGMt+E29s84h5xvpZveWUq0s77Y= X-Received: by 2002:a05:6000:70c:b0:385:efc7:932d with SMTP id ffacd0b85a97d-385fd423ae4mr1564033f8f.46.1733219267478; Tue, 03 Dec 2024 01:47:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IGaOJ9gxKaUnP3CbsR1qXN6hxrElYasKjqPVFXIuPLpn506OYh8TYc8ohv1ITpz8dyfapfkFg== X-Received: by 2002:a05:6000:70c:b0:385:efc7:932d with SMTP id ffacd0b85a97d-385fd423ae4mr1564014f8f.46.1733219267074; Tue, 03 Dec 2024 01:47:47 -0800 (PST) Received: from localhost (p200300cbc7461b00fd9ec26cc5521de7.dip0.t-ipconnect.de. [2003:cb:c746:1b00:fd9e:c26c:c552:1de7]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-385e4a54b71sm9361779f8f.79.2024.12.03.01.47.44 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 03 Dec 2024 01:47:45 -0800 (PST) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, David Hildenbrand , Andrew Morton , Oscar Salvador , Zi Yan , Michael Ellerman , Nicholas Piggin , Christophe Leroy , Naveen N Rao , Madhavan Srinivasan Subject: [PATCH RESEND v2 4/6] mm/page_alloc: sort out the alloc_contig_range() gfp flags mess Date: Tue, 3 Dec 2024 10:47:30 +0100 Message-ID: <20241203094732.200195-5-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241203094732.200195-1-david@redhat.com> References: <20241203094732.200195-1-david@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: suyUrLHaw2q9mO66x-wuSByDlwuTjsI0_jzuZ4uEV0E_1733219267 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true X-Stat-Signature: 9cpouqyb99cbsh1s1o39ue3h8topc3g7 X-Rspam-User: X-Rspamd-Queue-Id: 87C2B14001B X-Rspamd-Server: rspam08 X-HE-Tag: 1733219261-62779 X-HE-Meta: U2FsdGVkX1+TXG6zFTfDO9B/9vte1LVaXFqHVSY63/R/Zb7RIaj0AsJFQD9dRORATw1mgpcUeivR/P3uyP3dgnLwlmRkLyHkHt8Lsg0NwWus1yee+Ttfmwi+xdJ2FBEG7c1XzsQHjbRPlDzJtBQ341HzUIc7zBcneLR1zrL3UsQmespGKWXsvVf8vGT1lh7aluTpEqP6fLE250MIpuPM8Huy3+sAwv2vafxEnCI0UevTnBb1cn1weDC21p/9j9QuWTmnIlfPj4nfJ0+ut0Ow/MLOh4/CPnjmwMDxtEA5bdNJUH3SpTtFsuOL+i6F9PfXNExqh+3sUTI4S2VSlW/ziJ8kxF7JOgh/yNBLktG0QnrMZt4I5/37Ipm7HKuIaeBAVszPayaPC6ZfXW7YNqCiAQEnv6Q5bOustrnQgzka7zKg98rcWFQixhJs/iu7qDqdzRvDQm/Ko2bhSBKoNRCSqoht0KW9Mhyy7LuHFdiytpDIB1fpelf5SJpD1dBA5hqxvyIuBqXS77vds733+FcD8qyXSOjnG3vkicLFUpTQoWzwQJLngJzqeEw65xpEb3bsp1afCBmylJU1O+j2xJDj6qzIgt7jgImmQXBVnVUB7jSYfmzTVe1iMH2fcck0DzYo2od1v9b3vsExKD2MVqenr2CtQ/NycsM1AstiOojL3Dugmu+AsZ04YqWvf4ZLvPLaG34c0VKpy1cLlPL0uPNPWAyDW9Tdx/xfQSQn1nXQgVSSEvq9KDHe9ktgG7j1FZ8/KpsFAa2cJ+pQ5MwR/8nEVProzdnuQkBoCyZF6rDmp/NMq1KLfhWCQCk2wkh0KvrMR1Vr3DIPjrb/xhT/auagePcFDCe/WtCE249r8GQLvFLG4zgB7SyOTtEezWVYrssTM8fqtvOa8pvcVCQbu4t1YskoI3WHO8POy5oLb3B4D8DUcZO0TEdx0vzIe5jC5BTQAzdxfRLmU6WgGBVRhXo e/EfgMtn j6OYGvcWy8NHdGsUOB5GSSeRYD7k9vgGCwhdxaDve6HIWQ+O2XArj7dPD+JXj0jALhsYTijueBicmc8I7mODQ8FTQElxGO1zTQAShLFj+/T8+HBwbzOJP0tTDZcEqv5G4iNwA6VHCoFUJZx0TEMBa71hqoH8MhiN7++Nmb6BvSTyqtkjaZn6LYTFKU74MnIWdGAdyMSJsvzR1txQWA2grforND7IqClYg8fiADTWEZgncjLVyh2N0jh+nH0FRX//2jmA1/2Kq4EC7mO/A9paSpgLUifDwvS2qAUcBMFd94EjnA36iP1aeL1Oouq+UwKRMK97rgsjzJmCOGMaOAoVGic0KOd/okMSvGtQq4/m/6xGy6d13zEZdxsnCXk7cOcJc0lhgYnthYvb2yUL5o6GNYndhbmyoEDpHJJPwnQqMxyNCVGe30NYxU0lhjJYOhWq6ymOMVSo+GhD7qWj8GRtQ2KXNOf7/5Bn8n9/ZEBK07cHHKCYUq87adHHjWUCYf1zCQ0kX 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: List-Subscribe: List-Unsubscribe: It's all a bit complicated for alloc_contig_range(). For example, we don't support many flags, so let's start bailing out on unsupported ones -- ignoring the placement hints, as we are already given the range to allocate. While we currently set cc.gfp_mask, in __alloc_contig_migrate_range() we simply create yet another GFP mask whereby we ignore the reclaim flags specify by the caller. That looks very inconsistent. Let's clean it up, constructing the gfp flags used for compaction/migration exactly once. Update the documentation of the gfp_mask parameter for alloc_contig_range() and alloc_contig_pages(). Acked-by: Zi Yan Signed-off-by: David Hildenbrand Reviewed-by: Vlastimil Babka Reviewed-by: Oscar Salvador --- mm/page_alloc.c | 48 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index ce7589a4ec01..54594cc4f650 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -6294,7 +6294,7 @@ static int __alloc_contig_migrate_range(struct compact_control *cc, int ret = 0; struct migration_target_control mtc = { .nid = zone_to_nid(cc->zone), - .gfp_mask = GFP_USER | __GFP_MOVABLE | __GFP_RETRY_MAYFAIL, + .gfp_mask = cc->gfp_mask, .reason = MR_CONTIG_RANGE, }; struct page *page; @@ -6390,6 +6390,39 @@ static void split_free_pages(struct list_head *list) } } +static int __alloc_contig_verify_gfp_mask(gfp_t gfp_mask, gfp_t *gfp_cc_mask) +{ + const gfp_t reclaim_mask = __GFP_IO | __GFP_FS | __GFP_RECLAIM; + const gfp_t action_mask = __GFP_COMP | __GFP_RETRY_MAYFAIL | __GFP_NOWARN; + const gfp_t cc_action_mask = __GFP_RETRY_MAYFAIL | __GFP_NOWARN; + + /* + * We are given the range to allocate; node, mobility and placement + * hints are irrelevant at this point. We'll simply ignore them. + */ + gfp_mask &= ~(GFP_ZONEMASK | __GFP_RECLAIMABLE | __GFP_WRITE | + __GFP_HARDWALL | __GFP_THISNODE | __GFP_MOVABLE); + + /* + * We only support most reclaim flags (but not NOFAIL/NORETRY), and + * selected action flags. + */ + if (gfp_mask & ~(reclaim_mask | action_mask)) + return -EINVAL; + + /* + * Flags to control page compaction/migration/reclaim, to free up our + * page range. Migratable pages are movable, __GFP_MOVABLE is implied + * for them. + * + * Traditionally we always had __GFP_HARDWALL|__GFP_RETRY_MAYFAIL set, + * keep doing that to not degrade callers. + */ + *gfp_cc_mask = (gfp_mask & (reclaim_mask | cc_action_mask)) | + __GFP_HARDWALL | __GFP_MOVABLE | __GFP_RETRY_MAYFAIL; + return 0; +} + /** * alloc_contig_range() -- tries to allocate given range of pages * @start: start PFN to allocate @@ -6398,7 +6431,9 @@ static void split_free_pages(struct list_head *list) * #MIGRATE_MOVABLE or #MIGRATE_CMA). All pageblocks * in range must have the same migratetype and it must * be either of the two. - * @gfp_mask: GFP mask to use during compaction + * @gfp_mask: GFP mask. Node/zone/placement hints are ignored; only some + * action and reclaim modifiers are supported. Reclaim modifiers + * control allocation behavior during compaction/migration/reclaim. * * The PFN range does not have to be pageblock aligned. The PFN range must * belong to a single zone. @@ -6424,11 +6459,14 @@ int alloc_contig_range_noprof(unsigned long start, unsigned long end, .mode = MIGRATE_SYNC, .ignore_skip_hint = true, .no_set_skip_hint = true, - .gfp_mask = current_gfp_context(gfp_mask), .alloc_contig = true, }; INIT_LIST_HEAD(&cc.migratepages); + gfp_mask = current_gfp_context(gfp_mask); + if (__alloc_contig_verify_gfp_mask(gfp_mask, (gfp_t *)&cc.gfp_mask)) + return -EINVAL; + /* * What we do here is we mark all pageblocks in range as * MIGRATE_ISOLATE. Because pageblock and max order pages may @@ -6571,7 +6609,9 @@ static bool zone_spans_last_pfn(const struct zone *zone, /** * alloc_contig_pages() -- tries to find and allocate contiguous range of pages * @nr_pages: Number of contiguous pages to allocate - * @gfp_mask: GFP mask to limit search and used during compaction + * @gfp_mask: GFP mask. Node/zone/placement hints limit the search; only some + * action and reclaim modifiers are supported. Reclaim modifiers + * control allocation behavior during compaction/migration/reclaim. * @nid: Target node * @nodemask: Mask for other possible nodes *