Re: [Linaro-mm-sig] [PATCHv23 00/16] Contiguous Memory Allocator

From: Barry Song
Date: Wed Feb 29 2012 - 04:36:07 EST


2012/2/23 Marek Szyprowski <m.szyprowski@xxxxxxxxxxx>:
> Hi,
>
> This is (yet another) quick update of CMA patches. I've rebased them
> onto next-20120222 tree from
> git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git and
> fixed the bug pointed by Aaro Koskinen.

For the whole series:

Tested-by: Barry Song <Baohua.Song@xxxxxxx>

and i also write a simple kernel helper to test the CMA:

/*
* kernek module helper for testing CMA
*
* Copyright (c) 2011 Cambridge Silicon Radio Limited, a CSR plc group company.
*
* Licensed under GPLv2 or later.
*/

#include <linux/module.h>
#include <linux/device.h>
#include <linux/fs.h>
#include <linux/miscdevice.h>
#include <linux/dma-mapping.h>

#define CMA_NUM 10
static struct device *cma_dev;
static dma_addr_t dma_phys[CMA_NUM];
static void *dma_virt[CMA_NUM];

/* any read request will free coherent memory, eg.
* cat /dev/cma_test
*/
static ssize_t
cma_test_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
{
int i;

for (i = 0; i < CMA_NUM; i++) {
if (dma_virt[i]) {
dma_free_coherent(cma_dev, (i + 1) * SZ_1M, dma_virt[i], dma_phys[i]);
_dev_info(cma_dev, "free virt: %p phys: %p\n", dma_virt[i], (void
*)dma_phys[i]);
dma_virt[i] = NULL;
break;
}
}
return 0;
}

/*
* any write request will alloc coherent memory, eg.
* echo 0 > /dev/cma_test
*/
static ssize_t
cma_test_write(struct file *file, const char __user *buf, size_t
count, loff_t *ppos)
{
int i;
int ret;

for (i = 0; i < CMA_NUM; i++) {
if (!dma_virt[i]) {
dma_virt[i] = dma_alloc_coherent(cma_dev, (i + 1) * SZ_1M,
&dma_phys[i], GFP_KERNEL);

if (dma_virt[i])
_dev_info(cma_dev, "alloc virt: %p phys: %p\n", dma_virt[i], (void
*)dma_phys[i]);
else {
dev_err(cma_dev, "no mem in CMA area\n");
ret = -ENOMEM;
}
break;
}
}

return count;
}

static const struct file_operations cma_test_fops = {
.owner = THIS_MODULE,
.read = cma_test_read,
.write = cma_test_write,
};

static struct miscdevice cma_test_misc = {
.name = "cma_test",
.fops = &cma_test_fops,
};

static int __init cma_test_init(void)
{
int ret = 0;

ret = misc_register(&cma_test_misc);
if (unlikely(ret)) {
pr_err("failed to register cma test misc device!\n");
return ret;
}
cma_dev = cma_test_misc.this_device;
cma_dev->coherent_dma_mask = ~0;
_dev_info(cma_dev, "registered.\n");

return ret;
}
module_init(cma_test_init);

static void __exit cma_test_exit(void)
{
misc_deregister(&cma_test_misc);
}
module_exit(cma_test_exit);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Barry Song <Baohua.Song@xxxxxxx>");
MODULE_DESCRIPTION("kernel module to help the test of CMA");
MODULE_ALIAS("CMA test");

While fulfilling "dd if=/dev/mmcblk0 of=/dev/null bs=4096
count=1024000000 &" and "dd if=/dev/zero of=/data/1 bs=4096
count=1024000000 &" to exhaust memory at background,
i alloc the contiguous memories using the cma_test driver:
$echo 0 > /dev/cma_test
[ 16.582216] misc cma_test: alloc virt: ceb00000 phys: 0eb00000
$echo 0 > /dev/cma_test
[ 20.843395] misc cma_test: alloc virt: cec00000 phys: 0ec00000
$echo 0 > /dev/cma_test
[ 21.774601] misc cma_test: alloc virt: cee00000 phys: 0ee00000
$echo 0 > /dev/cma_test
[ 22.925633] misc cma_test: alloc virt: cf100000 phys: 0f100000

i did see the page write back is executed and contiguous memories are
always available.

P.S. the whole series was also back ported to 2.6.38.8 which our
release is based on.

