Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3086365pxv; Mon, 12 Jul 2021 09:00:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyNgwjZy22c9f1cMvSB9zim+rhwMnxpKOiHUJUKgbO0YtLIJiqqoIOM9hMrfwU4KZnN5UO4 X-Received: by 2002:a92:200b:: with SMTP id j11mr38726576ile.183.1626105606517; Mon, 12 Jul 2021 09:00:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626105606; cv=none; d=google.com; s=arc-20160816; b=MU5aCQgRUpZZhgKoccIQMWHMc74n5LJ0TtL/gYl2eEqeX3/BtLGUjHjbcB1WSpFexM ThWoHgl7JiR8XedDfb3ypJM02cuuztakpeaodHZGA58XNcsH1zrcgyzmev/SFFqvwTIh IuR31v2ge5zqHvEt9giX5+gag+oPiKRJqt3f0BriAzt0w4OtL2W8XOvnax842XMIa799 NkGdixt90FixGqGBB1r1UbTxnh7jZrJkjWRLFVUEuywv+8BPF6KADlkSz1X186lC5Sda 7ZIHDJrPt4vg2YYKmrSKrll+L4asaesAbtjUqITR+zxvolOYpCM3mwEoZxlwWjKVd/yo eNIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=N9Vsyf7u0V+Ft7+096/kMzSi5iobK3XqcnGMJrpg+tE=; b=brUpQJztfzRaPZQK9HVgLSXOYJYBVvWkbx6ZICtH/6xE/M1CKIwDeJuB+7OXNEI5Os jDYfWDKG94mHLbH4bOY6mH4MTDWG44NjzV4QSQJYIGy3ZAAo0YldY1imfgwrAvx8m16i 0ctLgWSecmvWHDP/Dhn4t5NsaOQbJH8KixAuHyPGky/IamaO3PME52xJJaYT35+ieLNL YhoxMlLIlIEmjgCTWSATKPQcE9ISJy238P9oYRSK4mF1i4tfdnAuJdGXO3paq4K4NvGP MnPm1UxlrRKNMuo5vWby5RNpBD5UC5rz+Ew4Nhw3CkaCRQZ2bN38Z762ekeLXJUW+hKi SrPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=hhSy8Vnz; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o11si19703828ils.18.2021.07.12.08.59.54; Mon, 12 Jul 2021 09:00:06 -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; dkim=pass header.i=@google.com header.s=20161025 header.b=hhSy8Vnz; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234121AbhGLQAh (ORCPT + 99 others); Mon, 12 Jul 2021 12:00:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48536 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235280AbhGLQAc (ORCPT ); Mon, 12 Jul 2021 12:00:32 -0400 Received: from mail-yb1-xb2e.google.com (mail-yb1-xb2e.google.com [IPv6:2607:f8b0:4864:20::b2e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A715C0613EF for ; Mon, 12 Jul 2021 08:57:43 -0700 (PDT) Received: by mail-yb1-xb2e.google.com with SMTP id r132so29777543yba.5 for ; Mon, 12 Jul 2021 08:57:43 -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=N9Vsyf7u0V+Ft7+096/kMzSi5iobK3XqcnGMJrpg+tE=; b=hhSy8Vnz1wd1BsEaHB/mm4pUGxueHg3H9aiR6qpV6lk+8ysJ6SCoL1MmYSCqJpIqwh 0tplbTJre0RBWmYNVtwpwimDV7DAezCaVKE1azllWzTzWLM4PePeeTHUK121IsBn6HGc GiMAc5r+QlaMlUo4+8m8cUYOjWvevJmJ1WljFQPI9rjP2VyKtvNAM9tPRTTsIgoLQ97l N32TyopBfSih3yP0Dci9auCmEQLajZkCwYnEXtq1IKrcaBK5GpjeqTP0XUoLZcN7eLIo fcOqysFdLZ4cMmkqV5fQ1x0SqtryUzk8ylJbhukP0eXS5gmwKr1EVpusI5lE+Ylh17Dx 7yCg== 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=N9Vsyf7u0V+Ft7+096/kMzSi5iobK3XqcnGMJrpg+tE=; b=rjXd5UOz3vUe60U2eDfXxXYLT8Ou7NswCj7Ze3licbW3ehAgkxOquOhWWSho6FjwNT 75mDInoK6M//YdglfKVKNVhItRVrIyFj+k3m28UupW9oVHxHkQ6sdjmO96TMcPDjEBXc e94VQtxyKZV0N0E5w3zO83viTI3N+SottPAgyYpg0MZQjeZQDKQhJJOhy8r7dygXhCeF Hy1qKY5fQFMMxIttb58sdplbUZewjJsj8iW21wutxOHlLcJCQ7uP055LCenoL7orzr0U b4n8KvpTziFsaxK8jTuM83qBWLnaIFl+OGZqP3NUdYK5OEmW91sJbv9s/A7ZqdvzeTZT 0/Aw== X-Gm-Message-State: AOAM530RkF8qah3+VwYdzg8SnnvKVQGpERNc/b+FVpjlR+dfT/uIm7Ta lvPdj+pdhCNMDZ0u1xBA2nJqXezdLp3WDl1CL/UHJQ== X-Received: by 2002:a25:ba08:: with SMTP id t8mr66449426ybg.111.1626105462122; Mon, 12 Jul 2021 08:57:42 -0700 (PDT) MIME-Version: 1.0 References: <20210710003626.3549282-1-surenb@google.com> <20210710003626.3549282-3-surenb@google.com> In-Reply-To: From: Suren Baghdasaryan Date: Mon, 12 Jul 2021 08:57:31 -0700 Message-ID: Subject: Re: [PATCH v3 3/3] mm, memcg: inline swap-related functions to improve disabled memcg config To: Michal Hocko Cc: Tejun Heo , Johannes Weiner , vdavydov.dev@gmail.com, Andrew Morton , Shakeel Butt , Roman Gushchin , songmuchun@bytedance.com, Yang Shi , alexs@kernel.org, richard.weiyang@gmail.com, Vlastimil Babka , Jens Axboe , Joonsoo Kim , David Hildenbrand , Matthew Wilcox , apopple@nvidia.com, Minchan Kim , Miaohe Lin , LKML , cgroups mailinglist , linux-mm , kernel-team Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jul 12, 2021 at 12:17 AM Michal Hocko wrote: > > On Fri 09-07-21 17:36:26, Suren Baghdasaryan wrote: > > Inline mem_cgroup_try_charge_swap, mem_cgroup_uncharge_swap and > > cgroup_throttle_swaprate functions to perform mem_cgroup_disabled static > > key check inline before calling the main body of the function. This > > minimizes the memcg overhead in the pagefault and exit_mmap paths when > > memcgs are disabled using cgroup_disable=memory command-line option. > > This change results in ~1% overhead reduction when running PFT test > > comparing {CONFIG_MEMCG=n} against {CONFIG_MEMCG=y, cgroup_disable=memory} > > configuration on an 8-core ARM64 Android device. > > > > Signed-off-by: Suren Baghdasaryan > > Reviewed-by: Shakeel Butt > > Acked-by: Johannes Weiner > > I find it a bit surprising to see such a big difference over a function > call in a slow path like swap in/out. Might be due to the nature of the test. It is designed to generate an avalanche of anonymous pagefaults and that might be the reason swap functions are hit this hard. > > Anyway the change makes sense. > > Acked-by: Michal Hocko > > Thanks! > > > --- > > include/linux/swap.h | 26 +++++++++++++++++++++++--- > > mm/memcontrol.c | 14 ++++---------- > > mm/swapfile.c | 5 +---- > > 3 files changed, 28 insertions(+), 17 deletions(-) > > > > diff --git a/include/linux/swap.h b/include/linux/swap.h > > index 6f5a43251593..f30d26b0f71d 100644 > > --- a/include/linux/swap.h > > +++ b/include/linux/swap.h > > @@ -721,7 +721,13 @@ static inline int mem_cgroup_swappiness(struct mem_cgroup *mem) > > #endif > > > > #if defined(CONFIG_SWAP) && defined(CONFIG_MEMCG) && defined(CONFIG_BLK_CGROUP) > > -extern void cgroup_throttle_swaprate(struct page *page, gfp_t gfp_mask); > > +extern void __cgroup_throttle_swaprate(struct page *page, gfp_t gfp_mask); > > +static inline void cgroup_throttle_swaprate(struct page *page, gfp_t gfp_mask) > > +{ > > + if (mem_cgroup_disabled()) > > + return; > > + __cgroup_throttle_swaprate(page, gfp_mask); > > +} > > #else > > static inline void cgroup_throttle_swaprate(struct page *page, gfp_t gfp_mask) > > { > > @@ -730,8 +736,22 @@ static inline void cgroup_throttle_swaprate(struct page *page, gfp_t gfp_mask) > > > > #ifdef CONFIG_MEMCG_SWAP > > extern void mem_cgroup_swapout(struct page *page, swp_entry_t entry); > > -extern int mem_cgroup_try_charge_swap(struct page *page, swp_entry_t entry); > > -extern void mem_cgroup_uncharge_swap(swp_entry_t entry, unsigned int nr_pages); > > +extern int __mem_cgroup_try_charge_swap(struct page *page, swp_entry_t entry); > > +static inline int mem_cgroup_try_charge_swap(struct page *page, swp_entry_t entry) > > +{ > > + if (mem_cgroup_disabled()) > > + return 0; > > + return __mem_cgroup_try_charge_swap(page, entry); > > +} > > + > > +extern void __mem_cgroup_uncharge_swap(swp_entry_t entry, unsigned int nr_pages); > > +static inline void mem_cgroup_uncharge_swap(swp_entry_t entry, unsigned int nr_pages) > > +{ > > + if (mem_cgroup_disabled()) > > + return; > > + __mem_cgroup_uncharge_swap(entry, nr_pages); > > +} > > + > > extern long mem_cgroup_get_nr_swap_pages(struct mem_cgroup *memcg); > > extern bool mem_cgroup_swap_full(struct page *page); > > #else > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > > index cdaf7003b43d..0b05322836ec 100644 > > --- a/mm/memcontrol.c > > +++ b/mm/memcontrol.c > > @@ -7234,7 +7234,7 @@ void mem_cgroup_swapout(struct page *page, swp_entry_t entry) > > } > > > > /** > > - * mem_cgroup_try_charge_swap - try charging swap space for a page > > + * __mem_cgroup_try_charge_swap - try charging swap space for a page > > * @page: page being added to swap > > * @entry: swap entry to charge > > * > > @@ -7242,16 +7242,13 @@ void mem_cgroup_swapout(struct page *page, swp_entry_t entry) > > * > > * Returns 0 on success, -ENOMEM on failure. > > */ > > -int mem_cgroup_try_charge_swap(struct page *page, swp_entry_t entry) > > +int __mem_cgroup_try_charge_swap(struct page *page, swp_entry_t entry) > > { > > unsigned int nr_pages = thp_nr_pages(page); > > struct page_counter *counter; > > struct mem_cgroup *memcg; > > unsigned short oldid; > > > > - if (mem_cgroup_disabled()) > > - return 0; > > - > > if (!cgroup_subsys_on_dfl(memory_cgrp_subsys)) > > return 0; > > > > @@ -7287,18 +7284,15 @@ int mem_cgroup_try_charge_swap(struct page *page, swp_entry_t entry) > > } > > > > /** > > - * mem_cgroup_uncharge_swap - uncharge swap space > > + * __mem_cgroup_uncharge_swap - uncharge swap space > > * @entry: swap entry to uncharge > > * @nr_pages: the amount of swap space to uncharge > > */ > > -void mem_cgroup_uncharge_swap(swp_entry_t entry, unsigned int nr_pages) > > +void __mem_cgroup_uncharge_swap(swp_entry_t entry, unsigned int nr_pages) > > { > > struct mem_cgroup *memcg; > > unsigned short id; > > > > - if (mem_cgroup_disabled()) > > - return; > > - > > id = swap_cgroup_record(entry, 0, nr_pages); > > rcu_read_lock(); > > memcg = mem_cgroup_from_id(id); > > diff --git a/mm/swapfile.c b/mm/swapfile.c > > index 707fa0481bb4..04a0c83f1313 100644 > > --- a/mm/swapfile.c > > +++ b/mm/swapfile.c > > @@ -3773,14 +3773,11 @@ static void free_swap_count_continuations(struct swap_info_struct *si) > > } > > > > #if defined(CONFIG_MEMCG) && defined(CONFIG_BLK_CGROUP) > > -void cgroup_throttle_swaprate(struct page *page, gfp_t gfp_mask) > > +void __cgroup_throttle_swaprate(struct page *page, gfp_t gfp_mask) > > { > > struct swap_info_struct *si, *next; > > int nid = page_to_nid(page); > > > > - if (mem_cgroup_disabled()) > > - return; > > - > > if (!(gfp_mask & __GFP_IO)) > > return; > > > > -- > > 2.32.0.93.g670b81a890-goog > > -- > Michal Hocko > SUSE Labs