Skip to contentSkip to conversation

Export __vmalloc_node symbol

PATCH In review [email protected] 2 participants 7 messages Feb 2, 2015

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

cover Export __vmalloc_node symbol

From: Oleg Drokin <[email protected]>

Looking to get rid of a deadlock in Lustre where vmalloc call recurses right back into Lustre to free some memory due to not accepting GFP mask I noticed that while vzalloc is replaceable with __vmalloc just as suggested, vzalloc_node is not. Recommended __vmalloc_node symbol is static to mm/vmalloc.c.
Hopefully nobody has any objections to me exporting it so that vzalloc_node suggestion actually becomes possible.

Second patch in the series is just a Lustre patch to take advantage of that newly exported symbol (as an example of usage).

Please consider.

Bruno Faccini (1):
staging/lustre: use __vmalloc_node() to avoid __GFP_FS default

Oleg Drokin (1):
mm: Export __vmalloc_node

 drivers/staging/lustre/lustre/include/obd_support.h | 18 ++++++++++++------
 include/linux/vmalloc.h                             |  3 +++
 mm/vmalloc.c                                        | 10 ++++------
 3 files changed, 19 insertions(+), 12 deletions(-)
Signature · 7 lines
2.1.0

--
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>
#1 lore raw

PATCH 1/2 mm: Export __vmalloc_node

From: Oleg Drokin <[email protected]>

vzalloc_node helpfully suggests to use __vmalloc_node if a more tight control over allocation flags is needed, but in fact __vmalloc_node is not only not exported, it's also static, so could not be used outside of mm/vmalloc.c
Make it to be available as it was apparently intended.

---
 include/linux/vmalloc.h |  3 +++
 mm/vmalloc.c            | 10 ++++------
 2 files changed, 7 insertions(+), 6 deletions(-)
include/linux/vmalloc.h +3 -0
index b87696f..7eb2c46 100644
@@ -73,6 +73,9 @@ extern void *vmalloc_exec(unsigned long size);
 extern void *vmalloc_32(unsigned long size);
 extern void *vmalloc_32_user(unsigned long size);
 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
+extern void *__vmalloc_node(unsigned long size, unsigned long align,
+			    gfp_t gfp_mask, pgprot_t prot, int node,
+			    const void *caller);
 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
 			unsigned long start, unsigned long end, gfp_t gfp_mask,
 			pgprot_t prot, int node, const void *caller);
mm/vmalloc.c +4 -6
index 39c3388..b882d95 100644
@@ -1552,9 +1552,6 @@ void *vmap(struct page **pages, unsigned int count,
 }
 EXPORT_SYMBOL(vmap);
 
-static void *__vmalloc_node(unsigned long size, unsigned long align,
-			    gfp_t gfp_mask, pgprot_t prot,
-			    int node, const void *caller);
 static void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask,
 				 pgprot_t prot, int node)
 {
@@ -1685,13 +1682,14 @@ fail:
  *	allocator with @gfp_mask flags.  Map them into contiguous
  *	kernel virtual space, using a pagetable protection of @prot.
  */
-static void *__vmalloc_node(unsigned long size, unsigned long align,
-			    gfp_t gfp_mask, pgprot_t prot,
-			    int node, const void *caller)
+void *__vmalloc_node(unsigned long size, unsigned long align,
+		     gfp_t gfp_mask, pgprot_t prot, int node,
+		     const void *caller)
 {
 	return __vmalloc_node_range(size, align, VMALLOC_START, VMALLOC_END,
 				gfp_mask, prot, node, caller);
 }
+EXPORT_SYMBOL(__vmalloc_node);
 
 void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot)
 {
Signature · 7 lines
2.1.0

--
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

Re: [PATCH 1/2] mm: Export __vmalloc_node

Quoted 8 lines · On Sun, 1 Feb 2015, [email protected] wrote:

From: Oleg Drokin <[email protected]>

vzalloc_node helpfully suggests to use __vmalloc_node if a more tight control over allocation flags is needed, but in fact __vmalloc_node is not only not exported, it's also static, so could not be used outside of mm/vmalloc.c
Make it to be available as it was apparently intended.

__vmalloc_node() is for the generalized functionality that is needed for the vmalloc API and not part of the API itself. I think what you want to do is add a vmalloc_node_gfp(), or more specifically a vzalloc_node_gfp(), to do GFP_NOFS when needed.

Quoted 42 lines
---
 include/linux/vmalloc.h |  3 +++
 mm/vmalloc.c            | 10 ++++------
 2 files changed, 7 insertions(+), 6 deletions(-)
include/linux/vmalloc.h +3 -0
index b87696f..7eb2c46 100644
@@ -73,6 +73,9 @@ extern void *vmalloc_exec(unsigned long size);
 extern void *vmalloc_32(unsigned long size);
 extern void *vmalloc_32_user(unsigned long size);
 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
+extern void *__vmalloc_node(unsigned long size, unsigned long align,
+			    gfp_t gfp_mask, pgprot_t prot, int node,
+			    const void *caller);
 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
 			unsigned long start, unsigned long end, gfp_t gfp_mask,
 			pgprot_t prot, int node, const void *caller);
