From patchwork Fri Nov 1 16:54:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ma=C3=ADra_Canal?= X-Patchwork-Id: 13859617 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 D3633E6F070 for ; Fri, 1 Nov 2024 16:58:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6F4A36B0099; Fri, 1 Nov 2024 12:58:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 680056B009A; Fri, 1 Nov 2024 12:58:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4F8046B009B; Fri, 1 Nov 2024 12:58:15 -0400 (EDT) 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 2D2956B0099 for ; Fri, 1 Nov 2024 12:58:15 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id DD96F160B1F for ; Fri, 1 Nov 2024 16:58:14 +0000 (UTC) X-FDA: 82738133562.18.23EB59F Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) by imf05.hostedemail.com (Postfix) with ESMTP id 685A9100002 for ; Fri, 1 Nov 2024 16:57:19 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=S3IrxxJW; dmarc=pass (policy=none) header.from=igalia.com; spf=pass (imf05.hostedemail.com: domain of mcanal@igalia.com designates 178.60.130.6 as permitted sender) smtp.mailfrom=mcanal@igalia.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1730480211; 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=CkGKvkV3mc7ind0IGB8Z7rq8Fs5Gz/hW7rWK8pt2t0Q=; b=PzDPz9pgoWB8ANEyD1Pt3ZJN6KquKrOmagcVX6umoQ03YH/QcRTBUXhZGsotqdl2t+BSI8 aW6f984hM/1pf4ZWHttekUcfVOx45MsWgPXQ0nRGcoJ9cIJh9GFGzeiW/eu3jvUmMbIz2s SjAHfDZ+1QOdOvzCdbbVC0agLl4fTYw= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=S3IrxxJW; dmarc=pass (policy=none) header.from=igalia.com; spf=pass (imf05.hostedemail.com: domain of mcanal@igalia.com designates 178.60.130.6 as permitted sender) smtp.mailfrom=mcanal@igalia.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730480211; a=rsa-sha256; cv=none; b=mLYCD1WAEjMr95Zq8lnrPwxjrip4jd3ZqUaJGmWwju80KIxkeRIoDAv5A056QnBQ70adLX jviupu5g5ZRpoXdhzZAwisxal2bDqEDALTQD0Bpu2scopyH8ndxDxfrW8VNxTENOrHfLcH vJwvyvnjr1upyQcOPp6yPCgFrsuukTw= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=CkGKvkV3mc7ind0IGB8Z7rq8Fs5Gz/hW7rWK8pt2t0Q=; b=S3IrxxJWRTtT5fHJKdV2venR33 ozEECWoZpl/tQV/QbSa7EDzHaCXu+o/ivjtn4mwaNPAplGnvQJQvYZU2ag/yo3q6fEOZw0zB6/Gfh 0OSV4Nd7PXCmRbdZqRGK+stMdW2N/eOCIiS/bT1GW7anznvh/UtpU4amuZmhv3AfFLrkUC1SuhXj7 vIUZFt0at6Jc9vezFXf7Abz6VlKT2zkuC1UsWsSQQbC3xJRagkVSsvF6tNnIKwClVJYg1/zuIlljQ /FFyHvnnW21rRgPr2En8tCizZD4BYd1Wj0RIFmZ9fiomODnAdyuCy8p+lDfMH1S9YB7RcNpvDv6IF C+ZJeDqw==; Received: from [187.36.213.55] (helo=morissey..) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1t6uyK-000VPu-6X; Fri, 01 Nov 2024 17:58:05 +0100 From: =?utf-8?q?Ma=C3=ADra_Canal?= To: Jonathan Corbet , Andrew Morton , Hugh Dickins , Barry Song , David Hildenbrand , Ryan Roberts , Baolin Wang , Lance Yang Cc: linux-mm@kvack.org, dri-devel@lists.freedesktop.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-dev@igalia.com, =?utf-8?q?Ma=C3=ADra_Canal?= Subject: [PATCH v5 3/5] mm: move ``get_order_from_str()`` to internal.h Date: Fri, 1 Nov 2024 13:54:07 -0300 Message-ID: <20241101165719.1074234-5-mcanal@igalia.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241101165719.1074234-2-mcanal@igalia.com> References: <20241101165719.1074234-2-mcanal@igalia.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 685A9100002 X-Stat-Signature: db5tuwy8wsf5wp4z8tfb8q3iyrgc9syj X-HE-Tag: 1730480239-786810 X-HE-Meta: U2FsdGVkX1+Gxo5Uql6iz7NWoPnn6TcmUKGWi4b8Pzud/aw+H6WQjrrwwm79AdBvXnk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O3B9zhWHX5IytMUiHT6OVFhLbtdRkchhe+CBmBLIk3lIyKrDVQ1uo/CKNhcmWJiYBphZQ/2owANjr2SvxG/xfe25oOKmaNHW3DOb5x5JOQIvOCbOhTGQpUY7pA9AmEgX2cF1TqWA2QvAO0hbmJwC1I3gMulCLveBQOd7AayJK2STzQsoA8mlnVYsUZHLXv4YTuPI7ZBdQMKGBYZPS0EY/ngwjC0hrzyNWJgf2fJKvecLHVWvjFeoyys 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: In order to implement a kernel parameter similar to ``thp_anon=`` for shmem, we'll need the function ``get_order_from_str()``. Instead of duplicating the function, move the function to a shared header, in which both mm/shmem.c and mm/huge_memory.c will be able to use it. Signed-off-by: MaĆ­ra Canal Reviewed-by: Baolin Wang --- mm/huge_memory.c | 38 +++++++++++++++----------------------- mm/internal.h | 22 ++++++++++++++++++++++ 2 files changed, 37 insertions(+), 23 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index f92068864469..a6edbd8c4f49 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -958,26 +958,6 @@ static int __init setup_transparent_hugepage(char *str) } __setup("transparent_hugepage=", setup_transparent_hugepage); -static inline int get_order_from_str(const char *size_str) -{ - unsigned long size; - char *endptr; - int order; - - size = memparse(size_str, &endptr); - - if (!is_power_of_2(size)) - goto err; - order = get_order(size); - if (BIT(order) & ~THP_ORDERS_ALL_ANON) - goto err; - - return order; -err: - pr_err("invalid size %s in thp_anon boot parameter\n", size_str); - return -EINVAL; -} - static char str_dup[PAGE_SIZE] __initdata; static int __init setup_thp_anon(char *str) { @@ -1007,10 +987,22 @@ static int __init setup_thp_anon(char *str) start_size = strsep(&subtoken, "-"); end_size = subtoken; - start = get_order_from_str(start_size); - end = get_order_from_str(end_size); + start = get_order_from_str(start_size, THP_ORDERS_ALL_ANON); + end = get_order_from_str(end_size, THP_ORDERS_ALL_ANON); } else { - start = end = get_order_from_str(subtoken); + start_size = end_size = subtoken; + start = end = get_order_from_str(subtoken, + THP_ORDERS_ALL_ANON); + } + + if (start == -EINVAL) { + pr_err("invalid size %s in thp_anon boot parameter\n", start_size); + goto err; + } + + if (end == -EINVAL) { + pr_err("invalid size %s in thp_anon boot parameter\n", end_size); + goto err; } if (start < 0 || end < 0 || start > end) diff --git a/mm/internal.h b/mm/internal.h index d5b93c5b6364..5a7302baeed7 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -1291,6 +1291,28 @@ static inline bool alloc_zeroed(void) &init_on_alloc); } +/* + * Parses a string with mem suffixes into its order. Useful to parse kernel + * parameters. + */ +static inline int get_order_from_str(const char *size_str, + unsigned long valid_orders) +{ + unsigned long size; + char *endptr; + int order; + + size = memparse(size_str, &endptr); + + if (!is_power_of_2(size)) + return -EINVAL; + order = get_order(size); + if (BIT(order) & ~valid_orders) + return -EINVAL; + + return order; +} + enum { /* mark page accessed */ FOLL_TOUCH = 1 << 16,