Message ID | 153077341292.40830.11333232703318633087.stgit@dwillia2-desk3.amr.corp.intel.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On Wed, Jul 04, 2018 at 11:50:13PM -0700, Dan Williams wrote: > +static ssize_t memmap_state_store(struct device *dev, > + struct device_attribute *attr, const char *buf, size_t len) > +{ > + int i; > + struct nd_pfn *nd_pfn = to_nd_pfn_safe(dev); > + struct memmap_async_state *async = &nd_pfn->async; > + > + if (strcmp(buf, "sync") == 0) > + /* pass */; > + else if (strcmp(buf, "sync\n") == 0) > + /* pass */; > + else > + return -EINVAL; Hmm what about: if (strncmp(buf, "sync", 4)) return -EINVAL; This collapses 6 lines into 4.
On Thu, Jul 5, 2018 at 1:29 AM, Johannes Thumshirn <jthumshirn@suse.de> wrote: > On Wed, Jul 04, 2018 at 11:50:13PM -0700, Dan Williams wrote: >> +static ssize_t memmap_state_store(struct device *dev, >> + struct device_attribute *attr, const char *buf, size_t len) >> +{ >> + int i; >> + struct nd_pfn *nd_pfn = to_nd_pfn_safe(dev); >> + struct memmap_async_state *async = &nd_pfn->async; >> + >> + if (strcmp(buf, "sync") == 0) >> + /* pass */; >> + else if (strcmp(buf, "sync\n") == 0) >> + /* pass */; >> + else >> + return -EINVAL; > > Hmm what about: > > if (strncmp(buf, "sync", 4)) > return -EINVAL; > > This collapses 6 lines into 4. ...but that also allows 'echo "syncAndThenSomeGarbage" > /sys/.../memmap_state' to succeed.
On Thu, Jul 05, 2018 at 07:46:05AM -0700, Dan Williams wrote: > ...but that also allows 'echo "syncAndThenSomeGarbage" > > /sys/.../memmap_state' to succeed. Yep it does :-(. Damn
On Thu, Jul 05, 2018 at 07:46:05AM -0700, Dan Williams wrote: > On Thu, Jul 5, 2018 at 1:29 AM, Johannes Thumshirn <jthumshirn@suse.de> wrote: > > On Wed, Jul 04, 2018 at 11:50:13PM -0700, Dan Williams wrote: > >> +static ssize_t memmap_state_store(struct device *dev, > >> + struct device_attribute *attr, const char *buf, size_t len) > >> +{ > >> + int i; > >> + struct nd_pfn *nd_pfn = to_nd_pfn_safe(dev); > >> + struct memmap_async_state *async = &nd_pfn->async; > >> + > >> + if (strcmp(buf, "sync") == 0) > >> + /* pass */; > >> + else if (strcmp(buf, "sync\n") == 0) > >> + /* pass */; > >> + else > >> + return -EINVAL; > > > > Hmm what about: > > > > if (strncmp(buf, "sync", 4)) > > return -EINVAL; > > > > This collapses 6 lines into 4. > > ...but that also allows 'echo "syncAndThenSomeGarbage" > > /sys/.../memmap_state' to succeed. if (strncmp(buf, "sync", 4)) return -EINVAL; if (buf[4] != '\0' && buf[4] != '\n') return -EINVAL;
On Thu, Jul 5, 2018 at 12:49 PM, Matthew Wilcox <willy@infradead.org> wrote: > On Thu, Jul 05, 2018 at 07:46:05AM -0700, Dan Williams wrote: >> On Thu, Jul 5, 2018 at 1:29 AM, Johannes Thumshirn <jthumshirn@suse.de> wrote: >> > On Wed, Jul 04, 2018 at 11:50:13PM -0700, Dan Williams wrote: >> >> +static ssize_t memmap_state_store(struct device *dev, >> >> + struct device_attribute *attr, const char *buf, size_t len) >> >> +{ >> >> + int i; >> >> + struct nd_pfn *nd_pfn = to_nd_pfn_safe(dev); >> >> + struct memmap_async_state *async = &nd_pfn->async; >> >> + >> >> + if (strcmp(buf, "sync") == 0) >> >> + /* pass */; >> >> + else if (strcmp(buf, "sync\n") == 0) >> >> + /* pass */; >> >> + else >> >> + return -EINVAL; >> > >> > Hmm what about: >> > >> > if (strncmp(buf, "sync", 4)) >> > return -EINVAL; >> > >> > This collapses 6 lines into 4. >> >> ...but that also allows 'echo "syncAndThenSomeGarbage" > >> /sys/.../memmap_state' to succeed. > > if (strncmp(buf, "sync", 4)) > return -EINVAL; > if (buf[4] != '\0' && buf[4] != '\n') > return -EINVAL; > Not sure that's a win either, I'd rather just: + if (strcmp(buf, "sync") == 0 || strcmp(buf, "sync\n") == 0) + /* pass */; + else + return -EINVAL; If we're trying to save those 2 lines.
Dan Williams <dan.j.williams@intel.com> writes: > On Thu, Jul 5, 2018 at 12:49 PM, Matthew Wilcox <willy@infradead.org> wrote: >> On Thu, Jul 05, 2018 at 07:46:05AM -0700, Dan Williams wrote: >>> On Thu, Jul 5, 2018 at 1:29 AM, Johannes Thumshirn <jthumshirn@suse.de> wrote: >>> > On Wed, Jul 04, 2018 at 11:50:13PM -0700, Dan Williams wrote: >>> >> +static ssize_t memmap_state_store(struct device *dev, >>> >> + struct device_attribute *attr, const char *buf, size_t len) >>> >> +{ >>> >> + int i; >>> >> + struct nd_pfn *nd_pfn = to_nd_pfn_safe(dev); >>> >> + struct memmap_async_state *async = &nd_pfn->async; >>> >> + >>> >> + if (strcmp(buf, "sync") == 0) >>> >> + /* pass */; >>> >> + else if (strcmp(buf, "sync\n") == 0) >>> >> + /* pass */; >>> >> + else >>> >> + return -EINVAL; >>> > >>> > Hmm what about: >>> > >>> > if (strncmp(buf, "sync", 4)) >>> > return -EINVAL; >>> > >>> > This collapses 6 lines into 4. >>> >>> ...but that also allows 'echo "syncAndThenSomeGarbage" > >>> /sys/.../memmap_state' to succeed. >> >> if (strncmp(buf, "sync", 4)) >> return -EINVAL; >> if (buf[4] != '\0' && buf[4] != '\n') >> return -EINVAL; >> > > Not sure that's a win either, I'd rather just: > > + if (strcmp(buf, "sync") == 0 || strcmp(buf, "sync\n") == 0) > + /* pass */; > + else > + return -EINVAL; > > If we're trying to save those 2 lines. WFM. I don't like that I had to go digging around in sysfs documentation to convince myself that strcmp was safe, but I guess that's my problem. ;-) Cheers, Jeff
On Thu, 5 Jul 2018 16:49:41 +0200 Johannes Thumshirn <jthumshirn@suse.de> wrote: > On Thu, Jul 05, 2018 at 07:46:05AM -0700, Dan Williams wrote: > > ...but that also allows 'echo "syncAndThenSomeGarbage" > > > /sys/.../memmap_state' to succeed. > > Yep it does :-(. > > Damn sysfs_streq()
On Thu, Jul 5, 2018 at 1:24 PM, Andrew Morton <akpm@linux-foundation.org> wrote: > On Thu, 5 Jul 2018 16:49:41 +0200 Johannes Thumshirn <jthumshirn@suse.de> wrote: > >> On Thu, Jul 05, 2018 at 07:46:05AM -0700, Dan Williams wrote: >> > ...but that also allows 'echo "syncAndThenSomeGarbage" > >> > /sys/.../memmap_state' to succeed. >> >> Yep it does :-(. >> >> Damn > > sysfs_streq() Nice... /me stares down a long list of needed cleanups in the libnvdimm sysfs implementation with that gem.
On Thu, Jul 05, 2018 at 01:24:55PM -0700, Andrew Morton wrote: > On Thu, 5 Jul 2018 16:49:41 +0200 Johannes Thumshirn <jthumshirn@suse.de> wrote: > > > On Thu, Jul 05, 2018 at 07:46:05AM -0700, Dan Williams wrote: > > > ...but that also allows 'echo "syncAndThenSomeGarbage" > > > > /sys/.../memmap_state' to succeed. > > > > Yep it does :-(. > > > > Damn > > sysfs_streq() Thanks! I didn't know that one existed. It's kind of a shame that we realised this was a problem and decided to solve it this way back in 2008 instead of realising that no driver actually cares whether there's a \n or not and stripping off the \n before the driver gets to see it. Probably too late to fix that now.
On Thu, Jul 05, 2018 at 01:34:01PM -0700, Dan Williams wrote: > > > > sysfs_streq() > > Nice... /me stares down a long list of needed cleanups in the > libnvdimm sysfs implementation with that gem. Cool. I think not only libnvdimm would profit from this. /me looks into scsi and nvme now.
diff --git a/drivers/nvdimm/pfn_devs.c b/drivers/nvdimm/pfn_devs.c index 147c62e2ef2b..00f1792d070c 100644 --- a/drivers/nvdimm/pfn_devs.c +++ b/drivers/nvdimm/pfn_devs.c @@ -1,15 +1,6 @@ -/* - * Copyright(c) 2013-2016 Intel Corporation. All rights reserved. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of version 2 of the GNU General Public License as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - */ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright(c) 2013-2018 Intel Corporation. All rights reserved. */ +#include <linux/memory_hotplug.h> #include <linux/memremap.h> #include <linux/blkdev.h> #include <linux/device.h> @@ -103,6 +94,43 @@ static ssize_t mode_store(struct device *dev, } static DEVICE_ATTR_RW(mode); +static ssize_t memmap_state_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct nd_pfn *nd_pfn = to_nd_pfn_safe(dev); + struct memmap_async_state *async = &nd_pfn->async; + + return sprintf(buf, "%s\n", bitmap_weight(async->active, + NR_MEMMAP_THREADS) ? "active" : "idle"); +} + +static ssize_t memmap_state_store(struct device *dev, + struct device_attribute *attr, const char *buf, size_t len) +{ + int i; + struct nd_pfn *nd_pfn = to_nd_pfn_safe(dev); + struct memmap_async_state *async = &nd_pfn->async; + + if (strcmp(buf, "sync") == 0) + /* pass */; + else if (strcmp(buf, "sync\n") == 0) + /* pass */; + else + return -EINVAL; + + for (i = 0; i < NR_MEMMAP_THREADS; i++) { + struct memmap_init_pages *thread = &async->page_init[i]; + + if (!test_bit(i, async->active)) + continue; + async_synchronize_cookie_domain(thread->cookie, + &memmap_init_domain); + } + + return len; +} +static DEVICE_ATTR_RW(memmap_state); + static ssize_t align_show(struct device *dev, struct device_attribute *attr, char *buf) { @@ -279,6 +307,7 @@ static struct attribute *nd_pfn_attributes[] = { &dev_attr_resource.attr, &dev_attr_size.attr, &dev_attr_supported_alignments.attr, + &dev_attr_memmap_state.attr, NULL, }; diff --git a/mm/page_alloc.c b/mm/page_alloc.c index d1466dd82bc2..90414c1d2ca8 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -5456,6 +5456,7 @@ void __ref build_all_zonelists(pg_data_t *pgdat) } ASYNC_DOMAIN_EXCLUSIVE(memmap_init_domain); +EXPORT_SYMBOL_GPL(memmap_init_domain); static void __meminit memmap_init_one(unsigned long pfn, unsigned long zone, int nid, enum memmap_context context, struct dev_pagemap *pgmap)
Applications may want to know that page structure initialization is complete rather than be subject to delays at first DAX fault. Also, page structure initialization consumes CPU resources impacting application performance, so a environment may want to wait before considering the system fully initialized. Provide a sysfs attribute to display the current state, and when written with 'sync' complete memmap initialization. Cc: Ross Zwisler <ross.zwisler@linux.intel.com> Cc: Vishal Verma <vishal.l.verma@intel.com> Cc: Dave Jiang <dave.jiang@intel.com> Cc: Johannes Thumshirn <jthumshirn@suse.de> Cc: Jeff Moyer <jmoyer@redhat.com> Signed-off-by: Dan Williams <dan.j.williams@intel.com> --- drivers/nvdimm/pfn_devs.c | 53 +++++++++++++++++++++++++++++++++++---------- mm/page_alloc.c | 1 + 2 files changed, 42 insertions(+), 12 deletions(-)