Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp4047379ybe; Mon, 16 Sep 2019 06:00:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqzU8c78MgyWwS5qkwN11sajQOa/gjJUrL9877r+xejQNTz38j6ugoTXRv9p68vz1GPfpURk X-Received: by 2002:aa7:ce88:: with SMTP id y8mr7706806edv.145.1568638851572; Mon, 16 Sep 2019 06:00:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568638851; cv=none; d=google.com; s=arc-20160816; b=hJa+ULPV6YygmliACQuiXn/O/QYXWBLCPOU4yeqmxkJOA0eyiLBAX67s0wCLNwcBxJ f7zhyp3J+gVpzA9Vnod79gXUmFBdRcDRTjEF5IGT+FqtVS/EJAhNOeT+kdxnbLdNuNCp 0SVP+2clUvGLWfOnkSMQaZgqoockiNl7WBNLeKa8d+eRjLavNrnE1lBmnDUBkuyWULRh 57GeBw5ruF18B/5hZtyhlxjUq7z9p6sg6qdgcwAnPe22oPWx117b+0fLAZNJLoUVv+d5 oMrZiGdTeDI3zqyI7J4tJ5fc0mP7ZM4yhBsY2Eet1OyJJJqExefiCWUoDGfnZz5m9vtn pb8Q== 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; bh=6Qvf/tFB1NW9gGSqT/wR7yVJwgXaFo5u9eZ6TcvIymQ=; b=AMarUxQKnVvb18LU+X0jNXh4GQqo1sasN3YO93fIQ0r1syx9bRv11LjURaJeoL1jz9 1ztFXtLTbat3JNzn0GzYgiCFkDvqQYk/hpR6U0cNFEaHQkPkPOBsxzaKKHNk3/3WzHrb T4HzmbZQjPmYojy9slNs51pSFvTpwzqKFwQTaMApgkSEG9FZgzSUlsm+k9Efcl3ULCxO Mn+XJkUzSBEpHv79KABOc2oatVZIugFN3To/UYlp8ab88J74jwHgKGDlYy87UIfBKpjk gtTWENpBGtYAapY0nQzWEpixHm0zcoLfLZJActkjHq5T5ss2+hkzQ7N3Kdbtyn1LLkpS ew8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=LI0rw6Yw; 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 w34si887986edc.252.2019.09.16.06.00.26; Mon, 16 Sep 2019 06:00:51 -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=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=LI0rw6Yw; 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 S1732909AbfIPM4X (ORCPT + 99 others); Mon, 16 Sep 2019 08:56:23 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:39313 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727948AbfIPM4W (ORCPT ); Mon, 16 Sep 2019 08:56:22 -0400 Received: by mail-wr1-f68.google.com with SMTP id r3so8624964wrj.6 for ; Mon, 16 Sep 2019 05:56:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=6Qvf/tFB1NW9gGSqT/wR7yVJwgXaFo5u9eZ6TcvIymQ=; b=LI0rw6YwWN8ZIfFY1x3z7d6DQpjq1QMQHKmc7RC7CC750QO/kXXnllfg27qnoqAVwj eOrs7Ok0zw8+0mC4k4Jas6ArWZ1toc9mxNIsx2MGIjCIOcF6TgNm28y0xTH98tDtjPvu z6tuz4dguo1cVBhI1ATSthZKAKNTJDFbcS59WGmsG1v5ES0TckZ2dtl9VnI6EtbL3yL1 nHOVapGTD/Ab1h2qi8Z5Vo6nyxPqUu++h8xLt+tZK/mdN2jQHtbw1gKF2BwoPBLN4+ey zop2FPw30hJ4cV7Q+Rttu+1PEwp0yQnXa9Ou3W/AI2BZ/RImBrdhOkEdR6QzE4EkXBUT yCRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=6Qvf/tFB1NW9gGSqT/wR7yVJwgXaFo5u9eZ6TcvIymQ=; b=amPgI/awnbTnP0jKrd80HcLVhf3KHsN50rBZy9Fz534v/YZYsoA4lRAtLXeyTkgKgN iLouIIjRjH/gtNlSe/JDmvtigR+5foIx6rJHlzfJubcjqDe1nNSuZtfnv+cA9emAqI+U IbgJNIjxR4HRo2zU2HJpM3NOKBa9KhoCGuonQzcG2esjIRWcPOGtbrrsoxlwX+lf+/pw NWu0bzMKcSDgD3qINVauqP3LPX8Oc1+ftRLxZy6LvCP6D+zV9AVfr3nAgaTEmMAgQSng Q02pNKpLNUftmqOmVyTkTgset+/JZJ9BENO3QbwFrkaGZFvAsT/1Bg24gdm0BnTtznHN zr4w== X-Gm-Message-State: APjAAAW5MjVlCZz2iizCxM6Nvsuy53m9KLM3GL7mriK07HbX+siM3a/u mSBKmq54wzqOXoW26I84tkPAKA== X-Received: by 2002:a5d:46c4:: with SMTP id g4mr11644497wrs.189.1568638579404; Mon, 16 Sep 2019 05:56:19 -0700 (PDT) Received: from localhost (p4FC6B710.dip0.t-ipconnect.de. [79.198.183.16]) by smtp.gmail.com with ESMTPSA id q15sm11000696wmb.28.2019.09.16.05.56.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Sep 2019 05:56:18 -0700 (PDT) Date: Mon, 16 Sep 2019 14:56:11 +0200 From: Johannes Weiner To: Roman Gushchin Cc: linux-mm@kvack.org, Michal Hocko , linux-kernel@vger.kernel.org, kernel-team@fb.com, Shakeel Butt , Vladimir Davydov , Waiman Long Subject: Re: [PATCH RFC 01/14] mm: memcg: subpage charging API Message-ID: <20190916125611.GB29985@cmpxchg.org> References: <20190905214553.1643060-1-guro@fb.com> <20190905214553.1643060-2-guro@fb.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190905214553.1643060-2-guro@fb.com> User-Agent: Mutt/1.12.1 (2019-06-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Sep 05, 2019 at 02:45:45PM -0700, Roman Gushchin wrote: > Introduce an API to charge subpage objects to the memory cgroup. > The API will be used by the new slab memory controller. Later it > can also be used to implement percpu memory accounting. > In both cases, a single page can be shared between multiple cgroups > (and in percpu case a single allocation is split over multiple pages), > so it's not possible to use page-based accounting. > > The implementation is based on percpu stocks. Memory cgroups are still > charged in pages, and the residue is stored in perpcu stock, or on the > memcg itself, when it's necessary to flush the stock. Did you just implement a slab allocator for page_counter to track memory consumed by the slab allocator? > @@ -2500,8 +2577,9 @@ void mem_cgroup_handle_over_high(void) > } > > static int try_charge(struct mem_cgroup *memcg, gfp_t gfp_mask, > - unsigned int nr_pages) > + unsigned int amount, bool subpage) > { > + unsigned int nr_pages = subpage ? ((amount >> PAGE_SHIFT) + 1) : amount; > unsigned int batch = max(MEMCG_CHARGE_BATCH, nr_pages); > int nr_retries = MEM_CGROUP_RECLAIM_RETRIES; > struct mem_cgroup *mem_over_limit; > @@ -2514,7 +2592,9 @@ static int try_charge(struct mem_cgroup *memcg, gfp_t gfp_mask, > if (mem_cgroup_is_root(memcg)) > return 0; > retry: > - if (consume_stock(memcg, nr_pages)) > + if (subpage && consume_subpage_stock(memcg, amount)) > + return 0; > + else if (!subpage && consume_stock(memcg, nr_pages)) > return 0; The layering here isn't clean. We have an existing per-cpu cache to batch-charge the page counter. Why does the new subpage allocator not sit on *top* of this, instead of wedged in between? I think what it should be is a try_charge_bytes() that simply gets one page from try_charge() and then does its byte tracking, regardless of how try_charge() chooses to implement its own page tracking. That would avoid the awkward @amount + @subpage multiplexing, as well as annotating all existing callsites of try_charge() with a non-descript "false" parameter. You can still reuse the stock data structures, use the lower bits of stock->nr_bytes for a different cgroup etc., but the charge API should really be separate.