Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp5962330imm; Tue, 26 Jun 2018 23:07:20 -0700 (PDT) X-Google-Smtp-Source: AAOMgpd6BKKdgMzyXbxHWZKkNdwvR+flj7wUbBWTnqF3Xi9HeVfymYvSHGApxJnXucLMbYnkOSpF X-Received: by 2002:a62:3848:: with SMTP id f69-v6mr528412pfa.10.1530079640666; Tue, 26 Jun 2018 23:07:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530079640; cv=none; d=google.com; s=arc-20160816; b=lIulzQwXNnqz7sHOrPOl9GEBi2vA0DwkkaYkDzXx+YD1tYh8Y43cvPG3shiPbPHUoX YpSfn0FdV6iHh7I0BbSSxb50f2ScWjjmOL07RHqKkq37qg7D3ovGLtiUr4BUnPLmplXF QXOtVDkBk2/HC0Mv1m1pfYfosv+a+a7gGtuveiSsOEEok8627cl3hDrQ4mt/yYe0VQmb 9b26mxuw/vHrYSKmtSbaFP9hv4GdAO4Y8pZvG5RTFr7DVWb6MfYT1lBVm1h6X2EAtqZG hslFGHSNVlcWvBuKlPfDuM+n4/vFpNCpVQoxjQLcJCZE9pUz42lAAMvYKVnRTmztcQO+ ckBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=3ps+gAwVXdy5arvYGiUVzRS5jQtBXjkjTtbqkRwO+pY=; b=shWV68wNA40eAsN1dTQP7JpZD4TO9EvL0+XbE+/IuB9mfN+nqeUO9IxiYG9eOaljen WtTMXypCwoolE4jzJha8uZWS1n4X/+SVf9y89vm4N+NN++mK5zZ8nTF7/6IhB4OJu118 iKZ1u1GGKoZPGRtE04pV5GVD74sStGyNiUZjt/BPNjFRNfEXmFqHmB1YGJbbnWCuW/Lr LW9PDFjYfmAy98xcxjmJZXD9hniJL/BH+HkYlvoeDDQh8yC0KTRtKVZFzMT532V5J/z8 Is2Q4P1kLZX41pzolotaUJjdaToyjhwLDBeoV2lAZo4g9IEyFYo+Izfl8S4jv/bDtTGa InQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ik1pqeN4; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y123-v6si3053699pfc.302.2018.06.26.23.07.05; Tue, 26 Jun 2018 23:07:20 -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=pass header.i=@gmail.com header.s=20161025 header.b=ik1pqeN4; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752883AbeF0FvD (ORCPT + 99 others); Wed, 27 Jun 2018 01:51:03 -0400 Received: from mail-yw0-f193.google.com ([209.85.161.193]:33873 "EHLO mail-yw0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750942AbeF0FvB (ORCPT ); Wed, 27 Jun 2018 01:51:01 -0400 Received: by mail-yw0-f193.google.com with SMTP id n187-v6so290787ywd.1; Tue, 26 Jun 2018 22:51:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=3ps+gAwVXdy5arvYGiUVzRS5jQtBXjkjTtbqkRwO+pY=; b=ik1pqeN4HmLDtEM0WCXzJYAWEinZTCSPmfiLRPFWHRZ22upQKlUTmTyeDt0DFH8+ZR hv7KWMaGy+Eb6DKp4qAAdJBAK6JiMpumaqg6nPYLY0xYj2+Gf83UpxhqLg9yF8RVWx8E qgB1y53ye0VMbBBjtIyavMisdZJc3hAZF4BR/JibliY9uUZwqEHNXXxuNibix1c29Sy6 aHnmK6lZGmmqvgdazswRDDt0mnqyT1iXXAzV/V10ybhafZlr/QbL6VRF+B+O++cEEmD7 v7TqqAPBmaWekddA8li1ZyEJkdbtYsgc10tJBeWyx491jvMbrgDLGotKYvQpfigdhHL7 eWAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=3ps+gAwVXdy5arvYGiUVzRS5jQtBXjkjTtbqkRwO+pY=; b=Xpbrrf6APdZsgqKgyWwk9fv9eFoQKPEj8Mnhpec9qPo8zWeKt0ZdNw/5TFsbmmAZaT SN16heq/e8xz4mtluQ9c9qEi4h0FPXWvpW00nWyH8psOenv6yS771bXHOx0ppC++Ifae iGqiUdRHZ6bZ0fkWBUxbiUYSbmMGbqZ18swOlJoLsFsR2yRd1BbSt0o4keLVqcnb2xk2 obScZC2ZOXjPrfrap1tCn2HsBGNa5AC19mjR2NohFku30gG56XwLrzAHxcC3WAvGyXnd fYmNxAcknx2xmYVKvjl6QDNRLHFU/pf4Dszuu3iNJbnJFX61NlrcYGewnkbkuRmDdCyC xFVQ== X-Gm-Message-State: APt69E1m/ykIe/6ZT0rXV/OT0Xsz/8qXL7T3tU2VVZKNtdJbF8LLNdaj EPr1aOwOVs3iH3u+rsbKP7stJB/VKI9VtDmbCb0= X-Received: by 2002:a0d:d84c:: with SMTP id a73-v6mr2130018ywe.379.1530078660475; Tue, 26 Jun 2018 22:51:00 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a81:1b04:0:0:0:0:0 with HTTP; Tue, 26 Jun 2018 22:50:59 -0700 (PDT) In-Reply-To: References: <20180625230659.139822-1-shakeelb@google.com> <20180625230659.139822-2-shakeelb@google.com> <20180626190619.GB3958@cmpxchg.org> From: Amir Goldstein Date: Wed, 27 Jun 2018 08:50:59 +0300 Message-ID: Subject: Re: [PATCH 1/2] fs: fsnotify: account fsnotify metadata to kmemcg To: Shakeel Butt Cc: Johannes Weiner , Andrew Morton , Michal Hocko , Vladimir Davydov , Jan Kara , Greg Thelen , Roman Gushchin , Alexander Viro , LKML , Cgroups , linux-fsdevel , Linux MM , Jan Kara Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jun 26, 2018 at 11:05 PM, Shakeel Butt wrote: > On Tue, Jun 26, 2018 at 12:03 PM Johannes Weiner wrote: >> >> 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) >> > > group->memcg is only NULL when memcg is disabled (i.e. > get_mem_cgroup_from_mm() returns root_mem_cgroup for offlined > mm->memcg). Though group->memcg can point to an offlined memcg. > > If I understand you correctly this is what we want: > > 1. If group->memcg is NULL then __GFP_ACCOUNT is a noop i.e. memcg is disabled. > 2. If group->memcg is root_mem_cgroup, then __GFP_ACCOUNT again is a > kind of noop (charges to root_mem_cgroups are bypassed). > 3. If group->memcg is offlined memcg, then make __GFP_ACCOUNT noop by > returning root_mem_cgroup from get_mem_cgroup_from_current(). > 4. Else charge group->memcg. > > This seems reasonable. After your Ack and Amir's or Jan's answer to > the nesting query, I will resend the next version of this patch > series. > > In future if we find any use-cases of memalloc_use_memcg nesting then > we can make it work for nesting. > For the fsnotify use case memalloc_use_memcg() certainly doesn't need to nest, but I wonder, if that facility becomes popular among different subsystems, how exactly do you intend to monitor that it doesn't grow nested use cases? I would suggest that you at least leave a WARN_ON_ONCE if memalloc_use_memcg() is called and active_memcg is already set. Thanks, Amir.