linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm: zbud: fix condition check on allocation size
@ 2013-07-17 14:30 Heesub Shin
  2013-07-18 12:48 ` Bob Liu
  0 siblings, 1 reply; 2+ messages in thread
From: Heesub Shin @ 2013-07-17 14:30 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Seth Jennings, linux-mm, linux-kernel, Dongjun Shin, Sunae Seo,
	Heesub Shin, Heesub Shin

zbud_alloc() incorrectly verifies the size of allocation limit. It
should deny the allocation request greater than (PAGE_SIZE -
ZHDR_SIZE_ALIGNED - CHUNK_SIZE), not (PAGE_SIZE - ZHDR_SIZE_ALIGNED)
which has no remaining spaces for its buddy. There is no point in
spending the entire zbud page storing only a single page, since we don't
have any benefits.

Signed-off-by: Heesub Shin <heesub.shin@samsung.com>
---
 mm/zbud.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/zbud.c b/mm/zbud.c
index 9bb4710..ad1e781 100644
--- a/mm/zbud.c
+++ b/mm/zbud.c
@@ -257,7 +257,7 @@ int zbud_alloc(struct zbud_pool *pool, int size, gfp_t gfp,
 
 	if (size <= 0 || gfp & __GFP_HIGHMEM)
 		return -EINVAL;
-	if (size > PAGE_SIZE - ZHDR_SIZE_ALIGNED)
+	if (size > PAGE_SIZE - ZHDR_SIZE_ALIGNED - CHUNK_SIZE)
 		return -ENOSPC;
 	chunks = size_to_chunks(size);
 	spin_lock(&pool->lock);
-- 
1.8.3.2

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] mm: zbud: fix condition check on allocation size
  2013-07-17 14:30 [PATCH] mm: zbud: fix condition check on allocation size Heesub Shin
@ 2013-07-18 12:48 ` Bob Liu
  0 siblings, 0 replies; 2+ messages in thread
From: Bob Liu @ 2013-07-18 12:48 UTC (permalink / raw)
  To: Heesub Shin
  Cc: Andrew Morton, Seth Jennings, linux-mm, linux-kernel,
	Dongjun Shin, Sunae Seo, Heesub Shin

On 07/17/2013 10:30 PM, Heesub Shin wrote:
> zbud_alloc() incorrectly verifies the size of allocation limit. It
> should deny the allocation request greater than (PAGE_SIZE -
> ZHDR_SIZE_ALIGNED - CHUNK_SIZE), not (PAGE_SIZE - ZHDR_SIZE_ALIGNED)
> which has no remaining spaces for its buddy. There is no point in
> spending the entire zbud page storing only a single page, since we don't
> have any benefits.
> 
> Signed-off-by: Heesub Shin <heesub.shin@samsung.com>

Looks good to me, although I'm thinking to make it more aggressive.
eg. minus two or three times of CHUNK_SIZE.

> ---
>  mm/zbud.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/mm/zbud.c b/mm/zbud.c
> index 9bb4710..ad1e781 100644
> --- a/mm/zbud.c
> +++ b/mm/zbud.c
> @@ -257,7 +257,7 @@ int zbud_alloc(struct zbud_pool *pool, int size, gfp_t gfp,
>  
>  	if (size <= 0 || gfp & __GFP_HIGHMEM)
>  		return -EINVAL;
> -	if (size > PAGE_SIZE - ZHDR_SIZE_ALIGNED)
> +	if (size > PAGE_SIZE - ZHDR_SIZE_ALIGNED - CHUNK_SIZE)
>  		return -ENOSPC;
>  	chunks = size_to_chunks(size);
>  	spin_lock(&pool->lock);
> 

-- 
Regards,
-Bob

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-07-18 12:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-07-17 14:30 [PATCH] mm: zbud: fix condition check on allocation size Heesub Shin
2013-07-18 12:48 ` Bob Liu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox