Skip to contentSkip to conversation

drivers, vmw_balloon.c: Determine page allocation flag can_sleep outside loop.

PATCH In review Rakib Mullick 3 participants 5 messages Oct 17, 2011

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drivers, vmw_balloon.c: Determine page allocation flag can_sleep outside loop.

In vmballoon_reserve_page function, flags has been passed from the callee function (vmballoon_inflate here). So, we can determine can_sleep outside the loop.

---

drivers/misc/vmw_balloon.c +1 -1
index 053d36c..6983d80 100644
@@ -412,6 +412,7 @@ static int vmballoon_reserve_page(struct vmballoon *b, bool can_sleep)
 	gfp_t flags;
 	unsigned int hv_status;
 	bool locked = false;
+	flags = can_sleep ? VMW_PAGE_ALLOC_CANSLEEP : VMW_PAGE_ALLOC_NOSLEEP;
 
 	do {
 		if (!can_sleep)
@@ -419,7 +420,6 @@ static int vmballoon_reserve_page(struct vmballoon *b, bool can_sleep)
 		else
 			STATS_INC(b->stats.sleep_alloc);
 
-		flags = can_sleep ? VMW_PAGE_ALLOC_CANSLEEP : VMW_PAGE_ALLOC_NOSLEEP;
 		page = alloc_page(flags);
 		if (!page) {
 			if (!can_sleep)
Acked-by on v1 1/1
#1 lore raw
Quoted 5 lines · Rakib Mullick

In vmballoon_reserve_page function, flags has been passed from the
callee function (vmballoon_inflate here). So, we can determine can_sleep outside the loop.

Thanks Rakib.

Quoted 15 lines

---

drivers/misc/vmw_balloon.c +1 -0
index 053d36c..6983d80 100644
@@ -412,6 +412,7 @@ static int vmballoon_reserve_page(struct vmballoon
 *b, bool can_sleep) gfp_t flags;
 	unsigned int hv_status;
 	bool locked = false;
+	flags = can_sleep ? VMW_PAGE_ALLOC_CANSLEEP : VMW_PAGE_ALLOC_NOSLEEP;
 
 	do {
 		if (!can_sleep)

drivers/misc/vmw_balloon.c static int vmballoon_reserve_page(struct vmballoon · line 422

Quoted 4 lines
drivers/misc/vmw_balloon.c +0 -1
@@ -419,7 +420,6 @@ static int vmballoon_reserve_page(struct vmballoon
 *b, bool can_sleep) else
 			STATS_INC(b->stats.sleep_alloc);
 
-		flags = can_sleep ? VMW_PAGE_ALLOC_CANSLEEP : 

VMW_PAGE_ALLOC_NOSLEEP;

Quoted 3 lines
drivers/misc/vmw_balloon.c +0 -0
 		page = alloc_page(flags);
 		if (!page) {
 			if (!can_sleep)
#2 lore raw
In reply to Rakib Mullick

drivers/misc/vmw_balloon.c static int vmballoon_reserve_page(struct vmballoon *b, bool can_sleep) · line 418

Quoted 12 lines · Rakib Mullick
drivers/misc/vmw_balloon.c +1 -0
index 053d36c..6983d80 100644
@@ -412,6 +412,7 @@ static int vmballoon_reserve_page(struct vmballoon *b, bool can_sleep)
 	gfp_t flags;
 	unsigned int hv_status;
 	bool locked = false;
+	flags = can_sleep ? VMW_PAGE_ALLOC_CANSLEEP : VMW_PAGE_ALLOC_NOSLEEP;
 
 	do {
 		if (!can_sleep)

Should be folded in with the declaration of gfp_t flags.

Would you also like to add a might_sleep_if(can_sleep) here?

Quoted 8 lines
drivers/misc/vmw_balloon.c +0 -1
@@ -419,7 +420,6 @@ static int vmballoon_reserve_page(struct vmballoon *b, bool can_sleep)
 		else
 			STATS_INC(b->stats.sleep_alloc);
 
-		flags = can_sleep ? VMW_PAGE_ALLOC_CANSLEEP : VMW_PAGE_ALLOC_NOSLEEP;
 		page = alloc_page(flags);
 		if (!page) {
 			if (!can_sleep)
#3 lore raw
Quoted 12 lines · David Rientjes
Quoted 10 lines · Rakib Mullick
drivers/misc/vmw_balloon.c +1 -0
index 053d36c..6983d80 100644
@@ -412,6 +412,7 @@ static int vmballoon_reserve_page(struct vmballoon *b, bool can_sleep)
       gfp_t flags;
       unsigned int hv_status;
       bool locked = false;
+     flags = can_sleep ? VMW_PAGE_ALLOC_CANSLEEP : VMW_PAGE_ALLOC_NOSLEEP;
 
Quoted 7 lines

drivers/misc/vmw_balloon.c static int vmballoon_reserve_page(struct vmballoon *b, bool can_sleep) · line 418

Quoted 2 lines
drivers/misc/vmw_balloon.c +0 -0
       do {
               if (!can_sleep)

Should be folded in with the declaration of gfp_t flags.

Would you also like to add a might_sleep_if(can_sleep) here?

I'm not sure. But, I don't think it's needed here. can_sleep tells whether alloc_page can sleep or not, which has been determined and passed by the callee function.

Thanks,
Rakib

#4 lore raw
Quoted 1 line · Rakib Mullick

On Tue, Oct 18, 2011 at 1:31 AM, David Rientjes <[email protected]>

Quoted 17 lines · wrote:
Quoted 17 lines · Rakib Mullick
Quoted 12 lines
drivers/misc/vmw_balloon.c +1 -0
index 053d36c..6983d80 100644
@@ -412,6 +412,7 @@ static int vmballoon_reserve_page(struct
 vmballoon *b, bool can_sleep) gfp_t flags;
      unsigned int hv_status;
      bool locked = false;
+     flags = can_sleep ? VMW_PAGE_ALLOC_CANSLEEP :
 VMW_PAGE_ALLOC_NOSLEEP;
 
      do {
Quoted 1 line
              if (!can_sleep)

Should be folded in with the declaration of gfp_t flags.

Quoted 6 lines
Quoted 1 line

Would you also like to add a might_sleep_if(can_sleep) here?

I'm not sure. But, I don't think it's needed here. can_sleep tells whether alloc_page can sleep or not, which has been determined and passed by the callee function.

vmballon_reserve_page() is always called from workqueue context and thus is always allowed to sleep. I do not see the benefit of adding might_sleep() here.

Thanks,
Dmitry

Quoted 3 lines

Thanks,
Rakib