Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp2996536rwb; Mon, 5 Sep 2022 05:04:16 -0700 (PDT) X-Google-Smtp-Source: AA6agR64Kev7aMS1IQuNTdrK2Fp6lJ6Q3N9KOnxMSl1nhy85albAyQ+7hnTgd8lTjfjTq44DOX5c X-Received: by 2002:a17:903:244f:b0:175:34d6:97a8 with SMTP id l15-20020a170903244f00b0017534d697a8mr29544095pls.100.1662379456673; Mon, 05 Sep 2022 05:04:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662379456; cv=none; d=google.com; s=arc-20160816; b=Nh8iH6tE3Smt00O4XMR0RQtvZGdb2J7sy6UdFtjZNnQpymv2Mj3x5BsAzgv2sL7JlC EqvowJlMZ7hpVB2FfL4LcIl/RwvuHCxPFwlhTrhbh28ZceTZGNjLjDFP8Zn6toPMSp2M IY/mtdpwGQz17uPfbbUDtsJ3BDS/nn86V6H+oRJ+IXXVGfsRNEf6LlY0Szst8dydicnG QAO018Z1zcI5Ir+D/Tc+dwSqQbpH9zadcFXZ/fGrOMBkfEpCbj9IHlbJcVYrn1BWuPr8 VyHCN9AaVZumHz6r2nPGADY79vKyglYk0//hjl41WhnddiZK/rivk0Qt3bzSe3qiLDcY G4LA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=Jzv7p7mWnJpzEKfXFeYlUoUTdDmCc5e2LsD6bqOO4z8=; b=0It3nfWljGJDeWctpQAyr5no5RrUW7c38r7taa1SK+IILTykcRDWhmkn4D7hlnjV84 6aHQ6C/YvQPWtY6rriR9dppwtNrKfA6/M5duP5EPJ/ZyUdi+VRHTBwixLsfDFVSMVYq7 Df3LovAgMXzcPsez8n3Qyaddj1hUyyyhofd0KBq23E8rODpxUZyUVvD/pG8bX9C5NpvN aNw6vXcFrwssKvc1DpA9i5DaDG9OEXGpJBpLgr5QNu07pWVAvyeM3Vp41I2AYFEV59HR eXqXN1hNLTGqAN6pUuGfO8rczhmv/TU9Bqw3NlFD8N4rzs0G2ZyUYrUQtunv7R4uMCaO zsBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=ch1mRR9T; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m65-20020a632644000000b0042b8b0284cdsi10648141pgm.97.2022.09.05.05.04.02; Mon, 05 Sep 2022 05:04:16 -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=@suse.com header.s=susede1 header.b=ch1mRR9T; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236817AbiIELbO (ORCPT + 99 others); Mon, 5 Sep 2022 07:31:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237150AbiIELbH (ORCPT ); Mon, 5 Sep 2022 07:31:07 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 193F958DF9 for ; Mon, 5 Sep 2022 04:31:05 -0700 (PDT) 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> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 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