From nobody Sun Nov 24 23:55:59 2024 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 89DD31CBE95; Fri, 1 Nov 2024 16:58:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.60.130.6 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730480298; cv=none; b=GBn74c8+zzlkTvbJ+2e6guwbqhKuAeXoGRTYNPSnVECNnk8boD6LrMqiIeT6e4gN9ROkUS83VsIguYQs9I2kzfS6O00TPjcx8/nZX1GGmW6pMbV1Y51luzFvDaaAywAV0prxTVo1R72AiLgfhWBvM8wV54kN3SmWZ9yLR66I6mQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730480298; c=relaxed/simple; bh=t0gVvn1fm0+Ylnlo8YrHN/+e9/MYu7TlgLFa+Ir0jFM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=o/I8hgYIS/klRIPcrKTDh9DbocD5RUJZxpFcN2+gvj4JA2U080nSknfcWYFb/w6yvXjzAILy0OqOIokEvpJuAS16kGK0nOGxcYIv1zxMBVjCnOTZwPJhqDW97QVsX2Zgnla2ZKO+jCgicoIEvhmBWYc/mzTF/WaRgqUOAAkRkGI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=S3IrxxJW; arc=none smtp.client-ip=178.60.130.6 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="S3IrxxJW" 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=20Canal?= 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=20Canal?= 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable In order to implement a kernel parameter similar to ``thp_anon=3D`` 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=C3=ADra 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=3D", setup_transparent_hugepage); =20 -static inline int get_order_from_str(const char *size_str) -{ - unsigned long size; - char *endptr; - int order; - - size =3D memparse(size_str, &endptr); - - if (!is_power_of_2(size)) - goto err; - order =3D 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 =3D strsep(&subtoken, "-"); end_size =3D subtoken; =20 - start =3D get_order_from_str(start_size); - end =3D get_order_from_str(end_size); + start =3D get_order_from_str(start_size, THP_ORDERS_ALL_ANON); + end =3D get_order_from_str(end_size, THP_ORDERS_ALL_ANON); } else { - start =3D end =3D get_order_from_str(subtoken); + start_size =3D end_size =3D subtoken; + start =3D end =3D get_order_from_str(subtoken, + THP_ORDERS_ALL_ANON); + } + + if (start =3D=3D -EINVAL) { + pr_err("invalid size %s in thp_anon boot parameter\n", start_size); + goto err; + } + + if (end =3D=3D -EINVAL) { + pr_err("invalid size %s in thp_anon boot parameter\n", end_size); + goto err; } =20 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); } =20 +/* + * 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 =3D memparse(size_str, &endptr); + + if (!is_power_of_2(size)) + return -EINVAL; + order =3D get_order(size); + if (BIT(order) & ~valid_orders) + return -EINVAL; + + return order; +} + enum { /* mark page accessed */ FOLL_TOUCH =3D 1 << 16, --=20 2.46.2