Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp5500391imm; Tue, 26 Jun 2018 12:22:29 -0700 (PDT) X-Google-Smtp-Source: AAOMgpe8R84n4R6cz4BmO8ZvTIKj2hQ1rhha0uBiGlqN7r6NU0GfMqdtbhezF4UYioC9rgFQ3qpe X-Received: by 2002:a62:b612:: with SMTP id j18-v6mr2786006pff.199.1530040949480; Tue, 26 Jun 2018 12:22:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530040949; cv=none; d=google.com; s=arc-20160816; b=osWb4JL1tNQCSns+AqBr9jkruFcgB3GZVZY5qnYK4SQmuJqw3VnrpS3oKWHjhjV7PC ziqe+Q5bRPikdYR3z782kBy7EhsYWIgsFsv23leHXvWaVo9F8C5Dybjm3vQdAOkN1PBH Hiq/mzfHYoduTiccXzDBjvRmHYRcFDJM+e/W81Vno+o8NKJt6uaA5CJytHRFV6qSTFEX K7Iwd0aV8DS6ufsTP5e/iCg0Z2sLrpPXnuk2oq8gDE/PXUpZmwzyGKlM79SobsUuYCv4 zk+cdzoPoWlduNj7V1afngGBkDPCdYg+F59WEl4eTK3OggHzqqxS33tYGV3IpM4k3I+w WAew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=PPSeppZvMDg0ZRlfiMVRQ2Q8cq4oVs68U1a3OI3sANE=; b=TqWyQNG145Ecpz+2Kf9WLKLyEkDftB53qpk8Fouy0SEYFAvKSIQOm7EsGv9n1uYbrA UINuCIk9fokJR2nEVIqOIZh9eJ3Z0adbQGxmmRiOoxyrEXyHm2TnlPh1GksgVm2Pr4ok ws6Cv55KCNIpKGCiCtEGUQJq0/zQru5YbS93H2MAre0O7NuVxj424e4aTaHKTsMAU73+ isto79NIOrwxjAo8o6ZRJMlO+Mh4IGy5lBQV69mZQrOfHIlrwbRW3/qPVFraXryPJVgn iUTJ7Us9EDuEowvpglfhBVU/zuj8ngGVkAEi7UITWdKbh/Yi4C3smiHRXuJEjVne+a9V Sgvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@cmpxchg.org header.s=x header.b=K88mHbGO; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a8-v6si1802766pgu.544.2018.06.26.12.22.15; Tue, 26 Jun 2018 12:22:29 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@cmpxchg.org header.s=x header.b=K88mHbGO; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934000AbeFZTD7 (ORCPT + 99 others); Tue, 26 Jun 2018 15:03:59 -0400 Received: from gum.cmpxchg.org ([85.214.110.215]:49364 "EHLO gum.cmpxchg.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751117AbeFZTD5 (ORCPT ); Tue, 26 Jun 2018 15:03:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=cmpxchg.org ; s=x; h=In-Reply-To:Content-Type:MIME-Version:References:Message-ID:Subject: Cc:To:From:Date:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=PPSeppZvMDg0ZRlfiMVRQ2Q8cq4oVs68U1a3OI3sANE=; b=K88mHbGO7lZfegACplZZG3hCNQ gR5UhoWoFMaMwoIA/9CSHxMsCQlHoPqu/ozBNvGpFlIew+2CcPwTNyUmzx7o1mc64biC3puhqrQIT Y+Os1fDPpsxysmuGO77YOtDQ37TkN06Mh+7wV5Q8p4hd5YN791wAiP89PIZpSsYejzlg=; Date: Tue, 26 Jun 2018 15:06:19 -0400 From: Johannes Weiner To: Shakeel Butt Cc: Andrew Morton , Michal Hocko , Vladimir Davydov , Jan Kara , Greg Thelen , Amir Goldstein , Roman Gushchin , Alexander Viro , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, Jan Kara Subject: Re: [PATCH 1/2] fs: fsnotify: account fsnotify metadata to kmemcg Message-ID: <20180626190619.GB3958@cmpxchg.org> References: <20180625230659.139822-1-shakeelb@google.com> <20180625230659.139822-2-shakeelb@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180625230659.139822-2-shakeelb@google.com> User-Agent: Mutt/1.10.0 (2018-05-17) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jun 25, 2018 at 04:06:58PM -0700, Shakeel Butt wrote: > @@ -140,8 +141,9 @@ struct fanotify_event_info *fanotify_alloc_event(struct fsnotify_group *group, > struct inode *inode, u32 mask, > const struct path *path) > { > - struct fanotify_event_info *event; > + struct fanotify_event_info *event = NULL; > gfp_t gfp = GFP_KERNEL; > + struct mem_cgroup *old_memcg = NULL; > > /* > * For queues with unlimited length lost events are not expected and > @@ -151,19 +153,25 @@ struct fanotify_event_info *fanotify_alloc_event(struct fsnotify_group *group, > if (group->max_events == UINT_MAX) > gfp |= __GFP_NOFAIL; > > + /* Whoever is interested in the event, pays for the allocation. */ > + if (group->memcg) { > + gfp |= __GFP_ACCOUNT; > + old_memcg = memalloc_use_memcg(group->memcg); > + } group->memcg is only NULL when memcg is disabled or there is some offlining race. Can you make memalloc_use_memcg(NULL) mean that it should charge root_mem_cgroup instead of current->mm->memcg? That way we can make this site unconditional while retaining the behavior: gfp_t gfp = GFP_KERNEL | __GFP_ACCOUNT; memalloc_use_memcg(group->memcg); kmem_cache_alloc(..., gfp); out: memalloc_unuse_memcg(); (dropping old_memcg and the unuse parameter as per the other mail) > if (fanotify_is_perm_event(mask)) { > struct fanotify_perm_event_info *pevent; > > pevent = kmem_cache_alloc(fanotify_perm_event_cachep, gfp); > if (!pevent) > - return NULL; > + goto out; > event = &pevent->fae; > pevent->response = 0; > goto init; > } > event = kmem_cache_alloc(fanotify_event_cachep, gfp); > if (!event) > - return NULL; > + goto out; > init: __maybe_unused > fsnotify_init_event(&event->fse, inode, mask); > event->tgid = get_pid(task_tgid(current)); > @@ -174,6 +182,9 @@ init: __maybe_unused > event->path.mnt = NULL; > event->path.dentry = NULL; > } > +out: > + if (group->memcg) > + memalloc_unuse_memcg(old_memcg); > return event; > } Thanks, Johannes