Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp4161787rwp; Sat, 15 Jul 2023 18:47:05 -0700 (PDT) X-Google-Smtp-Source: APBJJlGIlAt9E3neA3FkrvwRFhnYLelrdpjnh526EncXEwsPpKN36MM3VlofKjxOl+dsFODo2Eqh X-Received: by 2002:a05:6402:1e94:b0:51f:ef58:da87 with SMTP id f20-20020a0564021e9400b0051fef58da87mr9117576edf.2.1689472025619; Sat, 15 Jul 2023 18:47:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689472025; cv=none; d=google.com; s=arc-20160816; b=g0xYEOQcubOOnvJwDXeVps72zClZZJDFVSBCBJlufPPRwZ32BiXO7EKdUP/zK5bAuo HQ19WhgqpJ9XUYpvqk6eoaMsJ0qQ9pUByxEBMn45gZPoYeGbfN4dYozMOXt4Rx8X2OQE RXpRJfm/2v9AISv2pgPQaI1V3Wj37Cnvo01M9qyL6DL6B2zdrMDdFzDjOz9WnLVGMIUy 4ndBqi4zeGnmpU0ID0XvuZD3IVOSFvyZOMUq4FUd2zekcRxHNTB1W/0FCtPnVbb+G/iv aWO9BKZdj2dtGoYNBmFktkfKzMvIM6/nGzMfv/xVEhiz8VZ8JToja8Unpor0vnmfMaB4 WFnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=lHWTTA67kIdojUfmyvgXKmILJ8BrAFEuc6q6jGxjRIE=; fh=p2sJc5/tSEVhihr7gqYojU8zavGWRI1KKn/DzTcrz7k=; b=ktWOzhqUM0w01UUIkBlSHzvCHd+ZwsX9sk6/KIrLMvd0s78G4zu1tDxzEL2fciNZu1 DaOUPcyziS4yrGpIME0UkvgVj5TQcYN0drWrmtyToNGEGCvqzur0c4WT/nZnFSAyPTV0 SxGOWrOP4o5QVLxCtnZZ6rzIuj2zsSiqRvGUqtapRXknOWWRCf35KA0HRvLqVayqqwO/ 75QfNuRdfn19F+2/gqNXpT7lfd+fkAICZL+HmXeubvEjgQ8WpGpp/vrgqNjsTF4t2JnG 2xM1xHMGcfHzD1YVc+JLSudWAP0xdL3Luh74A0tqwxffoE6frGZE7/dHwL1tiaPp3BgO gvOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=RNE0S0KQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u22-20020a05640207d600b0052166e59367si2964220edy.330.2023.07.15.18.46.41; Sat, 15 Jul 2023 18:47:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=RNE0S0KQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230037AbjGPBJf (ORCPT + 99 others); Sat, 15 Jul 2023 21:09:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229795AbjGPBJe (ORCPT ); Sat, 15 Jul 2023 21:09:34 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3433D271F for ; Sat, 15 Jul 2023 18:09:33 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id C544060C47 for ; Sun, 16 Jul 2023 01:09:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C3452C433C7; Sun, 16 Jul 2023 01:09:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689469772; bh=5SSm4qEXPJuLohs5+byCGS3o4lRGePIKkaLKy1/+IXc=; h=From:To:Cc:Subject:Date:From; b=RNE0S0KQf9cRwje4zpnYyVSB45dXyxazFqRNu79k0NvYqvDcqN3SDgAQKkSSlThfu bvt8zjM+7qrgXnrITpz0BXGwD6EIWrjEvP8Sgouy+zj3Ti9+08V0ssNOZS4t84SVjB +i7dELXzNCAV4Ps/cElbr5vod97Fi8CSEMEzQsKkGpjCI4AAnTvKvmFtgbTxa0igmt jaz3LqNmLDx1Uirxipq9HaXZTwq2bhq0XjBjmWxL89463OKLVZYI9/hm0sA1muGdRd sBVyyfPI2Yan0+hwlQsdkB2X/Vo7PgdhJx7e4N8Sl0NgCz4jmCBnYdCKiKthemyOTr QSYdaRb4YsDzw== From: Chao Yu To: sj@kernel.org, akpm@linux-foundation.org, damon@lists.linux.dev Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Chao Yu Subject: [PATCH 1/2] mm/damon/dbgfs: reduce stack usage in str_to_schemes() Date: Sun, 16 Jul 2023 09:09:26 +0800 Message-Id: <20230716010927.3010606-1-chao@kernel.org> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org struct damos_quota quota caused the stack usage of str_to_schemes() to grow beyond the warning limit on 32-bit architectures w/ gcc. mm/damon/dbgfs.c: In function ‘str_to_schemes’: mm/damon/dbgfs.c:292:1: warning: the frame size of 1496 bytes is larger than 1024 bytes [-Wframe-larger-than=] Allocating dynamic memory in str_to_schemes() to fix this issue. Signed-off-by: Chao Yu --- mm/damon/dbgfs.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/mm/damon/dbgfs.c b/mm/damon/dbgfs.c index 124f0f8c97b7..78acc7366895 100644 --- a/mm/damon/dbgfs.c +++ b/mm/damon/dbgfs.c @@ -237,18 +237,26 @@ static struct damos **str_to_schemes(const char *str, ssize_t len, int pos = 0, parsed, ret; unsigned int action_input; enum damos_action action; + struct damos_quota *quota; schemes = kmalloc_array(max_nr_schemes, sizeof(scheme), GFP_KERNEL); if (!schemes) return NULL; + quota = kmalloc(sizeof(struct damos_quota), GFP_KERNEL); + if (!quota) { + kfree(schemes); + return NULL; + } + *nr_schemes = 0; while (pos < len && *nr_schemes < max_nr_schemes) { struct damos_access_pattern pattern = {}; - struct damos_quota quota = {}; struct damos_watermarks wmarks; + memset(quota, 0, sizeof(struct damos_quota)); + ret = sscanf(&str[pos], "%lu %lu %u %u %u %u %u %lu %lu %lu %u %u %u %u %lu %lu %lu %lu%n", &pattern.min_sz_region, &pattern.max_sz_region, @@ -256,10 +264,10 @@ static struct damos **str_to_schemes(const char *str, ssize_t len, &pattern.max_nr_accesses, &pattern.min_age_region, &pattern.max_age_region, - &action_input, "a.ms, - "a.sz, "a.reset_interval, - "a.weight_sz, "a.weight_nr_accesses, - "a.weight_age, &wmarks.metric, + &action_input, "a->ms, + "a->sz, "a->reset_interval, + "a->weight_sz, "a->weight_nr_accesses, + "a->weight_age, &wmarks.metric, &wmarks.interval, &wmarks.high, &wmarks.mid, &wmarks.low, &parsed); if (ret != 18) @@ -278,15 +286,17 @@ static struct damos **str_to_schemes(const char *str, ssize_t len, goto fail; pos += parsed; - scheme = damon_new_scheme(&pattern, action, "a, &wmarks); + scheme = damon_new_scheme(&pattern, action, quota, &wmarks); if (!scheme) goto fail; schemes[*nr_schemes] = scheme; *nr_schemes += 1; } + kfree(quota); return schemes; fail: + kfree(quota); free_schemes_arr(schemes, *nr_schemes); return NULL; } -- 2.40.1