27 Apr, 2015

1 commit

  • Pull fourth vfs update from Al Viro:
    "d_inode() annotations from David Howells (sat in for-next since before
    the beginning of merge window) + four assorted fixes"

    * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs:
    RCU pathwalk breakage when running into a symlink overmounting something
    fix I_DIO_WAKEUP definition
    direct-io: only inc/dec inode->i_dio_count for file systems
    fs/9p: fix readdir()
    VFS: assorted d_backing_inode() annotations
    VFS: fs/inode.c helpers: d_inode() annotations
    VFS: fs/cachefiles: d_backing_inode() annotations
    VFS: fs library helpers: d_inode() annotations
    VFS: assorted weird filesystems: d_inode() annotations
    VFS: normal filesystems (and lustre): d_inode() annotations
    VFS: security/: d_inode() annotations
    VFS: security/: d_backing_inode() annotations
    VFS: net/: d_inode() annotations
    VFS: net/unix: d_backing_inode() annotations
    VFS: kernel/: d_inode() annotations
    VFS: audit: d_backing_inode() annotations
    VFS: Fix up some ->d_inode accesses in the chelsio driver
    VFS: Cachefiles should perform fs modifications on the top layer only
    VFS: AF_UNIX sockets should call mknod on the top layer only

    Linus Torvalds
     

17 Apr, 2015

1 commit

  • Pull third hunk of vfs changes from Al Viro:
    "This contains the ->direct_IO() changes from Omar + saner
    generic_write_checks() + dealing with fcntl()/{read,write}() races
    (mirroring O_APPEND/O_DIRECT into iocb->ki_flags and instead of
    repeatedly looking at ->f_flags, which can be changed by fcntl(2),
    check ->ki_flags - which cannot) + infrastructure bits for dhowells'
    d_inode annotations + Christophs switch of /dev/loop to
    vfs_iter_write()"

    * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs: (30 commits)
    block: loop: switch to VFS ITER_BVEC
    configfs: Fix inconsistent use of file_inode() vs file->f_path.dentry->d_inode
    VFS: Make pathwalk use d_is_reg() rather than S_ISREG()
    VFS: Fix up debugfs to use d_is_dir() in place of S_ISDIR()
    VFS: Combine inode checks with d_is_negative() and d_is_positive() in pathwalk
    NFS: Don't use d_inode as a variable name
    VFS: Impose ordering on accesses of d_inode and d_flags
    VFS: Add owner-filesystem positive/negative dentry checks
    nfs: generic_write_checks() shouldn't be done on swapout...
    ocfs2: use __generic_file_write_iter()
    mirror O_APPEND and O_DIRECT into iocb->ki_flags
    switch generic_write_checks() to iocb and iter
    ocfs2: move generic_write_checks() before the alignment checks
    ocfs2_file_write_iter: stop messing with ppos
    udf_file_write_iter: reorder and simplify
    fuse: ->direct_IO() doesn't need generic_write_checks()
    ext4_file_write_iter: move generic_write_checks() up
    xfs_file_aio_write_checks: switch to iocb/iov_iter
    generic_write_checks(): drop isblk argument
    blkdev_write_iter: expand generic_file_checks() call in there
    ...

    Linus Torvalds
     

16 Apr, 2015