mm/vmalloc.c +1 -6
index 39c3388..b882d95 100644
@@ -1552,9 +1552,6 @@ void *vmap(struct page **pages, unsigned int count,
 }
 EXPORT_SYMBOL(vmap);
 
-static void *__vmalloc_node(unsigned long size, unsigned long align,
-			    gfp_t gfp_mask, pgprot_t prot,
-			    int node, const void *caller);
 static void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask,
 				 pgprot_t prot, int node)
 {
@@ -1685,13 +1682,14 @@ fail:
  *	allocator with @gfp_mask flags.  Map them into contiguous
  *	kernel virtual space, using a pagetable protection of @prot.
  */
-static void *__vmalloc_node(unsigned long size, unsigned long align,
-			    gfp_t gfp_mask, pgprot_t prot,
-			    int node, const void *caller)
+void *__vmalloc_node(unsigned long size, unsigned long align,

mm/vmalloc.c fail: · line 1695

Quoted 10 lines
mm/vmalloc.c +3 -0
+		     gfp_t gfp_mask, pgprot_t prot, int node,
+		     const void *caller)
 {
 	return __vmalloc_node_range(size, align, VMALLOC_START, VMALLOC_END,
 				gfp_mask, prot, node, caller);
 }
+EXPORT_SYMBOL(__vmalloc_node);
 
 void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot)
 {

--
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>

#3 lore raw

Re: [PATCH 1/2] mm: Export __vmalloc_node

Hello!

Quoted 11 lines · David Rientjes
Quoted 8 lines · On Sun, 1 Feb 2015, [email protected] wrote:

From: Oleg Drokin <[email protected]>

vzalloc_node helpfully suggests to use __vmalloc_node if a more tight control over allocation flags is needed, but in fact __vmalloc_node is not only not exported, it's also static, so could not be used outside of mm/vmalloc.c
Make it to be available as it was apparently intended.

Quoted 4 lines

__vmalloc_node() is for the generalized functionality that is needed for the vmalloc API and not part of the API itself. I think what you want to do is add a vmalloc_node_gfp(), or more specifically a vzalloc_node_gfp(), to do GFP_NOFS when needed.

So, the comment for the vzalloc_node reads:
* For tight control over page level allocator and protection flags
* use __vmalloc_node() instead.
*/
void *vzalloc_node(unsigned long size, int node)

Very similar to the comment for vzalloc:
* For tight control over page level allocator and protection flags
* use __vmalloc() instead.
*/
void *vzalloc(unsigned long size)

__vmalloc is exported and is allowed to be used everywhere.

Should we then just take down the __vmalloc_node comment near vzalloc_node to no longer confuse people?

Quoted 51 lines
Quoted 51 lines

---
include/linux/vmalloc.h | 3 +++
mm/vmalloc.c | 10 ++++------

2 files changed, 7 insertions(+), 6 deletions(-)
include/linux/vmalloc.h +3 -0
index b87696f..7eb2c46 100644
@@ -73,6 +73,9 @@ extern void *vmalloc_exec(unsigned long size);
 extern void *vmalloc_32(unsigned long size);
 extern void *vmalloc_32_user(unsigned long size);
 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
+extern void *__vmalloc_node(unsigned long size, unsigned long align,
+			    gfp_t gfp_mask, pgprot_t prot, int node,
+			    const void *caller);
 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
 			unsigned long start, unsigned long end, gfp_t gfp_mask,
 			pgprot_t prot, int node, const void *caller);
