Message ID | 20210707222111.16339-5-allison.henderson@oracle.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | Delayed Attributes | expand |
On Wed, Jul 07, 2021 at 03:21:02PM -0700, Allison Henderson wrote: > Because xattrs can be over a page in size, we need to handle possible > krealloc errors to avoid warnings. If the allocation does fail, fall > back to kmem_alloc_large, with a memcpy. > > The warning: > WARNING: CPU: 1 PID: 20255 at mm/page_alloc.c:3446 > get_page_from_freelist+0x100b/0x1690 > > is caused when sizes larger that a page are allocated with the > __GFP_NOFAIL flag option. We encounter this error now because attr > values can be up to 64k in size. So we cannot use __GFP_NOFAIL, and > we need to handle the error code if the allocation fails. > > Signed-off-by: Allison Henderson <allison.henderson@oracle.com> I'm pretty sure that 'mm: Add kvrealloc' fixes this a little more elegantly, but either look fine to me. So while I'll probably take Dave's, here's a: Reviewed-by: Darrick J. Wong <djwong@kernel.org> in the meantime. --D > --- > fs/xfs/xfs_log_recover.c | 10 +++++++++- > 1 file changed, 9 insertions(+), 1 deletion(-) > > diff --git a/fs/xfs/xfs_log_recover.c b/fs/xfs/xfs_log_recover.c > index ec4ccae..6ab467b 100644 > --- a/fs/xfs/xfs_log_recover.c > +++ b/fs/xfs/xfs_log_recover.c > @@ -2062,7 +2062,15 @@ xlog_recover_add_to_cont_trans( > old_ptr = item->ri_buf[item->ri_cnt-1].i_addr; > old_len = item->ri_buf[item->ri_cnt-1].i_len; > > - ptr = krealloc(old_ptr, len + old_len, GFP_KERNEL | __GFP_NOFAIL); > + ptr = krealloc(old_ptr, len + old_len, GFP_KERNEL); > + if (ptr == NULL) { > + ptr = kmem_alloc_large(len + old_len, KM_ZERO); > + if (ptr == NULL) > + return -ENOMEM; > + > + memcpy(ptr, old_ptr, old_len); > + } > + > memcpy(&ptr[old_len], dp, len); > item->ri_buf[item->ri_cnt-1].i_len += len; > item->ri_buf[item->ri_cnt-1].i_addr = ptr; > -- > 2.7.4 >
On 7/8/21 9:09 PM, Darrick J. Wong wrote: > On Wed, Jul 07, 2021 at 03:21:02PM -0700, Allison Henderson wrote: >> Because xattrs can be over a page in size, we need to handle possible >> krealloc errors to avoid warnings. If the allocation does fail, fall >> back to kmem_alloc_large, with a memcpy. >> >> The warning: >> WARNING: CPU: 1 PID: 20255 at mm/page_alloc.c:3446 >> get_page_from_freelist+0x100b/0x1690 >> >> is caused when sizes larger that a page are allocated with the >> __GFP_NOFAIL flag option. We encounter this error now because attr >> values can be up to 64k in size. So we cannot use __GFP_NOFAIL, and >> we need to handle the error code if the allocation fails. >> >> Signed-off-by: Allison Henderson <allison.henderson@oracle.com> > > I'm pretty sure that 'mm: Add kvrealloc' fixes this a little more > elegantly, but either look fine to me. So while I'll probably take > Dave's, here's a: > > Reviewed-by: Darrick J. Wong <djwong@kernel.org> > > in the meantime. Alrighty, thank you! Either is fine. Allison > > --D > >> --- >> fs/xfs/xfs_log_recover.c | 10 +++++++++- >> 1 file changed, 9 insertions(+), 1 deletion(-) >> >> diff --git a/fs/xfs/xfs_log_recover.c b/fs/xfs/xfs_log_recover.c >> index ec4ccae..6ab467b 100644 >> --- a/fs/xfs/xfs_log_recover.c >> +++ b/fs/xfs/xfs_log_recover.c >> @@ -2062,7 +2062,15 @@ xlog_recover_add_to_cont_trans( >> old_ptr = item->ri_buf[item->ri_cnt-1].i_addr; >> old_len = item->ri_buf[item->ri_cnt-1].i_len; >> >> - ptr = krealloc(old_ptr, len + old_len, GFP_KERNEL | __GFP_NOFAIL); >> + ptr = krealloc(old_ptr, len + old_len, GFP_KERNEL); >> + if (ptr == NULL) { >> + ptr = kmem_alloc_large(len + old_len, KM_ZERO); >> + if (ptr == NULL) >> + return -ENOMEM; >> + >> + memcpy(ptr, old_ptr, old_len); >> + } >> + >> memcpy(&ptr[old_len], dp, len); >> item->ri_buf[item->ri_cnt-1].i_len += len; >> item->ri_buf[item->ri_cnt-1].i_addr = ptr; >> -- >> 2.7.4 >>
diff --git a/fs/xfs/xfs_log_recover.c b/fs/xfs/xfs_log_recover.c index ec4ccae..6ab467b 100644 --- a/fs/xfs/xfs_log_recover.c +++ b/fs/xfs/xfs_log_recover.c @@ -2062,7 +2062,15 @@ xlog_recover_add_to_cont_trans( old_ptr = item->ri_buf[item->ri_cnt-1].i_addr; old_len = item->ri_buf[item->ri_cnt-1].i_len; - ptr = krealloc(old_ptr, len + old_len, GFP_KERNEL | __GFP_NOFAIL); + ptr = krealloc(old_ptr, len + old_len, GFP_KERNEL); + if (ptr == NULL) { + ptr = kmem_alloc_large(len + old_len, KM_ZERO); + if (ptr == NULL) + return -ENOMEM; + + memcpy(ptr, old_ptr, old_len); + } + memcpy(&ptr[old_len], dp, len); item->ri_buf[item->ri_cnt-1].i_len += len; item->ri_buf[item->ri_cnt-1].i_addr = ptr;
Because xattrs can be over a page in size, we need to handle possible krealloc errors to avoid warnings. If the allocation does fail, fall back to kmem_alloc_large, with a memcpy. The warning: WARNING: CPU: 1 PID: 20255 at mm/page_alloc.c:3446 get_page_from_freelist+0x100b/0x1690 is caused when sizes larger that a page are allocated with the __GFP_NOFAIL flag option. We encounter this error now because attr values can be up to 64k in size. So we cannot use __GFP_NOFAIL, and we need to handle the error code if the allocation fails. Signed-off-by: Allison Henderson <allison.henderson@oracle.com> --- fs/xfs/xfs_log_recover.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)