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 F2C12ECAAD3 for ; Mon, 5 Sep 2022 11:55:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7F8AE801DA; Mon, 5 Sep 2022 07:55:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7A7B78D0050; Mon, 5 Sep 2022 07:55:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 697E3801DA; Mon, 5 Sep 2022 07:55:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 5AC1D8D0050 for ; Mon, 5 Sep 2022 07:55:21 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 26342AC3E6 for ; Mon, 5 Sep 2022 11:55:21 +0000 (UTC) X-FDA: 79877876442.11.2AF1D86 Received: from gnuweeb.org (gnuweeb.org [51.81.211.47]) by imf20.hostedemail.com (Postfix) with ESMTP id B4A521C007D for ; Mon, 5 Sep 2022 11:55:20 +0000 (UTC) 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 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1662378920; a=rsa-sha256; cv=none; b=hmoM3BV1yDOv01sSWkerKBIW7Af3LXCChuyVzBMWm52VWJZtpvOPrv1AOaUE7IV+O+I4e9 KnqkuBF3pREBMDgSJVCnQee8a4kWC6nyxFo0yMEo0CHBju4IcQBsejCzp+WBAb9WgsglnY m8QwwPN0+C2sIXsKEour8VMO8q8Y7Ps= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=gnuweeb.org header.s=default header.b=JqGZ4l+n; spf=pass (imf20.hostedemail.com: domain of ammarfaizi2@gnuweeb.org designates 51.81.211.47 as permitted sender) smtp.mailfrom=ammarfaizi2@gnuweeb.org; dmarc=pass (policy=none) header.from=gnuweeb.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662378920; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=kO6tcztYXqSzi2vQ9WhmEuDh4vwHOQAB4oh1uQllp5Q=; b=M0ZNnqtz+EFOXc5CY14qw8uFlYCKTxG3QQy3wsNUtJD795Yy54ypRQ9s6UPxCFzXcnMsF9 oTMZUBOPZ7EICL4kTtp6teWrWVxsrnf2FRc+5H/CSOdOiV0KJ5MSoVbrH4Dp4mfMnB73SO tfP23AJ3LMgrgxk8RqTFqJB2HG9az4s= X-Stat-Signature: mpfy3unn8ac7mqdn684riqzf8ta96spg X-Rspamd-Queue-Id: B4A521C007D Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=gnuweeb.org header.s=default header.b=JqGZ4l+n; spf=pass (imf20.hostedemail.com: domain of ammarfaizi2@gnuweeb.org designates 51.81.211.47 as permitted sender) smtp.mailfrom=ammarfaizi2@gnuweeb.org; dmarc=pass (policy=none) header.from=gnuweeb.org X-Rspam-User: X-Rspamd-Server: rspam03 X-HE-Tag: 1662378920-902047 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 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