1. 19 12月, 2012 5 次提交
    • G
      slub: slub-specific propagation changes · 107dab5c
      Glauber Costa 提交于
      SLUB allows us to tune a particular cache behavior with sysfs-based
      tunables.  When creating a new memcg cache copy, we'd like to preserve any
      tunables the parent cache already had.
      
      This can be done by tapping into the store attribute function provided by
      the allocator.  We of course don't need to mess with read-only fields.
      Since the attributes can have multiple types and are stored internally by
      sysfs, the best strategy is to issue a ->show() in the root cache, and
      then ->store() in the memcg cache.
      
      The drawback of that, is that sysfs can allocate up to a page in buffering
      for show(), that we are likely not to need, but also can't guarantee.  To
      avoid always allocating a page for that, we can update the caches at store
      time with the maximum attribute size ever stored to the root cache.  We
      will then get a buffer big enough to hold it.  The corolary to this, is
      that if no stores happened, nothing will be propagated.
      
      It can also happen that a root cache has its tunables updated during
      normal system operation.  In this case, we will propagate the change to
      all caches that are already active.
      
      [akpm@linux-foundation.org: tweak code to avoid __maybe_unused]
      Signed-off-by: NGlauber Costa <glommer@parallels.com>
      Cc: Christoph Lameter <cl@linux.com>
      Cc: David Rientjes <rientjes@google.com>
      Cc: Frederic Weisbecker <fweisbec@redhat.com>
      Cc: Greg Thelen <gthelen@google.com>
      Cc: Johannes Weiner <hannes@cmpxchg.org>
      Cc: JoonSoo Kim <js1304@gmail.com>
      Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
      Cc: Mel Gorman <mel@csn.ul.ie>
      Cc: Michal Hocko <mhocko@suse.cz>
      Cc: Pekka Enberg <penberg@cs.helsinki.fi>
      Cc: Rik van Riel <riel@redhat.com>
      Cc: Suleiman Souhlal <suleiman@google.com>
      Cc: Tejun Heo <tj@kernel.org>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      107dab5c
    • G
      memcg: destroy memcg caches · 1f458cbf
      Glauber Costa 提交于
      Implement destruction of memcg caches.  Right now, only caches where our
      reference counter is the last remaining are deleted.  If there are any
      other reference counters around, we just leave the caches lying around
      until they go away.
      
      When that happens, a destruction function is called from the cache code.
      Caches are only destroyed in process context, so we queue them up for
      later processing in the general case.
      Signed-off-by: NGlauber Costa <glommer@parallels.com>
      Cc: Christoph Lameter <cl@linux.com>
      Cc: David Rientjes <rientjes@google.com>
      Cc: Frederic Weisbecker <fweisbec@redhat.com>
      Cc: Greg Thelen <gthelen@google.com>
      Cc: Johannes Weiner <hannes@cmpxchg.org>
      Cc: JoonSoo Kim <js1304@gmail.com>
      Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
      Cc: Mel Gorman <mel@csn.ul.ie>
      Cc: Michal Hocko <mhocko@suse.cz>
      Cc: Pekka Enberg <penberg@cs.helsinki.fi>
      Cc: Rik van Riel <riel@redhat.com>
      Cc: Suleiman Souhlal <suleiman@google.com>
      Cc: Tejun Heo <tj@kernel.org>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      1f458cbf
    • G
      sl[au]b: allocate objects from memcg cache · d79923fa
      Glauber Costa 提交于
      We are able to match a cache allocation to a particular memcg.  If the
      task doesn't change groups during the allocation itself - a rare event,
      this will give us a good picture about who is the first group to touch a
      cache page.
      
      This patch uses the now available infrastructure by calling
      memcg_kmem_get_cache() before all the cache allocations.
      Signed-off-by: NGlauber Costa <glommer@parallels.com>
      Cc: Christoph Lameter <cl@linux.com>
      Cc: David Rientjes <rientjes@google.com>
      Cc: Frederic Weisbecker <fweisbec@redhat.com>
      Cc: Greg Thelen <gthelen@google.com>
      Cc: Johannes Weiner <hannes@cmpxchg.org>
      Cc: JoonSoo Kim <js1304@gmail.com>
      Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
      Cc: Mel Gorman <mel@csn.ul.ie>
      Cc: Michal Hocko <mhocko@suse.cz>
      Cc: Pekka Enberg <penberg@cs.helsinki.fi>
      Cc: Rik van Riel <riel@redhat.com>
      Cc: Suleiman Souhlal <suleiman@google.com>
      Cc: Tejun Heo <tj@kernel.org>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      d79923fa
    • G
      sl[au]b: always get the cache from its page in kmem_cache_free() · b9ce5ef4
      Glauber Costa 提交于
      struct page already has this information.  If we start chaining caches,
      this information will always be more trustworthy than whatever is passed
      into the function.
      Signed-off-by: NGlauber Costa <glommer@parallels.com>
      Cc: Christoph Lameter <cl@linux.com>
      Cc: David Rientjes <rientjes@google.com>
      Cc: Frederic Weisbecker <fweisbec@redhat.com>
      Cc: Greg Thelen <gthelen@google.com>
      Cc: Johannes Weiner <hannes@cmpxchg.org>
      Cc: JoonSoo Kim <js1304@gmail.com>
      Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
      Cc: Mel Gorman <mel@csn.ul.ie>
      Cc: Michal Hocko <mhocko@suse.cz>
      Cc: Pekka Enberg <penberg@cs.helsinki.fi>
      Cc: Rik van Riel <riel@redhat.com>
      Cc: Suleiman Souhlal <suleiman@google.com>
      Cc: Tejun Heo <tj@kernel.org>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      b9ce5ef4
    • G
      slab/slub: consider a memcg parameter in kmem_create_cache · 2633d7a0
      Glauber Costa 提交于
      Allow a memcg parameter to be passed during cache creation.  When the slub
      allocator is being used, it will only merge caches that belong to the same
      memcg.  We'll do this by scanning the global list, and then translating
      the cache to a memcg-specific cache
      
      Default function is created as a wrapper, passing NULL to the memcg
      version.  We only merge caches that belong to the same memcg.
      
      A helper is provided, memcg_css_id: because slub needs a unique cache name
      for sysfs.  Since this is visible, but not the canonical location for slab
      data, the cache name is not used, the css_id should suffice.
      Signed-off-by: NGlauber Costa <glommer@parallels.com>
      Cc: Christoph Lameter <cl@linux.com>
      Cc: David Rientjes <rientjes@google.com>
      Cc: Frederic Weisbecker <fweisbec@redhat.com>
      Cc: Greg Thelen <gthelen@google.com>
      Cc: Johannes Weiner <hannes@cmpxchg.org>
      Cc: JoonSoo Kim <js1304@gmail.com>
      Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
      Cc: Mel Gorman <mel@csn.ul.ie>
      Cc: Michal Hocko <mhocko@suse.cz>
      Cc: Pekka Enberg <penberg@cs.helsinki.fi>
      Cc: Rik van Riel <riel@redhat.com>
      Cc: Suleiman Souhlal <suleiman@google.com>
      Cc: Tejun Heo <tj@kernel.org>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      2633d7a0
  2. 12 12月, 2012 1 次提交
    • L
      slub, hotplug: ignore unrelated node's hot-adding and hot-removing · b9d5ab25
      Lai Jiangshan 提交于
      SLUB only focuses on the nodes which have normal memory and it ignores the
      other node's hot-adding and hot-removing.
      
      Aka: if some memory of a node which has no onlined memory is online, but
      this new memory onlined is not normal memory (for example, highmem), we
      should not allocate kmem_cache_node for SLUB.
      
      And if the last normal memory is offlined, but the node still has memory,
      we should remove kmem_cache_node for that node.  (The current code delays
      it when all of the memory is offlined)
      
      So we only do something when marg->status_change_nid_normal > 0.
      marg->status_change_nid is not suitable here.
      
      The same problem doesn't exist in SLAB, because SLAB allocates kmem_list3
      for every node even the node don't have normal memory, SLAB tolerates
      kmem_list3 on alien nodes.  SLUB only focuses on the nodes which have
      normal memory, it don't tolerate alien kmem_cache_node.  The patch makes
      SLUB become self-compatible and avoids WARNs and BUGs in rare conditions.
      Signed-off-by: NLai Jiangshan <laijs@cn.fujitsu.com>
      Cc: David Rientjes <rientjes@google.com>
      Cc: Minchan Kim <minchan.kim@gmail.com>
      Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
      Cc: Yasuaki Ishimatsu <isimatu.yasuaki@jp.fujitsu.com>
      Cc: Rob Landley <rob@landley.net>
      Cc: Andrew Morton <akpm@linux-foundation.org>
      Cc: Jiang Liu <jiang.liu@huawei.com>
      Cc: Kay Sievers <kay.sievers@vrfy.org>
      Cc: Greg Kroah-Hartman <gregkh@suse.de>
      Cc: Mel Gorman <mgorman@suse.de>
      Cc: Wen Congyang <wency@cn.fujitsu.com>
      Acked-by: NChristoph Lameter <cl@linux.com>
      Cc: Pekka Enberg <penberg@kernel.org>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      b9d5ab25
  3. 11 12月, 2012 4 次提交
  4. 31 10月, 2012 2 次提交
  5. 24 10月, 2012 4 次提交
  6. 19 10月, 2012 1 次提交
    • J
      slub: remove one code path and reduce lock contention in __slab_free() · 837d678d
      Joonsoo Kim 提交于
      When we try to free object, there is some of case that we need
      to take a node lock. This is the necessary step for preventing a race.
      After taking a lock, then we try to cmpxchg_double_slab().
      But, there is a possible scenario that cmpxchg_double_slab() is failed
      with taking a lock. Following example explains it.
      
      CPU A               CPU B
      need lock
      ...                 need lock
      ...                 lock!!
      lock..but spin      free success
      spin...             unlock
      lock!!
      free fail
      
      In this case, retry with taking a lock is occured in CPU A.
      I think that in this case for CPU A,
      "release a lock first, and re-take a lock if necessary" is preferable way.
      
      There are two reasons for this.
      
      First, this makes __slab_free()'s logic somehow simple.
      With this patch, 'was_frozen = 1' is "always" handled without taking a lock.
      So we can remove one code path.
      
      Second, it may reduce lock contention.
      When we do retrying, status of slab is already changed,
      so we don't need a lock anymore in almost every case.
      "release a lock first, and re-take a lock if necessary" policy is
      helpful to this.
      Signed-off-by: NJoonsoo Kim <js1304@gmail.com>
      Acked-by: NChristoph Lameter <cl@linux.com>
      Signed-off-by: NPekka Enberg <penberg@kernel.org>
      837d678d
  7. 03 10月, 2012 1 次提交
  8. 25 9月, 2012 1 次提交
  9. 19 9月, 2012 1 次提交
  10. 18 9月, 2012 1 次提交
    • J
      slub: consider pfmemalloc_match() in get_partial_node() · 8ba00bb6
      Joonsoo Kim 提交于
      get_partial() is currently not checking pfmemalloc_match() meaning that
      it is possible for pfmemalloc pages to leak to non-pfmemalloc users.
      This is a problem in the following situation.  Assume that there is a
      request from normal allocation and there are no objects in the per-cpu
      cache and no node-partial slab.
      
      In this case, slab_alloc enters the slow path and new_slab_objects() is
      called which may return a PFMEMALLOC page.  As the current user is not
      allowed to access PFMEMALLOC page, deactivate_slab() is called
      ([5091b74a: mm: slub: optimise the SLUB fast path to avoid pfmemalloc
      checks]) and returns an object from PFMEMALLOC page.
      
      Next time, when we get another request from normal allocation,
      slab_alloc() enters the slow-path and calls new_slab_objects().  In
      new_slab_objects(), we call get_partial() and get a partial slab which
      was just deactivated but is a pfmemalloc page.  We extract one object
      from it and re-deactivate.
      
        "deactivate -> re-get in get_partial -> re-deactivate" occures repeatedly.
      
      As a result, access to PFMEMALLOC page is not properly restricted and it
      can cause a performance degradation due to frequent deactivation.
      deactivation frequently.
      
      This patch changes get_partial_node() to take pfmemalloc_match() into
      account and prevents the "deactivate -> re-get in get_partial()
      scenario.  Instead, new_slab() is called.
      Signed-off-by: NJoonsoo Kim <js1304@gmail.com>
      Acked-by: NDavid Rientjes <rientjes@google.com>
      Signed-off-by: NMel Gorman <mgorman@suse.de>
      Cc: David Miller <davem@davemloft.net>
      Cc: Chuck Lever <chuck.lever@oracle.com>
      Cc: Pekka Enberg <penberg@kernel.org>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      8ba00bb6
  11. 10 9月, 2012 1 次提交
    • C
      slub: Zero initial memory segment for kmem_cache and kmem_cache_node · 9df53b15
      Christoph Lameter 提交于
      Tony Luck reported the following problem on IA-64:
      
        Worked fine yesterday on next-20120905, crashes today. First sign of
        trouble was an unaligned access, then a NULL dereference. SL*B related
        bits of my config:
      
        CONFIG_SLUB_DEBUG=y
        # CONFIG_SLAB is not set
        CONFIG_SLUB=y
        CONFIG_SLABINFO=y
        # CONFIG_SLUB_DEBUG_ON is not set
        # CONFIG_SLUB_STATS is not set
      
        And he console log.
      
        PID hash table entries: 4096 (order: 1, 32768 bytes)
        Dentry cache hash table entries: 262144 (order: 7, 2097152 bytes)
        Inode-cache hash table entries: 131072 (order: 6, 1048576 bytes)
        Memory: 2047920k/2086064k available (13992k code, 38144k reserved,
        6012k data, 880k init)
        kernel unaligned access to 0xca2ffc55fb373e95, ip=0xa0000001001be550
        swapper[0]: error during unaligned kernel access
         -1 [1]
        Modules linked in:
      
        Pid: 0, CPU 0, comm:              swapper
        psr : 00001010084a2018 ifs : 800000000000060f ip  :
        [<a0000001001be550>]    Not tainted (3.6.0-rc4-zx1-smp-next-20120906)
        ip is at new_slab+0x90/0x680
        unat: 0000000000000000 pfs : 000000000000060f rsc : 0000000000000003
        rnat: 9666960159966a59 bsps: a0000001001441c0 pr  : 9666960159965a59
        ldrs: 0000000000000000 ccv : 0000000000000000 fpsr: 0009804c8a70433f
        csd : 0000000000000000 ssd : 0000000000000000
        b0  : a0000001001be500 b6  : a00000010112cb20 b7  : a0000001011660a0
        f6  : 0fff7f0f0f0f0e54f0000 f7  : 0ffe8c5c1000000000000
        f8  : 1000d8000000000000000 f9  : 100068800000000000000
        f10 : 10005f0f0f0f0e54f0000 f11 : 1003e0000000000000078
        r1  : a00000010155eef0 r2  : 0000000000000000 r3  : fffffffffffc1638
        r8  : e0000040600081b8 r9  : ca2ffc55fb373e95 r10 : 0000000000000000
        r11 : e000004040001646 r12 : a000000101287e20 r13 : a000000101280000
        r14 : 0000000000004000 r15 : 0000000000000078 r16 : ca2ffc55fb373e75
        r17 : e000004040040000 r18 : fffffffffffc1646 r19 : e000004040001646
        r20 : fffffffffffc15f8 r21 : 000000000000004d r22 : a00000010132fa68
        r23 : 00000000000000ed r24 : 0000000000000000 r25 : 0000000000000000
        r26 : 0000000000000001 r27 : a0000001012b8500 r28 : a00000010135f4a0
        r29 : 0000000000000000 r30 : 0000000000000000 r31 : 0000000000000001
        Unable to handle kernel NULL pointer dereference (address
        0000000000000018)
        swapper[0]: Oops 11003706212352 [2]
        Modules linked in:
      
        Pid: 0, CPU 0, comm:              swapper
        psr : 0000121008022018 ifs : 800000000000cc18 ip  :
        [<a0000001004dc8f1>]    Not tainted (3.6.0-rc4-zx1-smp-next-20120906)
        ip is at __copy_user+0x891/0x960
        unat: 0000000000000000 pfs : 0000000000000813 rsc : 0000000000000003
        rnat: 0000000000000000 bsps: 0000000000000000 pr  : 9666960159961765
        ldrs: 0000000000000000 ccv : 0000000000000000 fpsr: 0009804c0270033f
        csd : 0000000000000000 ssd : 0000000000000000
        b0  : a00000010004b550 b6  : a00000010004b740 b7  : a00000010000c750
        f6  : 000000000000000000000 f7  : 1003e9e3779b97f4a7c16
        f8  : 1003e0a00000010001550 f9  : 100068800000000000000
        f10 : 10005f0f0f0f0e54f0000 f11 : 1003e0000000000000078
        r1  : a00000010155eef0 r2  : a0000001012870b0 r3  : a0000001012870b8
        r8  : 0000000000000298 r9  : 0000000000000013 r10 : 0000000000000000
        r11 : 9666960159961a65 r12 : a000000101287010 r13 : a000000101280000
        r14 : a000000101287068 r15 : a000000101287080 r16 : 0000000000000298
        r17 : 0000000000000010 r18 : 0000000000000018 r19 : a000000101287310
        r20 : 0000000000000290 r21 : 0000000000000000 r22 : 0000000000000000
        r23 : a000000101386f58 r24 : 0000000000000000 r25 : 000000007fffffff
        r26 : a000000101287078 r27 : a0000001013c69b0 r28 : 0000000000000000
        r29 : 0000000000000014 r30 : 0000000000000000 r31 : 0000000000000813
      
      Sedat Dilek and Hugh Dickins reported similar problems as well.
      
      Earlier patches in the common set moved the zeroing of the kmem_cache
      structure into common code. See "Move allocation of kmem_cache into
      common code".
      
      The allocation for the two special structures is still done from SLUB
      specific code but no zeroing is done since the cache creation functions
      used to zero. This now needs to be updated so that the structures are
      zeroed during allocation in kmem_cache_init().  Otherwise random pointer
      values may be followed.
      Reported-by: NTony Luck <tony.luck@intel.com>
      Reported-by: NSedat Dilek <sedat.dilek@gmail.com>
      Tested-by: NSedat Dilek <sedat.dilek@gmail.com>
      Reported-by: NHugh Dickins <hughd@google.com>
      Tested-by: NSedat Dilek <sedat.dilek@gmail.com>
      Signed-off-by: NChristoph Lameter <cl@linux.com>
      Signed-off-by: NPekka Enberg <penberg@kernel.org>
      9df53b15
  12. 05 9月, 2012 14 次提交
  13. 16 8月, 2012 3 次提交
  14. 01 8月, 2012 1 次提交
    • C
      mm: slub: optimise the SLUB fast path to avoid pfmemalloc checks · 5091b74a
      Christoph Lameter 提交于
      This patch removes the check for pfmemalloc from the alloc hotpath and
      puts the logic after the election of a new per cpu slab.  For a pfmemalloc
      page we do not use the fast path but force the use of the slow path which
      is also used for the debug case.
      
      This has the side-effect of weakening pfmemalloc processing in the
      following way;
      
      1. A process that is allocating for network swap calls __slab_alloc.
         pfmemalloc_match is true so the freelist is loaded and c->freelist is
         now pointing to a pfmemalloc page.
      
      2. A process that is attempting normal allocations calls slab_alloc,
         finds the pfmemalloc page on the freelist and uses it because it did
         not check pfmemalloc_match()
      
      The patch allows non-pfmemalloc allocations to use pfmemalloc pages with
      the kmalloc slabs being the most vunerable caches on the grounds they
      are most likely to have a mix of pfmemalloc and !pfmemalloc requests. A
      later patch will still protect the system as processes will get throttled
      if the pfmemalloc reserves get depleted but performance will not degrade
      as smoothly.
      
      [mgorman@suse.de: Expanded changelog]
      Signed-off-by: NChristoph Lameter <cl@linux.com>
      Signed-off-by: NMel Gorman <mgorman@suse.de>
      Cc: David Miller <davem@davemloft.net>
      Cc: Neil Brown <neilb@suse.de>
      Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
      Cc: Mike Christie <michaelc@cs.wisc.edu>
      Cc: Eric B Munson <emunson@mgebm.net>
      Cc: Eric Dumazet <eric.dumazet@gmail.com>
      Cc: Sebastian Andrzej Siewior <sebastian@breakpoint.cc>
      Cc: Mel Gorman <mgorman@suse.de>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      5091b74a