Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp6790575imm; Wed, 27 Jun 2018 13:29:09 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeEiDsELIaAsRgKV8mh1b/woGeNVWdNEKkZVhQYbPDwB7l1o5JVyRVx+mPkW6jw1K38TAJF X-Received: by 2002:a62:df52:: with SMTP id u79-v6mr7267782pfg.164.1530131349897; Wed, 27 Jun 2018 13:29:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530131349; cv=none; d=google.com; s=arc-20160816; b=pfH+MjiAqp1hM0ImlIWUb/uBePszneRgaoKIIwWlLZREXXAjwu9WbSC6TfK7PSu+mv TYV03rE2082u2nQdDgX0pVoYaS56y27nrWQVW9QDFBk8cpXxVMgUVs3oq/6OQ+qKVFMn BdhiLt4qELiWKF0iuQx6HFQHoqlVmBYjptJzw91rwX6f1pzkFyf/ajRc3gFNQVC2AhAd cjdqCakk3Z0Ca8BOCcbxcPIVPTOXmXycBqDgf/0DkEvaXsntoSn/GSJu494r2MYjOAEt kDtjKGt1s/AwLP6cdVvNUb/On1N0l1WfJIZb1L1///mqpC5F77GAeweBlzNhx7z9YWns kmhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=TlrWWiQPCjtC68tVmQ7b4F+X4V3UVnh2azcLgqQiihM=; b=Yj53zcioUNJ1AEuALSsK9B4A/bW8CqvzOerAxfGmULmVzADTR1tpefDvShuCtbKyrH kFY575NF22YKCHtCLVUEXrH8cunKRK98eZUCc3dAhnwIBrwaNEynp+SzX3pD2VAiBEpX GzVPs8E1n+d5MGeclg1UtZUhTo1tgPx6PBDmMYr9hnR8x3iR6NswPmMP7POZDsRBcwIf yCOpTLv4MkYSkyA7R8YPMhjoyVfPC2YP2k6LEZiEcpxTBN88VpD+Mmin48yYRzyyD8wf +2NV9hiUVjHBHIE6J8dvi46lHP5RpnQ3IaCStEeW3i0XHMVxVxetZtewJL3iMM1C4gPw e5mw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="Bq/hMMEG"; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t8-v6si20524ply.139.2018.06.27.13.28.56; Wed, 27 Jun 2018 13:29:09 -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=@google.com header.s=20161025 header.b="Bq/hMMEG"; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966390AbeF0TNC (ORCPT + 99 others); Wed, 27 Jun 2018 15:13:02 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:37500 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965421AbeF0TM7 (ORCPT ); Wed, 27 Jun 2018 15:12:59 -0400 Received: by mail-pf0-f195.google.com with SMTP id y5-v6so1409319pfn.4 for ; Wed, 27 Jun 2018 12:12:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=TlrWWiQPCjtC68tVmQ7b4F+X4V3UVnh2azcLgqQiihM=; b=Bq/hMMEGB/x9xox1vKQmpA8TnWjUQ3cVxD760QU68bDDWQAVR6wgBN6aHeWoKQDwWf x3SiCzX21Hc7O5Po2zJoBeYAKx37/PB356xhoZrI+XW+nlrTfa/oSjmijvqwXuFbdM7p UU8MCvzxc55L1dlVyLFs81xckxYX0Kzr1iV9OVRNvhez1xceNcKKjNIPs5Dv3potbtfl yzvtwCvHZxxtgm0zqmLOVbBKcl9sm5LUe0UqATfRjGeh5E3FwJk/bVq1rVU9sJ1Q/WOD 735uIGBvJkJA7woiZS0AVa+A0UXnWp+9RPEA9CyrVEIkAjhrk5LsJrUHA9X0pzN+/WMI 3a8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=TlrWWiQPCjtC68tVmQ7b4F+X4V3UVnh2azcLgqQiihM=; b=c+tlHXkUrOz4PpyFkDalZS1xM5bCQvzaPtk4l7K0M0CoOjI0ZZOnhqEdLMD1h0BGjZ Y9sX5SuQwTeXXPl7Ad/7kW9t1/JgRI0zbwZ28QtH8B0tgbMXCGIQ4p+NQRakusHw/jdl tuRDbEHiUSqamGgGg+XH8MJSYifUmPiFHzyX2FxYsijritikuDrfY5FJVdExfefXDJ65 hSTzleixMldl8Uh7/HhQ5F16R+D0MPzRKJarIidzeNtw93jCZS9rnqsvSkeJ9xyZ3Rsd t39aD0PZ+LyRj5CfUjLVRqplkm8nT2RkUtW09rFJSkWUQaaYDn/olsk/t1w5lK9TEPvw LCRA== X-Gm-Message-State: APt69E0sX87+UzvvfiwmeaHW0FyJnGPnWAibYvpl4oV7hiBnOJEgVHcx vIADE/EO3x9H061SmX1OHNpvpA== X-Received: by 2002:a62:9c9c:: with SMTP id u28-v6mr7201380pfk.90.1530126778531; Wed, 27 Jun 2018 12:12:58 -0700 (PDT) Received: from shakeelb.mtv.corp.google.com ([2620:15c:2cb:201:3a5f:3a4f:fa44:6b63]) by smtp.gmail.com with ESMTPSA id l6-v6sm8733667pfc.172.2018.06.27.12.12.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 27 Jun 2018 12:12:57 -0700 (PDT) From: Shakeel Butt To: Andrew Morton Cc: Michal Hocko , Johannes Weiner , 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, Shakeel Butt Subject: [PATCH v8 0/2] Directed kmem charging Date: Wed, 27 Jun 2018 12:12:48 -0700 Message-Id: <20180627191250.209150-1-shakeelb@google.com> X-Mailer: git-send-email 2.18.0.rc2.346.g013aa6912e-goog Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The Linux kernel's memory cgroup allows limiting the memory usage of the jobs running on the system to provide isolation between the jobs. All the kernel memory allocated in the context of the job and marked with __GFP_ACCOUNT will also be included in the memory usage and be limited by the job's limit. The kernel memory can only be charged to the memcg of the process in whose context kernel memory was allocated. However there are cases where the allocated kernel memory should be charged to the memcg different from the current processes's memcg. This patch series contains two such concrete use-cases i.e. fsnotify and buffer_head. The fsnotify event objects can consume a lot of system memory for large or unlimited queues if there is either no or slow listener. The events are allocated in the context of the event producer. However they should be charged to the event consumer. Similarly the buffer_head objects can be allocated in a memcg different from the memcg of the page for which buffer_head objects are being allocated. To solve this issue, this patch series introduces mechanism to charge kernel memory to a given memcg. In case of fsnotify events, the memcg of the consumer can be used for charging and for buffer_head, the memcg of the page can be charged. For directed charging, the caller can use the scope API memalloc_[un]use_memcg() to specify the memcg to charge for all the __GFP_ACCOUNT allocations within the scope. Shakeel Butt (2): fs: fsnotify: account fsnotify metadata to kmemcg fs, mm: account buffer_head to kmemcg fs/buffer.c | 15 ++++++- fs/notify/dnotify/dnotify.c | 5 ++- fs/notify/fanotify/fanotify.c | 17 ++++++-- fs/notify/fanotify/fanotify_user.c | 5 ++- fs/notify/group.c | 4 ++ fs/notify/inotify/inotify_fsnotify.c | 15 ++++++- fs/notify/inotify/inotify_user.c | 5 ++- include/linux/fsnotify_backend.h | 12 ++++-- include/linux/memcontrol.h | 14 +++++++ include/linux/sched.h | 3 ++ include/linux/sched/mm.h | 41 +++++++++++++++++++ kernel/fork.c | 3 ++ mm/memcontrol.c | 60 ++++++++++++++++++++++++++-- 13 files changed, 182 insertions(+), 17 deletions(-) -- 2.18.0.rc2.346.g013aa6912e-goog