mm/vmalloc.c +4 -6
index 39c3388..b882d95 100644
@@ -1552,9 +1552,6 @@ void *vmap(struct page **pages, unsigned int count,
 }
 EXPORT_SYMBOL(vmap);
 
-static void *__vmalloc_node(unsigned long size, unsigned long align,
-			    gfp_t gfp_mask, pgprot_t prot,
-			    int node, const void *caller);
 static void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask,
 				 pgprot_t prot, int node)
 {
@@ -1685,13 +1682,14 @@ fail:
 *	allocator with @gfp_mask flags.  Map them into contiguous
 *	kernel virtual space, using a pagetable protection of @prot.
 */
-static void *__vmalloc_node(unsigned long size, unsigned long align,
-			    gfp_t gfp_mask, pgprot_t prot,
-			    int node, const void *caller)
+void *__vmalloc_node(unsigned long size, unsigned long align,
+		     gfp_t gfp_mask, pgprot_t prot, int node,
+		     const void *caller)
 {
 	return __vmalloc_node_range(size, align, VMALLOC_START, VMALLOC_END,
 				gfp_mask, prot, node, caller);
 }
+EXPORT_SYMBOL(__vmalloc_node);
 
Quoted 2 lines

mm/vmalloc.c fail: · line 1695

Quoted 2 lines
mm/vmalloc.c +0 -0
 void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot)
 {

--
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>

#4 lore raw

PATCH 2/2 staging/lustre: use __vmalloc_node() to avoid __GFP_FS default

In reply to [email protected]

From: Bruno Faccini <[email protected]>

When possible, try to use of __vmalloc_node() instead of vzalloc/vzalloc_node which allows for protection flag specification, and particularly to not set __GFP_FS, which can cause some deadlock situations in our code due to recursive calls.

Additionally fixed a typo in the macro name: VEROBSE->VERBOSE

Reviewed-on: http://review.whamcloud.com/11190
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-5349

---
 drivers/staging/lustre/lustre/include/obd_support.h | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)
