Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp2998104rwb; Mon, 5 Sep 2022 05:05:12 -0700 (PDT) X-Google-Smtp-Source: AA6agR5L+6rUKxgYKnrRr7EGs8ydNv0DL7cutnwlZlkWi6V0wE+lmH/ovKZx9WPZAe2mXe6V1GWb X-Received: by 2002:a05:6a00:138c:b0:538:1e50:a161 with SMTP id t12-20020a056a00138c00b005381e50a161mr12100633pfg.43.1662379512425; Mon, 05 Sep 2022 05:05:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662379512; cv=none; d=google.com; s=arc-20160816; b=K9Laqb2IZYnNxodUPT/TLSpH26YPomNeXKO262T+usgdu2DcToKiBycG9Jbi5PmfRN +TmonwSqV+jL6zj850und5R0GQSBNrXJw1qScJIR/SjokcmDtksQ3NaO2uWHFkfHpYmf QEqdITzU3ne4C+kQPKwtTYev3BNxXF+OdZTXErJD4EiaodVzeQFOvp/k13cc22CM/Z4X 3GTteucwVDnnSP9Vq41Bebyn6zZs9doNbnWhs6PD8JkwOC2layCUOn2ygXk5DetoUj+X 8sW6bR65tHxTUnEqUsCofWkc0pdw5+h/sRyd0+DvRsxlt27BKXs4bEqLfLnDo50JJGB6 zBzw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=kO6tcztYXqSzi2vQ9WhmEuDh4vwHOQAB4oh1uQllp5Q=; b=q0ncJ2xNO+iTzQuBlb2JykiMF3jgZ1ZbN+XbTNnKZTJf8+0kT4klKDkyHdSjvVOXXY Krb52zZlfqrRcwioLsuySf0clVO0LX2Uh8v/whvwV+HdndLjLhRoyfs8hDMjfvbc1zcZ 7L3jV78SzDkz9WDYBIrBMtBLsM1JKmdV1bNwvlXLtvMNWM+OIlM6jr0rMbLEvx/JiqZq RhZgwjGLl7JHPA3OS2cF6FGBx6b9aAw/7hseOvd88gkOnHiQlpV6/h8FSRhfSx339Ark TmTp9ES6SEeVpYQ9bkF3oavuGyCK4CgcoAeXyisPhxVZEDjDA99v83E2fTD5ti0gR+ff n0GA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gnuweeb.org header.s=default header.b=JqGZ4l+n; 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=gnuweeb.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k2-20020a056a00134200b00538503e7706si11313152pfu.378.2022.09.05.05.05.00; Mon, 05 Sep 2022 05:05:12 -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=@gnuweeb.org header.s=default header.b=JqGZ4l+n; 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=gnuweeb.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236921AbiIELzY (ORCPT + 99 others); Mon, 5 Sep 2022 07:55:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237781AbiIELzV (ORCPT ); Mon, 5 Sep 2022 07:55:21 -0400 Received: from gnuweeb.org (gnuweeb.org [51.81.211.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F2A1427170 for ; Mon, 5 Sep 2022 04:55:19 -0700 (PDT) Received: from localhost.localdomain (unknown [182.2.42.181]) by gnuweeb.org (Postfix) with ESMTPSA id 74AE6804FD; Mon, 5 Sep 2022 11:55:14 +0000 (UTC) X-GW-Data: lPqxHiMPbJw1wb7CM9QUryAGzr0yq5atzVDdxTR0iA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1662378919; bh=Ax3MC0XcIkDxhT39fYMzcJEvWVrtUjw9z/eRM8QtIpg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JqGZ4l+n16P9GGgKdRmQ+7QjZtwOHRXaFmjP6vP56fRD5aQ5OIxt+/xJhYLW3/Eb0 ilhOBVxCX+Sm4+ovQR7UKqg8+bMEQlw50dw3JSAfBJSsdvyiSuXJdsJ49moyTWqBl3 RHaE8u5fyGbUOM4aFwzj1BdQ5wg35RpuwDNwG3Cf5wBEDl58CzEWKUbyKNjdJs4xmb pAzxAd9tRDMrkFpd/rCoWsK0DFQq+dxxAdIdfNn9t+72ZIa8AEJaaPNHG7hV0RWpyV 2+Dk97CrgJBIghgfjlv/KK5B5mOT2gPbDmq5L6jT5yJnBnZ7iiZienFCBFSsPgK8Ra WqCk6vXoTCzRQ== From: Ammar Faizi To: Michal Hocko Cc: Ammar Faizi , Oscar Salvador , Andrew Morton , Linux Kernel Mailing List , Linux Memory Management Mailing List , Vlastimil Babka , Eric Dumazet , Waiman Long , Suren Baghdasaryan , Marco Elver , Andrey Konovalov , Alexander Potapenko Subject: Re: [PATCH v2 3/3] mm,page_owner: Filter out stacks by a threshold counter Date: Mon, 5 Sep 2022 18:54:59 +0700 Message-Id: <20220905115459.567583-1-ammarfaizi2@gnuweeb.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: <20220905031012.4450-1-osalvador@suse.de> <20220905031012.4450-4-osalvador@suse.de> <573c4049045a5ff342ff9998c69dfae7-ammarfaizi2@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_SORBS_WEB,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no 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 On Mon, 5 Sep 2022 13:31:02 +0200, Michal Hocko wrote: > On Mon 05-09-22 17:51:37, Ammar Faizi wrote: > > On Mon, 5 Sep 2022 05:10:12 +0200, Oscar Salvador wrote: > > > +static int page_owner_threshold_show(struct seq_file *p, void *v) > > > +{ > > > + seq_printf(p, "%lu\n", threshold); > > > > Remove a slipped leading 0x20 space here (before seq_printf()). > > > > > + return 0; > > > +} > > > + > > > +static ssize_t write_page_owner_threshold(struct file *file, const char __user *buf, > > > + size_t count, loff_t *pos) > > > +{ > > > + char *kbuf; > > > + int ret = 0; > > > + > > > + count = min_t(size_t, count, PAGE_SIZE); > > > + kbuf = kmalloc(count, GFP_KERNEL); > > > + if (!kbuf) > > > + return -ENOMEM; > > > + > > > + if (copy_from_user(kbuf, buf, count)) { > > > + ret = -EFAULT; > > > + goto out; > > > + } > > > + > > > + kbuf[count - 1] = '\0'; > > > + > > > + ret = kstrtoul(kbuf, 10, &threshold); > > > + > > > +out: > > > + kfree(kbuf); > > > + return ret ? ret : count; > > > +} > > > > Still the same comment on this, kmalloc() is not really needed here. > > Capping the size to PAGE_SIZE (usually 4K) is too big. `unsinged long` > > is 64-bit at most, this means the max val is 18446744073709551615 > > (20 chars). The lifetime of @kbuf is very short as well, using a stack > > allocated array of chars is fine? > > > > Untested: > > > > static ssize_t write_page_owner_threshold(struct file *file, const char __user *buf, > > size_t count, loff_t *pos) > > { > > char kbuf[21]; > > int ret; > > > > count = min_t(size_t, count, sizeof(kbuf)); > > if (copy_from_user(kbuf, buf, count)) > > return -EFAULT; > > > > kbuf[count - 1] = '\0'; > > ret = kstrtoul(kbuf, 10, &threshold); > > return ret ? ret : count; > > } > > Isn't there a proc_dointvec counterpart for debugfs? Ah, well. If that's much simpler, we should go with that. I am not familiar proc_dointvec() interface, so I couldn't say about it. Thanks for the comment. TIL. -- Ammar Faizi