Skip to contentSkip to conversation

docs/core-api: add memory allocation guide

PATCH Superseded Mike Rapoport 2 participants 9 messages Aug 17, 2018 – Sep 13, 2018

Subsystems (3)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover docs/core-api: add memory allocation guide

Hi,

As Vlastimil mentioned at [1], it would be nice to have some guide about memory allocation. This set adds such guide that summarizes the "best practices".

The changes from the RFC include additions and corrections from Michal and Randy. I've also added markup to cross-reference the kernel-doc documentation.

I've split the patch into three to separate labels addition to the exiting files from the new contents.

Note that the second patch depends on the mm docs update [2] that Andrew took to the -mm tree.

v2 -> v3:
* s/HW/hardware

[1] https://www.spinics.net/lists/netfilter-devel/msg55542.html
[2] https://lkml.org/lkml/2018/7/26/684

Mike Rapoport (3):
docs: core-api/gfp_mask-from-fs-io: add a label for cross-referencing
docs: core-api/mm-api: add a lable for GFP flags section
docs: core-api: add memory allocation guide

 Documentation/core-api/gfp_mask-from-fs-io.rst |   2 +
 Documentation/core-api/index.rst               |   1 +
 Documentation/core-api/memory-allocation.rst   | 124 +++++++++++++++++++++++++
 Documentation/core-api/mm-api.rst              |   2 +
 4 files changed, 129 insertions(+)
 create mode 100644 Documentation/core-api/memory-allocation.rst
Signature · 1 line
2.7.4
#1 lore raw

PATCH v3 1/3 docs: core-api/gfp_mask-from-fs-io: add a label for cross-referencing

---
 Documentation/core-api/gfp_mask-from-fs-io.rst | 2 ++
 1 file changed, 2 insertions(+)
Documentation/core-api/gfp_mask-from-fs-io.rst +2 -0
index e0df8f4..e7c32a8 100644
@@ -1,3 +1,5 @@
+.. _gfp_mask_from_fs_io:
+
 =================================
 GFP masks used from FS/IO context
 =================================
Signature · 1 line
2.7.4
#2 lore raw

PATCH v3 2/3 docs: core-api/mm-api: add a lable for GFP flags section

In reply to Mike Rapoport
---
 Documentation/core-api/mm-api.rst | 2 ++
 1 file changed, 2 insertions(+)
Documentation/core-api/mm-api.rst +2 -0
index 46ae353..5ce1ec1 100644
@@ -14,6 +14,8 @@ User Space Memory Access
 .. kernel-doc:: mm/util.c
    :functions: get_user_pages_fast
 
+.. _mm-api-gfp-flags:
+
 Memory Allocation Controls
 ==========================
 
Signature · 1 line
2.7.4
#3 lore raw

PATCH v3 3/3 docs: core-api: add memory allocation guide

In reply to Mike Rapoport
---
 Documentation/core-api/index.rst             |   1 +
 Documentation/core-api/memory-allocation.rst | 124 +++++++++++++++++++++++++++
 2 files changed, 125 insertions(+)
 create mode 100644 Documentation/core-api/memory-allocation.rst
Documentation/core-api/index.rst +1 -0
index cdc2020..8afc0da 100644
@@ -27,6 +27,7 @@ Core utilities
    errseq
    printk-formats
    circular-buffers
+   memory-allocation
    mm-api
    gfp_mask-from-fs-io
    timekeeping
Documentation/core-api/memory-allocation.rst new file +124 -0

124 lines not on this page · raw message

Signature · 1 line
2.7.4
maintainer
#4 lore raw

Re: [PATCH v3 3/3] docs: core-api: add memory allocation guide

Sorry for being so slow to get to this...it fell into a dark crack in my rickety email folder hierarchy. I do have one question...

Documentation/core-api/memory-allocation.rst line 70

Quoted 13 lines · On Fri, 17 Aug 2018 17:47:16 +0300 Mike Rapoport <[email protected]>…
Documentation/core-api/memory-allocation.rst new file +13 -0
+    ``GFP_HIGHUSER_MOVABLE`` does not require that allocated memory
+    will be directly accessible by the kernel or the hardware and
+    implies that the data is movable.
+
+    ``GFP_HIGHUSER`` means that the allocated memory is not movable,
+    but it is not required to be directly accessible by the kernel or
+    the hardware. An example may be a hardware allocation that maps
+    data directly into userspace but has no addressing limitations.
+
+    ``GFP_USER`` means that the allocated memory is not movable and it
+    must be directly accessible by the kernel or the hardware. It is
+    typically used by hardware for buffers that are mapped to
+    userspace (e.g. graphics) that hardware still must DMA to.

I realize that this is copied from elsewhere, but still...as I understand it, the "HIGH" part means that the allocation can be satisfied from high memory, nothing more. So...it's irrelevant on 64-bit machines to start with, right? And it has nothing to do with DMA, I would think. That would be handled by the DMA infrastructure and, perhaps, the DMA* zones. Right?

I ask because high memory is an artifact of how things are laid out on 32-bit systems; hardware can often DMA quite easily into memory that the kernel sees as "high". So, to me, this description seems kind of confusing; I wouldn't mention hardware at all. But maybe I'm missing something?

Thanks,

jon

#5 lore raw

Re: [PATCH v3 3/3] docs: core-api: add memory allocation guide

Quoted 26 lines · Jonathan Corbet

Sorry for being so slow to get to this...it fell into a dark crack in my rickety email folder hierarchy. I do have one question...

Documentation/core-api/memory-allocation.rst line 70

