From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.6 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B7D2AC433DF for ; Tue, 23 Jun 2020 05:19:40 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7C52620738 for ; Tue, 23 Jun 2020 05:19:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="jCOr62ye" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7C52620738 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 01B176B0002; Tue, 23 Jun 2020 01:19:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F0CED6B0005; Tue, 23 Jun 2020 01:19:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DFAF76B0006; Tue, 23 Jun 2020 01:19:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id C58546B0002 for ; Tue, 23 Jun 2020 01:19:39 -0400 (EDT) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 4619A180AD82F for ; Tue, 23 Jun 2020 05:19:39 +0000 (UTC) X-FDA: 76959324078.21.judge08_5d12a4326e38 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin21.hostedemail.com (Postfix) with ESMTP id 1FD0E180442C3 for ; Tue, 23 Jun 2020 05:19:39 +0000 (UTC) X-HE-Tag: judge08_5d12a4326e38 X-Filterd-Recvd-Size: 4866 Received: from mail-lj1-f193.google.com (mail-lj1-f193.google.com [209.85.208.193]) by imf41.hostedemail.com (Postfix) with ESMTP for ; Tue, 23 Jun 2020 05:19:38 +0000 (UTC) Received: by mail-lj1-f193.google.com with SMTP id n23so21884182ljh.7 for ; Mon, 22 Jun 2020 22:19:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=m95VDq7vD4nelWbzJkHtAeoIzyCCp23MjAnbmWTbSGI=; b=jCOr62yeRNUdZ0UVcLguc83CENqg9FEukBdY4YKk7gENM0KS/aQL2ekCpjUfPukcvU 2ZhXXypuEta5EKExrLrI5UPED8tKfhpCfY9Px1ciIETwh1wwlDN3Fs20svNTJEafG1NX L/IFKJ5si8iCl0lWMqWORyQqKM+fG2lz4ZxLrhfDhT3u9t4siE2c/oPP5tUWEohgZW5X 3TAtzzpivXsuKhIe4+Cp8p/maHMYnYYmjeRHi1NO0GwN7csyHWEJ/+waHgqcpIOusTIQ ykP9zoJcveK5EIiNIgfCqKlRhKAO31K8xJ20LK/O53HnmWn7yXS4SNvGVYRArqyjwSj8 S4DQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=m95VDq7vD4nelWbzJkHtAeoIzyCCp23MjAnbmWTbSGI=; b=Q0u0Yfzk+0whXMCyHynlEk1X1j4zwS0vjs+2KA8UXCpNPPIiJtdhbshoTZG0g/Rjsg 6QlXjFeA4jOvoN10Q7cMwZP8NvXahCrk62cjcWrSGMoG0UWqVpI64wtdNJ6cFsxar3+I PUhpKYhX9td2Gqr/PZTRSsNZMTjOkfuL19v4wZnoezlrAACHF8CAgJkHc1Qx6jqsoGA7 IiTY6MErJ/Gi5VWXC5JoqOXjhe4xochqxgHuEi9t/JMWO9LtvDupeJMef8Eytc98Z0Aw CXzJyST2EWkRGqT8oqCmZH80bUADc+WcvDjhyopAI/iO7f4x9SXQVjezxwRN2XOWaI8S Uz8w== X-Gm-Message-State: AOAM530sBHVnhgMhHCeG7sHXLfud51VXN5gvAzFGZ+iNroL89xi/YH3w GGXKP48GilkKo2bDKOWgOvSGV0nf1I7mA0n/v7Z8gQ== X-Google-Smtp-Source: ABdhPJzsReRxsBHVAFItMED09vw0+nP/ywSpWw3LzwYR129pYpbFLacCRwCH5/8rkhVYcZiWOll0wQ3YHigfKeW5UHk= X-Received: by 2002:a2e:8754:: with SMTP id q20mr10480767ljj.270.1592889576802; Mon, 22 Jun 2020 22:19:36 -0700 (PDT) MIME-Version: 1.0 References: <20200623015846.1141975-1-guro@fb.com> <20200623015846.1141975-10-guro@fb.com> In-Reply-To: <20200623015846.1141975-10-guro@fb.com> From: Shakeel Butt Date: Mon, 22 Jun 2020 22:19:25 -0700 Message-ID: Subject: Re: [PATCH v7 09/19] mm: memcg/slab: charge individual slab objects instead of pages To: Roman Gushchin Cc: Andrew Morton , Christoph Lameter , Johannes Weiner , Michal Hocko , Linux MM , Vlastimil Babka , Kernel Team , LKML Content-Type: text/plain; charset="UTF-8" X-Rspamd-Queue-Id: 1FD0E180442C3 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Mon, Jun 22, 2020 at 6:58 PM Roman Gushchin wrote: > > Switch to per-object accounting of non-root slab objects. > > Charging is performed using obj_cgroup API in the pre_alloc hook. > Obj_cgroup is charged with the size of the object and the size of > metadata: as now it's the size of an obj_cgroup pointer. If the amount of > memory has been charged successfully, the actual allocation code is > executed. Otherwise, -ENOMEM is returned. > > In the post_alloc hook if the actual allocation succeeded, corresponding > vmstats are bumped and the obj_cgroup pointer is saved. Otherwise, the > charge is canceled. > > On the free path obj_cgroup pointer is obtained and used to uncharge the > size of the releasing object. > > Memcg and lruvec counters are now representing only memory used by active > slab objects and do not include the free space. The free space is shared > and doesn't belong to any specific cgroup. > > Global per-node slab vmstats are still modified from > (un)charge_slab_page() functions. The idea is to keep all slab pages > accounted as slab pages on system level. > > Signed-off-by: Roman Gushchin > Reviewed-by: Vlastimil Babka > --- [snip] > +static inline struct kmem_cache *memcg_slab_pre_alloc_hook(struct kmem_cache *s, > + struct obj_cgroup **objcgp, > + size_t objects, gfp_t flags) > +{ > + struct kmem_cache *cachep; > + > + cachep = memcg_kmem_get_cache(s, objcgp); > + if (is_root_cache(cachep)) > + return s; > + > + if (obj_cgroup_charge(*objcgp, flags, objects * obj_full_size(s))) { > + memcg_kmem_put_cache(cachep); I think you forgot to put obj_cgroup_put(*objcgp) here again. > + cachep = NULL; > + } > + > + return cachep; > +} > + After the above fix: Reviewed-by: Shakeel Butt