38 commits

  • Merge second patchbomb from Andrew Morton:

    - the rest of MM

    - various misc bits

    - add ability to run /sbin/reboot at reboot time

    - printk/vsprintf changes

    - fiddle with seq_printf() return value

    * akpm: (114 commits)
    parisc: remove use of seq_printf return value
    lru_cache: remove use of seq_printf return value
    tracing: remove use of seq_printf return value
    cgroup: remove use of seq_printf return value
    proc: remove use of seq_printf return value
    s390: remove use of seq_printf return value
    cris fasttimer: remove use of seq_printf return value
    cris: remove use of seq_printf return value
    openrisc: remove use of seq_printf return value
    ARM: plat-pxa: remove use of seq_printf return value
    nios2: cpuinfo: remove use of seq_printf return value
    microblaze: mb: remove use of seq_printf return value
    ipc: remove use of seq_printf return value
    rtc: remove use of seq_printf return value
    power: wakeup: remove use of seq_printf return value
    x86: mtrr: if: remove use of seq_printf return value
    linux/bitmap.h: improve BITMAP_{LAST,FIRST}_WORD_MASK
    MAINTAINERS: CREDITS: remove Stefano Brivio from B43
    .mailmap: add Ricardo Ribalda
    CREDITS: add Ricardo Ribalda Delgado
    ...

    Linus Torvalds
     
  • Do not perform cond_resched() before the busy compaction loop in
    __zs_compact(), because this loop does it when needed.

    Signed-off-by: Sergey Senozhatsky
    Acked-by: Minchan Kim
    Cc: Nitin Gupta
    Cc: Stephen Rothwell
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Sergey Senozhatsky
     
  • There is no point in overriding the size class below. It causes fatal
    corruption on the next chunk on the 3264-bytes size class, which is the
    last size class that is not huge.

    For example, if the requested size was exactly 3264 bytes, current
    zsmalloc allocates and returns a chunk from the size class of 3264 bytes,
    not 4096. User access to this chunk may overwrite head of the next
    adjacent chunk.

    Here is the panic log captured when freelist was corrupted due to this:

    Kernel BUG at ffffffc00030659c [verbose debug info unavailable]
    Internal error: Oops - BUG: 96000006 [#1] PREEMPT SMP
    Modules linked in:
    exynos-snapshot: core register saved(CPU:5)
    CPUMERRSR: 0000000000000000, L2MERRSR: 0000000000000000
    exynos-snapshot: context saved(CPU:5)
    exynos-snapshot: item - log_kevents is disabled
    CPU: 5 PID: 898 Comm: kswapd0 Not tainted 3.10.61-4497415-eng #1
    task: ffffffc0b8783d80 ti: ffffffc0b71e8000 task.ti: ffffffc0b71e8000
    PC is at obj_idx_to_offset+0x0/0x1c
    LR is at obj_malloc+0x44/0xe8
    pc : [] lr : [] pstate: a0000045
    sp : ffffffc0b71eb790
    x29: ffffffc0b71eb790 x28: ffffffc00204c000
    x27: 000000000001d96f x26: 0000000000000000
    x25: ffffffc098cc3500 x24: ffffffc0a13f2810
    x23: ffffffc098cc3501 x22: ffffffc0a13f2800
    x21: 000011e1a02006e3 x20: ffffffc0a13f2800
    x19: ffffffbc02a7e000 x18: 0000000000000000
    x17: 0000000000000000 x16: 0000000000000feb
    x15: 0000000000000000 x14: 00000000a01003e3
    x13: 0000000000000020 x12: fffffffffffffff0
    x11: ffffffc08b264000 x10: 00000000e3a01004
    x9 : ffffffc08b263fea x8 : ffffffc0b1e611c0
    x7 : ffffffc000307d24 x6 : 0000000000000000
    x5 : 0000000000000038 x4 : 000000000000011e
    x3 : ffffffbc00003e90 x2 : 0000000000000cc0
    x1 : 00000000d0100371 x0 : ffffffbc00003e90

    Reported-by: Sooyong Suk
    Signed-off-by: Heesub Shin
    Tested-by: Sooyong Suk
    Acked-by: Minchan Kim
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Heesub Shin
     
  • In putback_zspage, we don't need to insert a zspage into list of zspage
    in size_class again to just fix fullness group. We could do directly
    without reinsertion so we could save some instuctions.

    Reported-by: Heesub Shin
    Signed-off-by: Minchan Kim
    Cc: Nitin Gupta
    Cc: Sergey Senozhatsky
    Cc: Dan Streetman
    Cc: Seth Jennings
    Cc: Ganesh Mahendran
    Cc: Luigi Semenzato
    Cc: Gunho Lee
    Cc: Juneho Choi
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Minchan Kim
     
  • A micro-optimization. Avoid additional branching and reduce (a bit)
    registry pressure (f.e. s_off += size; d_off += size; may be calculated
    twise: first for >= PAGE_SIZE check and later for offset update in "else"
    clause).

    scripts/bloat-o-meter shows some improvement

    add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-10 (-10)
    function old new delta
    zs_object_copy 550 540 -10

    Signed-off-by: Sergey Senozhatsky
    Acked-by: Minchan Kim
    Cc: Nitin Gupta
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Sergey Senozhatsky
     
  • Do not synchronize rcu in zs_compact(). Neither zsmalloc not
    zram use rcu.

    Signed-off-by: Sergey Senozhatsky
    Acked-by: Minchan Kim
    Cc: Nitin Gupta
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Sergey Senozhatsky
     
  • Signed-off-by: Yinghao Xie
    Suggested-by: Minchan Kim
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Yinghao Xie
     
  • Create zsmalloc doc which explains design concept and stat information.

    Signed-off-by: Minchan Kim
    Cc: Juneho Choi
    Cc: Gunho Lee
    Cc: Luigi Semenzato
    Cc: Dan Streetman
    Cc: Seth Jennings
    Cc: Nitin Gupta
    Cc: Jerome Marchand
    Cc: Sergey Senozhatsky
    Cc: Joonsoo Kim
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Minchan Kim
     
  • During investigating compaction, fullness information of each class is
    helpful for investigating how the compaction works well. With that, we
    could know how compaction works well more clear on each size class.

    Signed-off-by: Minchan Kim
    Cc: Juneho Choi
    Cc: Gunho Lee
    Cc: Luigi Semenzato
    Cc: Dan Streetman
    Cc: Seth Jennings
    Cc: Nitin Gupta
    Cc: Jerome Marchand
    Cc: Sergey Senozhatsky
    Cc: Joonsoo Kim
    Cc: Mel Gorman
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Minchan Kim
     
  • We store handle on header of each allocated object so it increases the
    size of each object by sizeof(unsigned long).

    If zram stores 4096 bytes to zsmalloc(ie, bad compression), zsmalloc needs
    4104B-class to add handle.

    However, 4104B-class has 1-pages_per_zspage so wasted size by internal
    fragment is 8192 - 4104, which is terrible.

    So this patch records the handle in page->private on such huge object(ie,
    pages_per_zspage == 1 && maxobj_per_zspage == 1) instead of header of each
    object so we could use 4096B-class, not 4104B-class.

    Signed-off-by: Minchan Kim
    Cc: Juneho Choi
    Cc: Gunho Lee
    Cc: Luigi Semenzato
    Cc: Dan Streetman
    Cc: Seth Jennings
    Cc: Nitin Gupta
    Cc: Jerome Marchand
    Cc: Sergey Senozhatsky
    Cc: Joonsoo Kim
    Cc: Mel Gorman
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Minchan Kim
     
  • Curretly, zsmalloc regards a zspage as ZS_ALMOST_EMPTY if the zspage has
    under 1/4 used objects(ie, fullness_threshold_frac). It could make result
    in loose packing since zsmalloc migrates only ZS_ALMOST_EMPTY zspage out.

    This patch changes the rule so that zsmalloc makes zspage which has above
    3/4 used object ZS_ALMOST_FULL so it could make tight packing.

    Signed-off-by: Minchan Kim
    Cc: Juneho Choi
    Cc: Gunho Lee
    Cc: Luigi Semenzato
    Cc: Dan Streetman
    Cc: Seth Jennings
    Cc: Nitin Gupta
    Cc: Jerome Marchand
    Cc: Sergey Senozhatsky
    Cc: Joonsoo Kim
    Cc: Mel Gorman
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Minchan Kim
     
  • This patch provides core functions for migration of zsmalloc. Migraion
    policy is simple as follows.

    for each size class {
    while {
    src_page = get zs_page from ZS_ALMOST_EMPTY
    if (!src_page)
    break;
    dst_page = get zs_page from ZS_ALMOST_FULL
    if (!dst_page)
    dst_page = get zs_page from ZS_ALMOST_EMPTY
    if (!dst_page)
    break;
    migrate(from src_page, to dst_page);
    }
    }

    For migration, we need to identify which objects in zspage are allocated
    to migrate them out. We could know it by iterating of freed objects in a
    zspage because first_page of zspage keeps free objects singly-linked list
    but it's not efficient. Instead, this patch adds a tag(ie,
    OBJ_ALLOCATED_TAG) in header of each object(ie, handle) so we could check
    whether the object is allocated easily.

    This patch adds another status bit in handle to synchronize between user
    access through zs_map_object and migration. During migration, we cannot
    move objects user are using due to data coherency between old object and
    new object.

    [akpm@linux-foundation.org: zsmalloc.c needs sched.h for cond_resched()]
    Signed-off-by: Minchan Kim
    Cc: Juneho Choi
    Cc: Gunho Lee
    Cc: Luigi Semenzato
    Cc: Dan Streetman
    Cc: Seth Jennings
    Cc: Nitin Gupta
    Cc: Jerome Marchand
    Cc: Sergey Senozhatsky
    Cc: Joonsoo Kim
    Cc: Mel Gorman
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Minchan Kim
     
  • In later patch, migration needs some part of functions in zs_malloc and
    zs_free so this patch factor out them.

    Signed-off-by: Minchan Kim
    Cc: Juneho Choi
    Cc: Gunho Lee
    Cc: Luigi Semenzato
    Cc: Dan Streetman
    Cc: Seth Jennings
    Cc: Nitin Gupta
    Cc: Jerome Marchand
    Cc: Sergey Senozhatsky
    Cc: Joonsoo Kim
    Cc: Mel Gorman
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Minchan Kim
     
  • Recently, we started to use zram heavily and some of issues
    popped.

    1) external fragmentation

    I got a report from Juneho Choi that fork failed although there are plenty
    of free pages in the system. His investigation revealed zram is one of
    the culprit to make heavy fragmentation so there was no more contiguous
    16K page for pgd to fork in the ARM.

    2) non-movable pages

    Other problem of zram now is that inherently, user want to use zram as
    swap in small memory system so they use zRAM with CMA to use memory
    efficiently. However, unfortunately, it doesn't work well because zRAM
    cannot use CMA's movable pages unless it doesn't support compaction. I
    got several reports about that OOM happened with zram although there are
    lots of swap space and free space in CMA area.

    3) internal fragmentation

    zRAM has started support memory limitation feature to limit memory usage
    and I sent a patchset(https://lkml.org/lkml/2014/9/21/148) for VM to be
    harmonized with zram-swap to stop anonymous page reclaim if zram consumed
    memory up to the limit although there are free space on the swap. One
    problem for that direction is zram has no way to know any hole in memory
    space zsmalloc allocated by internal fragmentation so zram would regard
    swap is full although there are free space in zsmalloc. For solving the
    issue, zram want to trigger compaction of zsmalloc before it decides full
    or not.

    This patchset is first step to support above issues. For that, it adds
    indirect layer between handle and object location and supports manual
    compaction to solve 3th problem first of all.

    After this patchset got merged, next step is to make VM aware of zsmalloc
    compaction so that generic compaction will move zsmalloced-pages
    automatically in runtime.

    In my imaginary experiment(ie, high compress ratio data with heavy swap
    in/out on 8G zram-swap), data is as follows,

    Before =
    zram allocated object : 60212066 bytes
    zram total used: 140103680 bytes
    ratio: 42.98 percent
    MemFree: 840192 kB

    Compaction

    After =
    frag ratio after compaction
    zram allocated object : 60212066 bytes
    zram total used: 76185600 bytes
    ratio: 79.03 percent
    MemFree: 901932 kB

    Juneho reported below in his real platform with small aging.
    So, I think the benefit would be bigger in real aging system
    for a long time.

    - frag_ratio increased 3% (ie, higher is better)
    - memfree increased about 6MB
    - In buddy info, Normal 2^3: 4, 2^2: 1: 2^1 increased, Highmem: 2^1 21 increased

    frag ratio after swap fragment
    used : 156677 kbytes
    total: 166092 kbytes
    frag_ratio : 94
    meminfo before compaction
    MemFree: 83724 kB
    Node 0, zone Normal 13642 1364 57 10 61 17 9 5 4 0 0
    Node 0, zone HighMem 425 29 1 0 0 0 0 0 0 0 0

    num_migrated : 23630
    compaction done

    frag ratio after compaction
    used : 156673 kbytes
    total: 160564 kbytes
    frag_ratio : 97
    meminfo after compaction
    MemFree: 89060 kB
    Node 0, zone Normal 14076 1544 67 14 61 17 9 5 4 0 0
    Node 0, zone HighMem 863 50 1 0 0 0 0 0 0 0 0

    This patchset adds more logics(about 480 lines) in zsmalloc but when I
    tested heavy swapin/out program, the regression for swapin/out speed is
    marginal because most of overheads were caused by compress/decompress and
    other MM reclaim stuff.

    This patch (of 7):

    Currently, handle of zsmalloc encodes object's location directly so it
    makes support of migration hard.

    This patch decouples handle and object via adding indirect layer. For
    that, it allocates handle dynamically and returns it to user. The handle
    is the address allocated by slab allocation so it's unique and we could
    keep object's location in the memory space allocated for handle.

    With it, we can change object's position without changing handle itself.

    Signed-off-by: Minchan Kim
    Cc: Juneho Choi
    Cc: Gunho Lee
    Cc: Luigi Semenzato
    Cc: Dan Streetman
    Cc: Seth Jennings
    Cc: Nitin Gupta
    Cc: Jerome Marchand
    Cc: Sergey Senozhatsky
    Cc: Joonsoo Kim
    Cc: Mel Gorman
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Minchan Kim
     
  • mm/compaction.c:250:13: warning: 'suitable_migration_target' defined but not used [-Wunused-function]

    Reported-by: Fengguang Wu
    Cc: Vlastimil Babka
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Andrew Morton
     
  • This will allow FS that uses VM_PFNMAP | VM_MIXEDMAP (no page structs) to
    get notified when access is a write to a read-only PFN.

    This can happen if we mmap() a file then first mmap-read from it to
    page-in a read-only PFN, than we mmap-write to the same page.

    We need this functionality to fix a DAX bug, where in the scenario above
    we fail to set ctime/mtime though we modified the file. An xfstest is
    attached to this patchset that shows the failure and the fix. (A DAX
    patch will follow)

    This functionality is extra important for us, because upon dirtying of a
    pmem page we also want to RDMA the page to a remote cluster node.

    We define a new pfn_mkwrite and do not reuse page_mkwrite because
    1 - The name ;-)
    2 - But mainly because it would take a very long and tedious
    audit of all page_mkwrite functions of VM_MIXEDMAP/VM_PFNMAP
    users. To make sure they do not now CRASH. For example current
    DAX code (which this is for) would crash.
    If we would want to reuse page_mkwrite, We will need to first
    patch all users, so to not-crash-on-no-page. Then enable this
    patch. But even if I did that I would not sleep so well at night.
    Adding a new vector is the safest thing to do, and is not that
    expensive. an extra pointer at a static function vector per driver.
    Also the new vector is better for performance, because else we
    Will call all current Kernel vectors, so to:
    check-ha-no-page-do-nothing and return.

    No need to call it from do_shared_fault because do_wp_page is called to
    change pte permissions anyway.

    Signed-off-by: Yigal Korman
    Signed-off-by: Boaz Harrosh
    Acked-by: Kirill A. Shutemov
    Cc: Matthew Wilcox
    Cc: Jan Kara
    Cc: Hugh Dickins
    Cc: Mel Gorman
    Cc: Dave Chinner
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Boaz Harrosh
     
  • A lot of filesystems use generic_file_mmap() and filemap_fault(),
    f_op->mmap and vm_ops->fault aren't enough to identify filesystem.

    This prints file name, vm_ops->fault, f_op->mmap and a_ops->readpage
    (which is almost always implemented and filesystem-specific).

    Example:

    [ 23.676410] BUG: Bad page map in process sh pte:1b7e6025 pmd:19bbd067
    [ 23.676887] page:ffffea00006df980 count:4 mapcount:1 mapping:ffff8800196426c0 index:0x97
    [ 23.677481] flags: 0x10000000000000c(referenced|uptodate)
    [ 23.677896] page dumped because: bad pte
    [ 23.678205] addr:00007f52fcb17000 vm_flags:00000075 anon_vma: (null) mapping:ffff8800196426c0 index:97
    [ 23.678922] file:libc-2.19.so fault:filemap_fault mmap:generic_file_readonly_mmap readpage:v9fs_vfs_readpage

    [akpm@linux-foundation.org: use pr_alert, per Kirill]
    Signed-off-by: Konstantin Khlebnikov
    Cc: Sasha Levin
    Acked-by: Kirill A. Shutemov
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Konstantin Khlebnikov
     
  • Mempools keep allocated objects in reserved for situations when ordinary
    allocation may not be possible to satisfy. These objects shouldn't be
    accessed before they leave the pool.

    This patch poison elements when get into the pool and unpoison when they
    leave it. This will let KASan to detect use-after-free of mempool's
    elements.

    Signed-off-by: Andrey Ryabinin
    Tested-by: David Rientjes
    Cc: Catalin Marinas
    Cc: Dmitry Chernenkov
    Cc: Dmitry Vyukov
    Cc: Alexander Potapenko
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Andrey Ryabinin
     
  • Like EXPORT_SYMBOL(): the positioning communicates that the macro pertains
    to the immediately preceding function.

    Cc: Dmitry Safonov
    Cc: Michal Nazarewicz
    Cc: Stefan Strogin
    Cc: Marek Szyprowski
    Cc: Joonsoo Kim
    Cc: Pintu Kumar
    Cc: Weijie Yang
    Cc: Laurent Pinchart
    Cc: Vyacheslav Tyrtov
    Cc: Aleksei Mateosian
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Andrew Morton
     
  • Here are two functions that provide interface to compute/get used size and
    size of biggest free chunk in cma region. Add that information to
    debugfs.

    [akpm@linux-foundation.org: move debug code from cma.c into cma_debug.c]
    [stefan.strogin@gmail.com: move code from cma_get_used() and cma_get_maxchunk() to cma_used_get() and cma_maxchunk_get()]
    Signed-off-by: Dmitry Safonov
    Signed-off-by: Stefan Strogin
    Acked-by: Michal Nazarewicz
    Cc: Marek Szyprowski
    Cc: Joonsoo Kim
    Cc: Pintu Kumar
    Cc: Weijie Yang
    Cc: Laurent Pinchart
    Cc: Vyacheslav Tyrtov
    Cc: Aleksei Mateosian
    Signed-off-by: Stefan Strogin
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Dmitry Safonov
     
  • Few trivial cleanups:

    - no need to call set_recommended_min_free_kbytes() from
    late_initcall() -- start_khugepaged() calls it;

    - no need to call set_recommended_min_free_kbytes() from
    start_khugepaged() if khugepaged is not started;

    - there isn't much point in running start_khugepaged() if we've just
    set transparent_hugepage_flags to zero;

    - start_khugepaged() is misnamed -- it also used to stop the thread;

    Signed-off-by: Kirill A. Shutemov
    Cc: David Rientjes
    Cc: Andrea Arcangeli
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Kirill A. Shutemov
     
  • Most-used page->mapping helper -- page_mapping() -- has already uninlined.
    Let's uninline also page_rmapping() and page_anon_vma(). It saves us
    depending on configuration around 400 bytes in text:

    text data bss dec hex filename
    660318 99254 410000 1169572 11d8a4 mm/built-in.o-before
    659854 99254 410000 1169108 11d6d4 mm/built-in.o

    I also tried to make code a bit more clean.

    [akpm@linux-foundation.org: coding-style fixes]
    Signed-off-by: Kirill A. Shutemov
    Cc: Christoph Lameter
    Cc: Konstantin Khlebnikov
    Cc: Rik van Riel
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Kirill A. Shutemov
     
  • Add trace events for cma_alloc() and cma_release().

    The cma_alloc tracepoint is used both for successful and failed allocations,
    in case of allocation failure pfn=-1UL is stored and printed.

    Signed-off-by: Stefan Strogin
    Cc: Ingo Molnar
    Cc: Steven Rostedt
    Cc: Joonsoo Kim
    Cc: Michal Nazarewicz
    Cc: Marek Szyprowski
    Cc: Laurent Pinchart
    Cc: Thierry Reding
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Stefan Strogin
     
  • memblock_reserve() calls memblock_reserve_region() which prints debugging
    information if 'memblock=debug' was passed on the command line. This
    patch adds the same behaviour, but for memblock_add function().

    [akpm@linux-foundation.org: s/memblock_memory/memblock_add/ in message]
    Signed-off-by: Alexander Kuleshov
    Cc: Martin Schwidefsky
    Cc: Philipp Hachtmann
    Cc: Fabian Frederick
    Cc: Catalin Marinas
    Cc: Emil Medve
    Cc: Akinobu Mita
    Cc: Tang Chen
    Cc: Tony Luck
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Alexander Kuleshov
     
  • Now we have an easy access to hugepages' activeness, so existing helpers to
    get the information can be cleaned up.

    [akpm@linux-foundation.org: s/PageHugeActive/page_huge_active/]
    Signed-off-by: Naoya Horiguchi
    Cc: Hugh Dickins
    Reviewed-by: Michal Hocko
    Cc: Mel Gorman
    Cc: Johannes Weiner
    Cc: David Rientjes
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Naoya Horiguchi
     
  • We are not safe from calling isolate_huge_page() on a hugepage
    concurrently, which can make the victim hugepage in invalid state and
    results in BUG_ON().

    The root problem of this is that we don't have any information on struct
    page (so easily accessible) about hugepages' activeness. Note that
    hugepages' activeness means just being linked to
    hstate->hugepage_activelist, which is not the same as normal pages'
    activeness represented by PageActive flag.

    Normal pages are isolated by isolate_lru_page() which prechecks PageLRU
    before isolation, so let's do similarly for hugetlb with a new
    paeg_huge_active().

    set/clear_page_huge_active() should be called within hugetlb_lock. But
    hugetlb_cow() and hugetlb_no_page() don't do this, being justified because
    in these functions set_page_huge_active() is called right after the
    hugepage is allocated and no other thread tries to isolate it.

    [akpm@linux-foundation.org: s/PageHugeActive/page_huge_active/, make it return bool]
    [fengguang.wu@intel.com: set_page_huge_active() can be static]
    Signed-off-by: Naoya Horiguchi
    Cc: Hugh Dickins
    Reviewed-by: Michal Hocko
    Cc: Mel Gorman
    Cc: Johannes Weiner
    Cc: David Rientjes
    Signed-off-by: Fengguang Wu
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Naoya Horiguchi
     
  • __put_compound_page() calls __page_cache_release() to do some freeing
    work, but it's obviously for thps, not for hugetlb. We don't care because
    PageLRU is always cleared and page->mem_cgroup is always NULL for hugetlb.
    But it's not correct and has potential risks, so let's make it
    conditional.

    Signed-off-by: Naoya Horiguchi
    Cc: Hugh Dickins
    Reviewed-by: Michal Hocko
    Cc: Mel Gorman
    Cc: Johannes Weiner
    Cc: David Rientjes
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Naoya Horiguchi
     
  • The creators of the C language gave us the while keyword. Let's use
    that instead of synthesizing it from if+goto.

    Made possible by 6597d783397a ("mm/mmap.c: replace find_vma_prepare()
    with clearer find_vma_links()").

    [akpm@linux-foundation.org: fix 80-col overflows]
    Signed-off-by: Rasmus Villemoes
    Cc: "Kirill A. Shutemov"
    Cc: Sasha Levin
    Cc: Cyrill Gorcunov
    Cc: Roman Gushchin
    Cc: Hugh Dickins
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Rasmus Villemoes
     
  • set_recommended_min_free_kbytes() adjusts zone water marks to be suitable
    for khugepaged. We avoid doing this if khugepaged is disabled, but don't
    catch the case when khugepaged is failed to start.

    Let's address this by checking khugepaged_thread instead of
    khugepaged_enabled() in set_recommended_min_free_kbytes().
    It's NULL if the kernel thread is stopped or failed to start.

    Signed-off-by: Kirill A. Shutemov
    Cc: David Rientjes
    Cc: Andrea Arcangeli
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Kirill A. Shutemov
     
  • We miss error-handling in few cases hugepage_init(). Let's fix that.

    Signed-off-by: Kirill A. Shutemov
    Cc: Andrea Arcangeli
    Acked-by: David Rientjes
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Kirill A. Shutemov
     
  • Mempools keep elements in a reserved pool for contexts in which allocation
    may not be possible. When an element is allocated from the reserved pool,
    its memory contents is the same as when it was added to the reserved pool.

    Because of this, elements lack any free poisoning to detect use-after-free
    errors.

    This patch adds free poisoning for elements backed by the slab allocator.
    This is possible because the mempool layer knows the object size of each
    element.

    When an element is added to the reserved pool, it is poisoned with
    POISON_FREE. When it is removed from the reserved pool, the contents are
    checked for POISON_FREE. If there is a mismatch, a warning is emitted to
    the kernel log.

    This is only effective for configs with CONFIG_DEBUG_SLAB or
    CONFIG_SLUB_DEBUG_ON.

    [fabio.estevam@freescale.com: use '%zu' for printing 'size_t' variable]
    [arnd@arndb.de: add missing include]
    Signed-off-by: David Rientjes
    Cc: Dave Kleikamp
    Cc: Christoph Hellwig
    Cc: Sebastian Ott
    Cc: Mikulas Patocka
    Cc: Catalin Marinas
    Signed-off-by: Fabio Estevam
    Signed-off-by: Arnd Bergmann
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    David Rientjes
     
  • All occurrences of mempools based on slab caches with object constructors
    have been removed from the tree, so disallow creating them.

    We can only dereference mem->ctor in mm/mempool.c without including
    mm/slab.h in include/linux/mempool.h. So simply note the restriction,
    just like the comment restricting usage of __GFP_ZERO, and warn on kernels
    with CONFIG_DEBUG_VM() if such a mempool is allocated from.

    We don't want to incur this check on every element allocation, so use
    VM_BUG_ON().

    Signed-off-by: David Rientjes
    Cc: Dave Kleikamp
    Cc: Christoph Hellwig
    Cc: Sebastian Ott
    Cc: Mikulas Patocka
    Cc: Catalin Marinas
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    David Rientjes
     
  • We converted some of the usages of ACCESS_ONCE to READ_ONCE in the mm/
    tree since it doesn't work reliably on non-scalar types.

    This patch removes the rest of the usages of ACCESS_ONCE, and use the new
    READ_ONCE API for the read accesses. This makes things cleaner, instead
    of using separate/multiple sets of APIs.

    Signed-off-by: Jason Low
    Acked-by: Michal Hocko
    Acked-by: Davidlohr Bueso
    Acked-by: Rik van Riel
    Reviewed-by: Christian Borntraeger
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Jason Low
     
  • Commit 38c5ce936a08 ("mm/gup: Replace ACCESS_ONCE with READ_ONCE")
    converted ACCESS_ONCE usage in gup_pmd_range() to READ_ONCE, since
    ACCESS_ONCE doesn't work reliably on non-scalar types.

    This patch also fixes the other ACCESS_ONCE usages in gup_pte_range()
    and __get_user_pages_fast() in mm/gup.c

    Signed-off-by: Jason Low
    Acked-by: Michal Hocko
    Acked-by: Davidlohr Bueso
    Acked-by: Rik van Riel
    Reviewed-by: Christian Borntraeger
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Jason Low
     
  • As suggested by Kirill the "goto"s in vma_to_resize aren't necessary, just
    change them to explicit return.

    Signed-off-by: Derek Che
    Suggested-by: "Kirill A. Shutemov"
    Acked-by: David Rientjes
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Derek
     
  • Recently I straced bash behavior in this dd zero pipe to read test, in
    part of testing under vm.overcommit_memory=2 (OVERCOMMIT_NEVER mode):

    # dd if=/dev/zero | read x

    The bash sub shell is calling mremap to reallocate more and more memory
    untill it finally failed -ENOMEM (I expect), or to be killed by system OOM
    killer (which should not happen under OVERCOMMIT_NEVER mode); But the
    mremap system call actually failed of -EFAULT, which is a surprise to me,
    I think it's supposed to be -ENOMEM? then I wrote this piece of C code
    testing confirmed it: https://gist.github.com/crquan/326bde37e1ddda8effe5

    $ ./remap
    allocated one page @0x7f686bf71000, (PAGE_SIZE: 4096)
    grabbed 7680512000 bytes of memory (1875125 pages) @ 00007f6690993000.
    mremap failed Bad address (14).

    The -EFAULT comes from the branch of security_vm_enough_memory_mm failure,
    underlyingly it calls __vm_enough_memory which returns only 0 for success
    or -ENOMEM; So why vma_to_resize needs to return -EFAULT in this case?
    this sounds like a mistake to me.

    Some more digging into git history:

    1) Before commit 119f657c7 ("RLIMIT_AS checking fix") in May 1 2005
    (pre 2.6.12 days) it was returning -ENOMEM for this failure;

    2) but commit 119f657c7 ("untangling do_mremap(), part 1") changed it
    accidentally, to what ever is preserved in local ret, which happened to
    be -EFAULT, in a previous assignment;

    3) then in commit 54f5de709 code refactoring, it's explicitly returning
    -EFAULT, should be wrong.

    Signed-off-by: Derek Che
    Acked-by: David Rientjes
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Derek
     
  • In original implementation of vm_map_ram made by Nick Piggin there were
    two bitmaps: alloc_map and dirty_map. None of them were used as supposed
    to be: finding a suitable free hole for next allocation in block.
    vm_map_ram allocates space sequentially in block and on free call marks
    pages as dirty, so freed space can't be reused anymore.

    Actually it would be very interesting to know the real meaning of those
    bitmaps, maybe implementation was incomplete, etc.

    But long time ago Zhang Yanfei removed alloc_map by these two commits:

    mm/vmalloc.c: remove dead code in vb_alloc
    3fcd76e8028e0be37b02a2002b4f56755daeda06
    mm/vmalloc.c: remove alloc_map from vmap_block
    b8e748b6c32999f221ea4786557b8e7e6c4e4e7a

    In this patch I replaced dirty_map with two range variables: dirty min and
    max. These variables store minimum and maximum position of dirty space in
    a block, since we need only to know the dirty range, not exact position of
    dirty pages.

    Why it was made? Several reasons: at first glance it seems that
    vm_map_ram allocator concerns about fragmentation thus it uses bitmaps for
    finding free hole, but it is not true. To avoid complexity seems it is
    better to use something simple, like min or max range values. Secondly,
    code also becomes simpler, without iteration over bitmap, just comparing
    values in min and max macros. Thirdly, bitmap occupies up to 1024 bits
    (4MB is a max size of a block). Here I replaced the whole bitmap with two
    longs.

    Finally vm_unmap_aliases should be slightly faster and the whole
    vmap_block structure occupies less memory.

    Signed-off-by: Roman Pen
    Cc: Zhang Yanfei
    Cc: Eric Dumazet
    Acked-by: Joonsoo Kim
    Cc: David Rientjes
    Cc: WANG Chao
    Cc: Fabian Frederick
    Cc: Christoph Lameter
    Cc: Gioh Kim
    Cc: Rob Jones
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Roman Pen
     
  • Previous implementation allocates new vmap block and repeats search of a
    free block from the very beginning, iterating over the CPU free list.

    Why it can be better??

    1. Allocation can happen on one CPU, but search can be done on another CPU.
    In worst case we preallocate amount of vmap blocks which is equal to
    CPU number on the system.

    2. In previous patch I added newly allocated block to the tail of free list
    to avoid soon exhaustion of virtual space and give a chance to occupy
    blocks which were allocated long time ago. Thus to find newly allocated
    block all the search sequence should be repeated, seems it is not efficient.

    In this patch newly allocated block is occupied right away, address of
    virtual space is returned to the caller, so there is no any need to repeat
    the search sequence, allocation job is done.

    Signed-off-by: Roman Pen
    Cc: Andrew Morton
    Cc: Eric Dumazet
    Acked-by: Joonsoo Kim
    Cc: David Rientjes
    Cc: WANG Chao
    Cc: Fabian Frederick
    Cc: Christoph Lameter
    Cc: Gioh Kim
    Cc: Rob Jones
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Roman Pen