drivers/staging/lustre/lustre/include/obd_support.h +12 -6
index 2991d2e..c90a88e 100644
@@ -655,11 +655,17 @@ do {									      \
 #define OBD_CPT_ALLOC_PTR(ptr, cptab, cpt)				      \
 	OBD_CPT_ALLOC(ptr, cptab, cpt, sizeof(*(ptr)))
 
-# define __OBD_VMALLOC_VEROBSE(ptr, cptab, cpt, size)			      \
+/* Direct use of __vmalloc_node() allows for protection flag specification
+ * (and particularly to not set __GFP_FS, which is likely to cause some
+ * deadlock situations in our code).
+ */
+# define __OBD_VMALLOC_VERBOSE(ptr, cptab, cpt, size)			      \
 do {									      \
-	(ptr) = cptab == NULL ?						      \
-		vzalloc(size) :						      \
-		vzalloc_node(size, cfs_cpt_spread_node(cptab, cpt));	      \
+	(ptr) = __vmalloc_node(size, 1, GFP_NOFS | __GFP_HIGHMEM | __GFP_ZERO,\
+			       PAGE_KERNEL,				      \
+			       cptab == NULL ? NUMA_NO_NODE :		      \
+					      cfs_cpt_spread_node(cptab, cpt),\
+			       __builtin_return_address(0));		      \
 	if (unlikely((ptr) == NULL)) {					\
 		CERROR("vmalloc of '" #ptr "' (%d bytes) failed\n",	   \
 		       (int)(size));					  \
@@ -671,9 +677,9 @@ do {									      \
 } while (0)
 
 # define OBD_VMALLOC(ptr, size)						      \
-	 __OBD_VMALLOC_VEROBSE(ptr, NULL, 0, size)
+	 __OBD_VMALLOC_VERBOSE(ptr, NULL, 0, size)
 # define OBD_CPT_VMALLOC(ptr, cptab, cpt, size)				      \
-	 __OBD_VMALLOC_VEROBSE(ptr, cptab, cpt, size)
+	 __OBD_VMALLOC_VERBOSE(ptr, cptab, cpt, size)
 
 
 /* Allocations above this size are considered too big and could not be done
Signature · 7 lines
2.1.0

--
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>
#5 lore raw

Re: [PATCH 2/2] staging/lustre: use __vmalloc_node() to avoid __GFP_FS default

Quoted 7 lines · On Sun, 1 Feb 2015, [email protected] wrote:

From: Bruno Faccini <[email protected]>

When possible, try to use of __vmalloc_node() instead of vzalloc/vzalloc_node which allows for protection flag specification, and particularly to not set __GFP_FS, which can cause some deadlock situations in our code due to recursive calls.

You're saying that all usage of OBD_ALLOC_LARGE() and OBD_CPT_ALLOC_LARGE() are in contexts where we need GFP_NOFS? It would be much better to keep using vzalloc{,_node)() in contexts that permit __GFP_FS for a higher likelihood of being able to allocate the memory.

Quoted 38 lines

Additionally fixed a typo in the macro name: VEROBSE->VERBOSE

Reviewed-on: http://review.whamcloud.com/11190
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-5349

---
 drivers/staging/lustre/lustre/include/obd_support.h | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)
drivers/staging/lustre/lustre/include/obd_support.h +10 -4
index 2991d2e..c90a88e 100644
@@ -655,11 +655,17 @@ do {									      \
 #define OBD_CPT_ALLOC_PTR(ptr, cptab, cpt)				      \
 	OBD_CPT_ALLOC(ptr, cptab, cpt, sizeof(*(ptr)))
 
-# define __OBD_VMALLOC_VEROBSE(ptr, cptab, cpt, size)			      \
+/* Direct use of __vmalloc_node() allows for protection flag specification
+ * (and particularly to not set __GFP_FS, which is likely to cause some
+ * deadlock situations in our code).
+ */
+# define __OBD_VMALLOC_VERBOSE(ptr, cptab, cpt, size)			      \
 do {									      \
-	(ptr) = cptab == NULL ?						      \
-		vzalloc(size) :						      \
-		vzalloc_node(size, cfs_cpt_spread_node(cptab, cpt));	      \
+	(ptr) = __vmalloc_node(size, 1, GFP_NOFS | __GFP_HIGHMEM | __GFP_ZERO,\
+			       PAGE_KERNEL,				      \
+			       cptab == NULL ? NUMA_NO_NODE :		      \
+					      cfs_cpt_spread_node(cptab, cpt),\
+			       __builtin_return_address(0));		      \
 	if (unlikely((ptr) == NULL)) {					\
 		CERROR("vmalloc of '" #ptr "' (%d bytes) failed\n",	   \
 		       (int)(size));					  \
@@ -671,9 +677,9 @@ do {									      \
 } while (0)

drivers/staging/lustre/lustre/include/obd_support.h do { \ · line 685

Quoted 10 lines
drivers/staging/lustre/lustre/include/obd_support.h +2 -2
 
 # define OBD_VMALLOC(ptr, size)						      \
-	 __OBD_VMALLOC_VEROBSE(ptr, NULL, 0, size)
+	 __OBD_VMALLOC_VERBOSE(ptr, NULL, 0, size)
 # define OBD_CPT_VMALLOC(ptr, cptab, cpt, size)				      \
-	 __OBD_VMALLOC_VEROBSE(ptr, cptab, cpt, size)
+	 __OBD_VMALLOC_VERBOSE(ptr, cptab, cpt, size)
 
 
 /* Allocations above this size are considered too big and could not be done

--
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>

#6 lore raw

Re: [PATCH 2/2] staging/lustre: use __vmalloc_node() to avoid __GFP_FS default

Quoted 10 lines · David Rientjes
Quoted 6 lines · On Sun, 1 Feb 2015, [email protected] wrote:

From: Bruno Faccini <[email protected]>

When possible, try to use of __vmalloc_node() instead of vzalloc/vzalloc_node which allows for protection flag specification, and particularly to not set __GFP_FS, which can cause some deadlock situations in our code due to recursive calls.

You're saying that all usage of OBD_ALLOC_LARGE() and OBD_CPT_ALLOC_LARGE() are in contexts where we need GFP_NOFS? It would be

Most of them fore sure (hm, there's only one OBD_CPT_ALLOC_LARGE in the client and I imagine it better be GFP_NOFS even though the condition for that is very unlikely, but that's what happens when you have tens of thousands nodes all doing the same code all the time - all sorts of unlikely things trigger a lot).

Quoted 2 lines

much better to keep using vzalloc{,_node)() in contexts that permit __GFP_FS for a higher likelihood of being able to allocate the memory.

While it's certainly possible to go audit all the OBD_ALLOC_LARGE and isolate the ones where __GFP_FS is not detrimential, I just found yesterday that vmalloc possibly does GFP_KERNEL allocations in its guts no matter what. I saw all the rants and stuff about that too (but somewhat old). Yet I cannot help but ask too if perhaps something could be done about it now?

Quoted 48 lines
Quoted 48 lines

Additionally fixed a typo in the macro name: VEROBSE->VERBOSE

Reviewed-on: http://review.whamcloud.com/11190
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-5349
---
drivers/staging/lustre/lustre/include/obd_support.h | 18 ++++++++++++------

1 file changed, 12 insertions(+), 6 deletions(-)
drivers/staging/lustre/lustre/include/obd_support.h +12 -6
index 2991d2e..c90a88e 100644
@@ -655,11 +655,17 @@ do {									      \
 #define OBD_CPT_ALLOC_PTR(ptr, cptab, cpt)				      \
 	OBD_CPT_ALLOC(ptr, cptab, cpt, sizeof(*(ptr)))
 
-# define __OBD_VMALLOC_VEROBSE(ptr, cptab, cpt, size)			      \
+/* Direct use of __vmalloc_node() allows for protection flag specification
+ * (and particularly to not set __GFP_FS, which is likely to cause some
+ * deadlock situations in our code).
+ */
+# define __OBD_VMALLOC_VERBOSE(ptr, cptab, cpt, size)			      \
 do {									      \
-	(ptr) = cptab == NULL ?						      \
-		vzalloc(size) :						      \
-		vzalloc_node(size, cfs_cpt_spread_node(cptab, cpt));	      \
+	(ptr) = __vmalloc_node(size, 1, GFP_NOFS | __GFP_HIGHMEM | __GFP_ZERO,\
+			       PAGE_KERNEL,				      \
+			       cptab == NULL ? NUMA_NO_NODE :		      \
+					      cfs_cpt_spread_node(cptab, cpt),\
+			       __builtin_return_address(0));		      \
 	if (unlikely((ptr) == NULL)) {					\
 		CERROR("vmalloc of '" #ptr "' (%d bytes) failed\n",	   \
 		       (int)(size));					  \
@@ -671,9 +677,9 @@ do {									      \
 } while (0)
 
 # define OBD_VMALLOC(ptr, size)						      \
-	 __OBD_VMALLOC_VEROBSE(ptr, NULL, 0, size)
+	 __OBD_VMALLOC_VERBOSE(ptr, NULL, 0, size)
 # define OBD_CPT_VMALLOC(ptr, cptab, cpt, size)				      \
-	 __OBD_VMALLOC_VEROBSE(ptr, cptab, cpt, size)
+	 __OBD_VMALLOC_VERBOSE(ptr, cptab, cpt, size)
 
 
Quoted 1 line

drivers/staging/lustre/lustre/include/obd_support.h do { \ · line 685

Quoted 1 line
drivers/staging/lustre/lustre/include/obd_support.h +0 -0
 /* Allocations above this size are considered too big and could not be done

--
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>