From mboxrd@z Thu Jan 1 00:00:00 1970 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 6F1CAECAAA1 for ; Tue, 6 Sep 2022 19:14:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 030596B0072; Tue, 6 Sep 2022 15:14:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F22576B0073; Tue, 6 Sep 2022 15:14:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DC2F68D0001; Tue, 6 Sep 2022 15:14:28 -0400 (EDT) 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 C62CB6B0072 for ; Tue, 6 Sep 2022 15:14:28 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 914D880203 for ; Tue, 6 Sep 2022 19:14:28 +0000 (UTC) X-FDA: 79882611816.09.175711C Received: from mail-oa1-f47.google.com (mail-oa1-f47.google.com [209.85.160.47]) by imf05.hostedemail.com (Postfix) with ESMTP id 5393710007C for ; Tue, 6 Sep 2022 19:14:28 +0000 (UTC) Received: by mail-oa1-f47.google.com with SMTP id 586e51a60fabf-11eab59db71so30507711fac.11 for ; Tue, 06 Sep 2022 12:14:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date; bh=tlzgL+2u0DPV2YOKquX9j8NBDXTqVNnTI8nxgIPmeDw=; b=l6c1itdpZvdYwG4IwaOmjElNQ1FGiBhWuNha2C6U4Q3thHjv8p/d5r5UK5S94F5UOe MqpiTSx0afjPM7mHcg+Aj5H9NA7x177AuBwW0zmHrM1/QsnwD7Nn7au4GXBRm+exjL5N uiryj7adO84x+qx0rsQa0kHCKn3s5scHfWKYpwufTV9acb2OMbDMLP8e6j93oKx9TlDc 51MgYL9VxPCyJgSQ+J5TUk9H1obtBTj9KIDnmxryxanm6AGb6SGxDi38CKjP07WCdr/i 91IhtdAhNvrOr7QMwmS2tR67YYG2giJ/KbjsLWIKP2pPKl3/XCIJacWZUOlFgXOUrONh Ca6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date; bh=tlzgL+2u0DPV2YOKquX9j8NBDXTqVNnTI8nxgIPmeDw=; b=4Lpi+IFAltmkpNlUWq0cDf9aT5unkR/d6MYZ9iJehV2kOP7+xbXBhgXn2Yqh5pZEIy Zj7pvHiFqMKoSTZMgqFSNLY50iL70dO6ffBiDehYiN+uSQJp0hCfQo7S4WP4U49el2Va 2RjoZCT3QyFxIloisZLmPun9pSORgsQbKe5RdUQEV0ihdTsL1DOmgZ6BjwBkDvHcvcVs 15FQjXtNywy0ENWL1zfv4bsSdZ9SCdWKlDKUBulAGGQzysioQsIaOUIjvEqIkbDAcWTy LoBmzdrk0rjDO4OxsmcIu2aC2I+UNiu+EPuIauPmN6vKsqPH0Gq06mCuYDrC6Fda//La Kcfw== X-Gm-Message-State: ACgBeo3XUW2mSJj73xKBzIMhs2JRu0pWfb7I/KFai0qVSUoKB8OujeyB YhLVT4icZYv97/Lc57o0oMwX0XzhDGv2zwg7wEHGokcOCvw5DbCq X-Google-Smtp-Source: AA6agR6Kdl5nytr+LprmxwyKiUqNQTtJ9bJb+UnUtXhQjA/+XJx+gmwOXvnq4rY9lmVgVrr/CzD4cTWE+shLrO8w9PM= X-Received: by 2002:a05:6808:10d5:b0:342:fde4:3766 with SMTP id s21-20020a05680810d500b00342fde43766mr10400144ois.123.1662491667162; Tue, 06 Sep 2022 12:14:27 -0700 (PDT) MIME-Version: 1.0 References: <20220903021221.1130021-1-zokeefe@google.com> In-Reply-To: From: "Zach O'Keefe" Date: Tue, 6 Sep 2022 12:13:51 -0700 Message-ID: Subject: Re: [PATCH mm-unstable] mm/khugepaged: fix struct collapse_control load_node definition To: Yang Shi Cc: Andrew Morton , linux-mm@kvack.org, kbuild-all@lists.01.org Content-Type: text/plain; charset="UTF-8" ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1662491668; a=rsa-sha256; cv=none; b=nAG4DhZmz1BvcShh/fOsdaaYjFtQ4xykvdHlnhuMxcO0IMdMvdmG8+kaDwOKzYhwdKT4UX gC4V9fjP/RhV0nY9xzax06g16XcZV/zM71kBnctmyq5mBkyFhZMAGqPg/rMcRDpmkrIcyy LRLRd0KKEgZIlcRGxbRJIWc+M2fLzqE= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=l6c1itdp; spf=pass (imf05.hostedemail.com: domain of zokeefe@google.com designates 209.85.160.47 as permitted sender) smtp.mailfrom=zokeefe@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662491668; 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=tlzgL+2u0DPV2YOKquX9j8NBDXTqVNnTI8nxgIPmeDw=; b=nJMMI8+tESmZQLVgpvv0CtY1Lqgm0wujFJYGfxH5MJc9TBNYiVyBZUjwv9PhEbZ5OxDsGe /fqgZoF5N57wOjvrw5lkn0DlMvnVL6seUQAG45YTlP6jZz1ITtaL5GAj215jv5ixprMsNM 4JggdZP5bEdfVHKOQ5m23JExK2lOFM0= X-Stat-Signature: rrou1e1htk9m5rdm1r9neaypw5krn3mm X-Rspamd-Queue-Id: 5393710007C X-Rspamd-Server: rspam07 X-Rspam-User: Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=l6c1itdp; spf=pass (imf05.hostedemail.com: domain of zokeefe@google.com designates 209.85.160.47 as permitted sender) smtp.mailfrom=zokeefe@google.com; dmarc=pass (policy=reject) header.from=google.com X-HE-Tag: 1662491668-598582 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: On Tue, Sep 6, 2022 at 11:46 AM Yang Shi wrote: > > On Fri, Sep 2, 2022 at 7:12 PM Zach O'Keefe wrote: > > > > HPAGE_PMD_ORDER is used to determine a minimal amount of bits needed to store > > per-node counters in struct collapse_control, defining the array to be either a > > u16[HPAGE_PMD_ORDER] or u32[HPAGE_PMD_ORDER]. > > > > For some architectures/configs, HPAGE_PMD_ORDER isn't resolved at preprocessor > > time (suitable for resolving preprocessor directives) but rather expands into a > > compiler built-in that is resolved at compile-time. E.g. for 32-bit MIPS (see > > link for full config): > > > > ---8<-- > > >> arch/mips/include/asm/pgtable.h:238:26: warning: "__builtin_ffs" is not defined, evaluates to 0 [-Wundef] > > 238 | #define PTE_T_LOG2 (__builtin_ffs(sizeof(pte_t)) - 1) > > | ^~~~~~~~~~~~~ > > arch/mips/include/asm/pgtable-32.h:65:43: note: in expansion of macro 'PTE_T_LOG2' > > 65 | # define PGDIR_SHIFT (2 * PAGE_SHIFT - PTE_T_LOG2 - 1) > > | ^~~~~~~~~~ > > include/asm-generic/pgtable-nop4d.h:11:33: note: in expansion of macro 'PGDIR_SHIFT' > > 11 | #define P4D_SHIFT PGDIR_SHIFT > > | ^~~~~~~~~~~ > > include/asm-generic/pgtable-nopud.h:18:25: note: in expansion of macro 'P4D_SHIFT' > > 18 | #define PUD_SHIFT P4D_SHIFT > > | ^~~~~~~~~ > > include/asm-generic/pgtable-nopmd.h:20:25: note: in expansion of macro 'PUD_SHIFT' > > 20 | #define PMD_SHIFT PUD_SHIFT > > | ^~~~~~~~~ > > include/linux/huge_mm.h:109:25: note: in expansion of macro 'PMD_SHIFT' > > 109 | #define HPAGE_PMD_SHIFT PMD_SHIFT > > | ^~~~~~~~~ > > include/linux/huge_mm.h:105:26: note: in expansion of macro 'HPAGE_PMD_SHIFT' > > 105 | #define HPAGE_PMD_ORDER (HPAGE_PMD_SHIFT-PAGE_SHIFT) > > | ^~~~~~~~~~~~~~~ > > mm/khugepaged.c:90:5: note: in expansion of macro 'HPAGE_PMD_ORDER' > > 90 | #if HPAGE_PMD_ORDER < 16 > > | ^~~~~~~~~~~~~~~ > > >> arch/mips/include/asm/pgtable.h:238:39: error: missing binary operator before token "(" > > 238 | #define PTE_T_LOG2 (__builtin_ffs(sizeof(pte_t)) - 1) > > | ^ > > arch/mips/include/asm/pgtable-32.h:65:43: note: in expansion of macro 'PTE_T_LOG2' > > 65 | # define PGDIR_SHIFT (2 * PAGE_SHIFT - PTE_T_LOG2 - 1) > > | ^~~~~~~~~~ > > include/asm-generic/pgtable-nop4d.h:11:33: note: in expansion of macro 'PGDIR_SHIFT' > > 11 | #define P4D_SHIFT PGDIR_SHIFT > > | ^~~~~~~~~~~ > > include/asm-generic/pgtable-nopud.h:18:25: note: in expansion of macro 'P4D_SHIFT' > > 18 | #define PUD_SHIFT P4D_SHIFT > > | ^~~~~~~~~ > > include/asm-generic/pgtable-nopmd.h:20:25: note: in expansion of macro 'PUD_SHIFT' > > 20 | #define PMD_SHIFT PUD_SHIFT > > | ^~~~~~~~~ > > include/linux/huge_mm.h:109:25: note: in expansion of macro 'PMD_SHIFT' > > 109 | #define HPAGE_PMD_SHIFT PMD_SHIFT > > | ^~~~~~~~~ > > include/linux/huge_mm.h:105:26: note: in expansion of macro 'HPAGE_PMD_SHIFT' > > 105 | #define HPAGE_PMD_ORDER (HPAGE_PMD_SHIFT-PAGE_SHIFT) > > | ^~~~~~~~~~~~~~~ > > mm/khugepaged.c:90:5: note: in expansion of macro 'HPAGE_PMD_ORDER' > > 90 | #if HPAGE_PMD_ORDER < 16 > > | ^~~~~~~~~~~~~~~ > > ---8<-- > > > > load_node is already special-cased for CONFIG_PPC64 in > > "mm-khugepaged-add-struct-collapse_control-fix-fix", and we could continue down > > that path by #define'ing away edge cases, but I think at this point it easier > > to just let load_node be an array of u32s. If it's ever an issue, we can > > revisit. > > > > This essentially rolls back both: > > > > "mm/khugepaged: use minimal bits to store num page < HPAGE_PMD_NR" > > "mm-khugepaged-add-struct-collapse_control-fix-fix" > > > > (though we'll leave it as a u32 vs an int). > > > > Link: https://lore.kernel.org/linux-mm/202209021349.F73i5d6X-lkp@intel.com/ > > Fixes: 5f7bb00bd9cd ("mm/khugepaged: use minimal bits to store num page < HPAGE_PMD_NR") > > Fixes: 03053c821af2 ("mm-khugepaged-add-struct-collapse_control-fix-fix") > > Signed-off-by: Zach O'Keefe > > --- > > mm/khugepaged.c | 7 +------ > > 1 file changed, 1 insertion(+), 6 deletions(-) > > > > diff --git a/mm/khugepaged.c b/mm/khugepaged.c > > index af3b07eb2389..29142a35d24c 100644 > > --- a/mm/khugepaged.c > > +++ b/mm/khugepaged.c > > @@ -93,13 +93,8 @@ struct collapse_control { > > bool is_khugepaged; > > > > /* Num pages scanned per node */ > > -#if defined(CONFIG_PPC64) > > u32 node_load[MAX_NUMNODES]; > > -#elif HPAGE_PMD_ORDER < 16 > > - u16 node_load[MAX_NUMNODES]; > > -#else > > - u32 node_load[MAX_NUMNODES]; > > -#endif > > I recall we need this to circumvent some build time warning about > stack usage? Or I misremember? > Hey Yang, thanks for keeping a look out here, and good memory! The stack usage issue was due to struct collapse_control being allocated on the stack when MAX_NUMNODES was massive[1]. Now that we kmalloc() them for MADV_COLLAPSE, idea is we'd want to limit required memory and the original change here was an optimization due to an observation that we really didn't need 32 bits to hold a maximum value of HPAGE_PMD_NR[2], but determining some safe upper bound for the number of requires bits per arch/config as been a bit of a pain, with special casing adding to support POWER64 already[3], and now this mips issue that would otherwise require something special. [1] https://lore.kernel.org/linux-mm/CAAa6QmQXn9odA-dsm-FFKqQmDvBuH0qDkmPFfXDS1so+Loe+4Q@mail.gmail.com/ [2] https://lore.kernel.org/linux-mm/Ys2CeIm%2FQmQwWh9a@google.com/ [3] https://lore.kernel.org/linux-next/Ytk0TQO9khUQgjxT@google.com/