Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp3324274pxb; Wed, 14 Apr 2021 02:49:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz7rKpi9dtQWnwtvel8Tr+vXDz9xkpCJ9L5TJVg/74uPtyoStSjmE/7MMFJRJAGYIQc0+p+ X-Received: by 2002:a17:906:ecb8:: with SMTP id qh24mr37941051ejb.162.1618393739998; Wed, 14 Apr 2021 02:48:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618393739; cv=none; d=google.com; s=arc-20160816; b=ZFacSQut8xDZrV8f/Lq335wBauGga3eB+0h2aaeKBzFqmUBUA0FYuV+4mzfd8s6gEL zio8izclVtyYBKV63aUp75KsdvcvzljA5X3OqmxjAXqMCqXaQ3hPggtNJGn9BiUyFFWs CJN/90GCNyBFvtxh7vVw8mFdTLMhRipYC/FkifvyMvTltQknK3oyDl4FljAaEv4klw4s oBdtoAMbMHwJfG/vlxRXHV/Z4ZoTIlvjYOWBtu65gdTW63JtMETGQLT1079cOkt0q1nr pzCTvQ3JCjpevkOIP3eTITcz2e4zr6uJ2Ax9neQhlq2V05Zq+f/iQp25/RtXo9KwlGj3 injA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=80OiZdRF0zG+/9/xLJu7PaNs7xvMkYou02sp8RHghi4=; b=bmT3DFYQVK35ezQECJYtI1FPHN8IuT82PsWGBSwQGhUij8NPKtkaJTFx68SZWfVp89 N7TaeEJZNbAZhFx04aTZ4zzRiel5PzfC0RDMfMUviUFAK7wKOTxSKEOmDHPHu3MFGhfc ziSWt1bF4oeM9oAtjCOPRZr/weFgmqm0Y7YEByaKa9h8PSUHfke4mKhleKXDT/6JLczx vQYIBsWMRSfhdSWR470c6zOfHA+Mb5nTs/nA0v9RLAYGn8EL1jbZ3mzaKD8d8X4NBb0k LKe55r1BUDCXmULStbHGQ+M1oJjdDkq1VrPn1mq8drRU5HXHj5hn25OKZr4hMCJ14blR 7wfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="Si/9Ody1"; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h14si4248903ejl.606.2021.04.14.02.48.36; Wed, 14 Apr 2021 02:48:59 -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=@redhat.com header.s=mimecast20190719 header.b="Si/9Ody1"; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346527AbhDNBVQ (ORCPT + 99 others); Tue, 13 Apr 2021 21:21:16 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:43381 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345684AbhDNBVN (ORCPT ); Tue, 13 Apr 2021 21:21:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618363252; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=80OiZdRF0zG+/9/xLJu7PaNs7xvMkYou02sp8RHghi4=; b=Si/9Ody13l/EO6BBWc3OKwOfzjcbDSe+4C/1PHosUBptpV3w1iSh9uRiozqH+yUxO5929P d5qaYubWxnJ9CB7FZ5GJl/RvQktsrT4NOeD0OoMTbHkdXc5kqJY8mzbC8Z4QtMv4YxLUcA vE80KOnkvQIQJcdXS5KpKr+5h02wR/U= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-350-mOc640h4MkquAy0kaneemg-1; Tue, 13 Apr 2021 21:20:50 -0400 X-MC-Unique: mOc640h4MkquAy0kaneemg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 72107107ACCD; Wed, 14 Apr 2021 01:20:48 +0000 (UTC) Received: from llong.com (ovpn-113-4.rdu2.redhat.com [10.10.113.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3E81F1F419; Wed, 14 Apr 2021 01:20:45 +0000 (UTC) From: Waiman Long To: Johannes Weiner , Michal Hocko , Vladimir Davydov , Andrew Morton , Tejun Heo , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Vlastimil Babka , Roman Gushchin Cc: linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-mm@kvack.org, Shakeel Butt , Muchun Song , Alex Shi , Chris Down , Yafang Shao , Wei Yang , Masayoshi Mizuma , Xing Zhengjun , Waiman Long Subject: [PATCH v3 1/5] mm/memcg: Pass both memcg and lruvec to mod_memcg_lruvec_state() Date: Tue, 13 Apr 2021 21:20:23 -0400 Message-Id: <20210414012027.5352-2-longman@redhat.com> In-Reply-To: <20210414012027.5352-1-longman@redhat.com> References: <20210414012027.5352-1-longman@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The caller of mod_memcg_lruvec_state() has both memcg and lruvec readily available. So both of them are now passed to mod_memcg_lruvec_state() and __mod_memcg_lruvec_state(). The __mod_memcg_lruvec_state() is updated to allow either of the two parameters to be set to null. This makes mod_memcg_lruvec_state() equivalent to mod_memcg_state() if lruvec is null. The new __mod_memcg_lruvec_state() function will be used in the next patch as a replacement of mod_memcg_state() in mm/percpu.c for the consolidation of the memory uncharge and vmstat update functions in the kmem_cache_free() path. Signed-off-by: Waiman Long Acked-by: Roman Gushchin Reviewed-by: Shakeel Butt --- include/linux/memcontrol.h | 12 +++++++----- mm/memcontrol.c | 19 +++++++++++++------ mm/slab.h | 2 +- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 0c04d39a7967..95f12996e66c 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -955,8 +955,8 @@ static inline unsigned long lruvec_page_state_local(struct lruvec *lruvec, return x; } -void __mod_memcg_lruvec_state(struct lruvec *lruvec, enum node_stat_item idx, - int val); +void __mod_memcg_lruvec_state(struct mem_cgroup *memcg, struct lruvec *lruvec, + enum node_stat_item idx, int val); void __mod_lruvec_kmem_state(void *p, enum node_stat_item idx, int val); static inline void mod_lruvec_kmem_state(void *p, enum node_stat_item idx, @@ -969,13 +969,14 @@ static inline void mod_lruvec_kmem_state(void *p, enum node_stat_item idx, local_irq_restore(flags); } -static inline void mod_memcg_lruvec_state(struct lruvec *lruvec, +static inline void mod_memcg_lruvec_state(struct mem_cgroup *memcg, + struct lruvec *lruvec, enum node_stat_item idx, int val) { unsigned long flags; local_irq_save(flags); - __mod_memcg_lruvec_state(lruvec, idx, val); + __mod_memcg_lruvec_state(memcg, lruvec, idx, val); local_irq_restore(flags); } @@ -1369,7 +1370,8 @@ static inline unsigned long lruvec_page_state_local(struct lruvec *lruvec, return node_page_state(lruvec_pgdat(lruvec), idx); } -static inline void __mod_memcg_lruvec_state(struct lruvec *lruvec, +static inline void __mod_memcg_lruvec_state(struct mem_cgroup *memcg, + struct lruvec *lruvec, enum node_stat_item idx, int val) { } diff --git a/mm/memcontrol.c b/mm/memcontrol.c index e064ac0d850a..d66e1e38f8ac 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -799,20 +799,27 @@ parent_nodeinfo(struct mem_cgroup_per_node *pn, int nid) return mem_cgroup_nodeinfo(parent, nid); } -void __mod_memcg_lruvec_state(struct lruvec *lruvec, enum node_stat_item idx, - int val) +/* + * Either one of memcg or lruvec can be NULL, but not both. + */ +void __mod_memcg_lruvec_state(struct mem_cgroup *memcg, struct lruvec *lruvec, + enum node_stat_item idx, int val) { struct mem_cgroup_per_node *pn; - struct mem_cgroup *memcg; long x, threshold = MEMCG_CHARGE_BATCH; + /* Update lruvec */ pn = container_of(lruvec, struct mem_cgroup_per_node, lruvec); - memcg = pn->memcg; + + if (!memcg) + memcg = pn->memcg; /* Update memcg */ __mod_memcg_state(memcg, idx, val); - /* Update lruvec */ + if (!lruvec) + return; + __this_cpu_add(pn->lruvec_stat_local->count[idx], val); if (vmstat_item_in_bytes(idx)) @@ -848,7 +855,7 @@ void __mod_lruvec_state(struct lruvec *lruvec, enum node_stat_item idx, /* Update memcg and lruvec */ if (!mem_cgroup_disabled()) - __mod_memcg_lruvec_state(lruvec, idx, val); + __mod_memcg_lruvec_state(NULL, lruvec, idx, val); } void __mod_lruvec_page_state(struct page *page, enum node_stat_item idx, diff --git a/mm/slab.h b/mm/slab.h index 076582f58f68..bc6c7545e487 100644 --- a/mm/slab.h +++ b/mm/slab.h @@ -293,7 +293,7 @@ static inline void mod_objcg_state(struct obj_cgroup *objcg, rcu_read_lock(); memcg = obj_cgroup_memcg(objcg); lruvec = mem_cgroup_lruvec(memcg, pgdat); - mod_memcg_lruvec_state(lruvec, idx, nr); + mod_memcg_lruvec_state(memcg, lruvec, idx, nr); rcu_read_unlock(); } -- 2.18.1