>
> Best regards
> Marek Szyprowski
> Samsung Poland R&D Center
>
> Links to previous versions of the patchset:
> v22: <http://www.spinics.net/lists/linux-media/msg44370.html>
> v21: <http://www.spinics.net/lists/linux-media/msg44155.html>
> v20: <http://www.spinics.net/lists/linux-mm/msg29145.html>
> v19: <http://www.spinics.net/lists/linux-mm/msg29145.html>
> v18: <http://www.spinics.net/lists/linux-mm/msg28125.html>
> v17: <http://www.spinics.net/lists/arm-kernel/msg148499.html>
> v16: <http://www.spinics.net/lists/linux-mm/msg25066.html>
> v15: <http://www.spinics.net/lists/linux-mm/msg23365.html>
> v14: <http://www.spinics.net/lists/linux-media/msg36536.html>
> v13: (internal, intentionally not released)
> v12: <http://www.spinics.net/lists/linux-media/msg35674.html>
> v11: <http://www.spinics.net/lists/linux-mm/msg21868.html>
> v10: <http://www.spinics.net/lists/linux-mm/msg20761.html>
> Âv9: <http://article.gmane.org/gmane.linux.kernel.mm/60787>
> Âv8: <http://article.gmane.org/gmane.linux.kernel.mm/56855>
> Âv7: <http://article.gmane.org/gmane.linux.kernel.mm/55626>
> Âv6: <http://article.gmane.org/gmane.linux.kernel.mm/55626>
> Âv5: (intentionally left out as CMA v5 was identical to CMA v4)
> Âv4: <http://article.gmane.org/gmane.linux.kernel.mm/52010>
> Âv3: <http://article.gmane.org/gmane.linux.kernel.mm/51573>
> Âv2: <http://article.gmane.org/gmane.linux.kernel.mm/50986>
> Âv1: <http://article.gmane.org/gmane.linux.kernel.mm/50669>
>
>
> Changelog:
>
> v23:
> Â Â1. fixed bug spotted by Aaro Koskinen (incorrect check inside VM_BUG_ON)
>
> Â Â2. rebased onto next-20120222 tree from
> Â Â Â git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
>
> v22:
> Â Â1. Fixed compilation break caused by missing fixup patch in v21
>
> Â Â2. Fixed typos in the comments
>
> Â Â3. Removed superfluous #include entries
>
> v21:
> Â Â1. Fixed incorrect check which broke memory compaction code
>
> Â Â2. Fixed hacky and racy min_free_kbytes handling
>
> Â Â3. Added serialization patch to watermark calculation
>
> Â Â4. Fixed typos here and there in the comments
>
> v20 and earlier - see previous patchsets.
>
>
> Patches in this patchset:
>
> Marek Szyprowski (6):
> Âmm: extract reclaim code from __alloc_pages_direct_reclaim()
> Âmm: trigger page reclaim in alloc_contig_range() to stabilise
> Â Âwatermarks
> Âdrivers: add Contiguous Memory Allocator
> ÂX86: integrate CMA with DMA-mapping subsystem
> ÂARM: integrate CMA with DMA-mapping subsystem
> ÂARM: Samsung: use CMA for 2 memory banks for s5p-mfc device
>
> Mel Gorman (1):
> Âmm: Serialize access to min_free_kbytes
>
> Michal Nazarewicz (9):
> Âmm: page_alloc: remove trailing whitespace
> Âmm: compaction: introduce isolate_migratepages_range()
> Âmm: compaction: introduce map_pages()
> Âmm: compaction: introduce isolate_freepages_range()
> Âmm: compaction: export some of the functions
> Âmm: page_alloc: introduce alloc_contig_range()
> Âmm: page_alloc: change fallbacks array handling
> Âmm: mmzone: MIGRATE_CMA migration type added
> Âmm: page_isolation: MIGRATE_CMA isolation functions added
>
> ÂDocumentation/kernel-parameters.txt  |  Â9 +
> Âarch/Kconfig             Â|  Â3 +
> Âarch/arm/Kconfig           Â|  Â2 +
> Âarch/arm/include/asm/dma-contiguous.h | Â 15 ++
> Âarch/arm/include/asm/mach/map.h    |  Â1 +
> Âarch/arm/kernel/setup.c        |  Â9 +-
> Âarch/arm/mm/dma-mapping.c       | Â369 ++++++++++++++++++++++++------
> Âarch/arm/mm/init.c          Â|  23 ++-
> Âarch/arm/mm/mm.h           Â|  Â3 +
> Âarch/arm/mm/mmu.c           |  31 ++-
> Âarch/arm/plat-s5p/dev-mfc.c      |  51 +----
> Âarch/x86/Kconfig           Â|  Â1 +
> Âarch/x86/include/asm/dma-contiguous.h | Â 13 +
> Âarch/x86/include/asm/dma-mapping.h  Â|  Â4 +
> Âarch/x86/kernel/pci-dma.c       |  18 ++-
> Âarch/x86/kernel/pci-nommu.c      |  Â8 +-
> Âarch/x86/kernel/setup.c        |  Â2 +
> Âdrivers/base/Kconfig         Â|  89 +++++++
> Âdrivers/base/Makefile         |  Â1 +
> Âdrivers/base/dma-contiguous.c     | Â401 +++++++++++++++++++++++++++++++
> Âinclude/asm-generic/dma-contiguous.h Â| Â 28 +++
> Âinclude/linux/device.h        Â|  Â4 +
> Âinclude/linux/dma-contiguous.h    Â| Â110 +++++++++
> Âinclude/linux/gfp.h          |  12 +
> Âinclude/linux/mmzone.h        Â|  47 +++-
> Âinclude/linux/page-isolation.h    Â|  18 +-
> Âmm/Kconfig              Â|  Â2 +-
> Âmm/Makefile              |  Â3 +-
> Âmm/compaction.c            | Â418 +++++++++++++++++++++------------
> Âmm/internal.h             |  33 +++
> Âmm/memory-failure.c          |  Â2 +-
> Âmm/memory_hotplug.c          |  Â6 +-
> Âmm/page_alloc.c            | Â409 ++++++++++++++++++++++++++++----
> Âmm/page_isolation.c          |  15 +-
> Âmm/vmstat.c              |  Â3 +
> Â35 files changed, 1790 insertions(+), 373 deletions(-)
> Âcreate mode 100644 arch/arm/include/asm/dma-contiguous.h
> Âcreate mode 100644 arch/x86/include/asm/dma-contiguous.h
> Âcreate mode 100644 drivers/base/dma-contiguous.c
> Âcreate mode 100644 include/asm-generic/dma-contiguous.h
> Âcreate mode 100644 include/linux/dma-contiguous.h
>
> --
> 1.7.1.569.g6f426

Thanks
barry
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/