Commit d634525d authored by Dave Chinner's avatar Dave Chinner Committed by Darrick J. Wong
Browse files

xfs: replace kmem_alloc_large() with kvmalloc()



There is no reason for this wrapper existing anymore. All the places
that use KM_NOFS allocation are within transaction contexts and
hence covered by memalloc_nofs_save/restore contexts. Hence we don't
need any special handling of vmalloc for large IOs anymore and
so special casing this code isn't necessary.

Signed-off-by: default avatarDave Chinner <dchinner@redhat.com>
Reviewed-by: default avatarDarrick J. Wong <djwong@kernel.org>
Signed-off-by: default avatarDarrick J. Wong <djwong@kernel.org>
parent 98fe2c3c
Loading
Loading
Loading
Loading
+0 −39
Original line number Diff line number Diff line
@@ -29,42 +29,3 @@ kmem_alloc(size_t size, xfs_km_flags_t flags)
		congestion_wait(BLK_RW_ASYNC, HZ/50);
	} while (1);
}


/*
 * __vmalloc() will allocate data pages and auxiliary structures (e.g.
 * pagetables) with GFP_KERNEL, yet we may be under GFP_NOFS context here. Hence
 * we need to tell memory reclaim that we are in such a context via
 * PF_MEMALLOC_NOFS to prevent memory reclaim re-entering the filesystem here
 * and potentially deadlocking.
 */
static void *
__kmem_vmalloc(size_t size, xfs_km_flags_t flags)
{
	unsigned nofs_flag = 0;
	void	*ptr;
	gfp_t	lflags = kmem_flags_convert(flags);

	if (flags & KM_NOFS)
		nofs_flag = memalloc_nofs_save();

	ptr = __vmalloc(size, lflags);

	if (flags & KM_NOFS)
		memalloc_nofs_restore(nofs_flag);

	return ptr;
}

void *
kmem_alloc_large(size_t size, xfs_km_flags_t flags)
{
	void	*ptr;

	trace_kmem_alloc_large(size, flags, _RET_IP_);

	ptr = kmem_alloc(size, flags | KM_MAYFAIL);
	if (ptr)
		return ptr;
	return __kmem_vmalloc(size, flags);
}
+0 −1
Original line number Diff line number Diff line
@@ -57,7 +57,6 @@ kmem_flags_convert(xfs_km_flags_t flags)
}

extern void *kmem_alloc(size_t, xfs_km_flags_t);
extern void *kmem_alloc_large(size_t size, xfs_km_flags_t);
static inline void  kmem_free(const void *ptr)
{
	kvfree(ptr);
+1 −1
Original line number Diff line number Diff line
@@ -489,7 +489,7 @@ xfs_attr_copy_value(
	}

	if (!args->value) {
		args->value = kmem_alloc_large(valuelen, KM_NOLOCKDEP);
		args->value = kvmalloc(valuelen, GFP_KERNEL | __GFP_NOLOCKDEP);
		if (!args->value)
			return -ENOMEM;
	}
+8 −6
Original line number Diff line number Diff line
@@ -25,11 +25,11 @@
 * reallocating the buffer if necessary.  Buffer contents are not preserved
 * across a reallocation.
 */
int
static int
xchk_setup_xattr_buf(
	struct xfs_scrub	*sc,
	size_t			value_size,
	xfs_km_flags_t		flags)
	gfp_t			flags)
{
	size_t			sz;
	struct xchk_xattr_buf	*ab = sc->buf;
@@ -57,7 +57,7 @@ xchk_setup_xattr_buf(
	 * Don't zero the buffer upon allocation to avoid runtime overhead.
	 * All users must be careful never to read uninitialized contents.
	 */
	ab = kmem_alloc_large(sizeof(*ab) + sz, flags);
	ab = kvmalloc(sizeof(*ab) + sz, flags);
	if (!ab)
		return -ENOMEM;

@@ -79,7 +79,7 @@ xchk_setup_xattr(
	 * without the inode lock held, which means we can sleep.
	 */
	if (sc->flags & XCHK_TRY_HARDER) {
		error = xchk_setup_xattr_buf(sc, XATTR_SIZE_MAX, 0);
		error = xchk_setup_xattr_buf(sc, XATTR_SIZE_MAX, GFP_KERNEL);
		if (error)
			return error;
	}
@@ -138,7 +138,8 @@ xchk_xattr_listent(
	 * doesn't work, we overload the seen_enough variable to convey
	 * the error message back to the main scrub function.
	 */
	error = xchk_setup_xattr_buf(sx->sc, valuelen, KM_MAYFAIL);
	error = xchk_setup_xattr_buf(sx->sc, valuelen,
			GFP_KERNEL | __GFP_RETRY_MAYFAIL);
	if (error == -ENOMEM)
		error = -EDEADLOCK;
	if (error) {
@@ -323,7 +324,8 @@ xchk_xattr_block(
		return 0;

	/* Allocate memory for block usage checking. */
	error = xchk_setup_xattr_buf(ds->sc, 0, KM_MAYFAIL);
	error = xchk_setup_xattr_buf(ds->sc, 0,
			GFP_KERNEL | __GFP_RETRY_MAYFAIL);
	if (error == -ENOMEM)
		return -EDEADLOCK;
	if (error)
+0 −3
Original line number Diff line number Diff line
@@ -65,7 +65,4 @@ xchk_xattr_dstmap(
			BITS_TO_LONGS(sc->mp->m_attr_geo->blksize);
}

int xchk_setup_xattr_buf(struct xfs_scrub *sc, size_t value_size,
		xfs_km_flags_t flags);

#endif	/* __XFS_SCRUB_ATTR_H__ */
Loading