From patchwork Wed Jul 20 14:06:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zach O'Keefe X-Patchwork-Id: 12924027 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 29BF5C43334 for ; Wed, 20 Jul 2022 14:06:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7E42F6B0073; Wed, 20 Jul 2022 10:06:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 794168E0001; Wed, 20 Jul 2022 10:06:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 635BA6B0075; Wed, 20 Jul 2022 10:06:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 530EE6B0073 for ; Wed, 20 Jul 2022 10:06:22 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 300991205B1 for ; Wed, 20 Jul 2022 14:06:22 +0000 (UTC) X-FDA: 79707653004.04.0AE7F26 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) by imf15.hostedemail.com (Postfix) with ESMTP id AAD10A008D for ; Wed, 20 Jul 2022 14:06:21 +0000 (UTC) Received: by mail-pj1-f73.google.com with SMTP id pg9-20020a17090b1e0900b001f076f7d15eso1270981pjb.5 for ; Wed, 20 Jul 2022 07:06:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=eS/0TDZ57j7zzZRooTjg5w5BNN07jR34xInjcUrqOSk=; b=sHOjDbjyuIQdDcTE8Obi8hnGKxuPEk2x/fZ9V413IAVimFiMjgOt4Mfkg2wYlz9Z6W c7uaSLW8wOF4YKCmqaxbNne7KBBtZapmQPYM3Fy2TvpVwm1cbzC2x+qMtyffSNyR4bdk lO5FRYjG9XQiKczz96mv96vBRT8ZraI4F5sTQrWR/gHS3Ykh/JOXpb89EnYgU4ZhO1Ie 7j3fCjF+C3nFp+ahikRYuPf87uuMVHnOYnwoFl/AHSmgCTnEG7pXMJZ3kA6FIizoygYu AGL44aOXGdum2qYpMUpdTB0y6myUh+l4SIvuFFDJ58NBt/i6BeDwu/VtO1MD4yLd/bVG Sfbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=eS/0TDZ57j7zzZRooTjg5w5BNN07jR34xInjcUrqOSk=; b=UNUq0+/ooX2D4IJD4kz+jFDrjBTrh7SPQh2DwHvHAXt+1riXQVww1jgYuqt/bFCZIZ WLmuf1pZ95/GYMLpXCznqhf005+dV8kqfNRSrLM2OxI4HdJdEh3qfE0wMxfBx2R9rXOu z5+z1z49VuutyCGsBEZ2dTSFAQcF+vSygGeNlBtihINSIpvyfsgowp1N3kTR9L4Soijp EBdarzcCMGwhPXXvBbI9m7A4XrJkMfmCt2CRm3t/2yqsadcYcfc6QUy6vF5lF5GB82V2 bOb0ztLNLLvx7D6njYt/9oevbTAPkP3GDj4S+TJHVcF72p9wlQHirFzi2vBDaSEKJm0P WjDg== X-Gm-Message-State: AJIora95xyKke/PE89bDiy5XNOIGWFG50BTAc6wvdMYO9ORayks+Zrng ZlZT8fhWfa3MVVorTPUOO19OSFM16SLu X-Google-Smtp-Source: AGRyM1vUJiy+ekO60jWK2XBEm40biWIDU7lblvBsX8GwFInAgpAo9b7s6iC67yR9zxZ+yJHm/Oy7Nq1KFFpJ X-Received: from zokeefe3.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1b6]) (user=zokeefe job=sendgmr) by 2002:a17:902:b198:b0:16c:1c13:cd8d with SMTP id s24-20020a170902b19800b0016c1c13cd8dmr38712413plr.92.1658325980700; Wed, 20 Jul 2022 07:06:20 -0700 (PDT) Date: Wed, 20 Jul 2022 07:06:00 -0700 In-Reply-To: <20220720140603.1958773-1-zokeefe@google.com> Message-Id: <20220720140603.1958773-2-zokeefe@google.com> Mime-Version: 1.0 References: <20220720140603.1958773-1-zokeefe@google.com> X-Mailer: git-send-email 2.37.0.170.g444d1eabd0-goog Subject: [PATCH mm-unstable 1/4] mm/khugepaged: Use minimal bits to store num page < HPAGE_PMD_NR From: "Zach O'Keefe" To: Andrew Morton Cc: linux-mm@kvack.org, Hugh Dickins , Yang Shi , Miaohe Lin , "Zach O'Keefe" ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1658325981; a=rsa-sha256; cv=none; b=YIPCXdYXOYuqnQlEuuEu4xry8IVhvXRH207KGfVhUDKWzcfBlwM6bZuciZzhkmIU+xjK/v Vby/6GPji78NtiCkCAZDF6KtT6c8rA/PMVuEDTmR2VMCoL4WtYr2xmFLCpkbcDiz2xhBjt 2tkkI62Np6wXf+htz47d2DL6Rl0TPjE= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=sHOjDbjy; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf15.hostedemail.com: domain of 33AvYYgcKCHEodZTTUTVddVaT.RdbaXcjm-bbZkPRZ.dgV@flex--zokeefe.bounces.google.com designates 209.85.216.73 as permitted sender) smtp.mailfrom=33AvYYgcKCHEodZTTUTVddVaT.RdbaXcjm-bbZkPRZ.dgV@flex--zokeefe.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1658325981; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=eS/0TDZ57j7zzZRooTjg5w5BNN07jR34xInjcUrqOSk=; b=3SMWKjegtd4VgT1ckojQ/LopZF64fCmXfEcrMItkme6fDr4w5SWUeCDCeDJv4tAF633Pgg C2VPfnUl0fDKVpAZ1Z2NEy8O7RtMDS29FcJ+hyVXZiEHe1R32bA3jVjCcqLKz3mg18YSw+ uYiWA3J7oI1rP8gM+RZcC599AFYG2jA= X-Rspam-User: Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=sHOjDbjy; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf15.hostedemail.com: domain of 33AvYYgcKCHEodZTTUTVddVaT.RdbaXcjm-bbZkPRZ.dgV@flex--zokeefe.bounces.google.com designates 209.85.216.73 as permitted sender) smtp.mailfrom=33AvYYgcKCHEodZTTUTVddVaT.RdbaXcjm-bbZkPRZ.dgV@flex--zokeefe.bounces.google.com X-Stat-Signature: ygd1asa4t47k9x4a8dupf1cq7ta4dczh X-Rspamd-Queue-Id: AAD10A008D X-Rspamd-Server: rspam02 X-HE-Tag: 1658325981-254083 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: Minimally, node_load[] entries just need to be able to hold the maximum value of HPAGE_PMD_NR, which is compile-time defined per-arch based on PMD_SHIFT and PAGE_SHIFT. node_load[] is only written either via memset(), or with via post-increment. struct collapse_control may be allocated via kmalloc() in other collapse contexts, and MAX_NUMNODES may be arbitrarily large. #define the underlying type of node_load[] based off HPAGE_PMD_NR to avoid excessive memory allocated for this struct. Fixes: 3b07f3bb225a ("mm/khugepaged: add struct collapse_control") Link: https://lore.kernel.org/linux-mm/Ys2CeIm%2FQmQwWh9a@google.com/ Signed-off-by: Zach O'Keefe Reviewed-by: Yang Shi Acked-by: David Rientjes --- mm/khugepaged.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 69990dacde14..ecd28bfeab60 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -92,8 +92,11 @@ struct collapse_control { bool is_khugepaged; /* Num pages scanned per node */ - int node_load[MAX_NUMNODES]; - +#if HPAGE_PMD_ORDER < 16 + u16 node_load[MAX_NUMNODES]; +#else + u32 node_load[MAX_NUMNODES]; +#endif /* Last target selected in hpage_collapse_find_target_node() */ int last_target_node; };