From: Dave Chinner <david@fromorbit.com>
To: linux-xfs@vger.kernel.org
Cc: hch@lst.de
Subject: [PATCH 04/10] xfs: merge _xfs_buf_get_pages()
Date: Thu, 27 May 2021 08:47:16 +1000 [thread overview]
Message-ID: <20210526224722.1111377-5-david@fromorbit.com> (raw)
In-Reply-To: <20210526224722.1111377-1-david@fromorbit.com>
From: Dave Chinner <dchinner@redhat.com>
Only called from one place now, so merge it into
xfs_buf_alloc_pages(). Because page array allocation is dependent on
bp->b_pages being null, always ensure that when the pages array is
freed we always set bp->b_pages to null.
Also convert the page array to use kmalloc() rather than
kmem_alloc() so we can use the gfp flags we've already calculated
for the allocation context instead of hard coding KM_NOFS semantics.
Signed-off-by: Dave Chinner <dchinner@redhat.com>
---
fs/xfs/xfs_buf.c | 48 ++++++++++++++----------------------------------
1 file changed, 14 insertions(+), 34 deletions(-)
diff --git a/fs/xfs/xfs_buf.c b/fs/xfs/xfs_buf.c
index 8ca4add138c5..aa978111c01f 100644
--- a/fs/xfs/xfs_buf.c
+++ b/fs/xfs/xfs_buf.c
@@ -272,31 +272,6 @@ _xfs_buf_alloc(
return 0;
}
-/*
- * Allocate a page array capable of holding a specified number
- * of pages, and point the page buf at it.
- */
-STATIC int
-_xfs_buf_get_pages(
- struct xfs_buf *bp,
- int page_count)
-{
- /* Make sure that we have a page list */
- if (bp->b_pages == NULL) {
- bp->b_page_count = page_count;
- if (page_count <= XB_PAGES) {
- bp->b_pages = bp->b_page_array;
- } else {
- bp->b_pages = kmem_alloc(sizeof(struct page *) *
- page_count, KM_NOFS);
- if (bp->b_pages == NULL)
- return -ENOMEM;
- }
- memset(bp->b_pages, 0, sizeof(struct page *) * page_count);
- }
- return 0;
-}
-
/*
* Frees b_pages if it was allocated.
*/
@@ -304,10 +279,9 @@ STATIC void
_xfs_buf_free_pages(
struct xfs_buf *bp)
{
- if (bp->b_pages != bp->b_page_array) {
+ if (bp->b_pages != bp->b_page_array)
kmem_free(bp->b_pages);
- bp->b_pages = NULL;
- }
+ bp->b_pages = NULL;
}
/*
@@ -389,16 +363,22 @@ xfs_buf_alloc_pages(
long filled = 0;
int error;
+ /* Make sure that we have a page list */
+ bp->b_page_count = page_count;
+ if (bp->b_page_count <= XB_PAGES) {
+ bp->b_pages = bp->b_page_array;
+ } else {
+ bp->b_pages = kzalloc(sizeof(struct page *) * bp->b_page_count,
+ gfp_mask);
+ if (!bp->b_pages)
+ return -ENOMEM;
+ }
+ bp->b_flags |= _XBF_PAGES;
+
/* Assure zeroed buffer for non-read cases. */
if (!(flags & XBF_READ))
gfp_mask |= __GFP_ZERO;
- error = _xfs_buf_get_pages(bp, page_count);
- if (unlikely(error))
- return error;
-
- bp->b_flags |= _XBF_PAGES;
-
/*
* Bulk filling of pages can take multiple calls. Not filling the entire
* array is not an allocation failure, so don't back off if we get at
--
2.31.1
next prev parent reply other threads:[~2021-05-26 22:47 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-26 22:47 [PATCH 00/10] xfs: buffer bulk page allocation and cleanups Dave Chinner
2021-05-26 22:47 ` [PATCH 01/10] xfs: split up xfs_buf_allocate_memory Dave Chinner
2021-05-27 22:48 ` Darrick J. Wong
2021-05-27 23:10 ` Darrick J. Wong
2021-05-26 22:47 ` [PATCH 02/10] xfs: use xfs_buf_alloc_pages for uncached buffers Dave Chinner
2021-05-27 22:50 ` Darrick J. Wong
2021-05-26 22:47 ` [PATCH 03/10] xfs: use alloc_pages_bulk_array() for buffers Dave Chinner
2021-05-27 22:59 ` Darrick J. Wong
2021-05-27 23:01 ` Darrick J. Wong
2021-05-26 22:47 ` Dave Chinner [this message]
2021-05-27 23:02 ` [PATCH 04/10] xfs: merge _xfs_buf_get_pages() Darrick J. Wong
2021-05-26 22:47 ` [PATCH 05/10] xfs: move page freeing into _xfs_buf_free_pages() Dave Chinner
2021-05-27 23:03 ` Darrick J. Wong
2021-05-26 22:47 ` [PATCH 06/10] xfs: remove ->b_offset handling for page backed buffers Dave Chinner
2021-05-27 23:09 ` Darrick J. Wong
2021-06-01 1:46 ` Dave Chinner
2021-05-26 22:47 ` [PATCH 07/10] xfs: simplify the b_page_count calculation Dave Chinner
2021-05-27 23:15 ` Darrick J. Wong
2021-05-27 23:29 ` Dave Chinner
2021-05-26 22:47 ` [PATCH 08/10] xfs: get rid of xb_to_gfp() Dave Chinner
2021-05-27 23:12 ` Darrick J. Wong
2021-05-26 22:47 ` [PATCH 09/10] xfs: cleanup error handling in xfs_buf_get_map Dave Chinner
2021-05-27 23:16 ` Darrick J. Wong
2021-05-26 22:47 ` [PATCH 10/10] xfs: merge xfs_buf_allocate_memory Dave Chinner
2021-05-27 23:17 ` Darrick J. Wong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210526224722.1111377-5-david@fromorbit.com \
--to=david@fromorbit.com \
--cc=hch@lst.de \
--cc=linux-xfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox