From patchwork Mon Dec 2 12:58:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13895603 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 28D8BE7716C for ; Thu, 5 Dec 2024 15:36:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 572326B0100; Thu, 5 Dec 2024 10:19:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 09C436B0139; Thu, 5 Dec 2024 10:19:27 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8B07F6B00BF; Thu, 5 Dec 2024 10:19:15 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 484E16B0082 for ; Mon, 2 Dec 2024 07:58:46 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id C12A981BA3 for ; Mon, 2 Dec 2024 12:58:45 +0000 (UTC) X-FDA: 82850023032.30.F2FA29A Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf01.hostedemail.com (Postfix) with ESMTP id EED9C4000E for ; Mon, 2 Dec 2024 12:58:34 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=QL75V15f; spf=pass (imf01.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733144315; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=BDcVjfuXZieBJ7OFGqsXEKMWupL5rjT8Tdv/3NGIh+8=; b=VhGmE6lEMr4XQjXpx4xnJKLQD2QVVwjwcN3OWQclkmL/waDr71xF8FZRCmWnrtzA6swNym O2fQWG2kljzYZ/65ta52mXG92CBZJ0RRXQLyDN95mnOpE0C7qa/iaF9j0yfdsUxBeQaQ4f NPMGFOp+8Sgniq3GfhChkn00Cp4lciI= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=QL75V15f; spf=pass (imf01.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733144315; a=rsa-sha256; cv=none; b=u+CH2NnL4W8HQjol/YA+3xSlCDEXHMMVB/k5MdKkX7EnBgcrDZuQuaXxWjCEvmM5EzHUYu dtJIi76Eq0Diu40JBXeHC8s3+HF1CmlepFjD+Urx7ya0ZlVOOsPkWbcBfbmN6zB61YfBrY cepntCff6xM+xePBsVS6U3VsC2wI8qY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733144323; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BDcVjfuXZieBJ7OFGqsXEKMWupL5rjT8Tdv/3NGIh+8=; b=QL75V15fTW3YIyGg6j2gOEGNAd7TtMkXzVhGzrGBKcm/NqDmlYQ2x6lm4O7bAMkIY4cVnU kmEdcL6bplzhAWsra2V6Zq8NpCUWfpIAT3mrSL6wzifS3q0lLtrQYyS9Gt9QLwpbw562nU F0e+z9G4AiRhUgOhvF9DG9gvEDEr3TY= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-609-guoW4AixOXSxWRl1bTT8Hg-1; Mon, 02 Dec 2024 07:58:42 -0500 X-MC-Unique: guoW4AixOXSxWRl1bTT8Hg-1 X-Mimecast-MFC-AGG-ID: guoW4AixOXSxWRl1bTT8Hg Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 63C71192538B; Mon, 2 Dec 2024 12:58:40 +0000 (UTC) Received: from t14s.cit.tum.de (unknown [10.39.194.150]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D1A9E1955E98; Mon, 2 Dec 2024 12:58:35 +0000 (UTC) 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 v1 4/6] mm/page_alloc: sort out the alloc_contig_range() gfp flags mess Date: Mon, 2 Dec 2024 13:58:10 +0100 Message-ID: <20241202125812.561028-5-david@redhat.com> In-Reply-To: <20241202125812.561028-1-david@redhat.com> References: <20241202125812.561028-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 X-Rspamd-Server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11h9LoHW EdHY7Edt T9Uc3nJu13qo0pNMK5SuSsLn1skTQutWNisw9EQkUMzI7wwigwicbT/fZhE51l9jQpV9x0xzHfBUeNw8UViLU49QkfVGvvVtiDft6T97lzW290i5G1JXFeFJzCAQbM24DmsuF5c+Ienf9EOjuU5tM3XqprUllPd3TllX0Nl3oXIQI+boQaubKF4fhFxpi1djwgWcKnY0VwZIfQ0Vfe8jhlWNOXfzjOlDxycsLembepjL1AbFs37WOjMpZMHSYi+jcRgdN7xleUgvc7N0mqW0Z23Ja1pwx29dPoRSFumKdWqMlUTvKpR+v/WSgCoZh9U2+WO0VevYoETzPU13qLUIcU7S/iq0er8Z3OvWLt/nT4AttJkzU2tjzOdQ15ma8ClXdz4pnPpIqN8t8CYIG7+6syCeSFw== 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(). Signed-off-by: David Hildenbrand --- 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 *