Received: by 2002:a25:2c96:0:0:0:0:0 with SMTP id s144csp1359792ybs; Mon, 25 May 2020 14:03:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz8Rj1iIn6o3i6Y3q9/hlY5YIGkU2k71J8NfBGGlMUOrAVJYSysmftexY8vgG9UhA4m//0z X-Received: by 2002:a17:907:217b:: with SMTP id rl27mr21181717ejb.291.1590440622939; Mon, 25 May 2020 14:03:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590440622; cv=none; d=google.com; s=arc-20160816; b=zqDUXzMI5KkXMA7WHltx8peVzzzOCPmXeOMKn2x77gJ+kOfvXjsGYkrSkgaqXRupQY qrRTgAS0fZNaaith5DBoc65JGyWoTuzGhauJGk/6jHggUuGTt8fWYEkBrhfhCE2UZQWo dsqcmEJeoyK6BxrDJXoF/6znECntnC9+7ku+RDM4+aVLgCQsF/Is5ujto7GVS3TFFmrk kkKdjVAlxXqY6bYGZ6KnrJn6vZzQFPgU+vVOsTxxDyq37a0w3GMrLuXhrd+K3gQrW2kg xqsmt7oJiF9SW8o1wT6vbmgCZ5ZhNDIyK2Sf6vFoEyAHmwrdBhvY1iOTiFroG7Ubjb9i GurQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=upbXuPBa/T/xbcUMnocTuegmsX48PAiU/2WmQycoi2E=; b=bDZW8s0sCsz6fWsx0j2SgJEPCguit8giTOSQKxrrbb8wvrcExC4TWsE1ZaWv7qkK4+ JXkn3kByLO3VczoBsrkeoalbhmKbayouJgInisbWEIL6utGwfYwnL6+N9fQ4Wx4LKCTZ IiXgn1zJGIUAzzzaGzZSi2sD+Bvk0ZyItlBk3zNklnTFsQBqh02KAi9xmzZwOwqevRIV 3ZOhsA1qB5asut/9Z1HvNYmZx4+SGHitE0w5114evRJrpbQsJx1ijiLH68a0LsTMDgNh o4zJo8nIfzoP4OQ2K4RTdyi1EebXK/KLvaBXudQ1nDJ8BA4Qa5Wb3o9KnpFViRGk6iRm j6Aw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bo18si9722092edb.450.2020.05.25.14.03.19; Mon, 25 May 2020 14:03:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391207AbgEYQK7 (ORCPT + 99 others); Mon, 25 May 2020 12:10:59 -0400 Received: from mx2.suse.de ([195.135.220.15]:53166 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388556AbgEYQK6 (ORCPT ); Mon, 25 May 2020 12:10:58 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id D9A41AEC9; Mon, 25 May 2020 16:10:58 +0000 (UTC) Subject: Re: [PATCH v3 09/19] mm: memcg/slab: charge individual slab objects instead of pages To: Roman Gushchin , Andrew Morton Cc: Johannes Weiner , Michal Hocko , linux-mm@kvack.org, kernel-team@fb.com, linux-kernel@vger.kernel.org References: <20200422204708.2176080-1-guro@fb.com> <20200422204708.2176080-10-guro@fb.com> From: Vlastimil Babka Message-ID: <75328f78-117b-5042-f42e-5ef01dd93086@suse.cz> Date: Mon, 25 May 2020 18:10:55 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 MIME-Version: 1.0 In-Reply-To: <20200422204708.2176080-10-guro@fb.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 4/22/20 10:46 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 Suggestion below: > @@ -568,32 +548,33 @@ static __always_inline int charge_slab_page(struct page *page, > gfp_t gfp, int order, > struct kmem_cache *s) > { > - int ret; > - > - if (is_root_cache(s)) { > - mod_node_page_state(page_pgdat(page), cache_vmstat_idx(s), > - PAGE_SIZE << order); > - return 0; > - } > +#ifdef CONFIG_MEMCG_KMEM > + if (!is_root_cache(s)) { This could also benefit from memcg_kmem_enabled() static key test AFAICS. Maybe even have a wrapper for both tests together? > + int ret; > > - ret = memcg_alloc_page_obj_cgroups(page, gfp, objs_per_slab(s)); > - if (ret) > - return ret; > + ret = memcg_alloc_page_obj_cgroups(page, gfp, objs_per_slab(s)); You created memcg_alloc_page_obj_cgroups() empty variant for !CONFIG_MEMCG_KMEM but now the only caller is under CONFIG_MEMCG_KMEM. > + if (ret) > + return ret; > > - return memcg_charge_slab(page, gfp, order, s); > + percpu_ref_get_many(&s->memcg_params.refcnt, 1 << order); Perhaps moving this refcount into memcg_alloc_page_obj_cgroups() (maybe the name should be different then) will allow you to not add #ifdef CONFIG_MEMCG_KMEM in this function. Maybe this is all moot after patch 12/19, will find out :) > + } > +#endif > + mod_node_page_state(page_pgdat(page), cache_vmstat_idx(s), > + PAGE_SIZE << order); > + return 0; > } > > static __always_inline void uncharge_slab_page(struct page *page, int order, > struct kmem_cache *s) > { > - if (is_root_cache(s)) { > - mod_node_page_state(page_pgdat(page), cache_vmstat_idx(s), > - -(PAGE_SIZE << order)); > - return; > +#ifdef CONFIG_MEMCG_KMEM > + if (!is_root_cache(s)) { Everything from above also applies here. > + memcg_free_page_obj_cgroups(page); > + percpu_ref_put_many(&s->memcg_params.refcnt, 1 << order); > } > - > - memcg_free_page_obj_cgroups(page); > - memcg_uncharge_slab(page, order, s); > +#endif > + mod_node_page_state(page_pgdat(page), cache_vmstat_idx(s), > + -(PAGE_SIZE << order)); > } > > static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)