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 D730CC6FA83 for ; Mon, 5 Sep 2022 11:31:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1D5BC8D0065; Mon, 5 Sep 2022 07:31:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 185808D0050; Mon, 5 Sep 2022 07:31:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 04BD48D0065; Mon, 5 Sep 2022 07:31:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id EA2C98D0050 for ; Mon, 5 Sep 2022 07:31:05 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id BBC2D1C5EB7 for ; Mon, 5 Sep 2022 11:31:05 +0000 (UTC) X-FDA: 79877815290.12.6E10220 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf10.hostedemail.com (Postfix) with ESMTP id 4468CC0062 for ; Mon, 5 Sep 2022 11:31:05 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id BE67A5FD4F; Mon, 5 Sep 2022 11:31:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1662377463; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Jzv7p7mWnJpzEKfXFeYlUoUTdDmCc5e2LsD6bqOO4z8=; b=ch1mRR9TjNUDND0PSuYzTWQ+6mBEj2pmJl1DM8Br/6sc1HUoQAv3YN7Fdg3mZWtfmbc2FT rhgPkzJT5cyTUUTvoQuEiVB3mPWxyF6e5TcjU3wDkdBjn/Gy6nLkRTaLZlI7x70Ls4icrn HfxQSwV79RwWPwgALFbI36BClEiU2Hg= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 9FD45139C7; Mon, 5 Sep 2022 11:31:03 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id iGM0JPfdFWMCZgAAMHmgww (envelope-from ); Mon, 05 Sep 2022 11:31:03 +0000 Date: Mon, 5 Sep 2022 13:31:02 +0200 From: Michal Hocko To: Ammar Faizi Cc: 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 Message-ID: References: <20220905031012.4450-1-osalvador@suse.de> <20220905031012.4450-4-osalvador@suse.de> <573c4049045a5ff342ff9998c69dfae7-ammarfaizi2@gnuweeb.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <573c4049045a5ff342ff9998c69dfae7-ammarfaizi2@gnuweeb.org> ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=ch1mRR9T; spf=pass (imf10.hostedemail.com: domain of mhocko@suse.com designates 195.135.220.29 as permitted sender) smtp.mailfrom=mhocko@suse.com; dmarc=pass (policy=quarantine) header.from=suse.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1662377465; a=rsa-sha256; cv=none; b=NSA0DHAxdJhn4nmm+KqibsmwjvZVPpvrzKQjdBXoUdpPFCHIt1OeeWQooz/QDcUhR2qn4c f2LqxRNsVMwujpNziJE2Pv3NtItpr2DHFyf2yxufmp1GTvqaoAwaWYpzBUW26TTe2KDxBn EDzxOPffxXwF5WvVqf4cYZPSi27j8HE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662377465; 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=Jzv7p7mWnJpzEKfXFeYlUoUTdDmCc5e2LsD6bqOO4z8=; b=tY96cJgePYJrkNxUVIBBXSFz14WxpJv2Nwm+PNLiMQcqw2qyZMRNCWiaSloaqm17cmUrus B/b7Yhj0kksLcx2ceSdHXQLFErCaMQVtVZnYmY5G44XTzcJarlkP+hpcssTPBxPVuG+X8u IZ+KoCUkCF6NBkX5qBcLMh+bYqfXxIQ= X-Rspamd-Server: rspam02 X-Rspam-User: Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=ch1mRR9T; spf=pass (imf10.hostedemail.com: domain of mhocko@suse.com designates 195.135.220.29 as permitted sender) smtp.mailfrom=mhocko@suse.com; dmarc=pass (policy=quarantine) header.from=suse.com X-Stat-Signature: dhe31q5nntznxg3xrzkcxt8gdes3zq9g X-Rspamd-Queue-Id: 4468CC0062 X-HE-Tag: 1662377465-725180 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 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? -- Michal Hocko SUSE Labs