Skip to contentSkip to conversation

kmalloc: Return NULL instead of link failure

PATCH Applied Jeff Mahoney 3 participants 4 messages Jan 20, 2009 – Jan 27, 2009 Memory management

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kmalloc: Return NULL instead of link failure

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

The SLAB kmalloc with a constant value isn't consistent with the other implementations because it bails out with __you_cannot_kmalloc_that_much rather than returning NULL and properly allowing the caller to fall back to vmalloc or take other action. This doesn't happen with a non-constant value or with SLOB or SLUB.

Starting with 2.6.28, I've been seeing build failures on s390x. This is due to init_section_page_cgroup trying to allocate 2.5MB when the max size for a kmalloc on s390x is 2MB.

It's failing because the value is constant. The workarounds at the call size are ugly and the caller shouldn't have to change behavior depending on what the backend of the API is.

So, this patch eliminates the link failure and returns NULL like the other implementations.

- ---

 include/linux/slab_def.h |   10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

- --- a/include/linux/slab_def.h
+++ b/include/linux/slab_def.h
@@ -43,10 +43,7 @@ static inline void *kmalloc(size_t size,
i++;
#include <linux/kmalloc_sizes.h>
#undef CACHE
- - {
- - extern void __you_cannot_kmalloc_that_much(void);
- - __you_cannot_kmalloc_that_much();
- - }
+ return NULL;
found:
#ifdef CONFIG_ZONE_DMA
if (flags & GFP_DMA)
@@ -77,10 +74,7 @@ static inline void *kmalloc_node(size_t
i++;
#include <linux/kmalloc_sizes.h>
#undef CACHE
- - {
- - extern void __you_cannot_kmalloc_that_much(void);
- - __you_cannot_kmalloc_that_much();
- - }
+ return NULL;
found:
#ifdef CONFIG_ZONE_DMA
if (flags & GFP_DMA)

- --
Jeff Mahoney
SUSE Labs
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)
Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org

iEYEARECAAYFAkl183YACgkQLPWxlyuTD7IMnQCfbf4NvJuyTustFrdJD/lcl6ub QQ0AniWOsKCWnBWuLLnm6rM+Atq6LBfd
=/evL
-----END PGP SIGNATURE-----

maintainer
#1 lore raw
Quoted 13 lines · On Tue, 20 Jan 2009 10:53:26 -0500 Jeff Mahoney <[email protected]> wrote:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

The SLAB kmalloc with a constant value isn't consistent with the other implementations because it bails out with __you_cannot_kmalloc_that_much rather than returning NULL and properly allowing the caller to fall back to vmalloc or take other action. This doesn't happen with a non-constant value or with SLOB or SLUB.

Starting with 2.6.28, I've been seeing build failures on s390x. This is due to init_section_page_cgroup trying to allocate 2.5MB when the max size for a kmalloc on s390x is 2MB.

Quoted 7 lines

It's failing because the value is constant. The workarounds at the call size are ugly and the caller shouldn't have to change behavior depending on what the backend of the API is.

So, this patch eliminates the link failure and returns NULL like the other implementations.

OK by me, is that's what the other sl[abcd...xyz]b.c implementations do.

That __you_cannot_kmalloc_that_much() thing has frequently been a PITA anyway - some gcc versions flub the constant_p() test and end up referencing __you_cannot_kmalloc_that_much() when the callsite was passing a variable `size' arg.

Quoted 21 lines

- ---

 include/linux/slab_def.h |   10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

- --- a/include/linux/slab_def.h
+++ b/include/linux/slab_def.h

(quoted diff) +1 -4
@@ -43,10 +43,7 @@ static inline void *kmalloc(size_t size,
 			i++;
 #include <linux/kmalloc_sizes.h>
 #undef CACHE
- -		{
- -			extern void __you_cannot_kmalloc_that_much(void);
- -			__you_cannot_kmalloc_that_much();
- -		}
+		return NULL;
 found:
 #ifdef CONFIG_ZONE_DMA
 		if (flags & GFP_DMA)
@@ -77,10 +74,7 @@ static inline void *kmalloc_node(size_t
 			i++;

Review static inline void *kmalloc_node(size_t · line 80

Quoted 10 lines
(quoted diff) +1 -4
 #include <linux/kmalloc_sizes.h>
 #undef CACHE
- -		{
- -			extern void __you_cannot_kmalloc_that_much(void);
- -			__you_cannot_kmalloc_that_much();
- -		}
+		return NULL;
 found:
 #ifdef CONFIG_ZONE_DMA
 		if (flags & GFP_DMA)

Strange patch format, but it applied.

I'll punt this patch in the Pekka direction.

Do you think we should include it in 2.6.28.x?

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#2 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 1 line · Andrew Morton

Strange patch format, but it applied.

Ugh, sorry about that. I forgot to disable the GPG signing. It escapes
- -'s like that.

Quoted 3 lines

I'll punt this patch in the Pekka direction.

Do you think we should include it in 2.6.28.x?

I think so. It's a corner case, but does fix a build failure.

- -Jeff

- --
Jeff Mahoney
SUSE Labs
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)
Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org

iEYEARECAAYFAkl/gCcACgkQLPWxlyuTD7IdcwCgkdOmH3P8a9q1RQYsOcCkG8C0 TYsAn3rEJMROguhVqbWuFlzg58t+vVEL
=RM/e
-----END PGP SIGNATURE-----

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

Applied
#3 lore raw
In reply to Andrew Morton
Quoted 31 lines · Andrew Morton
Quoted 13 lines · On Tue, 20 Jan 2009 10:53:26 -0500 Jeff Mahoney <[email protected]> wrote:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

The SLAB kmalloc with a constant value isn't consistent with the other implementations because it bails out with __you_cannot_kmalloc_that_much rather than returning NULL and properly allowing the caller to fall back to vmalloc or take other action. This doesn't happen with a non-constant value or with SLOB or SLUB.

Starting with 2.6.28, I've been seeing build failures on s390x. This is due to init_section_page_cgroup trying to allocate 2.5MB when the max size for a kmalloc on s390x is 2MB.

Quoted 7 lines

It's failing because the value is constant. The workarounds at the call size are ugly and the caller shouldn't have to change behavior depending on what the backend of the API is.

So, this patch eliminates the link failure and returns NULL like the other implementations.

OK by me, is that's what the other sl[abcd...xyz]b.c implementations do.

That __you_cannot_kmalloc_that_much() thing has frequently been a PITA anyway - some gcc versions flub the constant_p() test and end up referencing __you_cannot_kmalloc_that_much() when the callsite was passing a variable `size' arg.

[snip]

Quoted 3 lines

Strange patch format, but it applied.

I'll punt this patch in the Pekka direction.

Applied, thanks!

Pekka

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>