Message ID | 20171123161137.ncjqskbvdm6dgb3z@dhcp22.suse.cz (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Michal Hocko wrote: > Hmm, you are right. I have (blindly) followed the current code flow > which is wrong as well. The following should do the trick. Should I > split that into two patches? Well, xfs_alloc_buftarg() needs to be more careful. xfs_alloc_buftarg( struct xfs_mount *mp, struct block_device *bdev, struct dax_device *dax_dev) { xfs_buftarg_t *btp; btp = kmem_zalloc(sizeof(*btp), KM_SLEEP | KM_NOFS); // This is GFP_NOFS context. But... btp->bt_mount = mp; btp->bt_dev = bdev->bd_dev; btp->bt_bdev = bdev; btp->bt_daxdev = dax_dev; if (xfs_setsize_buftarg_early(btp, bdev)) goto error; if (list_lru_init(&btp->bt_lru)) // This is GFP_KERNEL context. goto error; if (percpu_counter_init(&btp->bt_io_count, 0, GFP_KERNEL)) // This is GFP_KERNEL context. goto error; // Need to undo list_lru_init() before kmem_free(). btp->bt_shrinker.count_objects = xfs_buftarg_shrink_count; btp->bt_shrinker.scan_objects = xfs_buftarg_shrink_scan; btp->bt_shrinker.seeks = DEFAULT_SEEKS; btp->bt_shrinker.flags = SHRINKER_NUMA_AWARE; register_shrinker(&btp->bt_shrinker); // This is GFP_KERNEL context. return btp; error: kmem_free(btp); return NULL; } -- To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Fri 24-11-17 01:17:12, Tetsuo Handa wrote: > Michal Hocko wrote: > > Hmm, you are right. I have (blindly) followed the current code flow > > which is wrong as well. The following should do the trick. Should I > > split that into two patches? > > Well, xfs_alloc_buftarg() needs to be more careful. [...] > btp = kmem_zalloc(sizeof(*btp), KM_SLEEP | KM_NOFS); // This is GFP_NOFS context. But... [...] > if (list_lru_init(&btp->bt_lru)) // This is GFP_KERNEL context. this sounds like a separate thing to cleanup or document.
On Thu, Nov 23, 2017 at 05:11:37PM +0100, Michal Hocko wrote: > On Fri 24-11-17 01:01:10, Tetsuo Handa wrote: > > Michal Hocko wrote: > > > On Thu 23-11-17 05:26:33, Christoph Hellwig wrote: > > > > Looks good, > > > > > > > > Reviewed-by: Christoph Hellwig <hch@lst.de> > > > > > > Thanks! > > > > > > > I can take a stab at the quota one. > > > > > > That would be really great! > > > > > Again, it does not look good. Since kmem_free() does only kvfree(), > > nothing will release memory allocated by list_lru_init(). > > Hmm, you are right. I have (blindly) followed the current code flow > which is wrong as well. The following should do the trick. Should I > split that into two patches? One is fine by me - if we're need to backport one fix, then we need to backport both :/ > --- > diff --git a/fs/xfs/xfs_buf.c b/fs/xfs/xfs_buf.c > index dd0e18af990c..4c6e86d861fd 100644 > --- a/fs/xfs/xfs_buf.c > +++ b/fs/xfs/xfs_buf.c > @@ -1815,25 +1815,27 @@ xfs_alloc_buftarg( > btp->bt_daxdev = dax_dev; > > if (xfs_setsize_buftarg_early(btp, bdev)) > - goto error; > + goto error_free; > > if (list_lru_init(&btp->bt_lru)) > - goto error; > + goto error_free; > > if (percpu_counter_init(&btp->bt_io_count, 0, GFP_KERNEL)) > - goto error; > + goto error_lru; > > btp->bt_shrinker.count_objects = xfs_buftarg_shrink_count; > btp->bt_shrinker.scan_objects = xfs_buftarg_shrink_scan; > btp->bt_shrinker.seeks = DEFAULT_SEEKS; > btp->bt_shrinker.flags = SHRINKER_NUMA_AWARE; > - if (register_shrinker(&btp->bt_shrinker)) { > - percpu_counter_destroy(&btp->bt_io_count); > - goto error; > - } > + if (register_shrinker(&btp->bt_shrinker)) > + goto error_pcpu; > return btp; > > -error: > +error_pcpu: > + percpu_counter_destroy(&btp->bt_io_count); > +error_lru: > + list_lru_destroy(&btp->bt_lru); > +error_free: > kmem_free(btp); > return NULL; That should do the trick. Acked-by: Dave Chinner <dchinner@redhat.com> Cheers, Dave.
diff --git a/fs/xfs/xfs_buf.c b/fs/xfs/xfs_buf.c index dd0e18af990c..4c6e86d861fd 100644 --- a/fs/xfs/xfs_buf.c +++ b/fs/xfs/xfs_buf.c @@ -1815,25 +1815,27 @@ xfs_alloc_buftarg( btp->bt_daxdev = dax_dev; if (xfs_setsize_buftarg_early(btp, bdev)) - goto error; + goto error_free; if (list_lru_init(&btp->bt_lru)) - goto error; + goto error_free; if (percpu_counter_init(&btp->bt_io_count, 0, GFP_KERNEL)) - goto error; + goto error_lru; btp->bt_shrinker.count_objects = xfs_buftarg_shrink_count; btp->bt_shrinker.scan_objects = xfs_buftarg_shrink_scan; btp->bt_shrinker.seeks = DEFAULT_SEEKS; btp->bt_shrinker.flags = SHRINKER_NUMA_AWARE; - if (register_shrinker(&btp->bt_shrinker)) { - percpu_counter_destroy(&btp->bt_io_count); - goto error; - } + if (register_shrinker(&btp->bt_shrinker)) + goto error_pcpu; return btp; -error: +error_pcpu: + percpu_counter_destroy(&btp->bt_io_count); +error_lru: + list_lru_destroy(&btp->bt_lru); +error_free: kmem_free(btp); return NULL; }