Message ID | 20201012125323.17509-2-david@redhat.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | virtio-mem: Big Block Mode (BBM) | expand |
On Mon, Oct 12, 2020 at 02:52:55PM +0200, David Hildenbrand wrote: >Let's determine the target nid only once in case we have none specified - >usually, we'll end up with node 0 either way. > >Cc: "Michael S. Tsirkin" <mst@redhat.com> >Cc: Jason Wang <jasowang@redhat.com> >Cc: Pankaj Gupta <pankaj.gupta.linux@gmail.com> >Signed-off-by: David Hildenbrand <david@redhat.com> Reviewed-by: Wei Yang <richard.weiyang@linux.alibaba.com> >--- > drivers/virtio/virtio_mem.c | 28 +++++++++++----------------- > 1 file changed, 11 insertions(+), 17 deletions(-) > >diff --git a/drivers/virtio/virtio_mem.c b/drivers/virtio/virtio_mem.c >index ba4de598f663..a1f5bf7a571a 100644 >--- a/drivers/virtio/virtio_mem.c >+++ b/drivers/virtio/virtio_mem.c >@@ -70,7 +70,7 @@ struct virtio_mem { > > /* The device block size (for communicating with the device). */ > uint64_t device_block_size; >- /* The translated node id. NUMA_NO_NODE in case not specified. */ >+ /* The determined node id for all memory of the device. */ > int nid; > /* Physical start address of the memory region. */ > uint64_t addr; >@@ -406,10 +406,6 @@ static int virtio_mem_sb_bitmap_prepare_next_mb(struct virtio_mem *vm) > static int virtio_mem_mb_add(struct virtio_mem *vm, unsigned long mb_id) > { > const uint64_t addr = virtio_mem_mb_id_to_phys(mb_id); >- int nid = vm->nid; >- >- if (nid == NUMA_NO_NODE) >- nid = memory_add_physaddr_to_nid(addr); > > /* > * When force-unloading the driver and we still have memory added to >@@ -423,7 +419,8 @@ static int virtio_mem_mb_add(struct virtio_mem *vm, unsigned long mb_id) > } > > dev_dbg(&vm->vdev->dev, "adding memory block: %lu\n", mb_id); >- return add_memory_driver_managed(nid, addr, memory_block_size_bytes(), >+ return add_memory_driver_managed(vm->nid, addr, >+ memory_block_size_bytes(), > vm->resource_name, > MEMHP_MERGE_RESOURCE); > } >@@ -440,13 +437,9 @@ static int virtio_mem_mb_add(struct virtio_mem *vm, unsigned long mb_id) > static int virtio_mem_mb_remove(struct virtio_mem *vm, unsigned long mb_id) > { > const uint64_t addr = virtio_mem_mb_id_to_phys(mb_id); >- int nid = vm->nid; >- >- if (nid == NUMA_NO_NODE) >- nid = memory_add_physaddr_to_nid(addr); > > dev_dbg(&vm->vdev->dev, "removing memory block: %lu\n", mb_id); >- return remove_memory(nid, addr, memory_block_size_bytes()); >+ return remove_memory(vm->nid, addr, memory_block_size_bytes()); > } > > /* >@@ -461,14 +454,11 @@ static int virtio_mem_mb_offline_and_remove(struct virtio_mem *vm, > unsigned long mb_id) > { > const uint64_t addr = virtio_mem_mb_id_to_phys(mb_id); >- int nid = vm->nid; >- >- if (nid == NUMA_NO_NODE) >- nid = memory_add_physaddr_to_nid(addr); > > dev_dbg(&vm->vdev->dev, "offlining and removing memory block: %lu\n", > mb_id); >- return offline_and_remove_memory(nid, addr, memory_block_size_bytes()); >+ return offline_and_remove_memory(vm->nid, addr, >+ memory_block_size_bytes()); > } > > /* >@@ -1659,6 +1649,10 @@ static int virtio_mem_init(struct virtio_mem *vm) > virtio_cread_le(vm->vdev, struct virtio_mem_config, region_size, > &vm->region_size); > >+ /* Determine the nid for the device based on the lowest address. */ >+ if (vm->nid == NUMA_NO_NODE) >+ vm->nid = memory_add_physaddr_to_nid(vm->addr); >+ > /* > * We always hotplug memory in memory block granularity. This way, > * we have to wait for exactly one memory block to online. >@@ -1707,7 +1701,7 @@ static int virtio_mem_init(struct virtio_mem *vm) > memory_block_size_bytes()); > dev_info(&vm->vdev->dev, "subblock size: 0x%llx", > (unsigned long long)vm->subblock_size); >- if (vm->nid != NUMA_NO_NODE) >+ if (vm->nid != NUMA_NO_NODE && IS_ENABLED(CONFIG_NUMA)) > dev_info(&vm->vdev->dev, "nid: %d", vm->nid); > > return 0; >-- >2.26.2
> Let's determine the target nid only once in case we have none specified - > usually, we'll end up with node 0 either way. > > Cc: "Michael S. Tsirkin" <mst@redhat.com> > Cc: Jason Wang <jasowang@redhat.com> > Cc: Pankaj Gupta <pankaj.gupta.linux@gmail.com> > Signed-off-by: David Hildenbrand <david@redhat.com> > --- > drivers/virtio/virtio_mem.c | 28 +++++++++++----------------- > 1 file changed, 11 insertions(+), 17 deletions(-) > > diff --git a/drivers/virtio/virtio_mem.c b/drivers/virtio/virtio_mem.c > index ba4de598f663..a1f5bf7a571a 100644 > --- a/drivers/virtio/virtio_mem.c > +++ b/drivers/virtio/virtio_mem.c > @@ -70,7 +70,7 @@ struct virtio_mem { > > /* The device block size (for communicating with the device). */ > uint64_t device_block_size; > - /* The translated node id. NUMA_NO_NODE in case not specified. */ > + /* The determined node id for all memory of the device. */ > int nid; > /* Physical start address of the memory region. */ > uint64_t addr; > @@ -406,10 +406,6 @@ static int virtio_mem_sb_bitmap_prepare_next_mb(struct virtio_mem *vm) > static int virtio_mem_mb_add(struct virtio_mem *vm, unsigned long mb_id) > { > const uint64_t addr = virtio_mem_mb_id_to_phys(mb_id); > - int nid = vm->nid; > - > - if (nid == NUMA_NO_NODE) > - nid = memory_add_physaddr_to_nid(addr); > > /* > * When force-unloading the driver and we still have memory added to > @@ -423,7 +419,8 @@ static int virtio_mem_mb_add(struct virtio_mem *vm, unsigned long mb_id) > } > > dev_dbg(&vm->vdev->dev, "adding memory block: %lu\n", mb_id); > - return add_memory_driver_managed(nid, addr, memory_block_size_bytes(), > + return add_memory_driver_managed(vm->nid, addr, > + memory_block_size_bytes(), > vm->resource_name, > MEMHP_MERGE_RESOURCE); > } > @@ -440,13 +437,9 @@ static int virtio_mem_mb_add(struct virtio_mem *vm, unsigned long mb_id) > static int virtio_mem_mb_remove(struct virtio_mem *vm, unsigned long mb_id) > { > const uint64_t addr = virtio_mem_mb_id_to_phys(mb_id); > - int nid = vm->nid; > - > - if (nid == NUMA_NO_NODE) > - nid = memory_add_physaddr_to_nid(addr); > > dev_dbg(&vm->vdev->dev, "removing memory block: %lu\n", mb_id); > - return remove_memory(nid, addr, memory_block_size_bytes()); > + return remove_memory(vm->nid, addr, memory_block_size_bytes()); > } > > /* > @@ -461,14 +454,11 @@ static int virtio_mem_mb_offline_and_remove(struct virtio_mem *vm, > unsigned long mb_id) > { > const uint64_t addr = virtio_mem_mb_id_to_phys(mb_id); > - int nid = vm->nid; > - > - if (nid == NUMA_NO_NODE) > - nid = memory_add_physaddr_to_nid(addr); > > dev_dbg(&vm->vdev->dev, "offlining and removing memory block: %lu\n", > mb_id); > - return offline_and_remove_memory(nid, addr, memory_block_size_bytes()); > + return offline_and_remove_memory(vm->nid, addr, > + memory_block_size_bytes()); > } > > /* > @@ -1659,6 +1649,10 @@ static int virtio_mem_init(struct virtio_mem *vm) > virtio_cread_le(vm->vdev, struct virtio_mem_config, region_size, > &vm->region_size); > > + /* Determine the nid for the device based on the lowest address. */ > + if (vm->nid == NUMA_NO_NODE) > + vm->nid = memory_add_physaddr_to_nid(vm->addr); > + > /* > * We always hotplug memory in memory block granularity. This way, > * we have to wait for exactly one memory block to online. > @@ -1707,7 +1701,7 @@ static int virtio_mem_init(struct virtio_mem *vm) > memory_block_size_bytes()); > dev_info(&vm->vdev->dev, "subblock size: 0x%llx", > (unsigned long long)vm->subblock_size); > - if (vm->nid != NUMA_NO_NODE) > + if (vm->nid != NUMA_NO_NODE && IS_ENABLED(CONFIG_NUMA)) > dev_info(&vm->vdev->dev, "nid: %d", vm->nid); > > return 0; Reviewed-by: Pankaj Gupta <pankaj.gupta.linux@gmail.com>
diff --git a/drivers/virtio/virtio_mem.c b/drivers/virtio/virtio_mem.c index ba4de598f663..a1f5bf7a571a 100644 --- a/drivers/virtio/virtio_mem.c +++ b/drivers/virtio/virtio_mem.c @@ -70,7 +70,7 @@ struct virtio_mem { /* The device block size (for communicating with the device). */ uint64_t device_block_size; - /* The translated node id. NUMA_NO_NODE in case not specified. */ + /* The determined node id for all memory of the device. */ int nid; /* Physical start address of the memory region. */ uint64_t addr; @@ -406,10 +406,6 @@ static int virtio_mem_sb_bitmap_prepare_next_mb(struct virtio_mem *vm) static int virtio_mem_mb_add(struct virtio_mem *vm, unsigned long mb_id) { const uint64_t addr = virtio_mem_mb_id_to_phys(mb_id); - int nid = vm->nid; - - if (nid == NUMA_NO_NODE) - nid = memory_add_physaddr_to_nid(addr); /* * When force-unloading the driver and we still have memory added to @@ -423,7 +419,8 @@ static int virtio_mem_mb_add(struct virtio_mem *vm, unsigned long mb_id) } dev_dbg(&vm->vdev->dev, "adding memory block: %lu\n", mb_id); - return add_memory_driver_managed(nid, addr, memory_block_size_bytes(), + return add_memory_driver_managed(vm->nid, addr, + memory_block_size_bytes(), vm->resource_name, MEMHP_MERGE_RESOURCE); } @@ -440,13 +437,9 @@ static int virtio_mem_mb_add(struct virtio_mem *vm, unsigned long mb_id) static int virtio_mem_mb_remove(struct virtio_mem *vm, unsigned long mb_id) { const uint64_t addr = virtio_mem_mb_id_to_phys(mb_id); - int nid = vm->nid; - - if (nid == NUMA_NO_NODE) - nid = memory_add_physaddr_to_nid(addr); dev_dbg(&vm->vdev->dev, "removing memory block: %lu\n", mb_id); - return remove_memory(nid, addr, memory_block_size_bytes()); + return remove_memory(vm->nid, addr, memory_block_size_bytes()); } /* @@ -461,14 +454,11 @@ static int virtio_mem_mb_offline_and_remove(struct virtio_mem *vm, unsigned long mb_id) { const uint64_t addr = virtio_mem_mb_id_to_phys(mb_id); - int nid = vm->nid; - - if (nid == NUMA_NO_NODE) - nid = memory_add_physaddr_to_nid(addr); dev_dbg(&vm->vdev->dev, "offlining and removing memory block: %lu\n", mb_id); - return offline_and_remove_memory(nid, addr, memory_block_size_bytes()); + return offline_and_remove_memory(vm->nid, addr, + memory_block_size_bytes()); } /* @@ -1659,6 +1649,10 @@ static int virtio_mem_init(struct virtio_mem *vm) virtio_cread_le(vm->vdev, struct virtio_mem_config, region_size, &vm->region_size); + /* Determine the nid for the device based on the lowest address. */ + if (vm->nid == NUMA_NO_NODE) + vm->nid = memory_add_physaddr_to_nid(vm->addr); + /* * We always hotplug memory in memory block granularity. This way, * we have to wait for exactly one memory block to online. @@ -1707,7 +1701,7 @@ static int virtio_mem_init(struct virtio_mem *vm) memory_block_size_bytes()); dev_info(&vm->vdev->dev, "subblock size: 0x%llx", (unsigned long long)vm->subblock_size); - if (vm->nid != NUMA_NO_NODE) + if (vm->nid != NUMA_NO_NODE && IS_ENABLED(CONFIG_NUMA)) dev_info(&vm->vdev->dev, "nid: %d", vm->nid); return 0;
Let's determine the target nid only once in case we have none specified - usually, we'll end up with node 0 either way. Cc: "Michael S. Tsirkin" <mst@redhat.com> Cc: Jason Wang <jasowang@redhat.com> Cc: Pankaj Gupta <pankaj.gupta.linux@gmail.com> Signed-off-by: David Hildenbrand <david@redhat.com> --- drivers/virtio/virtio_mem.c | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-)