From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: MIME-Version: 1.0 In-Reply-To: <20180416205150.113915-2-shakeelb@google.com> References: <20180416205150.113915-1-shakeelb@google.com> <20180416205150.113915-2-shakeelb@google.com> From: Shakeel Butt Date: Tue, 5 Jun 2018 10:54:18 -0700 Message-ID: Subject: Re: [PATCH v5 1/2] mm: memcg: remote memcg charging for kmem allocations To: Michal Hocko , Jan Kara , Amir Goldstein , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Greg Thelen , Johannes Weiner , Vladimir Davydov , Mel Gorman , Vlastimil Babka Cc: linux-fsdevel , Linux MM , Cgroups , LKML , Shakeel Butt Content-Type: text/plain; charset="UTF-8" Sender: owner-linux-mm@kvack.org List-ID: On Mon, Apr 16, 2018 at 1:51 PM, Shakeel Butt wrote: > Introduce the memcg variant for kmalloc[_node] and > kmem_cache_alloc[_node]. For kmem_cache_alloc, the kernel switches the > root kmem cache with the memcg specific kmem cache for __GFP_ACCOUNT > allocations to charge those allocations to the memcg. However, the memcg > to charge is extracted from the current task_struct. This patch > introduces the variant of kmem cache allocation functions where the memcg > can be provided explicitly by the caller instead of deducing the memcg > from the current task. > > The kmalloc allocations are underlying served using the kmem caches unless > the size of the allocation request is larger than KMALLOC_MAX_CACHE_SIZE, > in which case, the kmem caches are bypassed and the request is routed > directly to page allocator. So, for __GFP_ACCOUNT kmalloc allocations, > the memcg of current task is charged. This patch introduces memcg variant > of kmalloc functions to allow callers to provide memcg for charging. > > These functions are useful for use-cases where the allocations should be > charged to the memcg different from the memcg of the caller. One such > concrete use-case is the allocations for fsnotify event objects where the > objects should be charged to the listener instead of the producer. > > One requirement to call these functions is that the caller must have the > reference to the memcg. Using kmalloc_memcg and kmem_cache_alloc_memcg > implicitly assumes that the caller is requesting a __GFP_ACCOUNT > allocation. > > Signed-off-by: Shakeel Butt I will send the v6 of this patchset after this merge window. In v6, I will make memalloc_memcg_[save|restore] scope API similar to NOFS, NOIO and NORECLAIM APIs. > --- > Changelog since v4: > - Removed branch from hot path of memory charging. > > Changelog since v3: > - Added node variant of directed kmem allocation functions. > > Changelog since v2: > - Merge the kmalloc_memcg patch into this patch. > - Instead of plumbing memcg throughout, use field in task_struct to pass > the target_memcg. > > Changelog since v1: > - Fixed build for SLOB >