lkml.org 
[lkml]   [2022]   [Sep]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: [PATCH v2 3/3] mm,page_owner: Filter out stacks by a threshold counter
Date
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

\
 
 \ /
  Last update: 2022-09-05 13:56    [W:0.056 / U:0.112 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site