Quoted 13 lines · On Fri, 17 Aug 2018 17:47:16 +0300 Mike Rapoport <[email protected]>…
Documentation/core-api/memory-allocation.rst new file +13 -0
+    ``GFP_HIGHUSER_MOVABLE`` does not require that allocated memory
+    will be directly accessible by the kernel or the hardware and
+    implies that the data is movable.
+
+    ``GFP_HIGHUSER`` means that the allocated memory is not movable,
+    but it is not required to be directly accessible by the kernel or
+    the hardware. An example may be a hardware allocation that maps
+    data directly into userspace but has no addressing limitations.
+
+    ``GFP_USER`` means that the allocated memory is not movable and it
+    must be directly accessible by the kernel or the hardware. It is
+    typically used by hardware for buffers that are mapped to
+    userspace (e.g. graphics) that hardware still must DMA to.

I realize that this is copied from elsewhere, but still...as I understand it, the "HIGH" part means that the allocation can be satisfied from high memory, nothing more. So...it's irrelevant on 64-bit machines to start with, right? And it has nothing to do with DMA, I would think. That would be handled by the DMA infrastructure and, perhaps, the DMA* zones. Right?

Quoted 5 lines

I ask because high memory is an artifact of how things are laid out on 32-bit systems; hardware can often DMA quite easily into memory that the kernel sees as "high". So, to me, this description seems kind of confusing; I wouldn't mention hardware at all. But maybe I'm missing something?

Well, I've amended the original text from gfp.h in attempt to make it more "user friendly". The GFP_HIGHUSER became really confusing :)
I think that we can drop mentions of hardware from GFP_HIGHUSER_MOVABLE and GFP_USER, but it makes sense to leave the example in the GFP_HIGHUSER description.

How about:

``GFP_HIGHUSER_MOVABLE`` does not require that allocated memory will be directly accessible by the kernel and implies that the data is movable.

``GFP_HIGHUSER`` means that the allocated memory is not movable, but it is not required to be directly accessible by the kernel. An example may be a hardware allocation that maps data directly into userspace but has no addressing limitations.

``GFP_USER`` means that the allocated memory is not movable and it must be directly accessible by the kernel

Quoted 4 lines

Thanks,

jon

Signature · 2 lines
Sincerely yours,
Mike.
maintainer
#6 lore raw

Re: [PATCH v3 3/3] docs: core-api: add memory allocation guide

Quoted 6 lines · On Wed, 12 Sep 2018 13:33:06 +0300 Mike Rapoport <[email protected]>…

How about:

``GFP_HIGHUSER_MOVABLE`` does not require that allocated memory will be directly accessible by the kernel and implies that the data is movable.

Quoted 7 lines

``GFP_HIGHUSER`` means that the allocated memory is not movable, but it is not required to be directly accessible by the kernel. An example may be a hardware allocation that maps data directly into userspace but has no addressing limitations.

``GFP_USER`` means that the allocated memory is not movable and it must be directly accessible by the kernel

Sounds good to me.

Thanks,

jon

#7 lore raw
In reply to Mike Rapoport

Any updates on this?

Quoted 37 lines · Mike Rapoport

Hi,

As Vlastimil mentioned at [1], it would be nice to have some guide about memory allocation. This set adds such guide that summarizes the "best practices".

The changes from the RFC include additions and corrections from Michal and Randy. I've also added markup to cross-reference the kernel-doc documentation.

I've split the patch into three to separate labels addition to the exiting files from the new contents.

Note that the second patch depends on the mm docs update [2] that Andrew took to the -mm tree.

v2 -> v3:
* s/HW/hardware

[1] https://www.spinics.net/lists/netfilter-devel/msg55542.html
[2] https://lkml.org/lkml/2018/7/26/684

Mike Rapoport (3):
docs: core-api/gfp_mask-from-fs-io: add a label for cross-referencing
docs: core-api/mm-api: add a lable for GFP flags section
docs: core-api: add memory allocation guide

 Documentation/core-api/gfp_mask-from-fs-io.rst |   2 +
 Documentation/core-api/index.rst               |   1 +
 Documentation/core-api/memory-allocation.rst   | 124 +++++++++++++++++++++++++
 Documentation/core-api/mm-api.rst              |   2 +
 4 files changed, 129 insertions(+)
 create mode 100644 Documentation/core-api/memory-allocation.rst
Signature · 1 line
2.7.4
Signature · 2 lines
Sincerely yours,
Mike.
#8 lore raw
In reply to Mike Rapoport

Ping?

Quoted 37 lines · Mike Rapoport

Hi,

As Vlastimil mentioned at [1], it would be nice to have some guide about memory allocation. This set adds such guide that summarizes the "best practices".

The changes from the RFC include additions and corrections from Michal and Randy. I've also added markup to cross-reference the kernel-doc documentation.

I've split the patch into three to separate labels addition to the exiting files from the new contents.

Note that the second patch depends on the mm docs update [2] that Andrew took to the -mm tree.

v2 -> v3:
* s/HW/hardware

[1] https://www.spinics.net/lists/netfilter-devel/msg55542.html
[2] https://lkml.org/lkml/2018/7/26/684

Mike Rapoport (3):
docs: core-api/gfp_mask-from-fs-io: add a label for cross-referencing
docs: core-api/mm-api: add a lable for GFP flags section
docs: core-api: add memory allocation guide

 Documentation/core-api/gfp_mask-from-fs-io.rst |   2 +
 Documentation/core-api/index.rst               |   1 +
 Documentation/core-api/memory-allocation.rst   | 124 +++++++++++++++++++++++++
 Documentation/core-api/mm-api.rst              |   2 +
 4 files changed, 129 insertions(+)
 create mode 100644 Documentation/core-api/memory-allocation.rst
Signature · 1 line
2.7.4
Signature · 2 lines
Sincerely yours,
Mike.